ecash.internet
Class ECashGen

java.lang.Object
  |
  +--ecash.internet.ECashGen
Direct Known Subclasses:
ECashBank, ECashBuyer, ECashSeller

public class ECashGen
extends java.lang.Object

Generic class for ECashBank, ECashBuyer and ECashSeller.

Author:
Michel Deriaz
See Also:
ECashBank, ECashBuyer, ECashSeller

Field Summary
static int BANK_PORT
          This constant defines on which port the bank is waiting for requests.
static int CHEAT_AMOUNTS_NOT_ALL_THE_SAME
          This code, used locally in reports or as function returned value, indicates that the amounts of the revealed notes are not all the same.
static int CHEAT_NOTE_REUSED_BY_BUYER
          This code, used locally in reports or as function returned value, indicates that the buyer re-used twice the same note.
static int CHEAT_NOTE_REUSED_BY_SELLER
          This code, used locally in reports or as function returned value, indicates that the seller re-used twice the same note.
static int CHEAT_WRONG_PASSWORD
          This code, used locally in reports or as function returned value, indicates that the password (or the bank account) is not correct.
static int CHEAT_WRONG_REVEALED_NOTES
          This code, used locally in reports or as function returned value, indicates that the revealed notes are not correct.
static int CHEAT_WRONG_RIS
          This code, used locally in reports or as function returned value, indicates that the RIS is not correct.
static int CHEAT_WRONG_SIGNATURE
          This code, used locally in reports or as function returned value, indicates that the signature is not correct (or that the signed part doesn't correspond to the unsigned one).
static int CONNECTION_CLOSED_BY_SERVER
          This code, used locally in reports or as function returned value, indicates that the connection was closed by the server.
static int KEY_NOT_AVAILABLE
          This code, used locally in reports or as function returned value, indicates that the public key is not available.
static int NOTES_EXP_SYNTAX_ERROR
          This code, used locally in reports or as function returned value, indicates that the notes expression carries one or several syntax errors.
static int NOTES_NOT_AVAILABLE
          This code, used locally in reports or as function returned value, indicates that the requested notes (for example during a paying operation) are not availables.
static int OK
          This code, used locally in reports or as function returned value, indicates that the operation (buy, deposit, ...) was correct and no cheating has been detected (like re-using a note twice, wrong signature, ...).
static java.lang.String OP_BUY
          This code, transmitted through the network, informs the partner of the current operation: The sender wants to buy some notes.
static java.lang.String OP_DEPOSIT
          This code, transmitted through the network, informs the partner of the current operation: The sender wants to deposit some notes at the bank.
static java.lang.String OP_GET_KEY
          This code, transmitted through the network, informs the partner of the current operation: The sender wants the public key of the bank.
static java.lang.String OP_PAY
          This code, transmitted through the network, informs the partner of the current operation: The sender wants to give some notes to the seller.
static int SELLER_PORT
          This constant defines on which port the seller is waiting for requests.
static int SERVER_NOT_READY
          This code, used locally in reports or as function returned value, indicates that the server (bank or seller) is not ready yet.
static java.lang.String TRANS_OK
          This code, transmitted through the network, informs the partner that the last set of transactions was successful.
 
Method Summary
 boolean checkIfNotesAvailable(java.util.Vector notesExpItems, java.util.Vector amountList)
          Returns true if the amounts list contains all the notes found in the notes expression items list, false otherwise.
 void close()
          Closes the socket.
 PubKey getKey()
          Returns the public key of the bank.
 int getKey(java.lang.String bankAddress)
          Connects to the bank and asks its public key.
 java.lang.String getREGEXP()
          Returns the regular expression that is used to define the syntax of the notes expression.
 boolean handshakeClient(java.lang.String serverAddress, int port)
          Connects to a server and constructs a secure crypted channel to it.
 boolean handshakeServer(int port)
          Connects to a client and constructs a secure crypted channel to it.
 boolean hasBankKey()
          Returns true if the public key is available, false otherwise.
 java.lang.String receiveCrypted()
          Receives a message from a secured crypted channel.
 void sendCrypted(char[] message)
          Sends a array of char, likely a password, over a secured crypted channel.
 void sendCrypted(java.lang.String message)
          Sends a message over a secured crypted channel.
 void setKey(PubKey pubKey)
          Sets the public key.
 void stopServer()
          Stops the server.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OP_BUY

public static final java.lang.String OP_BUY
This code, transmitted through the network, informs the partner of the current operation: The sender wants to buy some notes.

See Also:
Constant Field Values

OP_PAY

public static final java.lang.String OP_PAY
This code, transmitted through the network, informs the partner of the current operation: The sender wants to give some notes to the seller.

See Also:
Constant Field Values

OP_DEPOSIT

public static final java.lang.String OP_DEPOSIT
This code, transmitted through the network, informs the partner of the current operation: The sender wants to deposit some notes at the bank.

See Also:
Constant Field Values

OP_GET_KEY

public static final java.lang.String OP_GET_KEY
This code, transmitted through the network, informs the partner of the current operation: The sender wants the public key of the bank.

See Also:
Constant Field Values

TRANS_OK

public static final java.lang.String TRANS_OK
This code, transmitted through the network, informs the partner that the last set of transactions was successful.

See Also:
Constant Field Values

OK

public static final int OK
This code, used locally in reports or as function returned value, indicates that the operation (buy, deposit, ...) was correct and no cheating has been detected (like re-using a note twice, wrong signature, ...).

See Also:
Constant Field Values

CHEAT_WRONG_PASSWORD

public static final int CHEAT_WRONG_PASSWORD
This code, used locally in reports or as function returned value, indicates that the password (or the bank account) is not correct.

See Also:
Constant Field Values

CHEAT_AMOUNTS_NOT_ALL_THE_SAME

public static final int CHEAT_AMOUNTS_NOT_ALL_THE_SAME
This code, used locally in reports or as function returned value, indicates that the amounts of the revealed notes are not all the same. This can occur when a client tries to make the bank sign a note with a bigger amount than revealed in the other notes.

See Also:
Constant Field Values

CHEAT_WRONG_REVEALED_NOTES

public static final int CHEAT_WRONG_REVEALED_NOTES
This code, used locally in reports or as function returned value, indicates that the revealed notes are not correct.

See Also:
Constant Field Values

CHEAT_WRONG_SIGNATURE

public static final int CHEAT_WRONG_SIGNATURE
This code, used locally in reports or as function returned value, indicates that the signature is not correct (or that the signed part doesn't correspond to the unsigned one).

See Also:
Constant Field Values

CHEAT_WRONG_RIS

public static final int CHEAT_WRONG_RIS
This code, used locally in reports or as function returned value, indicates that the RIS is not correct.

See Also:
Constant Field Values

CHEAT_NOTE_REUSED_BY_SELLER

public static final int CHEAT_NOTE_REUSED_BY_SELLER
This code, used locally in reports or as function returned value, indicates that the seller re-used twice the same note. This occurs when the bank get twice the same note with the same RIS.

See Also:
Constant Field Values

CHEAT_NOTE_REUSED_BY_BUYER

public static final int CHEAT_NOTE_REUSED_BY_BUYER
This code, used locally in reports or as function returned value, indicates that the buyer re-used twice the same note. This occurs when the bank get twice the same note but with differents valids RIS.

See Also:
Constant Field Values

CONNECTION_CLOSED_BY_SERVER

public static final int CONNECTION_CLOSED_BY_SERVER
This code, used locally in reports or as function returned value, indicates that the connection was closed by the server. This can append either because of a technical problem, or because the client cheats. The term "cheat" covers unvoluntary cheating, like providing a wrong password or a wrong account number, or voluntary cheating, like re-using several time the same note.

See Also:
Constant Field Values

SERVER_NOT_READY

public static final int SERVER_NOT_READY
This code, used locally in reports or as function returned value, indicates that the server (bank or seller) is not ready yet. One reason could simply be that the server is already in connection with someone else.

See Also:
Constant Field Values

KEY_NOT_AVAILABLE

public static final int KEY_NOT_AVAILABLE
This code, used locally in reports or as function returned value, indicates that the public key is not available.

See Also:
Constant Field Values

NOTES_EXP_SYNTAX_ERROR

public static final int NOTES_EXP_SYNTAX_ERROR
This code, used locally in reports or as function returned value, indicates that the notes expression carries one or several syntax errors.

See Also:
Constant Field Values

NOTES_NOT_AVAILABLE

public static final int NOTES_NOT_AVAILABLE
This code, used locally in reports or as function returned value, indicates that the requested notes (for example during a paying operation) are not availables.

See Also:
Constant Field Values

BANK_PORT

public static final int BANK_PORT
This constant defines on which port the bank is waiting for requests.

See Also:
Constant Field Values

SELLER_PORT

public static final int SELLER_PORT
This constant defines on which port the seller is waiting for requests.

See Also:
Constant Field Values
Method Detail

hasBankKey

public boolean hasBankKey()
Returns true if the public key is available, false otherwise.

Returns:
a boolean indicating whether the public key is available or not

getKey

public PubKey getKey()
Returns the public key of the bank.

Returns:
the public key of the bank

getKey

public int getKey(java.lang.String bankAddress)
Connects to the bank and asks its public key. Returns a code that indicate how the operation succeeded. The code can be
ECashGen.OK,
ECashGen.SERVER_NOT_READY or
ECashGen.KEY_NOT_AVAILABLE.

Parameters:
bankAddress - the address of the bank, for example "123.123.33.123"
Returns:
an integer describing the success of the operation

setKey

public void setKey(PubKey pubKey)
Sets the public key.

Parameters:
pubKey - the public key

getREGEXP

public java.lang.String getREGEXP()
Returns the regular expression that is used to define the syntax of the notes expression. It can be used to control users inputs.

Returns:
the regular expression defining the syntax of a notes expressions

stopServer

public void stopServer()
Stops the server. This method can be used by the bank or a seller to avoid any connection from clientxs


checkIfNotesAvailable

public boolean checkIfNotesAvailable(java.util.Vector notesExpItems,
                                     java.util.Vector amountList)
Returns true if the amounts list contains all the notes found in the notes expression items list, false otherwise. The amount list is a vector of String, and each item is an amount of an available note. The notes expression items vector is also a vector of String, and can be considered as a splitted notes expression.
Warning: The amounts list will be modified by this method.

Parameters:
notesExpItems - a vector of String that represents a splitted notes expression
Returns:
a boolean indicating whether the requested notes are availables or not

handshakeClient

public boolean handshakeClient(java.lang.String serverAddress,
                               int port)
Connects to a server and constructs a secure crypted channel to it. Returns true if the operation succeed, false otherwise.

Parameters:
serverAddress - the address of the server
port - the port of the server
Returns:
a boolean indicating whether the operation succeeded or not

handshakeServer

public boolean handshakeServer(int port)
Connects to a client and constructs a secure crypted channel to it. Returns true if the operation succeed, false otherwise.

Parameters:
port - the port of the server
Returns:
a boolean indicating whether the operation succeeded or not

sendCrypted

public void sendCrypted(java.lang.String message)
Sends a message over a secured crypted channel. The handshakeClient() or the handshakeServer() methods can be used to set up such a channel.

Parameters:
message - the message to crypt and to send
See Also:
handshakeClient(java.lang.String, int), handshakeServer(int)

sendCrypted

public void sendCrypted(char[] message)
Sends a array of char, likely a password, over a secured crypted channel. The handshakeClient() or the handshakeServer() methods can be used to set up such a channel.

Parameters:
message - the message to crypt and to send
See Also:
handshakeClient(java.lang.String, int), handshakeServer(int)

receiveCrypted

public java.lang.String receiveCrypted()
Receives a message from a secured crypted channel. The handshakeClient() or the handshakeServer() methods can be used to set up such a channel.
Note: This method will block until an input is available.

Returns:
the message, as a plaintext
See Also:
handshakeClient(java.lang.String, int), handshakeServer(int)

close

public void close()
Closes the socket.