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.

}<br />

//pendingAccounts.aprove(pack.activationNumber);<br />

Debugger.debug(getClass(), 1, "Verifued signature <strong>of</strong> activationNumber = " +<br />

pack.activationNumber + ".");<br />

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

PendingAccount p = pendingAccounts.get(pack.activationNumber);<br />

createCertificate(pack.activationNumber, p.certificateSigningRequest);<br />

pendingAccounts.remove(p);<br />

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

"Certificate for activationNumber: " + pack.activationNumber +<br />

" Created successfully.");<br />

return;<br />

}<br />

catch(Exception e)<br />

{<br />

Debugger.debug(getClass(), 1, "Exception: ", e);<br />

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

"Error generating certificate.");<br />

return;<br />

}<br />

}<br />

public synchronized NetPacket activationRequest(RegistrationInfoPacket pack)<br />

{<br />

try<br />

{<br />

Debugger.debug(getClass(), 1, "Attempting to retrieve certificate");<br />

File generatedCert = new File(Config.OpenSSLpath + pack.activationNumber +<br />

".crt");<br />

Certificate certificate = FileHandler.importCertificate(generatedCert);<br />

Debugger.debug(getClass(), 1, "Certificate found, returning it in an<br />

ActivationCompletedPacket");<br />

return new ActivationCompletedPacket(certificate);<br />

}<br />

catch(Exception ex)<br />

{<br />

Debugger.debug(getClass(), 1, "Exception: ", ex);<br />

return new StatusPacket(false, "Error retrieving certificate " +<br />

ex.getMessage());<br />

}<br />

}<br />

public synchronized void createCertificate(long activationNumber, byte[]<br />

certificateSigningRequest) throws<br />

Exception<br />

{<br />

//String filesep = System.getProperty("file.separator");<br />

Debugger.debug(getClass(), 1, "Creating cerfiticate from received<br />

certificaterequest");<br />

Debugger.debug(getClass(), 1, "Writing certificaterequest to file");<br />

File certRequestFile = new File(Config.OpenSSLpath + "certificaterequest.csr");<br />

FileOutputStream fos = new FileOutputStream(certRequestFile);<br />

fos.write(certificateSigningRequest);<br />

fos.close();<br />

Runtime rt = Runtime.getRuntime();<br />

String command = "openssl ca -in " + Config.OpenSSLpath + "certificaterequest.csr<br />

-out " + Config.OpenSSLpath<br />

+ activationNumber + ".crt -notext -batch -key spammail";<br />

Debugger.debug(getClass(), 1, "Executing openssl command: " + command);<br />

Process process = rt.exec(command);<br />

File generatedCert = new File(Config.OpenSSLpath + activationNumber + ".crt");<br />

Debugger.debug(getClass(), 1, "Waiting for certificatefile to be created and<br />

proceed when it is.");<br />

int checks = 0;<br />

while(!generatedCert.exists() || generatedCert.length() == 0 ||<br />

!generatedCert.canRead())<br />

{<br />

if(checks >= 30)<br />

{<br />

356

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

Saved successfully!

Ooh no, something went wrong!