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(base::OpenFile(file_path, "rb")); | 120 ScopedStdioHandle handle( |
| 121 file_util::OpenFile(file_path, "rb")); |
121 if (!handle.get()) { | 122 if (!handle.get()) { |
122 LOG(ERROR) << "Could not open private key file: " << filename; | 123 LOG(ERROR) << "Could not open private key file: " << filename; |
123 return NULL; | 124 return NULL; |
124 } | 125 } |
125 // Assume it is PEM_encoded. Load it as an EVP_PKEY. | 126 // Assume it is PEM_encoded. Load it as an EVP_PKEY. |
126 EVP_PKEY* pkey = PEM_read_PrivateKey(handle.get(), NULL, NULL, NULL); | 127 EVP_PKEY* pkey = PEM_read_PrivateKey(handle.get(), NULL, NULL, NULL); |
127 if (!pkey) { | 128 if (!pkey) { |
128 LOG(ERROR) << "Could not load public key file: " << filename | 129 LOG(ERROR) << "Could not load public key file: " << filename |
129 << ", " << GetOpenSSLErrorString(); | 130 << ", " << GetOpenSSLErrorString(); |
130 return NULL; | 131 return NULL; |
(...skipping 28 matching lines...) Expand all Loading... |
159 if (!pkey.get()) | 160 if (!pkey.get()) |
160 return false; | 161 return false; |
161 return GetPrivateKeyPkcs8Bytes(pkey, pkcs8); | 162 return GetPrivateKeyPkcs8Bytes(pkey, pkcs8); |
162 } | 163 } |
163 | 164 |
164 // Same as ImportPrivateKey, but for public ones. | 165 // Same as ImportPrivateKey, but for public ones. |
165 EVP_PKEY* ImportPublicKeyFile(const char* filename) { | 166 EVP_PKEY* ImportPublicKeyFile(const char* filename) { |
166 // Load file as PEM data. | 167 // Load file as PEM data. |
167 base::FilePath certs_dir = GetTestCertsDirectory(); | 168 base::FilePath certs_dir = GetTestCertsDirectory(); |
168 base::FilePath file_path = certs_dir.AppendASCII(filename); | 169 base::FilePath file_path = certs_dir.AppendASCII(filename); |
169 ScopedStdioHandle handle(base::OpenFile(file_path, "rb")); | 170 ScopedStdioHandle handle(file_util::OpenFile(file_path, "rb")); |
170 if (!handle.get()) { | 171 if (!handle.get()) { |
171 LOG(ERROR) << "Could not open public key file: " << filename; | 172 LOG(ERROR) << "Could not open public key file: " << filename; |
172 return NULL; | 173 return NULL; |
173 } | 174 } |
174 EVP_PKEY* pkey = PEM_read_PUBKEY(handle.get(), NULL, NULL, NULL); | 175 EVP_PKEY* pkey = PEM_read_PUBKEY(handle.get(), NULL, NULL, NULL); |
175 if (!pkey) { | 176 if (!pkey) { |
176 LOG(ERROR) << "Could not load public key file: " << filename | 177 LOG(ERROR) << "Could not load public key file: " << filename |
177 << ", " << GetOpenSSLErrorString(); | 178 << ", " << GetOpenSSLErrorString(); |
178 return NULL; | 179 return NULL; |
179 } | 180 } |
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
715 std::string signature; | 716 std::string signature; |
716 DoKeySigningWithWrapper(wrapper_key.get(), | 717 DoKeySigningWithWrapper(wrapper_key.get(), |
717 openssl_key.get(), | 718 openssl_key.get(), |
718 message, | 719 message, |
719 &signature); | 720 &signature); |
720 ASSERT_TRUE(VerifyTestECDSASignature(message, signature)); | 721 ASSERT_TRUE(VerifyTestECDSASignature(message, signature)); |
721 } | 722 } |
722 | 723 |
723 } // namespace android | 724 } // namespace android |
724 } // namespace net | 725 } // namespace net |
OLD | NEW |