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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 } | 100 } |
101 | 101 |
102 // Helper function for deleting a vector of certificates. | 102 // Helper function for deleting a vector of certificates. |
103 static void DeleteCert(SSLCertificate* cert) { delete cert; } | 103 static void DeleteCert(SSLCertificate* cert) { delete cert; } |
104 | 104 |
105 std::vector<SSLCertificate*> certs_; | 105 std::vector<SSLCertificate*> certs_; |
106 | 106 |
107 DISALLOW_COPY_AND_ASSIGN(SSLCertChain); | 107 DISALLOW_COPY_AND_ASSIGN(SSLCertChain); |
108 }; | 108 }; |
109 | 109 |
| 110 enum KeyType { KT_RSA, KT_ECDSA, KT_DEFAULT = KT_RSA }; |
| 111 |
110 // Parameters for generating an identity for testing. If common_name is | 112 // Parameters for generating an identity for testing. If common_name is |
111 // non-empty, it will be used for the certificate's subject and issuer name, | 113 // non-empty, it will be used for the certificate's subject and issuer name, |
112 // otherwise a random string will be used. |not_before| and |not_after| are | 114 // otherwise a random string will be used. |not_before| and |not_after| are |
113 // offsets to the current time in number of seconds. | 115 // offsets to the current time in number of seconds. |
114 struct SSLIdentityParams { | 116 struct SSLIdentityParams { |
115 std::string common_name; | 117 std::string common_name; |
116 int not_before; // in seconds. | 118 int not_before; // in seconds. |
117 int not_after; // in seconds. | 119 int not_after; // in seconds. |
| 120 KeyType key_type; |
118 }; | 121 }; |
119 | 122 |
120 // Our identity in an SSL negotiation: a keypair and certificate (both | 123 // Our identity in an SSL negotiation: a keypair and certificate (both |
121 // with the same public key). | 124 // with the same public key). |
122 // This too is pretty much immutable once created. | 125 // This too is pretty much immutable once created. |
123 class SSLIdentity { | 126 class SSLIdentity { |
124 public: | 127 public: |
125 // Generates an identity (keypair and self-signed certificate). If | 128 // Generates an identity (keypair and self-signed certificate). If |
126 // common_name is non-empty, it will be used for the certificate's | 129 // common_name is non-empty, it will be used for the certificate's |
127 // subject and issuer name, otherwise a random string will be used. | 130 // subject and issuer name, otherwise a random string will be used. |
128 // Returns NULL on failure. | 131 // Returns NULL on failure. |
129 // Caller is responsible for freeing the returned object. | 132 // Caller is responsible for freeing the returned object. |
130 static SSLIdentity* Generate(const std::string& common_name); | 133 static SSLIdentity* Generate(const std::string& common_name, |
| 134 KeyType key_type); |
131 | 135 |
132 // Generates an identity with the specified validity period. | 136 // Generates an identity with the specified validity period. |
133 static SSLIdentity* GenerateForTest(const SSLIdentityParams& params); | 137 static SSLIdentity* GenerateForTest(const SSLIdentityParams& params); |
134 | 138 |
135 // Construct an identity from a private key and a certificate. | 139 // Construct an identity from a private key and a certificate. |
136 static SSLIdentity* FromPEMStrings(const std::string& private_key, | 140 static SSLIdentity* FromPEMStrings(const std::string& private_key, |
137 const std::string& certificate); | 141 const std::string& certificate); |
138 | 142 |
139 virtual ~SSLIdentity() {} | 143 virtual ~SSLIdentity() {} |
140 | 144 |
141 // Returns a new SSLIdentity object instance wrapping the same | 145 // Returns a new SSLIdentity object instance wrapping the same |
142 // identity information. | 146 // identity information. |
143 // Caller is responsible for freeing the returned object. | 147 // Caller is responsible for freeing the returned object. |
144 virtual SSLIdentity* GetReference() const = 0; | 148 virtual SSLIdentity* GetReference() const = 0; |
145 | 149 |
146 // Returns a temporary reference to the certificate. | 150 // Returns a temporary reference to the certificate. |
147 virtual const SSLCertificate& certificate() const = 0; | 151 virtual const SSLCertificate& certificate() const = 0; |
148 | 152 |
149 // Helpers for parsing converting between PEM and DER format. | 153 // Helpers for parsing converting between PEM and DER format. |
150 static bool PemToDer(const std::string& pem_type, | 154 static bool PemToDer(const std::string& pem_type, |
151 const std::string& pem_string, | 155 const std::string& pem_string, |
152 std::string* der); | 156 std::string* der); |
153 static std::string DerToPem(const std::string& pem_type, | 157 static std::string DerToPem(const std::string& pem_type, |
154 const unsigned char* data, | 158 const unsigned char* data, |
155 size_t length); | 159 size_t length); |
156 }; | 160 }; |
157 | 161 |
158 extern const char kPemTypeCertificate[]; | 162 extern const char kPemTypeCertificate[]; |
159 extern const char kPemTypeRsaPrivateKey[]; | 163 extern const char kPemTypeRsaPrivateKey[]; |
| 164 extern const char kPemTypeEcPrivateKey[]; |
160 | 165 |
161 } // namespace rtc | 166 } // namespace rtc |
162 | 167 |
163 #endif // WEBRTC_BASE_SSLIDENTITY_H_ | 168 #endif // WEBRTC_BASE_SSLIDENTITY_H_ |
OLD | NEW |