Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 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_RTC_BASE_OPENSSLIDENTITY_H_ | 11 #ifndef WEBRTC_RTC_BASE_OPENSSLIDENTITY_H_ |
| 12 #define WEBRTC_RTC_BASE_OPENSSLIDENTITY_H_ | 12 #define WEBRTC_RTC_BASE_OPENSSLIDENTITY_H_ |
| 13 | 13 |
| 14 #include <openssl/evp.h> | 14 #include <openssl/evp.h> |
| 15 #include <openssl/x509.h> | 15 #include <openssl/x509.h> |
| 16 | 16 |
| 17 #include <memory> | 17 #include <memory> |
| 18 #include <string> | 18 #include <string> |
| 19 #include <vector> | |
| 19 | 20 |
| 20 #include "webrtc/rtc_base/checks.h" | 21 #include "webrtc/rtc_base/checks.h" |
| 21 #include "webrtc/rtc_base/constructormagic.h" | 22 #include "webrtc/rtc_base/constructormagic.h" |
| 22 #include "webrtc/rtc_base/sslidentity.h" | 23 #include "webrtc/rtc_base/sslidentity.h" |
| 23 | 24 |
| 24 typedef struct ssl_ctx_st SSL_CTX; | 25 typedef struct ssl_ctx_st SSL_CTX; |
| 25 | 26 |
| 26 namespace rtc { | 27 namespace rtc { |
| 27 | 28 |
| 28 // OpenSSLKeyPair encapsulates an OpenSSL EVP_PKEY* keypair object, | 29 // OpenSSLKeyPair encapsulates an OpenSSL EVP_PKEY* keypair object, |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 55 EVP_PKEY* pkey_; | 56 EVP_PKEY* pkey_; |
| 56 | 57 |
| 57 RTC_DISALLOW_COPY_AND_ASSIGN(OpenSSLKeyPair); | 58 RTC_DISALLOW_COPY_AND_ASSIGN(OpenSSLKeyPair); |
| 58 }; | 59 }; |
| 59 | 60 |
| 60 // OpenSSLCertificate encapsulates an OpenSSL X509* certificate object, | 61 // OpenSSLCertificate encapsulates an OpenSSL X509* certificate object, |
| 61 // which is also reference counted inside the OpenSSL library. | 62 // which is also reference counted inside the OpenSSL library. |
| 62 class OpenSSLCertificate : public SSLCertificate { | 63 class OpenSSLCertificate : public SSLCertificate { |
| 63 public: | 64 public: |
| 64 // Caller retains ownership of the X509 object. | 65 // Caller retains ownership of the X509 object. |
| 65 explicit OpenSSLCertificate(X509* x509) : x509_(x509) { | 66 explicit OpenSSLCertificate(X509* x509); |
| 66 AddReference(); | 67 |
| 67 } | 68 // Caller retains owership of STACK_OF(X509). |
| 69 explicit OpenSSLCertificate(STACK_OF(X509)* chain); | |
| 68 | 70 |
| 69 static OpenSSLCertificate* Generate(OpenSSLKeyPair* key_pair, | 71 static OpenSSLCertificate* Generate(OpenSSLKeyPair* key_pair, |
| 70 const SSLIdentityParams& params); | 72 const SSLIdentityParams& params); |
| 71 static OpenSSLCertificate* FromPEMString(const std::string& pem_string); | 73 static OpenSSLCertificate* FromPEMString(const std::string& pem_string); |
| 72 | 74 |
| 73 ~OpenSSLCertificate() override; | 75 ~OpenSSLCertificate() override; |
| 74 | 76 |
| 75 OpenSSLCertificate* GetReference() const override; | 77 OpenSSLCertificate* GetReference() const override; |
| 76 | 78 |
| 77 X509* x509() const { return x509_; } | 79 X509* x509() const { return x509_; } |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 93 unsigned char* digest, | 95 unsigned char* digest, |
| 94 size_t size, | 96 size_t size, |
| 95 size_t* length); | 97 size_t* length); |
| 96 | 98 |
| 97 bool GetSignatureDigestAlgorithm(std::string* algorithm) const override; | 99 bool GetSignatureDigestAlgorithm(std::string* algorithm) const override; |
| 98 std::unique_ptr<SSLCertChain> GetChain() const override; | 100 std::unique_ptr<SSLCertChain> GetChain() const override; |
| 99 | 101 |
| 100 int64_t CertificateExpirationTime() const override; | 102 int64_t CertificateExpirationTime() const override; |
| 101 | 103 |
| 102 private: | 104 private: |
| 103 void AddReference() const; | 105 void AddReference(X509* x509) const; |
| 104 | 106 |
| 105 X509* x509_; | 107 X509* x509_; |
| 108 // Non-leaf certificate chain. | |
| 109 std::vector<OpenSSLCertificate*> cert_chain_; | |
|
davidben_webrtc
2017/09/26 23:21:46
You don't seem to free this in the destructor. Thi
| |
| 106 | 110 |
| 107 RTC_DISALLOW_COPY_AND_ASSIGN(OpenSSLCertificate); | 111 RTC_DISALLOW_COPY_AND_ASSIGN(OpenSSLCertificate); |
| 108 }; | 112 }; |
| 109 | 113 |
| 110 // Holds a keypair and certificate together, and a method to generate | 114 // Holds a keypair and certificate together, and a method to generate |
| 111 // them consistently. | 115 // them consistently. |
| 112 class OpenSSLIdentity : public SSLIdentity { | 116 class OpenSSLIdentity : public SSLIdentity { |
| 113 public: | 117 public: |
| 114 static OpenSSLIdentity* GenerateWithExpiration(const std::string& common_name, | 118 static OpenSSLIdentity* GenerateWithExpiration(const std::string& common_name, |
| 115 const KeyParams& key_params, | 119 const KeyParams& key_params, |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 138 std::unique_ptr<OpenSSLKeyPair> key_pair_; | 142 std::unique_ptr<OpenSSLKeyPair> key_pair_; |
| 139 std::unique_ptr<OpenSSLCertificate> certificate_; | 143 std::unique_ptr<OpenSSLCertificate> certificate_; |
| 140 | 144 |
| 141 RTC_DISALLOW_COPY_AND_ASSIGN(OpenSSLIdentity); | 145 RTC_DISALLOW_COPY_AND_ASSIGN(OpenSSLIdentity); |
| 142 }; | 146 }; |
| 143 | 147 |
| 144 | 148 |
| 145 } // namespace rtc | 149 } // namespace rtc |
| 146 | 150 |
| 147 #endif // WEBRTC_RTC_BASE_OPENSSLIDENTITY_H_ | 151 #endif // WEBRTC_RTC_BASE_OPENSSLIDENTITY_H_ |
| OLD | NEW |