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) {} | 28 : data_(data), digest_algorithm_(DIGEST_SHA_1), expiration_time_(-1) {} |
29 explicit FakeSSLCertificate(const std::vector<std::string>& certs) | 29 explicit FakeSSLCertificate(const std::vector<std::string>& certs) |
30 : data_(certs.front()), digest_algorithm_(DIGEST_SHA_1) { | 30 : data_(certs.front()), |
31 digest_algorithm_(DIGEST_SHA_1), | |
32 expiration_time_(-1) { | |
31 std::vector<std::string>::const_iterator it; | 33 std::vector<std::string>::const_iterator it; |
32 // Skip certs[0]. | 34 // Skip certs[0]. |
33 for (it = certs.begin() + 1; it != certs.end(); ++it) { | 35 for (it = certs.begin() + 1; it != certs.end(); ++it) { |
34 certs_.push_back(FakeSSLCertificate(*it)); | 36 certs_.push_back(FakeSSLCertificate(*it)); |
35 } | 37 } |
36 } | 38 } |
37 virtual FakeSSLCertificate* GetReference() const { | 39 virtual FakeSSLCertificate* GetReference() const { |
38 return new FakeSSLCertificate(*this); | 40 return new FakeSSLCertificate(*this); |
39 } | 41 } |
40 virtual std::string ToPEMString() const { | 42 virtual std::string ToPEMString() const { |
41 return data_; | 43 return data_; |
42 } | 44 } |
43 virtual void ToDER(Buffer* der_buffer) const { | 45 virtual void ToDER(Buffer* der_buffer) const { |
44 std::string der_string; | 46 std::string der_string; |
45 VERIFY(SSLIdentity::PemToDer(kPemTypeCertificate, data_, &der_string)); | 47 VERIFY(SSLIdentity::PemToDer(kPemTypeCertificate, data_, &der_string)); |
46 der_buffer->SetData(der_string.c_str(), der_string.size()); | 48 der_buffer->SetData(der_string.c_str(), der_string.size()); |
47 } | 49 } |
48 int64_t CertificateExpirationTime() const override { return -1; } | 50 int64_t CertificateExpirationTime() const override { |
51 return expiration_time_; | |
52 } | |
53 void SetCertificateExpirationTime(int64_t expiration_time) { | |
54 expiration_time_ = expiration_time; | |
55 } | |
49 void set_digest_algorithm(const std::string& algorithm) { | 56 void set_digest_algorithm(const std::string& algorithm) { |
50 digest_algorithm_ = algorithm; | 57 digest_algorithm_ = algorithm; |
51 } | 58 } |
52 virtual bool GetSignatureDigestAlgorithm(std::string* algorithm) const { | 59 virtual bool GetSignatureDigestAlgorithm(std::string* algorithm) const { |
53 *algorithm = digest_algorithm_; | 60 *algorithm = digest_algorithm_; |
54 return true; | 61 return true; |
55 } | 62 } |
56 virtual bool ComputeDigest(const std::string& algorithm, | 63 virtual bool ComputeDigest(const std::string& algorithm, |
57 unsigned char* digest, | 64 unsigned char* digest, |
58 size_t size, | 65 size_t size, |
(...skipping 13 matching lines...) Expand all Loading... | |
72 } | 79 } |
73 | 80 |
74 private: | 81 private: |
75 static FakeSSLCertificate* DupCert(FakeSSLCertificate cert) { | 82 static FakeSSLCertificate* DupCert(FakeSSLCertificate cert) { |
76 return cert.GetReference(); | 83 return cert.GetReference(); |
77 } | 84 } |
78 static void DeleteCert(SSLCertificate* cert) { delete cert; } | 85 static void DeleteCert(SSLCertificate* cert) { delete cert; } |
79 std::string data_; | 86 std::string data_; |
80 std::vector<FakeSSLCertificate> certs_; | 87 std::vector<FakeSSLCertificate> certs_; |
81 std::string digest_algorithm_; | 88 std::string digest_algorithm_; |
89 int64_t expiration_time_; | |
torbjorng (webrtc)
2015/12/07 14:53:26
nit: Please add comment about unit (seconds?)
hbos
2015/12/07 15:59:36
Done.
| |
82 }; | 90 }; |
83 | 91 |
84 class FakeSSLIdentity : public rtc::SSLIdentity { | 92 class FakeSSLIdentity : public rtc::SSLIdentity { |
85 public: | 93 public: |
86 explicit FakeSSLIdentity(const std::string& data) : cert_(data) {} | 94 explicit FakeSSLIdentity(const std::string& data) : cert_(data) {} |
87 explicit FakeSSLIdentity(const FakeSSLCertificate& cert) : cert_(cert) {} | 95 explicit FakeSSLIdentity(const FakeSSLCertificate& cert) : cert_(cert) {} |
88 virtual FakeSSLIdentity* GetReference() const { | 96 virtual FakeSSLIdentity* GetReference() const { |
89 return new FakeSSLIdentity(*this); | 97 return new FakeSSLIdentity(*this); |
90 } | 98 } |
91 virtual const FakeSSLCertificate& certificate() const { return cert_; } | 99 virtual const FakeSSLCertificate& certificate() const { return cert_; } |
92 private: | 100 private: |
93 FakeSSLCertificate cert_; | 101 FakeSSLCertificate cert_; |
94 }; | 102 }; |
95 | 103 |
96 } // namespace rtc | 104 } // namespace rtc |
97 | 105 |
98 #endif // WEBRTC_BASE_FAKESSLIDENTITY_H_ | 106 #endif // WEBRTC_BASE_FAKESSLIDENTITY_H_ |
OLD | NEW |