|
@@ -85,12 +85,6 @@ import com.google.polo.wire.WireFormat;
|
|
|
|
|
|
public class Remote implements Closeable
|
|
public class Remote implements Closeable
|
|
{
|
|
{
|
|
- public static interface Pairing
|
|
|
|
- {
|
|
|
|
- public void prompt();
|
|
|
|
- public void interrupted(InterruptedException exception);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
private static final String STORE = "bigscreenbot.keystore";
|
|
private static final String STORE = "bigscreenbot.keystore";
|
|
private static final char[] PASSWORD = "b1GsSC33Nb0T".toCharArray();
|
|
private static final char[] PASSWORD = "b1GsSC33Nb0T".toCharArray();
|
|
private static final char[] NULL = new char[]{};
|
|
private static final char[] NULL = new char[]{};
|
|
@@ -207,7 +201,7 @@ public class Remote implements Closeable
|
|
return devices;
|
|
return devices;
|
|
}
|
|
}
|
|
|
|
|
|
- public boolean startPairDevice(String device, final Pairing pairing) throws MalformedURLException, UnknownHostException, IOException, PoloException
|
|
|
|
|
|
+ public boolean startPairDevice(String device, final Runnable runnable) throws MalformedURLException, UnknownHostException, IOException, PoloException, KeyStoreException, NoSuchAlgorithmException, CertificateException
|
|
{
|
|
{
|
|
SSLSocket socket = (SSLSocket)factory.createSocket();
|
|
SSLSocket socket = (SSLSocket)factory.createSocket();
|
|
final InetSocketAddress address = getDevice(device);
|
|
final InetSocketAddress address = getDevice(device);
|
|
@@ -221,7 +215,7 @@ public class Remote implements Closeable
|
|
session.addInputEncoding(option);
|
|
session.addInputEncoding(option);
|
|
session.addOutputEncoding(option);
|
|
session.addOutputEncoding(option);
|
|
|
|
|
|
- return session.doPair(new PairingListener()
|
|
|
|
|
|
+ if (session.doPair(new PairingListener()
|
|
{
|
|
{
|
|
@Override
|
|
@Override
|
|
public void onLogMessage(LogLevel level, String message)
|
|
public void onLogMessage(LogLevel level, String message)
|
|
@@ -233,7 +227,7 @@ public class Remote implements Closeable
|
|
@Override
|
|
@Override
|
|
public void onPerformInputDeviceRole(PairingSession session)
|
|
public void onPerformInputDeviceRole(PairingSession session)
|
|
{
|
|
{
|
|
- pairing.prompt();
|
|
|
|
|
|
+ runnable.run();
|
|
|
|
|
|
Secret secret = new Secret(), oldSecret = secrets.put(address, secret);
|
|
Secret secret = new Secret(), oldSecret = secrets.put(address, secret);
|
|
|
|
|
|
@@ -247,7 +241,6 @@ public class Remote implements Closeable
|
|
catch (InterruptedException exception)
|
|
catch (InterruptedException exception)
|
|
{
|
|
{
|
|
session.teardown();
|
|
session.teardown();
|
|
- pairing.interrupted(exception);
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -270,9 +263,25 @@ public class Remote implements Closeable
|
|
if (verbose)
|
|
if (verbose)
|
|
System.out.println(session + " ended.");
|
|
System.out.println(session + " ended.");
|
|
}
|
|
}
|
|
- });
|
|
|
|
|
|
+ }))
|
|
|
|
+ {
|
|
|
|
+ synchronized (store)
|
|
|
|
+ {
|
|
|
|
+ Certificate certificate = context.getServerCertificate();
|
|
|
|
+ String alias = String.format(REMOTE_ALIAS, certificate.hashCode());
|
|
|
|
+
|
|
|
|
+ if (store.containsAlias(alias))
|
|
|
|
+ store.deleteEntry(alias);
|
|
|
|
+
|
|
|
|
+ store.setCertificateEntry(alias, certificate);
|
|
|
|
+
|
|
|
|
+ store();
|
|
|
|
+ }
|
|
|
|
|
|
- // TODO: store server certificate
|
|
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
|
|
|
|
public boolean finishPairDevice(String device, String code) throws MalformedURLException
|
|
public boolean finishPairDevice(String device, String code) throws MalformedURLException
|