openssl_certificate.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright 2004 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_OPENSSL_CERTIFICATE_H_
  11. #define RTC_BASE_OPENSSL_CERTIFICATE_H_
  12. #include <openssl/ossl_typ.h>
  13. #include <stddef.h>
  14. #include <stdint.h>
  15. #include <string>
  16. #include "rtc_base/buffer.h"
  17. #include "rtc_base/constructor_magic.h"
  18. #include "rtc_base/ssl_certificate.h"
  19. #include "rtc_base/ssl_identity.h"
  20. namespace rtc {
  21. class OpenSSLKeyPair;
  22. // OpenSSLCertificate encapsulates an OpenSSL X509* certificate object,
  23. // which is also reference counted inside the OpenSSL library.
  24. class OpenSSLCertificate final : public SSLCertificate {
  25. public:
  26. // X509 object has its reference count incremented. So the caller and
  27. // OpenSSLCertificate share ownership.
  28. explicit OpenSSLCertificate(X509* x509);
  29. static std::unique_ptr<OpenSSLCertificate> Generate(
  30. OpenSSLKeyPair* key_pair,
  31. const SSLIdentityParams& params);
  32. static std::unique_ptr<OpenSSLCertificate> FromPEMString(
  33. const std::string& pem_string);
  34. ~OpenSSLCertificate() override;
  35. std::unique_ptr<SSLCertificate> Clone() const override;
  36. X509* x509() const { return x509_; }
  37. std::string ToPEMString() const override;
  38. void ToDER(Buffer* der_buffer) const override;
  39. bool operator==(const OpenSSLCertificate& other) const;
  40. bool operator!=(const OpenSSLCertificate& other) const;
  41. // Compute the digest of the certificate given algorithm
  42. bool ComputeDigest(const std::string& algorithm,
  43. unsigned char* digest,
  44. size_t size,
  45. size_t* length) const override;
  46. // Compute the digest of a certificate as an X509 *
  47. static bool ComputeDigest(const X509* x509,
  48. const std::string& algorithm,
  49. unsigned char* digest,
  50. size_t size,
  51. size_t* length);
  52. bool GetSignatureDigestAlgorithm(std::string* algorithm) const override;
  53. int64_t CertificateExpirationTime() const override;
  54. private:
  55. X509* x509_; // NOT OWNED
  56. RTC_DISALLOW_COPY_AND_ASSIGN(OpenSSLCertificate);
  57. };
  58. } // namespace rtc
  59. #endif // RTC_BASE_OPENSSL_CERTIFICATE_H_