summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjörn Hagemeister2014-11-11 14:11:52 +0100
committerBjörn Hagemeister2014-11-11 14:11:52 +0100
commit91d32290d336e615e2d8ef7f009e753e146136bb (patch)
tree9ee96a1b70e5ba46f52c1d6a46e537849f252152
parentFixed several things for successful up and download of images after using all... (diff)
downloadsatellite-daemon-91d32290d336e615e2d8ef7f009e753e146136bb.tar.gz
satellite-daemon-91d32290d336e615e2d8ef7f009e753e146136bb.tar.xz
satellite-daemon-91d32290d336e615e2d8ef7f009e753e146136bb.zip
Implemented possible connection to master server via proxy server.
Currently proxy server is found by DNS searching.
-rw-r--r--config/global.properties.example43
-rw-r--r--pom.xml5
-rw-r--r--src/main/java/org/openslx/satellitedaemon/App.java60
-rw-r--r--src/main/java/org/openslx/satellitedaemon/Globals.java33
4 files changed, 130 insertions, 11 deletions
diff --git a/config/global.properties.example b/config/global.properties.example
index 2275e2b..4c009a6 100644
--- a/config/global.properties.example
+++ b/config/global.properties.example
@@ -1,15 +1,42 @@
# Example configuration file for the satellite-daemon
-
# hostname of the masterserver
-MASTERSERVER_HOST=132.230.4.17
+MASTERSERVER_HOST=111.111.4.12
+
+# the image folder where all up- and downloads are saved
+IMAGE_FOLDER=./images
+
+# the keystore that is used for the filetransfer
+TRUSTSTORE_PATH=./config/trust.jks
+
+# type of the keystore???
+KEYSTORE_TYPE=jks
-# the truststore that is used to validate the certificate of the server
-# leave blank to use system's cacert store
-TRUSTSTORE_PATH=/path/to/truststore.jks
+# the password of the keystore above
+FILETRANSFER_KEYSTORE_PASSWORD=password
-# port to which the thrift connection is opened (usually this is 9090)
+# the alias of the keystore for the secure thrift connection
+THRIFT_KEYSTORE_ALIAS=alias
+
+# it's password
+THRIFT_KEYSTORE_PASSWORD=password
+
+# and it's path
+THRIFT_KEYSTORE_PATH=./config/satellite.jks
+
+# port where the thrift connection is opened (usually this is 9191)
THRIFT_PORT=9090
-# the image folder where all up- and downloads are saved
-IMAGE_FOLDER=/path/to/images
+# proxy configuration:
+# 3 options for proxy configuration: AUTO = autmatically, YES, NO. If nothing is
+# set, the default automatically will be choosen.
+PROXY_CONF=AUTO
+# If PROXY_CONF = YES some more information for connection are necessary:
+# PROXY_ADDR = destination addres
+PROXY_ADDR=1.2.3.4
+
+# PROXY_PORT = port for proxy connection
+PROXY_PORT=1080
+# Username and password are optional, if empty, it is assumed that not necessary:
+PROXY_USERNAME=test
+PROXY_PASSWORD=password
diff --git a/pom.xml b/pom.xml
index b9c6d45..cf842c7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -114,5 +114,10 @@
<version>1.0.6</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>com.googlecode.vestige</groupId>
+ <artifactId>proxy_vole</artifactId>
+ <version>0.0.3-SNAPSHOT</version>
+ </dependency>
</dependencies>
</project>
diff --git a/src/main/java/org/openslx/satellitedaemon/App.java b/src/main/java/org/openslx/satellitedaemon/App.java
index 4a6bb7b..e43c9a1 100644
--- a/src/main/java/org/openslx/satellitedaemon/App.java
+++ b/src/main/java/org/openslx/satellitedaemon/App.java
@@ -1,16 +1,24 @@
package org.openslx.satellitedaemon;
import java.math.BigInteger;
+import java.net.Authenticator;
+import java.net.InetSocketAddress;
+import java.net.Proxy;
+import java.net.ProxySelector;
import java.security.NoSuchAlgorithmException;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
-import java.util.Random;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
+import org.openslx.network.StaticProxyAuthenticator;
+import org.openslx.network.StaticProxySelector;
import org.openslx.satellitedaemon.filetransfer.FileDownloadWorker;
import org.openslx.satellitedaemon.filetransfer.FileUploadWorker;
+import com.btr.proxy.search.wpad.WpadProxySearchStrategy;
+import com.btr.proxy.util.ProxyException;
+
/***********************************************************************************************/
/**
* Main class for uploading images from the HS-Server to the Satellite Server.
@@ -102,15 +110,63 @@ public class App
}
} else if ( args.length == 0 ) {
// No Option choosed, try to load existing identity.
+
if ( !tryLoadIdentity() ) {
System.exit( 2 );
}
}
-
+
if ( !Globals.masterServerSslContextInit() ) {
log.error( "Problem with initializing the SSLContext" );
System.exit( 1 );
}
+
+ log.info( "Configure proxy settings ..." );
+ // Configuring proxy settings. First read options from config file.
+ String proxyConfiguration = Globals.getProxyConf();
+ if ((proxyConfiguration.equals( "AUTO")) || (proxyConfiguration.equals( "" ))) {
+ log.info( "Configuring proxy settings automatically..." );
+ // Configuring proxy settings automatically.
+ WpadProxySearchStrategy wPSS = new WpadProxySearchStrategy();
+ try {
+ ProxySelector pS = wPSS.getProxySelector();
+ ProxySelector.setDefault(pS);
+ } catch (ProxyException e) {
+ log.error( "Setting proxy configuration automatically failed.", e );
+ }
+ } else if (proxyConfiguration.equals( "YES" )) {
+ // Take the proxy settings from config file.
+ // First check if one of the following necessary options might not be set.
+ if (Globals.checkProxySettings()) {
+ String proxyAddress = Globals.getProxyAddress();
+ int proxyPort = Globals.getProxyPort();
+ if (Globals.getProxyUsername().equals( "" ) || Globals.getProxyPassword().equals("")) {
+ log.info( "Configuring proxy settings manually without authentication..." );
+ // use Proxy without authentication.
+ Proxy proxy = new Proxy( Proxy.Type.SOCKS, new InetSocketAddress( proxyAddress, proxyPort ) );
+
+ StaticProxySelector sPS = new StaticProxySelector(proxy);
+ ProxySelector.setDefault( sPS );
+ } else {
+ log.info( "Configuring proxy settings manually with authentication..." );
+ // Use proxy with authentication.
+ String proxyUname = Globals.getProxyUsername();
+ String proxyPass = Globals.getProxyPassword();
+
+ Proxy proxy = new Proxy( Proxy.Type.SOCKS, new InetSocketAddress( proxyAddress, proxyPort ) );
+
+ StaticProxySelector sPS = new StaticProxySelector( proxy );
+ ProxySelector.setDefault( sPS );
+
+ // Set authentication.
+ StaticProxyAuthenticator sPA = new StaticProxyAuthenticator( proxyUname, proxyPass );
+ Authenticator.setDefault( sPA );
+ }
+ }
+ }
+ log.info( "... proxy settings are done." );
+
+
// Start Up- and Download.
Thread uploadWorker = new Thread( new FileUploadWorker() );
uploadWorker.start();
diff --git a/src/main/java/org/openslx/satellitedaemon/Globals.java b/src/main/java/org/openslx/satellitedaemon/Globals.java
index 0b0d287..d75459b 100644
--- a/src/main/java/org/openslx/satellitedaemon/Globals.java
+++ b/src/main/java/org/openslx/satellitedaemon/Globals.java
@@ -50,6 +50,26 @@ public class Globals
{
return properties.getProperty( "IMAGE_FOLDER" );
}
+
+ public static String getProxyConf()
+ {
+ return properties.getProperty( "PROXY_CONF" );
+ }
+
+ public static String getProxyAddress()
+ {
+ return properties.getProperty( "PROXY_ADDR" );
+ }
+
+ public static String getProxyUsername()
+ {
+ return properties.getProperty( "PROXY_USERNAME" );
+ }
+
+ public static String getProxyPassword()
+ {
+ return properties.getProperty( "PROXY_PASSWORD" );
+ }
// Integers //
@@ -58,6 +78,11 @@ public class Globals
return tryToParseInt( properties.getProperty( "THRIFT_PORT" ) );
}
+ public static int getProxyPort()
+ {
+ return tryToParseInt( properties.getProperty( "PROXY_PORT" ) );
+ }
+
/**
* Load properties
*/
@@ -129,7 +154,7 @@ public class Globals
* Tries to parse an int. Returns 0 on error.
*
* @param s
- * The strig to parse
+ * The string to parse
* @return The parsed int or 0 on error
*/
public static int tryToParseInt( String s )
@@ -140,4 +165,10 @@ public class Globals
return 0;
}
}
+
+ public static boolean checkProxySettings() {
+ return (
+ (getProxyAddress() != "") &&
+ (getProxyPort() != 0));
+ }
}