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

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

Issue 1526783002: Build a chain in ClientCertStoreNSS to send intermediates to the server. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: WIP test does not work Created 4 years, 10 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 "net/ssl/client_cert_store_nss.h" 5 #include "net/ssl/client_cert_store_nss.h"
6 6
7 #include <cert.h>
8 #include <certt.h>
9 #include <pk11pub.h>
10 #include <stdint.h>
11
12 #include <string>
13
14 #include "base/memory/ref_counted.h"
15 #include "base/run_loop.h"
16 #include "crypto/scoped_test_nss_db.h"
17 #include "net/cert/x509_certificate.h"
7 #include "net/ssl/client_cert_store_unittest-inl.h" 18 #include "net/ssl/client_cert_store_unittest-inl.h"
19 #include "net/ssl/ssl_cert_request_info.h"
20 #include "net/test/cert_test_util.h"
21 #include "testing/gtest/include/gtest/gtest.h"
8 22
9 namespace net { 23 namespace net {
10 24
11 class ClientCertStoreNSSTestDelegate { 25 class ClientCertStoreNSSTestDelegate {
12 public: 26 public:
13 ClientCertStoreNSSTestDelegate() {} 27 ClientCertStoreNSSTestDelegate() {}
14 28
15 bool SelectClientCerts(const CertificateList& input_certs, 29 bool SelectClientCerts(const CertificateList& input_certs,
16 const SSLCertRequestInfo& cert_request_info, 30 const SSLCertRequestInfo& cert_request_info,
17 CertificateList* selected_certs) { 31 CertificateList* selected_certs) {
18 // Filters |input_certs| using the logic being used to filter the system 32 // Filters |input_certs| using the logic being used to filter the system
19 // store when GetClientCerts() is called. 33 // store when GetClientCerts() is called.
20 ClientCertStoreNSS::FilterCertsOnWorkerThread( 34 ClientCertStoreNSS::FilterCertsOnWorkerThread(
21 input_certs, cert_request_info, false, selected_certs); 35 input_certs, cert_request_info, selected_certs);
22 return true; 36 return true;
23 } 37 }
24 }; 38 };
25 39
26 INSTANTIATE_TYPED_TEST_CASE_P(NSS, 40 INSTANTIATE_TYPED_TEST_CASE_P(NSS,
27 ClientCertStoreTest, 41 ClientCertStoreTest,
28 ClientCertStoreNSSTestDelegate); 42 ClientCertStoreNSSTestDelegate);
29 43
44 // Tests that ClientCertStoreNSS attempts to build a certificate chain by
45 // querying NSS before return a certificate.
46 TEST(ClientCertStoreNSSTest, BuildsCertificateChain) {
47 // Set up a test DB and import client_1.pem and client_1_ca.pem.
48 scoped_refptr<X509Certificate> client_1(
49 ImportCertFromFile(GetTestCertsDirectory(), "client_1.pem"));
50 ASSERT_TRUE(client_1.get());
51 scoped_refptr<X509Certificate> client_1_ca(
52 ImportCertFromFile(GetTestCertsDirectory(), "client_1_ca.pem"));
53 ASSERT_TRUE(client_1_ca.get());
54
55 crypto::ScopedTestNSSDB test_db;
56 ASSERT_EQ(SECSuccess,
57 PK11_ImportCert(test_db.slot(), client_1->os_cert_handle(),
58 CK_INVALID_HANDLE, "client_1",
59 PR_FALSE /* includeTrust (unused) */));
60 ASSERT_EQ(SECSuccess,
61 PK11_ImportCert(test_db.slot(), client_1_ca->os_cert_handle(),
62 CK_INVALID_HANDLE, "client_1_ca",
63 PR_FALSE /* includeTrust (unused) */));
64
65 // Request certificates matching client_1_ca.pem.
66 scoped_ptr<ClientCertStoreNSS> store(
67 new ClientCertStoreNSS(ClientCertStoreNSS::PasswordDelegateFactory()));
68 scoped_refptr<SSLCertRequestInfo> request(new SSLCertRequestInfo);
69 request->cert_authorities.push_back(std::string(
70 reinterpret_cast<const char*>(kAuthority1DN), sizeof(kAuthority1DN)));
71
72 CertificateList selected_certs;
73 base::RunLoop loop;
74 store->GetClientCerts(*request.get(), &selected_certs, loop.QuitClosure());
75 loop.Run();
76
77 // The result should have include client_1_ca.pem.
78 ASSERT_EQ(1u, selected_certs.size());
79 scoped_refptr<X509Certificate> selected_cert = selected_certs[0];
80 EXPECT_TRUE(selected_cert->Equals(client_1.get()));
81 ASSERT_EQ(1u, selected_cert->GetIntermediateCertificates().size());
82 EXPECT_TRUE(X509Certificate::IsSameOSCert(
83 client_1_ca->os_cert_handle(),
84 selected_cert->GetIntermediateCertificates()[0]));
85 }
86
30 } // namespace net 87 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698