Commit 3195ac56 authored by Jose Blaya's avatar Jose Blaya
Browse files

Merge branch 'release/1.1.8' into release/2.0.0

parents 9a773068 22c31aaa
......@@ -11,6 +11,8 @@ import Foundation
protocol SecureStore: class {
var publicKey: SecKey? { get }
@discardableResult func publicKeyEntry() -> SecKey?
@discardableResult func setPublicKey(withData data: Data) -> SecKey?
func username() -> String?
......
......@@ -474,6 +474,7 @@ class DefaultAccountProvider: AccountProvider, ConfigurationAccess, DatabaseAcce
if let username = accessedDatabase.secure.username() {
accessedDatabase.secure.setPassword(nil, for: username)
accessedDatabase.secure.setUsername(nil)
accessedDatabase.secure.clear(for: username)
accessedDatabase.secure.setToken(nil, for: accessedDatabase.secure.tokenKey(for: username))
}
accessedDatabase.secure.setPublicUsername(nil)
......
......@@ -134,19 +134,23 @@ extension Client {
let errorMessage = {
return "Cannot load PIA public key"
}
guard let pubKeyFile = bundle.path(forResource: "PIA", ofType: "pub") else {
fatalError(errorMessage())
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
}
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 = [
......
......@@ -31,6 +31,14 @@ class KeychainStore: SecureStore {
var publicKey: SecKey?
func publicKeyEntry() -> SecKey? {
guard let publicKey = try? backend.publicKey(withIdentifier: Entries.publicKey) else {
return nil
}
self.publicKey = publicKey
return publicKey
}
func setPublicKey(withData data: Data) -> SecKey? {
backend.remove(publicKeyWithIdentifier: Entries.publicKey)
guard let publicKey = try? backend.add(publicKeyWithIdentifier: Entries.publicKey, data: data) else {
......
Supports Markdown
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