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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Exception<br />

{<br />

Debugger.debug(getClass(), 1, "BlindFactors received... User: " + username);<br />

CoinSet coinset = null;<br />

boolean found = false;<br />

int i = 0;<br />

while(i < coinSets.size())<br />

{<br />

coinset = ((CoinSet) coinSets.elementAt(i));<br />

if(coinset.username.equals(username))<br />

{<br />

coinSets.remove(i);<br />

found = true;<br />

break;<br />

}<br />

i++;<br />

}<br />

//Not found?<br />

if(!found)<br />

{<br />

String error =<br />

"Username unknown. Probably a BlindingFactorPacket was sent before the<br />

corresponding CurrencyExchangePacket.";<br />

Debugger.debug(getClass(), 1, error);<br />

throw new Exception(error);<br />

}<br />

//Validate certificate<br />

try<br />

{<br />

Debugger.debug(getClass(), 1, "Verifying the certificate...");<br />

cp.certificate.verify(RSPublicKey);<br />

}<br />

catch(Exception e)<br />

{<br />

String error = "The certificate supplied is invalid. Verification <strong>of</strong> the RS<br />

signature failed.";<br />

Debugger.debug(getClass(), 1, error);<br />

throw new Exception(error);<br />

}<br />

Debugger.debug(getClass(), 1, "Certificate succesfully verified.");<br />

//Calculate the amount <strong>of</strong> the coins on the way<br />

boolean amountAddedForSet = false;<br />

double amount = 0.0;<br />

Debugger.debug(getClass(), 1, "Unblinding and verifying the coins....");<br />

//Check that all coins are the same (except the blinded one in each set).<br />

for(int c = 0; c < coinset.blindedCoins.length; c++)<br />

{<br />

amountAddedForSet = false;<br />

//This loop goes through the coins in each set<br />

//Since the sets MUST be the same size, the loop runs to coins[0].lenght and<br />

not coins[c].length<br />

for(int r = 0; r < coinset.blindedCoins[0].length; r++)<br />

{<br />

//Do we have a blindingfactor?<br />

if(r != coinset.blindingFactorIndexes[c])<br />

{<br />

Debugger.debug(getClass(), 1,<br />

"Verifying coin " + (1 + c *<br />

coinset.blindedCoins[0].length + r) + " <strong>of</strong> "<br />

+ (coinset.blindedCoins.length *<br />

coinset.blindedCoins[0].length) + "...");<br />

//Check the contents <strong>of</strong> the coin<br />

compareCoins(coinset.blindedCoins[c][r], cp.getRSABlindingFactor(c,<br />

r), cp.coins[c][r],<br />

cp.certificate);<br />

//Calculate the amount <strong>of</strong> all the coins<br />

if(!amountAddedForSet)<br />

351

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

Saved successfully!

Ooh no, something went wrong!