Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: webrtc/base/sslidentity_unittest.cc

Issue 1683193003: Implement certificate lifetime parameter as required by WebRTC RFC. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Address feedback Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« webrtc/base/sslidentity.cc ('K') | « webrtc/base/sslidentity.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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);
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);
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 }
OLDNEW
« webrtc/base/sslidentity.cc ('K') | « webrtc/base/sslidentity.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698