P2PWNC
Class P2PWNCClient

java.lang.Object
  extended byP2PWNC.P2PWNCProto
      extended byP2PWNC.P2PWNCClient

public class P2PWNCClient
extends P2PWNCProto

This class provides the functionality of a P2PWNC protocol client program. That is, it provides functions to connect to the service provider and maintain a session.

Version:
0.0.1
Author:
Pantelis Frangoudis, Elias Efstathiou

Field Summary
protected  P2PWNCCert clientCert
          Consumer (client) certificate.
protected  P2PWNCKey clientPrivKey
          Consumer (client) secret key.
protected  java.net.Socket clientSocket
          Socket through which the communication to the service provider is performed.
protected  P2PWNCConverter converter
          Instance of the P2PWNCConverter class, responsible for conversions of messages from wire (text) to internal representation.
protected  P2PWNCCrypt cryptHandler
          Instance of the P2PWNCCrypt class, responsible for cryptograhic operations performed by the client (such as receipt signing).
protected  int currentWeight
          Current weight of a provider-consumer session (that is the amount of traffic initiated by/forwarded to the consumer.
protected  P2PWNCio ioHandler
          Instance of the P2PWNCio class, responsible for i/o operations, such as reading keys and certificates, reading/writing messages from/to the network, etc.
static int P2PWNC_ALGO_ECC
          Elliptic Curve cryptosystem identifier.
static int P2PWNC_ALGO_RSA
          RSA cryptosystem identifier.
static int P2PWNC_MSG_CACK
          This message type corresponds to a P2PWNC "connection acknowledgement" message (CACK).
static int P2PWNC_MSG_CONN
          This message type corresponds to a P2PWNC "connect" message (CONN).
static int P2PWNC_MSG_RCPT
          This message type corresponds to a P2PWNC "receipt" message (RCPT).
static int P2PWNC_MSG_RREQ
          This message type corresponds to a P2PWNC "receipt request" message (RREQ).
static int P2PWNC_MSG_TEAR
          This message type corresponds to a P2PWNC "tear connection" message (TEAR).
static int P2PWNC_SERVER_PORT
          The standard port a service provider listens for client messages, as specified by the P2PWNC protocol).
protected  P2PWNCKey providerKey
          Service provider public key.
protected  java.net.InetAddress serverAddr
          Internet address of the service provider.
protected  int sessionTimestamp
          Session timestamp.
 
Constructor Summary
(package private) P2PWNCClient(java.lang.String certPath, java.lang.String privKeyPath)
          Constructs a P2PWNCClient object, reading the client certificate and secret key from files.
 
Method Summary
 boolean connectToP2PWNCServer(java.lang.String hostname, int port)
          Connects to the service provider.
static void main(java.lang.String[] args)
           
 void P2PWNCClientFunc()
          Main client function.
static void printUsage()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

providerKey

protected P2PWNCKey providerKey
Service provider public key. This is obtained when the provider first asks the client for a receipt (RREQ message).


clientCert

protected P2PWNCCert clientCert
Consumer (client) certificate. This is normally read from a file.


clientPrivKey

protected P2PWNCKey clientPrivKey
Consumer (client) secret key. This is normally read from a file.


sessionTimestamp

protected int sessionTimestamp
Session timestamp. This field indicates when the session started. The timestamp is set by the provider, when it responds (CACK) to a client's connection (CONN) message.


currentWeight

protected int currentWeight
Current weight of a provider-consumer session (that is the amount of traffic initiated by/forwarded to the consumer. Each time the client receives an RREQ message this field is updated.


ioHandler

protected P2PWNCio ioHandler
Instance of the P2PWNCio class, responsible for i/o operations, such as reading keys and certificates, reading/writing messages from/to the network, etc.


cryptHandler

protected P2PWNCCrypt cryptHandler
Instance of the P2PWNCCrypt class, responsible for cryptograhic operations performed by the client (such as receipt signing).


converter

protected P2PWNCConverter converter
Instance of the P2PWNCConverter class, responsible for conversions of messages from wire (text) to internal representation. For example, when a receipt is to be transmitted to the service provider, it is converted from a P2PWNCReceipt object to a text message.


clientSocket

protected java.net.Socket clientSocket
Socket through which the communication to the service provider is performed.


serverAddr

protected java.net.InetAddress serverAddr
Internet address of the service provider.


P2PWNC_SERVER_PORT

public static final int P2PWNC_SERVER_PORT
The standard port a service provider listens for client messages, as specified by the P2PWNC protocol).

See Also:
Constant Field Values

P2PWNC_ALGO_RSA

public static final int P2PWNC_ALGO_RSA
RSA cryptosystem identifier.

See Also:
Constant Field Values

P2PWNC_ALGO_ECC

public static final int P2PWNC_ALGO_ECC
Elliptic Curve cryptosystem identifier.

See Also:
Constant Field Values

P2PWNC_MSG_RCPT

public static final int P2PWNC_MSG_RCPT
This message type corresponds to a P2PWNC "receipt" message (RCPT).

See Also:
Constant Field Values

P2PWNC_MSG_CONN

public static final int P2PWNC_MSG_CONN
This message type corresponds to a P2PWNC "connect" message (CONN).

See Also:
Constant Field Values

P2PWNC_MSG_RREQ

public static final int P2PWNC_MSG_RREQ
This message type corresponds to a P2PWNC "receipt request" message (RREQ).

See Also:
Constant Field Values

P2PWNC_MSG_CACK

public static final int P2PWNC_MSG_CACK
This message type corresponds to a P2PWNC "connection acknowledgement" message (CACK).

See Also:
Constant Field Values

P2PWNC_MSG_TEAR

public static final int P2PWNC_MSG_TEAR
This message type corresponds to a P2PWNC "tear connection" message (TEAR).

See Also:
Constant Field Values
Constructor Detail

P2PWNCClient

P2PWNCClient(java.lang.String certPath,
             java.lang.String privKeyPath)
Constructs a P2PWNCClient object, reading the client certificate and secret key from files. It also constructs the client's ioHandler, cryptHandler and converter fields and sets providerKey to null and sessionTimestamp and currentWeight to 0.

Parameters:
certPath - String The path of the client certificate file.
privKeyPath - String The path of the file where the secret key of the client is stored.
Method Detail

connectToP2PWNCServer

public boolean connectToP2PWNCServer(java.lang.String hostname,
                                     int port)
Connects to the service provider. This function initiates a TCP connection to the specified P2PWNC service provider module, after having initialized the serverAddr and clientSocket fields. It sends a CONN message to the server, reads the server response in order to set the session timestamp.

Parameters:
hostname - String The IP address of the service provider.
port - int The TCP port the service provider listens for client messages.
Returns:
boolean Returns true if the connection to the server has succeeded.

P2PWNCClientFunc

public void P2PWNCClientFunc()
Main client function. In this method, there is an infinite loop in which the client waits for RREQ messages on clientSocket. Each time it receives such a message the client has to parse it, extract information about the current session weight (and store it in the currentWeight field), check the server's public key (included in the RREQ message) and finally sign a receipt and send it to the service provider.


printUsage

public static void printUsage()

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException,
                        java.security.SignatureException,
                        java.security.InvalidKeyException,
                        java.security.NoSuchAlgorithmException
Throws:
java.io.IOException
java.security.SignatureException
java.security.InvalidKeyException
java.security.NoSuchAlgorithmException