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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 // TODO(hbos,torbjorng): Don't change KT_DEFAULT without first updating | 118 // TODO(hbos,torbjorng): Don't change KT_DEFAULT without first updating |
119 // PeerConnectionFactory_nativeCreatePeerConnection's certificate generation | 119 // PeerConnectionFactory_nativeCreatePeerConnection's certificate generation |
120 // code. | 120 // code. |
121 enum KeyType { KT_RSA, KT_ECDSA, KT_LAST, KT_DEFAULT = KT_RSA }; | 121 enum KeyType { KT_RSA, KT_ECDSA, KT_LAST, KT_DEFAULT = KT_RSA }; |
122 | 122 |
123 static const int kRsaDefaultModSize = 1024; | 123 static const int kRsaDefaultModSize = 1024; |
124 static const int kRsaDefaultExponent = 0x10001; // = 2^16+1 = 65537 | 124 static const int kRsaDefaultExponent = 0x10001; // = 2^16+1 = 65537 |
125 static const int kRsaMinModSize = 1024; | 125 static const int kRsaMinModSize = 1024; |
126 static const int kRsaMaxModSize = 8192; | 126 static const int kRsaMaxModSize = 8192; |
127 | 127 |
| 128 // Certificate default validity lifetime. |
| 129 static const int CERTIFICATE_LIFETIME = 60*60*24*30; // 30 days, arbitrarily |
| 130 // Certificate validity window. |
| 131 // This is to compensate for slightly incorrect system clocks. |
| 132 static const int CERTIFICATE_WINDOW = -60*60*24; |
| 133 |
128 struct RSAParams { | 134 struct RSAParams { |
129 unsigned int mod_size; | 135 unsigned int mod_size; |
130 unsigned int pub_exp; | 136 unsigned int pub_exp; |
131 }; | 137 }; |
132 | 138 |
133 enum ECCurve { EC_NIST_P256, /* EC_FANCY, */ EC_LAST }; | 139 enum ECCurve { EC_NIST_P256, /* EC_FANCY, */ EC_LAST }; |
134 | 140 |
135 class KeyParams { | 141 class KeyParams { |
136 public: | 142 public: |
137 // Generate a KeyParams object from a simple KeyType, using default params. | 143 // Generate a KeyParams object from a simple KeyType, using default params. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 // with the same public key). | 188 // with the same public key). |
183 // This too is pretty much immutable once created. | 189 // This too is pretty much immutable once created. |
184 class SSLIdentity { | 190 class SSLIdentity { |
185 public: | 191 public: |
186 // Generates an identity (keypair and self-signed certificate). If | 192 // Generates an identity (keypair and self-signed certificate). If |
187 // common_name is non-empty, it will be used for the certificate's | 193 // common_name is non-empty, it will be used for the certificate's |
188 // subject and issuer name, otherwise a random string will be used. | 194 // subject and issuer name, otherwise a random string will be used. |
189 // Returns NULL on failure. | 195 // Returns NULL on failure. |
190 // Caller is responsible for freeing the returned object. | 196 // Caller is responsible for freeing the returned object. |
191 static SSLIdentity* Generate(const std::string& common_name, | 197 static SSLIdentity* Generate(const std::string& common_name, |
192 const KeyParams& key_param); | 198 const KeyParams& key_param, |
| 199 time_t certificate_lifetime); |
| 200 static SSLIdentity* Generate(const std::string& common_name, |
| 201 const KeyParams& key_param) { |
| 202 return Generate(common_name, key_param, CERTIFICATE_LIFETIME); |
| 203 } |
193 static SSLIdentity* Generate(const std::string& common_name, | 204 static SSLIdentity* Generate(const std::string& common_name, |
194 KeyType key_type) { | 205 KeyType key_type) { |
195 return Generate(common_name, KeyParams(key_type)); | 206 return Generate(common_name, KeyParams(key_type)); |
196 } | 207 } |
197 | 208 |
198 // Generates an identity with the specified validity period. | 209 // Generates an identity with the specified validity period. |
199 static SSLIdentity* GenerateForTest(const SSLIdentityParams& params); | 210 static SSLIdentity* GenerateForTest(const SSLIdentityParams& params); |
200 | 211 |
201 // Construct an identity from a private key and a certificate. | 212 // Construct an identity from a private key and a certificate. |
202 static SSLIdentity* FromPEMStrings(const std::string& private_key, | 213 static SSLIdentity* FromPEMStrings(const std::string& private_key, |
(...skipping 24 matching lines...) Expand all Loading... |
227 // |s| is not 0-terminated; its char count is defined by |length|. | 238 // |s| is not 0-terminated; its char count is defined by |length|. |
228 int64_t ASN1TimeToSec(const unsigned char* s, size_t length, bool long_format); | 239 int64_t ASN1TimeToSec(const unsigned char* s, size_t length, bool long_format); |
229 | 240 |
230 extern const char kPemTypeCertificate[]; | 241 extern const char kPemTypeCertificate[]; |
231 extern const char kPemTypeRsaPrivateKey[]; | 242 extern const char kPemTypeRsaPrivateKey[]; |
232 extern const char kPemTypeEcPrivateKey[]; | 243 extern const char kPemTypeEcPrivateKey[]; |
233 | 244 |
234 } // namespace rtc | 245 } // namespace rtc |
235 | 246 |
236 #endif // WEBRTC_BASE_SSLIDENTITY_H_ | 247 #endif // WEBRTC_BASE_SSLIDENTITY_H_ |
OLD | NEW |