OLD | NEW |
1 /* This Source Code Form is subject to the terms of the Mozilla Public | 1 /* This Source Code Form is subject to the terms of the Mozilla Public |
2 * License, v. 2.0. If a copy of the MPL was not distributed with this | 2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 /* | 4 /* |
5 * This file deals with PKCS #11 passwords and authentication. | 5 * This file deals with PKCS #11 passwords and authentication. |
6 */ | 6 */ |
7 #include "seccomon.h" | 7 #include "seccomon.h" |
8 #include "secmod.h" | 8 #include "secmod.h" |
9 #include "secmodi.h" | 9 #include "secmodi.h" |
10 #include "secmodti.h" | 10 #include "secmodti.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 } PK11_Global = { 1, PR_FALSE, NULL, NULL, NULL }; | 39 } PK11_Global = { 1, PR_FALSE, NULL, NULL, NULL }; |
40 | 40 |
41 /*********************************************************** | 41 /*********************************************************** |
42 * Password Utilities | 42 * Password Utilities |
43 ***********************************************************/ | 43 ***********************************************************/ |
44 /* | 44 /* |
45 * Check the user's password. Log into the card if it's correct. | 45 * Check the user's password. Log into the card if it's correct. |
46 * succeed if the user is already logged in. | 46 * succeed if the user is already logged in. |
47 */ | 47 */ |
48 SECStatus | 48 SECStatus |
49 pk11_CheckPassword(PK11SlotInfo *slot,char *pw) | 49 pk11_CheckPassword(PK11SlotInfo *slot,char *pw,PRBool contextSpecific) |
50 { | 50 { |
51 int len = 0; | 51 int len = 0; |
52 CK_RV crv; | 52 CK_RV crv; |
53 SECStatus rv; | 53 SECStatus rv; |
54 int64 currtime = PR_Now(); | 54 int64 currtime = PR_Now(); |
55 PRBool mustRetry; | 55 PRBool mustRetry; |
56 int retry = 0; | 56 int retry = 0; |
57 | 57 |
58 if (slot->protectedAuthPath) { | 58 if (slot->protectedAuthPath) { |
59 len = 0; | 59 len = 0; |
60 pw = NULL; | 60 pw = NULL; |
61 } else if (pw == NULL) { | 61 } else if (pw == NULL) { |
62 PORT_SetError(SEC_ERROR_INVALID_ARGS); | 62 PORT_SetError(SEC_ERROR_INVALID_ARGS); |
63 return SECFailure; | 63 return SECFailure; |
64 } else { | 64 } else { |
65 len = PORT_Strlen(pw); | 65 len = PORT_Strlen(pw); |
66 } | 66 } |
67 | 67 |
68 do { | 68 do { |
69 PK11_EnterSlotMonitor(slot); | 69 PK11_EnterSlotMonitor(slot); |
70 » crv = PK11_GETTAB(slot)->C_Login(slot->session,CKU_USER, | 70 » crv = PK11_GETTAB(slot)->C_Login(slot->session, |
| 71 » » contextSpecific ? CKU_CONTEXT_SPECIFIC : CKU_USER, |
71 (unsigned char *)pw,len); | 72 (unsigned char *)pw,len); |
72 slot->lastLoginCheck = 0; | 73 slot->lastLoginCheck = 0; |
73 mustRetry = PR_FALSE; | 74 mustRetry = PR_FALSE; |
74 PK11_ExitSlotMonitor(slot); | 75 PK11_ExitSlotMonitor(slot); |
75 switch (crv) { | 76 switch (crv) { |
76 /* if we're already logged in, we're good to go */ | 77 /* if we're already logged in, we're good to go */ |
77 case CKR_OK: | 78 case CKR_OK: |
| 79 /* TODO If it was for CKU_CONTEXT_SPECIFIC should we do this */ |
78 slot->authTransact = PK11_Global.transaction; | 80 slot->authTransact = PK11_Global.transaction; |
79 /* Fall through */ | 81 /* Fall through */ |
80 case CKR_USER_ALREADY_LOGGED_IN: | 82 case CKR_USER_ALREADY_LOGGED_IN: |
81 slot->authTime = currtime; | 83 slot->authTime = currtime; |
82 rv = SECSuccess; | 84 rv = SECSuccess; |
83 break; | 85 break; |
84 case CKR_PIN_INCORRECT: | 86 case CKR_PIN_INCORRECT: |
85 PORT_SetError(SEC_ERROR_BAD_PASSWORD); | 87 PORT_SetError(SEC_ERROR_BAD_PASSWORD); |
86 rv = SECWouldBlock; /* everything else is ok, only the pin is bad */ | 88 rv = SECWouldBlock; /* everything else is ok, only the pin is bad */ |
87 break; | 89 break; |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 } else if (askpw == -1) { | 235 } else if (askpw == -1) { |
234 if (!PK11_Global.inTransaction || | 236 if (!PK11_Global.inTransaction || |
235 (PK11_Global.transaction != slot->authTransact)) { | 237 (PK11_Global.transaction != slot->authTransact)) { |
236 PK11_EnterSlotMonitor(slot); | 238 PK11_EnterSlotMonitor(slot); |
237 PK11_GETTAB(slot)->C_Logout(slot->session); | 239 PK11_GETTAB(slot)->C_Logout(slot->session); |
238 slot->lastLoginCheck = 0; | 240 slot->lastLoginCheck = 0; |
239 PK11_ExitSlotMonitor(slot); | 241 PK11_ExitSlotMonitor(slot); |
240 NeedAuth = PR_TRUE; | 242 NeedAuth = PR_TRUE; |
241 } | 243 } |
242 } | 244 } |
243 if (NeedAuth) PK11_DoPassword(slot,PR_TRUE,wincx); | 245 if (NeedAuth) PK11_DoPassword(slot,PR_TRUE,wincx,PR_FALSE); |
244 } | 246 } |
245 | 247 |
246 void | 248 void |
247 PK11_SlotDBUpdate(PK11SlotInfo *slot) | 249 PK11_SlotDBUpdate(PK11SlotInfo *slot) |
248 { | 250 { |
249 SECMOD_UpdateModule(slot->module); | 251 SECMOD_UpdateModule(slot->module); |
250 } | 252 } |
251 | 253 |
252 /* | 254 /* |
253 * set new askpw and timeout values | 255 * set new askpw and timeout values |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 return slot->needLogin && !PK11_IsLoggedIn(slot,wincx); | 294 return slot->needLogin && !PK11_IsLoggedIn(slot,wincx); |
293 } | 295 } |
294 | 296 |
295 /* | 297 /* |
296 * make sure a slot is authenticated... | 298 * make sure a slot is authenticated... |
297 * This function only does the authentication if it is needed. | 299 * This function only does the authentication if it is needed. |
298 */ | 300 */ |
299 SECStatus | 301 SECStatus |
300 PK11_Authenticate(PK11SlotInfo *slot, PRBool loadCerts, void *wincx) { | 302 PK11_Authenticate(PK11SlotInfo *slot, PRBool loadCerts, void *wincx) { |
301 if (pk11_LoginStillRequired(slot,wincx)) { | 303 if (pk11_LoginStillRequired(slot,wincx)) { |
302 » return PK11_DoPassword(slot,loadCerts,wincx); | 304 » return PK11_DoPassword(slot,loadCerts,wincx,PR_FALSE); |
303 } | 305 } |
304 return SECSuccess; | 306 return SECSuccess; |
305 } | 307 } |
306 | 308 |
307 /* | 309 /* |
308 * Authenticate to "unfriendly" tokens (tokens which need to be logged | 310 * Authenticate to "unfriendly" tokens (tokens which need to be logged |
309 * in to find the certs. | 311 * in to find the certs. |
310 */ | 312 */ |
311 SECStatus | 313 SECStatus |
312 pk11_AuthenticateUnfriendly(PK11SlotInfo *slot, PRBool loadCerts, void *wincx) | 314 pk11_AuthenticateUnfriendly(PK11SlotInfo *slot, PRBool loadCerts, void *wincx) |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 | 525 |
524 | 526 |
525 /* | 527 /* |
526 * authenticate to a slot. This loops until we can't recover, the user | 528 * authenticate to a slot. This loops until we can't recover, the user |
527 * gives up, or we succeed. If we're already logged in and this function | 529 * gives up, or we succeed. If we're already logged in and this function |
528 * is called we will still prompt for a password, but we will probably | 530 * is called we will still prompt for a password, but we will probably |
529 * succeed no matter what the password was (depending on the implementation | 531 * succeed no matter what the password was (depending on the implementation |
530 * of the PKCS 11 module. | 532 * of the PKCS 11 module. |
531 */ | 533 */ |
532 SECStatus | 534 SECStatus |
533 PK11_DoPassword(PK11SlotInfo *slot, PRBool loadCerts, void *wincx) | 535 PK11_DoPassword(PK11SlotInfo *slot, PRBool loadCerts, void *wincx, |
| 536 » » » PRBool contextSpecific) |
534 { | 537 { |
535 SECStatus rv = SECFailure; | 538 SECStatus rv = SECFailure; |
536 char * password; | 539 char * password; |
537 PRBool attempt = PR_FALSE; | 540 PRBool attempt = PR_FALSE; |
538 | 541 |
539 if (PK11_NeedUserInit(slot)) { | 542 if (PK11_NeedUserInit(slot)) { |
540 PORT_SetError(SEC_ERROR_IO); | 543 PORT_SetError(SEC_ERROR_IO); |
541 return SECFailure; | 544 return SECFailure; |
542 } | 545 } |
543 | 546 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 PORT_Free(password); | 595 PORT_Free(password); |
593 continue; | 596 continue; |
594 } | 597 } |
595 /* applicaton tried to authenticate and succeeded we're done */ | 598 /* applicaton tried to authenticate and succeeded we're done */ |
596 if (strcmp(password, PK11_PW_AUTHENTICATED) == 0) { | 599 if (strcmp(password, PK11_PW_AUTHENTICATED) == 0) { |
597 rv = SECSuccess; | 600 rv = SECSuccess; |
598 PORT_Free(password); | 601 PORT_Free(password); |
599 break; | 602 break; |
600 } | 603 } |
601 } | 604 } |
602 » rv = pk11_CheckPassword(slot,password); | 605 » rv = pk11_CheckPassword(slot,password,contextSpecific); |
603 PORT_Memset(password, 0, PORT_Strlen(password)); | 606 PORT_Memset(password, 0, PORT_Strlen(password)); |
604 PORT_Free(password); | 607 PORT_Free(password); |
605 if (rv != SECWouldBlock) break; | 608 if (rv != SECWouldBlock) break; |
606 } | 609 } |
607 if (rv == SECSuccess) { | 610 if (rv == SECSuccess) { |
608 if (!PK11_IsFriendly(slot)) { | 611 if (!PK11_IsFriendly(slot)) { |
609 nssTrustDomain_UpdateCachedTokenCerts(slot->nssToken->trustDomain, | 612 nssTrustDomain_UpdateCachedTokenCerts(slot->nssToken->trustDomain, |
610 slot->nssToken); | 613 slot->nssToken); |
611 } | 614 } |
612 } else if (!attempt) PORT_SetError(SEC_ERROR_BAD_PASSWORD); | 615 } else if (!attempt) PORT_SetError(SEC_ERROR_BAD_PASSWORD); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
762 case CKS_RO_PUBLIC_SESSION: | 765 case CKS_RO_PUBLIC_SESSION: |
763 default: | 766 default: |
764 break; /* fail */ | 767 break; /* fail */ |
765 case CKS_RW_USER_FUNCTIONS: | 768 case CKS_RW_USER_FUNCTIONS: |
766 case CKS_RW_SO_FUNCTIONS: | 769 case CKS_RW_SO_FUNCTIONS: |
767 case CKS_RO_USER_FUNCTIONS: | 770 case CKS_RO_USER_FUNCTIONS: |
768 return PR_TRUE; | 771 return PR_TRUE; |
769 } | 772 } |
770 return PR_FALSE; | 773 return PR_FALSE; |
771 } | 774 } |
OLD | NEW |