OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2011 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 |
| 11 #include <memory> |
11 #include <string> | 12 #include <string> |
12 | 13 |
13 #include "webrtc/base/gunit.h" | 14 #include "webrtc/base/gunit.h" |
14 #include "webrtc/base/helpers.h" | 15 #include "webrtc/base/helpers.h" |
15 #include "webrtc/base/ssladapter.h" | 16 #include "webrtc/base/ssladapter.h" |
16 #include "webrtc/base/sslidentity.h" | 17 #include "webrtc/base/sslidentity.h" |
17 | 18 |
18 using rtc::SSLIdentity; | 19 using rtc::SSLIdentity; |
19 | 20 |
20 const char kTestCertificate[] = "-----BEGIN CERTIFICATE-----\n" | 21 const char kTestCertificate[] = "-----BEGIN CERTIFICATE-----\n" |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 ASSERT_TRUE(expected_len <= sizeof(DigestType)); | 168 ASSERT_TRUE(expected_len <= sizeof(DigestType)); |
168 | 169 |
169 rv = test_cert_->ComputeDigest(algorithm, digest, sizeof(digest), | 170 rv = test_cert_->ComputeDigest(algorithm, digest, sizeof(digest), |
170 &digest_len); | 171 &digest_len); |
171 EXPECT_TRUE(rv); | 172 EXPECT_TRUE(rv); |
172 EXPECT_EQ(expected_len, digest_len); | 173 EXPECT_EQ(expected_len, digest_len); |
173 EXPECT_EQ(0, memcmp(digest, expected_digest, expected_len)); | 174 EXPECT_EQ(0, memcmp(digest, expected_digest, expected_len)); |
174 } | 175 } |
175 | 176 |
176 private: | 177 private: |
177 rtc::scoped_ptr<SSLIdentity> identity_rsa1_; | 178 std::unique_ptr<SSLIdentity> identity_rsa1_; |
178 rtc::scoped_ptr<SSLIdentity> identity_rsa2_; | 179 std::unique_ptr<SSLIdentity> identity_rsa2_; |
179 rtc::scoped_ptr<SSLIdentity> identity_ecdsa1_; | 180 std::unique_ptr<SSLIdentity> identity_ecdsa1_; |
180 rtc::scoped_ptr<SSLIdentity> identity_ecdsa2_; | 181 std::unique_ptr<SSLIdentity> identity_ecdsa2_; |
181 rtc::scoped_ptr<rtc::SSLCertificate> test_cert_; | 182 std::unique_ptr<rtc::SSLCertificate> test_cert_; |
182 }; | 183 }; |
183 | 184 |
184 TEST_F(SSLIdentityTest, FixedDigestSHA1) { | 185 TEST_F(SSLIdentityTest, FixedDigestSHA1) { |
185 TestDigestForFixedCert(rtc::DIGEST_SHA_1, 20, kTestCertSha1); | 186 TestDigestForFixedCert(rtc::DIGEST_SHA_1, 20, kTestCertSha1); |
186 } | 187 } |
187 | 188 |
188 // HASH_AlgSHA224 is not supported in the chromium linux build. | 189 // HASH_AlgSHA224 is not supported in the chromium linux build. |
189 TEST_F(SSLIdentityTest, FixedDigestSHA224) { | 190 TEST_F(SSLIdentityTest, FixedDigestSHA224) { |
190 TestDigestForFixedCert(rtc::DIGEST_SHA_224, 28, kTestCertSha224); | 191 TestDigestForFixedCert(rtc::DIGEST_SHA_224, 28, kTestCertSha224); |
191 } | 192 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 "ZWJSVEMwHhcNMTQwMTAyMTgyNDQ3WhcNMTQwMjAxMTgyNDQ3WjARMQ8wDQYDVQQD\n" | 245 "ZWJSVEMwHhcNMTQwMTAyMTgyNDQ3WhcNMTQwMjAxMTgyNDQ3WjARMQ8wDQYDVQQD\n" |
245 "EwZXZWJSVEMwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMYRkbhmI7kVA/rM\n" | 246 "EwZXZWJSVEMwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMYRkbhmI7kVA/rM\n" |
246 "czsZ+6JDhDvnkF+vn6yCAGuRPV03zuRqZtDy4N4to7PZu9PjqrRl7nDMXrG3YG9y\n" | 247 "czsZ+6JDhDvnkF+vn6yCAGuRPV03zuRqZtDy4N4to7PZu9PjqrRl7nDMXrG3YG9y\n" |
247 "rlIAZ72KjcKKFAJxQyAKLCIdawKRyp8RdK3LEySWEZb0AV58IadqPZDTNHHRX8dz\n" | 248 "rlIAZ72KjcKKFAJxQyAKLCIdawKRyp8RdK3LEySWEZb0AV58IadqPZDTNHHRX8dz\n" |
248 "5aTSMsbbkZ+C/OzTnbiMqLL/vg6jAgMBAAEwDQYJKoZIhvcNAQELBQADgYEAUflI\n" | 249 "5aTSMsbbkZ+C/OzTnbiMqLL/vg6jAgMBAAEwDQYJKoZIhvcNAQELBQADgYEAUflI\n" |
249 "VUe5Krqf5RVa5C3u/UTAOAUJBiDS3VANTCLBxjuMsvqOG0WvaYWP3HYPgrz0jXK2\n" | 250 "VUe5Krqf5RVa5C3u/UTAOAUJBiDS3VANTCLBxjuMsvqOG0WvaYWP3HYPgrz0jXK2\n" |
250 "LJE/mGw3MyFHEqi81jh95J+ypl6xKW6Rm8jKLR87gUvCaVYn/Z4/P3AqcQTB7wOv\n" | 251 "LJE/mGw3MyFHEqi81jh95J+ypl6xKW6Rm8jKLR87gUvCaVYn/Z4/P3AqcQTB7wOv\n" |
251 "UD0A8qfhfDM+LK6rPAnCsVN0NRDY3jvd6rzix9M=\n" | 252 "UD0A8qfhfDM+LK6rPAnCsVN0NRDY3jvd6rzix9M=\n" |
252 "-----END CERTIFICATE-----\n"; | 253 "-----END CERTIFICATE-----\n"; |
253 | 254 |
254 rtc::scoped_ptr<SSLIdentity> identity( | 255 std::unique_ptr<SSLIdentity> identity( |
255 SSLIdentity::FromPEMStrings(kRSA_PRIVATE_KEY_PEM, kCERT_PEM)); | 256 SSLIdentity::FromPEMStrings(kRSA_PRIVATE_KEY_PEM, kCERT_PEM)); |
256 EXPECT_TRUE(identity); | 257 EXPECT_TRUE(identity); |
257 EXPECT_EQ(kCERT_PEM, identity->certificate().ToPEMString()); | 258 EXPECT_EQ(kCERT_PEM, identity->certificate().ToPEMString()); |
258 } | 259 } |
259 | 260 |
260 TEST_F(SSLIdentityTest, FromPEMStringsEC) { | 261 TEST_F(SSLIdentityTest, FromPEMStringsEC) { |
261 static const char kRSA_PRIVATE_KEY_PEM[] = | 262 static const char kRSA_PRIVATE_KEY_PEM[] = |
262 "-----BEGIN EC PRIVATE KEY-----\n" | 263 "-----BEGIN EC PRIVATE KEY-----\n" |
263 "MHcCAQEEIKkIztWLPbs4Y2zWv7VW2Ov4is2ifleCuPgRB8fRv3IkoAoGCCqGSM49\n" | 264 "MHcCAQEEIKkIztWLPbs4Y2zWv7VW2Ov4is2ifleCuPgRB8fRv3IkoAoGCCqGSM49\n" |
264 "AwEHoUQDQgAEDPV33NrhSdhg9cBRkUWUXnVMXc3h17i9ARbSmNgminKcBXb8/y8L\n" | 265 "AwEHoUQDQgAEDPV33NrhSdhg9cBRkUWUXnVMXc3h17i9ARbSmNgminKcBXb8/y8L\n" |
265 "A76cMWQPPM0ybHO8OS7ZVg2U/m+TwE1M2g==\n" | 266 "A76cMWQPPM0ybHO8OS7ZVg2U/m+TwE1M2g==\n" |
266 "-----END EC PRIVATE KEY-----\n"; | 267 "-----END EC PRIVATE KEY-----\n"; |
267 static const char kCERT_PEM[] = | 268 static const char kCERT_PEM[] = |
268 "-----BEGIN CERTIFICATE-----\n" | 269 "-----BEGIN CERTIFICATE-----\n" |
269 "MIIB0jCCAXmgAwIBAgIJAMCjpFt9t6LMMAoGCCqGSM49BAMCMEUxCzAJBgNVBAYT\n" | 270 "MIIB0jCCAXmgAwIBAgIJAMCjpFt9t6LMMAoGCCqGSM49BAMCMEUxCzAJBgNVBAYT\n" |
270 "AkFVMRMw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l2cxmDtOIQr\n" | 278 "/zAKBggqhkjOPQQDAgNHADBEAiAQRojsTyZG0BlKoU7gOt5h+yAMLl2cxmDtOIQr\n" |
278 "GWP/PwIgJynB4AUDsPT0DWmethOXYijB5sY5UPd9DvgmiS/Mr6s=\n" | 279 "GWP/PwIgJynB4AUDsPT0DWmethOXYijB5sY5UPd9DvgmiS/Mr6s=\n" |
279 "-----END CERTIFICATE-----\n"; | 280 "-----END CERTIFICATE-----\n"; |
280 | 281 |
281 rtc::scoped_ptr<SSLIdentity> identity( | 282 std::unique_ptr<SSLIdentity> identity( |
282 SSLIdentity::FromPEMStrings(kRSA_PRIVATE_KEY_PEM, kCERT_PEM)); | 283 SSLIdentity::FromPEMStrings(kRSA_PRIVATE_KEY_PEM, kCERT_PEM)); |
283 EXPECT_TRUE(identity); | 284 EXPECT_TRUE(identity); |
284 EXPECT_EQ(kCERT_PEM, identity->certificate().ToPEMString()); | 285 EXPECT_EQ(kCERT_PEM, identity->certificate().ToPEMString()); |
285 } | 286 } |
286 | 287 |
287 TEST_F(SSLIdentityTest, PemDerConversion) { | 288 TEST_F(SSLIdentityTest, PemDerConversion) { |
288 std::string der; | 289 std::string der; |
289 EXPECT_TRUE(SSLIdentity::PemToDer("CERTIFICATE", kTestCertificate, &der)); | 290 EXPECT_TRUE(SSLIdentity::PemToDer("CERTIFICATE", kTestCertificate, &der)); |
290 | 291 |
291 EXPECT_EQ(kTestCertificate, SSLIdentity::DerToPem( | 292 EXPECT_EQ(kTestCertificate, SSLIdentity::DerToPem( |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 } | 409 } |
409 }; | 410 }; |
410 | 411 |
411 TEST_F(SSLIdentityExpirationTest, TestASN1TimeToSec) { | 412 TEST_F(SSLIdentityExpirationTest, TestASN1TimeToSec) { |
412 TestASN1TimeToSec(); | 413 TestASN1TimeToSec(); |
413 } | 414 } |
414 | 415 |
415 TEST_F(SSLIdentityExpirationTest, TestExpireTime) { | 416 TEST_F(SSLIdentityExpirationTest, TestExpireTime) { |
416 TestExpireTime(500); | 417 TestExpireTime(500); |
417 } | 418 } |
OLD | NEW |