jason.server
Class Session

java.lang.Object
  |
  +--javacard.framework.service.BasicService
        |
        +--jason.server.Session
All Implemented Interfaces:
Constants, javacard.framework.service.Service

public class Session
extends javacard.framework.service.BasicService
implements Constants

Title: Javacards As Secure Object Store

Description: Session class containing methods to set up a secure session between client and server.

Copyright: Copyright (c) 2002

Company: University of Twente


Field Summary
private  Cipher cipher
           
private  byte[] clientRandom
           
private  boolean failure
           
static byte INS_INVOKE
          INS used for a method invocation
static byte INS_LOGIN
          INS used for loggin in
static byte INS_PUT_KEY
          INS used for personalization
private  boolean isInvoking
           
private  boolean isLoggingIn
           
private  byte[] jdf
          The jdf array contains all information from the Jason Definition File.
private  KeyStore keyStore
           
private  short methodOffset
          Set by decrypt(javacard.framework.APDU) to the index within the jdf array where the invoked method starts
private  RandomData randomData
           
private  byte role
           
static byte ROLE_CARD
           
private  byte[] serverRandom
           
private  XORKey sessionKey
           
private  Signature signature
           
 
Fields inherited from class javacard.framework.service.BasicService
 
Fields inherited from interface jason.Constants
ANYBODY, APPLICATION_DATA_TAG, FCI_TAG, JC_RMI_DATA_TAG, JDF_TAG, NORMAL_TAG, SECURITY_AUTHENTIC, SECURITY_CONFIDENTIAL, SECURITY_CONFIDENTIAL_AUTHENTIC, SECURITY_PLAIN, TYPE_ARRAY, TYPE_BOOLEAN, TYPE_BOOLEAN_ARRAY, TYPE_BYTE, TYPE_BYTE_ARRAY, TYPE_INT, TYPE_INT_ARRAY, TYPE_OBJECT, TYPE_OBJECT_ARRAY, TYPE_SHORT, TYPE_SHORT_ARRAY, TYPE_VOID
 
Constructor Summary
Session(KeyStore keyStore, byte[] jdf)
          Default constructor
 
Method Summary
private  boolean decrypt(javacard.framework.APDU apdu)
          Decrypts the apdu buffer when necessary.
private  boolean encrypt(javacard.framework.APDU apdu)
          Encrypts or signs the return value when necessary.
private  boolean login(javacard.framework.APDU apdu)
          For each login procedure the login method will be invoked twice.
 boolean processCommand(javacard.framework.APDU apdu)
          The Session object itself can also process some commands.
 boolean processDataIn(javacard.framework.APDU apdu)
          Remembers if the apdu is an invoke APDU.
 boolean processDataOut(javacard.framework.APDU apdu)
          A select APDU will be expanded by the JDF array.
private  boolean putKey(javacard.framework.APDU apdu)
           
 
Methods inherited from class javacard.framework.service.BasicService
fail, getCLA, getINS, getOutputLength, getP1, getP2, getStatusWord, isProcessed, receiveInData, selectingApplet, setOutputLength, setProcessed, setStatusWord, succeed, succeedWithStatusWord
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INS_INVOKE

public static final byte INS_INVOKE
INS used for a method invocation

See Also:
Constant Field Values

INS_LOGIN

public static final byte INS_LOGIN
INS used for loggin in

See Also:
Constant Field Values

INS_PUT_KEY

public static final byte INS_PUT_KEY
INS used for personalization

See Also:
Constant Field Values

ROLE_CARD

public static final byte ROLE_CARD
See Also:
Constant Field Values

randomData

private RandomData randomData

clientRandom

private byte[] clientRandom

serverRandom

private byte[] serverRandom

role

private byte role

failure

private boolean failure

keyStore

private KeyStore keyStore

cipher

private Cipher cipher

signature

private Signature signature

sessionKey

private XORKey sessionKey

jdf

private byte[] jdf
The jdf array contains all information from the Jason Definition File. It has the following format:

   jdf {
     u1 
     method[] methods
   }
   method {
     u2 
     u1 
     u1[] roles
     u1 
     u1 
     u1[] modifier
   }
 


methodOffset

private short methodOffset
Set by decrypt(javacard.framework.APDU) to the index within the jdf array where the invoked method starts


isInvoking

private boolean isInvoking

isLoggingIn

private boolean isLoggingIn
Constructor Detail

Session

public Session(KeyStore keyStore,
               byte[] jdf)
Default constructor

Parameters:
keyStore - The KeyStore that will be used with this Session object
jdf - The specific security requirements for a single Object
Method Detail

processDataIn

public boolean processDataIn(javacard.framework.APDU apdu)
Remembers if the apdu is an invoke APDU. The value of isInvoking is used in the processDataOut(javacard.framework.APDU) method to decide if the outgoing APDU should be encrypted or not. If it is an invoke APDU the decrypt(javacard.framework.APDU) method is invoked

Specified by:
processDataIn in interface javacard.framework.service.Service
Overrides:
processDataIn in class javacard.framework.service.BasicService
Parameters:
apdu - The unprocessed APDU
Returns:
false or the return value of decrypt(javacard.framework.APDU)

processCommand

public boolean processCommand(javacard.framework.APDU apdu)
The Session object itself can also process some commands. Login and personalization are the only commands that the Session will process. While encountering an INS_LOGIN the login method is called. While encountering an INS_PUT_KEY the putKey is called. All other INS values will keep the apdu unprocessed.

Specified by:
processCommand in interface javacard.framework.service.Service
Overrides:
processCommand in class javacard.framework.service.BasicService
Parameters:
apdu -
Returns:
true if the apdu should not further be processed, false otherwise

login

private boolean login(javacard.framework.APDU apdu)
For each login procedure the login method will be invoked twice. The first time (when isLoggingIn is false) it will receive an APDU in the following format:
CLA INS P1 P2 Lc Role
byte
ClientRandom
length
ClientRandom
The response APDU that is being sent the first time is:
SW1 SW2 ServerRandom
length
ServerRandom SignedClientRandom
length
SignedClientRandom
The second time the login method is invoked, it expects an APDU of the following format:
CLA INS P1 P2 Lc SignedServerRandom
length
SignedServerRandom
The second time the response APDU will look like:
SW1 SW2 EncryptedSessionKey
length
EncryptedSessionKey

Parameters:
apdu - unprocessed APDU
Returns:
true if the apdu can be considered processed

putKey

private boolean putKey(javacard.framework.APDU apdu)

decrypt

private boolean decrypt(javacard.framework.APDU apdu)
Decrypts the apdu buffer when necessary. If the terminal has not logged in nothing will happen. If the signature is not correct, then an ISO7816.SW_SECURITY_STATUS exception is thrown.

Parameters:
apdu - The unencrypted apdu
Returns:
false

encrypt

private boolean encrypt(javacard.framework.APDU apdu)
Encrypts or signs the return value when necessary. The methodOffset has already been set by the decrypt(javacard.framework.APDU) method.

Parameters:
apdu - The plain result APDU
Returns:
true

processDataOut

public boolean processDataOut(javacard.framework.APDU apdu)
A select APDU will be expanded by the JDF array. An invocation APDU will be encrypted when necessary.

Specified by:
processDataOut in interface javacard.framework.service.Service
Overrides:
processDataOut in class javacard.framework.service.BasicService
Parameters:
apdu - The APDU
Returns:
false