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.

import <strong>Spam</strong>Cash.Utilities.Debugger;<br />

import <strong>Spam</strong>Cash.Servers.AbstractServer;<br />

import java.util.Vector;<br />

import java.security.cert.*;<br />

import java.util.Random;<br />

import java.net.Socket;<br />

import java.net.InetAddress;<br />

import java.io.*;<br />

import java.security.interfaces.*;<br />

import org.logi.crypto.keys.RSABlindingFactor;<br />

public class CurrencyExchangeServer extends AbstractServer<br />

{<br />

private RSAPublicKey RSPublicKey, BLSPublicKey;<br />

private Certificate certificate, BLSCert;<br />

private Vector usedCoinSerials, usedCoins;<br />

private static Accounts accounts;<br />

private File file;<br />

private CESConfiguration config;<br />

private Vector coinSets;<br />

public CurrencyExchangeServer() throws Exception<br />

{<br />

super(Config.CESCertificateName, Config.CESPrivateKeyName, Config.CESPort);<br />

org.logi.crypto.Crypto.initRandom();<br />

file = new File(Config.CESConfigFilePath);<br />

if(!file.exists())<br />

{<br />

Debugger.debug(getClass(), 1, "Creating server data.");<br />

usedCoinSerials = new Vector();<br />

usedCoins = new Vector();<br />

coinSets = new Vector();<br />

accounts = new Accounts(new BankAccount("Bent", "Bent01", 100));<br />

accounts.addAccount(new BankAccount("Santa", "Claus", 40000));<br />

accounts.addAccount(new BankAccount("user1", "user1", 40000));<br />

accounts.addAccount(new BankAccount("user2", "user2", 40000));<br />

accounts.addAccount(new BankAccount("Anders", "And", 3));<br />

accounts.addAccount(new BankAccount("test", "test", 12000));<br />

}<br />

else<br />

{<br />

Debugger.debug(getClass(), 1, "Reading server data from file.");<br />

config = (CESConfiguration) FileHandler.readObject(file);<br />

usedCoinSerials = config.usedCoinSerials;<br />

usedCoins = config.usedCoins;<br />

coinSets = config.coinSets;<br />

accounts = config.accounts;<br />

}<br />

RSPublicKey = (RSAPublicKey) FileHandler.importCertificate(new<br />

File(Config.RSCertificateName)).getPublicKey();<br />

BLSCert = FileHandler.importCertificate(new File(Config.BLSCertificateName));<br />

BLSPublicKey = (RSAPublicKey) BLSCert.getPublicKey();<br />

}<br />

certificate = FileHandler.importCertificate(new File(Config.CESCertificateName));<br />

protected void printStatus()<br />

{<br />

Debugger.debug(getClass(), 1, "Status:\n" + accounts.toString());<br />

}<br />

public static void main(String[] args)<br />

{<br />

try<br />

{<br />

347

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

Saved successfully!

Ooh no, something went wrong!