--- a/jdk/src/java.base/share/classes/sun/security/ssl/ServerHandshaker.java Wed Dec 02 03:29:49 2015 +0000
+++ b/jdk/src/java.base/share/classes/sun/security/ssl/ServerHandshaker.java Wed Dec 02 03:37:29 2015 +0000
@@ -528,6 +528,36 @@
}
}
+ // check the ALPN extension
+ ALPNExtension clientHelloALPN = (ALPNExtension)
+ mesg.extensions.get(ExtensionType.EXT_ALPN);
+
+ if ((clientHelloALPN != null) && (localApl.length > 0)) {
+
+ // Intersect the requested and the locally supported,
+ // and save for later.
+ String negotiatedValue = null;
+ List<String> protocols = clientHelloALPN.getPeerAPs();
+
+ // Use server preference order
+ for (String ap : localApl) {
+ if (protocols.contains(ap)) {
+ negotiatedValue = ap;
+ break;
+ }
+ }
+
+ if (negotiatedValue == null) {
+ fatalSE(Alerts.alert_no_application_protocol,
+ new SSLHandshakeException(
+ "No matching ALPN values"));
+ }
+ applicationProtocol = negotiatedValue;
+
+ } else {
+ applicationProtocol = "";
+ }
+
// cookie exchange
if (isDTLS) {
HelloCookieManager hcMgr = sslContext.getHelloCookieManager();
@@ -921,6 +951,11 @@
}
}
+ // Prepare the ALPN response
+ if (applicationProtocol != null && !applicationProtocol.isEmpty()) {
+ m1.extensions.add(new ALPNExtension(applicationProtocol));
+ }
+
if (debug != null && Debug.isOn("handshake")) {
m1.print(System.out);
System.out.println("Cipher suite: " + session.getSuite());