| 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 object type indepentent functions. | 5 * This file manages object type indepentent functions. |
| 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 1559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1570 } | 1570 } |
| 1571 | 1571 |
| 1572 /* | 1572 /* |
| 1573 * Change an attribute on a raw object | 1573 * Change an attribute on a raw object |
| 1574 */ | 1574 */ |
| 1575 SECStatus | 1575 SECStatus |
| 1576 PK11_WriteRawAttribute(PK11ObjectType objType, void *objSpec, | 1576 PK11_WriteRawAttribute(PK11ObjectType objType, void *objSpec, |
| 1577 CK_ATTRIBUTE_TYPE attrType, SECItem *item) | 1577 CK_ATTRIBUTE_TYPE attrType, SECItem *item) |
| 1578 { | 1578 { |
| 1579 PK11SlotInfo *slot = NULL; | 1579 PK11SlotInfo *slot = NULL; |
| 1580 CK_OBJECT_HANDLE handle; | 1580 CK_OBJECT_HANDLE handle = 0; |
| 1581 CK_ATTRIBUTE setTemplate; | 1581 CK_ATTRIBUTE setTemplate; |
| 1582 CK_RV crv; | 1582 CK_RV crv; |
| 1583 CK_SESSION_HANDLE rwsession; | 1583 CK_SESSION_HANDLE rwsession; |
| 1584 | 1584 |
| 1585 switch (objType) { | 1585 switch (objType) { |
| 1586 case PK11_TypeGeneric: | 1586 case PK11_TypeGeneric: |
| 1587 slot = ((PK11GenericObject *)objSpec)->slot; | 1587 slot = ((PK11GenericObject *)objSpec)->slot; |
| 1588 handle = ((PK11GenericObject *)objSpec)->objectID; | 1588 handle = ((PK11GenericObject *)objSpec)->objectID; |
| 1589 break; | 1589 break; |
| 1590 case PK11_TypePrivKey: | 1590 case PK11_TypePrivKey: |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1623 } | 1623 } |
| 1624 return SECSuccess; | 1624 return SECSuccess; |
| 1625 } | 1625 } |
| 1626 | 1626 |
| 1627 | 1627 |
| 1628 SECStatus | 1628 SECStatus |
| 1629 PK11_ReadRawAttribute(PK11ObjectType objType, void *objSpec, | 1629 PK11_ReadRawAttribute(PK11ObjectType objType, void *objSpec, |
| 1630 CK_ATTRIBUTE_TYPE attrType, SECItem *item) | 1630 CK_ATTRIBUTE_TYPE attrType, SECItem *item) |
| 1631 { | 1631 { |
| 1632 PK11SlotInfo *slot = NULL; | 1632 PK11SlotInfo *slot = NULL; |
| 1633 CK_OBJECT_HANDLE handle; | 1633 CK_OBJECT_HANDLE handle = 0; |
| 1634 | 1634 |
| 1635 switch (objType) { | 1635 switch (objType) { |
| 1636 case PK11_TypeGeneric: | 1636 case PK11_TypeGeneric: |
| 1637 slot = ((PK11GenericObject *)objSpec)->slot; | 1637 slot = ((PK11GenericObject *)objSpec)->slot; |
| 1638 handle = ((PK11GenericObject *)objSpec)->objectID; | 1638 handle = ((PK11GenericObject *)objSpec)->objectID; |
| 1639 break; | 1639 break; |
| 1640 case PK11_TypePrivKey: | 1640 case PK11_TypePrivKey: |
| 1641 slot = ((SECKEYPrivateKey *)objSpec)->pkcs11Slot; | 1641 slot = ((SECKEYPrivateKey *)objSpec)->pkcs11Slot; |
| 1642 handle = ((SECKEYPrivateKey *)objSpec)->pkcs11ID; | 1642 handle = ((SECKEYPrivateKey *)objSpec)->pkcs11ID; |
| 1643 break; | 1643 break; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1774 { | 1774 { |
| 1775 CK_ATTRIBUTE theTemplate[] = { | 1775 CK_ATTRIBUTE theTemplate[] = { |
| 1776 { CKA_ID, NULL, 0 }, | 1776 { CKA_ID, NULL, 0 }, |
| 1777 { CKA_CLASS, NULL, 0 } | 1777 { CKA_CLASS, NULL, 0 } |
| 1778 }; | 1778 }; |
| 1779 /* if you change the array, change the variable below as well */ | 1779 /* if you change the array, change the variable below as well */ |
| 1780 CK_ATTRIBUTE *keyclass = &theTemplate[1]; | 1780 CK_ATTRIBUTE *keyclass = &theTemplate[1]; |
| 1781 int tsize = sizeof(theTemplate)/sizeof(theTemplate[0]); | 1781 int tsize = sizeof(theTemplate)/sizeof(theTemplate[0]); |
| 1782 /* if you change the array, change the variable below as well */ | 1782 /* if you change the array, change the variable below as well */ |
| 1783 CK_OBJECT_HANDLE peerID; | 1783 CK_OBJECT_HANDLE peerID; |
| 1784 CK_OBJECT_HANDLE parent; | |
| 1785 PLArenaPool *arena; | 1784 PLArenaPool *arena; |
| 1786 CK_RV crv; | 1785 CK_RV crv; |
| 1787 | 1786 |
| 1788 /* now we need to create space for the public key */ | 1787 /* now we need to create space for the public key */ |
| 1789 arena = PORT_NewArena( DER_DEFAULT_CHUNKSIZE); | 1788 arena = PORT_NewArena( DER_DEFAULT_CHUNKSIZE); |
| 1790 if (arena == NULL) return CK_INVALID_HANDLE; | 1789 if (arena == NULL) return CK_INVALID_HANDLE; |
| 1791 | 1790 |
| 1792 crv = PK11_GetAttributes(arena,slot,searchID,theTemplate,tsize); | 1791 crv = PK11_GetAttributes(arena,slot,searchID,theTemplate,tsize); |
| 1793 if (crv != CKR_OK) { | 1792 if (crv != CKR_OK) { |
| 1794 PORT_FreeArena(arena,PR_FALSE); | 1793 PORT_FreeArena(arena,PR_FALSE); |
| 1795 PORT_SetError( PK11_MapError(crv) ); | 1794 PORT_SetError( PK11_MapError(crv) ); |
| 1796 return CK_INVALID_HANDLE; | 1795 return CK_INVALID_HANDLE; |
| 1797 } | 1796 } |
| 1798 | 1797 |
| 1799 if ((theTemplate[0].ulValueLen == 0) || (theTemplate[0].ulValueLen == -1)) { | 1798 if ((theTemplate[0].ulValueLen == 0) || (theTemplate[0].ulValueLen == -1)) { |
| 1800 PORT_FreeArena(arena,PR_FALSE); | 1799 PORT_FreeArena(arena,PR_FALSE); |
| 1801 if (matchclass == CKO_CERTIFICATE) | 1800 if (matchclass == CKO_CERTIFICATE) |
| 1802 PORT_SetError(SEC_ERROR_BAD_KEY); | 1801 PORT_SetError(SEC_ERROR_BAD_KEY); |
| 1803 else | 1802 else |
| 1804 PORT_SetError(SEC_ERROR_NO_KEY); | 1803 PORT_SetError(SEC_ERROR_NO_KEY); |
| 1805 return CK_INVALID_HANDLE; | 1804 return CK_INVALID_HANDLE; |
| 1806 } | 1805 } |
| 1807 | 1806 |
| 1808 | 1807 |
| 1809 | 1808 |
| 1810 /* | 1809 /* |
| 1811 * issue the find | 1810 * issue the find |
| 1812 */ | 1811 */ |
| 1813 parent = *(CK_OBJECT_CLASS *)(keyclass->pValue); | |
| 1814 *(CK_OBJECT_CLASS *)(keyclass->pValue) = matchclass; | 1812 *(CK_OBJECT_CLASS *)(keyclass->pValue) = matchclass; |
| 1815 | 1813 |
| 1816 peerID = pk11_FindObjectByTemplate(slot,theTemplate,tsize); | 1814 peerID = pk11_FindObjectByTemplate(slot,theTemplate,tsize); |
| 1817 PORT_FreeArena(arena,PR_FALSE); | 1815 PORT_FreeArena(arena,PR_FALSE); |
| 1818 | 1816 |
| 1819 return peerID; | 1817 return peerID; |
| 1820 } | 1818 } |
| 1821 | 1819 |
| 1822 /* | 1820 /* |
| 1823 * count the number of objects that match the template. | 1821 * count the number of objects that match the template. |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2015 PORT_SetError( PK11_MapError(crv) ); | 2013 PORT_SetError( PK11_MapError(crv) ); |
| 2016 return NULL; | 2014 return NULL; |
| 2017 } | 2015 } |
| 2018 | 2016 |
| 2019 item->data = (unsigned char*) theTemplate[0].pValue; | 2017 item->data = (unsigned char*) theTemplate[0].pValue; |
| 2020 item->len =theTemplate[0].ulValueLen; | 2018 item->len =theTemplate[0].ulValueLen; |
| 2021 | 2019 |
| 2022 return item; | 2020 return item; |
| 2023 } | 2021 } |
| 2024 | 2022 |
| OLD | NEW |