blob: 2b4ae2e57ae542b563a46bf366aaf859d020b529 [file] [log] [blame]
henrike@webrtc.orgf0488722014-05-13 18:00:261/*
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 17:11:0011#ifndef RTC_BASE_FAKE_SSL_IDENTITY_H_
12#define RTC_BASE_FAKE_SSL_IDENTITY_H_
henrike@webrtc.orgf0488722014-05-13 18:00:2613
Henrik Kjellanderec78f1c2017-06-29 05:52:5014#include <memory>
15#include <vector>
henrike@webrtc.orgf0488722014-05-13 18:00:2616
Ali Tofigh7fa90572022-03-17 14:47:4917#include "absl/strings/string_view.h"
Steve Anton10542f22019-01-11 17:11:0018#include "rtc_base/ssl_certificate.h"
19#include "rtc_base/ssl_identity.h"
Henrik Kjellanderec78f1c2017-06-29 05:52:5020
21namespace rtc {
22
Taylor Brandstetterc3928662018-02-23 21:04:5123class FakeSSLCertificate : public SSLCertificate {
Henrik Kjellanderec78f1c2017-06-29 05:52:5024 public:
25 // SHA-1 is the default digest algorithm because it is available in all build
26 // configurations used for unit testing.
Ali Tofigh7fa90572022-03-17 14:47:4927 explicit FakeSSLCertificate(absl::string_view pem_string);
Steve Anton9de3aac2017-10-24 17:08:2628
29 FakeSSLCertificate(const FakeSSLCertificate&);
30 ~FakeSSLCertificate() override;
31
32 // SSLCertificate implementation.
Steve Antonf25303e2018-10-16 22:23:3133 std::unique_ptr<SSLCertificate> Clone() const override;
Steve Anton9de3aac2017-10-24 17:08:2634 std::string ToPEMString() const override;
35 void ToDER(Buffer* der_buffer) const override;
36 int64_t CertificateExpirationTime() const override;
37 bool GetSignatureDigestAlgorithm(std::string* algorithm) const override;
Ali Tofigh7fa90572022-03-17 14:47:4938 bool ComputeDigest(absl::string_view algorithm,
Henrik Kjellanderec78f1c2017-06-29 05:52:5039 unsigned char* digest,
40 size_t size,
Steve Anton9de3aac2017-10-24 17:08:2641 size_t* length) const override;
Steve Anton9de3aac2017-10-24 17:08:2642
43 void SetCertificateExpirationTime(int64_t expiration_time);
44
Ali Tofigh7fa90572022-03-17 14:47:4945 void set_digest_algorithm(absl::string_view algorithm);
Henrik Kjellanderec78f1c2017-06-29 05:52:5046
47 private:
Taylor Brandstetterc3928662018-02-23 21:04:5148 std::string pem_string_;
Henrik Kjellanderec78f1c2017-06-29 05:52:5049 std::string digest_algorithm_;
50 // Expiration time in seconds relative to epoch, 1970-01-01T00:00:00Z (UTC).
51 int64_t expiration_time_;
52};
53
Taylor Brandstetterc3928662018-02-23 21:04:5154class FakeSSLIdentity : public SSLIdentity {
Henrik Kjellanderec78f1c2017-06-29 05:52:5055 public:
Ali Tofigh7fa90572022-03-17 14:47:4956 explicit FakeSSLIdentity(absl::string_view pem_string);
Taylor Brandstetterc3928662018-02-23 21:04:5157 // For a certificate chain.
58 explicit FakeSSLIdentity(const std::vector<std::string>& pem_strings);
Steve Anton9de3aac2017-10-24 17:08:2659 explicit FakeSSLIdentity(const FakeSSLCertificate& cert);
60
Taylor Brandstetterc3928662018-02-23 21:04:5161 explicit FakeSSLIdentity(const FakeSSLIdentity& o);
62
63 ~FakeSSLIdentity() override;
64
Steve Anton9de3aac2017-10-24 17:08:2665 // SSLIdentity implementation.
Taylor Brandstetterc3928662018-02-23 21:04:5166 const SSLCertificate& certificate() const override;
67 const SSLCertChain& cert_chain() const override;
Steve Anton9de3aac2017-10-24 17:08:2668 // 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 05:52:5075 private:
Harald Alvestrand8515d5a2020-03-20 21:51:3276 std::unique_ptr<SSLIdentity> CloneInternal() const override;
77
Taylor Brandstetterc3928662018-02-23 21:04:5178 std::unique_ptr<SSLCertChain> cert_chain_;
Henrik Kjellanderec78f1c2017-06-29 05:52:5079};
80
81} // namespace rtc
henrike@webrtc.orgf0488722014-05-13 18:00:2682
Steve Anton10542f22019-01-11 17:11:0083#endif // RTC_BASE_FAKE_SSL_IDENTITY_H_