From 741e5d5fd03f5530ba116e9d1909d5888e470a7e Mon Sep 17 00:00:00 2001 From: Michael Petretti Date: Wed, 7 May 2014 17:53:03 +0200 Subject: small change --- src/main/java/org/openslx/satellitedaemon/App.java | 62 +++++++++++++++++----- 1 file changed, 49 insertions(+), 13 deletions(-) (limited to 'src/main/java/org/openslx/satellitedaemon/App.java') diff --git a/src/main/java/org/openslx/satellitedaemon/App.java b/src/main/java/org/openslx/satellitedaemon/App.java index 9eb1cd6..9f42623 100644 --- a/src/main/java/org/openslx/satellitedaemon/App.java +++ b/src/main/java/org/openslx/satellitedaemon/App.java @@ -1,9 +1,13 @@ package org.openslx.satellitedaemon; +import java.io.File; +import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; +import java.net.ConnectException; import java.nio.ByteBuffer; import java.security.InvalidKeyException; +import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.SignatureException; @@ -11,6 +15,11 @@ import java.security.UnrecoverableKeyException; import java.security.cert.CertificateException; import java.util.UUID; +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.TrustManager; +import javax.net.ssl.TrustManagerFactory; + +import org.apache.commons.net.ftp.FTPSClient; import org.apache.thrift.TException; import org.apache.thrift.protocol.TBinaryProtocol; import org.apache.thrift.protocol.TProtocol; @@ -27,28 +36,55 @@ import org.openslx.satellitedaemon.util.RndStringEncrypt; * */ public class App { - public static void main(String[] args) throws UnrecoverableKeyException, NoSuchAlgorithmException, CertificateException, FileNotFoundException, KeyStoreException, IOException, InvalidKeyException, SignatureException { + public static void main(String[] args) throws UnrecoverableKeyException, + NoSuchAlgorithmException, CertificateException, + FileNotFoundException, KeyStoreException, IOException, + InvalidKeyException, SignatureException { + String nilsIp = "132.230.4.23"; + int thriftPort = 9090; + int ftpPort = 2221; try { TTransport transport; - transport = new TSocket("132.230.4.23", 9090); //Nils IP + transport = new TSocket(nilsIp, thriftPort); // Nils IP transport.open(); TProtocol protocol = new TBinaryProtocol(transport); - ImageServer.Client client = new ImageServer.Client( - protocol); + ImageServer.Client client = new ImageServer.Client(protocol); String rnd = client.startServerAuthentication("uni-freiburg.de"); - System.out.println(rnd); - - RndStringEncrypt rse = new RndStringEncrypt("serverid", "password", "/home/michael/satellite-daemon/config/serverid.jks"); + System.out.println(rnd); + + RndStringEncrypt rse = new RndStringEncrypt("serverid", "password", + "/home/michael/satellite-daemon/config/serverid.jks"); byte[] byteArray = rse.encryptRndString(rnd); - ServerSessionData sSD = client.serverAuthenticate("uni-freiburg.de", ByteBuffer.wrap(byteArray)); - System.out.println(sSD.sessionId); - ImageData imDat = new ImageData(UUID.randomUUID().toString(), 113, "TestImage", 100, 105, "me", "anyThing", true, false, "theBest", "theVeryBest", 1024 ); - FtpCredentials ftpc = client.submitImage(sSD.sessionId, imDat); - - transport.close(); + ServerSessionData sSD = client.serverAuthenticate( + "uni-freiburg.de", ByteBuffer.wrap(byteArray)); + System.out.println(sSD.sessionId); + ImageData imDat = new ImageData(UUID.randomUUID().toString(), 113, + "TestImage", System.currentTimeMillis(), System.currentTimeMillis(), "me", "anyThing", true, false, + "theBest", "theVeryBest", 1024); + FtpCredentials ftpc = client.submitImage(sSD.sessionId, imDat); + FTPSClient ftpClient = new FTPSClient("SSL", true); + TrustManagerFactory trustManagerFactory = TrustManagerFactory + .getInstance(KeyManagerFactory.getDefaultAlgorithm()); + KeyStore keystore = KeyStore.getInstance("JKS"); + keystore.load(new FileInputStream(new File( + "/home/michael/satellite-daemon/config/ftpsid.jks")), + "password".toCharArray()); + trustManagerFactory.init(keystore); + TrustManager trustManager = trustManagerFactory.getTrustManagers()[0]; + ftpClient.setTrustManager(trustManager); + try { + ftpClient.connect( nilsIp, ftpPort ); + if (!ftpClient.login(ftpc.username, ftpc.password)) { + throw new ConnectException("Could not login."); + } + System.out.println( "Connected to " + nilsIp + ":" + ftpPort + ". Reply code: " + ftpClient.getReplyCode() ); + } finally { + ftpClient.disconnect(); + } + transport.close(); } catch (TException x) { x.printStackTrace(); } -- cgit v1.2.3-55-g7522