diff --git a/Sources/Entities/Wallet/Config.swift b/Sources/Entities/Wallet/Config.swift index d0d4db4..adcd6c3 100644 --- a/Sources/Entities/Wallet/Config.swift +++ b/Sources/Entities/Wallet/Config.swift @@ -27,18 +27,15 @@ public struct OpenId4VCIConfig { public let clientId: ClientId public let authFlowRedirectionURI: URL public let authorizeIssuanceConfig: AuthorizeIssuanceConfig - public let usesSelfSignedDelegation: Bool public init( clientId: ClientId, authFlowRedirectionURI: URL, - authorizeIssuanceConfig: AuthorizeIssuanceConfig = .favorScopes, - usesSelfSignedDelegation: Bool = false + authorizeIssuanceConfig: AuthorizeIssuanceConfig = .favorScopes ) { self.clientId = clientId self.authFlowRedirectionURI = authFlowRedirectionURI self.authorizeIssuanceConfig = authorizeIssuanceConfig - self.usesSelfSignedDelegation = usesSelfSignedDelegation } } diff --git a/Sources/Issuers/Issuer.swift b/Sources/Issuers/Issuer.swift index 19e8720..b445f27 100644 --- a/Sources/Issuers/Issuer.swift +++ b/Sources/Issuers/Issuer.swift @@ -103,39 +103,29 @@ public actor Issuer: IssuerType { self.issuerMetadata = issuerMetadata self.config = config - var authorizationServerParPoster = parPoster - authorizationServerParPoster.usesSelfSignedDelegation = config.usesSelfSignedDelegation - var authorizationServerTokenPoster = tokenPoster - authorizationServerTokenPoster.usesSelfSignedDelegation = config.usesSelfSignedDelegation authorizer = try AuthorizationServerClient( - parPoster: authorizationServerParPoster, - tokenPoster: authorizationServerTokenPoster, + parPoster: parPoster, + tokenPoster: tokenPoster, config: config, authorizationServerMetadata: authorizationServerMetadata, credentialIssuerIdentifier: issuerMetadata.credentialIssuerIdentifier, dpopConstructor: dpopConstructor ) - var issuanceRequesterPoster = requesterPoster - issuanceRequesterPoster.usesSelfSignedDelegation = config.usesSelfSignedDelegation issuanceRequester = IssuanceRequester( issuerMetadata: issuerMetadata, - poster: issuanceRequesterPoster, + poster: requesterPoster, dpopConstructor: dpopConstructor ) - var deferredPoster = deferredRequesterPoster - deferredPoster.usesSelfSignedDelegation = config.usesSelfSignedDelegation deferredIssuanceRequester = IssuanceRequester( issuerMetadata: issuerMetadata, - poster: deferredPoster + poster: deferredRequesterPoster ) - var notifyIssuerPoster = notificationPoster - notifyIssuerPoster.usesSelfSignedDelegation = config.usesSelfSignedDelegation notifyIssuer = NotifyIssuer( issuerMetadata: issuerMetadata, - poster: notifyIssuerPoster + poster: notificationPoster ) } diff --git a/Sources/Main/Resolvers/CredentialOffer/AuthorizationServerMetadataResolver.swift b/Sources/Main/Resolvers/CredentialOffer/AuthorizationServerMetadataResolver.swift index e0757ec..6a49439 100644 --- a/Sources/Main/Resolvers/CredentialOffer/AuthorizationServerMetadataResolver.swift +++ b/Sources/Main/Resolvers/CredentialOffer/AuthorizationServerMetadataResolver.swift @@ -38,17 +38,11 @@ public actor AuthorizationServerMetadataResolver: AuthorizationServerMetadataRes private let oauthFetcher: Fetcher public init( - usesSelfSignedDelegation: Bool = false, oidcFetcher: Fetcher = Fetcher(), oauthFetcher: Fetcher = Fetcher() ) { - var oidc = oidcFetcher - oidc.usesSelfSignedDelegation = usesSelfSignedDelegation - self.oidcFetcher = oidc - - var oauth = oauthFetcher - oauth.usesSelfSignedDelegation = usesSelfSignedDelegation - self.oauthFetcher = oauth + self.oidcFetcher = oidcFetcher + self.oauthFetcher = oauthFetcher } /// Resolves client metadata asynchronously. diff --git a/Sources/Main/Resolvers/CredentialOffer/CredentialIssuerMetadataResolver.swift b/Sources/Main/Resolvers/CredentialOffer/CredentialIssuerMetadataResolver.swift index a34e10a..52b75a9 100644 --- a/Sources/Main/Resolvers/CredentialOffer/CredentialIssuerMetadataResolver.swift +++ b/Sources/Main/Resolvers/CredentialOffer/CredentialIssuerMetadataResolver.swift @@ -44,12 +44,9 @@ public actor CredentialIssuerMetadataResolver: CredentialIssuerMetadataType { private let fetcher: Fetcher public init( - usesSelfSignedDelegation: Bool = false, fetcher: Fetcher = Fetcher() ) { - var metaDataFetcher = fetcher - metaDataFetcher.usesSelfSignedDelegation = usesSelfSignedDelegation - self.fetcher = metaDataFetcher + self.fetcher = fetcher } /// Resolves client metadata asynchronously. diff --git a/Sources/Main/Resolvers/CredentialOffer/CredentialOfferRequestResolver.swift b/Sources/Main/Resolvers/CredentialOffer/CredentialOfferRequestResolver.swift index 7d70d88..afd57d2 100644 --- a/Sources/Main/Resolvers/CredentialOffer/CredentialOfferRequestResolver.swift +++ b/Sources/Main/Resolvers/CredentialOffer/CredentialOfferRequestResolver.swift @@ -53,15 +53,11 @@ public actor CredentialOfferRequestResolver { /// - credentialIssuerMetadataResolver: An object responsible for resolving credential issuer metadata. /// - authorizationServerMetadataResolver: An object responsible for resolving authorization server metadata. public init( - usesSelfSignedDelegation: Bool = false, fetcher: Fetcher = Fetcher(), credentialIssuerMetadataResolver: CredentialIssuerMetadataResolver = CredentialIssuerMetadataResolver(), authorizationServerMetadataResolver: AuthorizationServerMetadataResolver = AuthorizationServerMetadataResolver() ) { - var credentialOfferFetcher = fetcher - credentialOfferFetcher.usesSelfSignedDelegation = usesSelfSignedDelegation - self.fetcher = credentialOfferFetcher - + self.fetcher = fetcher self.credentialIssuerMetadataResolver = credentialIssuerMetadataResolver self.authorizationServerMetadataResolver = authorizationServerMetadataResolver } diff --git a/Sources/Utilities/RemoteDataAccess/Fetcher.swift b/Sources/Utilities/RemoteDataAccess/Fetcher.swift index 047df53..3457110 100644 --- a/Sources/Utilities/RemoteDataAccess/Fetcher.swift +++ b/Sources/Utilities/RemoteDataAccess/Fetcher.swift @@ -45,7 +45,6 @@ public enum FetchError: LocalizedError { public protocol Fetching { var session: Networking { get set } - var usesSelfSignedDelegation: Bool { get set } associatedtype Element: Decodable @@ -64,16 +63,14 @@ public protocol Fetching { public struct Fetcher: Fetching { public var session: Networking - public var usesSelfSignedDelegation: Bool + /** Initializes a Fetcher instance. */ public init( - session: Networking = URLSession.shared, - usesSelfSignedDelegation: Bool = false + session: Networking = URLSession.shared ) { self.session = session - self.usesSelfSignedDelegation = usesSelfSignedDelegation } /** @@ -86,16 +83,7 @@ public struct Fetcher: Fetching { */ public func fetch(url: URL) async -> Result { do { - let session: Networking = { - if self.usesSelfSignedDelegation { - let delegate = SelfSignedSessionDelegate() - let configuration = URLSessionConfiguration.default - return URLSession(configuration: configuration, delegate: delegate, delegateQueue: nil) - } else { - return self.session - } - }() - let (data, response) = try await session.data(from: url) + let (data, response) = try await self.session.data(from: url) let statusCode = (response as? HTTPURLResponse)?.statusCode ?? 0 if !statusCode.isWithinRange(200...299) { @@ -117,16 +105,7 @@ public struct Fetcher: Fetching { public func fetchString(url: URL) async throws -> Result { do { - let session: Networking = { - if self.usesSelfSignedDelegation { - let delegate = SelfSignedSessionDelegate() - let configuration = URLSessionConfiguration.default - return URLSession(configuration: configuration, delegate: delegate, delegateQueue: nil) - } else { - return self.session - } - }() - let (data, response) = try await session.data(from: url) + let (data, response) = try await self.session.data(from: url) let statusCode = (response as? HTTPURLResponse)?.statusCode ?? 0 if !statusCode.isWithinRange(200...299) { diff --git a/Sources/Utilities/RemoteDataAccess/Poster.swift b/Sources/Utilities/RemoteDataAccess/Poster.swift index 6025bcb..187ae94 100644 --- a/Sources/Utilities/RemoteDataAccess/Poster.swift +++ b/Sources/Utilities/RemoteDataAccess/Poster.swift @@ -46,7 +46,6 @@ public enum PostError: LocalizedError { public protocol PostingType { var session: Networking { get set } - var usesSelfSignedDelegation: Bool { get set } /** Performs a POST request with the provided URLRequest. @@ -72,17 +71,14 @@ public protocol PostingType { public struct Poster: PostingType { public var session: Networking - public var usesSelfSignedDelegation: Bool /** Initializes a Poster instance. */ public init( - session: Networking = URLSession.shared, - usesSelfSignedDelegation: Bool = false + session: Networking = URLSession.shared ) { self.session = session - self.usesSelfSignedDelegation = usesSelfSignedDelegation } /** @@ -95,16 +91,7 @@ public struct Poster: PostingType { */ public func post(request: URLRequest) async -> Result { do { - let session: Networking = { - if self.usesSelfSignedDelegation { - let delegate = SelfSignedSessionDelegate() - let configuration = URLSessionConfiguration.default - return URLSession(configuration: configuration, delegate: delegate, delegateQueue: nil) - } else { - return self.session - } - }() - let (data, response) = try await session.data(for: request) + let (data, response) = try await self.session.data(for: request) let statusCode = (response as? HTTPURLResponse)?.statusCode ?? 0 if statusCode >= 400 && statusCode < 500 { @@ -143,16 +130,7 @@ public struct Poster: PostingType { */ public func check(request: URLRequest) async -> Result { do { - let session: Networking = { - if self.usesSelfSignedDelegation { - let delegate = SelfSignedSessionDelegate() - let configuration = URLSessionConfiguration.default - return URLSession(configuration: configuration, delegate: delegate, delegateQueue: nil) - } else { - return self.session - } - }() - let (_, response) = try await session.data(for: request) + let (_, response) = try await self.session.data(for: request) return .success((response as? HTTPURLResponse)?.statusCode.isWithinRange(200...299) ?? false) } catch let error as NSError { diff --git a/Tests/Helpers/Wallet.swift b/Tests/Helpers/Wallet.swift index ee14046..229131c 100644 --- a/Tests/Helpers/Wallet.swift +++ b/Tests/Helpers/Wallet.swift @@ -31,9 +31,7 @@ extension Wallet { let credentialConfigurationIdentifier = try CredentialConfigurationIdentifier(value: identifier) let credentialIssuerIdentifier = try CredentialIssuerId(CREDENTIAL_ISSUER_PUBLIC_URL) - let resolver = CredentialIssuerMetadataResolver( - usesSelfSignedDelegation: config.usesSelfSignedDelegation - ) + let resolver = CredentialIssuerMetadataResolver() let issuerMetadata = await resolver.resolve( source: .credentialIssuer( credentialIssuerIdentifier @@ -44,9 +42,7 @@ extension Wallet { case .success(let metaData): if let authorizationServer = metaData?.authorizationServers.first, let metaData { - let resolver = AuthorizationServerMetadataResolver( - usesSelfSignedDelegation: config.usesSelfSignedDelegation - ) + let resolver = AuthorizationServerMetadataResolver() let authServerMetadata = await resolver.resolve(url: authorizationServer) let offer = try CredentialOffer( @@ -171,15 +167,7 @@ extension Wallet { offerUri: String, claimSet: ClaimSet? = nil ) async throws -> [(String, String)] { - let resolver = CredentialOfferRequestResolver( - usesSelfSignedDelegation: config.usesSelfSignedDelegation, - credentialIssuerMetadataResolver: CredentialIssuerMetadataResolver( - usesSelfSignedDelegation: config.usesSelfSignedDelegation - ), - authorizationServerMetadataResolver: AuthorizationServerMetadataResolver( - usesSelfSignedDelegation: config.usesSelfSignedDelegation - ) - ) + let resolver = CredentialOfferRequestResolver() let result = await resolver .resolve( source: try .init( @@ -203,16 +191,7 @@ extension Wallet { scope: String, claimSet: ClaimSet? = nil ) async throws -> String { - let result = await CredentialOfferRequestResolver( - usesSelfSignedDelegation: config.usesSelfSignedDelegation, - credentialIssuerMetadataResolver: CredentialIssuerMetadataResolver( - usesSelfSignedDelegation: config.usesSelfSignedDelegation - ), - authorizationServerMetadataResolver: - AuthorizationServerMetadataResolver( - usesSelfSignedDelegation: config.usesSelfSignedDelegation - ) - ).resolve( + let result = await CredentialOfferRequestResolver().resolve( source: try .init( urlString: offerUri ) @@ -235,16 +214,7 @@ extension Wallet { scope: String, claimSet: ClaimSet? = nil ) async throws -> String { - let result = await CredentialOfferRequestResolver( - usesSelfSignedDelegation: config.usesSelfSignedDelegation, - credentialIssuerMetadataResolver: CredentialIssuerMetadataResolver( - usesSelfSignedDelegation: config.usesSelfSignedDelegation - ), - authorizationServerMetadataResolver: - AuthorizationServerMetadataResolver( - usesSelfSignedDelegation: config.usesSelfSignedDelegation - ) - ).resolve( + let result = await CredentialOfferRequestResolver().resolve( source: try .init( urlString: offerUri ) diff --git a/Tests/Issuance/IssuanceBatchRequestTest.swift b/Tests/Issuance/IssuanceBatchRequestTest.swift index bfdf366..521ec8f 100644 --- a/Tests/Issuance/IssuanceBatchRequestTest.swift +++ b/Tests/Issuance/IssuanceBatchRequestTest.swift @@ -188,16 +188,7 @@ class IssuanceBatchRequestTest: XCTestCase { // Given let url = "\(CREDENTIAL_ISSUER_PUBLIC_URL)/credentialoffer?credential_offer=\(SdJwtVC_CredentialOffer)" - guard let offer = try? await CredentialOfferRequestResolver( - usesSelfSignedDelegation: config.usesSelfSignedDelegation, - credentialIssuerMetadataResolver: CredentialIssuerMetadataResolver( - usesSelfSignedDelegation: config.usesSelfSignedDelegation - ), - authorizationServerMetadataResolver: - AuthorizationServerMetadataResolver( - usesSelfSignedDelegation: config.usesSelfSignedDelegation - ) - ).resolve( + guard let offer = try? await CredentialOfferRequestResolver().resolve( source: try .init( urlString: url )