Skip to content

Commit

Permalink
JSON-RPC clients: remove deprecated SSLContext methods
Browse files Browse the repository at this point in the history
  • Loading branch information
msgilligan committed Sep 7, 2023
1 parent c7a1fba commit 053aa5e
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 88 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ A high-level view of the changes in each ConsensusJ binary release.

Released: Under development

=== JSON-RPC clients

* Remove deprecated methods that use `SSLSocketFactory` (In favor of `SSLContext`)

== v0.7.0-alpha2

Released: 2023-08-30
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import org.slf4j.LoggerFactory;

import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import java.io.EOFException;
import java.io.IOException;
import java.net.SocketException;
Expand Down Expand Up @@ -128,26 +127,6 @@ public BitcoinClient(SSLContext sslContext, Network network, URI server, String
mapper.registerModule(new RpcClientModule());
}

/**
* @deprecated Use {@link BitcoinClient#BitcoinClient(SSLContext, Network, URI, String, String)}
*/
@Deprecated
public BitcoinClient(SSLSocketFactory sslSocketFactory, Network network, URI server, String rpcuser, String rpcpassword) {
super(sslSocketFactory, JsonRpcMessage.Version.V2, server, rpcuser, rpcpassword);
this.network = network;
ThreadFactory threadFactory = new BitcoinClientThreadFactory(new Context(), "Bitcoin RPC Client");
executorService = Executors.newFixedThreadPool(THREAD_POOL_SIZE, threadFactory);
mapper.registerModule(new RpcClientModule());
}

/**
* @deprecated Use {@link BitcoinClient#BitcoinClient(SSLContext, Network, URI, String, String)}
*/
@Deprecated
public BitcoinClient(SSLSocketFactory sslSocketFactory, NetworkParameters netParams, URI server, String rpcuser, String rpcpassword) {
this(sslSocketFactory, netParams.network(), server, rpcuser, rpcpassword);
}

// TODO: Reconcile this constructor mode with {@link #waitForServer(int)}
/**
* Incubating constructor that doesn't require a {@link Network}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.slf4j.LoggerFactory;

import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import java.io.IOException;
import java.math.BigInteger;
import java.net.URI;
Expand Down Expand Up @@ -75,16 +74,6 @@ public BitcoinExtendedClient(SSLContext sslContext, Network network, URI server,
super(sslContext, network, server, rpcuser, rpcpassword);
}

@Deprecated
public BitcoinExtendedClient(SSLSocketFactory sslSocketFactory, Network network, URI server, String rpcuser, String rpcpassword) {
super(sslSocketFactory, network, server, rpcuser, rpcpassword);
}

@Deprecated
public BitcoinExtendedClient(SSLSocketFactory sslSocketFactory, NetworkParameters netParams, URI server, String rpcuser, String rpcpassword) {
super(sslSocketFactory, netParams.network(), server, rpcuser, rpcpassword);
}

public BitcoinExtendedClient(Network network, URI server, String rpcuser, String rpcpassword) {
this(getDefaultSSLContext(), network, server, rpcuser, rpcpassword);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.consensusj.bitcoinj.util.BlockUtil;

import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import java.net.URI;

/**
Expand Down Expand Up @@ -50,16 +49,6 @@ public RxBitcoinClient(SSLContext sslContext, Network network, URI server, Strin
}
}

@Deprecated
public RxBitcoinClient(SSLSocketFactory sslSocketFactory, Network network, URI server, String rpcuser, String rpcpassword, boolean useZmq) {
super(sslSocketFactory, network, server, rpcuser, rpcpassword);
if (useZmq) {
chainTipService = new RxBitcoinZmqService(this);
} else {
chainTipService = new PollingChainTipServiceImpl(this);
}
}

@Override
public Flowable<ChainTip> chainTipPublisher() {
return Flowable.fromPublisher(chainTipService.chainTipPublisher());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ SSLContext sslContext(CommandLine line) {
throw new ToolException(1, e.getMessage());
}
} else {
// Otherwise, use the default SSLSocketFactory
// Otherwise, use the default SSLContext
try {
sslContext = SSLContext.getDefault();
} catch (NoSuchAlgorithmException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.consensusj.jsonrpc.AbstractRpcClient;

import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.PrintWriter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.slf4j.LoggerFactory;

import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
Expand Down Expand Up @@ -62,30 +61,6 @@ public CompositeTrustManager(Path trustStorePath) throws FileNotFoundException {
this(new FileInputStream(trustStorePath.toFile()));
}

@Deprecated
public static SSLSocketFactory getCompositeSSLSocketFactory(Path trustStorePath) throws NoSuchAlgorithmException, KeyManagementException, FileNotFoundException {
TrustManager tm = new CompositeTrustManager(trustStorePath);
return getSocketFactory(tm);
}


@Deprecated
public static SSLSocketFactory getCompositeSSLSocketFactory(InputStream trustStoreStream) throws NoSuchAlgorithmException, KeyManagementException {
TrustManager tm = new CompositeTrustManager(trustStoreStream);
return getSocketFactory(tm);
}

@Deprecated
public static SSLSocketFactory getAlternateSSLSocketFactory(Path trustStorePath) throws KeyStoreException, IOException, NoSuchAlgorithmException, KeyManagementException, CertificateException {
return getAlternateSSLSocketFactory(new FileInputStream(trustStorePath.toFile()));
}

@Deprecated
public static SSLSocketFactory getAlternateSSLSocketFactory(InputStream trustStoreStream) throws KeyStoreException, IOException, NoSuchAlgorithmException, KeyManagementException, CertificateException {
X509TrustManager trustManager = getCustomTrustManager(trustStoreStream);
return getSocketFactory( trustManager );
}

/**
* Used to create an SSLContext using {@link CompositeTrustManager}
* See: https://stackoverflow.com/questions/859111/how-can-i-use-different-certificates-on-specific-connections
Expand Down Expand Up @@ -121,11 +96,6 @@ public static SSLContext getAlternateSSLContext(InputStream trustStoreStream) th
return getSSLContext( trustManager );
}

@Deprecated
private static SSLSocketFactory getSocketFactory(TrustManager trustManager) throws NoSuchAlgorithmException, KeyManagementException {
return getSSLContext(trustManager).getSocketFactory();
}

private static SSLContext getSSLContext(TrustManager trustManager) throws NoSuchAlgorithmException, KeyManagementException {
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(null, new TrustManager[] {trustManager}, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,6 @@ public class JsonRpcClientHttpUrlConnection extends AbstractRpcClient {
private static final String UTF8 = StandardCharsets.UTF_8.name();
private final SSLSocketFactory sslSocketFactory;

/**
* @deprecated Use {@link JsonRpcClientHttpUrlConnection#JsonRpcClientHttpUrlConnection(SSLContext, JsonRpcMessage.Version, URI, String, String)}
*/
@Deprecated
public JsonRpcClientHttpUrlConnection(SSLSocketFactory socketFactory, JsonRpcMessage.Version jsonRpcVersion, URI server, final String rpcUser, final String rpcPassword) {
super(jsonRpcVersion);
this.sslSocketFactory = socketFactory;
log.debug("Constructing JSON-RPC client for: {}", server);
this.serverURI = server;
this.username = rpcUser;
this.password = rpcPassword;
}

public JsonRpcClientHttpUrlConnection(SSLContext sslContext, JsonRpcMessage.Version jsonRpcVersion, URI server, final String rpcUser, final String rpcPassword) {
super(jsonRpcVersion);
this.sslSocketFactory = sslContext.getSocketFactory();
Expand Down

0 comments on commit 053aa5e

Please sign in to comment.