OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "net/ssl/ssl_platform_key_util.h" |
| 6 |
| 7 #include <openssl/ecdsa.h> |
| 8 #include <stddef.h> |
| 9 |
| 10 #include "base/memory/ref_counted.h" |
| 11 #include "net/cert/x509_certificate.h" |
| 12 #include "net/ssl/ssl_private_key.h" |
| 13 #include "net/test/cert_test_util.h" |
| 14 #include "net/test/test_data_directory.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 |
| 17 namespace net { |
| 18 |
| 19 namespace { |
| 20 |
| 21 bool GetClientCertInfoFromFile(const char* filename, |
| 22 SSLPrivateKey::Type* out_type, |
| 23 size_t* out_max_length) { |
| 24 scoped_refptr<X509Certificate> cert = |
| 25 ImportCertFromFile(GetTestCertsDirectory(), filename); |
| 26 if (!cert) { |
| 27 ADD_FAILURE() << "Could not read " << filename; |
| 28 return false; |
| 29 } |
| 30 |
| 31 return GetClientCertInfo(cert.get(), out_type, out_max_length); |
| 32 } |
| 33 |
| 34 } // namespace |
| 35 |
| 36 TEST(SSLPlatformKeyUtil, GetClientCertInfo) { |
| 37 SSLPrivateKey::Type type; |
| 38 size_t max_length; |
| 39 |
| 40 ASSERT_TRUE(GetClientCertInfoFromFile("client_1.pem", &type, &max_length)); |
| 41 EXPECT_EQ(SSLPrivateKey::Type::RSA, type); |
| 42 EXPECT_EQ(2048u / 8u, max_length); |
| 43 |
| 44 ASSERT_TRUE(GetClientCertInfoFromFile("client_4.pem", &type, &max_length)); |
| 45 EXPECT_EQ(SSLPrivateKey::Type::ECDSA_P256, type); |
| 46 EXPECT_EQ(ECDSA_SIG_max_len(256u / 8u), max_length); |
| 47 } |
| 48 |
| 49 } // namespace net |
OLD | NEW |