henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 1 | /* |
| 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 Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 11 | #ifndef RTC_BASE_FAKE_SSL_IDENTITY_H_ |
| 12 | #define RTC_BASE_FAKE_SSL_IDENTITY_H_ |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 13 | |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 14 | #include <memory> |
| 15 | #include <vector> |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 16 | |
Ali Tofigh | 7fa9057 | 2022-03-17 14:47:49 | [diff] [blame] | 17 | #include "absl/strings/string_view.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 18 | #include "rtc_base/ssl_certificate.h" |
| 19 | #include "rtc_base/ssl_identity.h" |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 20 | |
| 21 | namespace rtc { |
| 22 | |
Taylor Brandstetter | c392866 | 2018-02-23 21:04:51 | [diff] [blame] | 23 | class FakeSSLCertificate : public SSLCertificate { |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 24 | public: |
| 25 | // SHA-1 is the default digest algorithm because it is available in all build |
| 26 | // configurations used for unit testing. |
Ali Tofigh | 7fa9057 | 2022-03-17 14:47:49 | [diff] [blame] | 27 | explicit FakeSSLCertificate(absl::string_view pem_string); |
Steve Anton | 9de3aac | 2017-10-24 17:08:26 | [diff] [blame] | 28 | |
| 29 | FakeSSLCertificate(const FakeSSLCertificate&); |
| 30 | ~FakeSSLCertificate() override; |
| 31 | |
| 32 | // SSLCertificate implementation. |
Steve Anton | f25303e | 2018-10-16 22:23:31 | [diff] [blame] | 33 | std::unique_ptr<SSLCertificate> Clone() const override; |
Steve Anton | 9de3aac | 2017-10-24 17:08:26 | [diff] [blame] | 34 | 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 Tofigh | 7fa9057 | 2022-03-17 14:47:49 | [diff] [blame] | 38 | bool ComputeDigest(absl::string_view algorithm, |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 39 | unsigned char* digest, |
| 40 | size_t size, |
Steve Anton | 9de3aac | 2017-10-24 17:08:26 | [diff] [blame] | 41 | size_t* length) const override; |
Steve Anton | 9de3aac | 2017-10-24 17:08:26 | [diff] [blame] | 42 | |
| 43 | void SetCertificateExpirationTime(int64_t expiration_time); |
| 44 | |
Ali Tofigh | 7fa9057 | 2022-03-17 14:47:49 | [diff] [blame] | 45 | void set_digest_algorithm(absl::string_view algorithm); |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 46 | |
| 47 | private: |
Taylor Brandstetter | c392866 | 2018-02-23 21:04:51 | [diff] [blame] | 48 | std::string pem_string_; |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 49 | 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 Brandstetter | c392866 | 2018-02-23 21:04:51 | [diff] [blame] | 54 | class FakeSSLIdentity : public SSLIdentity { |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 55 | public: |
Ali Tofigh | 7fa9057 | 2022-03-17 14:47:49 | [diff] [blame] | 56 | explicit FakeSSLIdentity(absl::string_view pem_string); |
Taylor Brandstetter | c392866 | 2018-02-23 21:04:51 | [diff] [blame] | 57 | // For a certificate chain. |
| 58 | explicit FakeSSLIdentity(const std::vector<std::string>& pem_strings); |
Steve Anton | 9de3aac | 2017-10-24 17:08:26 | [diff] [blame] | 59 | explicit FakeSSLIdentity(const FakeSSLCertificate& cert); |
| 60 | |
Taylor Brandstetter | c392866 | 2018-02-23 21:04:51 | [diff] [blame] | 61 | explicit FakeSSLIdentity(const FakeSSLIdentity& o); |
| 62 | |
| 63 | ~FakeSSLIdentity() override; |
| 64 | |
Steve Anton | 9de3aac | 2017-10-24 17:08:26 | [diff] [blame] | 65 | // SSLIdentity implementation. |
Taylor Brandstetter | c392866 | 2018-02-23 21:04:51 | [diff] [blame] | 66 | const SSLCertificate& certificate() const override; |
| 67 | const SSLCertChain& cert_chain() const override; |
Steve Anton | 9de3aac | 2017-10-24 17:08:26 | [diff] [blame] | 68 | // 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 Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 75 | private: |
Harald Alvestrand | 8515d5a | 2020-03-20 21:51:32 | [diff] [blame] | 76 | std::unique_ptr<SSLIdentity> CloneInternal() const override; |
| 77 | |
Taylor Brandstetter | c392866 | 2018-02-23 21:04:51 | [diff] [blame] | 78 | std::unique_ptr<SSLCertChain> cert_chain_; |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | } // namespace rtc |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 82 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 83 | #endif // RTC_BASE_FAKE_SSL_IDENTITY_H_ |