Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Support decrypting of ASCII-Armored passwords with YubiKey.
  • Loading branch information
oleg authored and oleg committed Jun 1, 2024
commit 74f2881c86032bdacf93052187d81da37a8f7917
13 changes: 11 additions & 2 deletions pass/Services/PasswordDecryptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ private func isEncryptKeyAlgoRSA(_ applicationRelatedData: Data) -> Bool {
return false
}

private func createPGPMessage(from encryptedData: Data) -> CryptoPGPMessage? {
var error: NSError?
let message = CryptoNewPGPMessageFromArmored(String(data: encryptedData, encoding: .ascii), &error)
if error == nil {
return message
}
return CryptoNewPGPMessage(encryptedData as Data)
}

private func getCapabilities(_ applicationRelatedData: Data) -> (Bool, Bool) {
let tlv = TKBERTLVRecord.sequenceOfRecords(from: applicationRelatedData)!
// 0x5f52: Historical Bytes
Expand Down Expand Up @@ -206,7 +215,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 +234,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