| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/base/keygen_handler.h" | 5 #include "net/base/keygen_handler.h" |
| 6 | 6 |
| 7 #include <pk11pub.h> | 7 #include <pk11pub.h> |
| 8 #include <secmod.h> | 8 #include <secmod.h> |
| 9 #include <ssl.h> | 9 #include <ssl.h> |
| 10 #include <secder.h> // DER_Encode() | 10 #include <secder.h> // DER_Encode() |
| 11 #include <cryptohi.h> // SEC_DerSignData() | 11 #include <cryptohi.h> // SEC_DerSignData() |
| 12 #include <keyhi.h> // SECKEY_CreateSubjectPublicKeyInfo() | 12 #include <keyhi.h> // SECKEY_CreateSubjectPublicKeyInfo() |
| 13 | 13 |
| 14 #include "base/base64.h" | 14 #include "base/base64.h" |
| 15 #include "base/nss_util_internal.h" |
| 15 #include "base/nss_util.h" | 16 #include "base/nss_util.h" |
| 16 #include "base/logging.h" | 17 #include "base/logging.h" |
| 17 | 18 |
| 18 namespace net { | 19 namespace net { |
| 19 | 20 |
| 20 const int64 DEFAULT_RSA_PUBLIC_EXPONENT = 0x10001; | 21 const int64 DEFAULT_RSA_PUBLIC_EXPONENT = 0x10001; |
| 21 | 22 |
| 22 // Template for creating the signed public key structure to be sent to the CA. | 23 // Template for creating the signed public key structure to be sent to the CA. |
| 23 DERTemplate SECAlgorithmIDTemplate[] = { | 24 DERTemplate SECAlgorithmIDTemplate[] = { |
| 24 { DER_SEQUENCE, | 25 { DER_SEQUENCE, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 CERTPublicKeyAndChallenge pkac; | 91 CERTPublicKeyAndChallenge pkac; |
| 91 void *keyGenParams; | 92 void *keyGenParams; |
| 92 pkac.challenge.data = NULL; | 93 pkac.challenge.data = NULL; |
| 93 bool isSuccess = true; // Set to false as soon as a step fails. | 94 bool isSuccess = true; // Set to false as soon as a step fails. |
| 94 | 95 |
| 95 std::string result_blob; // the result. | 96 std::string result_blob; // the result. |
| 96 | 97 |
| 97 // Ensure NSS is initialized. | 98 // Ensure NSS is initialized. |
| 98 base::EnsureNSSInit(); | 99 base::EnsureNSSInit(); |
| 99 | 100 |
| 100 slot = PK11_GetInternalKeySlot(); | 101 slot = base::GetDefaultNSSKeySlot(); |
| 101 if (!slot) { | 102 if (!slot) { |
| 102 LOG(ERROR) << "Couldn't get Internal key slot!"; | 103 LOG(ERROR) << "Couldn't get Internal key slot!"; |
| 103 isSuccess = false; | 104 isSuccess = false; |
| 104 goto failure; | 105 goto failure; |
| 105 } | 106 } |
| 106 | 107 |
| 107 switch (keyGenMechanism) { | 108 switch (keyGenMechanism) { |
| 108 case CKM_RSA_PKCS_KEY_PAIR_GEN: | 109 case CKM_RSA_PKCS_KEY_PAIR_GEN: |
| 109 rsaKeyGenParams.keySizeInBits = key_size_in_bits_; | 110 rsaKeyGenParams.keySizeInBits = key_size_in_bits_; |
| 110 rsaKeyGenParams.pe = DEFAULT_RSA_PUBLIC_EXPONENT; | 111 rsaKeyGenParams.pe = DEFAULT_RSA_PUBLIC_EXPONENT; |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 PK11_FreeSlot(slot); | 245 PK11_FreeSlot(slot); |
| 245 } | 246 } |
| 246 if (pkac.challenge.data) { | 247 if (pkac.challenge.data) { |
| 247 free(pkac.challenge.data); | 248 free(pkac.challenge.data); |
| 248 } | 249 } |
| 249 | 250 |
| 250 return (isSuccess ? result_blob : std::string()); | 251 return (isSuccess ? result_blob : std::string()); |
| 251 } | 252 } |
| 252 | 253 |
| 253 } // namespace net | 254 } // namespace net |
| OLD | NEW |