blob: 5b5e427673746dd00d50538086f8d46c5e83c710 [file] [log] [blame]
mattm436ccfe2017-06-19 20:24:081// 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éky6d9c0072017-07-18 17:24:035#ifndef NET_SSL_CLIENT_CERT_IDENTITY_TEST_UTIL_H_
6#define NET_SSL_CLIENT_CERT_IDENTITY_TEST_UTIL_H_
mattm436ccfe2017-06-19 20:24:087
8#include "net/ssl/client_cert_identity.h"
9
10namespace base {
11class FilePath;
12}
13
14namespace net {
15
16// Simple ClientCertIdentity implementation for testing.
17// Note: this implementation of AcquirePrivateKey will always call the callback
18// synchronously.
19class 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.
52ClientCertIdentityList FakeClientCertIdentityListFromCertificateList(
53 const CertificateList& certs);
54
55} // namespace net
56
Bence Béky6d9c0072017-07-18 17:24:0357#endif // NET_SSL_CLIENT_CERT_IDENTITY_TEST_UTIL_H_