Browse Source

Diagnostics showed that thigns seems to be working correctly.

Douglas William Thrift 9 years ago
parent
commit
a794dd0f56

+ 15 - 0
src/net/douglasthrift/bigscreenbot/BigScreenBot.java

@@ -557,6 +557,21 @@ public class BigScreenBot extends Bot
         }
     }
 
+    @Override
+    public void dispose()
+    {
+        super.dispose();
+
+        try
+        {
+            remote.close();
+        }
+        catch (IOException exception)
+        {
+            error(exception);
+        }
+    }
+
     public void sendMessage(String channel, String sender, String message)
     {
         sendMessage(channel != null ? channel : sender, message);

+ 8 - 72
src/net/douglasthrift/bigscreenbot/Remote.java

@@ -24,6 +24,7 @@
 
 package net.douglasthrift.bigscreenbot;
 
+import java.io.Closeable;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
@@ -71,7 +72,7 @@ import com.google.polo.pairing.PairingContext;
 import com.google.polo.ssl.DummySSLSocketFactory;
 import com.google.polo.ssl.SslUtil;
 
-public class Remote
+public class Remote implements Closeable
 {
     private static final String STORE = "bigscreenbot.keystore";
     private static final char[] PASSWORD = "b1GsSC33Nb0T".toCharArray();
@@ -130,72 +131,13 @@ public class Remote
 
         factory.init(store, NULL);
 
-        final javax.net.ssl.X509ExtendedKeyManager manager = (javax.net.ssl.X509ExtendedKeyManager)factory.getKeyManagers()[0];
-
-        this.factory = DummySSLSocketFactory.fromKeyManagers(new KeyManager[]{
-            new javax.net.ssl.X509ExtendedKeyManager()
-            {
-                @Override
-                public java.security.PrivateKey getPrivateKey(String alias)
-                {
-                    java.security.PrivateKey key = manager.getPrivateKey(alias);
-
-                    System.out.println("getPrivateKey(" + alias + ") -> " + key);
-
-                    return key;
-                }
-
-                @Override
-                public X509Certificate[] getCertificateChain(String alias)
-                {
-                    X509Certificate[] chain = manager.getCertificateChain(alias);
-
-                    System.out.println("getCertificateChain(" + alias + ") -> " + java.util.Arrays.toString(chain));
-
-                    return chain;
-                }
-
-                @Override
-                public String chooseServerAlias(String keyType, java.security.Principal[] issuers, java.net.Socket socket)
-                {
-                    String alias = manager.chooseServerAlias(keyType, issuers, socket);
-
-                    System.out.println("chooseServerAlias(" + keyType + ", " + java.util.Arrays.toString(issuers) + ", " + socket + ") -> " + alias);
-
-                    return alias;
-                }
-
-                @Override
-                public String[] getServerAliases(String keyType, java.security.Principal[] issuers)
-                {
-                    String[] aliases = manager.getServerAliases(keyType, issuers);
-
-                    System.out.println("getServerAliases(" + keyType + ", " + java.util.Arrays.toString(issuers) + ") -> " + java.util.Arrays.toString(aliases));
-
-                    return aliases;
-                }
-
-                @Override
-                public String chooseClientAlias(String[] keyType, java.security.Principal[] issuers, java.net.Socket socket)
-                {
-                    String alias = manager.chooseClientAlias(keyType, issuers, socket);
-
-                    System.out.println("chooseClientAlias(" + java.util.Arrays.toString(keyType) + ", " + java.util.Arrays.toString(issuers) + ", " + socket + ") -> " + alias);
-
-                    return alias;
-                }
-
-                @Override
-                public String[] getClientAliases(String keyType, java.security.Principal[] issuers)
-                {
-                    String[] aliases = manager.getClientAliases(keyType, issuers);
-
-                    System.out.println("getClientAliases(" + keyType + ", " + java.util.Arrays.toString(issuers) + ") -> " + java.util.Arrays.toString(aliases));
+        this.factory = DummySSLSocketFactory.fromKeyManagers(factory.getKeyManagers());
+    }
 
-                    return aliases;
-                }
-            }
-        });
+    @Override
+    public void close() throws IOException
+    {
+        mdns.close();
     }
 
     public List<String> listDevices()
@@ -246,12 +188,6 @@ public class Remote
     {
     }
 
-    @Override
-    protected void finalize() throws IOException
-    {
-        mdns.close();
-    }
-
     private void store() throws FileNotFoundException, IOException, KeyStoreException, NoSuchAlgorithmException, CertificateException
     {
         FileOutputStream stream = null;