From 91d32290d336e615e2d8ef7f009e753e146136bb Mon Sep 17 00:00:00 2001 From: Björn Hagemeister Date: Tue, 11 Nov 2014 14:11:52 +0100 Subject: Implemented possible connection to master server via proxy server. Currently proxy server is found by DNS searching. --- src/main/java/org/openslx/satellitedaemon/App.java | 60 +++++++++++++++++++++- 1 file changed, 58 insertions(+), 2 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 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(); -- cgit v1.2.3-55-g7522