blob: c3a8d1f171007a9371c3b9ce4db67ffa98305e71 [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
Steve Anton10542f22019-01-11 09:11:00 -080011#ifndef RTC_BASE_FAKE_SSL_IDENTITY_H_
12#define RTC_BASE_FAKE_SSL_IDENTITY_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
Steve Anton10542f22019-01-11 09:11:00 -080017#include "rtc_base/ssl_certificate.h"
18#include "rtc_base/ssl_identity.h"
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020019
20namespace rtc {
21
Taylor Brandstetterc3928662018-02-23 13:04:51 -080022class FakeSSLCertificate : public SSLCertificate {
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020023 public:
24 // SHA-1 is the default digest algorithm because it is available in all build
25 // configurations used for unit testing.
Taylor Brandstetterc3928662018-02-23 13:04:51 -080026 explicit FakeSSLCertificate(const std::string& pem_string);
Steve Anton9de3aac2017-10-24 10:08:26 -070027
28 FakeSSLCertificate(const FakeSSLCertificate&);
29 ~FakeSSLCertificate() override;
30
31 // SSLCertificate implementation.
Steve Antonf25303e2018-10-16 15:23:31 -070032 std::unique_ptr<SSLCertificate> Clone() const override;
Steve Anton9de3aac2017-10-24 10:08:26 -070033 std::string ToPEMString() const override;
34 void ToDER(Buffer* der_buffer) const override;
35 int64_t CertificateExpirationTime() const override;
36 bool GetSignatureDigestAlgorithm(std::string* algorithm) const override;
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020037 bool ComputeDigest(const std::string& algorithm,
38 unsigned char* digest,
39 size_t size,
Steve Anton9de3aac2017-10-24 10:08:26 -070040 size_t* length) const override;
Steve Anton9de3aac2017-10-24 10:08:26 -070041
42 void SetCertificateExpirationTime(int64_t expiration_time);
43
44 void set_digest_algorithm(const std::string& algorithm);
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020045
46 private:
Taylor Brandstetterc3928662018-02-23 13:04:51 -080047 std::string pem_string_;
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020048 std::string digest_algorithm_;
49 // Expiration time in seconds relative to epoch, 1970-01-01T00:00:00Z (UTC).
50 int64_t expiration_time_;
51};
52
Taylor Brandstetterc3928662018-02-23 13:04:51 -080053class FakeSSLIdentity : public SSLIdentity {
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020054 public:
Taylor Brandstetterc3928662018-02-23 13:04:51 -080055 explicit FakeSSLIdentity(const std::string& pem_string);
56 // For a certificate chain.
57 explicit FakeSSLIdentity(const std::vector<std::string>& pem_strings);
Steve Anton9de3aac2017-10-24 10:08:26 -070058 explicit FakeSSLIdentity(const FakeSSLCertificate& cert);
59
Taylor Brandstetterc3928662018-02-23 13:04:51 -080060 explicit FakeSSLIdentity(const FakeSSLIdentity& o);
61
62 ~FakeSSLIdentity() override;
63
Steve Anton9de3aac2017-10-24 10:08:26 -070064 // SSLIdentity implementation.
65 FakeSSLIdentity* GetReference() const override;
Taylor Brandstetterc3928662018-02-23 13:04:51 -080066 const SSLCertificate& certificate() const override;
67 const SSLCertChain& cert_chain() const override;
Steve Anton9de3aac2017-10-24 10:08:26 -070068 // Not implemented.
69 std::string PrivateKeyToPEMString() const override;
70 // Not implemented.
71 std::string PublicKeyToPEMString() const override;
72 // Not implemented.
73 virtual bool operator==(const SSLIdentity& other) const;
74
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020075 private:
Taylor Brandstetterc3928662018-02-23 13:04:51 -080076 std::unique_ptr<SSLCertChain> cert_chain_;
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020077};
78
79} // namespace rtc
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000080
Steve Anton10542f22019-01-11 09:11:00 -080081#endif // RTC_BASE_FAKE_SSL_IDENTITY_H_