Skip to content

Commit

Permalink
Add Alamofire; Start adding Gateway Service.
Browse files Browse the repository at this point in the history
  • Loading branch information
yspreen committed Apr 25, 2021
1 parent 23ae178 commit 57a1a02
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 3 deletions.
21 changes: 21 additions & 0 deletions DGCAVerifier.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -79,6 +81,7 @@
CE44799626306C9B009A836B /* Data+Base45.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Data+Base45.swift"; sourceTree = "<group>"; };
CE8912E426321AA500CB92AF /* KID.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KID.swift; sourceTree = "<group>"; };
CE8912E926321DAA00CB92AF /* SHA256.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SHA256.swift; sourceTree = "<group>"; };
CE8912F42634C60E00CB92AF /* GatewayConnection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GatewayConnection.swift; sourceTree = "<group>"; };
CEA1555C262F63B30024B7AC /* EuDgcSchema.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EuDgcSchema.swift; sourceTree = "<group>"; };
CEA15562262F6DAB0024B7AC /* ChildDismissedDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChildDismissedDelegate.swift; sourceTree = "<group>"; };
CEA1556A262F784E0024B7AC /* SelfSizedTableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelfSizedTableView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -159,6 +163,7 @@
CE1BDF98262A4CD600766F97 /* X509.swift */,
CE8912E426321AA500CB92AF /* KID.swift */,
CE8912E926321DAA00CB92AF /* SHA256.swift */,
CE8912F42634C60E00CB92AF /* GatewayConnection.swift */,
);
path = Services;
sourceTree = "<group>";
Expand Down Expand Up @@ -299,6 +304,7 @@
CE13CEFF262DCC180070C80E /* FloatingPanel */,
CE157F86262E24DE00FE4821 /* SwiftyJSON */,
CE44798C26304D8F009A836B /* JSONSchema */,
CE8912FA2634C6B900CB92AF /* Alamofire */,
);
productName = DGCAVerifier;
productReference = CEA6D6E8261F8D2700715333 /* DGCAVerifier.app */;
Expand Down Expand Up @@ -376,6 +382,7 @@
CE13CEFE262DCC180070C80E /* XCRemoteSwiftPackageReference "FloatingPanel" */,
CE157F85262E24DE00FE4821 /* XCRemoteSwiftPackageReference "SwiftyJSON" */,
CE44798B26304D8F009A836B /* XCRemoteSwiftPackageReference "JSONSchema" */,
CE8912F92634C6B900CB92AF /* XCRemoteSwiftPackageReference "Alamofire" */,
);
productRefGroup = CEA6D6E9261F8D2700715333 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */
Expand All @@ -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 */;
Expand Down
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion DGCAVerifier/Services/KID.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions DGCAVerifier/ViewControllers/Scan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

}
Expand Down
4 changes: 2 additions & 2 deletions DGCAVerifierTests/EHNTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
57 changes: 57 additions & 0 deletions PatientScannerDemo/Services/GatewayConnection.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}
}

0 comments on commit 57a1a02

Please sign in to comment.