question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exception when configuring SSL: "Jetty ALPN/NPN has not been properly configured." (and possible solution)

See original GitHub issue

I am unable to configure an SSL gRPC.

SslContextBuilder sslBuilder = GrpcSslContexts.forServer(new File("a"), new File("b"))
sslBuilder.build();

Causes this exception:

Exception in thread "main" java.lang.IllegalArgumentException: Jetty ALPN/NPN has not been properly configured.
        at io.grpc.netty.GrpcSslContexts.selectApplicationProtocolConfig(GrpcSslContexts.java:143)
        at io.grpc.netty.GrpcSslContexts.configure(GrpcSslContexts.java:120)
        at io.grpc.netty.GrpcSslContexts.configure(GrpcSslContexts.java:109)
        at io.grpc.netty.GrpcSslContexts.forServer(GrpcSslContexts.java:90)

I think the root cause is here:

/**
   * Indicates whether or not the Jetty ALPN jar is installed in the boot classloader.
   */
  static boolean isJettyAlpnConfigured() {
    try {
      Class.forName("org.eclipse.jetty.alpn.ALPN", true, null);
      return true;
    } catch (ClassNotFoundException e) {
      return false;
    }
  }

This method is restricting the search to the boot classloader, which I don’t think is correct. i.e. in the following code, the first line executes fine, but the second line throws CNFE (despite the class being loaded), causing isJettyAlpnConfigured() to return false:

System.out.println("Class loaded? " + org.eclipse.jetty.alpn.ALPN.class);
System.out.println("Maybe not: " + Class.forName("org.eclipse.jetty.alpn.ALPN", true, null));

I suspect the Class.forName(String) variant should be used instead (which doesn’t throw CNFE), but maybe there was some good rationale for restricting to the boot classpath?

FWIW I am using alpn-api-1.1.2.v20150522.jar with the following other deps: grpc-all-0.9.0.jar hpack-0.10.1.jar netty-all-4.1.0.Beta6.jar okhttp-2.4.0.jar okio-1.6.0.jar protobuf-java-3.0.0-beta-1.jar

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
qiang-daicommented, Apr 28, 2017

This is my way:

  1. Edit catalina.sh /usr/local/Cellar/tomcat/8.5.3/libexec/bin/catalina.sh
  2. At line 103, add the following CATALINA_OPTS="-javaagent:/Library/Tomcat/lib/jetty-alpn-agent-2.0.6.jar"
  3. Restart tomcat ../bin/shutdown.sh ../bin/startup.sh
0reactions
prayagupacommented, Mar 11, 2018

For non-tomcat app, I could make it work with -javaagent on CentOS; which is documented in https://github.com/grpc/grpc-java/blob/master/SECURITY.md#tls-with-jdk-jetty-alpnnpn. BUT For some reason does not require jetty-alpn on MacOS.

wget http://central.maven.org/maven2/org/mortbay/jetty/alpn/jetty-alpn-agent/2.0.7/jetty-alpn-agent-2.0.7.jar

/home/prayagupd/jdk1.8.0_161/bin/java -jar 
-Djavax.net.ssl.keyStore=/home/prayagupd/keystore/keystore.jks 
-Djavax.net.ssl.keyStorePassword=password 
-Djavax.net.ssl.trustStore=/home/prayagupd/keystore/truststore.jks 
-Djavax.net.ssl.trustStorePassword=password 
-javaagent:jetty-alpn-agent-2.0.7.jar nlu-intent-toolkit.jar test-agent "music venues near me?" credentials.json
Read more comments on GitHub >

github_iconTop Results From Across the Web

Jetty ALPN/NPN has not been properly configured - Stack ...
This solution might help some who is using spring boot application with embedded jetty server. Following should be the entries in pom.xml file....
Read more >
Jetty ALPN/NPN has not been properly configured.
Jetty ALPN/NPN has not been properly configured. Here is the traceback. java.lang.IllegalArgumentException: Could not instantiate implementation: ...
Read more >
Jetty ALPN/NPN has not been properly configured — Solution
In order to fix this, we need to configure an ALPN client that matches our JDK version for our project.
Read more >
Authentication
ALPN is a fairly new standard and (where possible) gRPC also supports ... or “Jetty ALPN/NPN has not been properly configured”, it most...
Read more >
Jetty ALPN/NPN has not been properly configured-Springboot
[Solved]-java.lang.IllegalArgumentException: Jetty ALPN/NPN has not been properly configured-Springboot ... Try adding a runtime dependency on netty-tcnative- ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found