Browse Source
SSLContext.getInstance("TLS") by default behaves differently on IBM JDK than on Oracle or OpenJDK.[1] On IBM JDK one gets sockets that have only TLSv1 enabled, which makes HTTPS connections fail since most servers refuse this old protocol version. On Oracle JDK/OpenJDK, one gets sockets with all available protocol versions enabled. Explicitly enable all available TLS protocol versions to make HTTPS connections work also on IBM JDK. [1] https://www.ibm.com/support/knowledgecenter/en/SSYKE2_8.0.0/com.ibm.java.security.component.80.doc/security-component/jsse2Docs/matchsslcontext_tls.html#matchsslcontext_tls Bug: 558709 Change-Id: I5ffc57a78e67a6239b9dad54840a49a8ed28930a Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>stable-5.7
Thomas Wolf
5 years ago
committed by
Matthias Sohn
7 changed files with 253 additions and 7 deletions
@ -0,0 +1,101 @@
|
||||
/* |
||||
* Copyright (c) 2020 Thomas Wolf <thomas.wolf@paranor.ch> |
||||
* |
||||
* This program and the accompanying materials are made available under the |
||||
* terms of the Eclipse Distribution License v. 1.0 which is available at |
||||
* https://www.eclipse.org/org/documents/edl-v10.php.
|
||||
* |
||||
* SPDX-License-Identifier: BSD-3-Clause |
||||
*/ |
||||
package org.eclipse.jgit.transport.internal; |
||||
|
||||
import java.io.IOException; |
||||
import java.net.InetAddress; |
||||
import java.net.Socket; |
||||
|
||||
import javax.net.ssl.SSLSocket; |
||||
import javax.net.ssl.SSLSocketFactory; |
||||
|
||||
/** |
||||
* An {@link SSLSocketFactory} that delegates to another factory and allows |
||||
* configuring the created socket via {@link #configure(SSLSocket)} before it is |
||||
* returned. |
||||
*/ |
||||
public abstract class DelegatingSSLSocketFactory extends SSLSocketFactory { |
||||
|
||||
private final SSLSocketFactory delegate; |
||||
|
||||
/** |
||||
* Creates a new {@link DelegatingSSLSocketFactory} based on the given |
||||
* delegate. |
||||
* |
||||
* @param delegate |
||||
* {@link SSLSocketFactory} to delegate to |
||||
*/ |
||||
public DelegatingSSLSocketFactory(SSLSocketFactory delegate) { |
||||
this.delegate = delegate; |
||||
} |
||||
|
||||
@Override |
||||
public SSLSocket createSocket() throws IOException { |
||||
return prepare(delegate.createSocket()); |
||||
} |
||||
|
||||
@Override |
||||
public SSLSocket createSocket(String host, int port) throws IOException { |
||||
return prepare(delegate.createSocket(host, port)); |
||||
} |
||||
|
||||
@Override |
||||
public SSLSocket createSocket(String host, int port, |
||||
InetAddress localAddress, int localPort) throws IOException { |
||||
return prepare( |
||||
delegate.createSocket(host, port, localAddress, localPort)); |
||||
} |
||||
|
||||
@Override |
||||
public SSLSocket createSocket(InetAddress host, int port) |
||||
throws IOException { |
||||
return prepare(delegate.createSocket(host, port)); |
||||
} |
||||
|
||||
@Override |
||||
public SSLSocket createSocket(InetAddress host, int port, |
||||
InetAddress localAddress, int localPort) throws IOException { |
||||
return prepare( |
||||
delegate.createSocket(host, port, localAddress, localPort)); |
||||
} |
||||
|
||||
@Override |
||||
public SSLSocket createSocket(Socket socket, String host, int port, |
||||
boolean autoClose) throws IOException { |
||||
return prepare(delegate.createSocket(socket, host, port, autoClose)); |
||||
} |
||||
|
||||
@Override |
||||
public String[] getDefaultCipherSuites() { |
||||
return delegate.getDefaultCipherSuites(); |
||||
} |
||||
|
||||
@Override |
||||
public String[] getSupportedCipherSuites() { |
||||
return delegate.getSupportedCipherSuites(); |
||||
} |
||||
|
||||
private SSLSocket prepare(Socket socket) throws IOException { |
||||
SSLSocket sslSocket = (SSLSocket) socket; |
||||
configure(sslSocket); |
||||
return sslSocket; |
||||
} |
||||
|
||||
/** |
||||
* Configure the newly created socket. |
||||
* |
||||
* @param socket |
||||
* to configure |
||||
* @throws IOException |
||||
* if the socket cannot be configured |
||||
*/ |
||||
protected abstract void configure(SSLSocket socket) throws IOException; |
||||
|
||||
} |
Loading…
Reference in new issue