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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 // Parameters for generating an identity for testing. If common_name is | 110 // 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, | 111 // 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 | 112 // otherwise a random string will be used. |not_before| and |not_after| are |
113 // offsets to the current time in number of seconds. | 113 // offsets to the current time in number of seconds. |
114 struct SSLIdentityParams { | 114 struct SSLIdentityParams { |
115 std::string common_name; | 115 std::string common_name; |
116 int not_before; // in seconds. | 116 int not_before; // in seconds. |
117 int not_after; // in seconds. | 117 int not_after; // in seconds. |
118 }; | 118 }; |
119 | 119 |
| 120 enum KeyType { KT_RSA, KT_ECDSA, KT_DEFAULT = KT_RSA }; |
| 121 |
120 // Our identity in an SSL negotiation: a keypair and certificate (both | 122 // Our identity in an SSL negotiation: a keypair and certificate (both |
121 // with the same public key). | 123 // with the same public key). |
122 // This too is pretty much immutable once created. | 124 // This too is pretty much immutable once created. |
123 class SSLIdentity { | 125 class SSLIdentity { |
124 public: | 126 public: |
125 // Generates an identity (keypair and self-signed certificate). If | 127 // Generates an identity (keypair and self-signed certificate). If |
126 // common_name is non-empty, it will be used for the certificate's | 128 // 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. | 129 // subject and issuer name, otherwise a random string will be used. |
128 // Returns NULL on failure. | 130 // Returns NULL on failure. |
129 // Caller is responsible for freeing the returned object. | 131 // Caller is responsible for freeing the returned object. |
130 static SSLIdentity* Generate(const std::string& common_name); | 132 static SSLIdentity* Generate(const std::string& common_name, |
| 133 KeyType key_type); |
131 | 134 |
132 // Generates an identity with the specified validity period. | 135 // Generates an identity with the specified validity period. |
133 static SSLIdentity* GenerateForTest(const SSLIdentityParams& params); | 136 static SSLIdentity* GenerateForTest(const SSLIdentityParams& params, |
| 137 KeyType key_type); |
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. |
(...skipping 10 matching lines...) Expand all Loading... |
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[]; |
160 | 164 |
161 } // namespace rtc | 165 } // namespace rtc |
162 | 166 |
163 #endif // WEBRTC_BASE_SSLIDENTITY_H_ | 167 #endif // WEBRTC_BASE_SSLIDENTITY_H_ |
OLD | NEW |