diff --git a/DGCAVerifier/Services/GatewayConnection/CustomHeaderInterceptor.swift b/DGCAVerifier/Services/GatewayConnection/CustomHeaderInterceptor.swift new file mode 100644 index 0000000..189d9e7 --- /dev/null +++ b/DGCAVerifier/Services/GatewayConnection/CustomHeaderInterceptor.swift @@ -0,0 +1,22 @@ +// +// CustomHeaderInterceptor.swift +// Verifier +// +// Created by Davide Aliti on 14/03/22. +// + +import Foundation +import Alamofire + +struct CustomHeaderInterceptor: RequestInterceptor { + + func adapt(_ urlRequest: URLRequest, for session: Session, completion: @escaping (Result) -> Void) { + var urlRequest = urlRequest + let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] + let iosVersion = ProcessInfo.processInfo.operatingSystemVersionString + let formattedIOSVersion = iosVersion.replacingOccurrences(of: "Version ", with: "").replacingOccurrences(of: " (Build ", with: "; Build/") + let customHeader = HTTPHeader(name: "User-Agent", value: "DGCAVerifierIOS / \(appVersion ?? "") (iOS \(formattedIOSVersion)") + urlRequest.headers.add(customHeader) + completion(.success(urlRequest)) + } +} diff --git a/DGCAVerifier/Services/GatewayConnection/GatewayConnection.swift b/DGCAVerifier/Services/GatewayConnection/GatewayConnection.swift index 570aef9..7ee90ef 100644 --- a/DGCAVerifier/Services/GatewayConnection/GatewayConnection.swift +++ b/DGCAVerifier/Services/GatewayConnection/GatewayConnection.swift @@ -59,7 +59,7 @@ class GatewayConnection { // Init session let evaluators = [certificateEvaluator: PinnedCertificatesTrustEvaluator(certificates: [certificate])] - session = Session(serverTrustManager: ServerTrustManager(evaluators: evaluators)) + session = Session(interceptor: CustomHeaderInterceptor(), serverTrustManager: ServerTrustManager(evaluators: evaluators)) } func initialize(completion: (()->())? = nil) { diff --git a/Verifier.xcodeproj/project.pbxproj b/Verifier.xcodeproj/project.pbxproj index bd7dbbe..0e49f84 100644 --- a/Verifier.xcodeproj/project.pbxproj +++ b/Verifier.xcodeproj/project.pbxproj @@ -287,6 +287,8 @@ 6B797DDD26D052B800EB2873 /* Data+SHA256.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B797DDC26D052B800EB2873 /* Data+SHA256.swift */; }; 6B797DDE26D052B800EB2873 /* Data+SHA256.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B797DDC26D052B800EB2873 /* Data+SHA256.swift */; }; 6BA8B9E5266FAC150060D767 /* GatewayConnection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F4F3C442649D60B00F59BA2 /* GatewayConnection.swift */; }; + 6BF86E2F27DF4D8A002DF298 /* CustomHeaderInterceptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6BF86E2E27DF4D8A002DF298 /* CustomHeaderInterceptor.swift */; }; + 6BF86E3027DF4D8A002DF298 /* CustomHeaderInterceptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6BF86E2E27DF4D8A002DF298 /* CustomHeaderInterceptor.swift */; }; 9020C5E12721600D00F45CA7 /* String+Char.swift in Sources */ = {isa = PBXBuildFile; fileRef = 653F929126B00F9C000BE8F5 /* String+Char.swift */; }; 9020C5E32721600D00F45CA7 /* UILabel+Inspectable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65021B3F26AEC142004C3D14 /* UILabel+Inspectable.swift */; }; 9020C5E42721600D00F45CA7 /* UIImageView+Inspectable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65021B5826AECF59004C3D14 /* UIImageView+Inspectable.swift */; }; @@ -564,6 +566,7 @@ 6BA8B9E1266F7E4C0060D767 /* RecoveryValidityCheckTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecoveryValidityCheckTests.swift; sourceTree = ""; }; 6BA8B9E3266F840B0060D767 /* TestValidityCheckTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestValidityCheckTests.swift; sourceTree = ""; }; 6BA8B9E72671227C0060D767 /* LocalDataTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalDataTests.swift; sourceTree = ""; }; + 6BF86E2E27DF4D8A002DF298 /* CustomHeaderInterceptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomHeaderInterceptor.swift; sourceTree = ""; }; 902155CF274E55490020DA88 /* StatementValidityCheck.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatementValidityCheck.swift; sourceTree = ""; }; 902BB46B27AD852400C397EB /* TestModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestModel.swift; sourceTree = ""; }; 9037A0A5270EFD2D0067DCF8 /* SettingsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsViewController.swift; sourceTree = ""; }; @@ -1198,6 +1201,7 @@ 65EFB5ED26B04D850081682B /* GatewayConnection+Certificates.swift */, 65EFB5F026B04D900081682B /* GatewayConnection+Settings.swift */, 65F280C726D65269009BC452 /* GatewayConnection+Revocation.swift */, + 6BF86E2E27DF4D8A002DF298 /* CustomHeaderInterceptor.swift */, ); path = GatewayConnection; sourceTree = ""; @@ -1822,6 +1826,7 @@ 658CB71C26AF27D200B90EC0 /* UIBarButtonItem+Appearance.swift in Sources */, 65F280D226D658CB009BC452 /* CRL+Entity.swift in Sources */, 65E7000226AF6E1F00715CCC /* UIStackView+ArrangedSubViews.swift in Sources */, + 6BF86E3027DF4D8A002DF298 /* CustomHeaderInterceptor.swift in Sources */, 14C3B3CF27BD47CC00C2C2A7 /* CustomPickerController.swift in Sources */, 659605FA26E7A6E0008AD4E2 /* CRLProgress.swift in Sources */, 65021B4D26AEC889004C3D14 /* ButtonStyle.swift in Sources */, @@ -2026,6 +2031,7 @@ 65E7001326AF7BB000715CCC /* FaqView.swift in Sources */, 65F280D126D658CB009BC452 /* CRL+Entity.swift in Sources */, 9F4F3C5A2649D60C00F59BA2 /* MainCoordinator.swift in Sources */, + 6BF86E2F27DF4D8A002DF298 /* CustomHeaderInterceptor.swift in Sources */, 98BF53D227A987F500B8FB1A /* HCertValidator.swift in Sources */, 659605F326E7911E008AD4E2 /* ProgressView.swift in Sources */, 653F928A26B00474000BE8F5 /* CountryCell.swift in Sources */,