Skip to content

Commit 0578692

Browse files
authored
CBL-7107: Identity/Cert expiration date should not be too old (#3474)
1 parent b140cf6 commit 0578692

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

Objective-C/Tests/TLSIdentityTest.m

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,20 @@ - (void) testCreateIdentityWithNoAttributes {
522522
Assert([error.localizedDescription containsString: @"-67655"]);
523523
}
524524

525+
- (void) testCertificateExpirationAlreadyPast {
526+
XCTSkipUnless(self.keyChainAccessAllowed);
527+
NSDate* expired = [NSDate distantPast];
528+
529+
[self expectException: @"NSInvalidArgumentException" in:^{
530+
NSError* error;
531+
[CBLTLSIdentity createIdentityForKeyUsages: kCBLKeyUsagesServerAuth
532+
attributes: kServerCertAttrs
533+
expiration: expired
534+
label: kServerCertLabel
535+
error: &error];
536+
}];
537+
}
538+
525539
- (void) testCertificateExpiration {
526540
XCTSkipUnless(self.keyChainAccessAllowed);
527541

Swift/Tests/TLSIdentityTest.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,21 @@ class TLSIdentityTest: CBLTestCase {
412412
}
413413
}
414414

415+
func testCertificateExpirationAlreadyPast() throws {
416+
try XCTSkipUnless(keyChainAccessAllowed)
417+
418+
// A date definitely in the past
419+
let expired = Date.distantPast
420+
421+
expectException(exception: .invalidArgumentException) {
422+
_ = try? TLSIdentity.createIdentity(
423+
for: .serverAuth,
424+
attributes: [certAttrCommonName: "CBL-Server"],
425+
expiration: expired,
426+
label: self.serverCertLabel)
427+
}
428+
}
429+
415430
func testCertificateExpiration() throws {
416431
try XCTSkipUnless(keyChainAccessAllowed)
417432

0 commit comments

Comments
 (0)