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

Side by Side Diff: nss/lib/pk11wrap/pk11akey.c

Issue 1504923011: Update NSS to 3.21 RTM and NSPR to 4.11 RTM (Closed) Base URL: http://src.chromium.org/svn/trunk/deps/third_party/nss
Patch Set: Created 5 years 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
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 * This file contains functions to manage asymetric keys, (public and 5 * This file contains functions to manage asymetric keys, (public and
6 * private keys). 6 * private keys).
7 */ 7 */
8 #include "seccomon.h" 8 #include "seccomon.h"
9 #include "secmod.h" 9 #include "secmod.h"
10 #include "secmodi.h" 10 #include "secmodi.h"
11 #include "secmodti.h" 11 #include "secmodti.h"
12 #include "pkcs11.h" 12 #include "pkcs11.h"
13 #include "pkcs11t.h" 13 #include "pkcs11t.h"
14 #include "pk11func.h" 14 #include "pk11func.h"
15 #include "cert.h" 15 #include "cert.h"
16 #include "key.h" 16 #include "key.h"
17 #include "secitem.h" 17 #include "secitem.h"
18 #include "secasn1.h" 18 #include "secasn1.h"
19 #include "secoid.h" 19 #include "secoid.h"
20 #include "secerr.h" 20 #include "secerr.h"
21 #include "sslerr.h"
22 #include "sechash.h" 21 #include "sechash.h"
23 22
24 #include "secpkcs5.h" 23 #include "secpkcs5.h"
25 #include "blapit.h" 24 #include "blapit.h"
26 25
27 static SECItem * 26 static SECItem *
28 pk11_MakeIDFromPublicKey(SECKEYPublicKey *pubKey) 27 pk11_MakeIDFromPublicKey(SECKEYPublicKey *pubKey)
29 { 28 {
30 /* set the ID to the public key so we can find it again */ 29 /* set the ID to the public key so we can find it again */
31 SECItem *pubKeyIndex = NULL; 30 SECItem *pubKeyIndex = NULL;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 CK_BBOOL ckfalse = CK_FALSE; 66 CK_BBOOL ckfalse = CK_FALSE;
68 CK_OBJECT_CLASS keyClass = CKO_PUBLIC_KEY; 67 CK_OBJECT_CLASS keyClass = CKO_PUBLIC_KEY;
69 CK_KEY_TYPE keyType = CKK_GENERIC_SECRET; 68 CK_KEY_TYPE keyType = CKK_GENERIC_SECRET;
70 CK_OBJECT_HANDLE objectID; 69 CK_OBJECT_HANDLE objectID;
71 CK_ATTRIBUTE theTemplate[11]; 70 CK_ATTRIBUTE theTemplate[11];
72 CK_ATTRIBUTE *signedattr = NULL; 71 CK_ATTRIBUTE *signedattr = NULL;
73 CK_ATTRIBUTE *attrs = theTemplate; 72 CK_ATTRIBUTE *attrs = theTemplate;
74 SECItem *ckaId = NULL; 73 SECItem *ckaId = NULL;
75 SECItem *pubValue = NULL; 74 SECItem *pubValue = NULL;
76 int signedcount = 0; 75 int signedcount = 0;
77 int templateCount = 0; 76 unsigned int templateCount = 0;
78 SECStatus rv; 77 SECStatus rv;
79 78
80 /* if we already have an object in the desired slot, use it */ 79 /* if we already have an object in the desired slot, use it */
81 if (!isToken && pubKey->pkcs11Slot == slot) { 80 if (!isToken && pubKey->pkcs11Slot == slot) {
82 return pubKey->pkcs11ID; 81 return pubKey->pkcs11ID;
83 } 82 }
84 83
85 /* free the existing key */ 84 /* free the existing key */
86 if (pubKey->pkcs11Slot != NULL) { 85 if (pubKey->pkcs11Slot != NULL) {
87 PK11SlotInfo *oSlot = pubKey->pkcs11Slot; 86 PK11SlotInfo *oSlot = pubKey->pkcs11Slot;
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 */ 385 */
387 keyLen = pk11_get_EC_PointLenInBytes(arena, ecParams); 386 keyLen = pk11_get_EC_PointLenInBytes(arena, ecParams);
388 if (keyLen < 0) { 387 if (keyLen < 0) {
389 return CKR_ATTRIBUTE_VALUE_INVALID; 388 return CKR_ATTRIBUTE_VALUE_INVALID;
390 } 389 }
391 390
392 391
393 /* If the point is uncompressed and the lengths match, it 392 /* If the point is uncompressed and the lengths match, it
394 * must be an unencoded point */ 393 * must be an unencoded point */
395 if ((*((char *)ecPoint->pValue) == EC_POINT_FORM_UNCOMPRESSED) 394 if ((*((char *)ecPoint->pValue) == EC_POINT_FORM_UNCOMPRESSED)
396 » && (ecPoint->ulValueLen == keyLen)) { 395 » && (ecPoint->ulValueLen == (unsigned int)keyLen)) {
397 return pk11_Attr2SecItem(arena, ecPoint, publicKeyValue); 396 return pk11_Attr2SecItem(arena, ecPoint, publicKeyValue);
398 } 397 }
399 398
400 /* now assume the key passed to us was encoded and decode it */ 399 /* now assume the key passed to us was encoded and decode it */
401 if (*((char *)ecPoint->pValue) == SEC_ASN1_OCTET_STRING) { 400 if (*((char *)ecPoint->pValue) == SEC_ASN1_OCTET_STRING) {
402 /* OK, now let's try to decode it and see if it's valid */ 401 /* OK, now let's try to decode it and see if it's valid */
403 encodedPublicValue.data = ecPoint->pValue; 402 encodedPublicValue.data = ecPoint->pValue;
404 encodedPublicValue.len = ecPoint->ulValueLen; 403 encodedPublicValue.len = ecPoint->ulValueLen;
405 rv = SEC_QuickDERDecodeItem(arena, publicKeyValue, 404 rv = SEC_QuickDERDecodeItem(arena, publicKeyValue,
406 SEC_ASN1_GET(SEC_OctetStringTemplate), &encodedPublicValue); 405 SEC_ASN1_GET(SEC_OctetStringTemplate), &encodedPublicValue);
407 406
408 /* it coded correctly & we know the key length (and they match) 407 /* it coded correctly & we know the key length (and they match)
409 * then we are done, return the results. */ 408 * then we are done, return the results. */
410 if (keyLen && rv == SECSuccess && publicKeyValue->len == keyLen) { 409 if (keyLen && rv == SECSuccess && publicKeyValue->len == (unsigned int)k eyLen) {
411 return CKR_OK; 410 return CKR_OK;
412 } 411 }
413 412
414 /* if we know the key length, one of the above tests should have 413 /* if we know the key length, one of the above tests should have
415 * succeded. If it doesn't the module gave us bad data */ 414 * succeded. If it doesn't the module gave us bad data */
416 if (keyLen) { 415 if (keyLen) {
417 return CKR_ATTRIBUTE_VALUE_INVALID; 416 return CKR_ATTRIBUTE_VALUE_INVALID;
418 } 417 }
419 418
420 419
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 /* 531 /*
533 * extract a public key from a slot and id 532 * extract a public key from a slot and id
534 */ 533 */
535 SECKEYPublicKey * 534 SECKEYPublicKey *
536 PK11_ExtractPublicKey(PK11SlotInfo *slot,KeyType keyType,CK_OBJECT_HANDLE id) 535 PK11_ExtractPublicKey(PK11SlotInfo *slot,KeyType keyType,CK_OBJECT_HANDLE id)
537 { 536 {
538 CK_OBJECT_CLASS keyClass = CKO_PUBLIC_KEY; 537 CK_OBJECT_CLASS keyClass = CKO_PUBLIC_KEY;
539 PLArenaPool *arena; 538 PLArenaPool *arena;
540 PLArenaPool *tmp_arena; 539 PLArenaPool *tmp_arena;
541 SECKEYPublicKey *pubKey; 540 SECKEYPublicKey *pubKey;
542 int templateCount = 0; 541 unsigned int templateCount = 0;
543 CK_KEY_TYPE pk11KeyType; 542 CK_KEY_TYPE pk11KeyType;
544 CK_RV crv; 543 CK_RV crv;
545 CK_ATTRIBUTE template[8]; 544 CK_ATTRIBUTE template[8];
546 CK_ATTRIBUTE *attrs= template; 545 CK_ATTRIBUTE *attrs= template;
547 CK_ATTRIBUTE *modulus,*exponent,*base,*prime,*subprime,*value; 546 CK_ATTRIBUTE *modulus,*exponent,*base,*prime,*subprime,*value;
548 CK_ATTRIBUTE *ecparams; 547 CK_ATTRIBUTE *ecparams;
549 548
550 /* if we didn't know the key type, get it */ 549 /* if we didn't know the key type, get it */
551 if (keyType== nullKey) { 550 if (keyType== nullKey) {
552 551
(...skipping 946 matching lines...) Expand 10 before | Expand all | Expand 10 after
1499 SECKEYPublicKey * 1498 SECKEYPublicKey *
1500 PK11_MakeKEAPubKey(unsigned char *keyData,int length) 1499 PK11_MakeKEAPubKey(unsigned char *keyData,int length)
1501 { 1500 {
1502 SECKEYPublicKey *pubk; 1501 SECKEYPublicKey *pubk;
1503 SECItem pkData; 1502 SECItem pkData;
1504 SECStatus rv; 1503 SECStatus rv;
1505 PLArenaPool *arena; 1504 PLArenaPool *arena;
1506 1505
1507 pkData.data = keyData; 1506 pkData.data = keyData;
1508 pkData.len = length; 1507 pkData.len = length;
1508 pkData.type = siBuffer;
1509 1509
1510 arena = PORT_NewArena (DER_DEFAULT_CHUNKSIZE); 1510 arena = PORT_NewArena (DER_DEFAULT_CHUNKSIZE);
1511 if (arena == NULL) 1511 if (arena == NULL)
1512 return NULL; 1512 return NULL;
1513 1513
1514 pubk = (SECKEYPublicKey *) PORT_ArenaZAlloc(arena, sizeof(SECKEYPublicKey)); 1514 pubk = (SECKEYPublicKey *) PORT_ArenaZAlloc(arena, sizeof(SECKEYPublicKey));
1515 if (pubk == NULL) { 1515 if (pubk == NULL) {
1516 PORT_FreeArena (arena, PR_FALSE); 1516 PORT_FreeArena (arena, PR_FALSE);
1517 return NULL; 1517 return NULL;
1518 } 1518 }
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after
2291 return keys; 2291 return keys;
2292 } 2292 }
2293 2293
2294 SECKEYPublicKeyList* 2294 SECKEYPublicKeyList*
2295 PK11_ListPublicKeysInSlot(PK11SlotInfo *slot, char *nickname) 2295 PK11_ListPublicKeysInSlot(PK11SlotInfo *slot, char *nickname)
2296 { 2296 {
2297 CK_ATTRIBUTE findTemp[4]; 2297 CK_ATTRIBUTE findTemp[4];
2298 CK_ATTRIBUTE *attrs; 2298 CK_ATTRIBUTE *attrs;
2299 CK_BBOOL ckTrue = CK_TRUE; 2299 CK_BBOOL ckTrue = CK_TRUE;
2300 CK_OBJECT_CLASS keyclass = CKO_PUBLIC_KEY; 2300 CK_OBJECT_CLASS keyclass = CKO_PUBLIC_KEY;
2301 int tsize = 0; 2301 unsigned int tsize = 0;
2302 int objCount = 0; 2302 int objCount = 0;
2303 CK_OBJECT_HANDLE *key_ids; 2303 CK_OBJECT_HANDLE *key_ids;
2304 SECKEYPublicKeyList *keys; 2304 SECKEYPublicKeyList *keys;
2305 int i,len; 2305 int i,len;
2306 2306
2307 2307
2308 attrs = findTemp; 2308 attrs = findTemp;
2309 PK11_SETATTRS(attrs, CKA_CLASS, &keyclass, sizeof(keyclass)); attrs++; 2309 PK11_SETATTRS(attrs, CKA_CLASS, &keyclass, sizeof(keyclass)); attrs++;
2310 PK11_SETATTRS(attrs, CKA_TOKEN, &ckTrue, sizeof(ckTrue)); attrs++; 2310 PK11_SETATTRS(attrs, CKA_TOKEN, &ckTrue, sizeof(ckTrue)); attrs++;
2311 if (nickname) { 2311 if (nickname) {
(...skipping 25 matching lines...) Expand all
2337 return keys; 2337 return keys;
2338 } 2338 }
2339 2339
2340 SECKEYPrivateKeyList* 2340 SECKEYPrivateKeyList*
2341 PK11_ListPrivKeysInSlot(PK11SlotInfo *slot, char *nickname, void *wincx) 2341 PK11_ListPrivKeysInSlot(PK11SlotInfo *slot, char *nickname, void *wincx)
2342 { 2342 {
2343 CK_ATTRIBUTE findTemp[4]; 2343 CK_ATTRIBUTE findTemp[4];
2344 CK_ATTRIBUTE *attrs; 2344 CK_ATTRIBUTE *attrs;
2345 CK_BBOOL ckTrue = CK_TRUE; 2345 CK_BBOOL ckTrue = CK_TRUE;
2346 CK_OBJECT_CLASS keyclass = CKO_PRIVATE_KEY; 2346 CK_OBJECT_CLASS keyclass = CKO_PRIVATE_KEY;
2347 int tsize = 0; 2347 unsigned int tsize = 0;
2348 int objCount = 0; 2348 int objCount = 0;
2349 CK_OBJECT_HANDLE *key_ids; 2349 CK_OBJECT_HANDLE *key_ids;
2350 SECKEYPrivateKeyList *keys; 2350 SECKEYPrivateKeyList *keys;
2351 int i,len; 2351 int i,len;
2352 2352
2353 2353
2354 attrs = findTemp; 2354 attrs = findTemp;
2355 PK11_SETATTRS(attrs, CKA_CLASS, &keyclass, sizeof(keyclass)); attrs++; 2355 PK11_SETATTRS(attrs, CKA_CLASS, &keyclass, sizeof(keyclass)); attrs++;
2356 PK11_SETATTRS(attrs, CKA_TOKEN, &ckTrue, sizeof(ckTrue)); attrs++; 2356 PK11_SETATTRS(attrs, CKA_TOKEN, &ckTrue, sizeof(ckTrue)); attrs++;
2357 if (nickname) { 2357 if (nickname) {
(...skipping 16 matching lines...) Expand all
2374 for (i=0; i < objCount ; i++) { 2374 for (i=0; i < objCount ; i++) {
2375 SECKEYPrivateKey *privKey = 2375 SECKEYPrivateKey *privKey =
2376 PK11_MakePrivKey(slot,nullKey,PR_TRUE,key_ids[i],wincx); 2376 PK11_MakePrivKey(slot,nullKey,PR_TRUE,key_ids[i],wincx);
2377 SECKEY_AddPrivateKeyToListTail(keys, privKey); 2377 SECKEY_AddPrivateKeyToListTail(keys, privKey);
2378 } 2378 }
2379 2379
2380 PORT_Free(key_ids); 2380 PORT_Free(key_ids);
2381 return keys; 2381 return keys;
2382 } 2382 }
2383 2383
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698