P2PWNC
Class P2PWNCConverter

java.lang.Object
  extended byP2PWNC.P2PWNCProto
      extended byP2PWNC.P2PWNCConverter

class P2PWNCConverter
extends P2PWNCProto

This class provides conversion functionality from the internal representation to text messages and vice versa. The methods provided have to do with parsing text messages read from the network (that is from the socket the client listens for and sends messages to the service provider).

Version:
0.0.1
Author:
Pantelis Frangoudis, Elias Efstathiou

Field Summary
protected  Base64 b64Encoder
          Base64 encoder/decoder.
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).
 
Constructor Summary
(package private) P2PWNCConverter()
          Constructs a new P2PWNCConverter object, initializing its b64encoder field.
 
Method Summary
 java.lang.String constructConnMsg(P2PWNCCert cert)
          Constructs a CONN text message.
static void main(java.lang.String[] args)
           
(package private)  int parseCACKMsg(java.lang.String text)
          Parses a CACK text message.
(package private)  P2PWNCRREQMsgInfo parseRREQMsg(java.lang.String text)
          Parses an RREQ text message.
 java.lang.String receiptToTextMsg(P2PWNCReceipt rcpt)
          Converts a P2PWNCReceipt object to an RCPT text message to be sent to the service provider.
 P2PWNCReceipt textMsgToReceipt(java.lang.String text)
          Parses an RCPT text message to the correspondent P2PWNCReceipt object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

b64Encoder

protected Base64 b64Encoder
Base64 encoder/decoder. It is used for encoding of raw data that will be placed in text messages (public keys, certificates, digital signatures)


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

P2PWNCConverter

P2PWNCConverter()
Constructs a new P2PWNCConverter object, initializing its b64encoder field.

Method Detail

receiptToTextMsg

public java.lang.String receiptToTextMsg(P2PWNCReceipt rcpt)
Converts a P2PWNCReceipt object to an RCPT text message to be sent to the service provider. An RCPT text message is composed of the following fields:
FieldDescription
Message TypeRCPT
Content-lengthLength of the message in octets
AlgorithmAlgorithm identifier and bit length of signature(for example RSA1024)
TimestampSession timestamp (in RFC822 format)
WeightCurrent session traffic (in bytes)
Client certificateThe client certificate data, that is the certificate issuer's public key, user's public key and issuer signature. These fields are base64-encoded and separated by two CRLF sequences.
Service provider public keyThis field is the base64 encoded public key of the service provider, ending with two CRLF sequences
Receipt signatureThis is the base64 signature of the receipt, produced by the service consumer (client) using its private key.

Parameters:
rcpt - P2PWNCReceipt The P2PWNCReceipt object that is to be converted to a text RCPT message
Returns:
String Returns the RCPT text message that corresponds to rcpt.

textMsgToReceipt

public P2PWNCReceipt textMsgToReceipt(java.lang.String text)
Parses an RCPT text message to the correspondent P2PWNCReceipt object.

Parameters:
text - String The text message to be parsed.
Returns:
P2PWNCReceipt The P2PWNCReceipt object which is the result of the parsing operation.

constructConnMsg

public java.lang.String constructConnMsg(P2PWNCCert cert)
Constructs a CONN text message. This message includes the certificate of the client that wishes to connect to a service provider. The certificate fields (public keys and signature are base64 encoded and placed in the message separated by a sequence of two CRLF line brakes. A CONN message consists of the following fields:
FieldDescription
Message TypeCONN
Content-lengthLength of the message in octets
Client certificateThe client certificate data, that is the certificate issuer's public key, user's public key and issuer signature. These fields are base64-encoded and separated by two CRLF sequences.

Parameters:
cert - P2PWNCCert The client certificate.
Returns:
String The resulting CONN message.

parseCACKMsg

int parseCACKMsg(java.lang.String text)
Parses a CACK text message. A CACK message is the acknowledgement of a CONN message sent by a client to a service provider. This message contains a timestamp set by the service provider indicating the time beginning of the session. This timestamp will be the same in the subsequent RCPT messages sent by the client to refresh the session. A CACK message contains the following fields:
FieldDescription
Message TypeCACK
Content-lengthLength of the message in octets
TimestampThe session timestamp (in RFC822 format).

Parameters:
text - String The CACK text message to be parsed.
Returns:
int The timestamp as the number of seconds since the Epoch.

parseRREQMsg

P2PWNCRREQMsgInfo parseRREQMsg(java.lang.String text)
Parses an RREQ text message. An RREQ message is periodically sent to the client by the service provider and is a request that the client sents back a signed receipt acknowledging that she has consumed a specific amount of service ("weight", measured in bytes). Thus, an RREQ message contains the receipt "weight". It also contains the service provider's public key, which will be stored by the client when she first receives an RREQ message. RREQ message fields are shown in the following table:
FieldDescription
Message TypeRREQ
Content-lengthLength of the message in octets
AlgorithmAlgorithm identifier and bit length of the provider's public key (for example RSA1024)
WeightCurrent session traffic (in bytes, as measured by the provider)
Service provider public keyThis field is the base64 encoded public key of the service provider

Parameters:
text - String The RREQ text message to be parsed.
Returns:
P2PWNCRREQMsgInfo The result of the parsing operation. The returned P2PWNCRREQMsgInfo object contains the extracted provider public key and the value of the weight field of the message.

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException
Throws:
java.io.IOException