|
18 | 18 |
|
19 | 19 | import com.google.api.client.http.HttpTransport; |
20 | 20 | import com.google.api.client.http.javanet.NetHttpTransport; |
| 21 | +import com.google.api.client.util.SslUtils; |
21 | 22 | import com.google.auth.http.HttpTransportFactory; |
22 | 23 | import com.google.cloud.bigquery.BigQuery; |
23 | 24 | import com.google.cloud.bigquery.BigQueryOptions; |
24 | 25 | import com.google.cloud.http.HttpTransportOptions; |
25 | 26 | import java.io.IOException; |
| 27 | +import java.lang.reflect.Field; |
26 | 28 | import java.net.InetAddress; |
27 | 29 | import java.net.Socket; |
28 | 30 | import java.net.UnknownHostException; |
| 31 | +import java.security.Provider; |
29 | 32 | import java.util.concurrent.atomic.AtomicReference; |
30 | 33 | import javax.net.ssl.SSLContext; |
| 34 | +import javax.net.ssl.SSLSession; |
31 | 35 | import javax.net.ssl.SSLSocket; |
32 | 36 | import javax.net.ssl.SSLSocketFactory; |
| 37 | +import javax.net.ssl.TrustManagerFactory; |
33 | 38 | import org.conscrypt.Conscrypt; |
34 | 39 | import org.conscrypt.OpenSSLSocketImpl; |
35 | 40 |
|
@@ -142,22 +147,18 @@ public HttpTransport create() { |
142 | 147 | NetHttpTransport.Builder builder = new NetHttpTransport.Builder(); |
143 | 148 |
|
144 | 149 | // 1. Explicitly initialize Conscrypt provider |
145 | | - java.security.Provider conscryptProvider = Conscrypt.newProvider(); |
| 150 | + Provider conscryptProvider = Conscrypt.newProvider(); |
146 | 151 | builder.setSecurityProvider(conscryptProvider); |
147 | 152 |
|
148 | 153 | // 2. Build SSLContext and tracing socket factory using SslUtils helpers to prevent |
149 | 154 | // Unknown authType: GENERIC (which is wrapped automatically inside initSslContext) |
150 | | - javax.net.ssl.TrustManagerFactory tmf = |
151 | | - com.google.api.client.util.SslUtils.getDefaultTrustManagerFactory(conscryptProvider); |
152 | | - SSLContext sslContext = |
153 | | - com.google.api.client.util.SslUtils.getTlsSslContext(conscryptProvider); |
154 | | - com.google.api.client.util.SslUtils.initSslContext(sslContext, null, tmf); |
| 155 | + TrustManagerFactory tmf = SslUtils.getDefaultTrustManagerFactory(conscryptProvider); |
| 156 | + SSLContext sslContext = SslUtils.getTlsSslContext(conscryptProvider); |
| 157 | + SslUtils.initSslContext(sslContext, null, tmf); |
155 | 158 |
|
156 | 159 | SSLSocketFactory baseFactory = sslContext.getSocketFactory(); |
157 | 160 | SSLSocketFactory tracingFactory = new TracingSSLSocketFactory(baseFactory); |
158 | 161 |
|
159 | | - // 3. Configure builder with tracing factory and generic PQC curves |
160 | | - builder.setNamedGroups(new String[] {"X25519MLKEM768", "X25519"}); |
161 | 162 | builder.setSslSocketFactory(tracingFactory); |
162 | 163 |
|
163 | 164 | return builder.build(); |
@@ -188,8 +189,8 @@ private Socket wrap(Socket socket) { |
188 | 189 | // Direct Conscrypt check since it is a direct dependency |
189 | 190 | if (rawSocket instanceof OpenSSLSocketImpl) { |
190 | 191 | curve = ((OpenSSLSocketImpl) rawSocket).getCurveNameForTesting(); |
191 | | - } else if (rawSocket instanceof javax.net.ssl.SSLSocket) { |
192 | | - curve = getSunJsseNegotiatedCurve((javax.net.ssl.SSLSocket) rawSocket); |
| 192 | + } else if (rawSocket instanceof SSLSocket) { |
| 193 | + curve = getSunJsseNegotiatedCurve((SSLSocket) rawSocket); |
193 | 194 | } |
194 | 195 |
|
195 | 196 | if (curve != null) { |
@@ -248,13 +249,13 @@ public Socket createSocket( |
248 | 249 |
|
249 | 250 | private static String getSunJsseNegotiatedCurve(SSLSocket socket) { |
250 | 251 | try { |
251 | | - javax.net.ssl.SSLSession session = socket.getSession(); |
| 252 | + SSLSession session = socket.getSession(); |
252 | 253 | if (session.getClass().getName().equals("sun.security.ssl.SSLSessionImpl")) { |
253 | | - java.lang.reflect.Field field = session.getClass().getDeclaredField("negotiatedMaxGroup"); |
| 254 | + Field field = session.getClass().getDeclaredField("negotiatedMaxGroup"); |
254 | 255 | field.setAccessible(true); |
255 | 256 | Object namedGroup = field.get(session); |
256 | 257 | if (namedGroup != null) { |
257 | | - java.lang.reflect.Field nameField = namedGroup.getClass().getDeclaredField("name"); |
| 258 | + Field nameField = namedGroup.getClass().getDeclaredField("name"); |
258 | 259 | nameField.setAccessible(true); |
259 | 260 | return (String) nameField.get(namedGroup); |
260 | 261 | } |
|
0 commit comments