Skip to content

Commit

Permalink
Fixes #5: selected() not run for cached sessions.
Browse files Browse the repository at this point in the history
Now properly calling the selected() method on the client in case of
SSL session resumption.

Also completely rewrote tests to cover more cases.
  • Loading branch information
sbordet committed Dec 2, 2014
1 parent cee36c3 commit d6eefa7
Show file tree
Hide file tree
Showing 4 changed files with 636 additions and 915 deletions.
54 changes: 31 additions & 23 deletions alpn-boot/src/main/java/sun/security/ssl/ClientHandshaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,9 @@ public Subject run() throws Exception {
// abbreviated initial handshake.
if (isInitialHandshake) {
session.setAsSessionResumption(true);
// ALPN_CHANGES_BEGIN
alpnSelected(mesg);
// ALPN_CHANGES_END
}

return;
Expand Down Expand Up @@ -660,42 +663,47 @@ public Subject run() throws Exception {

// ALPN_CHANGES_BEGIN
if (isInitialHandshake)
alpnSelected(mesg);
// ALPN_CHANGES_END
}

// ALPN_CHANGES_BEGIN
private void alpnSelected(ServerHello mesg) throws IOException
{
ALPN.ClientProvider provider = (ALPN.ClientProvider)(conn != null ? ALPN.get(conn) : ALPN.get(engine));
Object ssl = conn != null ? conn : engine;
if (provider != null)
{
ALPN.ClientProvider provider = (ALPN.ClientProvider)(conn != null ? ALPN.get(conn) : ALPN.get(engine));
Object ssl = conn != null ? conn : engine;
if (provider != null)
ALPNExtension extension = (ALPNExtension)mesg.extensions.get(ExtensionType.EXT_ALPN);
if (extension != null)
{
ALPNExtension extension = (ALPNExtension)mesg.extensions.get(ExtensionType.EXT_ALPN);
if (extension != null)
List<String> protocols = extension.getProtocols();
try
{
List<String> protocols = extension.getProtocols();
try
{
String protocol = protocols == null || protocols.isEmpty() ? null : protocols.get(0);
if (ALPN.debug)
System.err.println("[C] ALPN protocol '" + protocol + "' selected by server for " + ssl);
provider.selected(protocol);
}
catch (Throwable x)
{
fatalSE(Alerts.alert_no_application_protocol, "Could not negotiate application protocol", x);
}
String protocol = protocols == null || protocols.isEmpty() ? null : protocols.get(0);
if (ALPN.debug)
System.err.println("[C] ALPN protocol '" + protocol + "' selected by server for " + ssl);
provider.selected(protocol);
}
else
catch (Throwable x)
{
if (ALPN.debug)
System.err.println("[C] ALPN not supported by server for " + ssl);
provider.unsupported();
fatalSE(Alerts.alert_no_application_protocol, "Could not negotiate application protocol", x);
}
}
else
{
if (ALPN.debug)
System.err.println("[C] ALPN client provider not present for " + ssl);
System.err.println("[C] ALPN not supported by server for " + ssl);
provider.unsupported();
}
}
// ALPN_CHANGES_END
else
{
if (ALPN.debug)
System.err.println("[C] ALPN client provider not present for " + ssl);
}
}
// ALPN_CHANGES_END

/*
* Server's own key was either a signing-only key, or was too
Expand Down
Loading

0 comments on commit d6eefa7

Please sign in to comment.