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

Side by Side Diff: net/cert/x509_certificate_unittest.cc

Issue 1720653002: Add new functions to handle UPN and email addresses (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix ios build breakage Created 4 years, 9 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 | « no previous file | net/cert/x509_util_nss.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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/cert/x509_certificate.h" 5 #include "net/cert/x509_certificate.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/pickle.h" 11 #include "base/pickle.h"
12 #include "base/sha1.h" 12 #include "base/sha1.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/string_split.h" 14 #include "base/strings/string_split.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "crypto/rsa_private_key.h" 16 #include "crypto/rsa_private_key.h"
17 #include "net/base/net_errors.h" 17 #include "net/base/net_errors.h"
18 #include "net/base/test_data_directory.h" 18 #include "net/base/test_data_directory.h"
19 #include "net/cert/asn1_util.h" 19 #include "net/cert/asn1_util.h"
20 #include "net/cert/x509_util_nss.h"
20 #include "net/test/cert_test_util.h" 21 #include "net/test/cert_test_util.h"
21 #include "net/test/test_certificate_data.h" 22 #include "net/test/test_certificate_data.h"
22 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
23 24
24 #if defined(USE_NSS_CERTS) 25 #if defined(USE_NSS_CERTS)
25 #include <cert.h> 26 #include <cert.h>
26 #endif 27 #endif
27 28
28 #if defined(OS_WIN) 29 #if defined(OS_WIN)
29 #include "base/win/windows_version.h" 30 #include "base/win/windows_version.h"
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 }; 501 };
501 ASSERT_EQ(arraysize(kIPv6Address), ip_addresses[1].size()); 502 ASSERT_EQ(arraysize(kIPv6Address), ip_addresses[1].size());
502 EXPECT_EQ(0, memcmp(ip_addresses[1].data(), kIPv6Address, 503 EXPECT_EQ(0, memcmp(ip_addresses[1].data(), kIPv6Address,
503 arraysize(kIPv6Address))); 504 arraysize(kIPv6Address)));
504 505
505 // Ensure the subjectAltName dirName has not influenced the handling of 506 // Ensure the subjectAltName dirName has not influenced the handling of
506 // the subject commonName. 507 // the subject commonName.
507 EXPECT_EQ("127.0.0.1", san_cert->subject().common_name); 508 EXPECT_EQ("127.0.0.1", san_cert->subject().common_name);
508 } 509 }
509 510
511 #if defined(USE_NSS_CERTS)
512 TEST(X509CertificateTest, ParseClientSubjectAltNames) {
513 base::FilePath certs_dir = GetTestCertsDirectory();
514
515 // This cert contains one rfc822Name field, and one Microsoft UPN
516 // otherName field.
517 scoped_refptr<X509Certificate> san_cert =
518 ImportCertFromFile(certs_dir, "client_3.pem");
519 ASSERT_NE(static_cast<X509Certificate*>(NULL), san_cert.get());
520
521 std::vector<std::string> rfc822_names;
522 net::x509_util::GetRFC822SubjectAltNames(san_cert->os_cert_handle(),
523 &rfc822_names);
524 ASSERT_EQ(1U, rfc822_names.size());
525 EXPECT_EQ("santest@example.com", rfc822_names[0]);
526
527 std::vector<std::string> upn_names;
528 net::x509_util::GetUPNSubjectAltNames(san_cert->os_cert_handle(), &upn_names);
529 ASSERT_EQ(1U, upn_names.size());
530 EXPECT_EQ("santest@ad.corp.example.com", upn_names[0]);
531 }
532 #endif // defined(USE_NSS_CERTS)
533
510 TEST(X509CertificateTest, ExtractSPKIFromDERCert) { 534 TEST(X509CertificateTest, ExtractSPKIFromDERCert) {
511 base::FilePath certs_dir = GetTestCertsDirectory(); 535 base::FilePath certs_dir = GetTestCertsDirectory();
512 scoped_refptr<X509Certificate> cert = 536 scoped_refptr<X509Certificate> cert =
513 ImportCertFromFile(certs_dir, "nist.der"); 537 ImportCertFromFile(certs_dir, "nist.der");
514 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert.get()); 538 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert.get());
515 539
516 std::string derBytes; 540 std::string derBytes;
517 EXPECT_TRUE(X509Certificate::GetDEREncoded(cert->os_cert_handle(), 541 EXPECT_TRUE(X509Certificate::GetDEREncoded(cert->os_cert_handle(),
518 &derBytes)); 542 &derBytes));
519 543
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after
1206 &actual_type); 1230 &actual_type);
1207 1231
1208 EXPECT_EQ(data.expected_bits, actual_bits); 1232 EXPECT_EQ(data.expected_bits, actual_bits);
1209 EXPECT_EQ(data.expected_type, actual_type); 1233 EXPECT_EQ(data.expected_type, actual_type);
1210 } 1234 }
1211 1235
1212 INSTANTIATE_TEST_CASE_P(, X509CertificatePublicKeyInfoTest, 1236 INSTANTIATE_TEST_CASE_P(, X509CertificatePublicKeyInfoTest,
1213 testing::ValuesIn(kPublicKeyInfoTestData)); 1237 testing::ValuesIn(kPublicKeyInfoTestData));
1214 1238
1215 } // namespace net 1239 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/cert/x509_util_nss.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698