OLD | NEW |
---|---|
1 /* ***** BEGIN LICENSE BLOCK ***** | 1 /* ***** BEGIN LICENSE BLOCK ***** |
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
3 * | 3 * |
4 * The contents of this file are subject to the Mozilla Public License Version | 4 * The contents of this file are subject to the Mozilla Public License Version |
5 * 1.1 (the "License"); you may not use this file except in compliance with | 5 * 1.1 (the "License"); you may not use this file except in compliance with |
6 * the License. You may obtain a copy of the License at | 6 * the License. You may obtain a copy of the License at |
7 * http://www.mozilla.org/MPL/ | 7 * http://www.mozilla.org/MPL/ |
8 * | 8 * |
9 * Software distributed under the License is distributed on an "AS IS" basis, | 9 * Software distributed under the License is distributed on an "AS IS" basis, |
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | 10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
190 if (srv) goto finish; | 190 if (srv) goto finish; |
191 // import cert and key | 191 // import cert and key |
192 srv = SEC_PKCS12DecoderImportBags(dcx); | 192 srv = SEC_PKCS12DecoderImportBags(dcx); |
193 if (srv) goto finish; | 193 if (srv) goto finish; |
194 | 194 |
195 if (!is_extractable) { | 195 if (!is_extractable) { |
196 SECItem attribute_value; | 196 SECItem attribute_value; |
197 CK_BBOOL attribute_data = CK_FALSE; | 197 CK_BBOOL attribute_data = CK_FALSE; |
198 attribute_value.data = &attribute_data; | 198 attribute_value.data = &attribute_data; |
199 attribute_value.len = sizeof(attribute_data); | 199 attribute_value.len = sizeof(attribute_data); |
200 CERTCertList* cert_list = SEC_PKCS12DecoderGetCerts(dcx); | |
201 | 200 |
202 // Iterate through each certificate in the chain and mark corresponding | 201 srv = SEC_PKCS12DecoderIterateInit(dcx); |
203 // private key as unextractable. | 202 if (srv) goto finish; |
204 for (CERTCertListNode* node = CERT_LIST_HEAD(cert_list); | 203 |
205 !CERT_LIST_END(node, cert_list); node = CERT_LIST_NEXT(node)) { | 204 const SEC_PKCS12DecoderItem* decoder_item = NULL; |
206 SECKEYPrivateKey* privKey = PK11_FindKeyByDERCert(slot, | 205 // Iterate through all the imported PKCS12 items and mark any accompanying |
207 node->cert, | 206 // private keys as unextractable. |
208 NULL); // wincx | 207 while (SEC_PKCS12DecoderIterateNext(dcx, &decoder_item) == SECSuccess) { |
208 if (decoder_item->type != SEC_OID_PKCS12_V1_CERT_BAG_ID) | |
209 continue; | |
210 if (!decoder_item->hasKey) | |
211 continue; | |
212 | |
213 // Once we have determined that the imported certificate has an | |
214 // associated private key too, only then can we mark the key as | |
215 // unextractable. | |
216 CERTCertificate* cert = PK11_FindCertFromDERCertItem( | |
217 slot, const_cast<SECItem*>(decoder_item->der), | |
218 NULL); // wincx | |
219 SECKEYPrivateKey* privKey = PK11_FindPrivateKeyFromCert(slot, cert, | |
220 NULL); // wincx | |
209 if (privKey) { | 221 if (privKey) { |
210 // Mark the private key as unextractable. | 222 // Mark the private key as unextractable. |
211 srv = PK11_WriteRawAttribute(PK11_TypePrivKey, privKey, CKA_EXTRACTABLE, | 223 srv = PK11_WriteRawAttribute(PK11_TypePrivKey, privKey, CKA_EXTRACTABLE, |
212 &attribute_value); | 224 &attribute_value); |
213 SECKEY_DestroyPrivateKey(privKey); | 225 SECKEY_DestroyPrivateKey(privKey); |
214 if (srv) { | 226 } |
215 LOG(ERROR) << "Couldn't set CKA_EXTRACTABLE attribute on private " | 227 if (cert) CERT_DestroyCertificate(cert); |
216 << "key."; | 228 if (srv) { |
217 break; | 229 LOG(ERROR) << "Couldn't set CKA_EXTRACTABLE attribute on private key."; |
218 } | 230 break; |
219 } | 231 } |
wtc
2011/07/29 19:08:37
The if (srv) statement on lines 228-231 should be
gauravsh
2011/07/29 20:04:55
Done.
| |
220 } | 232 } |
221 CERT_DestroyCertList(cert_list); | |
222 if (srv) goto finish; | 233 if (srv) goto finish; |
223 } | 234 } |
224 | 235 |
225 import_result = net::OK; | 236 import_result = net::OK; |
226 finish: | 237 finish: |
227 // If srv != SECSuccess, NSS probably set a specific error code. | 238 // If srv != SECSuccess, NSS probably set a specific error code. |
228 // We should use that error code instead of inventing a new one | 239 // We should use that error code instead of inventing a new one |
229 // for every error possible. | 240 // for every error possible. |
230 if (srv != SECSuccess) { | 241 if (srv != SECSuccess) { |
231 int error = PORT_GetError(); | 242 int error = PORT_GetError(); |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
439 finish: | 450 finish: |
440 if (srv) | 451 if (srv) |
441 LOG(ERROR) << "PKCS#12 export failed with error " << PORT_GetError(); | 452 LOG(ERROR) << "PKCS#12 export failed with error " << PORT_GetError(); |
442 if (ecx) | 453 if (ecx) |
443 SEC_PKCS12DestroyExportContext(ecx); | 454 SEC_PKCS12DestroyExportContext(ecx); |
444 SECITEM_ZfreeItem(&unicodePw, PR_FALSE); | 455 SECITEM_ZfreeItem(&unicodePw, PR_FALSE); |
445 return return_count; | 456 return return_count; |
446 } | 457 } |
447 | 458 |
448 } // namespace mozilla_security_manager | 459 } // namespace mozilla_security_manager |
OLD | NEW |