GRPC - .IllegalArgumentException: Jetty ALPN/NPN 没有正确配置
GRPC - .IllegalArgumentException: Jetty ALPN/NPN has not been properly configured
我正在尝试在 pods 上的 docker 容器中启用 TLS 启动 GRPC 服务器,但在服务器启动期间出现以下错误
我正在尝试参考 https://github.com/grpc/grpc-java/blob/master/SECURITY.md#transport-security-tls
Java : jdk1.8.0_131
OpenSSL 版本:OpenSSL 1.0.1e-fips
异常:
*Exception in thread "main" java.lang.IllegalArgumentException: Jetty ALPN/NPN has not been properly configured.
at io.grpc.netty.GrpcSslContexts.selectApplicationProtocolConfig(GrpcSslContexts.java:174)
at io.grpc.netty.GrpcSslContexts.configure(GrpcSslContexts.java:151)
at io.grpc.netty.GrpcSslContexts.configure(GrpcSslContexts.java:139)
at io.grpc.netty.GrpcSslContexts.forServer(GrpcSslContexts.java:119)
at io.grpc.netty.NettyServerBuilder.useTransportSecurity(NettyServerBuilder.java:377)
at io.grpc.netty.NettyServerBuilder.useTransportSecurity(NettyServerBuilder.java:63)*
还想知道如何在本地测试 openssl 方法?
这就是我尝试 运行 jar 的方式:java -jar -Denv=e1 app.jar
以下是特定于 GRPC 的其他 GRPC 相关 POM 依赖项 - 我在我的 POM 中:
-- 扩展 --
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.4.0.Final</version>
</extension>
</extensions>
--- 插件 ----
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.5.0</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:3.2.0:exe:${os.detected.classifier}</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.3.0:exe:${os.detected.classifier}</pluginArtifact>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>
---依赖关系---
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-protobuf</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-stub</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-boringssl-static</artifactId>
<version>2.0.1.Final</version>
</dependency>
Openssl / jdk 版本会是问题吗?
您需要添加对 Netty TCNative 的依赖才能获得正确的安全依赖。在 gRPC 的 SECURITY.md 文件中,您需要添加以下内容:
<project>
<dependencies>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-boringssl-static</artifactId>
<version>1.1.33.Fork26</version>
</dependency>
</dependencies>
</project>
请注意,这将在即将发布的 gRPC 1.4 版本中更改为指向 netty-tcnative-parent-2.0.1.Final
虽然这个问题已经回答了。直到今天我都处于类似的情况,因为我无法启动码头服务器(嵌入式)。
此解决方案可能会帮助一些正在使用 spring 带有嵌入式码头服务器的启动应用程序。
以下应该是 pom.xml 文件中的条目。
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative</artifactId>
<version>2.0.6.Final</version>
<classifier>${os.detected.classifier}</classifier>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-boringssl-static</artifactId>
<version>2.0.6.Final</version>
<classifier>${os.detected.classifier}</classifier>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.mortbay.jetty.alpn</groupId>
<artifactId>alpn-boot</artifactId>
<version>8.1.11.v20170118</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.alpn</groupId>
<artifactId>alpn-api</artifactId>
<version>1.1.3.v20160715</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
alpn-boot 的版本应该取决于您使用的JDK。请参考以下link查看版本:
http://www.eclipse.org/jetty/documentation/current/alpn-chapter.html#alpn-versions
完成此操作后,如果您使用 STS 启动 spring 引导应用程序,请重建您的项目并将以下条目添加到您的 JVM 参数中。
java-Xbootclasspath/p:%path_to_alpn_boot_jar%
然后启动服务器,它应该可以工作了。
谢谢。
我正在尝试在 pods 上的 docker 容器中启用 TLS 启动 GRPC 服务器,但在服务器启动期间出现以下错误
我正在尝试参考 https://github.com/grpc/grpc-java/blob/master/SECURITY.md#transport-security-tls
Java : jdk1.8.0_131 OpenSSL 版本:OpenSSL 1.0.1e-fips
异常:
*Exception in thread "main" java.lang.IllegalArgumentException: Jetty ALPN/NPN has not been properly configured.
at io.grpc.netty.GrpcSslContexts.selectApplicationProtocolConfig(GrpcSslContexts.java:174)
at io.grpc.netty.GrpcSslContexts.configure(GrpcSslContexts.java:151)
at io.grpc.netty.GrpcSslContexts.configure(GrpcSslContexts.java:139)
at io.grpc.netty.GrpcSslContexts.forServer(GrpcSslContexts.java:119)
at io.grpc.netty.NettyServerBuilder.useTransportSecurity(NettyServerBuilder.java:377)
at io.grpc.netty.NettyServerBuilder.useTransportSecurity(NettyServerBuilder.java:63)*
还想知道如何在本地测试 openssl 方法?
这就是我尝试 运行 jar 的方式:java -jar -Denv=e1 app.jar
以下是特定于 GRPC 的其他 GRPC 相关 POM 依赖项 - 我在我的 POM 中: -- 扩展 --
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.4.0.Final</version>
</extension>
</extensions>
--- 插件 ----
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.5.0</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:3.2.0:exe:${os.detected.classifier}</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.3.0:exe:${os.detected.classifier}</pluginArtifact>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>
---依赖关系---
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-protobuf</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-stub</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-boringssl-static</artifactId>
<version>2.0.1.Final</version>
</dependency>
Openssl / jdk 版本会是问题吗?
您需要添加对 Netty TCNative 的依赖才能获得正确的安全依赖。在 gRPC 的 SECURITY.md 文件中,您需要添加以下内容:
<project>
<dependencies>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-boringssl-static</artifactId>
<version>1.1.33.Fork26</version>
</dependency>
</dependencies>
</project>
请注意,这将在即将发布的 gRPC 1.4 版本中更改为指向 netty-tcnative-parent-2.0.1.Final
虽然这个问题已经回答了。直到今天我都处于类似的情况,因为我无法启动码头服务器(嵌入式)。
此解决方案可能会帮助一些正在使用 spring 带有嵌入式码头服务器的启动应用程序。
以下应该是 pom.xml 文件中的条目。
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative</artifactId>
<version>2.0.6.Final</version>
<classifier>${os.detected.classifier}</classifier>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-boringssl-static</artifactId>
<version>2.0.6.Final</version>
<classifier>${os.detected.classifier}</classifier>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.mortbay.jetty.alpn</groupId>
<artifactId>alpn-boot</artifactId>
<version>8.1.11.v20170118</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.alpn</groupId>
<artifactId>alpn-api</artifactId>
<version>1.1.3.v20160715</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
alpn-boot 的版本应该取决于您使用的JDK。请参考以下link查看版本: http://www.eclipse.org/jetty/documentation/current/alpn-chapter.html#alpn-versions
完成此操作后,如果您使用 STS 启动 spring 引导应用程序,请重建您的项目并将以下条目添加到您的 JVM 参数中。
java-Xbootclasspath/p:%path_to_alpn_boot_jar%
然后启动服务器,它应该可以工作了。
谢谢。