From f7bfa631457f1ead2b9b59775d8a0ddad2a1ebc3 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Fri, 5 Jul 2019 19:40:11 -0700 Subject: [PATCH] Ignore reported pairing state if pinned cert is not found --- .../com/limelight/nvstream/http/NvHTTP.java | 23 +++++++++++-------- .../nvstream/http/PairingManager.java | 12 ---------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/moonlight-common/src/main/java/com/limelight/nvstream/http/NvHTTP.java b/moonlight-common/src/main/java/com/limelight/nvstream/http/NvHTTP.java index aa93e5c6..356c61a2 100644 --- a/moonlight-common/src/main/java/com/limelight/nvstream/http/NvHTTP.java +++ b/moonlight-common/src/main/java/com/limelight/nvstream/http/NvHTTP.java @@ -256,13 +256,9 @@ public class NvHTTP { // This may be null, but that's okay details.remoteAddress = getXmlString(serverInfo, "ExternalIP"); - - try { - details.pairState = Integer.parseInt(getXmlString(serverInfo, "PairStatus")) == 1 ? - PairState.PAIRED : PairState.NOT_PAIRED; - } catch (NumberFormatException e) { - details.pairState = PairState.FAILED; - } + + // This has some extra logic to always report unpaired if the pinned cert isn't there + details.pairState = getPairState(serverInfo); try { details.runningGameId = getCurrentGame(serverInfo); @@ -362,11 +358,20 @@ public class NvHTTP { } public PairingManager.PairState getPairState() throws IOException, XmlPullParserException { - return pm.getPairState(getServerInfo()); + return getPairState(getServerInfo()); } public PairingManager.PairState getPairState(String serverInfo) throws IOException, XmlPullParserException { - return pm.getPairState(serverInfo); + // If we don't have a server cert, we can't be paired even if the host thinks we are + if (serverCert == null) { + return PairState.NOT_PAIRED; + } + + if (!NvHTTP.getXmlString(serverInfo, "PairStatus").equals("1")) { + return PairState.NOT_PAIRED; + } + + return PairState.PAIRED; } public long getMaxLumaPixelsH264(String serverInfo) throws XmlPullParserException, IOException { diff --git a/moonlight-common/src/main/java/com/limelight/nvstream/http/PairingManager.java b/moonlight-common/src/main/java/com/limelight/nvstream/http/PairingManager.java index 6d794610..dd9aae3c 100644 --- a/moonlight-common/src/main/java/com/limelight/nvstream/http/PairingManager.java +++ b/moonlight-common/src/main/java/com/limelight/nvstream/http/PairingManager.java @@ -1,11 +1,7 @@ package com.limelight.nvstream.http; -import javax.crypto.BadPaddingException; import javax.crypto.Cipher; -import javax.crypto.IllegalBlockSizeException; -import javax.crypto.NoSuchPaddingException; import javax.crypto.SecretKey; -import javax.crypto.ShortBufferException; import javax.crypto.spec.SecretKeySpec; import org.xmlpull.v1.XmlPullParserException; @@ -177,14 +173,6 @@ public class PairingManager { r.nextInt(10), r.nextInt(10), r.nextInt(10), r.nextInt(10)); } - - public PairState getPairState(String serverInfo) throws IOException, XmlPullParserException { - if (!NvHTTP.getXmlString(serverInfo, "PairStatus").equals("1")) { - return PairState.NOT_PAIRED; - } - - return PairState.PAIRED; - } public X509Certificate getPairedCert() { return serverCert;