Use createPGPMessage instead of CryptoNewPGPMessage to support ASCII-armored password with YubiKey (#658)
This commit is contained in:
parent
5bf7ff2da7
commit
c5d9d258d8
2 changed files with 13 additions and 13 deletions
|
|
@ -206,7 +206,7 @@ func verifyPin(smartCard: YKFSmartCardInterface, pin: String) async throws {
|
||||||
|
|
||||||
func decipher(smartCard: YKFSmartCardInterface, ciphertext: Data, chained: Bool) async throws -> Data {
|
func decipher(smartCard: YKFSmartCardInterface, ciphertext: Data, chained: Bool) async throws -> Data {
|
||||||
var error: NSError?
|
var error: NSError?
|
||||||
let message = CryptoNewPGPMessage(ciphertext)
|
let message = createPGPMessage(from: ciphertext)
|
||||||
guard let mpi1 = Gopenpgp.HelperPassGetEncryptedMPI1(message, &error) else {
|
guard let mpi1 = Gopenpgp.HelperPassGetEncryptedMPI1(message, &error) else {
|
||||||
throw AppError.yubiKey(.decipher(message: "Failed to get encrypted MPI."))
|
throw AppError.yubiKey(.decipher(message: "Failed to get encrypted MPI."))
|
||||||
}
|
}
|
||||||
|
|
@ -225,7 +225,7 @@ func decipher(smartCard: YKFSmartCardInterface, ciphertext: Data, chained: Bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
func decryptPassword(deciphered: Data, ciphertext: Data) throws -> String {
|
func decryptPassword(deciphered: Data, ciphertext: Data) throws -> String {
|
||||||
let message = CryptoNewPGPMessage(ciphertext)
|
let message = createPGPMessage(from: ciphertext)
|
||||||
|
|
||||||
guard let algoByte = deciphered.first, let algo = symmetricKeyIDNameDict[algoByte] else {
|
guard let algoByte = deciphered.first, let algo = symmetricKeyIDNameDict[algoByte] else {
|
||||||
throw AppError.yubiKey(.decipher(message: "Failed to new session key."))
|
throw AppError.yubiKey(.decipher(message: "Failed to new session key."))
|
||||||
|
|
|
||||||
|
|
@ -147,15 +147,15 @@ struct GopenPGPInterface: PGPInterface {
|
||||||
var shortKeyID: [String] {
|
var shortKeyID: [String] {
|
||||||
publicKeys.keys.map { $0.suffix(8).uppercased() }
|
publicKeys.keys.map { $0.suffix(8).uppercased() }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
private func createPGPMessage(from encryptedData: Data) -> CryptoPGPMessage? {
|
|
||||||
// Important note:
|
public func createPGPMessage(from encryptedData: Data) -> CryptoPGPMessage? {
|
||||||
// Even if Defaults.encryptInArmored is true now, it could be different during the encryption.
|
// Important note:
|
||||||
var error: NSError?
|
// Even if Defaults.encryptInArmored is true now, it could be different during the encryption.
|
||||||
let message = CryptoNewPGPMessageFromArmored(String(data: encryptedData, encoding: .ascii), &error)
|
var error: NSError?
|
||||||
if error == nil {
|
let message = CryptoNewPGPMessageFromArmored(String(data: encryptedData, encoding: .ascii), &error)
|
||||||
return message
|
if error == nil {
|
||||||
}
|
return message
|
||||||
return CryptoNewPGPMessage(encryptedData.mutable as Data)
|
}
|
||||||
}
|
return CryptoNewPGPMessage(encryptedData.mutable as Data)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue