log on init
This commit is contained in:
parent
c4d632137d
commit
0cddf0fcf7
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue