Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for TLSv1.1 and TLSv1.2 #98

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public void checkServerTrusted(X509Certificate[] chain, String authType) {
try {
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, trustAllCerts, new SecureRandom());
TRUSTED_FACTORY = context.getSocketFactory();
TRUSTED_FACTORY = new TLSSocketFactory(context);
} catch (GeneralSecurityException e) {
IOException ioException = new IOException(
"Security exception configuring SSL context");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Copyright (c) 2014 Kevin Sawicki <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/

/*
* TLSSocketFactory added by Fmstrat is used to enable TLSv1.1 and TLSv1.2 support
* Supported protocols per API can be found at:
* https://developer.android.com/reference/javax/net/ssl/SSLSocket.html
*/
package com.github.kevinsawicki.http;

import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;

import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;

public class TLSSocketFactory extends SSLSocketFactory {

private final javax.net.ssl.SSLSocketFactory socketFactory;

public TLSSocketFactory(SSLContext sslContext) {
super();
this.socketFactory = sslContext.getSocketFactory();
}

@Override
public Socket createSocket(
final Socket socket,
final String host,
final int port,
final boolean autoClose
) throws java.io.IOException {
SSLSocket sslSocket = (SSLSocket) this.socketFactory.createSocket(
socket,
host,
port,
autoClose
);
sslSocket.setEnabledProtocols(sslSocket.getSupportedProtocols());
return sslSocket;
}

@Override
public String[] getDefaultCipherSuites() {
return this.socketFactory.getDefaultCipherSuites();
}

@Override
public String[] getSupportedCipherSuites() {
return this.socketFactory.getSupportedCipherSuites();
}

@Override
public Socket createSocket(String s, int i) throws IOException {
return null;
}

@Override
public Socket createSocket(String s, int i, InetAddress inetAddress, int i2) throws IOException {
return null;
}

@Override
public Socket createSocket(InetAddress inetAddress, int i) throws IOException {
return null;
}

@Override
public Socket createSocket(InetAddress inetAddress, int i, InetAddress inetAddress2, int i2) throws IOException {
return null;
}
}