Skip to content

Commit 3f4387b

Browse files
committed
fix: simplify implementation
1 parent 6b82602 commit 3f4387b

3 files changed

Lines changed: 26 additions & 106 deletions

File tree

google-http-client/src/main/java/com/google/api/client/http/javanet/NetHttpTransport.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ private static Proxy defaultProxy() {
9595
private final boolean isMtls;
9696

9797
/**
98-
* Returns the default SSL socket factory, which is PQC-enabled if Bouncy Castle JJSSE is on the classpath.
98+
* Returns the default SSL socket factory, which is PQC-enabled if Bouncy Castle JJSSE is on the
99+
* classpath.
99100
*/
100101
private static SSLSocketFactory getDefaultSslSocketFactory() {
101102
try {
@@ -146,8 +147,7 @@ public NetHttpTransport() {
146147
HostnameVerifier hostnameVerifier,
147148
boolean isMtls) {
148149
this.connectionFactory = getConnectionFactory(connectionFactory);
149-
// Securely wrap the socket factory to enforce PQC hybrid negotiation scope-specifically
150-
this.sslSocketFactory = sslSocketFactory != null ? new PqcDelegatingSSLSocketFactory(sslSocketFactory) : null;
150+
this.sslSocketFactory = sslSocketFactory;
151151
this.hostnameVerifier = hostnameVerifier;
152152
this.isMtls = isMtls;
153153
}
@@ -310,26 +310,30 @@ public Builder trustCertificates(KeyStore trustStore) throws GeneralSecurityExce
310310
}
311311

312312
/**
313-
* Sets the SSL socket factory based on a root certificate trust store and a specific security provider.
313+
* Sets the SSL socket factory based on a root certificate trust store and a specific security
314+
* provider.
314315
*
315316
* @param trustStore certificate trust store
316317
* @param provider security provider to use for SSL context
317318
* @since 1.39
318319
*/
319-
public Builder trustCertificates(KeyStore trustStore, Provider provider) throws GeneralSecurityException {
320+
public Builder trustCertificates(KeyStore trustStore, Provider provider)
321+
throws GeneralSecurityException {
320322
SSLContext sslContext = SslUtils.getTlsSslContext(provider);
321323
SslUtils.initSslContext(sslContext, trustStore, SslUtils.getPkixTrustManagerFactory());
322324
return setSslSocketFactory(sslContext.getSocketFactory());
323325
}
324326

325327
/**
326-
* Sets the SSL socket factory based on a root certificate trust store and a specific security provider name.
328+
* Sets the SSL socket factory based on a root certificate trust store and a specific security
329+
* provider name.
327330
*
328331
* @param trustStore certificate trust store
329332
* @param providerName security provider name to use for SSL context
330333
* @since 1.39
331334
*/
332-
public Builder trustCertificates(KeyStore trustStore, String providerName) throws GeneralSecurityException {
335+
public Builder trustCertificates(KeyStore trustStore, String providerName)
336+
throws GeneralSecurityException {
333337
try {
334338
SSLContext sslContext = SslUtils.getTlsSslContext(providerName);
335339
SslUtils.initSslContext(sslContext, trustStore, SslUtils.getPkixTrustManagerFactory());
@@ -412,7 +416,8 @@ public NetHttpTransport build() {
412416
if (System.getProperty(SHOULD_USE_PROXY_FLAG) != null) {
413417
setProxy(defaultProxy());
414418
}
415-
SSLSocketFactory factory = sslSocketFactory != null ? sslSocketFactory : getDefaultSslSocketFactory();
419+
SSLSocketFactory factory =
420+
sslSocketFactory != null ? sslSocketFactory : getDefaultSslSocketFactory();
416421
return this.proxy == null
417422
? new NetHttpTransport(connectionFactory, factory, hostnameVerifier, isMtls)
418423
: new NetHttpTransport(this.proxy, factory, hostnameVerifier, isMtls);

google-http-client/src/main/java/com/google/api/client/http/javanet/PqcDelegatingSSLSocketFactory.java

Lines changed: 0 additions & 86 deletions
This file was deleted.

google-http-client/src/main/java/com/google/api/client/util/SslUtils.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.security.NoSuchAlgorithmException;
2121
import java.security.NoSuchProviderException;
2222
import java.security.Provider;
23+
import java.security.Security;
2324
import java.security.cert.CertificateException;
2425
import java.security.cert.X509Certificate;
2526
import javax.net.ssl.HostnameVerifier;
@@ -29,9 +30,8 @@
2930
import javax.net.ssl.TrustManager;
3031
import javax.net.ssl.TrustManagerFactory;
3132
import javax.net.ssl.X509TrustManager;
32-
import org.bouncycastle.jsse.provider.BouncyCastleJsseProvider;
3333
import org.bouncycastle.jce.provider.BouncyCastleProvider;
34-
import java.security.Security;
34+
import org.bouncycastle.jsse.provider.BouncyCastleJsseProvider;
3535

3636
/**
3737
* SSL utilities.
@@ -51,25 +51,27 @@ public static SSLContext getSslContext() throws NoSuchAlgorithmException {
5151
}
5252

5353
/**
54-
* Returns the SSL context for "TLS" algorithm using Bouncy Castle JJSSE provider scope-specifically.
54+
* Returns the SSL context for "TLS" algorithm using Bouncy Castle JJSSE provider
55+
* scope-specifically.
5556
*
56-
* @since 1.14
57+
* @since 2.1.1
5758
*/
5859
public static SSLContext getTlsSslContext() throws NoSuchAlgorithmException {
5960
// 1. Explicitly register Bouncy Castle cryptographic provider globally if not already present.
6061
if (Security.getProvider("BC") == null) {
6162
Security.addProvider(new BouncyCastleProvider());
6263
}
63-
64+
6465
// 2. Explicitly instantiate Bouncy Castle cryptographic (JCA) provider instance.
6566
BouncyCastleProvider cryptoProvider = new BouncyCastleProvider();
66-
67+
6768
// 3. Explicitly instantiate Bouncy Castle JJSSE provider bound to our crypto provider.
6869
BouncyCastleJsseProvider provider = new BouncyCastleJsseProvider(cryptoProvider);
69-
70-
// 3. Create standard TLS context instance bound specifically to our Bouncy Castle JJSSE provider.
70+
71+
// 3. Create standard TLS context instance bound specifically to our Bouncy Castle JJSSE
72+
// provider.
7173
SSLContext bcContext = SSLContext.getInstance("TLS", provider);
72-
74+
7375
try {
7476
// 4. Initialize the Bouncy Castle SSLContext with default managers.
7577
bcContext.init(null, null, null);
@@ -86,7 +88,7 @@ public static SSLContext getTlsSslContext() throws NoSuchAlgorithmException {
8688
}
8789
return fallbackContext;
8890
}
89-
91+
9092
// 6. Return the raw Bouncy Castle SSLContext.
9193
return bcContext;
9294
}
@@ -96,8 +98,7 @@ public static SSLContext getTlsSslContext() throws NoSuchAlgorithmException {
9698
*
9799
* @since 1.39
98100
*/
99-
public static SSLContext getTlsSslContext(Provider provider)
100-
throws NoSuchAlgorithmException {
101+
public static SSLContext getTlsSslContext(Provider provider) throws NoSuchAlgorithmException {
101102
return SSLContext.getInstance("TLS", provider);
102103
}
103104

0 commit comments

Comments
 (0)