Skip to content

Commit 3640e52

Browse files
COVIDSafe code from version 1.1
0 parents  commit 3640e52

File tree

330 files changed

+16060
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

330 files changed

+16060
-0
lines changed

CovidSafe.xcodeproj/project.pbxproj

Lines changed: 1754 additions & 0 deletions
Large diffs are not rendered by default.

CovidSafe.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1130"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "5DD41D3623DCB03B00FD4AB0"
18+
BuildableName = "COVIDSafe.app"
19+
BlueprintName = "CovidSafe"
20+
ReferencedContainer = "container:CovidSafe.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Debug"
27+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "YES">
30+
<Testables>
31+
</Testables>
32+
</TestAction>
33+
<LaunchAction
34+
buildConfiguration = "Release"
35+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
36+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
37+
launchStyle = "0"
38+
useCustomWorkingDirectory = "NO"
39+
ignoresPersistentStateOnLaunch = "NO"
40+
debugDocumentVersioning = "YES"
41+
debugServiceExtension = "internal"
42+
allowLocationSimulation = "YES">
43+
<BuildableProductRunnable
44+
runnableDebuggingMode = "0">
45+
<BuildableReference
46+
BuildableIdentifier = "primary"
47+
BlueprintIdentifier = "5DD41D3623DCB03B00FD4AB0"
48+
BuildableName = "COVIDSafe.app"
49+
BlueprintName = "CovidSafe"
50+
ReferencedContainer = "container:CovidSafe.xcodeproj">
51+
</BuildableReference>
52+
</BuildableProductRunnable>
53+
<EnvironmentVariables>
54+
<EnvironmentVariable
55+
key = "OS_ACTIVITY_MODE"
56+
value = "disable"
57+
isEnabled = "YES">
58+
</EnvironmentVariable>
59+
</EnvironmentVariables>
60+
</LaunchAction>
61+
<ProfileAction
62+
buildConfiguration = "Release"
63+
shouldUseLaunchSchemeArgsEnv = "YES"
64+
savedToolIdentifier = ""
65+
useCustomWorkingDirectory = "NO"
66+
debugDocumentVersioning = "YES">
67+
<BuildableProductRunnable
68+
runnableDebuggingMode = "0">
69+
<BuildableReference
70+
BuildableIdentifier = "primary"
71+
BlueprintIdentifier = "5DD41D3623DCB03B00FD4AB0"
72+
BuildableName = "COVIDSafe.app"
73+
BlueprintName = "CovidSafe"
74+
ReferencedContainer = "container:CovidSafe.xcodeproj">
75+
</BuildableReference>
76+
</BuildableProductRunnable>
77+
</ProfileAction>
78+
<AnalyzeAction
79+
buildConfiguration = "Debug">
80+
</AnalyzeAction>
81+
<ArchiveAction
82+
buildConfiguration = "Release"
83+
revealArchiveInOrganizer = "YES">
84+
</ArchiveAction>
85+
</Scheme>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1140"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "5B92D668243018040049877B"
18+
BuildableName = "COVIDSafe-staging.app"
19+
BlueprintName = "CovidSafe-staging"
20+
ReferencedContainer = "container:CovidSafe.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Debug"
27+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "YES">
30+
<Testables>
31+
</Testables>
32+
</TestAction>
33+
<LaunchAction
34+
buildConfiguration = "Debug"
35+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
36+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
37+
launchStyle = "0"
38+
useCustomWorkingDirectory = "NO"
39+
ignoresPersistentStateOnLaunch = "NO"
40+
debugDocumentVersioning = "YES"
41+
debugServiceExtension = "internal"
42+
allowLocationSimulation = "YES">
43+
<BuildableProductRunnable
44+
runnableDebuggingMode = "0">
45+
<BuildableReference
46+
BuildableIdentifier = "primary"
47+
BlueprintIdentifier = "5B92D668243018040049877B"
48+
BuildableName = "COVIDSafe-staging.app"
49+
BlueprintName = "CovidSafe-staging"
50+
ReferencedContainer = "container:CovidSafe.xcodeproj">
51+
</BuildableReference>
52+
</BuildableProductRunnable>
53+
</LaunchAction>
54+
<ProfileAction
55+
buildConfiguration = "Release"
56+
shouldUseLaunchSchemeArgsEnv = "YES"
57+
savedToolIdentifier = ""
58+
useCustomWorkingDirectory = "NO"
59+
debugDocumentVersioning = "YES">
60+
<BuildableProductRunnable
61+
runnableDebuggingMode = "0">
62+
<BuildableReference
63+
BuildableIdentifier = "primary"
64+
BlueprintIdentifier = "5B92D668243018040049877B"
65+
BuildableName = "COVIDSafe-staging.app"
66+
BlueprintName = "CovidSafe-staging"
67+
ReferencedContainer = "container:CovidSafe.xcodeproj">
68+
</BuildableReference>
69+
</BuildableProductRunnable>
70+
</ProfileAction>
71+
<AnalyzeAction
72+
buildConfiguration = "Debug">
73+
</AnalyzeAction>
74+
<ArchiveAction
75+
buildConfiguration = "Release"
76+
revealArchiveInOrganizer = "YES">
77+
</ArchiveAction>
78+
</Scheme>

CovidSafe.xcworkspace/contents.xcworkspacedata

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// Certificates.swift
3+
// CovidSafe
4+
//
5+
// Copyright © 2020 Australian Government. All rights reserved.
6+
//
7+
8+
import Foundation
9+
struct CovidCertificates {
10+
11+
static let AmazonRootCA1: SecCertificate = CovidCertificates.certificate(filename: "AmazonRootCA1")
12+
static let AmazonRootCA2: SecCertificate = CovidCertificates.certificate(filename: "AmazonRootCA2")
13+
static let AmazonRootCA3: SecCertificate = CovidCertificates.certificate(filename: "AmazonRootCA3")
14+
static let AmazonRootCA4: SecCertificate = CovidCertificates.certificate(filename: "AmazonRootCA4")
15+
static let SFSRootCA: SecCertificate = CovidCertificates.certificate(filename: "SFSRootCAG2")
16+
17+
private static func certificate(filename: String) -> SecCertificate {
18+
19+
let filePath = Bundle.main.path(forResource: filename, ofType: "cer")!
20+
let data = try! Data(contentsOf: URL(fileURLWithPath: filePath))
21+
let certificate = SecCertificateCreateWithData(nil, data as CFData)!
22+
23+
return certificate
24+
}
25+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//
2+
// CovidNetworking.swift
3+
// CovidSafe
4+
//
5+
// Copyright © 2020 Australian Government. All rights reserved.
6+
//
7+
8+
import Foundation
9+
import Alamofire
10+
11+
final class CovidServerTrustManager: ServerTrustManager {
12+
override func serverTrustEvaluator(forHost host: String) throws -> ServerTrustEvaluating? {
13+
guard let evaluator = evaluators[host] else {
14+
for key in evaluators.keys {
15+
if (host.hasSuffix(key)) {
16+
return evaluators[key]
17+
}
18+
}
19+
if allHostsMustBeEvaluated {
20+
throw AFError.serverTrustEvaluationFailed(reason: .noRequiredEvaluator(host: host))
21+
}
22+
23+
return nil
24+
}
25+
return evaluator
26+
}
27+
}
28+
29+
class CovidNetworking {
30+
static private let validCerts = [CovidCertificates.AmazonRootCA1, CovidCertificates.AmazonRootCA2, CovidCertificates.AmazonRootCA3, CovidCertificates.AmazonRootCA4, CovidCertificates.SFSRootCA]
31+
private let evaluators = [
32+
"covidsafe.gov.au": PinnedCertificatesTrustEvaluator(certificates: CovidNetworking.validCerts)
33+
]
34+
35+
static let shared = CovidNetworking()
36+
public let session: Session
37+
38+
init() {
39+
let serverTrustPolicy = CovidServerTrustManager(evaluators: evaluators)
40+
session = Session(serverTrustManager:serverTrustPolicy)
41+
}
42+
}
43+
44+
enum APIError: Error {
45+
case ExpireSession
46+
case ServerError
47+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// CovidRequestInterceptor.swift
3+
// CovidSafe
4+
//
5+
// Copyright © 2020 Australian Government. All rights reserved.
6+
//
7+
8+
import Foundation
9+
import Alamofire
10+
final class CovidRequestRetrier: Alamofire.RequestInterceptor {
11+
private let numRetries: Int
12+
private var retriesExecuted: Int = 0
13+
14+
init(retries: Int) {
15+
self.numRetries = retries
16+
}
17+
18+
func retry(_ request: Request, for session: Session, dueTo error: Error, completion: @escaping (RetryResult) -> Void) {
19+
guard let response = request.task?.response as? HTTPURLResponse, response.statusCode == 403 else {
20+
/// The request did not fail due to a 403 Forbidden response.
21+
let isServerTrustEvaluationError = error.asAFError?.isServerTrustEvaluationError ?? false
22+
if ( retriesExecuted >= numRetries || isServerTrustEvaluationError) {
23+
return completion(.doNotRetryWithError(error))
24+
}
25+
retriesExecuted += 1
26+
return completion(.retryWithDelay(1.0))
27+
}
28+
return completion(.doNotRetryWithError(error))
29+
}
30+
}

0 commit comments

Comments
 (0)