Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(282)

Side by Side Diff: nss/lib/softoken/sftkdb.c

Issue 16132005: Allow NSS to be built with NO_NSPR_10_SUPPORT. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/nss/
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « nss/lib/softoken/pkcs11c.c ('k') | nss/lib/softoken/softoken.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 * The following code handles the storage of PKCS 11 modules used by the 5 * The following code handles the storage of PKCS 11 modules used by the
6 * NSS. For the rest of NSS, only one kind of database handle exists: 6 * NSS. For the rest of NSS, only one kind of database handle exists:
7 * 7 *
8 * SFTKDBHandle 8 * SFTKDBHandle
9 * 9 *
10 * There is one SFTKDBHandle for the each key database and one for each cert 10 * There is one SFTKDBHandle for the each key database and one for each cert
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 if (inPeerDBTransaction) { 562 if (inPeerDBTransaction) {
563 /* The transaction must have failed. Abort. */ 563 /* The transaction must have failed. Abort. */
564 (*keyTarget->sdb_Abort)(keyTarget); 564 (*keyTarget->sdb_Abort)(keyTarget);
565 PORT_Assert(crv != CKR_OK); 565 PORT_Assert(crv != CKR_OK);
566 if (crv == CKR_OK) crv = CKR_GENERAL_ERROR; 566 if (crv == CKR_OK) crv = CKR_GENERAL_ERROR;
567 } 567 }
568 return crv; 568 return crv;
569 } 569 }
570 570
571 static CK_RV 571 static CK_RV
572 sftkdb_CreateObject(PRArenaPool *arena, SFTKDBHandle *handle, 572 sftkdb_CreateObject(PLArenaPool *arena, SFTKDBHandle *handle,
573 SDB *db, CK_OBJECT_HANDLE *objectID, 573 SDB *db, CK_OBJECT_HANDLE *objectID,
574 CK_ATTRIBUTE *template, CK_ULONG count) 574 CK_ATTRIBUTE *template, CK_ULONG count)
575 { 575 {
576 PRBool inTransaction = PR_FALSE; 576 PRBool inTransaction = PR_FALSE;
577 CK_RV crv; 577 CK_RV crv;
578 578
579 inTransaction = PR_TRUE; 579 inTransaction = PR_TRUE;
580 580
581 crv = (*db->sdb_CreateObject)(db, objectID, template, count); 581 crv = (*db->sdb_CreateObject)(db, objectID, template, count);
582 if (crv != CKR_OK) { 582 if (crv != CKR_OK) {
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 * 1009 *
1010 * NOTE: we must update the template or return an error, or the update caller 1010 * NOTE: we must update the template or return an error, or the update caller
1011 * will loop forever! 1011 * will loop forever!
1012 * 1012 *
1013 * Two copies of the source code for this algorithm exist in NSS. 1013 * Two copies of the source code for this algorithm exist in NSS.
1014 * Changes must be made in both copies. 1014 * Changes must be made in both copies.
1015 * The other copy is in pk11_IncrementNickname() in pk11wrap/pk11merge.c. 1015 * The other copy is in pk11_IncrementNickname() in pk11wrap/pk11merge.c.
1016 * 1016 *
1017 */ 1017 */
1018 static CK_RV 1018 static CK_RV
1019 sftkdb_resolveConflicts(PRArenaPool *arena, CK_OBJECT_CLASS objectType, 1019 sftkdb_resolveConflicts(PLArenaPool *arena, CK_OBJECT_CLASS objectType,
1020 CK_ATTRIBUTE *ptemplate, CK_ULONG *plen) 1020 CK_ATTRIBUTE *ptemplate, CK_ULONG *plen)
1021 { 1021 {
1022 CK_ATTRIBUTE *attr; 1022 CK_ATTRIBUTE *attr;
1023 char *nickname, *newNickname; 1023 char *nickname, *newNickname;
1024 int end, digit; 1024 int end, digit;
1025 1025
1026 /* sanity checks. We should never get here with these errors */ 1026 /* sanity checks. We should never get here with these errors */
1027 if (objectType != CKO_CERTIFICATE) { 1027 if (objectType != CKO_CERTIFICATE) {
1028 return CKR_GENERAL_ERROR; /* shouldn't happen */ 1028 return CKR_GENERAL_ERROR; /* shouldn't happen */
1029 } 1029 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 PORT_Memset(&newNickname[end+1],'0',attr->ulValueLen - end); 1081 PORT_Memset(&newNickname[end+1],'0',attr->ulValueLen - end);
1082 attr->pValue = newNickname; 1082 attr->pValue = newNickname;
1083 attr->ulValueLen++; 1083 attr->ulValueLen++;
1084 return CKR_OK; 1084 return CKR_OK;
1085 } 1085 }
1086 1086
1087 /* 1087 /*
1088 * set an attribute and sign it if necessary 1088 * set an attribute and sign it if necessary
1089 */ 1089 */
1090 static CK_RV 1090 static CK_RV
1091 sftkdb_setAttributeValue(PRArenaPool *arena, SFTKDBHandle *handle, 1091 sftkdb_setAttributeValue(PLArenaPool *arena, SFTKDBHandle *handle,
1092 SDB *db, CK_OBJECT_HANDLE objectID, const CK_ATTRIBUTE *template, 1092 SDB *db, CK_OBJECT_HANDLE objectID, const CK_ATTRIBUTE *template,
1093 CK_ULONG count) 1093 CK_ULONG count)
1094 { 1094 {
1095 CK_RV crv; 1095 CK_RV crv;
1096 crv = (*db->sdb_SetAttributeValue)(db, objectID, template, count); 1096 crv = (*db->sdb_SetAttributeValue)(db, objectID, template, count);
1097 if (crv != CKR_OK) { 1097 if (crv != CKR_OK) {
1098 return crv; 1098 return crv;
1099 } 1099 }
1100 crv = sftk_signTemplate(arena, handle, db == handle->update, 1100 crv = sftk_signTemplate(arena, handle, db == handle->update,
1101 objectID, template, count); 1101 objectID, template, count);
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after
1728 * This code also handles the following corner cases: 1728 * This code also handles the following corner cases:
1729 * 1) the single byte overflows. On overflow we increment the next byte up 1729 * 1) the single byte overflows. On overflow we increment the next byte up
1730 * and so forth until we have overflowed the entire CKA_ID. 1730 * and so forth until we have overflowed the entire CKA_ID.
1731 * 2) If we overflow the entire CKA_ID we expand it by one byte. 1731 * 2) If we overflow the entire CKA_ID we expand it by one byte.
1732 * 3) the CKA_ID is non-existant, we create a new one with one byte. 1732 * 3) the CKA_ID is non-existant, we create a new one with one byte.
1733 * This means no matter what CKA_ID is passed, the result of this function 1733 * This means no matter what CKA_ID is passed, the result of this function
1734 * is always a new CKA_ID, and this function will never return the same 1734 * is always a new CKA_ID, and this function will never return the same
1735 * CKA_ID the it has returned in the passed. 1735 * CKA_ID the it has returned in the passed.
1736 */ 1736 */
1737 static CK_RV 1737 static CK_RV
1738 sftkdb_incrementCKAID(PRArenaPool *arena, CK_ATTRIBUTE *ptemplate) 1738 sftkdb_incrementCKAID(PLArenaPool *arena, CK_ATTRIBUTE *ptemplate)
1739 { 1739 {
1740 unsigned char *buf = ptemplate->pValue; 1740 unsigned char *buf = ptemplate->pValue;
1741 CK_ULONG len = ptemplate->ulValueLen; 1741 CK_ULONG len = ptemplate->ulValueLen;
1742 1742
1743 if (buf == NULL || len == (CK_ULONG)-1) { 1743 if (buf == NULL || len == (CK_ULONG)-1) {
1744 /* we have no valid CKAID, we'll create a basic one byte CKA_ID below */ 1744 /* we have no valid CKAID, we'll create a basic one byte CKA_ID below */
1745 len = 0; 1745 len = 0;
1746 } else { 1746 } else {
1747 CK_ULONG i; 1747 CK_ULONG i;
1748 1748
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1822 * return SFTKDB_MODIFY_OBJECT 1822 * return SFTKDB_MODIFY_OBJECT
1823 * If we want to use the target version, 1823 * If we want to use the target version,
1824 * return SFTKDB_DROP_ATTRIBUTE 1824 * return SFTKDB_DROP_ATTRIBUTE
1825 * 1825 *
1826 * In the end the caller will remove any attributes in the source 1826 * In the end the caller will remove any attributes in the source
1827 * template when SFTKDB_DROP_ATTRIBUTE is specified, then use do a 1827 * template when SFTKDB_DROP_ATTRIBUTE is specified, then use do a
1828 * set attributes with that template on the target if we received 1828 * set attributes with that template on the target if we received
1829 * any SFTKDB_MODIFY_OBJECT returns. 1829 * any SFTKDB_MODIFY_OBJECT returns.
1830 */ 1830 */
1831 sftkdbUpdateStatus 1831 sftkdbUpdateStatus
1832 sftkdb_reconcileTrustEntry(PRArenaPool *arena, CK_ATTRIBUTE *target, 1832 sftkdb_reconcileTrustEntry(PLArenaPool *arena, CK_ATTRIBUTE *target,
1833 CK_ATTRIBUTE *source) 1833 CK_ATTRIBUTE *source)
1834 { 1834 {
1835 CK_ULONG targetTrust = sftkdb_getULongFromTemplate(target->type, 1835 CK_ULONG targetTrust = sftkdb_getULongFromTemplate(target->type,
1836 target, 1); 1836 target, 1);
1837 CK_ULONG sourceTrust = sftkdb_getULongFromTemplate(target->type, 1837 CK_ULONG sourceTrust = sftkdb_getULongFromTemplate(target->type,
1838 source, 1); 1838 source, 1);
1839 1839
1840 /* 1840 /*
1841 * try to pick the best solution between the source and the 1841 * try to pick the best solution between the source and the
1842 * target. Update the source template if we want the target value 1842 * target. Update the source template if we want the target value
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1909 CKA_TRUST_TIME_STAMPING }; 1909 CKA_TRUST_TIME_STAMPING };
1910 1910
1911 #define SFTK_TRUST_TEMPLATE_COUNT \ 1911 #define SFTK_TRUST_TEMPLATE_COUNT \
1912 (sizeof(sftkdb_trustList)/sizeof(sftkdb_trustList[0])) 1912 (sizeof(sftkdb_trustList)/sizeof(sftkdb_trustList[0]))
1913 /* 1913 /*
1914 * Run through the list of known trust types, and reconcile each trust 1914 * Run through the list of known trust types, and reconcile each trust
1915 * entry one by one. Keep track of we really need to write out the source 1915 * entry one by one. Keep track of we really need to write out the source
1916 * trust object (overwriting the existing one). 1916 * trust object (overwriting the existing one).
1917 */ 1917 */
1918 static sftkdbUpdateStatus 1918 static sftkdbUpdateStatus
1919 sftkdb_reconcileTrust(PRArenaPool *arena, SDB *db, CK_OBJECT_HANDLE id, 1919 sftkdb_reconcileTrust(PLArenaPool *arena, SDB *db, CK_OBJECT_HANDLE id,
1920 CK_ATTRIBUTE *ptemplate, CK_ULONG *plen) 1920 CK_ATTRIBUTE *ptemplate, CK_ULONG *plen)
1921 { 1921 {
1922 CK_ATTRIBUTE trustTemplate[SFTK_TRUST_TEMPLATE_COUNT]; 1922 CK_ATTRIBUTE trustTemplate[SFTK_TRUST_TEMPLATE_COUNT];
1923 unsigned char trustData[SFTK_TRUST_TEMPLATE_COUNT*SDB_ULONG_SIZE]; 1923 unsigned char trustData[SFTK_TRUST_TEMPLATE_COUNT*SDB_ULONG_SIZE];
1924 sftkdbUpdateStatus update = SFTKDB_DO_NOTHING; 1924 sftkdbUpdateStatus update = SFTKDB_DO_NOTHING;
1925 CK_ULONG i; 1925 CK_ULONG i;
1926 CK_RV crv; 1926 CK_RV crv;
1927 1927
1928 1928
1929 for (i=0; i < SFTK_TRUST_TEMPLATE_COUNT; i++) { 1929 for (i=0; i < SFTK_TRUST_TEMPLATE_COUNT; i++) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1995 (*(CK_BBOOL *)(attr->pValue) == CK_TRUE)) { 1995 (*(CK_BBOOL *)(attr->pValue) == CK_TRUE)) {
1996 update = SFTKDB_MODIFY_OBJECT; 1996 update = SFTKDB_MODIFY_OBJECT;
1997 } 1997 }
1998 } 1998 }
1999 1999
2000 done: 2000 done:
2001 return update; 2001 return update;
2002 } 2002 }
2003 2003
2004 static sftkdbUpdateStatus 2004 static sftkdbUpdateStatus
2005 sftkdb_handleIDAndName(PRArenaPool *arena, SDB *db, CK_OBJECT_HANDLE id, 2005 sftkdb_handleIDAndName(PLArenaPool *arena, SDB *db, CK_OBJECT_HANDLE id,
2006 CK_ATTRIBUTE *ptemplate, CK_ULONG *plen) 2006 CK_ATTRIBUTE *ptemplate, CK_ULONG *plen)
2007 { 2007 {
2008 sftkdbUpdateStatus update = SFTKDB_DO_NOTHING; 2008 sftkdbUpdateStatus update = SFTKDB_DO_NOTHING;
2009 CK_ATTRIBUTE *attr1, *attr2; 2009 CK_ATTRIBUTE *attr1, *attr2;
2010 CK_ATTRIBUTE ttemplate[2] = { 2010 CK_ATTRIBUTE ttemplate[2] = {
2011 {CKA_ID, NULL, 0}, 2011 {CKA_ID, NULL, 0},
2012 {CKA_LABEL, NULL, 0} 2012 {CKA_LABEL, NULL, 0}
2013 }; 2013 };
2014 CK_RV crv; 2014 CK_RV crv;
2015 2015
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
2074 2074
2075 /* 2075 /*
2076 * This function updates the template before we write the object out. 2076 * This function updates the template before we write the object out.
2077 * 2077 *
2078 * If we are going to skip updating this object, return PR_FALSE. 2078 * If we are going to skip updating this object, return PR_FALSE.
2079 * If it should be updated we return PR_TRUE. 2079 * If it should be updated we return PR_TRUE.
2080 * To help readability, these have been defined 2080 * To help readability, these have been defined
2081 * as SFTK_DONT_UPDATE and SFTK_UPDATE respectively. 2081 * as SFTK_DONT_UPDATE and SFTK_UPDATE respectively.
2082 */ 2082 */
2083 static PRBool 2083 static PRBool
2084 sftkdb_updateObjectTemplate(PRArenaPool *arena, SDB *db, 2084 sftkdb_updateObjectTemplate(PLArenaPool *arena, SDB *db,
2085 CK_OBJECT_CLASS objectType, 2085 CK_OBJECT_CLASS objectType,
2086 CK_ATTRIBUTE *ptemplate, CK_ULONG *plen, 2086 CK_ATTRIBUTE *ptemplate, CK_ULONG *plen,
2087 CK_OBJECT_HANDLE *targetID) 2087 CK_OBJECT_HANDLE *targetID)
2088 { 2088 {
2089 PRBool done; /* should we repeat the loop? */ 2089 PRBool done; /* should we repeat the loop? */
2090 CK_OBJECT_HANDLE id; 2090 CK_OBJECT_HANDLE id;
2091 CK_RV crv = CKR_OK; 2091 CK_RV crv = CKR_OK;
2092 2092
2093 do { 2093 do {
2094 crv = sftkdb_checkConflicts(db, objectType, ptemplate, 2094 crv = sftkdb_checkConflicts(db, objectType, ptemplate,
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
2728 } 2728 }
2729 2729
2730 CK_RV 2730 CK_RV
2731 sftkdb_Shutdown(void) 2731 sftkdb_Shutdown(void)
2732 { 2732 {
2733 s_shutdown(); 2733 s_shutdown();
2734 sftkdbCall_Shutdown(); 2734 sftkdbCall_Shutdown();
2735 return CKR_OK; 2735 return CKR_OK;
2736 } 2736 }
2737 2737
OLDNEW
« no previous file with comments | « nss/lib/softoken/pkcs11c.c ('k') | nss/lib/softoken/softoken.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698