mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2025-07-21 12:03:02 +00:00
Handle pairing while a pairing attempt is pending
This commit is contained in:
parent
a14a4a8d60
commit
ba398e4073
@ -35,7 +35,8 @@ public class PairingManager {
|
|||||||
NOT_PAIRED,
|
NOT_PAIRED,
|
||||||
PAIRED,
|
PAIRED,
|
||||||
PIN_WRONG,
|
PIN_WRONG,
|
||||||
FAILED
|
FAILED,
|
||||||
|
ALREADY_IN_PROGRESS
|
||||||
}
|
}
|
||||||
|
|
||||||
public PairingManager(NvHTTP http, LimelightCryptoProvider cryptoProvider) {
|
public PairingManager(NvHTTP http, LimelightCryptoProvider cryptoProvider) {
|
||||||
@ -69,10 +70,15 @@ public class PairingManager {
|
|||||||
private X509Certificate extractPlainCert(String text) throws XmlPullParserException, IOException, CertificateException
|
private X509Certificate extractPlainCert(String text) throws XmlPullParserException, IOException, CertificateException
|
||||||
{
|
{
|
||||||
String certText = NvHTTP.getXmlString(text, "plaincert");
|
String certText = NvHTTP.getXmlString(text, "plaincert");
|
||||||
|
if (certText != null) {
|
||||||
byte[] certBytes = hexToBytes(certText);
|
byte[] certBytes = hexToBytes(certText);
|
||||||
CertificateFactory cf = CertificateFactory.getInstance("X.509");
|
CertificateFactory cf = CertificateFactory.getInstance("X.509");
|
||||||
return (X509Certificate)cf.generateCertificate(new ByteArrayInputStream(certBytes));
|
return (X509Certificate)cf.generateCertificate(new ByteArrayInputStream(certBytes));
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private byte[] generateRandomBytes(int length)
|
private byte[] generateRandomBytes(int length)
|
||||||
{
|
{
|
||||||
@ -184,10 +190,14 @@ public class PairingManager {
|
|||||||
bytesToHex(salt)+"&clientcert="+bytesToHex(pemCertBytes),
|
bytesToHex(salt)+"&clientcert="+bytesToHex(pemCertBytes),
|
||||||
false);
|
false);
|
||||||
if (!NvHTTP.getXmlString(getCert, "paired").equals("1")) {
|
if (!NvHTTP.getXmlString(getCert, "paired").equals("1")) {
|
||||||
http.openHttpConnectionToString(http.baseUrlHttp + "/unpair?"+http.buildUniqueIdUuidString(), true);
|
|
||||||
return PairState.FAILED;
|
return PairState.FAILED;
|
||||||
}
|
}
|
||||||
X509Certificate serverCert = extractPlainCert(getCert);
|
X509Certificate serverCert = extractPlainCert(getCert);
|
||||||
|
if (serverCert == null) {
|
||||||
|
// Attempting to pair while another device is pairing will cause GFE
|
||||||
|
// to give an empty cert in the response.
|
||||||
|
return PairState.ALREADY_IN_PROGRESS;
|
||||||
|
}
|
||||||
|
|
||||||
// Generate a random challenge and encrypt it with our AES key
|
// Generate a random challenge and encrypt it with our AES key
|
||||||
byte[] randomChallenge = generateRandomBytes(16);
|
byte[] randomChallenge = generateRandomBytes(16);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user