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

Side by Side Diff: net/ssl/ssl_platform_key_util_unittest.cc

Issue 2822283002: Remove SSLPrivateKey metadata hooks. (Closed)
Patch Set: emaxx comment Created 3 years, 8 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
« no previous file with comments | « net/ssl/ssl_platform_key_util.cc ('k') | net/ssl/ssl_platform_key_win.cc » ('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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/ssl/ssl_platform_key_util.h" 5 #include "net/ssl/ssl_platform_key_util.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "net/cert/x509_certificate.h" 10 #include "net/cert/x509_certificate.h"
11 #include "net/ssl/ssl_private_key.h" 11 #include "net/ssl/ssl_private_key.h"
12 #include "net/test/cert_test_util.h" 12 #include "net/test/cert_test_util.h"
13 #include "net/test/test_data_directory.h" 13 #include "net/test/test_data_directory.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "third_party/boringssl/src/include/openssl/ecdsa.h" 15 #include "third_party/boringssl/src/include/openssl/ecdsa.h"
16 #include "third_party/boringssl/src/include/openssl/evp.h"
16 17
17 namespace net { 18 namespace net {
18 19
19 namespace { 20 namespace {
20 21
21 bool GetClientCertInfoFromFile(const char* filename, 22 bool GetClientCertInfoFromFile(const char* filename,
22 SSLPrivateKey::Type* out_type, 23 int* out_type,
23 size_t* out_max_length) { 24 size_t* out_max_length) {
24 scoped_refptr<X509Certificate> cert = 25 scoped_refptr<X509Certificate> cert =
25 ImportCertFromFile(GetTestCertsDirectory(), filename); 26 ImportCertFromFile(GetTestCertsDirectory(), filename);
26 if (!cert) { 27 if (!cert) {
27 ADD_FAILURE() << "Could not read " << filename; 28 ADD_FAILURE() << "Could not read " << filename;
28 return false; 29 return false;
29 } 30 }
30 31
31 return GetClientCertInfo(cert.get(), out_type, out_max_length); 32 return GetClientCertInfo(cert.get(), out_type, out_max_length);
32 } 33 }
33 34
34 size_t BitsToBytes(size_t bits) { 35 size_t BitsToBytes(size_t bits) {
35 return (bits + 7) / 8; 36 return (bits + 7) / 8;
36 } 37 }
37 38
38 } // namespace 39 } // namespace
39 40
40 TEST(SSLPlatformKeyUtil, GetClientCertInfo) { 41 TEST(SSLPlatformKeyUtil, GetClientCertInfo) {
41 SSLPrivateKey::Type type; 42 int type;
42 size_t max_length; 43 size_t max_length;
43 44
44 ASSERT_TRUE(GetClientCertInfoFromFile("client_1.pem", &type, &max_length)); 45 ASSERT_TRUE(GetClientCertInfoFromFile("client_1.pem", &type, &max_length));
45 EXPECT_EQ(SSLPrivateKey::Type::RSA, type); 46 EXPECT_EQ(EVP_PKEY_RSA, type);
46 EXPECT_EQ(2048u / 8u, max_length); 47 EXPECT_EQ(2048u / 8u, max_length);
47 48
48 ASSERT_TRUE(GetClientCertInfoFromFile("client_4.pem", &type, &max_length)); 49 ASSERT_TRUE(GetClientCertInfoFromFile("client_4.pem", &type, &max_length));
49 EXPECT_EQ(SSLPrivateKey::Type::ECDSA_P256, type); 50 EXPECT_EQ(EVP_PKEY_EC, type);
50 EXPECT_EQ(ECDSA_SIG_max_len(BitsToBytes(256)), max_length); 51 EXPECT_EQ(ECDSA_SIG_max_len(BitsToBytes(256)), max_length);
51 52
52 ASSERT_TRUE(GetClientCertInfoFromFile("client_5.pem", &type, &max_length)); 53 ASSERT_TRUE(GetClientCertInfoFromFile("client_5.pem", &type, &max_length));
53 EXPECT_EQ(SSLPrivateKey::Type::ECDSA_P384, type); 54 EXPECT_EQ(EVP_PKEY_EC, type);
54 EXPECT_EQ(ECDSA_SIG_max_len(BitsToBytes(384)), max_length); 55 EXPECT_EQ(ECDSA_SIG_max_len(BitsToBytes(384)), max_length);
55 56
56 ASSERT_TRUE(GetClientCertInfoFromFile("client_6.pem", &type, &max_length)); 57 ASSERT_TRUE(GetClientCertInfoFromFile("client_6.pem", &type, &max_length));
57 EXPECT_EQ(SSLPrivateKey::Type::ECDSA_P521, type); 58 EXPECT_EQ(EVP_PKEY_EC, type);
58 EXPECT_EQ(ECDSA_SIG_max_len(BitsToBytes(521)), max_length); 59 EXPECT_EQ(ECDSA_SIG_max_len(BitsToBytes(521)), max_length);
59 } 60 }
60 61
61 } // namespace net 62 } // namespace net
OLDNEW
« no previous file with comments | « net/ssl/ssl_platform_key_util.cc ('k') | net/ssl/ssl_platform_key_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698