Commit 6b264dc1 authored by Jose Blaya's avatar Jose Blaya
Browse files

- Access to pubKey from a DispatchQueue

- Changed copy for Couldnt get your plan button
parent cfd3671b
......@@ -14,7 +14,7 @@
"login.purchase.button" = "Buy now";
"login.redeem.footer" = "Have a gift card or trial card?";
"login.redeem.button" = "Redeem now";
"login.restore.button" = "Couldn't get your plan?";
"login.restore.button" = "Didn't receive account details?";
"login.error.title" = "Log in";
"login.error.validation" = "You must enter a username and password.";
"login.error.unauthorized" = "Your username or password is incorrect.";
......
......@@ -17,7 +17,7 @@ extension Client {
/// If `true`, expose development features.
public var isDevelopment: Bool
let publicKey: SecKey
var publicKey: SecKey?
// MARK: WebServices
......@@ -122,6 +122,10 @@ extension Client {
#endif
// MARK: Access to Data PublicKey
private let accessQueue = DispatchQueue(label: "SynchronizedDataAccess",
attributes: .concurrent)
// MARK: Initialization
init() {
......@@ -131,24 +135,7 @@ extension Client {
let errorMessage = {
return "Cannot load PIA public key"
}
if let publicKey = database.secure.publicKeyEntry() {
self.publicKey = publicKey
} else {
guard let pubKeyFile = bundle.path(forResource: "PIA", ofType: "pub") else {
fatalError(errorMessage())
}
guard let pubKeyData = try? Data(contentsOf: URL(fileURLWithPath: pubKeyFile)) else {
fatalError(errorMessage())
}
guard let strippedData = pubKeyData.withStrippedASN1Header() else {
fatalError(errorMessage())
}
guard let publicKey = database.secure.setPublicKey(withData: strippedData) else {
fatalError(errorMessage())
}
self.publicKey = publicKey
}
let production = "https://www.privateinternetaccess.com"
baseUrls = [
.production: production
......@@ -203,6 +190,26 @@ extension Client {
#if os(iOS)
inAppPlans = [:]
#endif
if let publicKey = database.secure.publicKeyEntry() {
self.publicKey = publicKey
} else {
accessQueue.sync {
guard let pubKeyFile = bundle.path(forResource: "PIA", ofType: "pub") else {
fatalError(errorMessage())
}
guard let pubKeyData = try? Data(contentsOf: URL(fileURLWithPath: pubKeyFile)) else {
fatalError(errorMessage())
}
guard let strippedData = pubKeyData.withStrippedASN1Header() else {
fatalError(errorMessage())
}
guard let publicKey = database.secure.setPublicKey(withData: strippedData) else {
fatalError(errorMessage())
}
self.publicKey = publicKey
}
}
}
// MARK: WebServices
......
......@@ -195,8 +195,9 @@ class PIAWebServices: WebServices, ConfigurationAccess {
callback?(nil, ClientError.malformedResponseData)
return
}
if self.accessedConfiguration.verifiesServersSignature {
guard response.verifySignature(publicKey: self.accessedConfiguration.publicKey) else {
if self.accessedConfiguration.verifiesServersSignature,
let key = self.accessedConfiguration.publicKey {
guard response.verifySignature(publicKey: key) else {
callback?(nil, ClientError.badServersSignature)
return
}
......
......@@ -164,7 +164,7 @@ internal enum L10n {
internal static let footer = L10n.tr("Welcome", "login.redeem.footer")
}
internal enum Restore {
/// Couldn't get your plan?
/// Didn't receive account details?
internal static let button = L10n.tr("Welcome", "login.restore.button")
}
internal enum Username {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment