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