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