fake_ssl_identity.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. #ifndef RTC_BASE_FAKE_SSL_IDENTITY_H_
  11. #define RTC_BASE_FAKE_SSL_IDENTITY_H_
  12. #include <memory>
  13. #include <vector>
  14. #include "rtc_base/ssl_certificate.h"
  15. #include "rtc_base/ssl_identity.h"
  16. namespace rtc {
  17. class FakeSSLCertificate : public SSLCertificate {
  18. public:
  19. // SHA-1 is the default digest algorithm because it is available in all build
  20. // configurations used for unit testing.
  21. explicit FakeSSLCertificate(const std::string& pem_string);
  22. FakeSSLCertificate(const FakeSSLCertificate&);
  23. ~FakeSSLCertificate() override;
  24. // SSLCertificate implementation.
  25. std::unique_ptr<SSLCertificate> Clone() const override;
  26. std::string ToPEMString() const override;
  27. void ToDER(Buffer* der_buffer) const override;
  28. int64_t CertificateExpirationTime() const override;
  29. bool GetSignatureDigestAlgorithm(std::string* algorithm) const override;
  30. bool ComputeDigest(const std::string& algorithm,
  31. unsigned char* digest,
  32. size_t size,
  33. size_t* length) const override;
  34. void SetCertificateExpirationTime(int64_t expiration_time);
  35. void set_digest_algorithm(const std::string& algorithm);
  36. private:
  37. std::string pem_string_;
  38. std::string digest_algorithm_;
  39. // Expiration time in seconds relative to epoch, 1970-01-01T00:00:00Z (UTC).
  40. int64_t expiration_time_;
  41. };
  42. class FakeSSLIdentity : public SSLIdentity {
  43. public:
  44. explicit FakeSSLIdentity(const std::string& pem_string);
  45. // For a certificate chain.
  46. explicit FakeSSLIdentity(const std::vector<std::string>& pem_strings);
  47. explicit FakeSSLIdentity(const FakeSSLCertificate& cert);
  48. explicit FakeSSLIdentity(const FakeSSLIdentity& o);
  49. ~FakeSSLIdentity() override;
  50. // SSLIdentity implementation.
  51. const SSLCertificate& certificate() const override;
  52. const SSLCertChain& cert_chain() const override;
  53. // Not implemented.
  54. std::string PrivateKeyToPEMString() const override;
  55. // Not implemented.
  56. std::string PublicKeyToPEMString() const override;
  57. // Not implemented.
  58. virtual bool operator==(const SSLIdentity& other) const;
  59. private:
  60. std::unique_ptr<SSLIdentity> CloneInternal() const override;
  61. std::unique_ptr<SSLCertChain> cert_chain_;
  62. };
  63. } // namespace rtc
  64. #endif // RTC_BASE_FAKE_SSL_IDENTITY_H_