| 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 #include "cryptohi.h" | 4 #include "cryptohi.h" |
| 5 #include "keyhi.h" | 5 #include "keyhi.h" |
| 6 #include "secoid.h" | 6 #include "secoid.h" |
| 7 #include "secitem.h" | 7 #include "secitem.h" |
| 8 #include "secder.h" | 8 #include "secder.h" |
| 9 #include "base64.h" | 9 #include "base64.h" |
| 10 #include "secasn1.h" | 10 #include "secasn1.h" |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 } | 437 } |
| 438 return seckey_UpdateCertPQGChain(subjectCert,0); | 438 return seckey_UpdateCertPQGChain(subjectCert,0); |
| 439 } | 439 } |
| 440 | 440 |
| 441 | 441 |
| 442 /* Decode the DSA PQG parameters. The params could be stored in two | 442 /* Decode the DSA PQG parameters. The params could be stored in two |
| 443 * possible formats, the old fortezza-only wrapped format or | 443 * possible formats, the old fortezza-only wrapped format or |
| 444 * the normal standard format. Store the decoded parameters in | 444 * the normal standard format. Store the decoded parameters in |
| 445 * a V3 certificate data structure. */ | 445 * a V3 certificate data structure. */ |
| 446 | 446 |
| 447 SECStatus | 447 static SECStatus |
| 448 SECKEY_DSADecodePQG(PLArenaPool *arena, SECKEYPublicKey *pubk, SECItem *params)
{ | 448 seckey_DSADecodePQG(PLArenaPool *arena, SECKEYPublicKey *pubk, |
| 449 const SECItem *params) { |
| 449 SECStatus rv; | 450 SECStatus rv; |
| 450 SECItem newparams; | 451 SECItem newparams; |
| 451 | 452 |
| 452 if (params == NULL) return SECFailure; | 453 if (params == NULL) return SECFailure; |
| 453 | 454 |
| 454 if (params->data == NULL) return SECFailure; | 455 if (params->data == NULL) return SECFailure; |
| 455 | 456 |
| 456 PORT_Assert(arena); | 457 PORT_Assert(arena); |
| 457 | 458 |
| 458 /* make a copy of the data into the arena so QuickDER output is valid */ | 459 /* make a copy of the data into the arena so QuickDER output is valid */ |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 keyType = rsaKey; | 533 keyType = rsaKey; |
| 533 break; | 534 break; |
| 534 default: | 535 default: |
| 535 keyType = nullKey; | 536 keyType = nullKey; |
| 536 } | 537 } |
| 537 return keyType; | 538 return keyType; |
| 538 } | 539 } |
| 539 | 540 |
| 540 /* Function used to determine what kind of cert we are dealing with. */ | 541 /* Function used to determine what kind of cert we are dealing with. */ |
| 541 KeyType | 542 KeyType |
| 542 CERT_GetCertKeyType (CERTSubjectPublicKeyInfo *spki) | 543 CERT_GetCertKeyType (const CERTSubjectPublicKeyInfo *spki) |
| 543 { | 544 { |
| 544 return seckey_GetKeyType(SECOID_GetAlgorithmTag(&spki->algorithm)); | 545 return seckey_GetKeyType(SECOID_GetAlgorithmTag(&spki->algorithm)); |
| 545 } | 546 } |
| 546 | 547 |
| 547 static SECKEYPublicKey * | 548 static SECKEYPublicKey * |
| 548 seckey_ExtractPublicKey(CERTSubjectPublicKeyInfo *spki) | 549 seckey_ExtractPublicKey(const CERTSubjectPublicKeyInfo *spki) |
| 549 { | 550 { |
| 550 SECKEYPublicKey *pubk; | 551 SECKEYPublicKey *pubk; |
| 551 SECItem os, newOs, newParms; | 552 SECItem os, newOs, newParms; |
| 552 SECStatus rv; | 553 SECStatus rv; |
| 553 PLArenaPool *arena; | 554 PLArenaPool *arena; |
| 554 SECOidTag tag; | 555 SECOidTag tag; |
| 555 | 556 |
| 556 arena = PORT_NewArena (DER_DEFAULT_CHUNKSIZE); | 557 arena = PORT_NewArena (DER_DEFAULT_CHUNKSIZE); |
| 557 if (arena == NULL) | 558 if (arena == NULL) |
| 558 return NULL; | 559 return NULL; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 587 if (rv == SECSuccess) | 588 if (rv == SECSuccess) |
| 588 return pubk; | 589 return pubk; |
| 589 break; | 590 break; |
| 590 case SEC_OID_ANSIX9_DSA_SIGNATURE: | 591 case SEC_OID_ANSIX9_DSA_SIGNATURE: |
| 591 case SEC_OID_SDN702_DSA_SIGNATURE: | 592 case SEC_OID_SDN702_DSA_SIGNATURE: |
| 592 pubk->keyType = dsaKey; | 593 pubk->keyType = dsaKey; |
| 593 prepare_dsa_pub_key_for_asn1(pubk); | 594 prepare_dsa_pub_key_for_asn1(pubk); |
| 594 rv = SEC_QuickDERDecodeItem(arena, pubk, SECKEY_DSAPublicKeyTemplate, &n
ewOs); | 595 rv = SEC_QuickDERDecodeItem(arena, pubk, SECKEY_DSAPublicKeyTemplate, &n
ewOs); |
| 595 if (rv != SECSuccess) break; | 596 if (rv != SECSuccess) break; |
| 596 | 597 |
| 597 rv = SECKEY_DSADecodePQG(arena, pubk, | 598 rv = seckey_DSADecodePQG(arena, pubk, |
| 598 &spki->algorithm.parameters); | 599 &spki->algorithm.parameters); |
| 599 | 600 |
| 600 if (rv == SECSuccess) return pubk; | 601 if (rv == SECSuccess) return pubk; |
| 601 break; | 602 break; |
| 602 case SEC_OID_X942_DIFFIE_HELMAN_KEY: | 603 case SEC_OID_X942_DIFFIE_HELMAN_KEY: |
| 603 pubk->keyType = dhKey; | 604 pubk->keyType = dhKey; |
| 604 prepare_dh_pub_key_for_asn1(pubk); | 605 prepare_dh_pub_key_for_asn1(pubk); |
| 605 rv = SEC_QuickDERDecodeItem(arena, pubk, SECKEY_DHPublicKeyTemplate, &ne
wOs); | 606 rv = SEC_QuickDERDecodeItem(arena, pubk, SECKEY_DHPublicKeyTemplate, &ne
wOs); |
| 606 if (rv != SECSuccess) break; | 607 if (rv != SECSuccess) break; |
| 607 | 608 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 637 break; | 638 break; |
| 638 } | 639 } |
| 639 | 640 |
| 640 SECKEY_DestroyPublicKey (pubk); | 641 SECKEY_DestroyPublicKey (pubk); |
| 641 return NULL; | 642 return NULL; |
| 642 } | 643 } |
| 643 | 644 |
| 644 | 645 |
| 645 /* required for JSS */ | 646 /* required for JSS */ |
| 646 SECKEYPublicKey * | 647 SECKEYPublicKey * |
| 647 SECKEY_ExtractPublicKey(CERTSubjectPublicKeyInfo *spki) | 648 SECKEY_ExtractPublicKey(const CERTSubjectPublicKeyInfo *spki) |
| 648 { | 649 { |
| 649 return seckey_ExtractPublicKey(spki); | 650 return seckey_ExtractPublicKey(spki); |
| 650 } | 651 } |
| 651 | 652 |
| 652 SECKEYPublicKey * | 653 SECKEYPublicKey * |
| 653 CERT_ExtractPublicKey(CERTCertificate *cert) | 654 CERT_ExtractPublicKey(CERTCertificate *cert) |
| 654 { | 655 { |
| 655 SECStatus rv; | 656 SECStatus rv; |
| 656 | 657 |
| 657 if (!cert) { | 658 if (!cert) { |
| (...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1337 if (spki && spki->arena) { | 1338 if (spki && spki->arena) { |
| 1338 PORT_FreeArena(spki->arena, PR_FALSE); | 1339 PORT_FreeArena(spki->arena, PR_FALSE); |
| 1339 } | 1340 } |
| 1340 } | 1341 } |
| 1341 | 1342 |
| 1342 /* | 1343 /* |
| 1343 * this only works for RSA keys... need to do something | 1344 * this only works for RSA keys... need to do something |
| 1344 * similiar to CERT_ExtractPublicKey for other key times. | 1345 * similiar to CERT_ExtractPublicKey for other key times. |
| 1345 */ | 1346 */ |
| 1346 SECKEYPublicKey * | 1347 SECKEYPublicKey * |
| 1347 SECKEY_DecodeDERPublicKey(SECItem *pubkder) | 1348 SECKEY_DecodeDERPublicKey(const SECItem *pubkder) |
| 1348 { | 1349 { |
| 1349 PLArenaPool *arena; | 1350 PLArenaPool *arena; |
| 1350 SECKEYPublicKey *pubk; | 1351 SECKEYPublicKey *pubk; |
| 1351 SECStatus rv; | 1352 SECStatus rv; |
| 1352 SECItem newPubkder; | 1353 SECItem newPubkder; |
| 1353 | 1354 |
| 1354 arena = PORT_NewArena (DER_DEFAULT_CHUNKSIZE); | 1355 arena = PORT_NewArena (DER_DEFAULT_CHUNKSIZE); |
| 1355 if (arena == NULL) { | 1356 if (arena == NULL) { |
| 1356 PORT_SetError (SEC_ERROR_NO_MEMORY); | 1357 PORT_SetError (SEC_ERROR_NO_MEMORY); |
| 1357 return NULL; | 1358 return NULL; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1378 } | 1379 } |
| 1379 | 1380 |
| 1380 PORT_FreeArena (arena, PR_FALSE); | 1381 PORT_FreeArena (arena, PR_FALSE); |
| 1381 return NULL; | 1382 return NULL; |
| 1382 } | 1383 } |
| 1383 | 1384 |
| 1384 /* | 1385 /* |
| 1385 * Decode a base64 ascii encoded DER encoded public key. | 1386 * Decode a base64 ascii encoded DER encoded public key. |
| 1386 */ | 1387 */ |
| 1387 SECKEYPublicKey * | 1388 SECKEYPublicKey * |
| 1388 SECKEY_ConvertAndDecodePublicKey(char *pubkstr) | 1389 SECKEY_ConvertAndDecodePublicKey(const char *pubkstr) |
| 1389 { | 1390 { |
| 1390 SECKEYPublicKey *pubk; | 1391 SECKEYPublicKey *pubk; |
| 1391 SECStatus rv; | 1392 SECStatus rv; |
| 1392 SECItem der; | 1393 SECItem der; |
| 1393 | 1394 |
| 1394 rv = ATOB_ConvertAsciiToItem (&der, pubkstr); | 1395 rv = ATOB_ConvertAsciiToItem (&der, pubkstr); |
| 1395 if (rv != SECSuccess) | 1396 if (rv != SECSuccess) |
| 1396 return NULL; | 1397 return NULL; |
| 1397 | 1398 |
| 1398 pubk = SECKEY_DecodeDERPublicKey (&der); | 1399 pubk = SECKEY_DecodeDERPublicKey (&der); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1418 CERT_SubjectPublicKeyInfoTemplate); | 1419 CERT_SubjectPublicKeyInfoTemplate); |
| 1419 | 1420 |
| 1420 SECKEY_DestroySubjectPublicKeyInfo(spki); | 1421 SECKEY_DestroySubjectPublicKeyInfo(spki); |
| 1421 | 1422 |
| 1422 finish: | 1423 finish: |
| 1423 return spkiDER; | 1424 return spkiDER; |
| 1424 } | 1425 } |
| 1425 | 1426 |
| 1426 | 1427 |
| 1427 CERTSubjectPublicKeyInfo * | 1428 CERTSubjectPublicKeyInfo * |
| 1428 SECKEY_DecodeDERSubjectPublicKeyInfo(SECItem *spkider) | 1429 SECKEY_DecodeDERSubjectPublicKeyInfo(const SECItem *spkider) |
| 1429 { | 1430 { |
| 1430 PLArenaPool *arena; | 1431 PLArenaPool *arena; |
| 1431 CERTSubjectPublicKeyInfo *spki; | 1432 CERTSubjectPublicKeyInfo *spki; |
| 1432 SECStatus rv; | 1433 SECStatus rv; |
| 1433 SECItem newSpkider; | 1434 SECItem newSpkider; |
| 1434 | 1435 |
| 1435 arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE); | 1436 arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE); |
| 1436 if (arena == NULL) { | 1437 if (arena == NULL) { |
| 1437 PORT_SetError(SEC_ERROR_NO_MEMORY); | 1438 PORT_SetError(SEC_ERROR_NO_MEMORY); |
| 1438 return NULL; | 1439 return NULL; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1457 } | 1458 } |
| 1458 | 1459 |
| 1459 PORT_FreeArena(arena, PR_FALSE); | 1460 PORT_FreeArena(arena, PR_FALSE); |
| 1460 return NULL; | 1461 return NULL; |
| 1461 } | 1462 } |
| 1462 | 1463 |
| 1463 /* | 1464 /* |
| 1464 * Decode a base64 ascii encoded DER encoded subject public key info. | 1465 * Decode a base64 ascii encoded DER encoded subject public key info. |
| 1465 */ | 1466 */ |
| 1466 CERTSubjectPublicKeyInfo * | 1467 CERTSubjectPublicKeyInfo * |
| 1467 SECKEY_ConvertAndDecodeSubjectPublicKeyInfo(char *spkistr) | 1468 SECKEY_ConvertAndDecodeSubjectPublicKeyInfo(const char *spkistr) |
| 1468 { | 1469 { |
| 1469 CERTSubjectPublicKeyInfo *spki; | 1470 CERTSubjectPublicKeyInfo *spki; |
| 1470 SECStatus rv; | 1471 SECStatus rv; |
| 1471 SECItem der; | 1472 SECItem der; |
| 1472 | 1473 |
| 1473 rv = ATOB_ConvertAsciiToItem(&der, spkistr); | 1474 rv = ATOB_ConvertAsciiToItem(&der, spkistr); |
| 1474 if (rv != SECSuccess) | 1475 if (rv != SECSuccess) |
| 1475 return NULL; | 1476 return NULL; |
| 1476 | 1477 |
| 1477 spki = SECKEY_DecodeDERSubjectPublicKeyInfo(&der); | 1478 spki = SECKEY_DecodeDERSubjectPublicKeyInfo(&der); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1640 if(freeit == PR_TRUE) { | 1641 if(freeit == PR_TRUE) { |
| 1641 PORT_Free(epki); | 1642 PORT_Free(epki); |
| 1642 } | 1643 } |
| 1643 } | 1644 } |
| 1644 } | 1645 } |
| 1645 } | 1646 } |
| 1646 | 1647 |
| 1647 SECStatus | 1648 SECStatus |
| 1648 SECKEY_CopyPrivateKeyInfo(PLArenaPool *poolp, | 1649 SECKEY_CopyPrivateKeyInfo(PLArenaPool *poolp, |
| 1649 SECKEYPrivateKeyInfo *to, | 1650 SECKEYPrivateKeyInfo *to, |
| 1650 » » » SECKEYPrivateKeyInfo *from) | 1651 » » » const SECKEYPrivateKeyInfo *from) |
| 1651 { | 1652 { |
| 1652 SECStatus rv = SECFailure; | 1653 SECStatus rv = SECFailure; |
| 1653 | 1654 |
| 1654 if((to == NULL) || (from == NULL)) { | 1655 if((to == NULL) || (from == NULL)) { |
| 1655 return SECFailure; | 1656 return SECFailure; |
| 1656 } | 1657 } |
| 1657 | 1658 |
| 1658 rv = SECOID_CopyAlgorithmID(poolp, &to->algorithm, &from->algorithm); | 1659 rv = SECOID_CopyAlgorithmID(poolp, &to->algorithm, &from->algorithm); |
| 1659 if(rv != SECSuccess) { | 1660 if(rv != SECSuccess) { |
| 1660 return SECFailure; | 1661 return SECFailure; |
| 1661 } | 1662 } |
| 1662 rv = SECITEM_CopyItem(poolp, &to->privateKey, &from->privateKey); | 1663 rv = SECITEM_CopyItem(poolp, &to->privateKey, &from->privateKey); |
| 1663 if(rv != SECSuccess) { | 1664 if(rv != SECSuccess) { |
| 1664 return SECFailure; | 1665 return SECFailure; |
| 1665 } | 1666 } |
| 1666 rv = SECITEM_CopyItem(poolp, &to->version, &from->version); | 1667 rv = SECITEM_CopyItem(poolp, &to->version, &from->version); |
| 1667 | 1668 |
| 1668 return rv; | 1669 return rv; |
| 1669 } | 1670 } |
| 1670 | 1671 |
| 1671 SECStatus | 1672 SECStatus |
| 1672 SECKEY_CopyEncryptedPrivateKeyInfo(PLArenaPool *poolp, | 1673 SECKEY_CopyEncryptedPrivateKeyInfo(PLArenaPool *poolp, |
| 1673 SECKEYEncryptedPrivateKeyInfo *to, | 1674 SECKEYEncryptedPrivateKeyInfo *to, |
| 1674 » » » » SECKEYEncryptedPrivateKeyInfo *from) | 1675 » » » » const SECKEYEncryptedPrivateKeyInfo *from) |
| 1675 { | 1676 { |
| 1676 SECStatus rv = SECFailure; | 1677 SECStatus rv = SECFailure; |
| 1677 | 1678 |
| 1678 if((to == NULL) || (from == NULL)) { | 1679 if((to == NULL) || (from == NULL)) { |
| 1679 return SECFailure; | 1680 return SECFailure; |
| 1680 } | 1681 } |
| 1681 | 1682 |
| 1682 rv = SECOID_CopyAlgorithmID(poolp, &to->algorithm, &from->algorithm); | 1683 rv = SECOID_CopyAlgorithmID(poolp, &to->algorithm, &from->algorithm); |
| 1683 if(rv != SECSuccess) { | 1684 if(rv != SECSuccess) { |
| 1684 return SECFailure; | 1685 return SECFailure; |
| 1685 } | 1686 } |
| 1686 rv = SECITEM_CopyItem(poolp, &to->encryptedData, &from->encryptedData); | 1687 rv = SECITEM_CopyItem(poolp, &to->encryptedData, &from->encryptedData); |
| 1687 | 1688 |
| 1688 return rv; | 1689 return rv; |
| 1689 } | 1690 } |
| 1690 | 1691 |
| 1691 KeyType | 1692 KeyType |
| 1692 SECKEY_GetPrivateKeyType(SECKEYPrivateKey *privKey) | 1693 SECKEY_GetPrivateKeyType(const SECKEYPrivateKey *privKey) |
| 1693 { | 1694 { |
| 1694 return privKey->keyType; | 1695 return privKey->keyType; |
| 1695 } | 1696 } |
| 1696 | 1697 |
| 1697 KeyType | 1698 KeyType |
| 1698 SECKEY_GetPublicKeyType(SECKEYPublicKey *pubKey) | 1699 SECKEY_GetPublicKeyType(const SECKEYPublicKey *pubKey) |
| 1699 { | 1700 { |
| 1700 return pubKey->keyType; | 1701 return pubKey->keyType; |
| 1701 } | 1702 } |
| 1702 | 1703 |
| 1703 SECKEYPublicKey* | 1704 SECKEYPublicKey* |
| 1704 SECKEY_ImportDERPublicKey(SECItem *derKey, CK_KEY_TYPE type) | 1705 SECKEY_ImportDERPublicKey(const SECItem *derKey, CK_KEY_TYPE type) |
| 1705 { | 1706 { |
| 1706 SECKEYPublicKey *pubk = NULL; | 1707 SECKEYPublicKey *pubk = NULL; |
| 1707 SECStatus rv = SECFailure; | 1708 SECStatus rv = SECFailure; |
| 1708 SECItem newDerKey; | 1709 SECItem newDerKey; |
| 1709 PLArenaPool *arena = NULL; | 1710 PLArenaPool *arena = NULL; |
| 1710 | 1711 |
| 1711 if (!derKey) { | 1712 if (!derKey) { |
| 1712 return NULL; | 1713 return NULL; |
| 1713 } | 1714 } |
| 1714 | 1715 |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1928 { | 1929 { |
| 1929 SECStatus rv = SECFailure; | 1930 SECStatus rv = SECFailure; |
| 1930 if (key && key->pkcs11Slot && key->pkcs11ID) { | 1931 if (key && key->pkcs11Slot && key->pkcs11ID) { |
| 1931 key->staticflags |= SECKEY_Attributes_Cached; | 1932 key->staticflags |= SECKEY_Attributes_Cached; |
| 1932 SECKEY_CacheAttribute(key, CKA_PRIVATE); | 1933 SECKEY_CacheAttribute(key, CKA_PRIVATE); |
| 1933 SECKEY_CacheAttribute(key, CKA_ALWAYS_AUTHENTICATE); | 1934 SECKEY_CacheAttribute(key, CKA_ALWAYS_AUTHENTICATE); |
| 1934 rv = SECSuccess; | 1935 rv = SECSuccess; |
| 1935 } | 1936 } |
| 1936 return rv; | 1937 return rv; |
| 1937 } | 1938 } |
| OLD | NEW |