Skip to content

Commit 47180d2

Browse files
committed
debug: add logging
1 parent 0bb986c commit 47180d2

2 files changed

Lines changed: 63 additions & 2 deletions

File tree

pqc-test/pqc-test-common/src/main/java/com/google/api/gax/httpjson/PqcConnectivityTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,18 @@ protected boolean clientSupportsPqc() {
169169

170170
@BeforeAll
171171
public static void setup() throws Exception {
172+
// Configure verbose Bouncy Castle and standard JJSSE debug logging on client-side
173+
java.util.logging.Logger rootLogger = java.util.logging.Logger.getLogger("org.bouncycastle");
174+
rootLogger.setLevel(java.util.logging.Level.FINEST);
175+
java.util.logging.Logger globalLogger = java.util.logging.Logger.getLogger("");
176+
globalLogger.setLevel(java.util.logging.Level.FINEST);
177+
for (java.util.logging.Handler handler : globalLogger.getHandlers()) {
178+
handler.setLevel(java.util.logging.Level.FINEST);
179+
}
180+
System.setProperty("javax.net.debug", "ssl,handshake");
181+
182+
System.out.println("[PQC-CLIENT-SETUP] Starting client logging setup.");
183+
System.out.println("[PQC-CLIENT-SETUP] Registered Security Providers: " + java.util.Arrays.toString(java.security.Security.getProviders()));
172184

173185
// Dynamically detect if PQC auto-upgrade wrapping is supported by current
174186
// classpath
@@ -193,6 +205,7 @@ public static void setup() throws Exception {
193205
ProcessBuilder pb =
194206
new ProcessBuilder(
195207
"java",
208+
"-Djavax.net.debug=ssl,handshake",
196209
"-cp",
197210
System.getProperty("java.class.path"),
198211
"com.google.api.gax.pqc.PqcTestServer");

pqc-test/pqc-test-common/src/main/java/com/google/api/gax/pqc/PqcTestServer.java

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public class PqcTestServer {
6464
private int grpcPort;
6565

6666
public void start() throws Exception {
67+
setupLogging();
6768

6869
KeyStore ks = KeyStore.getInstance("PKCS12");
6970
try (InputStream is = getClass().getResourceAsStream("/pqctest.p12")) {
@@ -213,6 +214,17 @@ public int getGrpcPort() {
213214
return grpcPort;
214215
}
215216

217+
private static void setupLogging() {
218+
java.util.logging.Logger rootLogger = java.util.logging.Logger.getLogger("org.bouncycastle");
219+
rootLogger.setLevel(java.util.logging.Level.FINEST);
220+
java.util.logging.Logger globalLogger = java.util.logging.Logger.getLogger("");
221+
globalLogger.setLevel(java.util.logging.Level.FINEST);
222+
for (java.util.logging.Handler handler : globalLogger.getHandlers()) {
223+
handler.setLevel(java.util.logging.Level.FINEST);
224+
}
225+
System.setProperty("javax.net.debug", "ssl,handshake");
226+
}
227+
216228
private static class ByteMarshaller implements io.grpc.MethodDescriptor.Marshaller<byte[]> {
217229
@Override
218230
public InputStream stream(byte[] value) {
@@ -257,13 +269,21 @@ private static class PqcEnforcingSSLEngine extends javax.net.ssl.SSLEngine {
257269

258270
@Override
259271
public void setSSLParameters(javax.net.ssl.SSLParameters params) {
272+
System.out.println("[PQC-SERVER-ENGINE] Calling setSSLParameters with params: " + params);
273+
if (params != null) {
274+
System.out.println("[PQC-SERVER-ENGINE] Protocols: " + java.util.Arrays.toString(params.getProtocols()));
275+
System.out.println("[PQC-SERVER-ENGINE] CipherSuites: " + java.util.Arrays.toString(params.getCipherSuites()));
276+
}
260277
delegate.setSSLParameters(params);
261278
Object objEngine = delegate;
262279
if (objEngine instanceof org.bouncycastle.jsse.BCSSLEngine) {
263280
org.bouncycastle.jsse.BCSSLEngine bcEngine = (org.bouncycastle.jsse.BCSSLEngine) objEngine;
264281
org.bouncycastle.jsse.BCSSLParameters bcParams = bcEngine.getParameters();
282+
System.out.println("[PQC-SERVER-ENGINE] BCSSLEngine detected. Setting named groups to: [X25519MLKEM768]");
265283
bcParams.setNamedGroups(new String[] {"X25519MLKEM768"});
266284
bcEngine.setParameters(bcParams);
285+
} else {
286+
System.out.println("[PQC-SERVER-ENGINE] WARNING: Delegate engine is NOT an instance of BCSSLEngine! Actual class: " + objEngine.getClass().getName());
267287
}
268288
}
269289

@@ -398,14 +418,42 @@ public void setWantClientAuth(boolean want) {
398418
public javax.net.ssl.SSLEngineResult unwrap(
399419
java.nio.ByteBuffer src, java.nio.ByteBuffer[] dsts, int offset, int length)
400420
throws javax.net.ssl.SSLException {
401-
return delegate.unwrap(src, dsts, offset, length);
421+
try {
422+
javax.net.ssl.SSLEngineResult result = delegate.unwrap(src, dsts, offset, length);
423+
logEngineResult("unwrap", result);
424+
return result;
425+
} catch (javax.net.ssl.SSLException e) {
426+
System.out.println("[PQC-SERVER-ENGINE] unwrap failed: " + e.getMessage());
427+
e.printStackTrace(System.out);
428+
throw e;
429+
}
402430
}
403431

404432
@Override
405433
public javax.net.ssl.SSLEngineResult wrap(
406434
java.nio.ByteBuffer[] srcs, int offset, int length, java.nio.ByteBuffer dst)
407435
throws javax.net.ssl.SSLException {
408-
return delegate.wrap(srcs, offset, length, dst);
436+
try {
437+
javax.net.ssl.SSLEngineResult result = delegate.wrap(srcs, offset, length, dst);
438+
logEngineResult("wrap", result);
439+
return result;
440+
} catch (javax.net.ssl.SSLException e) {
441+
System.out.println("[PQC-SERVER-ENGINE] wrap failed: " + e.getMessage());
442+
e.printStackTrace(System.out);
443+
throw e;
444+
}
445+
}
446+
447+
private void logEngineResult(String action, javax.net.ssl.SSLEngineResult result) {
448+
javax.net.ssl.SSLSession session = delegate.getHandshakeSession();
449+
if (session == null) {
450+
session = delegate.getSession();
451+
}
452+
String suite = (session != null) ? session.getCipherSuite() : "NONE";
453+
String protocol = (session != null) ? session.getProtocol() : "NONE";
454+
System.out.println("[PQC-SERVER-ENGINE] " + action + " - Status: " + result.getStatus()
455+
+ ", HandshakeStatus: " + result.getHandshakeStatus()
456+
+ ", Session Protocol: " + protocol + ", CipherSuite: " + suite);
409457
}
410458

411459
@Override

0 commit comments

Comments
 (0)