log on init

This commit is contained in:
Dmitry Bespalov 2019-09-04 14:03:56 +02:00
parent c4d632137d
commit 0cddf0fcf7
2 changed files with 7 additions and 4 deletions

View File

@ -1,3 +1,6 @@
import Foundation
import CryptoSwift
public class KeycardCommandSet {
let cardChannel: CardChannel
let secureChannel: SecureChannel
@ -236,7 +239,9 @@ public class KeycardCommandSet {
}
public func initialize(pin: String, puk: String, sharedSecret: [UInt8]) throws -> APDUResponse {
let cmd = APDUCommand(cla: CLA.proprietary.rawValue, ins: KeycardINS.initialize.rawValue, p1: 0, p2: 0, data: secureChannel.oneShotEncrypt(data: (Array((pin + puk).utf8) + sharedSecret)))
let data = (Array((pin + puk).utf8) + sharedSecret)
Logger.shared.log("initialize(pin=\(pin) puk=\(puk) sharedSecret=\(Data(sharedSecret).toHexString())): data=\(Data(data).toHexString())")
let cmd = APDUCommand(cla: CLA.proprietary.rawValue, ins: KeycardINS.initialize.rawValue, p1: 0, p2: 0, data: secureChannel.oneShotEncrypt(data: data))
return try secureChannel.transmit(channel: cardChannel, cmd: cmd)
}
}

View File

@ -159,9 +159,7 @@ class SecureChannel {
func oneShotEncrypt(data: [UInt8]) -> [UInt8] {
self.iv = Crypto.shared.random(count: SecureChannel.blockLength)
// let encrypted = Crypto.shared.aes256Enc(data: data, iv: iv, key: secret!)
let paddedData = Crypto.shared.iso7816_4Pad(data: data, blockSize: SecureChannel.blockLength)
let encrypted = Crypto.shared.aes256Enc(data: paddedData, iv: iv, key: secret!)
let encrypted = Crypto.shared.aes256Enc(data: data, iv: iv, key: secret!)
return [UInt8(self.publicKey!.count)] + publicKey! + iv + encrypted
}