From fd0581e51fc1f57c6b392963871ccc63a7172929 Mon Sep 17 00:00:00 2001 From: dtsiflit Date: Mon, 30 Sep 2024 10:44:54 +0300 Subject: [PATCH] [fix] sdjwtvc verifier protovol, added x509 package --- Package.resolved | 27 ++++++++++++++++++++++++ Package.swift | 7 ++++++- Sources/Verifier/SDJWTVerifier.swift | 29 +++++++++++++++++--------- Sources/Verifier/SdJwtVcVerifier.swift | 22 +++++++++++++++++++ 4 files changed, 74 insertions(+), 11 deletions(-) create mode 100644 Sources/Verifier/SdJwtVcVerifier.swift diff --git a/Package.resolved b/Package.resolved index 7ddd407..155af77 100644 --- a/Package.resolved +++ b/Package.resolved @@ -27,6 +27,33 @@ "version" : "0.15.0" } }, + { + "identity" : "swift-asn1", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-asn1.git", + "state" : { + "revision" : "df5d2fcd22e3f480e3ef85bf23e277a4a0ef524d", + "version" : "1.2.0" + } + }, + { + "identity" : "swift-certificates", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-certificates.git", + "state" : { + "revision" : "2f797305c1b5b982acaa6005d8a9f970cc4e97ff", + "version" : "1.5.0" + } + }, + { + "identity" : "swift-crypto", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-crypto.git", + "state" : { + "revision" : "81bee98e706aee68d39ed5996db069ef2b313d62", + "version" : "3.7.1" + } + }, { "identity" : "swiftyjson", "kind" : "remoteSourceControl", diff --git a/Package.swift b/Package.swift index 4955728..59265df 100644 --- a/Package.swift +++ b/Package.swift @@ -25,6 +25,10 @@ let package = Package( .package( url: "https://github.com/beatt83/jose-swift.git", from: "3.1.0" + ), + .package( + url: "https://github.com/apple/swift-certificates.git", + from: "1.0.0" ) ], targets: [ @@ -32,7 +36,8 @@ let package = Package( name: "eudi-lib-sdjwt-swift", dependencies: [ "jose-swift", - .product(name: "SwiftyJSON", package: "swiftyjson") + .product(name: "SwiftyJSON", package: "swiftyjson"), + .product(name: "X509", package: "swift-certificates"), ], path: "Sources", plugins: [ diff --git a/Sources/Verifier/SDJWTVerifier.swift b/Sources/Verifier/SDJWTVerifier.swift index 557c9dc..26b4219 100644 --- a/Sources/Verifier/SDJWTVerifier.swift +++ b/Sources/Verifier/SDJWTVerifier.swift @@ -79,10 +79,15 @@ public class SDJWTVerifier { /// - claimVerifier: An optional closure to verify claims. /// - Returns: A `Result` containing the verified `SignedSDJWT` or an error. /// - public func verifyIssuance(issuersSignatureVerifier: (JWS) throws -> SignatureVerifier, - claimVerifier: ((_ nbf: Int?, _ exp: Int?) throws -> ClaimsVerifier)? = nil) rethrows -> Result { + public func verifyIssuance( + issuersSignatureVerifier: (JWS) throws -> SignatureVerifier, + claimVerifier: ((_ nbf: Int?, _ exp: Int?) throws -> ClaimsVerifier)? = nil + ) rethrows -> Result { Result { - try self.verify(issuersSignatureVerifier: issuersSignatureVerifier, claimVerifier: claimVerifier).get() + try self.verify( + issuersSignatureVerifier: issuersSignatureVerifier, + claimVerifier: claimVerifier + ).get() } } @@ -95,9 +100,11 @@ public class SDJWTVerifier { /// - keyBindingVerifier: An optional closure to verify key binding. /// - Returns: A `Result` containing the verified `SignedSDJWT` or an error. /// - public func verifyPresentation(issuersSignatureVerifier: (JWS) throws -> SignatureVerifier, - claimVerifier: ((_ nbf: Int?, _ exp: Int?) throws -> ClaimsVerifier)? = nil, - keyBindingVerifier: ((JWS, JWK) throws -> KeyBindingVerifier)? = nil) -> Result { + public func verifyPresentation( + issuersSignatureVerifier: (JWS) throws -> SignatureVerifier, + claimVerifier: ((_ nbf: Int?, _ exp: Int?) throws -> ClaimsVerifier)? = nil, + keyBindingVerifier: ((JWS, JWK) throws -> KeyBindingVerifier)? = nil + ) -> Result { Result { let commonVerifyResult = self.verify(issuersSignatureVerifier: issuersSignatureVerifier, claimVerifier: claimVerifier) let sdjwt = try commonVerifyResult.get() @@ -121,10 +128,12 @@ public class SDJWTVerifier { } } - public func verifyEnvelope(envelope: JWS, - issuersSignatureVerifier: (JWS) throws -> SignatureVerifier, - holdersSignatureVerifier: () throws -> SignatureVerifier, - claimVerifier: (_ audClaim: String, _ iat: Int) -> ClaimsVerifier) -> Result { + public func verifyEnvelope( + envelope: JWS, + issuersSignatureVerifier: (JWS) throws -> SignatureVerifier, + holdersSignatureVerifier: () throws -> SignatureVerifier, + claimVerifier: (_ audClaim: String, _ iat: Int) -> ClaimsVerifier + ) -> Result { Result { try issuersSignatureVerifier(sdJwt.jwt).verify() try holdersSignatureVerifier().verify() diff --git a/Sources/Verifier/SdJwtVcVerifier.swift b/Sources/Verifier/SdJwtVcVerifier.swift new file mode 100644 index 0000000..0801929 --- /dev/null +++ b/Sources/Verifier/SdJwtVcVerifier.swift @@ -0,0 +1,22 @@ +/* + * 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. + */ +protocol SdJwtVcVerifierType { + +} + +class SdJwtVcVerifier { + +}