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, decoder_item->der, |
| 218 NULL); // wincx |
| 219 if (!cert) { |
| 220 LOG(ERROR) << "Could not grab a handle to the certificate in the slot " |
| 221 << "from the corresponding PKCS#12 DER certificate."; |
| 222 continue; |
| 223 } |
| 224 SECKEYPrivateKey* privKey = PK11_FindPrivateKeyFromCert(slot, cert, |
| 225 NULL); // wincx |
| 226 CERT_DestroyCertificate(cert); |
209 if (privKey) { | 227 if (privKey) { |
210 // Mark the private key as unextractable. | 228 // Mark the private key as unextractable. |
211 srv = PK11_WriteRawAttribute(PK11_TypePrivKey, privKey, CKA_EXTRACTABLE, | 229 srv = PK11_WriteRawAttribute(PK11_TypePrivKey, privKey, CKA_EXTRACTABLE, |
212 &attribute_value); | 230 &attribute_value); |
213 SECKEY_DestroyPrivateKey(privKey); | 231 SECKEY_DestroyPrivateKey(privKey); |
214 if (srv) { | 232 if (srv) { |
215 LOG(ERROR) << "Couldn't set CKA_EXTRACTABLE attribute on private " | 233 LOG(ERROR) << "Could not set CKA_EXTRACTABLE attribute on private " |
216 << "key."; | 234 << "key."; |
217 break; | 235 break; |
218 } | 236 } |
219 } | 237 } |
220 } | 238 } |
221 CERT_DestroyCertList(cert_list); | |
222 if (srv) goto finish; | 239 if (srv) goto finish; |
223 } | 240 } |
224 | 241 |
225 import_result = net::OK; | 242 import_result = net::OK; |
226 finish: | 243 finish: |
227 // If srv != SECSuccess, NSS probably set a specific error code. | 244 // If srv != SECSuccess, NSS probably set a specific error code. |
228 // We should use that error code instead of inventing a new one | 245 // We should use that error code instead of inventing a new one |
229 // for every error possible. | 246 // for every error possible. |
230 if (srv != SECSuccess) { | 247 if (srv != SECSuccess) { |
231 int error = PORT_GetError(); | 248 int error = PORT_GetError(); |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 finish: | 456 finish: |
440 if (srv) | 457 if (srv) |
441 LOG(ERROR) << "PKCS#12 export failed with error " << PORT_GetError(); | 458 LOG(ERROR) << "PKCS#12 export failed with error " << PORT_GetError(); |
442 if (ecx) | 459 if (ecx) |
443 SEC_PKCS12DestroyExportContext(ecx); | 460 SEC_PKCS12DestroyExportContext(ecx); |
444 SECITEM_ZfreeItem(&unicodePw, PR_FALSE); | 461 SECITEM_ZfreeItem(&unicodePw, PR_FALSE); |
445 return return_count; | 462 return return_count; |
446 } | 463 } |
447 | 464 |
448 } // namespace mozilla_security_manager | 465 } // namespace mozilla_security_manager |
OLD | NEW |