How to do card response encryption (how to set R_ENCRYPTION)

Guy,

i'm working with Secure Channel Protocol '02' and the JCOP shell. I have no problem to open the secure channel by doing the "init-update" & "ext-auth", and to send encrypted data to the card.

I use the default Security Domain of the simulator for both loading the applet, and process init-update & ext_auth.

byte[] buf = apdu.getBuffer();

switch (buf[ISO7816.OFFSET_INS])

{

case (byte) 0x50:// init-update

sc = GPSystem.getSecureChannel() ;

case (byte) 0x82:// ext-auth

short nbrByte = sc.processSecurity(apdu) ;

apdu.setOutgoingAndSend((short)ISO7816.OFFSET_CDATA,nbrByte);

return ;

}

i also use the same SD to uncyphered command:

case (byte) 0x01:// reload purse

{

if (sc==null)

ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);

byte sc_level = sc.getSecurityLevel() ;

if ((sc_level & 0x83)!=0x83)

ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);

// condition fullfilled, get the APDU

byte dataRead = (byte)apdu.setIncomingAndReceive() ;

byte[] buffer = apdu.getBuffer() ;

// uncypher

short clearData = sc.unwrap(buffer,(short)ISO7816.OFFSET_CDATA,dataRead) ;

// send back encyphered data, just for test ...

apdu.setOutgoingAndSend(ISO7816.OFFSET_CDATA,buffer[ISO7816.OFFSET_LC]) ;

return ;

}

My problem is when i want the card the send encrypted response back to JCOP shell.I think the problem come from the "ext-auth", in annexe E.5.2 it say that P1 should indicate the security level, but it doesn't say which value to specify response-encryption.

Thanks.

[2677 byte] By [Enoilla] at [2007-10-3 3:51:17]
# 1

Enoill,

youre using a jcop card, right? why do you try to implement the scp02 by yourself then? the issuer security domain will do it all for you.

the globalplatform spec. specifies with the ext-auth p1 parameter the level of security for scp02. sec. level 0 = just authentication, sec. level 1 = authentication+mac, sec. level 3 = authentication+mac+data encryption

lexdabeara at 2007-7-14 21:48:54 > top of Java-index,Java Mobility Forums,Consumer and Commerce...
# 2

Hi and thanks for your feedback,

as a matter of fact i do use the security domain as specified by scp02.You can see that verifying the "init-update" apdu and "ext-auth" apdu is done by:

sc = GPSystem.getSecureChannel() ;

short nbrByte = sc.processSecurity(apdu)

i also use ext-auth p1 parameter to specify the level of security, but it seems sec level=3 just specify Command Encryption, and not Response Encryption.

My problem is how to set the sec. level to Response Encryption (R_ENCRYPTION), and then which api of SecurityDomain should i call ? (i guess (sc.wrap).

E.

Enoilla at 2007-7-14 21:48:54 > top of Java-index,Java Mobility Forums,Consumer and Commerce...
# 3
Still don't have the answer, was just wandering if somebody can help here.thanks,E.
Enoilla at 2007-7-14 21:48:54 > top of Java-index,Java Mobility Forums,Consumer and Commerce...
# 4

I guess it is done with the BEGIN R-MAC SESSION command.

From GlobalPlatform 2.1.1 BEGIN R-MAC SESSION command specification:

P1 = 0x30 => Response Encryption and R-MAC (RFU)

Unfortunately this command is optional in GlobalPlatform and seems not to be supported by the JCOP cards.

Else I would expect the wrap method to do the job.

Cheers,

Crispan

lionkinga at 2007-7-14 21:48:54 > top of Java-index,Java Mobility Forums,Consumer and Commerce...
# 5

After reading http://forum.java.sun.com/thread.jspa?threadID=672352&tstart=30 where HartmutForJCOP gives some information on using SCP between the Offcard API (JCShell) and an applet I am a little bit irritated.

As far as I understand correctly what HartmutForJCOP says, the SecureChannel.wrap(...) method should work fine and encode the response data.

I tried this with an applet but the response was sent out plain.

So either I am wrong or HartmutForJCOP is. I would guess it is me. Maybe I did forget something in my applet. Can someone shed some light on this issue?

lionkinga at 2007-7-14 21:48:54 > top of Java-index,Java Mobility Forums,Consumer and Commerce...
# 6

The GP wrap and encrypt method is not supported by JCOP. Reasoning: JCOP does not support R-MAC.

I think Hartmut explained the general case. So if you would like R-MAC functionality you would need to extend your security domain and implement the wrap and encrypt methods either in the SD itself or in the applet.

lexdabeara at 2007-7-14 21:48:54 > top of Java-index,Java Mobility Forums,Consumer and Commerce...
# 7
Thank you very much for the clarification, Lexdabear!
lionkinga at 2007-7-14 21:48:54 > top of Java-index,Java Mobility Forums,Consumer and Commerce...