// SunJSSE does not support dynamic system properties, no way to re-use // system properties in samevm/agentvm mode. For further debugging output // set the -Djavax.net.debug=ssl:handshake property on the @run lines.
// ClientHello fields finalint version; finalbyte[] random; finalbyte[] sessId; final List<Integer> cipherSuites = new ArrayList<>(); final List<Integer> compressionList = new ArrayList<>(); final Map<Integer,byte[]> extensionMap = new LinkedHashMap<>();
// These are fields built from specific extension data fields we // are interested in for our tests final List<Integer> suppGroups = new ArrayList<>(); final Map<Integer,byte[]> keyShares = new LinkedHashMap<>(); final List<Integer> suppVersions = new ArrayList<>();
// Create and check the ClientHello message
SSLEngineResult clientResult = engine.wrap(clientOut, cTOs);
logResult("client wrap: ", clientResult); if (clientResult.getStatus() != SSLEngineResult.Status.OK) { thrownew RuntimeException("Client wrap got status: " +
clientResult.getStatus());
}
cTOs.flip();
System.out.println("----- ORIGINAL CLIENT HELLO -----\n" +
dumpHexBytes(cTOs));
ClientHello initialCh = new ClientHello(cTOs);
if (!initialCh.suppVersions.contains(TLS_PROT_VER_13)) { thrownew RuntimeException( "Missing TLSv1.3 protocol in supported_versions");
} elseif (!initialCh.keyShares.containsKey(NG_X25519) ||
!initialCh.keyShares.containsKey(NG_SECP256R1)) { thrownew RuntimeException( "Missing one or more expected KeyShares");
}
// Craft the HRR message with the passed-in named group as the // key share named group to request.
ByteBuffer sTOc = buildHRRMessage(initialCh, hrrNamedGroup);
System.out.println("----- SERVER HELLO RETRY REQUEST -----\n" +
dumpHexBytes(sTOc));
// Unwrap the HRR and process it
clientResult = engine.unwrap(sTOc, clientOut);
logResult("client unwrap: ", clientResult); if (clientResult.getStatus() != SSLEngineResult.Status.OK) { thrownew RuntimeException("Client wrap got status: " +
clientResult.getStatus());
}
runDelegatedTasks(engine);
try { // Now we're expecting to reissue the ClientHello, this time // with a secp384r1 share.
cTOs.compact();
clientResult = engine.wrap(clientOut, cTOs);
logResult("client wrap: ", clientResult); if (clientResult.getStatus() != SSLEngineResult.Status.OK) { thrownew RuntimeException("Client wrap got status: " +
clientResult.getStatus());
}
} catch (RuntimeException | SSLException ssle) { if (expectedPass) {
System.out.println("Caught unexpected exception"); throw ssle;
} else {
System.out.println("Caught expected exception: " + ssle);
// Try issuing another wrap call and see if we can get // the Alert out.
clientResult = engine.wrap(clientOut, cTOs);
logResult("client wrap: ", clientResult); if (clientResult.getStatus() != SSLEngineResult.Status.CLOSED) { thrownew RuntimeException("Client wrap got status: " +
clientResult.getStatus());
}
if (!reissuedCh.keyShares.containsKey(hrrNamedGroup)) { thrownew RuntimeException("Missing secp384r1 key share");
}
}
privatestatic ByteBuffer buildHRRMessage(ClientHello cliHello, int namedGroup) throws IOException { // Create a ByteBuffer that will be large enough to handle // the HelloRetryRequest
ByteBuffer hrrBuf = ByteBuffer.allocate(2048); // More than enough!
// Advance past the TLS record and handshake message headers. We will // go back later and scribble in the proper lengths. The record header // is 5 bytes long, the handshake header is 4.
hrrBuf.position(9);
hrrBuf.putShort((short)TLS_LEGACY_VER);
hrrBuf.put(HRR_RANDOM);
hrrBuf.put((byte)cliHello.sessId.length);
hrrBuf.put(cliHello.sessId);
hrrBuf.putShort(cliHello.cipherSuites.get(0).shortValue());
hrrBuf.put((byte)COMP_NONE);
// Use a separate stream for creating the extension section
ByteArrayOutputStream extBaos = new ByteArrayOutputStream();
DataOutputStream extStream = new DataOutputStream(extBaos);
// Supported version
extStream.writeShort(HELLO_EXT_SUPP_VERS);
extStream.writeShort(2);
extStream.writeShort(TLS_PROT_VER_13);
// Now add in the extensions into the main message
hrrBuf.putShort((short)extStream.size());
hrrBuf.put(extBaos.toByteArray());
// At this point we can go back and write in the TLS record and // handshake message headers.
hrrBuf.flip();
// Write in the TLS record header
hrrBuf.put((byte)TLS_REC_HANDSHAKE);
hrrBuf.putShort((short)TLS_LEGACY_VER);
hrrBuf.putShort((short)(hrrBuf.limit() - 5));
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.