From c4b51e6fd2b7e0fc3531cb43064f64e9d0d0b74e Mon Sep 17 00:00:00 2001 From: Michael Petretti Date: Thu, 10 Jul 2014 16:48:49 +0200 Subject: Fixed a lot of TODOs and upload works. --- .../java/org/openslx/satellitedaemon/Globals.java | 90 +++++++++++++++++++++- 1 file changed, 87 insertions(+), 3 deletions(-) (limited to 'src/main/java/org/openslx/satellitedaemon/Globals.java') diff --git a/src/main/java/org/openslx/satellitedaemon/Globals.java b/src/main/java/org/openslx/satellitedaemon/Globals.java index 3bfd5cb..afcb3c6 100644 --- a/src/main/java/org/openslx/satellitedaemon/Globals.java +++ b/src/main/java/org/openslx/satellitedaemon/Globals.java @@ -2,15 +2,29 @@ package org.openslx.satellitedaemon; import java.io.BufferedInputStream; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; +import java.security.KeyManagementException; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateException; import java.util.Properties; +import javax.net.ssl.SSLContext; +import javax.net.ssl.TrustManager; +import javax.net.ssl.TrustManagerFactory; + +import org.apache.log4j.Logger; + public class Globals { + private static Logger log = Logger.getLogger( Globals.class ); private static final Properties properties = new Properties(); private static boolean loadedProperties = false; + private static SSLContext context = null; - /** + /*********************************************************************************************** * If there are more ints or Strings which should be added to config/global.properties, * add to suiting enum, add a 'case' to getPropertyInt/String() and add checks to * propertiesValid(). @@ -20,7 +34,7 @@ public class Globals */ public static enum PropInt { - FTPPORT, THRIFTPORT // More int's? Add them separated with "," + FTPPORT, THRIFTPORT, BLOCKSIZE // More int's? Add them separated with "," } public static enum PropString @@ -29,6 +43,11 @@ public class Globals RNDSTRINGENCRYPTALIAS, RNDSTRINGENCRYPTPASSWORD, RNDSTRINGENCRYPTPATH } + /*********************************************************************************************** + * + * @return + * @throws IOException + */ public static boolean loadProperties() throws IOException { if ( loadedProperties ) @@ -42,7 +61,11 @@ public class Globals return true; } - // Calling + /*********************************************************************************************** + * + * @param props + * @return + */ public static int getPropertyInt( Globals.PropInt props ) { String result = null; @@ -51,6 +74,9 @@ public class Globals case FTPPORT: result = properties.getProperty( "ftp_port" ); break; + case BLOCKSIZE: + result = properties.getProperty( "blockSize" ); + break; case THRIFTPORT: result = properties.getProperty( "ThriftPort" ); break; @@ -64,6 +90,11 @@ public class Globals return Integer.valueOf( result ); } + /*********************************************************************************************** + * + * @param props + * @return + */ public static String getPropertyString( Globals.PropString props ) { String result = null; @@ -100,9 +131,15 @@ public class Globals return result; } + // TODO: add real checks + /*********************************************************************************************** + * + * @return + */ public static boolean propertiesValid() { if ( Globals.getPropertyInt( PropInt.FTPPORT ) == 0 + || Globals.getPropertyInt( PropInt.BLOCKSIZE ) == 0 || Globals.getPropertyInt( PropInt.THRIFTPORT ) == 0 || Globals.getPropertyString( PropString.FTPSERVERIP ).isEmpty() || Globals.getPropertyString( PropString.FTPSERVERIP ) == null @@ -126,4 +163,51 @@ public class Globals return true; } } + + /*********************************************************************************************** + * + * @return + */ + public static boolean masterServerSslContextInit() + { + char[] passphrase = Globals.getPropertyString( PropString.FTPSKEYSTOREPWD ).toCharArray(); + KeyStore keystore; + try { + keystore = KeyStore.getInstance( "JKS" ); + keystore.load( new FileInputStream( Globals.getPropertyString( PropString.FTPSKEYSTOREPATH ) ), passphrase ); + TrustManagerFactory tmf = TrustManagerFactory.getInstance( TrustManagerFactory.getDefaultAlgorithm() ); + tmf.init( keystore ); + context = SSLContext.getInstance( "SSLv3" ); + TrustManager[] trustManagers = tmf.getTrustManagers(); + context.init( null, trustManagers, null ); + } catch ( KeyStoreException e ) { + log.error("KeyStoreException"); + return false; + } catch ( NoSuchAlgorithmException e ) { + log.error("NoSuchAlgorithmException"); + return false; + } catch ( CertificateException e ) { + log.error("CertificateException"); + return false; + } catch ( FileNotFoundException e ) { + log.error("FileNotFoundException"); + return false; + } catch ( IOException e ) { + log.error("IOException"); + return false; + } catch ( KeyManagementException e ) { + log.error("KeyManagementException"); + return false; + } + return true; + } + + + /*********************************************************************************************** + * + * @return + */ + public static SSLContext getMasterServerSslContext(){ + return Globals.context; + } } -- cgit v1.2.3-55-g7522