This discussion is archived
1 2 3 4 5 Previous Next 71 Replies Latest reply: Oct 12, 2009 5:35 PM by safarmer Go to original post RSS
  • 15. Re: Global Platform- MACing MAC Retail
    843851 Newbie
    Currently Being Moderated
    Hi,

    I get d2b8d984cb4853d7 instead of DE84CF5EE526CAC2.


    The S-ENC base key is 40 41 42 43 .... 4F,
    The session counter ihave a value of 00 01,
    The card challenge : 6C 7F FC 11 3F B9,
    and the host challenge : 00 00 00 00 00 00 00 00.



    Thank you very much
  • 16. Re: Global Platform- MACing MAC Retail
    safarmer Expert
    Currently Being Moderated
    Here is the log output from running against my code using the data you provided.
    Input to session S-ENC derivation: 01 82 00 01 00 00 00 00 00 00 00 00 00 00 00 00
    S-ENC: 25c8794a1304fe254f5ea1378c2f8c5825c8794a1304fe25
    Input to session DEK derivation : 01 81 00 01 00 00 00 00 00 00 00 00 00 00 00 00
    S-DEK: 0e51fdf197151f237a57bc154013fd380e51fdf197151f23
    Input to session CMAC derivation: 01 01 00 01 00 00 00 00 00 00 00 00 00 00 00 00
    S-MAC: 9bec98891580c2b345fe9ec48afb8c2a9bec98891580c2b3
    Input to session RMAC derivation: 01 02 00 01 00 00 00 00 00 00 00 00 00 00 00 00
    Input to card cryptogram verification: 00 00 00 00 00 00 00 00 00 01 6c 7f fc 11 3f b9 80 00 00 00 00 00 00 00
    Signature : de 84 cf 5e e5 26 ca c2
    Cryptogram: de 84 cf 5e e5 26 ca c2
    Card cryptogram authenticated
    Hopefully this may help you track down where they differ.

    Cheers,
    Shane
  • 17. Re: Global Platform- MACing MAC Retail
    safarmer Expert
    Currently Being Moderated
    Also, the MAC method for verifying the card and host cryptogram is different to the retail MAC used for EXTERNAL AUTHENTICATE. Here is some code to generate the signature for host and card cryptograms.
        /**
         * Calculate the DES CBC MAC using the standard cipher algorithms
         * 
         * @param key
         *            Key used for MAC calculation
         * @param data
         *            Data to calculate the MAC for
         * @param iv
         *            ICV
         * 
         * @returns CBC MAC
         */
        public byte[] cbcMac(byte[] data) throws AuthenticationException {
    
            byte[] temp;
            try {
                Cipher cbcDES = Cipher.getInstance("DESede/CBC/NoPadding");
                IvParameterSpec params = new IvParameterSpec(DEFAULT_ICV);
                cbcDES.init(Cipher.ENCRYPT_MODE, sessionSENC, params);
    
                temp = cbcDES.doFinal(data);
            } catch (GeneralSecurityException e) {
                throw new AuthenticationException("Error performing CBC MAC", e);
            }
    
            byte[] signature = new byte[8];
            System.arraycopy(temp, temp.length - 8, signature, 0, signature.length);
            return signature;
        }
    Cheers,
    Shane
  • 18. Re: Global Platform- MACing MAC Retail
    843851 Newbie
    Currently Being Moderated
    Hi,

    It's works very well thank you.

    Now I have to send my host cryptogramm to the card but I have to compute a mac of my message but I don't know the method and the Key i should use to do this.

    Can you help me?


    Thank you very much
  • 19. Re: Global Platform- MACing MAC Retail
    843851 Newbie
    Currently Being Moderated
    It's C-MAC Generation on Modified APDU or C-MAC Generation on Unmodified APDU?

    thanks
  • 20. Re: Global Platform- MACing MAC Retail
    safarmer Expert
    Currently Being Moderated
    Hi,

    It depends on the i value for your secure channel. You will need to check section F of the card spec to find your i value for the SCP if you do not already know it.

    From GP 2.1.1 - E.1.1 - SCP02 Secure Channel
    In SCP02 the card shall support at least one of the following implementation options as defined by "i" (see Appendix F - GlobalPlatform Data Values and Card Recognition Data):
    - "i" = '04': Initiation mode explicit, C-MAC on modified APDU, ICV set to zero, no ICV encryption, 1 Secure Channel base key,
    - "i" = '05': Initiation mode explicit, C-MAC on modified APDU, ICV set to zero, no ICV encryption, 3 Secure Channel Keys,
    - "i" = '0A': Initiation mode implicit, C-MAC on unmodified APDU, ICV set to MAC over AID, no ICV encryption, 1 Secure Channel base key,
    - "i" = '0B': Initiation mode implicit, C-MAC on unmodified APDU, ICV set to MAC over AID, no ICV encryption, 3 Secure Channel Keys.,
    - "i" = '14': Initiation mode explicit, C-MAC on modified APDU, ICV set to zero, ICV encryption for CMAC session, 1 Secure Channel base key,
    - "i" = '15': Initiation mode explicit, C-MAC on modified APDU, ICV set to zero, ICV encryption for CMAC session, 3 Secure Channel Keys,
    - "i" = '1A': Initiation mode implicit, C-MAC on unmodified APDU, ICV set to MAC over AID, ICV encryption for C-MAC session, 1 Secure Channel base key,
    - "i" = '1B': Initiation mode implicit, C-MAC on unmodified APDU, ICV set to MAC over AID, ICV encryption for C-MAC session, 3 Secure Channel Keys.
    Cheers,
    Shane
  • 21. Re: Global Platform- MACing MAC Retail
    843851 Newbie
    Currently Being Moderated
    Hi,

    I think it's value is 15 but I don't know really. It's a Nokia 6212 phone so where did I get this information please?


    Thanks

    Adrien
  • 22. Re: Global Platform- MACing MAC Retail
    843851 Newbie
    Currently Being Moderated
    Oups sorry i didn't read fine your answer i will search this value
  • 23. Re: Global Platform- MACing MAC Retail
    843851 Newbie
    Currently Being Moderated
    I think that I will find the value in appendix H instead of appendix F no? But i try to find the answer but i don't understand where to find tis value. I think it's in th byte 6 of key diversification send by the card when it respond to my Ini update commande no?

    thanks

    Adrien
  • 24. Re: Global Platform- MACing MAC Retail
    safarmer Expert
    Currently Being Moderated
    I am looking in the GP card spec v 2.1.1 and it only goes to F.

    From section F.3:
    The Security Domain management data may be returned in the SELECT response message within template '73' as described in Section 9.9.3.1 - Data Field Returned in the Response Message. When present, the Security Domain management data shall be coded as follows.

    Tag '64' of the SD management data is {globalPlatform 4 scp i} OID for Secure Channel Protocol of the selected Security Domain and its implementation options. I think the value you are refering to in INITIALIZE UPDATE response is the Secure Channel Protocol identifier (which would be 01 or 02 for SCP01 and SCP02 respectively).

    Cheers,
    Shane
  • 25. Re: Global Platform- MACing MAC Retail
    843851 Newbie
    Currently Being Moderated
    But the appendix F describe the SCP '10' and my I use the SCP '02'. It is the right appendix to find an answer?


    Thanks

    Adrien
  • 26. Re: Global Platform- MACing MAC Retail
    safarmer Expert
    Currently Being Moderated
    We are obviously looking at different version of the card spec :)

    03/25/2003 GlobalPlatform Card Specification 2.1.1 235

    F. GlobalPlatform Data Values and Card Recognition Data
  • 27. Re: Global Platform- MACing MAC Retail
    843851 Newbie
    Currently Being Moderated
    March 2006 Version 2.2 F : Secure Channel Protocol '10' and H : GlobalPlatform Data Values and Card Recognition Data.


    So I have to look the F appendix. It's better for me because i didn't understand why I have to read something about SCP '10'
  • 28. Re: Global Platform- MACing MAC Retail
    safarmer Expert
    Currently Being Moderated
    Depending on your card, you may want to check out GP card spec 2.1.1. I assume that is the version on your card as there are few (if any GP2.2) cards around. That said, the SCP chapters should be fine in 2.2 as long as you reference the correct protocol (SCP02).

    Cheers,
    Shane
  • 29. Re: Global Platform- MACing MAC Retail
    843851 Newbie
    Currently Being Moderated
    Sorry but I do not understand how to get the value of my i parameter.