| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <Security/SecAsn1Coder.h> | 7 #include <Security/SecAsn1Coder.h> |
| 8 #include <Security/SecAsn1Templates.h> | 8 #include <Security/SecAsn1Templates.h> |
| 9 #include <Security/Security.h> | 9 #include <Security/Security.h> |
| 10 | 10 |
| 11 #include "base/base64.h" | 11 #include "base/base64.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/mac/mac_logging.h" |
| 13 #include "base/mac/scoped_cftyperef.h" | 14 #include "base/mac/scoped_cftyperef.h" |
| 14 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 15 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
| 16 #include "base/sys_string_conversions.h" | 17 #include "base/sys_string_conversions.h" |
| 17 #include "crypto/cssm_init.h" | 18 #include "crypto/cssm_init.h" |
| 18 #include "crypto/mac_security_services_lock.h" | 19 #include "crypto/mac_security_services_lock.h" |
| 19 | 20 |
| 20 // These are in Security.framework but not declared in a public header. | 21 // These are in Security.framework but not declared in a public header. |
| 21 extern const SecAsn1Template kSecAsn1AlgorithmIDTemplate[]; | 22 extern const SecAsn1Template kSecAsn1AlgorithmIDTemplate[]; |
| 22 extern const SecAsn1Template kSecAsn1SubjectPublicKeyInfoTemplate[]; | 23 extern const SecAsn1Template kSecAsn1SubjectPublicKeyInfoTemplate[]; |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 goto failure; | 186 goto failure; |
| 186 } | 187 } |
| 187 | 188 |
| 188 // Base64 encode the result. | 189 // Base64 encode the result. |
| 189 std::string input(reinterpret_cast<char*>(encoded.Data), encoded.Length); | 190 std::string input(reinterpret_cast<char*>(encoded.Data), encoded.Length); |
| 190 base::Base64Encode(input, &result); | 191 base::Base64Encode(input, &result); |
| 191 } | 192 } |
| 192 | 193 |
| 193 failure: | 194 failure: |
| 194 if (err) | 195 if (err) |
| 195 LOG(ERROR) << "SSL Keygen failed! OSStatus = " << err; | 196 OSSTATUS_LOG(ERROR, err) << "SSL Keygen failed!"; |
| 196 else | 197 else |
| 197 VLOG(1) << "SSL Keygen succeeded! Output is: " << result; | 198 VLOG(1) << "SSL Keygen succeeded! Output is: " << result; |
| 198 | 199 |
| 199 // Remove keys from keychain if asked to during unit testing: | 200 // Remove keys from keychain if asked to during unit testing: |
| 200 if (!stores_key_) { | 201 if (!stores_key_) { |
| 201 if (public_key) | 202 if (public_key) |
| 202 SecKeychainItemDelete(reinterpret_cast<SecKeychainItemRef>(public_key)); | 203 SecKeychainItemDelete(reinterpret_cast<SecKeychainItemRef>(public_key)); |
| 203 if (private_key) | 204 if (private_key) |
| 204 SecKeychainItemDelete(reinterpret_cast<SecKeychainItemRef>(private_key)); | 205 SecKeychainItemDelete(reinterpret_cast<SecKeychainItemRef>(private_key)); |
| 205 } | 206 } |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 return err; | 316 return err; |
| 316 } | 317 } |
| 317 err = CSSM_SignData(cc_handle, &data, 1, CSSM_ALGID_NONE, signature); | 318 err = CSSM_SignData(cc_handle, &data, 1, CSSM_ALGID_NONE, signature); |
| 318 if (err) | 319 if (err) |
| 319 crypto::LogCSSMError("CSSM_SignData", err); | 320 crypto::LogCSSMError("CSSM_SignData", err); |
| 320 CSSM_DeleteContext(cc_handle); | 321 CSSM_DeleteContext(cc_handle); |
| 321 return err; | 322 return err; |
| 322 } | 323 } |
| 323 | 324 |
| 324 } // namespace net | 325 } // namespace net |
| OLD | NEW |