Skip to content

Commit

Permalink
Merge pull request apache#256 from lizhanhui/openssl
Browse files Browse the repository at this point in the history
feat: use openssl SSL provider to create TLS/SSL engine, adding netty…
  • Loading branch information
lizhanhui authored Apr 11, 2024
2 parents 7b556f9 + e68ee8e commit 648b73e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
6 changes: 5 additions & 1 deletion mqtt-cs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-boringssl-static</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down Expand Up @@ -78,4 +82,4 @@
</dependency>
</dependencies>

</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,18 @@ private void initSslContext() {
return;
}

SslProvider sslProvider = OpenSsl.isAvailable() ? SslProvider.OPENSSL : SslProvider.JDK;
if (OpenSsl.isAvailable()) {
LOG.info("OpenSSL is available");
} else {
LOG.warn("OpenSSL is NOT available, falling back to JDK SslEngine");
}
try {
InputStream certStream = new ClassPathResource(CERT_FILE_NAME).getInputStream();
InputStream keyStream = new ClassPathResource(KEY_FILE_NAME).getInputStream();
SslContextBuilder contextBuilder = SslContextBuilder.forServer(certStream, keyStream);
contextBuilder.clientAuth(ClientAuth.OPTIONAL);
contextBuilder.sslProvider(OpenSsl.isAvailable() ? SslProvider.OPENSSL : SslProvider.JDK);
contextBuilder.sslProvider(sslProvider);
if (connectConf.isNeedClientAuth()) {
LOG.info("client tls authentication is required.");
contextBuilder.clientAuth(ClientAuth.REQUIRE);
Expand Down
7 changes: 4 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
<rpc-grpc-impl.version>1.3.8</rpc-grpc-impl.version>
<guava.version>32.0.0-jre</guava.version>
<jraft-core.version>1.3.11</jraft-core.version>

<netty.version>4.1.43.Final</netty.version>
<netty.tcnative.version>2.0.26.Final</netty.tcnative.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -95,12 +96,12 @@
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.43.Final</version>
<version>${netty.version}</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-boringssl-static</artifactId>
<version>2.0.26.Final</version>
<version>${netty.tcnative.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
Expand Down

0 comments on commit 648b73e

Please sign in to comment.