blob: 52aaf05558225484d4bc868377aea3a41f296439 [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
21class FakeSSLCertificate : public rtc::SSLCertificate {
22 public:
23 // SHA-1 is the default digest algorithm because it is available in all build
24 // configurations used for unit testing.
Steve Anton9de3aac2017-10-24 10:08:26 -070025 explicit FakeSSLCertificate(const std::string& data);
26
27 explicit FakeSSLCertificate(const std::vector<std::string>& certs);
28
29 FakeSSLCertificate(const FakeSSLCertificate&);
30 ~FakeSSLCertificate() override;
31
32 // SSLCertificate implementation.
33 FakeSSLCertificate* GetReference() const override;
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;
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020038 bool ComputeDigest(const std::string& algorithm,
39 unsigned char* digest,
40 size_t size,
Steve Anton9de3aac2017-10-24 10:08:26 -070041 size_t* length) const override;
42 std::unique_ptr<SSLCertChain> GetChain() const override;
43
44 void SetCertificateExpirationTime(int64_t expiration_time);
45
46 void set_digest_algorithm(const std::string& algorithm);
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020047
48 private:
David Benjamin3df76b12017-09-29 12:27:18 -040049 static std::unique_ptr<SSLCertificate> DupCert(FakeSSLCertificate cert) {
50 return cert.GetUniqueReference();
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020051 }
52 static void DeleteCert(SSLCertificate* cert) { delete cert; }
53 std::string data_;
54 std::vector<FakeSSLCertificate> certs_;
55 std::string digest_algorithm_;
56 // Expiration time in seconds relative to epoch, 1970-01-01T00:00:00Z (UTC).
57 int64_t expiration_time_;
58};
59
60class FakeSSLIdentity : public rtc::SSLIdentity {
61 public:
Steve Anton9de3aac2017-10-24 10:08:26 -070062 explicit FakeSSLIdentity(const std::string& data);
63 explicit FakeSSLIdentity(const FakeSSLCertificate& cert);
64
65 // SSLIdentity implementation.
66 FakeSSLIdentity* GetReference() const override;
67 const FakeSSLCertificate& certificate() const override;
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 Kjellanderec78f1c2017-06-29 07:52:50 +020075 private:
76 FakeSSLCertificate cert_;
77};
78
79} // namespace rtc
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000080
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020081#endif // RTC_BASE_FAKESSLIDENTITY_H_