core
Class Protocol

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--core.Protocol
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
ANTOINE, BANK, COMPANY, INITAND, INITNS, INITXAV, INITYAHA, RESPAND, RESPNS, RESPXAV, RESPYAHA, SERVYAHA

public abstract class Protocol
extends java.lang.Thread

Any extension of this abstract class represents a security protocol from the viewpoint of one of its agents. For example, to implement a Protocol with n agents, we need n classes extending Protocol.

Author:
Xavier Didelot

Field Summary
private  java.util.Vector agents
          This vector represents all the Agent with whom this Protocol communicates
protected  Message m0
          This message is used to manipulate the fields of a Message
private static java.lang.Class messageC
           
private static java.lang.Class messageKeyC
           
private  java.security.KeyStore myKeyStore
          The KeyStore in which all public/private keys are stored
private static java.lang.Class nonceC
           
protected  java.util.Vector nonces
          This vector contains the nonces that this Protocol knows
private  java.util.Stack parts
          This stack is used to store the different fields of a given message
private  char[] password
          This is the password to use to access the KeyStore
private  SecretKeyStore secretKeyStore
          The SecretKeyStore in which all secret/shared keys are stored
private  java.util.Stack stackM0
          This stack is used to restore a previous state during the protocol run
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Protocol(java.lang.String m, java.lang.String mk, java.lang.String n)
          Creates a new instance of Protocol
 
Method Summary
protected  void addAgent(Agent agent)
          This method adds an agent to the list of known agents
protected  void addNonce(INonce nonce)
          This method adds a nonce to the list of known nonces
protected  void addParts(IMessage[] array, int size)
          This method adds the given Messages into the list of Messages to be treated
protected  Agent agentFromId(java.lang.String id)
          get Agent from id
protected  void checkTag(Message mm, java.lang.String s)
           
 void createNewNonce(java.lang.String id)
          This method creates a new Nonce
 java.lang.String get(java.lang.String id)
          Waits for a message from the given agent and returns it.
 java.util.Vector getAgents()
          This method returns the Vector of Agents
abstract  java.lang.String[] getArgs(java.lang.String[] args)
          This method has to be implemented by classes extending the Protocol class.
protected  Message getPart()
          This method returns the next field to be treated
 java.security.PrivateKey getPrivateKey(java.lang.String agent)
          This method returns the Private Key of a given agent by looking after it in the KeyStore
 java.security.PublicKey getPublicKey(java.lang.String agent)
          This method returns the Public Key of a given agent by looking after it in the KeyStore
 java.security.Key getSecretKey(java.lang.String id)
          This method returns the Secret Key of a given agent by looking after it in the SecretKeyStore
protected  java.lang.String IPFromId(java.lang.String id)
          This method returns the IP of the agent whose id is given
protected  Message message()
           
protected  Message message(Agent agent)
           
protected  Message message(INonce n)
           
protected  Message message(Message m1, Message m2)
           
protected  Message message(java.lang.String s)
           
protected  IMessageKey messageKey()
           
protected  IMessageKey messageKey(java.security.Key key)
           
protected  IMessageKey messageKey(Message msg)
           
protected  IMessageKey messageKey(java.lang.String algo)
           
protected  java.lang.String nameFromId(java.lang.String id)
          This method returns the name of the agent whose id is given
 void newAgent(java.lang.String id, int port)
          Waits for a connection to be established.
protected  INonce nonce()
           
protected  INonce nonce(java.lang.Integer i)
           
protected  INonce nonce(java.lang.String s)
           
 INonce nonceFromId(java.lang.String id)
          This method returns the Nonce whose id is given
 void put(java.lang.String id, java.lang.String what)
          Sends a message to another agent
 void put(java.lang.String id, java.lang.String what, int port)
          Sends a message to another agent using the specified port
protected  Message restoreM0()
          This method restore the last value of Message m0
abstract  void run()
          This method has to be implemented by classes extending the Protocol class.
 void setIPToId(java.lang.String ip, java.lang.String id)
          This method sets the IP of a given Agent
protected  void setKS(java.lang.String fileKeyStore, java.lang.String password)
          this method sets the KeyStore that has to be used
 void setNameToId(java.lang.String name, java.lang.String id)
          This method sets the name of a given Agent
protected  void setSKS(java.lang.String file)
          this method sets the SecretKeyStore that has to be used
 void setValueToNonce(java.lang.String value, java.lang.String id)
          This method sets the value of a given Nonce
protected  void storeM0()
          This method saves the current value of Message m0
 java.lang.String valueFromNonce(java.lang.String id)
          This method returns the value of a given Nonce
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

secretKeyStore

private SecretKeyStore secretKeyStore
The SecretKeyStore in which all secret/shared keys are stored


myKeyStore

private java.security.KeyStore myKeyStore
The KeyStore in which all public/private keys are stored


agents

private java.util.Vector agents
This vector represents all the Agent with whom this Protocol communicates


password

private char[] password
This is the password to use to access the KeyStore


nonces

protected java.util.Vector nonces
This vector contains the nonces that this Protocol knows


parts

private java.util.Stack parts
This stack is used to store the different fields of a given message


stackM0

private java.util.Stack stackM0
This stack is used to restore a previous state during the protocol run


m0

protected Message m0
This message is used to manipulate the fields of a Message


messageC

private static java.lang.Class messageC

messageKeyC

private static java.lang.Class messageKeyC

nonceC

private static java.lang.Class nonceC
Constructor Detail

Protocol

public Protocol(java.lang.String m,
                java.lang.String mk,
                java.lang.String n)
Creates a new instance of Protocol

Method Detail

message

protected Message message()

message

protected Message message(java.lang.String s)

message

protected Message message(Message m1,
                          Message m2)

message

protected Message message(Agent agent)

message

protected Message message(INonce n)

nonce

protected INonce nonce()

nonce

protected INonce nonce(java.lang.Integer i)

nonce

protected INonce nonce(java.lang.String s)

messageKey

protected IMessageKey messageKey()

messageKey

protected IMessageKey messageKey(java.lang.String algo)

messageKey

protected IMessageKey messageKey(java.security.Key key)

messageKey

protected IMessageKey messageKey(Message msg)

checkTag

protected void checkTag(Message mm,
                        java.lang.String s)
                 throws java.lang.Exception
java.lang.Exception

storeM0

protected void storeM0()
This method saves the current value of Message m0


restoreM0

protected Message restoreM0()
This method restore the last value of Message m0

Returns:
the last value of Message m0

getPart

protected Message getPart()
This method returns the next field to be treated

Returns:
next field to be treated

addAgent

protected void addAgent(Agent agent)
This method adds an agent to the list of known agents

Parameters:
agent - agent to add to the list of known agents

addNonce

protected void addNonce(INonce nonce)
This method adds a nonce to the list of known nonces

Parameters:
nonce - nonce to add to the list of known nonces

setSKS

protected void setSKS(java.lang.String file)
this method sets the SecretKeyStore that has to be used

Parameters:
file - the SecretKeyStore that has to be used

setKS

protected void setKS(java.lang.String fileKeyStore,
                     java.lang.String password)
this method sets the KeyStore that has to be used

Parameters:
fileKeyStore - the KeyStore that has to be used
password - password to use to access this KeyStore

addParts

protected void addParts(IMessage[] array,
                        int size)
                 throws java.lang.Exception
This method adds the given Messages into the list of Messages to be treated

Parameters:
array - array of messages that will have to be treated
size - expected size of the array
Throws:
java.lang.Exception - if the Message does not have the expected number of fields

getPrivateKey

public java.security.PrivateKey getPrivateKey(java.lang.String agent)
This method returns the Private Key of a given agent by looking after it in the KeyStore

Parameters:
agent - the agent whose key we are looking for
Returns:
the private key of the given agent

getPublicKey

public java.security.PublicKey getPublicKey(java.lang.String agent)
This method returns the Public Key of a given agent by looking after it in the KeyStore

Parameters:
agent - the agent whose key we are looking for
Returns:
the public key of the given agent

getSecretKey

public java.security.Key getSecretKey(java.lang.String id)
                               throws java.io.IOException,
                                      java.lang.ClassNotFoundException
This method returns the Secret Key of a given agent by looking after it in the SecretKeyStore

Returns:
the secret key of the given agent
java.io.IOException
java.lang.ClassNotFoundException

agentFromId

protected Agent agentFromId(java.lang.String id)
get Agent from id

Parameters:
id - id of the agent to find
Returns:
the Agent corresponding to this id

nonceFromId

public INonce nonceFromId(java.lang.String id)
This method returns the Nonce whose id is given

Parameters:
id - id of the Nonce we are looking for
Returns:
the Nonce whose id is given

nameFromId

protected java.lang.String nameFromId(java.lang.String id)
                               throws java.lang.Exception
This method returns the name of the agent whose id is given

Parameters:
id - id of the agent whose name we are looking for
Returns:
the name of the agent whose id is given
java.lang.Exception

IPFromId

protected java.lang.String IPFromId(java.lang.String id)
                             throws java.lang.Exception
This method returns the IP of the agent whose id is given

Parameters:
id - id of the agent whose name we are looking for
Returns:
the IP of the agent whose id is given
java.lang.Exception

get

public java.lang.String get(java.lang.String id)
Waits for a message from the given agent and returns it.

Parameters:
id - id of the agent from which to get a message
Returns:
the next message received

newAgent

public void newAgent(java.lang.String id,
                     int port)
Waits for a connection to be established. The id assigned to this agent is the arguement id

Parameters:
id - id to assign to the new host
port - port on which we are waiting for a connection

put

public void put(java.lang.String id,
                java.lang.String what)
Sends a message to another agent

Parameters:
what - the message to send

put

public void put(java.lang.String id,
                java.lang.String what,
                int port)
Sends a message to another agent using the specified port

Parameters:
what - the message to send
port - port to use to send the message

setNameToId

public void setNameToId(java.lang.String name,
                        java.lang.String id)
                 throws java.lang.Exception
This method sets the name of a given Agent

Parameters:
name - name to give to the Agent
id - id of the Agent
Throws:
java.lang.Exception - if the name of this Agent has already been set to something else

setIPToId

public void setIPToId(java.lang.String ip,
                      java.lang.String id)
This method sets the IP of a given Agent

Parameters:
ip - IP to give to the Agent
id - id of the Agent

setValueToNonce

public void setValueToNonce(java.lang.String value,
                            java.lang.String id)
                     throws java.lang.Exception
This method sets the value of a given Nonce

Parameters:
value - value to give to the Nonce
id - id of the Nonce
Throws:
java.lang.Exception - if the value of this Nonce has already been set to something else

createNewNonce

public void createNewNonce(java.lang.String id)
This method creates a new Nonce

Parameters:
id - id of the new Nonce to create

valueFromNonce

public java.lang.String valueFromNonce(java.lang.String id)
This method returns the value of a given Nonce

Parameters:
id - id of the Nonce whose value we are looking for
Returns:
the value of the given Nonce

run

public abstract void run()
This method has to be implemented by classes extending the Protocol class. It represents the actions to perform when the protocol is started.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

getArgs

public abstract java.lang.String[] getArgs(java.lang.String[] args)
This method has to be implemented by classes extending the Protocol class. It represents the actions to perform to get the arguments of the protocol.


getAgents

public java.util.Vector getAgents()
This method returns the Vector of Agents

Returns:
the vector of Agents