-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from niscy-eudiw/feature/x509-client-id-scheme
Feature/x509 client id scheme
- Loading branch information
Showing
12 changed files
with
277 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (c) 2023 European Commission | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import Foundation | ||
import X509 | ||
|
||
extension SubjectAlternativeNames { | ||
func rawSubjectAlternativeNames() -> [String] { | ||
self.compactMap { generalName in | ||
switch generalName { | ||
case .dnsName(let name): | ||
return name | ||
default: return nil | ||
} | ||
} | ||
} | ||
|
||
func rawUniformResourceIdentifiers() -> [String] { | ||
self.compactMap { generalName in | ||
switch generalName { | ||
case .uniformResourceIdentifier(let identifier): | ||
return identifier | ||
default: return nil | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright (c) 2023 European Commission | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import XCTest | ||
import X509 | ||
|
||
@testable import SiopOpenID4VP | ||
|
||
final class X509CertificateTests: XCTestCase { | ||
|
||
override func setUpWithError() throws { | ||
} | ||
|
||
override func tearDownWithError() throws { | ||
} | ||
|
||
func testSecKeyCreationFromX509Certificate() throws { | ||
|
||
if let data = Data(base64Encoded: TestsConstants.x5cCertificate) { | ||
let derBytes = [UInt8](data) | ||
let certificate = try Certificate(derEncoded: derBytes) | ||
|
||
let publicKey = certificate.publicKey | ||
let pem = try publicKey.serializeAsPEM().pemString | ||
|
||
let secKey = try KeyController.convertPEMToPublicKey(pem) | ||
XCTAssertNotNil(secKey) | ||
|
||
let clientIndentifier = "client_identifer.example.com" | ||
guard let dnss = try? certificate.extensions.subjectAlternativeNames?.rawSubjectAlternativeNames() else { | ||
XCTFail("Could not locate subject alternative names") | ||
return | ||
} | ||
XCTAssert(!dnss.isEmpty) | ||
XCTAssert(dnss.contains(where: { $0 == clientIndentifier })) | ||
|
||
let uri = "https://www.example.com" | ||
guard let uris = try? certificate.extensions.subjectAlternativeNames?.rawUniformResourceIdentifiers() else { | ||
XCTFail("Could not locate uri's") | ||
return | ||
} | ||
XCTAssert(!uris.isEmpty) | ||
XCTAssert(uris.contains(where: { $0 == uri })) | ||
|
||
let valid = publicKey.isValidSignature(certificate.signature, for: certificate) | ||
XCTAssert(valid) | ||
|
||
let legacyCertificate = SecCertificateCreateWithData(nil, data as CFData) | ||
XCTAssertNotNil(legacyCertificate) | ||
|
||
} else { | ||
XCTFail("Could not get SecKey from base64 x509") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.