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 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 cert->slot = PK11_ReferenceSlot(slot); | 317 cert->slot = PK11_ReferenceSlot(slot); |
318 cert->pkcs11ID = certID; | 318 cert->pkcs11ID = certID; |
319 cert->ownSlot = PR_TRUE; | 319 cert->ownSlot = PR_TRUE; |
320 cert->series = slot->series; | 320 cert->series = slot->series; |
321 } | 321 } |
322 | 322 |
323 trust = (CERTCertTrust*)PORT_ArenaAlloc(cert->arena, sizeof(CERTCertTrust)); | 323 trust = (CERTCertTrust*)PORT_ArenaAlloc(cert->arena, sizeof(CERTCertTrust)); |
324 if (trust == NULL) | 324 if (trust == NULL) |
325 goto loser; | 325 goto loser; |
326 PORT_Memset(trust,0, sizeof(CERTCertTrust)); | 326 PORT_Memset(trust,0, sizeof(CERTCertTrust)); |
327 cert->trust = trust; | |
328 | 327 |
329 if(! pk11_HandleTrustObject(slot, cert, trust) ) { | 328 if(! pk11_HandleTrustObject(slot, cert, trust) ) { |
330 unsigned int type; | 329 unsigned int type; |
331 | 330 |
332 /* build some cert trust flags */ | 331 /* build some cert trust flags */ |
333 if (CERT_IsCACert(cert, &type)) { | 332 if (CERT_IsCACert(cert, &type)) { |
334 unsigned int trustflags = CERTDB_VALID_CA; | 333 unsigned int trustflags = CERTDB_VALID_CA; |
335 | 334 |
336 /* Allow PKCS #11 modules to give us trusted CA's. We only accept | 335 /* Allow PKCS #11 modules to give us trusted CA's. We only accept |
337 * valid CA's which are self-signed here. They must have an object | 336 * valid CA's which are self-signed here. They must have an object |
(...skipping 20 matching lines...) Expand all Loading... |
358 trust->objectSigningFlags |= trustflags; | 357 trust->objectSigningFlags |= trustflags; |
359 } | 358 } |
360 } | 359 } |
361 } | 360 } |
362 | 361 |
363 if (PK11_IsUserCert(slot,cert,certID)) { | 362 if (PK11_IsUserCert(slot,cert,certID)) { |
364 trust->sslFlags |= CERTDB_USER; | 363 trust->sslFlags |= CERTDB_USER; |
365 trust->emailFlags |= CERTDB_USER; | 364 trust->emailFlags |= CERTDB_USER; |
366 /* trust->objectSigningFlags |= CERTDB_USER; */ | 365 /* trust->objectSigningFlags |= CERTDB_USER; */ |
367 } | 366 } |
| 367 CERT_LockCertTrust(cert); |
| 368 cert->trust = trust; |
| 369 CERT_UnlockCertTrust(cert); |
| 370 |
368 return cert; | 371 return cert; |
369 | 372 |
370 loser: | 373 loser: |
371 if (nickname) | 374 if (nickname) |
372 PORT_Free(nickname); | 375 PORT_Free(nickname); |
373 if (cert) | 376 if (cert) |
374 CERT_DestroyCertificate(cert); | 377 CERT_DestroyCertificate(cert); |
375 return NULL; | 378 return NULL; |
376 } | 379 } |
377 | 380 |
(...skipping 1025 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1403 * this is the new version for NSS SMIME code | 1406 * this is the new version for NSS SMIME code |
1404 * this stuff should REALLY be in the SMIME code, but some things in here are no
t public | 1407 * this stuff should REALLY be in the SMIME code, but some things in here are no
t public |
1405 * (they should be!) | 1408 * (they should be!) |
1406 */ | 1409 */ |
1407 static CERTCertificate * | 1410 static CERTCertificate * |
1408 pk11_FindCertObjectByRecipientNew(PK11SlotInfo *slot, NSSCMSRecipient **recipien
tlist, int *rlIndex, void *pwarg) | 1411 pk11_FindCertObjectByRecipientNew(PK11SlotInfo *slot, NSSCMSRecipient **recipien
tlist, int *rlIndex, void *pwarg) |
1409 { | 1412 { |
1410 NSSCMSRecipient *ri = NULL; | 1413 NSSCMSRecipient *ri = NULL; |
1411 int i; | 1414 int i; |
1412 PRBool tokenRescanDone = PR_FALSE; | 1415 PRBool tokenRescanDone = PR_FALSE; |
| 1416 CERTCertTrust trust; |
1413 | 1417 |
1414 for (i=0; (ri = recipientlist[i]) != NULL; i++) { | 1418 for (i=0; (ri = recipientlist[i]) != NULL; i++) { |
1415 CERTCertificate *cert = NULL; | 1419 CERTCertificate *cert = NULL; |
1416 if (ri->kind == RLSubjKeyID) { | 1420 if (ri->kind == RLSubjKeyID) { |
1417 SECItem *derCert = cert_FindDERCertBySubjectKeyID(ri->id.subjectKeyI
D); | 1421 SECItem *derCert = cert_FindDERCertBySubjectKeyID(ri->id.subjectKeyI
D); |
1418 if (!derCert && !tokenRescanDone) { | 1422 if (!derCert && !tokenRescanDone) { |
1419 /* | 1423 /* |
1420 * We didn't find the cert by its key ID. If we have slots | 1424 * We didn't find the cert by its key ID. If we have slots |
1421 * with removable tokens, a failure from | 1425 * with removable tokens, a failure from |
1422 * cert_FindDERCertBySubjectKeyID doesn't necessarily imply | 1426 * cert_FindDERCertBySubjectKeyID doesn't necessarily imply |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1483 if (derCert) { | 1487 if (derCert) { |
1484 cert = PK11_FindCertFromDERCertItem(slot, derCert, pwarg); | 1488 cert = PK11_FindCertFromDERCertItem(slot, derCert, pwarg); |
1485 SECITEM_FreeItem(derCert, PR_TRUE); | 1489 SECITEM_FreeItem(derCert, PR_TRUE); |
1486 } | 1490 } |
1487 } else { | 1491 } else { |
1488 cert = PK11_FindCertByIssuerAndSNOnToken(slot, ri->id.issuerAndSN, | 1492 cert = PK11_FindCertByIssuerAndSNOnToken(slot, ri->id.issuerAndSN, |
1489 pwarg); | 1493 pwarg); |
1490 } | 1494 } |
1491 if (cert) { | 1495 if (cert) { |
1492 /* this isn't our cert */ | 1496 /* this isn't our cert */ |
1493 » if ((cert->trust == NULL) || | 1497 » if (CERT_GetCertTrust(cert, &trust) != SECSuccess || |
1494 »» ((cert->trust->emailFlags & CERTDB_USER) != CERTDB_USER)) { | 1498 »» ((trust.emailFlags & CERTDB_USER) != CERTDB_USER)) { |
1495 CERT_DestroyCertificate(cert); | 1499 CERT_DestroyCertificate(cert); |
1496 continue; | 1500 continue; |
1497 } | 1501 } |
1498 ri->slot = PK11_ReferenceSlot(slot); | 1502 ri->slot = PK11_ReferenceSlot(slot); |
1499 *rlIndex = i; | 1503 *rlIndex = i; |
1500 return cert; | 1504 return cert; |
1501 } | 1505 } |
1502 } | 1506 } |
1503 *rlIndex = -1; | 1507 *rlIndex = -1; |
1504 return NULL; | 1508 return NULL; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1543 /* | 1547 /* |
1544 * We're looking for a cert which we have the private key for that's on the | 1548 * We're looking for a cert which we have the private key for that's on the |
1545 * list of recipients. This searches one slot. | 1549 * list of recipients. This searches one slot. |
1546 */ | 1550 */ |
1547 static CERTCertificate * | 1551 static CERTCertificate * |
1548 pk11_FindCertObjectByRecipient(PK11SlotInfo *slot, | 1552 pk11_FindCertObjectByRecipient(PK11SlotInfo *slot, |
1549 SEC_PKCS7RecipientInfo **recipientArray, | 1553 SEC_PKCS7RecipientInfo **recipientArray, |
1550 SEC_PKCS7RecipientInfo **rip, void *pwarg) | 1554 SEC_PKCS7RecipientInfo **rip, void *pwarg) |
1551 { | 1555 { |
1552 SEC_PKCS7RecipientInfo *ri = NULL; | 1556 SEC_PKCS7RecipientInfo *ri = NULL; |
| 1557 CERTCertTrust trust; |
1553 int i; | 1558 int i; |
1554 | 1559 |
1555 for (i=0; (ri = recipientArray[i]) != NULL; i++) { | 1560 for (i=0; (ri = recipientArray[i]) != NULL; i++) { |
1556 CERTCertificate *cert; | 1561 CERTCertificate *cert; |
1557 | 1562 |
1558 cert = PK11_FindCertByIssuerAndSNOnToken(slot, ri->issuerAndSN, | 1563 cert = PK11_FindCertByIssuerAndSNOnToken(slot, ri->issuerAndSN, |
1559 pwarg); | 1564 pwarg); |
1560 if (cert) { | 1565 if (cert) { |
1561 /* this isn't our cert */ | 1566 /* this isn't our cert */ |
1562 » if ((cert->trust == NULL) || | 1567 » if (CERT_GetCertTrust(cert, &trust) != SECSuccess || |
1563 »» ((cert->trust->emailFlags & CERTDB_USER) != CERTDB_USER)) { | 1568 »» ((trust.emailFlags & CERTDB_USER) != CERTDB_USER)) { |
1564 CERT_DestroyCertificate(cert); | 1569 CERT_DestroyCertificate(cert); |
1565 continue; | 1570 continue; |
1566 } | 1571 } |
1567 *rip = ri; | 1572 *rip = ri; |
1568 return cert; | 1573 return cert; |
1569 } | 1574 } |
1570 | 1575 |
1571 } | 1576 } |
1572 *rip = NULL; | 1577 *rip = NULL; |
1573 return NULL; | 1578 return NULL; |
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2253 | 2258 |
2254 /* not implemented */ | 2259 /* not implemented */ |
2255 return PR_FALSE; | 2260 return PR_FALSE; |
2256 } | 2261 } |
2257 | 2262 |
2258 PRBool | 2263 PRBool |
2259 PK11_FortezzaHasKEA(CERTCertificate *cert) | 2264 PK11_FortezzaHasKEA(CERTCertificate *cert) |
2260 { | 2265 { |
2261 /* look at the subject and see if it is a KEA for MISSI key */ | 2266 /* look at the subject and see if it is a KEA for MISSI key */ |
2262 SECOidData *oid; | 2267 SECOidData *oid; |
| 2268 CERTCertTrust trust; |
2263 | 2269 |
2264 if ((cert->trust == NULL) || | 2270 if (CERT_GetCertTrust(cert, &trust) != SECSuccess || |
2265 ((cert->trust->sslFlags & CERTDB_USER) != CERTDB_USER)) { | 2271 ((trust.sslFlags & CERTDB_USER) != CERTDB_USER)) { |
2266 return PR_FALSE; | 2272 return PR_FALSE; |
2267 } | 2273 } |
2268 | 2274 |
2269 oid = SECOID_FindOID(&cert->subjectPublicKeyInfo.algorithm.algorithm); | 2275 oid = SECOID_FindOID(&cert->subjectPublicKeyInfo.algorithm.algorithm); |
2270 if (!oid) { | 2276 if (!oid) { |
2271 return PR_FALSE; | 2277 return PR_FALSE; |
2272 } | 2278 } |
2273 | 2279 |
2274 return (PRBool)((oid->offset == SEC_OID_MISSI_KEA_DSS_OLD) || | 2280 return (PRBool)((oid->offset == SEC_OID_MISSI_KEA_DSS_OLD) || |
2275 (oid->offset == SEC_OID_MISSI_KEA_DSS) || | 2281 (oid->offset == SEC_OID_MISSI_KEA_DSS) || |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2669 } | 2675 } |
2670 if (!found) { | 2676 if (!found) { |
2671 PK11_FreeSlotList(slotList); | 2677 PK11_FreeSlotList(slotList); |
2672 PORT_SetError(SEC_ERROR_NO_TOKEN); | 2678 PORT_SetError(SEC_ERROR_NO_TOKEN); |
2673 slotList = NULL; | 2679 slotList = NULL; |
2674 } | 2680 } |
2675 | 2681 |
2676 nssCryptokiObjectArray_Destroy(instances); | 2682 nssCryptokiObjectArray_Destroy(instances); |
2677 return slotList; | 2683 return slotList; |
2678 } | 2684 } |
OLD | NEW |