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
|
|
@ -43,7 +43,21 @@ class CredentialProviderViewController: ASCredentialProviderViewController {
|
|||
}
|
||||
|
||||
override func provideCredentialWithoutUserInteraction(for credentialIdentity: ASPasswordCredentialIdentity) {
|
||||
credentialProvider.identifier = credentialIdentity.serviceIdentifier
|
||||
if !PasscodeLock.shared.hasPasscode, Defaults.isRememberPGPPassphraseOn {
|
||||
credentialProvider.credentials(for: credentialIdentity)
|
||||
} else {
|
||||
extensionContext.cancelRequest(withError: NSError(domain: ASExtensionErrorDomain, code: ASExtensionError.userInteractionRequired.rawValue))
|
||||
}
|
||||
}
|
||||
|
||||
override func prepareInterfaceToProvideCredential(for credentialIdentity: ASPasswordCredentialIdentity) {
|
||||
guard let identifier = credentialIdentity.recordIdentifier else {
|
||||
return
|
||||
}
|
||||
credentialProvider.identifier = credentialIdentity.serviceIdentifier
|
||||
passwordsViewController.navigationItem.prompt = identifier
|
||||
passwordsViewController.showPasswordsWithSuggstion([identifier])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ extension PasswordsViewController: UITableViewDelegate {
|
|||
if indexPath.section == 0 {
|
||||
entry = dataSource.suggestedPasswordsTableEntries[indexPath.row]
|
||||
} else {
|
||||
entry = dataSource.filteredPasswordsTableEntries[indexPath.row]
|
||||
entry = dataSource.otherPasswordsTableEntries[indexPath.row]
|
||||
}
|
||||
} else {
|
||||
entry = dataSource.filteredPasswordsTableEntries[indexPath.row]
|
||||
|
|
|
|||
|
|
@ -23,18 +23,21 @@ class CredentialProvider {
|
|||
guard let recordIdentifier = identity.recordIdentifier else {
|
||||
return
|
||||
}
|
||||
guard let pwCredentials = provideCredentials(in: viewController, with: recordIdentifier) else {
|
||||
|
||||
provideCredentials(in: viewController, with: recordIdentifier) { credential in
|
||||
guard let credential = credential else {
|
||||
return
|
||||
}
|
||||
|
||||
extensionContext?.completeRequest(withSelectedCredential: pwCredentials)
|
||||
self.extensionContext?.completeRequest(withSelectedCredential: credential)
|
||||
}
|
||||
}
|
||||
|
||||
func persistAndProvideCredentials(with passwordPath: String) {
|
||||
guard let pwCredentials = provideCredentials(in: viewController, with: passwordPath) else {
|
||||
provideCredentials(in: viewController, with: passwordPath) { credential in
|
||||
guard let credential = credential else {
|
||||
return
|
||||
}
|
||||
guard let credentialIdentity = provideCredentialIdentity(for: identifier, user: pwCredentials.user, recordIdentifier: passwordPath) else {
|
||||
guard let credentialIdentity = provideCredentialIdentity(for: self.identifier, user: credential.user, recordIdentifier: passwordPath) else {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -44,7 +47,8 @@ class CredentialProvider {
|
|||
ASCredentialIdentityStore.shared.saveCredentialIdentities([credentialIdentity])
|
||||
}
|
||||
}
|
||||
extensionContext?.completeRequest(withSelectedCredential: pwCredentials)
|
||||
self.extensionContext?.completeRequest(withSelectedCredential: credential)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -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,12 +10,16 @@ import UIKit
|
|||
import passKit
|
||||
|
||||
func decryptPassword(in controller: UIViewController, with passwordPath: String, using keyID: String? = nil, completion: @escaping ((Password) -> Void)) {
|
||||
DispatchQueue.global(qos: .userInteractive).async {
|
||||
do {
|
||||
let requestPGPKeyPassphrase = Utils.createRequestPGPKeyPassphraseHandler(controller: controller)
|
||||
let decryptedPassword = try PasswordStore.shared.decrypt(path: passwordPath, keyID: keyID, requestPGPKeyPassphrase: requestPGPKeyPassphrase)
|
||||
|
||||
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
|
||||
|
|
@ -24,7 +28,11 @@ func decryptPassword(in controller: UIViewController, with passwordPath: String,
|
|||
alert.addAction(selectKey)
|
||||
|
||||
controller.present(alert, animated: true)
|
||||
}
|
||||
} catch {
|
||||
DispatchQueue.main.async {
|
||||
Utils.alert(title: "CannotCopyPassword".localize(), message: error.localizedDescription, controller: controller)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue