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