mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8254631: Better support ALPN byte wire values in SunJSSE
Reviewed-by: xuelei, dfuchs
This commit is contained in:
parent
541c7f74bb
commit
fe5cccc1ec
6 changed files with 450 additions and 11 deletions
|
@ -336,6 +336,48 @@ import java.util.function.BiFunction;
|
|||
* started, an {@code SSLEngine} can not switch between client and server
|
||||
* modes, even when performing renegotiations.
|
||||
* <P>
|
||||
* The ApplicationProtocol {@code String} values returned by the methods
|
||||
* in this class are in the network byte representation sent by the peer.
|
||||
* The bytes could be directly compared, or converted to its Unicode
|
||||
* {code String} format for comparison.
|
||||
*
|
||||
* <blockquote><pre>
|
||||
* String networkString = sslEngine.getHandshakeApplicationProtocol();
|
||||
* byte[] bytes = networkString.getBytes(StandardCharsets.ISO_8859_1);
|
||||
*
|
||||
* //
|
||||
* // Match using bytes:
|
||||
* //
|
||||
* // "http/1.1" (7-bit ASCII values same in UTF-8)
|
||||
* // MEETEI MAYEK LETTERS "HUK UN I" (Unicode 0xabcd->0xabcf)
|
||||
* //
|
||||
* String HTTP1_1 = "http/1.1";
|
||||
* byte[] HTTP1_1_BYTES = HTTP1_1.getBytes(StandardCharsets.UTF_8);
|
||||
*
|
||||
* byte[] HUK_UN_I_BYTES = new byte[] {
|
||||
* (byte) 0xab, (byte) 0xcd,
|
||||
* (byte) 0xab, (byte) 0xce,
|
||||
* (byte) 0xab, (byte) 0xcf};
|
||||
*
|
||||
* if ((Arrays.compare(bytes, HTTP1_1_BYTES) == 0 )
|
||||
* || Arrays.compare(bytes, HUK_UN_I_BYTES) == 0) {
|
||||
* ...
|
||||
* }
|
||||
*
|
||||
* //
|
||||
* // Alternatively match using string.equals() if we know the ALPN value
|
||||
* // was encoded from a {@code String} using a certain character set,
|
||||
* // for example {@code UTF-8}. The ALPN value must first be properly
|
||||
* // decoded to a Unicode {@code String} before use.
|
||||
* //
|
||||
* String unicodeString = new String(bytes, StandardCharsets.UTF_8);
|
||||
* if (unicodeString.equals(HTTP1_1)
|
||||
* || unicodeString.equals("\u005cuabcd\u005cuabce\u005cuabcf")) {
|
||||
* ...
|
||||
* }
|
||||
* </pre></blockquote>
|
||||
*
|
||||
* <P>
|
||||
* Applications might choose to process delegated tasks in different
|
||||
* threads. When an {@code SSLEngine}
|
||||
* is created, the current {@link java.security.AccessControlContext}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -646,6 +646,27 @@ public class SSLParameters {
|
|||
* requested by the peer, the underlying protocol will determine what
|
||||
* action to take. (For example, ALPN will send a
|
||||
* {@code "no_application_protocol"} alert and terminate the connection.)
|
||||
* <p>
|
||||
* The {@code String} values must be presented using the network
|
||||
* byte representation expected by the peer. For example, if an ALPN
|
||||
* {@code String} should be exchanged using {@code UTF-8}, the
|
||||
* {@code String} should be converted to its {@code byte[]} representation
|
||||
* and stored as a byte-oriented {@code String} before calling this method.
|
||||
*
|
||||
* <blockquote><pre>
|
||||
* // MEETEI MAYEK LETTERS HUK UN I (Unicode 0xabcd->0xabcf): 2 bytes
|
||||
* byte[] bytes = "\u005cuabcd\u005cuabce\u005cuabcf"
|
||||
* .getBytes(StandardCharsets.UTF_8);
|
||||
* String HUK_UN_I = new String(bytes, StandardCharsets.ISO_8859_1);
|
||||
*
|
||||
* // 0x00-0xFF: 1 byte
|
||||
* String rfc7301Grease8F = "\u005c008F\u005c008F";
|
||||
*
|
||||
* SSLParameters p = sslSocket.getSSLParameters();
|
||||
* p.setApplicationProtocols(new String[] {
|
||||
* "h2", "http/1.1", rfc7301Grease8F, HUK_UN_I});
|
||||
* sslSocket.setSSLParameters(p);
|
||||
* </pre></blockquote>
|
||||
*
|
||||
* @implSpec
|
||||
* This method will make a copy of the {@code protocols} array.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -130,6 +130,47 @@ import java.util.function.BiFunction;
|
|||
* socket can not switch between client and server modes, even when
|
||||
* performing renegotiations.
|
||||
*
|
||||
* <P> The ApplicationProtocol {@code String} values returned by the methods
|
||||
* in this class are in the network byte representation sent by the peer.
|
||||
* The bytes could be directly compared, or converted to its Unicode
|
||||
* {code String} format for comparison.
|
||||
*
|
||||
* <blockquote><pre>
|
||||
* String networkString = sslSocket.getHandshakeApplicationProtocol();
|
||||
* byte[] bytes = networkString.getBytes(StandardCharsets.ISO_8859_1);
|
||||
*
|
||||
* //
|
||||
* // Match using bytes:
|
||||
* //
|
||||
* // "http/1.1" (7-bit ASCII values same in UTF-8)
|
||||
* // MEETEI MAYEK LETTERS "HUK UN I" (Unicode 0xabcd->0xabcf)
|
||||
* //
|
||||
* String HTTP1_1 = "http/1.1";
|
||||
* byte[] HTTP1_1_BYTES = HTTP1_1.getBytes(StandardCharsets.UTF_8);
|
||||
*
|
||||
* byte[] HUK_UN_I_BYTES = new byte[] {
|
||||
* (byte) 0xab, (byte) 0xcd,
|
||||
* (byte) 0xab, (byte) 0xce,
|
||||
* (byte) 0xab, (byte) 0xcf};
|
||||
*
|
||||
* if ((Arrays.compare(bytes, HTTP1_1_BYTES) == 0 )
|
||||
* || Arrays.compare(bytes, HUK_UN_I_BYTES) == 0) {
|
||||
* ...
|
||||
* }
|
||||
*
|
||||
* //
|
||||
* // Alternatively match using string.equals() if we know the ALPN value
|
||||
* // was encoded from a {@code String} using a certain character set,
|
||||
* // for example {@code UTF-8}. The ALPN value must first be properly
|
||||
* // decoded to a Unicode {@code String} before use.
|
||||
* //
|
||||
* String unicodeString = new String(bytes, StandardCharsets.UTF_8);
|
||||
* if (unicodeString.equals(HTTP1_1)
|
||||
* || unicodeString.equals("\u005cuabcd\u005cuabce\u005cuabcf")) {
|
||||
* ...
|
||||
* }
|
||||
* </pre></blockquote>
|
||||
*
|
||||
* @apiNote
|
||||
* When the connection is no longer needed, the client and server
|
||||
* applications should each close both sides of their respective connection.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue