mattm | 436ccfe | 2017-06-19 20:24:08 | [diff] [blame] | 1 | // Copyright 2017 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 | |
Bence Béky | 6d9c007 | 2017-07-18 17:24:03 | [diff] [blame] | 5 | #ifndef NET_SSL_CLIENT_CERT_IDENTITY_TEST_UTIL_H_ |
| 6 | #define NET_SSL_CLIENT_CERT_IDENTITY_TEST_UTIL_H_ |
mattm | 436ccfe | 2017-06-19 20:24:08 | [diff] [blame] | 7 | |
| 8 | #include "net/ssl/client_cert_identity.h" |
| 9 | |
| 10 | namespace base { |
| 11 | class FilePath; |
| 12 | } |
| 13 | |
| 14 | namespace net { |
| 15 | |
| 16 | // Simple ClientCertIdentity implementation for testing. |
| 17 | // Note: this implementation of AcquirePrivateKey will always call the callback |
| 18 | // synchronously. |
| 19 | class FakeClientCertIdentity : public ClientCertIdentity { |
| 20 | public: |
| 21 | FakeClientCertIdentity(scoped_refptr<X509Certificate> cert, |
| 22 | scoped_refptr<SSLPrivateKey> key); |
| 23 | ~FakeClientCertIdentity() override; |
| 24 | |
| 25 | // Creates a FakeClientCertIdentity from a certificate file (DER or PEM) and |
| 26 | // private key file (unencrypted pkcs8). Returns nullptr on error. |
| 27 | static std::unique_ptr<FakeClientCertIdentity> CreateFromCertAndKeyFiles( |
| 28 | const base::FilePath& dir, |
| 29 | const std::string& cert_filename, |
| 30 | const std::string& key_filename); |
| 31 | |
| 32 | // Duplicates the FakeClientCertIdentity. |
| 33 | std::unique_ptr<FakeClientCertIdentity> Copy(); |
| 34 | |
| 35 | // Returns the SSLPrivateKey in a more convenient way, for tests. |
| 36 | SSLPrivateKey* ssl_private_key() const { return key_.get(); } |
| 37 | |
| 38 | // ClientCertIdentity implementation: |
| 39 | void AcquirePrivateKey( |
| 40 | const base::Callback<void(scoped_refptr<SSLPrivateKey>)>& |
| 41 | private_key_callback) override; |
| 42 | #if defined(OS_MACOSX) |
| 43 | SecIdentityRef sec_identity_ref() const override; |
| 44 | #endif |
| 45 | |
| 46 | private: |
| 47 | scoped_refptr<SSLPrivateKey> key_; |
| 48 | }; |
| 49 | |
| 50 | // Converts a CertificateList to a ClientCertIdentityList of |
| 51 | // FakeClientCertIdentity, with null private keys. |
| 52 | ClientCertIdentityList FakeClientCertIdentityListFromCertificateList( |
| 53 | const CertificateList& certs); |
| 54 | |
| 55 | } // namespace net |
| 56 | |
Bence Béky | 6d9c007 | 2017-07-18 17:24:03 | [diff] [blame] | 57 | #endif // NET_SSL_CLIENT_CERT_IDENTITY_TEST_UTIL_H_ |