blob: 4494a524efab907916463fffb0c7178636974d1d [file] [log] [blame]
henrike@webrtc.orgf0488722014-05-13 18:00:26 +00001/*
2 * Copyright 2012 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef RTC_BASE_FAKESSLIDENTITY_H_
12#define RTC_BASE_FAKESSLIDENTITY_H_
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000013
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020014#include <memory>
15#include <vector>
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000016
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "rtc_base/sslidentity.h"
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020018
19namespace rtc {
20
Taylor Brandstetterc3928662018-02-23 13:04:51 -080021class FakeSSLCertificate : public SSLCertificate {
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020022 public:
23 // SHA-1 is the default digest algorithm because it is available in all build
24 // configurations used for unit testing.
Taylor Brandstetterc3928662018-02-23 13:04:51 -080025 explicit FakeSSLCertificate(const std::string& pem_string);
Steve Anton9de3aac2017-10-24 10:08:26 -070026
27 FakeSSLCertificate(const FakeSSLCertificate&);
28 ~FakeSSLCertificate() override;
29
30 // SSLCertificate implementation.
31 FakeSSLCertificate* GetReference() const override;
32 std::string ToPEMString() const override;
33 void ToDER(Buffer* der_buffer) const override;
34 int64_t CertificateExpirationTime() const override;
35 bool GetSignatureDigestAlgorithm(std::string* algorithm) const override;
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020036 bool ComputeDigest(const std::string& algorithm,
37 unsigned char* digest,
38 size_t size,
Steve Anton9de3aac2017-10-24 10:08:26 -070039 size_t* length) const override;
Steve Anton9de3aac2017-10-24 10:08:26 -070040
41 void SetCertificateExpirationTime(int64_t expiration_time);
42
43 void set_digest_algorithm(const std::string& algorithm);
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020044
45 private:
Taylor Brandstetterc3928662018-02-23 13:04:51 -080046 std::string pem_string_;
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020047 std::string digest_algorithm_;
48 // Expiration time in seconds relative to epoch, 1970-01-01T00:00:00Z (UTC).
49 int64_t expiration_time_;
50};
51
Taylor Brandstetterc3928662018-02-23 13:04:51 -080052class FakeSSLIdentity : public SSLIdentity {
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020053 public:
Taylor Brandstetterc3928662018-02-23 13:04:51 -080054 explicit FakeSSLIdentity(const std::string& pem_string);
55 // For a certificate chain.
56 explicit FakeSSLIdentity(const std::vector<std::string>& pem_strings);
Steve Anton9de3aac2017-10-24 10:08:26 -070057 explicit FakeSSLIdentity(const FakeSSLCertificate& cert);
58
Taylor Brandstetterc3928662018-02-23 13:04:51 -080059 explicit FakeSSLIdentity(const FakeSSLIdentity& o);
60
61 ~FakeSSLIdentity() override;
62
Steve Anton9de3aac2017-10-24 10:08:26 -070063 // SSLIdentity implementation.
64 FakeSSLIdentity* GetReference() const override;
Taylor Brandstetterc3928662018-02-23 13:04:51 -080065 const SSLCertificate& certificate() const override;
66 const SSLCertChain& cert_chain() const override;
Steve Anton9de3aac2017-10-24 10:08:26 -070067 // Not implemented.
68 std::string PrivateKeyToPEMString() const override;
69 // Not implemented.
70 std::string PublicKeyToPEMString() const override;
71 // Not implemented.
72 virtual bool operator==(const SSLIdentity& other) const;
73
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020074 private:
Taylor Brandstetterc3928662018-02-23 13:04:51 -080075 std::unique_ptr<SSLCertChain> cert_chain_;
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020076};
77
78} // namespace rtc
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000079
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020080#endif // RTC_BASE_FAKESSLIDENTITY_H_