diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2013-11-10 08:23:37 +0100 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2013-11-10 08:23:37 +0100 |
commit | 1d84496c0f44aa86dfce76a80e2f9864c73a2c9b (patch) | |
tree | 553e4c19ca3995eac612009a0e260ce98b717ec2 /src/common.c | |
parent | 1c85ee5851ba9ca33c8f177cd33f877c25fe1efb (diff) | |
download | gnutls-1d84496c0f44aa86dfce76a80e2f9864c73a2c9b.tar.gz |
Allow getting the PIN from the GNUTLS_PKCS11_PIN environment variable.
Diffstat (limited to 'src/common.c')
-rw-r--r-- | src/common.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/common.c b/src/common.c index 75728985d7..d5a0c33a76 100644 --- a/src/common.c +++ b/src/common.c @@ -961,7 +961,7 @@ pin_callback(void *user, int attempt, const char *token_url, const char *token_label, unsigned int flags, char *pin, size_t pin_max) { - const char *password; + const char *password = NULL; const char *desc; int cache = MAX_CACHE_TRIES; unsigned len; @@ -1007,8 +1007,18 @@ pin_callback(void *user, int attempt, const char *token_url, printf("Token '%s' with URL '%s' ", token_label, token_url); printf("requires %s PIN\n", desc); + + password = getenv("GNUTLS_PKCS11_PIN"); + + if (password == NULL) + password = getpass("Enter PIN: "); + else { + if (flags & GNUTLS_PIN_WRONG) { + fprintf(stderr, "Cannot continue with a wrong password in the environment.\n"); + exit(1); + } + } - password = getpass("Enter PIN: "); if (password == NULL || password[0] == 0) { fprintf(stderr, "No password given\n"); exit(1); |