29.07.2013 Views

Master of Science thesis Fighting Spam

Master of Science thesis Fighting Spam

Master of Science thesis Fighting Spam

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

public CurrencyExchangeClient() throws Exception<br />

{<br />

CESCertificate = FileHandler.importCertificate(new<br />

File(Config.CESCertificateName));<br />

BLSCertificate = FileHandler.importCertificate(new<br />

File(Config.BLSCertificateName));<br />

}<br />

/**<br />

* Method to start a currencyExchange with the server<br />

* @param username String<br />

* @param password String<br />

* @throws Exception An exception is thrown when the connection encounters problems<br />

*/<br />

public boolean logonToCurrencyServer(String username, String password) throws<br />

Exception<br />

{<br />

StatusPacket pack = logon(username, password);<br />

if(pack.ok)<br />

{<br />

this.username = username;<br />

this.password = password;<br />

}<br />

else<br />

throw new Exception(pack.message);<br />

return pack.ok;<br />

}<br />

private StatusPacket logon(String username, String password) throws Exception<br />

{<br />

//If a valid session does not exist..create one.<br />

checkSession();<br />

}<br />

//logon<br />

serverSession.send(new LogonPacket(username, password));<br />

StatusPacket responsePacket = (StatusPacket) serverSession.receive();<br />

return responsePacket;<br />

private void checkSession() throws Exception<br />

{<br />

if(serverSession == null || serverSession.closed)<br />

{<br />

createSession();<br />

}<br />

}<br />

private void createSession() throws Exception<br />

{<br />

Debugger.debug(getClass(), 3, "Creating new session with the CES: " +<br />

Config.CESAddress + ":" + Config.CESPort);<br />

Socket socket = new Socket(InetAddress.getByName(Config.CESAddress),<br />

Config.CESPort);<br />

serverSession = new session(socket, false, (RSAPublicKey)<br />

CESCertificate.getPublicKey(),true);<br />

}<br />

public Coin[] withdraw(double amount, Certificate certificate) throws Exception<br />

{<br />

Debugger.debug(getClass(), 3, "Withdrawing "+amount+"...");<br />

int necessaryCoins = necessaryCoins(amount);<br />

Coin[][] coins = generateCoins(necessaryCoins);<br />

checkSession();<br />

//Initialize blindingFactors and blind the coins<br />

RSABlindingFactor[][] blindingFactors = new<br />

RSABlindingFactor[coins.length][coins[0].length];<br />

BlindedCoin[][] blindedCoins = new BlindedCoin[coins.length][coins[0].length];<br />

for(int i = 0; i < coins.length; i++)<br />

215

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!