Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 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 | |
| 11 | #ifndef RTC_BASE_OPENSSLCERTIFICATE_H_ |
| 12 | #define RTC_BASE_OPENSSLCERTIFICATE_H_ |
| 13 | |
Yves Gerey | 2e00abc | 2018-10-05 15:39:24 +0200 | [diff] [blame^] | 14 | #include <openssl/base.h> // for X509, ssl_ctx_st |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 15 | |
Yves Gerey | 2e00abc | 2018-10-05 15:39:24 +0200 | [diff] [blame^] | 16 | #include <stddef.h> // for size_t |
| 17 | #include <stdint.h> // for int64_t |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 18 | #include <string> |
| 19 | |
Yves Gerey | 2e00abc | 2018-10-05 15:39:24 +0200 | [diff] [blame^] | 20 | #include "rtc_base/buffer.h" // for Buffer |
| 21 | #include "rtc_base/constructormagic.h" // for RTC_DISALLOW_COPY_AND_ASSIGN |
| 22 | #include "rtc_base/sslcertificate.h" // for SSLCertificate |
| 23 | #include "rtc_base/sslidentity.h" // for SSLIdentityParams |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 24 | |
| 25 | typedef struct ssl_ctx_st SSL_CTX; |
| 26 | |
| 27 | namespace rtc { |
| 28 | |
| 29 | class OpenSSLKeyPair; |
| 30 | |
| 31 | // OpenSSLCertificate encapsulates an OpenSSL X509* certificate object, |
| 32 | // which is also reference counted inside the OpenSSL library. |
| 33 | class OpenSSLCertificate : public SSLCertificate { |
| 34 | public: |
| 35 | // X509 object has its reference count incremented. So the caller and |
| 36 | // OpenSSLCertificate share ownership. |
| 37 | explicit OpenSSLCertificate(X509* x509); |
| 38 | |
| 39 | static OpenSSLCertificate* Generate(OpenSSLKeyPair* key_pair, |
| 40 | const SSLIdentityParams& params); |
| 41 | static OpenSSLCertificate* FromPEMString(const std::string& pem_string); |
| 42 | |
| 43 | ~OpenSSLCertificate() override; |
| 44 | |
| 45 | OpenSSLCertificate* GetReference() const override; |
| 46 | |
| 47 | X509* x509() const { return x509_; } |
| 48 | |
| 49 | std::string ToPEMString() const override; |
| 50 | void ToDER(Buffer* der_buffer) const override; |
| 51 | bool operator==(const OpenSSLCertificate& other) const; |
| 52 | bool operator!=(const OpenSSLCertificate& other) const; |
| 53 | |
| 54 | // Compute the digest of the certificate given algorithm |
| 55 | bool ComputeDigest(const std::string& algorithm, |
| 56 | unsigned char* digest, |
| 57 | size_t size, |
| 58 | size_t* length) const override; |
| 59 | |
| 60 | // Compute the digest of a certificate as an X509 * |
| 61 | static bool ComputeDigest(const X509* x509, |
| 62 | const std::string& algorithm, |
| 63 | unsigned char* digest, |
| 64 | size_t size, |
| 65 | size_t* length); |
| 66 | |
| 67 | bool GetSignatureDigestAlgorithm(std::string* algorithm) const override; |
| 68 | |
| 69 | int64_t CertificateExpirationTime() const override; |
| 70 | |
| 71 | private: |
| 72 | void AddReference() const; |
| 73 | |
| 74 | X509* x509_; // NOT OWNED |
| 75 | RTC_DISALLOW_COPY_AND_ASSIGN(OpenSSLCertificate); |
| 76 | }; |
| 77 | |
| 78 | } // namespace rtc |
| 79 | |
| 80 | #endif // RTC_BASE_OPENSSLCERTIFICATE_H_ |