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 manages PKCS #11 instances of certificates. | 5 * This file manages PKCS #11 instances of certificates. |
6 */ | 6 */ |
7 | 7 |
8 #include "secport.h" | 8 #include "secport.h" |
9 #include "seccomon.h" | 9 #include "seccomon.h" |
10 #include "secmod.h" | 10 #include "secmod.h" |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 * Build an CERTCertificate structure from a PKCS#11 object ID.... certID | 286 * Build an CERTCertificate structure from a PKCS#11 object ID.... certID |
287 * Must be a CertObject. This code does not explicitly checks that. | 287 * Must be a CertObject. This code does not explicitly checks that. |
288 */ | 288 */ |
289 CERTCertificate * | 289 CERTCertificate * |
290 PK11_MakeCertFromHandle(PK11SlotInfo *slot,CK_OBJECT_HANDLE certID, | 290 PK11_MakeCertFromHandle(PK11SlotInfo *slot,CK_OBJECT_HANDLE certID, |
291 CK_ATTRIBUTE *privateLabel) | 291 CK_ATTRIBUTE *privateLabel) |
292 { | 292 { |
293 char * nickname = NULL; | 293 char * nickname = NULL; |
294 CERTCertificate *cert = NULL; | 294 CERTCertificate *cert = NULL; |
295 CERTCertTrust *trust; | 295 CERTCertTrust *trust; |
296 PRBool isFortezzaRootCA = PR_FALSE; | |
297 PRBool swapNickname = PR_FALSE; | |
298 | 296 |
299 cert = pk11_fastCert(slot,certID,privateLabel, &nickname); | 297 cert = pk11_fastCert(slot,certID,privateLabel, &nickname); |
300 if (cert == NULL) | 298 if (cert == NULL) |
301 goto loser; | 299 goto loser; |
302 » | 300 |
303 if (nickname) { | 301 if (nickname) { |
304 if (cert->nickname != NULL) { | 302 if (cert->nickname != NULL) { |
305 cert->dbnickname = cert->nickname; | 303 cert->dbnickname = cert->nickname; |
306 } | 304 } |
307 cert->nickname = PORT_ArenaStrdup(cert->arena,nickname); | 305 cert->nickname = PORT_ArenaStrdup(cert->arena,nickname); |
308 PORT_Free(nickname); | 306 PORT_Free(nickname); |
309 nickname = NULL; | 307 nickname = NULL; |
310 swapNickname = PR_TRUE; | |
311 } | 308 } |
312 | 309 |
313 /* remember where this cert came from.... If we have just looked | 310 /* remember where this cert came from.... If we have just looked |
314 * it up from the database and it already has a slot, don't add a new | 311 * it up from the database and it already has a slot, don't add a new |
315 * one. */ | 312 * one. */ |
316 if (cert->slot == NULL) { | 313 if (cert->slot == NULL) { |
317 cert->slot = PK11_ReferenceSlot(slot); | 314 cert->slot = PK11_ReferenceSlot(slot); |
318 cert->pkcs11ID = certID; | 315 cert->pkcs11ID = certID; |
319 cert->ownSlot = PR_TRUE; | 316 cert->ownSlot = PR_TRUE; |
320 cert->series = slot->series; | 317 cert->series = slot->series; |
(...skipping 15 matching lines...) Expand all Loading... |
336 * valid CA's which are self-signed here. They must have an object | 333 * valid CA's which are self-signed here. They must have an object |
337 * ID of '0'. */ | 334 * ID of '0'. */ |
338 if (pk11_isID0(slot,certID) && | 335 if (pk11_isID0(slot,certID) && |
339 cert->isRoot) { | 336 cert->isRoot) { |
340 trustflags |= CERTDB_TRUSTED_CA; | 337 trustflags |= CERTDB_TRUSTED_CA; |
341 /* is the slot a fortezza card? allow the user or | 338 /* is the slot a fortezza card? allow the user or |
342 * admin to turn on objectSigning, but don't turn | 339 * admin to turn on objectSigning, but don't turn |
343 * full trust on explicitly */ | 340 * full trust on explicitly */ |
344 if (PK11_DoesMechanism(slot,CKM_KEA_KEY_DERIVE)) { | 341 if (PK11_DoesMechanism(slot,CKM_KEA_KEY_DERIVE)) { |
345 trust->objectSigningFlags |= CERTDB_VALID_CA; | 342 trust->objectSigningFlags |= CERTDB_VALID_CA; |
346 isFortezzaRootCA = PR_TRUE; | |
347 } | 343 } |
348 } | 344 } |
349 if ((type & NS_CERT_TYPE_SSL_CA) == NS_CERT_TYPE_SSL_CA) { | 345 if ((type & NS_CERT_TYPE_SSL_CA) == NS_CERT_TYPE_SSL_CA) { |
350 trust->sslFlags |= trustflags; | 346 trust->sslFlags |= trustflags; |
351 } | 347 } |
352 if ((type & NS_CERT_TYPE_EMAIL_CA) == NS_CERT_TYPE_EMAIL_CA) { | 348 if ((type & NS_CERT_TYPE_EMAIL_CA) == NS_CERT_TYPE_EMAIL_CA) { |
353 trust->emailFlags |= trustflags; | 349 trust->emailFlags |= trustflags; |
354 } | 350 } |
355 if ((type & NS_CERT_TYPE_OBJECT_SIGNING_CA) | 351 if ((type & NS_CERT_TYPE_OBJECT_SIGNING_CA) |
356 == NS_CERT_TYPE_OBJECT_SIGNING_CA) { | 352 == NS_CERT_TYPE_OBJECT_SIGNING_CA) { |
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
975 c->object.cryptoContext = NULL; | 971 c->object.cryptoContext = NULL; |
976 cert->istemp = PR_FALSE; | 972 cert->istemp = PR_FALSE; |
977 cert->isperm = PR_TRUE; | 973 cert->isperm = PR_TRUE; |
978 } | 974 } |
979 | 975 |
980 /* add the new instance to the cert, force an update of the | 976 /* add the new instance to the cert, force an update of the |
981 * CERTCertificate, and finish | 977 * CERTCertificate, and finish |
982 */ | 978 */ |
983 nssPKIObject_AddInstance(&c->object, certobj); | 979 nssPKIObject_AddInstance(&c->object, certobj); |
984 /* nssTrustDomain_AddCertsToCache may release a reference to 'c' and | 980 /* nssTrustDomain_AddCertsToCache may release a reference to 'c' and |
985 * replace 'c' by a different value. So we add a reference to 'c' to | 981 * replace 'c' with a different value. So we add a reference to 'c' to |
986 * prevent 'c' from being destroyed. */ | 982 * prevent 'c' from being destroyed. */ |
987 nssCertificate_AddRef(c); | 983 nssCertificate_AddRef(c); |
988 nssTrustDomain_AddCertsToCache(STAN_GetDefaultTrustDomain(), &c, 1); | 984 nssTrustDomain_AddCertsToCache(STAN_GetDefaultTrustDomain(), &c, 1); |
989 /* XXX should we pass the original value of 'c' to | |
990 * STAN_ForceCERTCertificateUpdate? */ | |
991 (void)STAN_ForceCERTCertificateUpdate(c); | 985 (void)STAN_ForceCERTCertificateUpdate(c); |
992 nssCertificate_Destroy(c); | 986 nssCertificate_Destroy(c); |
993 SECITEM_FreeItem(keyID,PR_TRUE); | 987 SECITEM_FreeItem(keyID,PR_TRUE); |
994 return SECSuccess; | 988 return SECSuccess; |
995 loser: | 989 loser: |
996 CERT_MapStanError(); | 990 CERT_MapStanError(); |
997 SECITEM_FreeItem(keyID,PR_TRUE); | 991 SECITEM_FreeItem(keyID,PR_TRUE); |
998 if (PORT_GetError() != SEC_ERROR_TOKEN_NOT_LOGGED_IN) { | 992 if (PORT_GetError() != SEC_ERROR_TOKEN_NOT_LOGGED_IN) { |
999 PORT_SetError(SEC_ERROR_ADDING_CERT); | 993 PORT_SetError(SEC_ERROR_ADDING_CERT); |
1000 } | 994 } |
(...skipping 1147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2148 return PK11_FindCertFromDERCertItem(slot, &cert->derCert, wincx); | 2142 return PK11_FindCertFromDERCertItem(slot, &cert->derCert, wincx); |
2149 } | 2143 } |
2150 | 2144 |
2151 CERTCertificate * | 2145 CERTCertificate * |
2152 PK11_FindCertFromDERCertItem(PK11SlotInfo *slot, const SECItem *inDerCert, | 2146 PK11_FindCertFromDERCertItem(PK11SlotInfo *slot, const SECItem *inDerCert, |
2153 void *wincx) | 2147 void *wincx) |
2154 | 2148 |
2155 { | 2149 { |
2156 NSSDER derCert; | 2150 NSSDER derCert; |
2157 NSSToken *tok; | 2151 NSSToken *tok; |
2158 NSSTrustDomain *td = STAN_GetDefaultTrustDomain(); | |
2159 nssCryptokiObject *co = NULL; | 2152 nssCryptokiObject *co = NULL; |
2160 SECStatus rv; | 2153 SECStatus rv; |
2161 | 2154 |
2162 tok = PK11Slot_GetNSSToken(slot); | 2155 tok = PK11Slot_GetNSSToken(slot); |
2163 NSSITEM_FROM_SECITEM(&derCert, inDerCert); | 2156 NSSITEM_FROM_SECITEM(&derCert, inDerCert); |
2164 rv = pk11_AuthenticateUnfriendly(slot, PR_TRUE, wincx); | 2157 rv = pk11_AuthenticateUnfriendly(slot, PR_TRUE, wincx); |
2165 if (rv != SECSuccess) { | 2158 if (rv != SECSuccess) { |
2166 PK11_FreeSlot(slot); | 2159 PK11_FreeSlot(slot); |
2167 return NULL; | 2160 return NULL; |
2168 } | 2161 } |
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2682 } | 2675 } |
2683 if (!found) { | 2676 if (!found) { |
2684 PK11_FreeSlotList(slotList); | 2677 PK11_FreeSlotList(slotList); |
2685 PORT_SetError(SEC_ERROR_NO_TOKEN); | 2678 PORT_SetError(SEC_ERROR_NO_TOKEN); |
2686 slotList = NULL; | 2679 slotList = NULL; |
2687 } | 2680 } |
2688 | 2681 |
2689 nssCryptokiObjectArray_Destroy(instances); | 2682 nssCryptokiObjectArray_Destroy(instances); |
2690 return slotList; | 2683 return slotList; |
2691 } | 2684 } |
| 2685 |
| 2686 /* |
| 2687 * Using __PK11_SetCertificateNickname is *DANGEROUS*. |
| 2688 * |
| 2689 * The API will update the NSS database, but it *will NOT* update the in-memory
data. |
| 2690 * As a result, after calling this API, there will be INCONSISTENCY between |
| 2691 * in-memory data and the database. |
| 2692 * |
| 2693 * Use of the API should be limited to short-lived tools, which will exit immedi
ately |
| 2694 * after using this API. |
| 2695 * |
| 2696 * If you ignore this warning, your process is TAINTED and will most likely misb
ehave. |
| 2697 */ |
| 2698 SECStatus |
| 2699 __PK11_SetCertificateNickname(CERTCertificate *cert, const char *nickname) |
| 2700 { |
| 2701 /* Can't set nickname of temp cert. */ |
| 2702 if (!cert->slot || cert->pkcs11ID == CK_INVALID_HANDLE) { |
| 2703 return SEC_ERROR_INVALID_ARGS; |
| 2704 } |
| 2705 return PK11_SetObjectNickname(cert->slot, cert->pkcs11ID, nickname); |
| 2706 } |
OLD | NEW |