| 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 24 matching lines...) Expand all Loading... |
| 35 * | 35 * |
| 36 * ***** END LICENSE BLOCK ***** */ | 36 * ***** END LICENSE BLOCK ***** */ |
| 37 | 37 |
| 38 #include "net/third_party/mozilla_security_manager/nsPKCS12Blob.h" | 38 #include "net/third_party/mozilla_security_manager/nsPKCS12Blob.h" |
| 39 | 39 |
| 40 #include <pk11pub.h> | 40 #include <pk11pub.h> |
| 41 #include <pkcs12.h> | 41 #include <pkcs12.h> |
| 42 #include <p12plcy.h> | 42 #include <p12plcy.h> |
| 43 #include <secerr.h> | 43 #include <secerr.h> |
| 44 | 44 |
| 45 #include "base/crypto/scoped_nss_types.h" |
| 45 #include "base/logging.h" | 46 #include "base/logging.h" |
| 46 #include "base/nss_util_internal.h" | 47 #include "base/nss_util_internal.h" |
| 47 #include "base/string_util.h" | 48 #include "base/string_util.h" |
| 48 #include "net/base/net_errors.h" | 49 #include "net/base/net_errors.h" |
| 49 #include "net/base/x509_certificate.h" | 50 #include "net/base/x509_certificate.h" |
| 50 | 51 |
| 51 namespace mozilla_security_manager { | 52 namespace mozilla_security_manager { |
| 52 | 53 |
| 53 namespace { | 54 namespace { |
| 54 | 55 |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 } // namespace | 254 } // namespace |
| 254 | 255 |
| 255 void EnsurePKCS12Init() { | 256 void EnsurePKCS12Init() { |
| 256 Singleton<PKCS12InitSingleton>::get(); | 257 Singleton<PKCS12InitSingleton>::get(); |
| 257 } | 258 } |
| 258 | 259 |
| 259 // Based on nsPKCS12Blob::ImportFromFile. | 260 // Based on nsPKCS12Blob::ImportFromFile. |
| 260 int nsPKCS12Blob_Import(const char* pkcs12_data, | 261 int nsPKCS12Blob_Import(const char* pkcs12_data, |
| 261 size_t pkcs12_len, | 262 size_t pkcs12_len, |
| 262 const string16& password) { | 263 const string16& password) { |
| 263 PK11SlotInfo *slot = base::GetDefaultNSSKeySlot(); | 264 base::ScopedPK11Slot slot(base::GetDefaultNSSKeySlot()); |
| 264 if (!slot) { | 265 if (!slot.get()) { |
| 265 LOG(ERROR) << "Couldn't get Internal key slot!"; | 266 LOG(ERROR) << "Couldn't get Internal key slot!"; |
| 266 return net::ERR_PKCS12_IMPORT_FAILED; | 267 return net::ERR_PKCS12_IMPORT_FAILED; |
| 267 } | 268 } |
| 268 | 269 |
| 269 int rv = nsPKCS12Blob_ImportHelper(pkcs12_data, pkcs12_len, password, false, | 270 int rv = nsPKCS12Blob_ImportHelper(pkcs12_data, pkcs12_len, password, false, |
| 270 slot); | 271 slot.get()); |
| 271 | 272 |
| 272 // When the user entered a zero length password: | 273 // When the user entered a zero length password: |
| 273 // An empty password should be represented as an empty | 274 // An empty password should be represented as an empty |
| 274 // string (a SECItem that contains a single terminating | 275 // string (a SECItem that contains a single terminating |
| 275 // NULL UTF16 character), but some applications use a | 276 // NULL UTF16 character), but some applications use a |
| 276 // zero length SECItem. | 277 // zero length SECItem. |
| 277 // We try both variations, zero length item and empty string, | 278 // We try both variations, zero length item and empty string, |
| 278 // 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. |
| 279 if (rv == net::ERR_PKCS12_IMPORT_BAD_PASSWORD && password.size() == 0) { | 280 if (rv == net::ERR_PKCS12_IMPORT_BAD_PASSWORD && password.size() == 0) { |
| 280 rv = nsPKCS12Blob_ImportHelper(pkcs12_data, pkcs12_len, password, true, | 281 rv = nsPKCS12Blob_ImportHelper(pkcs12_data, pkcs12_len, password, true, |
| 281 slot); | 282 slot.get()); |
| 282 } | 283 } |
| 283 | |
| 284 PK11_FreeSlot(slot); | |
| 285 return rv; | 284 return rv; |
| 286 } | 285 } |
| 287 | 286 |
| 288 // Based on nsPKCS12Blob::ExportToFile | 287 // Based on nsPKCS12Blob::ExportToFile |
| 289 // | 288 // |
| 290 // 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 |
| 291 // also), encode the blob, and stuff it into the file. | 290 // also), encode the blob, and stuff it into the file. |
| 292 // | 291 // |
| 293 // TODO: handle slots correctly | 292 // TODO: handle slots correctly |
| 294 // mirror "slotToUse" behavior from PSM 1.x | 293 // mirror "slotToUse" behavior from PSM 1.x |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 finish: | 387 finish: |
| 389 if (srv) | 388 if (srv) |
| 390 LOG(ERROR) << "PKCS#12 export failed with error " << PORT_GetError(); | 389 LOG(ERROR) << "PKCS#12 export failed with error " << PORT_GetError(); |
| 391 if (ecx) | 390 if (ecx) |
| 392 SEC_PKCS12DestroyExportContext(ecx); | 391 SEC_PKCS12DestroyExportContext(ecx); |
| 393 SECITEM_ZfreeItem(&unicodePw, PR_FALSE); | 392 SECITEM_ZfreeItem(&unicodePw, PR_FALSE); |
| 394 return return_count; | 393 return return_count; |
| 395 } | 394 } |
| 396 | 395 |
| 397 } // namespace mozilla_security_manager | 396 } // namespace mozilla_security_manager |
| OLD | NEW |