| 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 |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 ASSERT_EQ(-1, res); | 385 ASSERT_EQ(-1, res); |
| 386 } | 386 } |
| 387 } | 387 } |
| 388 | 388 |
| 389 void TestExpireTime(int times) { | 389 void TestExpireTime(int times) { |
| 390 // We test just ECDSA here since what we're out to exercise is the | 390 // We test just ECDSA here since what we're out to exercise is the |
| 391 // interfaces for expiration setting and reading. | 391 // interfaces for expiration setting and reading. |
| 392 for (int i = 0; i < times; i++) { | 392 for (int i = 0; i < times; i++) { |
| 393 // We limit the time to < 2^31 here, i.e., we stay before 2038, since else | 393 // We limit the time to < 2^31 here, i.e., we stay before 2038, since else |
| 394 // we hit time offset limitations in OpenSSL on some 32-bit systems. | 394 // we hit time offset limitations in OpenSSL on some 32-bit systems. |
| 395 time_t now = time(NULL); | 395 time_t time_before_generation = time(nullptr); |
| 396 time_t lifetime = rtc::CreateRandomId() % (0x80000000 - now); | 396 time_t lifetime = |
| 397 rtc::CreateRandomId() % (0x80000000 - time_before_generation); |
| 397 rtc::KeyParams key_params = rtc::KeyParams::ECDSA(rtc::EC_NIST_P256); | 398 rtc::KeyParams key_params = rtc::KeyParams::ECDSA(rtc::EC_NIST_P256); |
| 398 SSLIdentity* identity = | 399 SSLIdentity* identity = |
| 399 rtc::SSLIdentity::Generate("", key_params, lifetime); | 400 rtc::SSLIdentity::Generate("", key_params, lifetime); |
| 400 EXPECT_EQ(now + lifetime, | 401 time_t time_after_generation = time(nullptr); |
| 402 EXPECT_LE(time_before_generation + lifetime, |
| 403 identity->certificate().CertificateExpirationTime()); |
| 404 EXPECT_GE(time_after_generation + lifetime, |
| 401 identity->certificate().CertificateExpirationTime()); | 405 identity->certificate().CertificateExpirationTime()); |
| 402 delete identity; | 406 delete identity; |
| 403 } | 407 } |
| 404 } | 408 } |
| 405 }; | 409 }; |
| 406 | 410 |
| 407 TEST_F(SSLIdentityExpirationTest, TestASN1TimeToSec) { | 411 TEST_F(SSLIdentityExpirationTest, TestASN1TimeToSec) { |
| 408 TestASN1TimeToSec(); | 412 TestASN1TimeToSec(); |
| 409 } | 413 } |
| 410 | 414 |
| 411 TEST_F(SSLIdentityExpirationTest, TestExpireTime) { | 415 TEST_F(SSLIdentityExpirationTest, TestExpireTime) { |
| 412 TestExpireTime(500); | 416 TestExpireTime(500); |
| 413 } | 417 } |
| OLD | NEW |