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 |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 // OpenSSLKeyPair encapsulates an OpenSSL EVP_PKEY* keypair object, | 28 // OpenSSLKeyPair encapsulates an OpenSSL EVP_PKEY* keypair object, |
29 // which is reference counted inside the OpenSSL library. | 29 // which is reference counted inside the OpenSSL library. |
30 class OpenSSLKeyPair { | 30 class OpenSSLKeyPair { |
31 public: | 31 public: |
32 explicit OpenSSLKeyPair(EVP_PKEY* pkey) : pkey_(pkey) { | 32 explicit OpenSSLKeyPair(EVP_PKEY* pkey) : pkey_(pkey) { |
33 ASSERT(pkey_ != NULL); | 33 ASSERT(pkey_ != NULL); |
34 } | 34 } |
35 | 35 |
36 static OpenSSLKeyPair* Generate(const KeyParams& key_params); | 36 static OpenSSLKeyPair* Generate(const KeyParams& key_params); |
| 37 // Constructs a key pair from the private key PEM string. This must not result |
| 38 // in missing public key parameters. Returns null on error. |
| 39 static OpenSSLKeyPair* FromPrivateKeyPEMString( |
| 40 const std::string& pem_string); |
37 | 41 |
38 virtual ~OpenSSLKeyPair(); | 42 virtual ~OpenSSLKeyPair(); |
39 | 43 |
40 virtual OpenSSLKeyPair* GetReference(); | 44 virtual OpenSSLKeyPair* GetReference(); |
41 | 45 |
42 EVP_PKEY* pkey() const { return pkey_; } | 46 EVP_PKEY* pkey() const { return pkey_; } |
| 47 std::string PrivateKeyToPEMString() const; |
| 48 std::string PublicKeyToPEMString() const; |
| 49 bool operator==(const OpenSSLKeyPair& other) const; |
| 50 bool operator!=(const OpenSSLKeyPair& other) const; |
43 | 51 |
44 private: | 52 private: |
45 void AddReference(); | 53 void AddReference(); |
46 | 54 |
47 EVP_PKEY* pkey_; | 55 EVP_PKEY* pkey_; |
48 | 56 |
49 RTC_DISALLOW_COPY_AND_ASSIGN(OpenSSLKeyPair); | 57 RTC_DISALLOW_COPY_AND_ASSIGN(OpenSSLKeyPair); |
50 }; | 58 }; |
51 | 59 |
52 // OpenSSLCertificate encapsulates an OpenSSL X509* certificate object, | 60 // OpenSSLCertificate encapsulates an OpenSSL X509* certificate object, |
53 // which is also reference counted inside the OpenSSL library. | 61 // which is also reference counted inside the OpenSSL library. |
54 class OpenSSLCertificate : public SSLCertificate { | 62 class OpenSSLCertificate : public SSLCertificate { |
55 public: | 63 public: |
56 // Caller retains ownership of the X509 object. | 64 // Caller retains ownership of the X509 object. |
57 explicit OpenSSLCertificate(X509* x509) : x509_(x509) { | 65 explicit OpenSSLCertificate(X509* x509) : x509_(x509) { |
58 AddReference(); | 66 AddReference(); |
59 } | 67 } |
60 | 68 |
61 static OpenSSLCertificate* Generate(OpenSSLKeyPair* key_pair, | 69 static OpenSSLCertificate* Generate(OpenSSLKeyPair* key_pair, |
62 const SSLIdentityParams& params); | 70 const SSLIdentityParams& params); |
63 static OpenSSLCertificate* FromPEMString(const std::string& pem_string); | 71 static OpenSSLCertificate* FromPEMString(const std::string& pem_string); |
64 | 72 |
65 ~OpenSSLCertificate() override; | 73 ~OpenSSLCertificate() override; |
66 | 74 |
67 OpenSSLCertificate* GetReference() const override; | 75 OpenSSLCertificate* GetReference() const override; |
68 | 76 |
69 X509* x509() const { return x509_; } | 77 X509* x509() const { return x509_; } |
70 | 78 |
71 std::string ToPEMString() const override; | 79 std::string ToPEMString() const override; |
72 | |
73 void ToDER(Buffer* der_buffer) const override; | 80 void ToDER(Buffer* der_buffer) const override; |
| 81 bool operator==(const OpenSSLCertificate& other) const; |
| 82 bool operator!=(const OpenSSLCertificate& other) const; |
74 | 83 |
75 // Compute the digest of the certificate given algorithm | 84 // Compute the digest of the certificate given algorithm |
76 bool ComputeDigest(const std::string& algorithm, | 85 bool ComputeDigest(const std::string& algorithm, |
77 unsigned char* digest, | 86 unsigned char* digest, |
78 size_t size, | 87 size_t size, |
79 size_t* length) const override; | 88 size_t* length) const override; |
80 | 89 |
81 // Compute the digest of a certificate as an X509 * | 90 // Compute the digest of a certificate as an X509 * |
82 static bool ComputeDigest(const X509* x509, | 91 static bool ComputeDigest(const X509* x509, |
83 const std::string& algorithm, | 92 const std::string& algorithm, |
(...skipping 25 matching lines...) Expand all Loading... |
109 static SSLIdentity* FromPEMStrings(const std::string& private_key, | 118 static SSLIdentity* FromPEMStrings(const std::string& private_key, |
110 const std::string& certificate); | 119 const std::string& certificate); |
111 ~OpenSSLIdentity() override; | 120 ~OpenSSLIdentity() override; |
112 | 121 |
113 const OpenSSLCertificate& certificate() const override; | 122 const OpenSSLCertificate& certificate() const override; |
114 OpenSSLIdentity* GetReference() const override; | 123 OpenSSLIdentity* GetReference() const override; |
115 | 124 |
116 // Configure an SSL context object to use our key and certificate. | 125 // Configure an SSL context object to use our key and certificate. |
117 bool ConfigureIdentity(SSL_CTX* ctx); | 126 bool ConfigureIdentity(SSL_CTX* ctx); |
118 | 127 |
| 128 std::string PrivateKeyToPEMString() const override; |
| 129 std::string PublicKeyToPEMString() const override; |
| 130 bool operator==(const OpenSSLIdentity& other) const; |
| 131 bool operator!=(const OpenSSLIdentity& other) const; |
| 132 |
119 private: | 133 private: |
120 OpenSSLIdentity(OpenSSLKeyPair* key_pair, OpenSSLCertificate* certificate); | 134 OpenSSLIdentity(OpenSSLKeyPair* key_pair, OpenSSLCertificate* certificate); |
121 | 135 |
122 static OpenSSLIdentity* GenerateInternal(const SSLIdentityParams& params); | 136 static OpenSSLIdentity* GenerateInternal(const SSLIdentityParams& params); |
123 | 137 |
124 std::unique_ptr<OpenSSLKeyPair> key_pair_; | 138 std::unique_ptr<OpenSSLKeyPair> key_pair_; |
125 std::unique_ptr<OpenSSLCertificate> certificate_; | 139 std::unique_ptr<OpenSSLCertificate> certificate_; |
126 | 140 |
127 RTC_DISALLOW_COPY_AND_ASSIGN(OpenSSLIdentity); | 141 RTC_DISALLOW_COPY_AND_ASSIGN(OpenSSLIdentity); |
128 }; | 142 }; |
129 | 143 |
130 | 144 |
131 } // namespace rtc | 145 } // namespace rtc |
132 | 146 |
133 #endif // WEBRTC_BASE_OPENSSLIDENTITY_H_ | 147 #endif // WEBRTC_BASE_OPENSSLIDENTITY_H_ |
OLD | NEW |