diff options
author | Werner Koch <wk@gnupg.org> | 1998-01-02 21:40:10 +0100 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 1998-01-02 21:40:10 +0100 |
commit | b7bdef0834f9d04f96f69a5323e0ac3e5e1b7bc2 (patch) | |
tree | cb6bae66627f4ea4d0a6b29631223ed2fe78ee8e /g10/passphrase.c | |
parent | Sylvester Version (diff) | |
download | gnupg2-b7bdef0834f9d04f96f69a5323e0ac3e5e1b7bc2.tar.xz gnupg2-b7bdef0834f9d04f96f69a5323e0ac3e5e1b7bc2.zip |
added more stuff
Diffstat (limited to 'g10/passphrase.c')
-rw-r--r-- | g10/passphrase.c | 59 |
1 files changed, 45 insertions, 14 deletions
diff --git a/g10/passphrase.c b/g10/passphrase.c index a974ca9f5..df8ac7176 100644 --- a/g10/passphrase.c +++ b/g10/passphrase.c @@ -25,13 +25,27 @@ #include <assert.h> #include "util.h" #include "memory.h" +#include "options.h" #include "ttyio.h" #include "cipher.h" #include "keydb.h" +static int pwfd = -1; static int hash_passphrase( DEK *dek, char *pw ); +void +set_passphrase_fd( int fd ) +{ + pwfd = fd; +} + +int +get_passphrase_fd() +{ + return pwfd; +} + /**************** * Get a passphrase for the secret key with KEYID, display TEXT @@ -41,35 +55,51 @@ static int hash_passphrase( DEK *dek, char *pw ); DEK * get_passphrase_hash( u32 *keyid, char *text ) { - char *p=NULL, *pw; + char *pw; DEK *dek; - if( keyid ) { + if( keyid && !opt.batch ) { char *ustr; - tty_printf("\nNeed a pass phrase to unlock the secret key!\n"); - tty_printf("KeyID: " ); + tty_printf("Need a pass phrase to unlock the secret key for:\n"); + tty_printf(" \"" ); ustr = get_user_id_string( keyid ); tty_print_string( ustr, strlen(ustr) ); m_free(ustr); - tty_printf("\n\n"); + tty_printf("\"\n\n"); } - if( keyid && (p=getenv("G10PASSPHRASE")) ) { - pw = m_alloc_secure(strlen(p)+1); - strcpy(pw,p); - tty_printf("Taking it from $G10PASSPHRASE !\n", keyid[1] ); + if( pwfd != -1 ) { /* read the passphrase from the given descriptor */ + int i, len; + + if( !opt.batch ) + tty_printf("Reading from file descriptor %d ...", pwfd ); + for( pw = NULL, i = len = 100; ; i++ ) { + if( i >= len-1 ) { + char *pw2 = pw; + len += 100; + pw = m_alloc_secure( len ); + if( pw2 ) + memcpy(pw, pw2, i ); + i=0; + } + if( read( pwfd, pw+i, 1) != 1 || pw[i] == '\n' ) + break; + } + pw[i] = 0; + if( !opt.batch ) + tty_printf("\b\b\b \n" ); } - else + else if( opt.batch ) + log_fatal("Can't query password in batchmode\n"); + else { pw = tty_get_hidden("Enter pass phrase: " ); + tty_kill_prompt(); + } dek = m_alloc_secure( sizeof *dek ); dek->algo = CIPHER_ALGO_BLOWFISH; if( hash_passphrase( dek, pw ) ) log_bug("get_passphrase_hash\n"); m_free(pw); /* is allocated in secure memory, so it will be burned */ - if( !p ) { - tty_kill_prompt(); - tty_printf("\n"); - } return dek; } @@ -89,6 +119,7 @@ make_dek_from_passphrase( DEK *dek, int mode ) tty_kill_prompt(); if( mode == 2 ) { pw2 = tty_get_hidden("Repeat pass phrase: " ); + tty_kill_prompt(); if( strcmp(pw, pw2) ) { m_free(pw2); m_free(pw); |