summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2020-03-13 04:16:27 +0000
committerDamien Miller <djm@mindrot.org>2020-03-14 19:39:30 +1100
commit1d89232a4aa97fe935cd60b8d24d75c2f70d56c5 (patch)
treedebfc98f39e1c871046e9578b4590fb5b506637f
parent5becbec023f2037394987f85ed7f74b9a28699e0 (diff)
upstream: improve error messages for some common PKCS#11 C_Login
failure cases; based on patch from Jacob Hoffman-Andrews in bz3130; ok dtucker OpenBSD-Commit-ID: b8b849621b4a98e468942efd0a1c519c12ce089e
-rw-r--r--ssh-pkcs11.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/ssh-pkcs11.c b/ssh-pkcs11.c
index cae24525..ec0e9186 100644
--- a/ssh-pkcs11.c
+++ b/ssh-pkcs11.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-pkcs11.c,v 1.48 2020/03/06 18:14:13 markus Exp $ */
+/* $OpenBSD: ssh-pkcs11.c,v 1.49 2020/03/13 04:16:27 djm Exp $ */
/*
* Copyright (c) 2010 Markus Friedl. All rights reserved.
* Copyright (c) 2014 Pedro Martelletto. All rights reserved.
@@ -271,9 +271,24 @@ pkcs11_login_slot(struct pkcs11_provider *provider, struct pkcs11_slotinfo *si,
(pin != NULL) ? strlen(pin) : 0);
if (pin != NULL)
freezero(pin, strlen(pin));
- if (rv != CKR_OK && rv != CKR_USER_ALREADY_LOGGED_IN) {
- error("C_Login failed: %lu", rv);
- return (-1);
+
+ switch (rv) {
+ case CKR_OK:
+ case CKR_USER_ALREADY_LOGGED_IN:
+ /* success */
+ break;
+ case CKR_PIN_LEN_RANGE:
+ error("PKCS#11 login failed: PIN length out of range");
+ return -1;
+ case CKR_PIN_INCORRECT:
+ error("PKCS#11 login failed: PIN incorrect");
+ return -1;
+ case CKR_PIN_LOCKED:
+ error("PKCS#11 login failed: PIN locked");
+ return -1;
+ default:
+ error("PKCS#11 login failed: error %lu", rv);
+ return -1;
}
si->logged_in = 1;
return (0);