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 <string> | 11 #include <string> |
12 | 12 |
13 #include "webrtc/base/gunit.h" | 13 #include "webrtc/base/gunit.h" |
14 #include "webrtc/base/helpers.h" | |
14 #include "webrtc/base/ssladapter.h" | 15 #include "webrtc/base/ssladapter.h" |
15 #include "webrtc/base/sslidentity.h" | 16 #include "webrtc/base/sslidentity.h" |
16 | 17 |
17 using rtc::SSLIdentity; | 18 using rtc::SSLIdentity; |
18 | 19 |
19 const char kTestCertificate[] = "-----BEGIN CERTIFICATE-----\n" | 20 const char kTestCertificate[] = "-----BEGIN CERTIFICATE-----\n" |
20 "MIIB6TCCAVICAQYwDQYJKoZIhvcNAQEEBQAwWzELMAkGA1UEBhMCQVUxEzARBgNV\n" | 21 "MIIB6TCCAVICAQYwDQYJKoZIhvcNAQEEBQAwWzELMAkGA1UEBhMCQVUxEzARBgNV\n" |
21 "BAgTClF1ZWVuc2xhbmQxGjAYBgNVBAoTEUNyeXB0U29mdCBQdHkgTHRkMRswGQYD\n" | 22 "BAgTClF1ZWVuc2xhbmQxGjAYBgNVBAoTEUNyeXB0U29mdCBQdHkgTHRkMRswGQYD\n" |
22 "VQQDExJUZXN0IENBICgxMDI0IGJpdCkwHhcNMDAxMDE2MjIzMTAzWhcNMDMwMTE0\n" | 23 "VQQDExJUZXN0IENBICgxMDI0IGJpdCkwHhcNMDAxMDE2MjIzMTAzWhcNMDMwMTE0\n" |
23 "MjIzMTAzWjBjMQswCQYDVQQGEwJBVTETMBEGA1UECBMKUXVlZW5zbGFuZDEaMBgG\n" | 24 "MjIzMTAzWjBjMQswCQYDVQQGEwJBVTETMBEGA1UECBMKUXVlZW5zbGFuZDEaMBgG\n" |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
288 EXPECT_TRUE(SSLIdentity::PemToDer("CERTIFICATE", kTestCertificate, &der)); | 289 EXPECT_TRUE(SSLIdentity::PemToDer("CERTIFICATE", kTestCertificate, &der)); |
289 | 290 |
290 EXPECT_EQ(kTestCertificate, SSLIdentity::DerToPem( | 291 EXPECT_EQ(kTestCertificate, SSLIdentity::DerToPem( |
291 "CERTIFICATE", | 292 "CERTIFICATE", |
292 reinterpret_cast<const unsigned char*>(der.data()), der.length())); | 293 reinterpret_cast<const unsigned char*>(der.data()), der.length())); |
293 } | 294 } |
294 | 295 |
295 TEST_F(SSLIdentityTest, GetSignatureDigestAlgorithm) { | 296 TEST_F(SSLIdentityTest, GetSignatureDigestAlgorithm) { |
296 TestGetSignatureDigestAlgorithm(); | 297 TestGetSignatureDigestAlgorithm(); |
297 } | 298 } |
299 | |
300 class SSLIdentityExpirationTest : public testing::Test { | |
301 public: | |
302 SSLIdentityExpirationTest() {} | |
303 ~SSLIdentityExpirationTest() {} | |
304 | |
305 void TestExpireTime(int times) { | |
306 for (int i = 0; i < times; i++) { | |
307 rtc::SSLIdentityParams params; | |
308 params.common_name = ""; | |
309 params.not_before = 0; | |
310 // We limit the time to < 2^31 here, i.e., we stay before 2038, since else | |
311 // we hit time offset limitations in OpenSSL on some 32-bit systems. | |
312 params.not_after = rtc::CreateRandomId() % 0x80000000; | |
313 // We test just ECDSA here since what we're out to exercise here is the | |
314 // code for expiration setting and reading. | |
315 params.key_params = rtc::KeyParams::ECDSA(rtc::EC_NIST_P256); | |
316 SSLIdentity* identity = rtc::SSLIdentity::GenerateForTest(params); | |
317 EXPECT_EQ(params.not_after, | |
318 identity->certificate().CertificateExpirationTime()); | |
319 delete identity; | |
320 } | |
321 } | |
322 }; | |
323 | |
324 TEST_F(SSLIdentityExpirationTest, Test) { | |
325 rtc::SetRandomTestMode(true); | |
326 TestExpireTime(500); | |
hbos
2015/11/26 16:43:37
If TestExpireTime(500) fails, will the effects of
| |
327 rtc::SetRandomTestMode(false); | |
328 } | |
OLD | NEW |