Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8349121: SSLParameters.setApplicationProtocols() ALPN example could be clarified #23379

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions src/java.base/share/classes/javax/net/ssl/SSLParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -653,19 +653,28 @@ public String[] getApplicationProtocols() {
* {@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.
* For example:
*
* <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);
* // Encode 3 Meetei Mayek letters (HUK, UN, I) using Unicode Escapes
* // 0xabcd->0xabcf, 2 Unicode bytes/letter.
* String HUK_UN_I = "\u005cuabcd\u005cuabce\u005cuabcf";
bradfordwetmore marked this conversation as resolved.
Show resolved Hide resolved
*
* // 0x00-0xFF: 1 byte
* String rfc7301Grease8A = "\u005cu008A\u005cu008A";
* // Convert into UTF-8 encoded bytes (3 bytes/letter)
* byte[] bytes = HUK_UN_I.getBytes(StandardCharsets.UTF_8);
*
* // Preserve octet byte order by using ISO_8859_1 encoding
* String encodedHukUnI =
* new String(bytes, StandardCharsets.ISO_8859_1);
bradfordwetmore marked this conversation as resolved.
Show resolved Hide resolved
*
* // Also, encode a two byte RFC 8701 GREASE ALPN value
* // e.g. 0x0A, 0x1A, 0x2A...0xFA
* String rfc8701Grease8A = "\u005cu008A\u005cu008A";
bradfordwetmore marked this conversation as resolved.
Show resolved Hide resolved
*
* // Set the ALPN vlues on the sslSocket.
* SSLParameters p = sslSocket.getSSLParameters();
* p.setApplicationProtocols(new String[] {
* "h2", "http/1.1", rfc7301Grease8A, HUK_UN_I});
* "h2", "http/1.1", encodedHukUnI, rfc8701Grease8A});
* sslSocket.setSSLParameters(p);
* </pre></blockquote>
*
Expand Down