#include <pkcs11/cryptoki.h>
#include <pkcs11/pkcs11.h>
-#define PINLEN 32
+/* was 32 octets, Petr Spacek suggested 1024, SoftHSMv2 uses 256... */
+#ifndef PINLEN
+#define PINLEN 256
+#endif
#ifndef PK11_NO_LOGERR
#define PK11_NO_LOGERR 1
char manuf[32];
char model[16];
char serial[16];
- char pin[PINLEN];
+ char pin[PINLEN + 1];
};
static ISC_LIST(pk11_token_t) tokens;
/* Override the token's PIN */
if (logon && pin != NULL && *pin != '\0') {
- memset(token->pin, 0, PINLEN);
+ if (strlen(pin) > PINLEN)
+ return ISC_R_RANGE;
+ memset(token->pin, 0, PINLEN + 1);
strncpy(token->pin, pin, PINLEN);
}
char *uri, *p, *a, *na, *v;
size_t len, l;
FILE *stream = NULL;
- char pin[PINLEN];
+ char pin[PINLEN + 1];
isc_boolean_t gotpin = ISC_FALSE;
isc_result_t ret;
ret = isc_stdio_open(v, "r", &stream);
if (ret != ISC_R_SUCCESS)
goto err;
- memset(pin, 0, PINLEN);
- ret = isc_stdio_read(pin, 1, PINLEN - 1, stream, NULL);
+ memset(pin, 0, PINLEN + 1);
+ ret = isc_stdio_read(pin, 1, PINLEN + 1, stream, &l);
if ((ret != ISC_R_SUCCESS) && (ret != ISC_R_EOF))
goto err;
+ if (l > PINLEN)
+ DST_RET(ISC_R_RANGE);
ret = isc_stdio_close(stream);
stream = NULL;
if (ret != ISC_R_SUCCESS)
DST_RET(ISC_R_NOTFOUND);
obj->slot = token->slotid;
if (gotpin) {
- memmove(token->pin, pin, PINLEN);
+ memmove(token->pin, pin, PINLEN + 1);
obj->reqlogon = ISC_TRUE;
}