Skip to content

Commit

Permalink
Use createPGPMessage instead of CryptoNewPGPMessage to support ASCII-…
Browse files Browse the repository at this point in the history
…armored password with YubiKey (#658)
  • Loading branch information
mssun authored Nov 30, 2024
1 parent 5bf7ff2 commit c5d9d25
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions pass/Services/PasswordDecryptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func verifyPin(smartCard: YKFSmartCardInterface, pin: String) async throws {

func decipher(smartCard: YKFSmartCardInterface, ciphertext: Data, chained: Bool) async throws -> Data {
var error: NSError?
let message = CryptoNewPGPMessage(ciphertext)
let message = createPGPMessage(from: ciphertext)
guard let mpi1 = Gopenpgp.HelperPassGetEncryptedMPI1(message, &error) else {
throw AppError.yubiKey(.decipher(message: "Failed to get encrypted MPI."))
}
Expand All @@ -225,7 +225,7 @@ func decipher(smartCard: YKFSmartCardInterface, ciphertext: Data, chained: Bool)
}

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 {
throw AppError.yubiKey(.decipher(message: "Failed to new session key."))
Expand Down
18 changes: 9 additions & 9 deletions passKit/Crypto/GopenPGPInterface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,15 @@ struct GopenPGPInterface: PGPInterface {
var shortKeyID: [String] {
publicKeys.keys.map { $0.suffix(8).uppercased() }
}
}

private func createPGPMessage(from encryptedData: Data) -> CryptoPGPMessage? {
// Important note:
// Even if Defaults.encryptInArmored is true now, it could be different during the encryption.
var error: NSError?
let message = CryptoNewPGPMessageFromArmored(String(data: encryptedData, encoding: .ascii), &error)
if error == nil {
return message
}
return CryptoNewPGPMessage(encryptedData.mutable as Data)
public func createPGPMessage(from encryptedData: Data) -> CryptoPGPMessage? {
// Important note:
// Even if Defaults.encryptInArmored is true now, it could be different during the encryption.
var error: NSError?
let message = CryptoNewPGPMessageFromArmored(String(data: encryptedData, encoding: .ascii), &error)
if error == nil {
return message
}
return CryptoNewPGPMessage(encryptedData.mutable as Data)
}

0 comments on commit c5d9d25

Please sign in to comment.