summaryrefslogtreecommitdiff
path: root/src/common.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common.c')
-rw-r--r--src/common.c108
1 files changed, 58 insertions, 50 deletions
diff --git a/src/common.c b/src/common.c
index 808146749e..51ba9465a6 100644
--- a/src/common.c
+++ b/src/common.c
@@ -116,8 +116,7 @@ print_x509_info (gnutls_session_t session, const char *hostname, int insecure)
size_t size = 0;
char *p = NULL;
- ret = gnutls_x509_crt_export (crt, GNUTLS_X509_FMT_PEM,
- p, &size);
+ ret = gnutls_x509_crt_export (crt, GNUTLS_X509_FMT_PEM, p, &size);
if (ret == GNUTLS_E_SHORT_MEMORY_BUFFER)
{
p = malloc (size);
@@ -886,65 +885,74 @@ service_to_port (const char *service)
return ntohs (server_port->s_port);
}
-static int pin_callback(void* user, int attempt, const char *token_url,
- const char *token_label, unsigned int flags, char* pin, size_t pin_max)
+static int
+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;
-int len;
+ const char *password;
+ int len;
/* allow caching of PIN */
-static char* cached_url = NULL;
-static char cached_pin[32] = "";
-
- printf("PIN required for token '%s' with URL '%s'\n", token_label, token_url);
- if (flags & GNUTLS_PKCS11_PIN_FINAL_TRY)
- printf("*** This is the final try before locking!\n");
- if (flags & GNUTLS_PKCS11_PIN_COUNT_LOW)
- printf("*** Only few tries left before locking!\n");
-
- if (flags == 0 && cached_url != NULL) {
- if (strcmp(cached_url, token_url)==0) {
- strcpy(pin, cached_pin);
- return 0;
- }
- }
-
- password = getpass("Enter pin: ");
- if (password==NULL || password[0] == 0) {
- fprintf(stderr, "No password given\n");
- exit(1);
+ static char *cached_url = NULL;
+ static char cached_pin[32] = "";
+
+ printf ("PIN required for token '%s' with URL '%s'\n", token_label,
+ token_url);
+ if (flags & GNUTLS_PKCS11_PIN_FINAL_TRY)
+ printf ("*** This is the final try before locking!\n");
+ if (flags & GNUTLS_PKCS11_PIN_COUNT_LOW)
+ printf ("*** Only few tries left before locking!\n");
+
+ if (flags == 0 && cached_url != NULL)
+ {
+ if (strcmp (cached_url, token_url) == 0)
+ {
+ strcpy (pin, cached_pin);
+ return 0;
}
-
- len = MIN(pin_max,strlen(password));
- memcpy(pin, password, len);
- pin[len] = 0;
-
- /* cache */
- strcpy(cached_pin, pin);
- free(cached_url);
- cached_url = strdup(token_url);
-
- return 0;
+ }
+
+ password = getpass ("Enter pin: ");
+ if (password == NULL || password[0] == 0)
+ {
+ fprintf (stderr, "No password given\n");
+ exit (1);
+ }
+
+ len = MIN (pin_max, strlen (password));
+ memcpy (pin, password, len);
+ pin[len] = 0;
+
+ /* cache */
+ strcpy (cached_pin, pin);
+ free (cached_url);
+ cached_url = strdup (token_url);
+
+ return 0;
}
-static int token_callback(void* user, const char* label, const unsigned retry)
+static int
+token_callback (void *user, const char *label, const unsigned retry)
{
-char buf[32];
-char *p;
+ char buf[32];
+ char *p;
- if (retry > 0) {
- fprintf(stderr, "Could not find token %s\n", label);
- return -1;
- }
- printf("Please insert token '%s' in slot and press enter\n", label);
- p = fgets(buf, sizeof(buf), stdin);
+ if (retry > 0)
+ {
+ fprintf (stderr, "Could not find token %s\n", label);
+ return -1;
+ }
+ printf ("Please insert token '%s' in slot and press enter\n", label);
+ p = fgets (buf, sizeof (buf), stdin);
- return 0;
+ return 0;
}
-void pkcs11_common(void)
+void
+pkcs11_common (void)
{
- gnutls_pkcs11_set_pin_function (pin_callback, NULL);
- gnutls_pkcs11_set_token_function(token_callback, NULL);
+ gnutls_pkcs11_set_pin_function (pin_callback, NULL);
+ gnutls_pkcs11_set_token_function (token_callback, NULL);
}