| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <openssl/bn.h> | 5 #include <openssl/bn.h> |
| 6 #include <openssl/dsa.h> | 6 #include <openssl/dsa.h> |
| 7 #include <openssl/ecdsa.h> | 7 #include <openssl/ecdsa.h> |
| 8 #include <openssl/err.h> | 8 #include <openssl/err.h> |
| 9 #include <openssl/evp.h> | 9 #include <openssl/evp.h> |
| 10 #include <openssl/pem.h> | 10 #include <openssl/pem.h> |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 return reinterpret_cast<unsigned char*>(WriteInto(str, size + 1)); | 110 return reinterpret_cast<unsigned char*>(WriteInto(str, size + 1)); |
| 111 } | 111 } |
| 112 | 112 |
| 113 // Load a given private key file into an EVP_PKEY. | 113 // Load a given private key file into an EVP_PKEY. |
| 114 // |filename| is the key file path. | 114 // |filename| is the key file path. |
| 115 // Returns a new EVP_PKEY on success, NULL on failure. | 115 // Returns a new EVP_PKEY on success, NULL on failure. |
| 116 EVP_PKEY* ImportPrivateKeyFile(const char* filename) { | 116 EVP_PKEY* ImportPrivateKeyFile(const char* filename) { |
| 117 // Load file in memory. | 117 // Load file in memory. |
| 118 base::FilePath certs_dir = GetTestCertsDirectory(); | 118 base::FilePath certs_dir = GetTestCertsDirectory(); |
| 119 base::FilePath file_path = certs_dir.AppendASCII(filename); | 119 base::FilePath file_path = certs_dir.AppendASCII(filename); |
| 120 ScopedStdioHandle handle( | 120 ScopedStdioHandle handle(base::OpenFile(file_path, "rb")); |
| 121 file_util::OpenFile(file_path, "rb")); | |
| 122 if (!handle.get()) { | 121 if (!handle.get()) { |
| 123 LOG(ERROR) << "Could not open private key file: " << filename; | 122 LOG(ERROR) << "Could not open private key file: " << filename; |
| 124 return NULL; | 123 return NULL; |
| 125 } | 124 } |
| 126 // Assume it is PEM_encoded. Load it as an EVP_PKEY. | 125 // Assume it is PEM_encoded. Load it as an EVP_PKEY. |
| 127 EVP_PKEY* pkey = PEM_read_PrivateKey(handle.get(), NULL, NULL, NULL); | 126 EVP_PKEY* pkey = PEM_read_PrivateKey(handle.get(), NULL, NULL, NULL); |
| 128 if (!pkey) { | 127 if (!pkey) { |
| 129 LOG(ERROR) << "Could not load public key file: " << filename | 128 LOG(ERROR) << "Could not load public key file: " << filename |
| 130 << ", " << GetOpenSSLErrorString(); | 129 << ", " << GetOpenSSLErrorString(); |
| 131 return NULL; | 130 return NULL; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 160 if (!pkey.get()) | 159 if (!pkey.get()) |
| 161 return false; | 160 return false; |
| 162 return GetPrivateKeyPkcs8Bytes(pkey, pkcs8); | 161 return GetPrivateKeyPkcs8Bytes(pkey, pkcs8); |
| 163 } | 162 } |
| 164 | 163 |
| 165 // Same as ImportPrivateKey, but for public ones. | 164 // Same as ImportPrivateKey, but for public ones. |
| 166 EVP_PKEY* ImportPublicKeyFile(const char* filename) { | 165 EVP_PKEY* ImportPublicKeyFile(const char* filename) { |
| 167 // Load file as PEM data. | 166 // Load file as PEM data. |
| 168 base::FilePath certs_dir = GetTestCertsDirectory(); | 167 base::FilePath certs_dir = GetTestCertsDirectory(); |
| 169 base::FilePath file_path = certs_dir.AppendASCII(filename); | 168 base::FilePath file_path = certs_dir.AppendASCII(filename); |
| 170 ScopedStdioHandle handle(file_util::OpenFile(file_path, "rb")); | 169 ScopedStdioHandle handle(base::OpenFile(file_path, "rb")); |
| 171 if (!handle.get()) { | 170 if (!handle.get()) { |
| 172 LOG(ERROR) << "Could not open public key file: " << filename; | 171 LOG(ERROR) << "Could not open public key file: " << filename; |
| 173 return NULL; | 172 return NULL; |
| 174 } | 173 } |
| 175 EVP_PKEY* pkey = PEM_read_PUBKEY(handle.get(), NULL, NULL, NULL); | 174 EVP_PKEY* pkey = PEM_read_PUBKEY(handle.get(), NULL, NULL, NULL); |
| 176 if (!pkey) { | 175 if (!pkey) { |
| 177 LOG(ERROR) << "Could not load public key file: " << filename | 176 LOG(ERROR) << "Could not load public key file: " << filename |
| 178 << ", " << GetOpenSSLErrorString(); | 177 << ", " << GetOpenSSLErrorString(); |
| 179 return NULL; | 178 return NULL; |
| 180 } | 179 } |
| (...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 std::string signature; | 715 std::string signature; |
| 717 DoKeySigningWithWrapper(wrapper_key.get(), | 716 DoKeySigningWithWrapper(wrapper_key.get(), |
| 718 openssl_key.get(), | 717 openssl_key.get(), |
| 719 message, | 718 message, |
| 720 &signature); | 719 &signature); |
| 721 ASSERT_TRUE(VerifyTestECDSASignature(message, signature)); | 720 ASSERT_TRUE(VerifyTestECDSASignature(message, signature)); |
| 722 } | 721 } |
| 723 | 722 |
| 724 } // namespace android | 723 } // namespace android |
| 725 } // namespace net | 724 } // namespace net |
| OLD | NEW |