Remove trailing whitespace
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / core / SslContextFactory.java
index 8deb4aa07240d1f4c53d0e5d15382e2eb93436ba..b2c5a199f53d9f2da23c873d6fc1a2ede6f6db5c 100644 (file)
@@ -19,14 +19,12 @@ import javax.net.ssl.SSLContext;
 import javax.net.ssl.TrustManagerFactory;
 
 import org.opendaylight.openflowjava.protocol.api.connection.TlsConfiguration;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.KeystoreType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.PathType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
  * Class for setting up TLS connection.
- * 
+ *
  * @author michal.polkorab
  */
 public class SslContextFactory {
@@ -34,12 +32,7 @@ public class SslContextFactory {
     // "TLS" - supports some version of TLS
     // Use "TLSv1", "TLSv1.1", "TLSv1.2" for specific TLS version
     private static final String PROTOCOL = "TLS";
-    private String keystore;
-    private KeystoreType keystoreType;
-    private String truststore;
-    private KeystoreType truststoreType;
-    private PathType keystorePathType;
-    private PathType truststorePathType;
+    private TlsConfiguration tlsConfig;
 
     private static final Logger LOGGER = LoggerFactory
             .getLogger(SslContextFactory.class);
@@ -50,12 +43,7 @@ public class SslContextFactory {
      *            keystore types
      */
     public SslContextFactory(TlsConfiguration tlsConfig) {
-        keystore = tlsConfig.getTlsKeystore();
-        keystoreType = tlsConfig.getTlsKeystoreType();
-        keystorePathType = tlsConfig.getTlsKeystorePathType();
-        truststore = tlsConfig.getTlsTruststore();
-        truststoreType = tlsConfig.getTlsTruststoreType();
-        truststorePathType = tlsConfig.getTlsTruststorePathType();
+        this.tlsConfig = tlsConfig;
     }
 
     /**
@@ -69,15 +57,15 @@ public class SslContextFactory {
         }
         SSLContext serverContext = null;
         try {
-            KeyStore ks = KeyStore.getInstance(keystoreType.name());
-            ks.load(SslKeyStore.asInputStream(keystore, keystorePathType),
-                    SslKeyStore.getKeyStorePassword());
+            KeyStore ks = KeyStore.getInstance(tlsConfig.getTlsKeystoreType().name());
+            ks.load(SslKeyStore.asInputStream(tlsConfig.getTlsKeystore(), tlsConfig.getTlsKeystorePathType()),
+                    tlsConfig.getKeystorePassword().toCharArray());
             KeyManagerFactory kmf = KeyManagerFactory.getInstance(algorithm);
-            kmf.init(ks, SslKeyStore.getCertificatePassword());
+            kmf.init(ks, tlsConfig.getCertificatePassword().toCharArray());
 
-            KeyStore ts = KeyStore.getInstance(truststoreType.name());
-            ts.load(SslKeyStore.asInputStream(truststore, truststorePathType),
-                    SslKeyStore.getKeyStorePassword());
+            KeyStore ts = KeyStore.getInstance(tlsConfig.getTlsTruststoreType().name());
+            ts.load(SslKeyStore.asInputStream(tlsConfig.getTlsTruststore(), tlsConfig.getTlsTruststorePathType()),
+                    tlsConfig.getTruststorePassword().toCharArray());
             TrustManagerFactory tmf = TrustManagerFactory.getInstance(algorithm);
             tmf.init(ts);