| 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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 } | 252 } |
| 253 }; | 253 }; |
| 254 | 254 |
| 255 } // namespace | 255 } // namespace |
| 256 | 256 |
| 257 void EnsurePKCS12Init() { | 257 void EnsurePKCS12Init() { |
| 258 Singleton<PKCS12InitSingleton>::get(); | 258 Singleton<PKCS12InitSingleton>::get(); |
| 259 } | 259 } |
| 260 | 260 |
| 261 // Based on nsPKCS12Blob::ImportFromFile. | 261 // Based on nsPKCS12Blob::ImportFromFile. |
| 262 int nsPKCS12Blob_Import(const char* pkcs12_data, | 262 int nsPKCS12Blob_Import(PK11SlotInfo* slot, |
| 263 const char* pkcs12_data, |
| 263 size_t pkcs12_len, | 264 size_t pkcs12_len, |
| 264 const string16& password) { | 265 const string16& password) { |
| 265 base::ScopedPK11Slot slot(base::GetDefaultNSSKeySlot()); | |
| 266 if (!slot.get()) { | |
| 267 LOG(ERROR) << "Couldn't get Internal key slot!"; | |
| 268 return net::ERR_PKCS12_IMPORT_FAILED; | |
| 269 } | |
| 270 | 266 |
| 271 int rv = nsPKCS12Blob_ImportHelper(pkcs12_data, pkcs12_len, password, false, | 267 int rv = nsPKCS12Blob_ImportHelper(pkcs12_data, pkcs12_len, password, false, |
| 272 slot.get()); | 268 slot); |
| 273 | 269 |
| 274 // When the user entered a zero length password: | 270 // When the user entered a zero length password: |
| 275 // An empty password should be represented as an empty | 271 // An empty password should be represented as an empty |
| 276 // string (a SECItem that contains a single terminating | 272 // string (a SECItem that contains a single terminating |
| 277 // NULL UTF16 character), but some applications use a | 273 // NULL UTF16 character), but some applications use a |
| 278 // zero length SECItem. | 274 // zero length SECItem. |
| 279 // We try both variations, zero length item and empty string, | 275 // We try both variations, zero length item and empty string, |
| 280 // without giving a user prompt when trying the different empty password fla
vors. | 276 // without giving a user prompt when trying the different empty password fla
vors. |
| 281 if (rv == net::ERR_PKCS12_IMPORT_BAD_PASSWORD && password.size() == 0) { | 277 if (rv == net::ERR_PKCS12_IMPORT_BAD_PASSWORD && password.size() == 0) { |
| 282 rv = nsPKCS12Blob_ImportHelper(pkcs12_data, pkcs12_len, password, true, | 278 rv = nsPKCS12Blob_ImportHelper(pkcs12_data, pkcs12_len, password, true, |
| 283 slot.get()); | 279 slot); |
| 284 } | 280 } |
| 285 return rv; | 281 return rv; |
| 286 } | 282 } |
| 287 | 283 |
| 288 // Based on nsPKCS12Blob::ExportToFile | 284 // Based on nsPKCS12Blob::ExportToFile |
| 289 // | 285 // |
| 290 // Having already loaded the certs, form them into a blob (loading the keys | 286 // Having already loaded the certs, form them into a blob (loading the keys |
| 291 // also), encode the blob, and stuff it into the file. | 287 // also), encode the blob, and stuff it into the file. |
| 292 // | 288 // |
| 293 // TODO: handle slots correctly | 289 // TODO: handle slots correctly |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 finish: | 384 finish: |
| 389 if (srv) | 385 if (srv) |
| 390 LOG(ERROR) << "PKCS#12 export failed with error " << PORT_GetError(); | 386 LOG(ERROR) << "PKCS#12 export failed with error " << PORT_GetError(); |
| 391 if (ecx) | 387 if (ecx) |
| 392 SEC_PKCS12DestroyExportContext(ecx); | 388 SEC_PKCS12DestroyExportContext(ecx); |
| 393 SECITEM_ZfreeItem(&unicodePw, PR_FALSE); | 389 SECITEM_ZfreeItem(&unicodePw, PR_FALSE); |
| 394 return return_count; | 390 return return_count; |
| 395 } | 391 } |
| 396 | 392 |
| 397 } // namespace mozilla_security_manager | 393 } // namespace mozilla_security_manager |
| OLD | NEW |