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 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
380 size_t length = strlen(entry.string); | 380 size_t length = strlen(entry.string); |
381 memcpy(buf, entry.string, length); // Copy the ASN1 string... | 381 memcpy(buf, entry.string, length); // Copy the ASN1 string... |
382 buf[length] = rtc::CreateRandomId(); // ...and terminate it with junk. | 382 buf[length] = rtc::CreateRandomId(); // ...and terminate it with junk. |
383 int64_t res = rtc::ASN1TimeToSec(buf, length - 1, entry.long_format); | 383 int64_t res = rtc::ASN1TimeToSec(buf, length - 1, entry.long_format); |
384 LOG(LS_VERBOSE) << entry.string; | 384 LOG(LS_VERBOSE) << entry.string; |
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 | |
391 // interfaces for expiration setting and reading. | |
390 for (int i = 0; i < times; i++) { | 392 for (int i = 0; i < times; i++) { |
391 rtc::SSLIdentityParams params; | |
392 params.common_name = ""; | |
393 params.not_before = 0; | |
394 // 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 |
395 // 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. |
396 params.not_after = rtc::CreateRandomId() % 0x80000000; | 395 time_t now = time(NULL); |
397 // We test just ECDSA here since what we're out to exercise here is the | 396 time_t lifetime = rtc::CreateRandomId() % (0x80000000 - now); |
hbos
2016/02/11 11:25:17
What about negative lifetimes? Generating an alrea
torbjorng (webrtc)
2016/02/11 13:41:48
That's an odd thing to do, and I don't think enfor
hbos
2016/02/11 14:56:45
I think it could be fine to require it to be posit
torbjorng (webrtc)
2016/02/11 15:26:00
Done.
| |
398 // code for expiration setting and reading. | 397 rtc::KeyParams key_params = rtc::KeyParams::ECDSA(rtc::EC_NIST_P256); |
399 params.key_params = rtc::KeyParams::ECDSA(rtc::EC_NIST_P256); | 398 SSLIdentity* identity = |
400 SSLIdentity* identity = rtc::SSLIdentity::GenerateForTest(params); | 399 rtc::SSLIdentity::Generate("", key_params, lifetime); |
hbos
2016/02/11 11:25:17
Is GenerateForTest still needed after this CL or c
torbjorng (webrtc)
2016/02/11 13:41:48
It is still used elsewhere (in sslstreamadapter_un
hbos
2016/02/11 14:56:45
Maybe have a TODO to clean it up some time in the
torbjorng (webrtc)
2016/02/11 15:26:00
Done.
| |
401 EXPECT_EQ(params.not_after, | 400 EXPECT_EQ(now + lifetime, |
402 identity->certificate().CertificateExpirationTime()); | 401 identity->certificate().CertificateExpirationTime()); |
403 delete identity; | 402 delete identity; |
404 } | 403 } |
405 } | 404 } |
406 }; | 405 }; |
407 | 406 |
408 TEST_F(SSLIdentityExpirationTest, TestASN1TimeToSec) { | 407 TEST_F(SSLIdentityExpirationTest, TestASN1TimeToSec) { |
409 TestASN1TimeToSec(); | 408 TestASN1TimeToSec(); |
410 } | 409 } |
411 | 410 |
412 TEST_F(SSLIdentityExpirationTest, TestExpireTime) { | 411 TEST_F(SSLIdentityExpirationTest, TestExpireTime) { |
413 TestExpireTime(500); | 412 TestExpireTime(500); |
414 } | 413 } |
OLD | NEW |