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) {
|
override func provideCredentialWithoutUserInteraction(for credentialIdentity: ASPasswordCredentialIdentity) {
|
||||||
credentialProvider.credentials(for: credentialIdentity)
|
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 {
|
if indexPath.section == 0 {
|
||||||
entry = dataSource.suggestedPasswordsTableEntries[indexPath.row]
|
entry = dataSource.suggestedPasswordsTableEntries[indexPath.row]
|
||||||
} else {
|
} else {
|
||||||
entry = dataSource.filteredPasswordsTableEntries[indexPath.row]
|
entry = dataSource.otherPasswordsTableEntries[indexPath.row]
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
entry = dataSource.filteredPasswordsTableEntries[indexPath.row]
|
entry = dataSource.filteredPasswordsTableEntries[indexPath.row]
|
||||||
|
|
|
||||||
|
|
@ -23,28 +23,32 @@ class CredentialProvider {
|
||||||
guard let recordIdentifier = identity.recordIdentifier else {
|
guard let recordIdentifier = identity.recordIdentifier else {
|
||||||
return
|
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) {
|
func persistAndProvideCredentials(with passwordPath: String) {
|
||||||
guard let pwCredentials = provideCredentials(in: viewController, with: passwordPath) else {
|
provideCredentials(in: viewController, with: passwordPath) { credential in
|
||||||
return
|
guard let credential = credential 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])
|
|
||||||
}
|
}
|
||||||
|
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)
|
return ASPasswordCredentialIdentity(serviceIdentifier: serviceIdentifier, user: user, recordIdentifier: recordIdentifier)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func provideCredentials(in viewController: UIViewController?, with path: String) -> ASPasswordCredential? {
|
private func provideCredentials(in viewController: UIViewController?, with path: String, completion: @escaping ((ASPasswordCredential?) -> Void)) {
|
||||||
print(path)
|
|
||||||
guard let viewController = viewController else {
|
guard let viewController = viewController else {
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
var credential: ASPasswordCredential?
|
|
||||||
decryptPassword(in: viewController, with: path) { password in
|
decryptPassword(in: viewController, with: path) { password in
|
||||||
let username = password.getUsernameForCompletion()
|
let username = password.getUsernameForCompletion()
|
||||||
let password = password.password
|
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
|
import passKit
|
||||||
|
|
||||||
func decryptPassword(in controller: UIViewController, with passwordPath: String, using keyID: String? = nil, completion: @escaping ((Password) -> Void)) {
|
func decryptPassword(in controller: UIViewController, with passwordPath: String, using keyID: String? = nil, completion: @escaping ((Password) -> Void)) {
|
||||||
do {
|
DispatchQueue.global(qos: .userInteractive).async {
|
||||||
let requestPGPKeyPassphrase = Utils.createRequestPGPKeyPassphraseHandler(controller: controller)
|
do {
|
||||||
let decryptedPassword = try PasswordStore.shared.decrypt(path: passwordPath, keyID: keyID, requestPGPKeyPassphrase: requestPGPKeyPassphrase)
|
let requestPGPKeyPassphrase = Utils.createRequestPGPKeyPassphraseHandler(controller: controller)
|
||||||
|
let decryptedPassword = try PasswordStore.shared.decrypt(path: passwordPath, keyID: keyID, requestPGPKeyPassphrase: requestPGPKeyPassphrase)
|
||||||
|
|
||||||
completion(decryptedPassword)
|
DispatchQueue.main.async {
|
||||||
} catch let AppError.pgpPrivateKeyNotFound(keyID: key) {
|
completion(decryptedPassword)
|
||||||
let alert = UIAlertController(title: "CannotShowPassword".localize(), message: AppError.pgpPrivateKeyNotFound(keyID: key).localizedDescription, preferredStyle: .alert)
|
}
|
||||||
alert.addAction(UIAlertAction.cancelAndPopView(controller: controller))
|
} catch let AppError.pgpPrivateKeyNotFound(keyID: key) {
|
||||||
let selectKey = UIAlertAction.selectKey(controller: controller) { action in
|
DispatchQueue.main.async {
|
||||||
decryptPassword(in: controller, with: passwordPath, using: action.title, completion: completion)
|
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