forked from ConnectSDK/Connect-SDK-Android-Core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use secure port for mouse socket connection
- Loading branch information
1 parent
2c04b6f
commit 48df1d7
Showing
4 changed files
with
77 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.connectsdk.service.webos; | ||
|
||
import android.util.Log; | ||
|
||
import com.connectsdk.core.Util; | ||
|
||
import javax.net.ssl.X509TrustManager; | ||
import java.security.cert.CertificateException; | ||
import java.security.cert.X509Certificate; | ||
|
||
import java.util.Arrays; | ||
|
||
public class WebOSTVTrustManager implements X509TrustManager { | ||
X509Certificate expectedCert; | ||
X509Certificate lastCheckedCert; | ||
|
||
public void setExpectedCertificate(X509Certificate cert) { | ||
this.expectedCert = cert; | ||
} | ||
|
||
public X509Certificate getLastCheckedCertificate () { | ||
return lastCheckedCert; | ||
} | ||
|
||
@Override | ||
public void checkClientTrusted(X509Certificate[] chain, String authType) | ||
throws CertificateException { | ||
} | ||
|
||
@Override | ||
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { | ||
Log.d(Util.T, "Expecting device cert " + (expectedCert != null ? expectedCert.getSubjectDN() : "(any)")); | ||
|
||
if (chain != null && chain.length > 0) { | ||
X509Certificate cert = chain[0]; | ||
|
||
lastCheckedCert = cert; | ||
|
||
if (expectedCert != null) { | ||
byte [] certBytes = cert.getEncoded(); | ||
byte [] expectedCertBytes = expectedCert.getEncoded(); | ||
|
||
Log.d(Util.T, "Device presented cert " + cert.getSubjectDN()); | ||
|
||
if (!Arrays.equals(certBytes, expectedCertBytes)) { | ||
throw new CertificateException("certificate does not match"); | ||
} | ||
} | ||
} else { | ||
lastCheckedCert = null; | ||
throw new CertificateException("no server certificate"); | ||
} | ||
} | ||
|
||
@Override | ||
public X509Certificate[] getAcceptedIssuers() { | ||
return new X509Certificate[0]; | ||
} | ||
} |