Skip to content

Commit 9475a81

Browse files
committed
Update
1 parent 3211ac8 commit 9475a81

File tree

2 files changed

+9
-78
lines changed

2 files changed

+9
-78
lines changed

aws-android-sdk-kinesisvideo/src/main/java/com/amazonaws/kinesisvideo/http/HostnameVerifyingX509ExtendedTrustManager.java

Lines changed: 3 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,9 @@ private X509ExtendedTrustManager getX509ExtendedTrustManager() {
4545
factory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
4646
factory.init((KeyStore) null);
4747
} catch (NoSuchAlgorithmException nsae) {
48-
log.error("Unable to initialize default TrustManagerFactory, using no-op X509ExtendedTrustManager", nsae);
49-
return getNoOpInstance();
48+
throw new RuntimeException("Unable to initialize default TrustManagerFactory", nsae);
5049
} catch (KeyStoreException nse) {
51-
log.error("Unable to initialize default TrustManagerFactory, using no-op X509ExtendedTrustManager", nse);
52-
return getNoOpInstance();
50+
throw new RuntimeException("Unable to initialize default TrustManagerFactory", nse);
5351
}
5452

5553
for (TrustManager tm: factory.getTrustManagers()) {
@@ -58,8 +56,7 @@ private X509ExtendedTrustManager getX509ExtendedTrustManager() {
5856
}
5957
}
6058

61-
log.debug("No default X509TrustManager found, using no-op");
62-
return getNoOpInstance();
59+
throw new RuntimeException("No default X509TrustManager found");
6360
}
6461

6562
@Override
@@ -170,65 +167,4 @@ public void performHostVerification(
170167
log.error("Failed to verify hostname: %s", hostName);
171168
throw new CertificateException("Failed to verify both host address and host name");
172169
}
173-
174-
175-
private X509ExtendedTrustManager getNoOpInstance() {
176-
return new X509ExtendedTrustManager() {
177-
@Override
178-
public void checkClientTrusted(
179-
final X509Certificate[] x509Certificates,
180-
final String s,
181-
final Socket socket)
182-
throws CertificateException {
183-
184-
}
185-
186-
@Override
187-
public void checkServerTrusted(
188-
final X509Certificate[] x509Certificates,
189-
final String s,
190-
final Socket socket)
191-
throws CertificateException {
192-
193-
}
194-
195-
@Override
196-
public void checkClientTrusted(
197-
final X509Certificate[] x509Certificates,
198-
final String s,
199-
final SSLEngine sslEngine)
200-
throws CertificateException {
201-
202-
}
203-
204-
@Override
205-
public void checkServerTrusted(
206-
final X509Certificate[] x509Certificates,
207-
final String s,
208-
final SSLEngine sslEngine)
209-
throws CertificateException {
210-
211-
}
212-
213-
@Override
214-
public void checkClientTrusted(
215-
final X509Certificate[] x509Certificates,
216-
final String s) throws CertificateException {
217-
218-
}
219-
220-
@Override
221-
public void checkServerTrusted(
222-
final X509Certificate[] x509Certificates,
223-
final String s) throws CertificateException {
224-
225-
}
226-
227-
@Override
228-
public X509Certificate[] getAcceptedIssuers() {
229-
return new X509Certificate[0];
230-
}
231-
};
232-
}
233-
234170
}

aws-android-sdk-kinesisvideo/src/main/java/com/amazonaws/kinesisvideo/http/KinesisVideoApacheHttpClient.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,13 @@
2323
import org.apache.http.client.methods.HttpPost;
2424
import org.apache.http.config.SocketConfig;
2525
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
26-
import org.apache.http.conn.ssl.TrustStrategy;
2726
import org.apache.http.entity.ContentType;
2827
import org.apache.http.entity.StringEntity;
2928
import org.apache.http.impl.client.CloseableHttpClient;
3029
import org.apache.http.impl.client.HttpClients;
3130

32-
import javax.net.ssl.SSLSession;
3331
import javax.net.ssl.SSLContext;
32+
import javax.net.ssl.X509ExtendedTrustManager;
3433

3534
import static com.amazonaws.kinesisvideo.common.preconditions.Preconditions.checkNotNull;
3635

@@ -43,6 +42,7 @@
4342
import java.security.KeyManagementException;
4443
import java.security.KeyStoreException;
4544
import java.security.NoSuchAlgorithmException;
45+
import java.security.SecureRandom;
4646
import java.security.cert.CertificateException;
4747
import java.security.cert.X509Certificate;
4848
import java.util.HashMap;
@@ -87,15 +87,10 @@ public CloseableHttpResponse executeRequest() {
8787
private CloseableHttpClient buildHttpClient() {
8888
try {
8989
final SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
90-
// Initializes context. Either of the first two parameters may be null in which case
91-
// the installed security providers will be searched for the highest priority implementation
92-
// of the appropriate factory. Likewise, the secure random parameter may be null in which case the default
93-
// implementation will be used.
94-
sslContext.init(null, null, null);
95-
96-
final SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(
97-
sslContext,
98-
HostnameVerifier.INSTANCE);
90+
sslContext.init(null, new X509ExtendedTrustManager[] {
91+
new HostnameVerifyingX509ExtendedTrustManager(true)}, new SecureRandom());
92+
93+
final SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext);
9994

10095
return HttpClients.custom()
10196
.setSSLSocketFactory(sslSocketFactory)

0 commit comments

Comments
 (0)