@@ -77,6 +77,15 @@ private func isEncryptKeyAlgoRSA(_ applicationRelatedData: Data) -> Bool {
7777 return false
7878}
7979
80+ private func createPGPMessage( from encryptedData: Data ) -> CryptoPGPMessage ? {
81+ var error : NSError ?
82+ let message = CryptoNewPGPMessageFromArmored ( String ( data: encryptedData, encoding: . ascii) , & error)
83+ if error == nil {
84+ return message
85+ }
86+ return CryptoNewPGPMessage ( encryptedData as Data )
87+ }
88+
8089private func getCapabilities( _ applicationRelatedData: Data ) -> ( Bool , Bool ) {
8190 let tlv = TKBERTLVRecord . sequenceOfRecords ( from: applicationRelatedData) !
8291 // 0x5f52: Historical Bytes
@@ -206,7 +215,7 @@ func verifyPin(smartCard: YKFSmartCardInterface, pin: String) async throws {
206215
207216func decipher( smartCard: YKFSmartCardInterface , ciphertext: Data , chained: Bool ) async throws -> Data {
208217 var error : NSError ?
209- let message = CryptoNewPGPMessage ( ciphertext)
218+ let message = createPGPMessage ( from : ciphertext)
210219 guard let mpi1 = Gopenpgp . HelperPassGetEncryptedMPI1 ( message, & error) else {
211220 throw AppError . yubiKey ( . decipher( message: " Failed to get encrypted MPI. " ) )
212221 }
@@ -225,7 +234,7 @@ func decipher(smartCard: YKFSmartCardInterface, ciphertext: Data, chained: Bool)
225234}
226235
227236func decryptPassword( deciphered: Data , ciphertext: Data ) throws -> String {
228- let message = CryptoNewPGPMessage ( ciphertext)
237+ let message = createPGPMessage ( from : ciphertext)
229238
230239 guard let algoByte = deciphered. first, let algo = symmetricKeyIDNameDict [ algoByte] else {
231240 throw AppError . yubiKey ( . decipher( message: " Failed to new session key. " ) )
0 commit comments