Fix issues when no PGP passphase and enabling passcode
This commit is contained in:
parent
29d74c48e5
commit
1f2a0e5458
4 changed files with 62 additions and 38 deletions
|
|
@ -23,28 +23,32 @@ class CredentialProvider {
|
|||
guard let recordIdentifier = identity.recordIdentifier else {
|
||||
return
|
||||
}
|
||||
guard let pwCredentials = provideCredentials(in: viewController, with: recordIdentifier) else {
|
||||
return
|
||||
}
|
||||
|
||||
extensionContext?.completeRequest(withSelectedCredential: pwCredentials)
|
||||
provideCredentials(in: viewController, with: recordIdentifier) { credential in
|
||||
guard let credential = credential else {
|
||||
return
|
||||
}
|
||||
self.extensionContext?.completeRequest(withSelectedCredential: credential)
|
||||
}
|
||||
}
|
||||
|
||||
func persistAndProvideCredentials(with passwordPath: String) {
|
||||
guard let pwCredentials = provideCredentials(in: viewController, with: passwordPath) else {
|
||||
return
|
||||
}
|
||||
guard let credentialIdentity = provideCredentialIdentity(for: identifier, user: pwCredentials.user, recordIdentifier: passwordPath) else {
|
||||
return
|
||||
}
|
||||
|
||||
let store = ASCredentialIdentityStore.shared
|
||||
store.getState { state in
|
||||
if state.isEnabled {
|
||||
ASCredentialIdentityStore.shared.saveCredentialIdentities([credentialIdentity])
|
||||
provideCredentials(in: viewController, with: passwordPath) { credential in
|
||||
guard let credential = credential else {
|
||||
return
|
||||
}
|
||||
guard let credentialIdentity = provideCredentialIdentity(for: self.identifier, user: credential.user, recordIdentifier: passwordPath) else {
|
||||
return
|
||||
}
|
||||
|
||||
let store = ASCredentialIdentityStore.shared
|
||||
store.getState { state in
|
||||
if state.isEnabled {
|
||||
ASCredentialIdentityStore.shared.saveCredentialIdentities([credentialIdentity])
|
||||
}
|
||||
}
|
||||
self.extensionContext?.completeRequest(withSelectedCredential: credential)
|
||||
}
|
||||
extensionContext?.completeRequest(withSelectedCredential: pwCredentials)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -55,16 +59,14 @@ private func provideCredentialIdentity(for identifier: ASCredentialServiceIdenti
|
|||
return ASPasswordCredentialIdentity(serviceIdentifier: serviceIdentifier, user: user, recordIdentifier: recordIdentifier)
|
||||
}
|
||||
|
||||
private func provideCredentials(in viewController: UIViewController?, with path: String) -> ASPasswordCredential? {
|
||||
print(path)
|
||||
private func provideCredentials(in viewController: UIViewController?, with path: String, completion: @escaping ((ASPasswordCredential?) -> Void)) {
|
||||
guard let viewController = viewController else {
|
||||
return nil
|
||||
return
|
||||
}
|
||||
var credential: ASPasswordCredential?
|
||||
decryptPassword(in: viewController, with: path) { password in
|
||||
let username = password.getUsernameForCompletion()
|
||||
let password = password.password
|
||||
credential = ASPasswordCredential(user: username, password: password)
|
||||
let credential = ASPasswordCredential(user: username, password: password)
|
||||
completion(credential)
|
||||
}
|
||||
return credential
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,21 +10,29 @@ import UIKit
|
|||
import passKit
|
||||
|
||||
func decryptPassword(in controller: UIViewController, with passwordPath: String, using keyID: String? = nil, completion: @escaping ((Password) -> Void)) {
|
||||
do {
|
||||
let requestPGPKeyPassphrase = Utils.createRequestPGPKeyPassphraseHandler(controller: controller)
|
||||
let decryptedPassword = try PasswordStore.shared.decrypt(path: passwordPath, keyID: keyID, requestPGPKeyPassphrase: requestPGPKeyPassphrase)
|
||||
DispatchQueue.global(qos: .userInteractive).async {
|
||||
do {
|
||||
let requestPGPKeyPassphrase = Utils.createRequestPGPKeyPassphraseHandler(controller: controller)
|
||||
let decryptedPassword = try PasswordStore.shared.decrypt(path: passwordPath, keyID: keyID, requestPGPKeyPassphrase: requestPGPKeyPassphrase)
|
||||
|
||||
completion(decryptedPassword)
|
||||
} catch let AppError.pgpPrivateKeyNotFound(keyID: key) {
|
||||
let alert = UIAlertController(title: "CannotShowPassword".localize(), message: AppError.pgpPrivateKeyNotFound(keyID: key).localizedDescription, preferredStyle: .alert)
|
||||
alert.addAction(UIAlertAction.cancelAndPopView(controller: controller))
|
||||
let selectKey = UIAlertAction.selectKey(controller: controller) { action in
|
||||
decryptPassword(in: controller, with: passwordPath, using: action.title, completion: completion)
|
||||
DispatchQueue.main.async {
|
||||
completion(decryptedPassword)
|
||||
}
|
||||
} catch let AppError.pgpPrivateKeyNotFound(keyID: key) {
|
||||
DispatchQueue.main.async {
|
||||
let alert = UIAlertController(title: "CannotShowPassword".localize(), message: AppError.pgpPrivateKeyNotFound(keyID: key).localizedDescription, preferredStyle: .alert)
|
||||
alert.addAction(UIAlertAction.cancelAndPopView(controller: controller))
|
||||
let selectKey = UIAlertAction.selectKey(controller: controller) { action in
|
||||
decryptPassword(in: controller, with: passwordPath, using: action.title, completion: completion)
|
||||
}
|
||||
alert.addAction(selectKey)
|
||||
|
||||
controller.present(alert, animated: true)
|
||||
}
|
||||
} catch {
|
||||
DispatchQueue.main.async {
|
||||
Utils.alert(title: "CannotCopyPassword".localize(), message: error.localizedDescription, controller: controller)
|
||||
}
|
||||
}
|
||||
alert.addAction(selectKey)
|
||||
|
||||
controller.present(alert, animated: true)
|
||||
} catch {
|
||||
Utils.alert(title: "CannotCopyPassword".localize(), message: error.localizedDescription, controller: controller)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue