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