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

Unified Diff: net/ssl/client_cert_identity_test_util.h

Issue 2898573002: Refactor client cert private key handling. (Closed)
Patch Set: removed no longer needed forward declaration Created 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/ssl/client_cert_identity_mac.cc ('k') | net/ssl/client_cert_identity_test_util.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/ssl/client_cert_identity_test_util.h
diff --git a/net/ssl/client_cert_identity_test_util.h b/net/ssl/client_cert_identity_test_util.h
new file mode 100644
index 0000000000000000000000000000000000000000..90c09f60b714d1313d0e702596e4ea3676f663fc
--- /dev/null
+++ b/net/ssl/client_cert_identity_test_util.h
@@ -0,0 +1,57 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_SSL_SSL_CLIENT_CERT_IDENTITY_TEST_UTIL_H_
+#define NET_SSL_SSL_CLIENT_CERT_IDENTITY_TEST_UTIL_H_
+
+#include "net/ssl/client_cert_identity.h"
+
+namespace base {
+class FilePath;
+}
+
+namespace net {
+
+// Simple ClientCertIdentity implementation for testing.
+// Note: this implementation of AcquirePrivateKey will always call the callback
+// synchronously.
+class FakeClientCertIdentity : public ClientCertIdentity {
+ public:
+ FakeClientCertIdentity(scoped_refptr<X509Certificate> cert,
+ scoped_refptr<SSLPrivateKey> key);
+ ~FakeClientCertIdentity() override;
+
+ // Creates a FakeClientCertIdentity from a certificate file (DER or PEM) and
+ // private key file (unencrypted pkcs8). Returns nullptr on error.
+ static std::unique_ptr<FakeClientCertIdentity> CreateFromCertAndKeyFiles(
+ const base::FilePath& dir,
+ const std::string& cert_filename,
+ const std::string& key_filename);
+
+ // Duplicates the FakeClientCertIdentity.
+ std::unique_ptr<FakeClientCertIdentity> Copy();
+
+ // Returns the SSLPrivateKey in a more convenient way, for tests.
+ SSLPrivateKey* ssl_private_key() const { return key_.get(); }
+
+ // ClientCertIdentity implementation:
+ void AcquirePrivateKey(
+ const base::Callback<void(scoped_refptr<SSLPrivateKey>)>&
+ private_key_callback) override;
+#if defined(OS_MACOSX)
+ SecIdentityRef sec_identity_ref() const override;
+#endif
+
+ private:
+ scoped_refptr<SSLPrivateKey> key_;
+};
+
+// Converts a CertificateList to a ClientCertIdentityList of
+// FakeClientCertIdentity, with null private keys.
+ClientCertIdentityList FakeClientCertIdentityListFromCertificateList(
+ const CertificateList& certs);
+
+} // namespace net
+
+#endif // NET_SSL_SSL_CLIENT_CERT_IDENTITY_TEST_UTIL_H_
« no previous file with comments | « net/ssl/client_cert_identity_mac.cc ('k') | net/ssl/client_cert_identity_test_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698