Apologies for the essay-like nature of this question. I have been struggling to get to grips with this and have tried to sum up my understanding of what is needed, with the specific questions I have.
In this question relating to reading data from a European DTCO company card, I was given advice that involved following the algorithm in the screenshot below (from Appendix 11 of this document) but I'm not clear how to perform the two highlighted steps.
I see that Sign is a segment of the array containing the certificate but what does it mean to open it with the public key? I can successfully perform the step before by reading CA_Certificate from the card and issuing a MANAGE SECURITY ENVIRONMENT APDU using CAR´ (see first step of algorithm) from it. But having selected the public key that way, what public key do I use in the open Sign step. The MSE selects one but I don't have it; I have only the European public key from ERCA, but is that the same key I have selected in the card? I don't have any private keys, but would I need them.
In the step for checking that Hash(C´) = H´, how should I calculate the hash? There seem to be so many different ways (is formats the right word?) of doing encryption/decryption/hashing that I'm quite confused.
All I really need to be able to do to read the data I need is to authenticate using EXTERNAL AUTHENTICATE, immediately after a GET CHALLENGE that returns an 8 byte challenge. I presume I need to use that to calculate the cipher for the EXTERNAL AUTHENTICATE. I found the sample code below (see full post) and although it appears to be in some C-like scripting language (I'm using C#) and for a different type of smartcard it seems quite similar to what I must use.
//
// Authenticate against CardOS card
//
var card = new Card(_scsh3.reader);
var crypto = new Crypto();
var key = new Key();
key.setComponent(Key.DES,
new ByteString("01010101010101010101010101010101", HEX));
// Get challenge
var challenge = card.sendApdu(0x00, 0x84, 0x00, 0x00, 8, [0x9000]);
// Crypto.DES_MAC_EMV is a CBC generated Retail-MAC
var cipher = crypto.sign(key, Crypto.DES_MAC_EMV, challenge);
card.sendApdu(0x00, 0x82, 0x00, 0x81, cipher);
print("Card returns " + card.SW.toString(16) + " - " + card.SWMSG);
Differences are
The additional P2 parameter indicating that MANAGE SECURITY ENVIRONMENT has been done, presumably with the CAR´ from Card_Certificate, which doesn't work for me, though it does with the CAR´ from CA_Certificate.
Lc of 0x80 instead of the 0x81 in the sample code.
Any cipher I calculate to use here would have to be 128 bytes long while it's unclear of the cipher length in the sample.