Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/X509/OCSP/OCSPCertID.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct OCSPCertID: DERImplicitlyTaggable, Hashable {
return .sha256UsingNil
case .sha384, .sha384UsingNil:
return .sha384UsingNil
case .sha512, .sha1UsingNil:
case .sha512, .sha512UsingNil:
return .sha512UsingNil
default:
return hashAlgorithm
Expand Down
29 changes: 29 additions & 0 deletions Tests/X509Tests/OCSPTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,35 @@ final class OCSPTests: XCTestCase {
try self.assertRoundTrips(certID)
}

func testCertIDNormalizesHashAlgorithmParameters() throws {
// Parsing must normalize the absent-parameters spelling of each supported hash
// algorithm to the explicit-NULL-parameters spelling, and leave the latter unchanged.
let normalizations: [(AlgorithmIdentifier, AlgorithmIdentifier)] = [
(.sha1, .sha1UsingNil),
(.sha1UsingNil, .sha1UsingNil),
(.sha256, .sha256UsingNil),
(.sha256UsingNil, .sha256UsingNil),
(.sha384, .sha384UsingNil),
(.sha384UsingNil, .sha384UsingNil),
(.sha512, .sha512UsingNil),
(.sha512UsingNil, .sha512UsingNil),
]

for (spelling, normalized) in normalizations {
let certID = OCSPCertID(
hashAlgorithm: spelling,
issuerNameHash: ASN1OctetString(contentBytes: [1, 2, 3, 4]),
issuerKeyHash: ASN1OctetString(contentBytes: [5, 6, 7, 8]),
serialNumber: .init(bytes: [9, 10, 11, 12])
)

var serializer = DER.Serializer()
try serializer.serialize(certID)
let parsed = try OCSPCertID(derEncoded: serializer.serializedBytes)
XCTAssertEqual(parsed.hashAlgorithm, normalized, "\(spelling) should normalize to \(normalized)")
}
}

func testOCSPCertIDSerialization() throws {
let certID = OCSPCertID(
hashAlgorithm: .p256PublicKey,
Expand Down