Skip to content

Commit 1dce8df

Browse files
author
nmittler
committed
Switching to netty-tcnative-boringssl-static
1 parent a3303b5 commit 1dce8df

File tree

6 files changed

+94
-51
lines changed

6 files changed

+94
-51
lines changed

.travis.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ language: java
55
env:
66
global:
77
- PROTOBUF_VERSION=3.0.0-beta-2
8-
- OPENSSL_VERSION=1.0.2d
98
- LDFLAGS=-L/tmp/protobuf-${PROTOBUF_VERSION}/lib
109
- CXXFLAGS=-I/tmp/protobuf-${PROTOBUF_VERSION}/include
11-
- LD_LIBRARY_PATH=/tmp/protobuf-${PROTOBUF_VERSION}/lib:/tmp/openssl-${OPENSSL_VERSION}/lib
10+
- LD_LIBRARY_PATH=/tmp/protobuf-${PROTOBUF_VERSION}/lib
1211

1312
before_install:
1413
# Work around https://github.com/travis-ci/travis-ci/issues/2317
@@ -42,7 +41,6 @@ notifications:
4241
cache:
4342
directories:
4443
- /tmp/protobuf-${PROTOBUF_VERSION}
45-
- /tmp/openssl-${OPENSSL_VERSION}
4644
- $HOME/.m2/repository/io/netty
4745
- $HOME/.gradle/caches/modules-2
4846
- $HOME/.gradle/wrapper

SECURITY.md

Lines changed: 88 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,101 @@ You may need to [update the security provider](https://developer.android.com/tra
1616

1717
## TLS with OpenSSL
1818

19-
This is currently the recommended approach for using gRPC over TLS (on non-Android systems).
19+
This is currently the recommended approach for using gRPC over TLS (on non-Android systems).
2020

21-
### Benefits of using OpenSSL
21+
The main benefits of using OpenSSL are:
2222

2323
1. **Speed**: In local testing, we've seen performance improvements of 3x over the JDK. GCM, which is used by the only cipher suite required by the HTTP/2 spec, is 10-500x faster.
2424
2. **Ciphers**: OpenSSL has its own ciphers and is not dependent on the limitations of the JDK. This allows supporting GCM on Java 7.
2525
3. **ALPN to NPN Fallback**: if the remote endpoint doesn't support ALPN.
2626
4. **Version Independence**: does not require using a different library version depending on the JDK update.
2727

28-
### Requirements for using OpenSSL
28+
Support for OpenSSL is only provided for the Netty transport via [netty-tcnative](https://github.com/netty/netty-tcnative), which is a fork of
29+
[Apache Tomcat's tcnative](http://tomcat.apache.org/native-doc/), a JNI wrapper around OpenSSL.
2930

30-
1. Currently only supported by the Netty transport (via netty-tcnative).
31-
2. [OpenSSL](https://www.openssl.org/) version >= 1.0.2 for ALPN support, or version >= 1.0.1 for NPN.
32-
3. [netty-tcnative](https://github.com/netty/netty-tcnative) version >= 1.1.33.Fork7 must be on classpath.
33-
4. Supported platforms (for netty-tcnative): `linux-x86_64`, `mac-x86_64`, `windows-x86_64`. Supporting other platforms will require manually building netty-tcnative.
31+
### OpenSSL: Dynamic vs Static (which to use?)
3432

35-
If the above requirements met, the Netty transport will automatically select OpenSSL as the default TLS provider.
33+
As of version `1.1.33.Fork13`, netty-tcnative provides two options for usage: statically or dynamically linked. For simplification of initial setup,
34+
we recommend that users first look at `netty-tcnative-boringssl-static`, which is statically linked against BoringSSL and Apache APR. Using this artifact requires no extra installation and guarantees that ALPN and the ciphers required for
35+
HTTP/2 are available.
3636

37-
### Configuring netty-tcnative
37+
Production systems, however, may require an easy upgrade path for OpenSSL security patches. In this case, relying on the statically linked artifact also implies waiting for the Netty team
38+
to release the new artifact to Maven Central, which can take some time. A better solution in this case is to use the dynamically linked `netty-tcnative` artifact, which allows the site administrator
39+
to easily upgrade OpenSSL in the standard way (e.g. apt-get) without relying on any new builds from Netty.
3840

39-
[Netty-tcnative](https://github.com/netty/netty-tcnative) is a fork of [Apache Tomcat's tcnative](http://tomcat.apache.org/native-doc/), a JNI wrapper around OpenSSL.
41+
### OpenSSL: Statically Linked (netty-tcnative-boringssl-static)
4042

41-
Netty uses classifiers when deploying to [Maven Central](http://repo1.maven.org/maven2/io/netty/netty-tcnative/) to provide distributions for the various platforms. On Linux it should be noted that OpenSSL uses a different soname for Fedora derivatives than other Linux releases. To work around this limitation, netty-tcnative deploys two separate versions for linux.
43+
This is the simplest way to configure the Netty transport for OpenSSL. You just need to add the appropriate `netty-tcnative-boringssl-static` artifact to your application's classpath.
44+
45+
Artifacts are available on [Maven Central](http://repo1.maven.org/maven2/io/netty/netty-tcnative-boringssl-static/) for the following platforms:
46+
47+
Maven Classifier | Description
48+
---------------- | -----------
49+
windows-x86_64 | Windows distribution
50+
osx-x86_64 | Mac distribution
51+
linux-x86_64 | Linux distribution
52+
53+
##### Getting netty-tcnative-boringssl-static from Maven
54+
55+
In Maven, you can use the [os-maven-plugin](https://github.com/trustin/os-maven-plugin) to help simplify the dependency.
56+
57+
```xml
58+
<project>
59+
<dependencies>
60+
<dependency>
61+
<groupId>io.netty</groupId>
62+
<artifactId>netty-tcnative-boringssl-static</artifactId>
63+
<version>1.1.33.Fork13</version>
64+
<classifier>${os.detected.classifier}</classifier>
65+
</dependency>
66+
</dependencies>
67+
68+
<build>
69+
<extensions>
70+
<!-- Use os-maven-plugin to initialize the "os.detected" properties -->
71+
<extension>
72+
<groupId>kr.motd.maven</groupId>
73+
<artifactId>os-maven-plugin</artifactId>
74+
<version>1.4.0.Final</version>
75+
</extension>
76+
</extensions>
77+
</build>
78+
</project>
79+
```
80+
81+
##### Getting netty-tcnative-boringssl-static from Gradle
82+
83+
Gradle you can use the [osdetector-gradle-plugin](https://github.com/google/osdetector-gradle-plugin), which is a wrapper around the os-maven-plugin.
84+
85+
```gradle
86+
buildscript {
87+
repositories {
88+
mavenCentral()
89+
}
90+
dependencies {
91+
classpath 'com.google.gradle:osdetector-gradle-plugin:1.4.0'
92+
}
93+
}
94+
95+
// Use the osdetector-gradle-plugin
96+
apply plugin: "com.google.osdetector"
97+
98+
dependencies {
99+
compile 'io.netty:netty-tcnative-boringssl-static:1.1.33.Fork13:' + osdetector.classifier
100+
}
101+
```
102+
103+
### OpenSSL: Dynamically Linked (netty-tcnative)
104+
105+
If for any reason you need to dynamically link against OpenSSL (e.g. you need control over the version of OpenSSL), you can instead use the `netty-tcnative` artifact.
106+
107+
Requirements:
108+
109+
1. [OpenSSL](https://www.openssl.org/) version >= 1.0.2 for ALPN support, or version >= 1.0.1 for NPN.
110+
2. [Apache APR library (libapr-1)](https://apr.apache.org/) version >= 1.5.2.
111+
3. [netty-tcnative](https://github.com/netty/netty-tcnative) version >= 1.1.33.Fork7 must be on classpath. Prior versions only supported NPN and only Fedora-derivatives were supported for Linux.
112+
113+
Artifacts are available on [Maven Central](http://repo1.maven.org/maven2/io/netty/netty-tcnative/) for the following platforms:
42114

43115
Classifier | Description
44116
---------------- | -----------
@@ -47,9 +119,9 @@ osx-x86_64 | Mac distribution
47119
linux-x86_64 | Used for non-Fedora derivatives of Linux
48120
linux-x86_64-fedora | Used for Fedora derivatives
49121

50-
*NOTE: Make sure you use a version of netty-tcnative >= 1.1.33.Fork7. Prior versions only supported NPN and only Fedora-derivatives were supported for Linux.*
122+
On Linux it should be noted that OpenSSL uses a different soname for Fedora derivatives than other Linux releases. To work around this limitation, netty-tcnative deploys two separate versions for linux.
51123

52-
#### Getting netty-tcnative from Maven
124+
##### Getting netty-tcnative from Maven
53125

54126
In Maven, you can use the [os-maven-plugin](https://github.com/trustin/os-maven-plugin) to help simplify the dependency.
55127

@@ -59,7 +131,7 @@ In Maven, you can use the [os-maven-plugin](https://github.com/trustin/os-maven-
59131
<dependency>
60132
<groupId>io.netty</groupId>
61133
<artifactId>netty-tcnative</artifactId>
62-
<version>1.1.33.Fork11</version>
134+
<version>1.1.33.Fork13</version>
63135
<classifier>${tcnative.classifier}</classifier>
64136
</dependency>
65137
</dependencies>
@@ -102,7 +174,7 @@ In Maven, you can use the [os-maven-plugin](https://github.com/trustin/os-maven-
102174
</project>
103175
```
104176

105-
#### Getting netty-tcnative from Gradle
177+
##### Getting netty-tcnative from Gradle
106178

107179
Gradle you can use the [osdetector-gradle-plugin](https://github.com/google/osdetector-gradle-plugin), which is a wrapper around the os-maven-plugin.
108180

@@ -127,7 +199,7 @@ if (osdetector.os == "linux" && osdetector.release.isLike("fedora")) {
127199
}
128200
129201
dependencies {
130-
compile 'io.netty:netty-tcnative:1.1.33.Fork11:' + tcnative_classifier
202+
compile 'io.netty:netty-tcnative:1.1.33.Fork13:' + tcnative_classifier
131203
}
132204
```
133205

build.gradle

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,6 @@ subprojects {
118118
}
119119
}
120120

121-
def tcnative_suffix = osdetector.classifier;
122-
// Fedora variants use a different soname for OpenSSL than other linux distributions
123-
// (see http://netty.io/wiki/forked-tomcat-native.html).
124-
if (osdetector.os == "linux" && osdetector.release.isLike("fedora")) {
125-
tcnative_suffix += "-fedora";
126-
}
127-
128121
def epoll_suffix = "";
129122
if (osdetector.classifier in ["linux-x86_64"]) {
130123
// The native code is only pre-compiled on certain platforms.
@@ -145,7 +138,7 @@ subprojects {
145138

146139
netty: 'io.netty:netty-codec-http2:4.1.0.CR1',
147140
netty_epoll: 'io.netty:netty-transport-native-epoll:4.1.0.CR1' + epoll_suffix,
148-
netty_tcnative: 'io.netty:netty-tcnative:1.1.33.Fork11:' + tcnative_suffix,
141+
netty_tcnative: 'io.netty:netty-tcnative-boringssl-static:1.1.33.Fork13:' + osdetector.classifier,
149142

150143
// Test dependencies.
151144
junit: 'junit:junit:4.11',

buildscripts/make_dependencies.bat

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ REM 7za is in http://www.7-zip.org/a/7z1507-extra.7z
33

44
REM Prerequisite:
55
REM 7za.exe in current directory or PATH
6-
REM Install http://slproweb.com/download/Win64OpenSSL_Light-1_0_2d.exe
76

87
set PROTOBUF_VER=3.0.0-beta-2
98
set CMAKE_NAME=cmake-3.3.2-win32-x86

buildscripts/make_dependencies.sh

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
#!/bin/bash
22
#
3-
# Build protoc & openssl
3+
# Build protoc
44
set -ev
55

66
DOWNLOAD_DIR=/tmp/source
77
INSTALL_DIR=/tmp/protobuf-${PROTOBUF_VERSION}
88
mkdir -p $DOWNLOAD_DIR
99

10-
# We may have set this elsewhere in order to allow gRPC find our custom
11-
# built openssl to run ALPN, but it may be incompatible with wget which
12-
# uses the system openssl. We unset this variable for this script.
13-
export -n LD_LIBRARY_PATH
14-
1510
# Make protoc
1611
# Can't check for presence of directory as cache auto-creates it.
1712
if [ -f ${INSTALL_DIR}/bin/protoc ]; then
@@ -28,20 +23,3 @@ else
2823
popd
2924
fi
3025

31-
INSTALL_DIR=/tmp/openssl-${OPENSSL_VERSION}
32-
33-
if [ -f ${INSTALL_DIR}/lib/libssl.so ]; then
34-
echo "Not building openssl. Already built"
35-
elif [ "$(uname)" = Darwin ]; then
36-
brew install openssl
37-
else
38-
# The version without the patch letter (e.g., 1.0.2 provided 1.0.2d)
39-
VERSION_BASE=${OPENSSL_VERSION%%[a-z]*}
40-
wget -O - https://www.openssl.org/source/old/$VERSION_BASE/openssl-${OPENSSL_VERSION}.tar.gz \
41-
| tar xz -C $DOWNLOAD_DIR
42-
pushd $DOWNLOAD_DIR/openssl-${OPENSSL_VERSION}
43-
./Configure linux-x86_64 shared no-ssl2 no-comp --prefix=${INSTALL_DIR}
44-
make -j$(nproc)
45-
make install
46-
popd
47-
fi

interop-testing/src/test/java/io/grpc/testing/integration/Http2NettyTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import io.grpc.netty.NettyChannelBuilder;
3737
import io.grpc.netty.NettyServerBuilder;
3838
import io.grpc.testing.TestUtils;
39+
import io.netty.handler.ssl.SslProvider;
3940
import io.netty.handler.ssl.SupportedCipherSuiteFilter;
4041

4142
import org.junit.AfterClass;
@@ -61,6 +62,7 @@ public static void startServer() {
6162
.sslContext(GrpcSslContexts
6263
.forServer(TestUtils.loadCert("server1.pem"), TestUtils.loadCert("server1.key"))
6364
.ciphers(TestUtils.preferredTestCiphers(), SupportedCipherSuiteFilter.INSTANCE)
65+
.sslProvider(SslProvider.OPENSSL)
6466
.build()));
6567
} catch (IOException ex) {
6668
throw new RuntimeException(ex);
@@ -80,6 +82,7 @@ protected ManagedChannel createChannel() {
8082
.sslContext(GrpcSslContexts.forClient()
8183
.trustManager(TestUtils.loadCert("ca.pem"))
8284
.ciphers(TestUtils.preferredTestCiphers(), SupportedCipherSuiteFilter.INSTANCE)
85+
.sslProvider(SslProvider.OPENSSL)
8386
.build())
8487
.build();
8588
} catch (Exception ex) {

0 commit comments

Comments
 (0)