Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(329)

Side by Side Diff: net/android/keystore_unittest.cc

Issue 324773002: Remove base/memory/scoped_handle.h (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/renderer/render_thread_impl.cc ('k') | net/base/net_log_logger.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
11 #include <openssl/rsa.h> 11 #include <openssl/rsa.h>
12 #include <openssl/x509.h> 12 #include <openssl/x509.h>
13 13
14 #include "base/android/build_info.h" 14 #include "base/android/build_info.h"
15 #include "base/android/jni_android.h" 15 #include "base/android/jni_android.h"
16 #include "base/android/jni_array.h" 16 #include "base/android/jni_array.h"
17 #include "base/android/scoped_java_ref.h" 17 #include "base/android/scoped_java_ref.h"
18 #include "base/basictypes.h" 18 #include "base/basictypes.h"
19 #include "base/bind.h" 19 #include "base/bind.h"
20 #include "base/callback.h" 20 #include "base/callback.h"
21 #include "base/compiler_specific.h" 21 #include "base/compiler_specific.h"
22 #include "base/file_util.h" 22 #include "base/file_util.h"
23 #include "base/files/file_path.h" 23 #include "base/files/file_path.h"
24 #include "base/memory/scoped_handle.h" 24 #include "base/files/scoped_file.h"
25 #include "base/strings/string_number_conversions.h" 25 #include "base/strings/string_number_conversions.h"
26 #include "base/strings/string_util.h" 26 #include "base/strings/string_util.h"
27 #include "crypto/openssl_util.h" 27 #include "crypto/openssl_util.h"
28 #include "jni/AndroidKeyStoreTestUtil_jni.h" 28 #include "jni/AndroidKeyStoreTestUtil_jni.h"
29 #include "net/android/keystore.h" 29 #include "net/android/keystore.h"
30 #include "net/android/keystore_openssl.h" 30 #include "net/android/keystore_openssl.h"
31 #include "net/base/test_data_directory.h" 31 #include "net/base/test_data_directory.h"
32 #include "testing/gtest/include/gtest/gtest.h" 32 #include "testing/gtest/include/gtest/gtest.h"
33 33
34 // Technical note: 34 // Technical note:
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 base::ScopedFILE handle(base::OpenFile(file_path, "rb"));
121 if (!handle.get()) { 121 if (!handle.get()) {
122 LOG(ERROR) << "Could not open private key file: " << filename; 122 LOG(ERROR) << "Could not open private key file: " << filename;
123 return NULL; 123 return NULL;
124 } 124 }
125 // Assume it is PEM_encoded. Load it as an EVP_PKEY. 125 // Assume it is PEM_encoded. Load it as an EVP_PKEY.
126 EVP_PKEY* pkey = PEM_read_PrivateKey(handle.get(), NULL, NULL, NULL); 126 EVP_PKEY* pkey = PEM_read_PrivateKey(handle.get(), NULL, NULL, NULL);
127 if (!pkey) { 127 if (!pkey) {
128 LOG(ERROR) << "Could not load public key file: " << filename 128 LOG(ERROR) << "Could not load public key file: " << filename
129 << ", " << GetOpenSSLErrorString(); 129 << ", " << GetOpenSSLErrorString();
130 return NULL; 130 return NULL;
(...skipping 28 matching lines...) Expand all
159 if (!pkey.get()) 159 if (!pkey.get())
160 return false; 160 return false;
161 return GetPrivateKeyPkcs8Bytes(pkey, pkcs8); 161 return GetPrivateKeyPkcs8Bytes(pkey, pkcs8);
162 } 162 }
163 163
164 // Same as ImportPrivateKey, but for public ones. 164 // Same as ImportPrivateKey, but for public ones.
165 EVP_PKEY* ImportPublicKeyFile(const char* filename) { 165 EVP_PKEY* ImportPublicKeyFile(const char* filename) {
166 // Load file as PEM data. 166 // Load file as PEM data.
167 base::FilePath certs_dir = GetTestCertsDirectory(); 167 base::FilePath certs_dir = GetTestCertsDirectory();
168 base::FilePath file_path = certs_dir.AppendASCII(filename); 168 base::FilePath file_path = certs_dir.AppendASCII(filename);
169 ScopedStdioHandle handle(base::OpenFile(file_path, "rb")); 169 base::ScopedFILE handle(base::OpenFile(file_path, "rb"));
170 if (!handle.get()) { 170 if (!handle.get()) {
171 LOG(ERROR) << "Could not open public key file: " << filename; 171 LOG(ERROR) << "Could not open public key file: " << filename;
172 return NULL; 172 return NULL;
173 } 173 }
174 EVP_PKEY* pkey = PEM_read_PUBKEY(handle.get(), NULL, NULL, NULL); 174 EVP_PKEY* pkey = PEM_read_PUBKEY(handle.get(), NULL, NULL, NULL);
175 if (!pkey) { 175 if (!pkey) {
176 LOG(ERROR) << "Could not load public key file: " << filename 176 LOG(ERROR) << "Could not load public key file: " << filename
177 << ", " << GetOpenSSLErrorString(); 177 << ", " << GetOpenSSLErrorString();
178 return NULL; 178 return NULL;
179 } 179 }
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 std::string signature; 715 std::string signature;
716 DoKeySigningWithWrapper(wrapper_key.get(), 716 DoKeySigningWithWrapper(wrapper_key.get(),
717 openssl_key.get(), 717 openssl_key.get(),
718 message, 718 message,
719 &signature); 719 &signature);
720 ASSERT_TRUE(VerifyTestECDSASignature(message, signature)); 720 ASSERT_TRUE(VerifyTestECDSASignature(message, signature));
721 } 721 }
722 722
723 } // namespace android 723 } // namespace android
724 } // namespace net 724 } // namespace net
OLDNEW
« no previous file with comments | « content/renderer/render_thread_impl.cc ('k') | net/base/net_log_logger.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698