OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_BASE_FAKESSLIDENTITY_H_ | 11 #ifndef WEBRTC_BASE_FAKESSLIDENTITY_H_ |
12 #define WEBRTC_BASE_FAKESSLIDENTITY_H_ | 12 #define WEBRTC_BASE_FAKESSLIDENTITY_H_ |
13 | 13 |
14 #include <algorithm> | 14 #include <algorithm> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "webrtc/base/common.h" | 17 #include "webrtc/base/common.h" |
18 #include "webrtc/base/messagedigest.h" | 18 #include "webrtc/base/messagedigest.h" |
19 #include "webrtc/base/sslidentity.h" | 19 #include "webrtc/base/sslidentity.h" |
20 | 20 |
21 namespace rtc { | 21 namespace rtc { |
22 | 22 |
23 class FakeSSLCertificate : public rtc::SSLCertificate { | 23 class FakeSSLCertificate : public rtc::SSLCertificate { |
24 public: | 24 public: |
25 // SHA-1 is the default digest algorithm because it is available in all build | 25 // SHA-1 is the default digest algorithm because it is available in all build |
26 // configurations used for unit testing. | 26 // configurations used for unit testing. |
27 explicit FakeSSLCertificate(const std::string& data) | 27 explicit FakeSSLCertificate(const std::string& data) |
28 : data_(data), digest_algorithm_(DIGEST_SHA_1), expiration_time_(-1) {} | 28 : data_(data), digest_algorithm_(DIGEST_SHA_1) {} |
29 explicit FakeSSLCertificate(const std::vector<std::string>& certs) | 29 explicit FakeSSLCertificate(const std::vector<std::string>& certs) |
30 : data_(certs.front()), | 30 : data_(certs.front()), digest_algorithm_(DIGEST_SHA_1) { |
31 digest_algorithm_(DIGEST_SHA_1), | |
32 expiration_time_(-1) { | |
33 std::vector<std::string>::const_iterator it; | 31 std::vector<std::string>::const_iterator it; |
34 // Skip certs[0]. | 32 // Skip certs[0]. |
35 for (it = certs.begin() + 1; it != certs.end(); ++it) { | 33 for (it = certs.begin() + 1; it != certs.end(); ++it) { |
36 certs_.push_back(FakeSSLCertificate(*it)); | 34 certs_.push_back(FakeSSLCertificate(*it)); |
37 } | 35 } |
38 } | 36 } |
39 virtual FakeSSLCertificate* GetReference() const { | 37 virtual FakeSSLCertificate* GetReference() const { |
40 return new FakeSSLCertificate(*this); | 38 return new FakeSSLCertificate(*this); |
41 } | 39 } |
42 virtual std::string ToPEMString() const { | 40 virtual std::string ToPEMString() const { |
43 return data_; | 41 return data_; |
44 } | 42 } |
45 virtual void ToDER(Buffer* der_buffer) const { | 43 virtual void ToDER(Buffer* der_buffer) const { |
46 std::string der_string; | 44 std::string der_string; |
47 VERIFY(SSLIdentity::PemToDer(kPemTypeCertificate, data_, &der_string)); | 45 VERIFY(SSLIdentity::PemToDer(kPemTypeCertificate, data_, &der_string)); |
48 der_buffer->SetData(der_string.c_str(), der_string.size()); | 46 der_buffer->SetData(der_string.c_str(), der_string.size()); |
49 } | 47 } |
50 int64_t CertificateExpirationTime() const override { | 48 int64_t CertificateExpirationTime() const override { return -1; } |
51 return expiration_time_; | |
52 } | |
53 void SetCertificateExpirationTime(int64_t expiration_time) { | |
54 expiration_time_ = expiration_time; | |
55 } | |
56 void set_digest_algorithm(const std::string& algorithm) { | 49 void set_digest_algorithm(const std::string& algorithm) { |
57 digest_algorithm_ = algorithm; | 50 digest_algorithm_ = algorithm; |
58 } | 51 } |
59 virtual bool GetSignatureDigestAlgorithm(std::string* algorithm) const { | 52 virtual bool GetSignatureDigestAlgorithm(std::string* algorithm) const { |
60 *algorithm = digest_algorithm_; | 53 *algorithm = digest_algorithm_; |
61 return true; | 54 return true; |
62 } | 55 } |
63 virtual bool ComputeDigest(const std::string& algorithm, | 56 virtual bool ComputeDigest(const std::string& algorithm, |
64 unsigned char* digest, | 57 unsigned char* digest, |
65 size_t size, | 58 size_t size, |
(...skipping 13 matching lines...) Expand all Loading... |
79 } | 72 } |
80 | 73 |
81 private: | 74 private: |
82 static FakeSSLCertificate* DupCert(FakeSSLCertificate cert) { | 75 static FakeSSLCertificate* DupCert(FakeSSLCertificate cert) { |
83 return cert.GetReference(); | 76 return cert.GetReference(); |
84 } | 77 } |
85 static void DeleteCert(SSLCertificate* cert) { delete cert; } | 78 static void DeleteCert(SSLCertificate* cert) { delete cert; } |
86 std::string data_; | 79 std::string data_; |
87 std::vector<FakeSSLCertificate> certs_; | 80 std::vector<FakeSSLCertificate> certs_; |
88 std::string digest_algorithm_; | 81 std::string digest_algorithm_; |
89 // Expiration time in seconds relative to epoch, 1970-01-01T00:00:00Z (UTC). | |
90 int64_t expiration_time_; | |
91 }; | 82 }; |
92 | 83 |
93 class FakeSSLIdentity : public rtc::SSLIdentity { | 84 class FakeSSLIdentity : public rtc::SSLIdentity { |
94 public: | 85 public: |
95 explicit FakeSSLIdentity(const std::string& data) : cert_(data) {} | 86 explicit FakeSSLIdentity(const std::string& data) : cert_(data) {} |
96 explicit FakeSSLIdentity(const FakeSSLCertificate& cert) : cert_(cert) {} | 87 explicit FakeSSLIdentity(const FakeSSLCertificate& cert) : cert_(cert) {} |
97 virtual FakeSSLIdentity* GetReference() const { | 88 virtual FakeSSLIdentity* GetReference() const { |
98 return new FakeSSLIdentity(*this); | 89 return new FakeSSLIdentity(*this); |
99 } | 90 } |
100 virtual const FakeSSLCertificate& certificate() const { return cert_; } | 91 virtual const FakeSSLCertificate& certificate() const { return cert_; } |
101 private: | 92 private: |
102 FakeSSLCertificate cert_; | 93 FakeSSLCertificate cert_; |
103 }; | 94 }; |
104 | 95 |
105 } // namespace rtc | 96 } // namespace rtc |
106 | 97 |
107 #endif // WEBRTC_BASE_FAKESSLIDENTITY_H_ | 98 #endif // WEBRTC_BASE_FAKESSLIDENTITY_H_ |
OLD | NEW |