|
@@ -885,6 +885,27 @@ void tls_deinit(void *ssl_ctx)
|
|
|
}
|
|
|
|
|
|
|
|
|
+#ifndef OPENSSL_NO_ENGINE
|
|
|
+
|
|
|
+/* Cryptoki return values */
|
|
|
+#define CKR_PIN_INCORRECT 0x000000a0
|
|
|
+#define CKR_PIN_INVALID 0x000000a1
|
|
|
+#define CKR_PIN_LEN_RANGE 0x000000a2
|
|
|
+
|
|
|
+/* libp11 */
|
|
|
+#define ERR_LIB_PKCS11 ERR_LIB_USER
|
|
|
+
|
|
|
+static int tls_is_pin_error(unsigned int err)
|
|
|
+{
|
|
|
+ return ERR_GET_LIB(err) == ERR_LIB_PKCS11 &&
|
|
|
+ (ERR_GET_REASON(err) == CKR_PIN_INCORRECT ||
|
|
|
+ ERR_GET_REASON(err) == CKR_PIN_INVALID ||
|
|
|
+ ERR_GET_REASON(err) == CKR_PIN_LEN_RANGE);
|
|
|
+}
|
|
|
+
|
|
|
+#endif /* OPENSSL_NO_ENGINE */
|
|
|
+
|
|
|
+
|
|
|
static int tls_engine_init(struct tls_connection *conn, const char *engine_id,
|
|
|
const char *pin, const char *key_id,
|
|
|
const char *cert_id, const char *ca_cert_id)
|
|
@@ -936,11 +957,16 @@ static int tls_engine_init(struct tls_connection *conn, const char *engine_id,
|
|
|
key_id, NULL,
|
|
|
&key_cb);
|
|
|
if (!conn->private_key) {
|
|
|
+ unsigned long err = ERR_get_error();
|
|
|
+
|
|
|
wpa_printf(MSG_ERROR,
|
|
|
"ENGINE: cannot load private key with id '%s' [%s]",
|
|
|
key_id,
|
|
|
- ERR_error_string(ERR_get_error(), NULL));
|
|
|
- ret = TLS_SET_PARAMS_ENGINE_PRV_INIT_FAILED;
|
|
|
+ ERR_error_string(err, NULL));
|
|
|
+ if (tls_is_pin_error(err))
|
|
|
+ ret = TLS_SET_PARAMS_ENGINE_PRV_BAD_PIN;
|
|
|
+ else
|
|
|
+ ret = TLS_SET_PARAMS_ENGINE_PRV_INIT_FAILED;
|
|
|
goto err;
|
|
|
}
|
|
|
}
|
|
@@ -2184,9 +2210,13 @@ static int tls_engine_get_cert(struct tls_connection *conn,
|
|
|
|
|
|
if (!ENGINE_ctrl_cmd(conn->engine, "LOAD_CERT_CTRL",
|
|
|
0, ¶ms, NULL, 1)) {
|
|
|
+ unsigned long err = ERR_get_error();
|
|
|
+
|
|
|
wpa_printf(MSG_ERROR, "ENGINE: cannot load client cert with id"
|
|
|
" '%s' [%s]", cert_id,
|
|
|
- ERR_error_string(ERR_get_error(), NULL));
|
|
|
+ ERR_error_string(err, NULL));
|
|
|
+ if (tls_is_pin_error(err))
|
|
|
+ return TLS_SET_PARAMS_ENGINE_PRV_BAD_PIN;
|
|
|
return TLS_SET_PARAMS_ENGINE_PRV_INIT_FAILED;
|
|
|
}
|
|
|
if (!params.cert) {
|