From 57a1a023b47eb971201ef1ad9ddcee034b91770c Mon Sep 17 00:00:00 2001 From: Yannick Spreen Date: Sat, 24 Apr 2021 23:56:54 +0200 Subject: [PATCH] Add Alamofire; Start adding Gateway Service. --- DGCAVerifier.xcodeproj/project.pbxproj | 21 +++++++ .../xcshareddata/swiftpm/Package.resolved | 9 +++ DGCAVerifier/Services/KID.swift | 2 +- DGCAVerifier/ViewControllers/Scan.swift | 2 + DGCAVerifierTests/EHNTests.swift | 4 +- .../Services/GatewayConnection.swift | 57 +++++++++++++++++++ 6 files changed, 92 insertions(+), 3 deletions(-) create mode 100644 PatientScannerDemo/Services/GatewayConnection.swift diff --git a/DGCAVerifier.xcodeproj/project.pbxproj b/DGCAVerifier.xcodeproj/project.pbxproj index d332b17..8a49018 100644 --- a/DGCAVerifier.xcodeproj/project.pbxproj +++ b/DGCAVerifier.xcodeproj/project.pbxproj @@ -25,6 +25,8 @@ CE7DE7FA2625EF18007E6694 /* SwiftCBOR in Frameworks */ = {isa = PBXBuildFile; productRef = CE7DE7F92625EF18007E6694 /* SwiftCBOR */; }; CE8912E526321AA500CB92AF /* KID.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE8912E426321AA500CB92AF /* KID.swift */; }; CE8912EA26321DAA00CB92AF /* SHA256.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE8912E926321DAA00CB92AF /* SHA256.swift */; }; + CE8912F52634C60E00CB92AF /* GatewayConnection.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE8912F42634C60E00CB92AF /* GatewayConnection.swift */; }; + CE8912FB2634C6B900CB92AF /* Alamofire in Frameworks */ = {isa = PBXBuildFile; productRef = CE8912FA2634C6B900CB92AF /* Alamofire */; }; CEA1555D262F63B30024B7AC /* EuDgcSchema.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEA1555C262F63B30024B7AC /* EuDgcSchema.swift */; }; CEA15563262F6DAB0024B7AC /* ChildDismissedDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEA15562262F6DAB0024B7AC /* ChildDismissedDelegate.swift */; }; CEA1556B262F784E0024B7AC /* SelfSizedTableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEA1556A262F784E0024B7AC /* SelfSizedTableView.swift */; }; @@ -79,6 +81,7 @@ CE44799626306C9B009A836B /* Data+Base45.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Data+Base45.swift"; sourceTree = ""; }; CE8912E426321AA500CB92AF /* KID.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KID.swift; sourceTree = ""; }; CE8912E926321DAA00CB92AF /* SHA256.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SHA256.swift; sourceTree = ""; }; + CE8912F42634C60E00CB92AF /* GatewayConnection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GatewayConnection.swift; sourceTree = ""; }; CEA1555C262F63B30024B7AC /* EuDgcSchema.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EuDgcSchema.swift; sourceTree = ""; }; CEA15562262F6DAB0024B7AC /* ChildDismissedDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChildDismissedDelegate.swift; sourceTree = ""; }; CEA1556A262F784E0024B7AC /* SelfSizedTableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelfSizedTableView.swift; sourceTree = ""; }; @@ -112,6 +115,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + CE8912FB2634C6B900CB92AF /* Alamofire in Frameworks */, CE157F87262E24DE00FE4821 /* SwiftyJSON in Frameworks */, CE44798D26304D8F009A836B /* JSONSchema in Frameworks */, CE7DE7FA2625EF18007E6694 /* SwiftCBOR in Frameworks */, @@ -159,6 +163,7 @@ CE1BDF98262A4CD600766F97 /* X509.swift */, CE8912E426321AA500CB92AF /* KID.swift */, CE8912E926321DAA00CB92AF /* SHA256.swift */, + CE8912F42634C60E00CB92AF /* GatewayConnection.swift */, ); path = Services; sourceTree = ""; @@ -299,6 +304,7 @@ CE13CEFF262DCC180070C80E /* FloatingPanel */, CE157F86262E24DE00FE4821 /* SwiftyJSON */, CE44798C26304D8F009A836B /* JSONSchema */, + CE8912FA2634C6B900CB92AF /* Alamofire */, ); productName = DGCAVerifier; productReference = CEA6D6E8261F8D2700715333 /* DGCAVerifier.app */; @@ -376,6 +382,7 @@ CE13CEFE262DCC180070C80E /* XCRemoteSwiftPackageReference "FloatingPanel" */, CE157F85262E24DE00FE4821 /* XCRemoteSwiftPackageReference "SwiftyJSON" */, CE44798B26304D8F009A836B /* XCRemoteSwiftPackageReference "JSONSchema" */, + CE8912F92634C6B900CB92AF /* XCRemoteSwiftPackageReference "Alamofire" */, ); productRefGroup = CEA6D6E9261F8D2700715333 /* Products */; projectDirPath = ""; @@ -429,6 +436,7 @@ CE8912EA26321DAA00CB92AF /* SHA256.swift in Sources */, CE3CC9442628C2130079FB78 /* CBOR.swift in Sources */, CE44799226306C86009A836B /* String.swift in Sources */, + CE8912F52634C60E00CB92AF /* GatewayConnection.swift in Sources */, CE44799726306C9B009A836B /* Data+Base45.swift in Sources */, CE13CF0F262DD0D80070C80E /* FullFloatingPanelLayout.swift in Sources */, CEA1556B262F784E0024B7AC /* SelfSizedTableView.swift in Sources */, @@ -817,6 +825,14 @@ minimumVersion = 0.4.3; }; }; + CE8912F92634C6B900CB92AF /* XCRemoteSwiftPackageReference "Alamofire" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/Alamofire/Alamofire"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 5.4.3; + }; + }; /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ @@ -840,6 +856,11 @@ package = CE7DE7F82625EF18007E6694 /* XCRemoteSwiftPackageReference "SwiftCBOR" */; productName = SwiftCBOR; }; + CE8912FA2634C6B900CB92AF /* Alamofire */ = { + isa = XCSwiftPackageProductDependency; + package = CE8912F92634C6B900CB92AF /* XCRemoteSwiftPackageReference "Alamofire" */; + productName = Alamofire; + }; /* End XCSwiftPackageProductDependency section */ }; rootObject = CEA6D6E0261F8D2700715333 /* Project object */; diff --git a/DGCAVerifier.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/DGCAVerifier.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index f915462..a3ac02e 100644 --- a/DGCAVerifier.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/DGCAVerifier.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -1,6 +1,15 @@ { "object": { "pins": [ + { + "package": "Alamofire", + "repositoryURL": "https://github.com/Alamofire/Alamofire", + "state": { + "branch": null, + "revision": "f96b619bcb2383b43d898402283924b80e2c4bae", + "version": "5.4.3" + } + }, { "package": "FloatingPanel", "repositoryURL": "https://github.com/SCENEE/FloatingPanel", diff --git a/DGCAVerifier/Services/KID.swift b/DGCAVerifier/Services/KID.swift index 905d62d..c6da198 100644 --- a/DGCAVerifier/Services/KID.swift +++ b/DGCAVerifier/Services/KID.swift @@ -31,7 +31,7 @@ import Foundation typealias KidBytes = [UInt8] struct KID { - public static func stringFrom(kidBytes: KidBytes) -> String { + public static func string(from kidBytes: KidBytes) -> String { return Data(kidBytes.prefix(8)).base64EncodedString() } public static func from(_ encodedCert: String) -> KidBytes { diff --git a/DGCAVerifier/ViewControllers/Scan.swift b/DGCAVerifier/ViewControllers/Scan.swift index ecc7ad7..84acea2 100644 --- a/DGCAVerifier/ViewControllers/Scan.swift +++ b/DGCAVerifier/ViewControllers/Scan.swift @@ -220,6 +220,8 @@ extension ScanVC { // print(CBOR.payload(from: data)?.toString() ?? "") // print(CBOR.header(from: data)?.toString() ?? "") presentViewer(for: HCert(from: data)) + + GatewayConnection.fetchCert() } } diff --git a/DGCAVerifierTests/EHNTests.swift b/DGCAVerifierTests/EHNTests.swift index 79675ed..ef22027 100644 --- a/DGCAVerifierTests/EHNTests.swift +++ b/DGCAVerifierTests/EHNTests.swift @@ -103,7 +103,7 @@ class EHNTests: XCTestCase { XCTAssert(false) return } - let kid = KID.stringFrom(kidBytes: kidBytes) + let kid = KID.string(from: kidBytes) guard let url = URL(string: "https://dgc.a-sit.at/ehn/cert/\(kid)") else { @@ -122,7 +122,7 @@ class EHNTests: XCTestCase { return } let encodedCert = body.base64EncodedString() - XCTAssert(KID.stringFrom(kidBytes: KID.from(encodedCert)) == kid) + XCTAssert(KID.string(from: KID.from(encodedCert)) == kid) if COSE.verify(data, with: encodedCert) { expectation.fulfill() } else { diff --git a/PatientScannerDemo/Services/GatewayConnection.swift b/PatientScannerDemo/Services/GatewayConnection.swift new file mode 100644 index 0000000..6bee524 --- /dev/null +++ b/PatientScannerDemo/Services/GatewayConnection.swift @@ -0,0 +1,57 @@ +// +/*- + * ---license-start + * eu-digital-green-certificates / dgca-verifier-app-ios + * --- + * Copyright (C) 2021 T-Systems International GmbH and all other contributors + * --- + * 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. + * ---license-end + */ +// +// GatewayConnection.swift +// PatientScannerDemo +// +// Created by Yannick Spreen on 4/24/21. +// + + +import Foundation +import Alamofire + +struct GatewayConnection { + static let serverURI = "https://dgca-verifier-service.cfapps.eu10.hana.ondemand.com/" + static let updateEndpoint = "signercertificateUpdate" + static let statusEndpoint = "signercertificateStatus" + + public static func fetchCert(resume resumeToken: String? = nil) { + AF.request(serverURI + updateEndpoint).response { + guard + case let .success(result) = $0.result, + let response = result, + let responseStr = String(data: response, encoding: .utf8), + let pubKey = X509.pubKey(from: responseStr), + let headers = $0.response?.headers, + let responseKid = headers["x-kid"] + else { + return + } + let kid = KID.from(responseStr) + let kidStr = KID.string(from: kid) + if kidStr != responseKid { + return + } + print(pubKey) + } + } +}