summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/satellitedaemon/util/GetFtpCredentials.java
diff options
context:
space:
mode:
authorMichael Petretti2014-05-08 13:30:30 +0200
committerMichael Petretti2014-05-08 13:30:30 +0200
commitb7e8b0af8f761b9fe501ba210d1c24c863e418fe (patch)
treeb511b878dc98ac10f6f36bce756d78b58d3cfb45 /src/main/java/org/openslx/satellitedaemon/util/GetFtpCredentials.java
parentsmall change (diff)
downloadsatellite-daemon-b7e8b0af8f761b9fe501ba210d1c24c863e418fe.tar.gz
satellite-daemon-b7e8b0af8f761b9fe501ba210d1c24c863e418fe.tar.xz
satellite-daemon-b7e8b0af8f761b9fe501ba210d1c24c863e418fe.zip
Making it look more pretty.
Diffstat (limited to 'src/main/java/org/openslx/satellitedaemon/util/GetFtpCredentials.java')
-rw-r--r--src/main/java/org/openslx/satellitedaemon/util/GetFtpCredentials.java92
1 files changed, 92 insertions, 0 deletions
diff --git a/src/main/java/org/openslx/satellitedaemon/util/GetFtpCredentials.java b/src/main/java/org/openslx/satellitedaemon/util/GetFtpCredentials.java
new file mode 100644
index 0000000..27fea93
--- /dev/null
+++ b/src/main/java/org/openslx/satellitedaemon/util/GetFtpCredentials.java
@@ -0,0 +1,92 @@
+package org.openslx.satellitedaemon.util;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.security.InvalidKeyException;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.SignatureException;
+import java.security.UnrecoverableKeyException;
+import java.security.cert.CertificateException;
+import java.util.UUID;
+
+import org.apache.thrift.TException;
+import org.apache.thrift.protocol.TBinaryProtocol;
+import org.apache.thrift.protocol.TProtocol;
+import org.apache.thrift.transport.TSocket;
+import org.apache.thrift.transport.TTransport;
+import org.openslx.imagemaster.thrift.iface.FtpCredentials;
+import org.openslx.imagemaster.thrift.iface.ImageData;
+import org.openslx.imagemaster.thrift.iface.ImageServer;
+import org.openslx.imagemaster.thrift.iface.ServerSessionData;
+
+public class GetFtpCredentials
+{
+ private static FtpCredentials ftpc = null;
+ // TODO: All of the Strings and int's should not fall from sky.
+ static String nilsIp = "132.230.4.23";
+ static int thriftPort = 9090;
+
+ /**
+ * Handles the authentication with the Satellite Server and sends the FtpCredentials, which
+ * are necessary for the upload of the image.
+ */
+ static {
+ try {
+ TTransport transport;
+ transport = new TSocket( nilsIp, thriftPort ); // Nils IP
+ transport.open();
+ TProtocol protocol = new TBinaryProtocol( transport );
+
+ ImageServer.Client client = new ImageServer.Client( protocol );
+ String toEncrypt = client.startServerAuthentication( "uni-freiburg.de" );
+ // System.out.println( toEncrypt );
+ EncryptWithServerIdPublicKey rse = new EncryptWithServerIdPublicKey( "serverid", "password",
+ "/home/michael/satellite-daemon/config/serverid.jks" );
+ byte[] byteArray = rse.encryptString( toEncrypt );
+ ServerSessionData sSD = client.serverAuthenticate(
+ "uni-freiburg.de", ByteBuffer.wrap( byteArray ) );
+
+ // TODO: Should be able to get the necessary strings ect. from the DB.
+ ImageData imDat = new ImageData( UUID.randomUUID().toString(), 113,
+ "TestImage", System.currentTimeMillis(), System.currentTimeMillis(), "me", "anyThing",
+ true, false, "theBest", "theVeryBest", 1024 );
+
+ ftpc = client.submitImage( sSD.sessionId, imDat );
+
+ transport.close();
+ } catch ( TException x ) {
+ x.printStackTrace();
+ } catch ( InvalidKeyException e ) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch ( NoSuchAlgorithmException e ) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch ( SignatureException e ) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch ( UnrecoverableKeyException e ) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch ( CertificateException e ) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch ( FileNotFoundException e ) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch ( KeyStoreException e ) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch ( IOException e ) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ public static FtpCredentials now()
+ {
+ return ftpc;
+ }
+}