Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail the build if we can't load the OpenSSL library #11269

Merged
merged 7 commits into from May 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions docker/docker-compose.yaml
Expand Up @@ -25,11 +25,11 @@ services:

build-leak:
<<: *common
command: /bin/bash -cl "./mvnw -Pleak clean install -Dio.netty.testsuite.badHost=netty.io"
command: /bin/bash -cl "./mvnw -Pleak clean install -Dio.netty.testsuite.badHost=netty.io -Dtcnative.classifier=linux-x86_64-fedora"

build:
<<: *common
command: /bin/bash -cl "./mvnw clean install -Dio.netty.testsuite.badHost=netty.io"
command: /bin/bash -cl "./mvnw clean install -Dio.netty.testsuite.badHost=netty.io -Dtcnative.classifier=linux-x86_64-fedora"

deploy:
<<: *common
Expand All @@ -52,7 +52,7 @@ services:
- ~/.m2:/root/.m2
- ~/local-staging:/root/local-staging
- ..:/code
command: /bin/bash -cl "cat <(echo -e \"${GPG_PRIVATE_KEY}\") | gpg --batch --import && ./mvnw clean javadoc:jar package gpg:sign org.sonatype.plugins:nexus-staging-maven-plugin:deploy -DnexusUrl=https://oss.sonatype.org -DserverId=sonatype-nexus-staging -DaltStagingDirectory=/root/local-staging -DskipRemoteStaging=true -DskipTests=true -Dgpg.passphrase=${GPG_PASSPHRASE} -Dgpg.keyname=${GPG_KEYNAME}"
command: /bin/bash -cl "cat <(echo -e \"${GPG_PRIVATE_KEY}\") | gpg --batch --import && ./mvnw clean javadoc:jar package gpg:sign org.sonatype.plugins:nexus-staging-maven-plugin:deploy -DnexusUrl=https://oss.sonatype.org -DserverId=sonatype-nexus-staging -DaltStagingDirectory=/root/local-staging -DskipRemoteStaging=true -DskipTests=true -Dgpg.passphrase=${GPG_PASSPHRASE} -Dgpg.keyname=${GPG_KEYNAME} -Dtcnative.classifier=linux-x86_64-fedora"

build-boringssl-static:
<<: *common
Expand Down
Expand Up @@ -58,7 +58,7 @@ public ConscryptOpenSslEngineInteropTest(BufferType type, ProtocolCipherCombo co

@BeforeClass
public static void checkOpenssl() {
assumeTrue(OpenSsl.isAvailable());
OpenSsl.ensureAvailability();
}

@Override
Expand Down
Expand Up @@ -63,7 +63,7 @@ public JdkOpenSslEngineInteroptTest(BufferType type, ProtocolCipherCombo protoco

@BeforeClass
public static void checkOpenSsl() {
assumeTrue(OpenSsl.isAvailable());
OpenSsl.ensureAvailability();
}

@Override
Expand Down
Expand Up @@ -17,16 +17,20 @@

import io.netty.internal.tcnative.CertificateVerifier;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.BeforeClass;
import org.junit.Test;

import java.lang.reflect.Field;

public class OpenSslCertificateExceptionTest {

@BeforeClass
public static void ensureOpenSsl() {
OpenSsl.ensureAvailability();
}

@Test
public void testValidErrorCode() throws Exception {
Assume.assumeTrue(OpenSsl.isAvailable());
Field[] fields = CertificateVerifier.class.getFields();
for (Field field : fields) {
if (field.isAccessible()) {
Expand All @@ -39,13 +43,11 @@ public void testValidErrorCode() throws Exception {

@Test(expected = IllegalArgumentException.class)
public void testNonValidErrorCode() {
Assume.assumeTrue(OpenSsl.isAvailable());
new OpenSslCertificateException(Integer.MIN_VALUE);
}

@Test
public void testCanBeInstancedWhenOpenSslIsNotAvailable() {
Assume.assumeFalse(OpenSsl.isAvailable());
new OpenSslCertificateException(0);
}
}
Expand Up @@ -21,13 +21,11 @@
import javax.net.ssl.SSLException;
import java.io.File;

import static org.junit.Assume.assumeTrue;

public class OpenSslClientContextTest extends SslContextTest {

@BeforeClass
public static void checkOpenSsl() {
assumeTrue(OpenSsl.isAvailable());
OpenSsl.ensureAvailability();
}

@Override
Expand Down
Expand Up @@ -57,7 +57,7 @@ public OpenSslConscryptSslEngineInteropTest(BufferType type, ProtocolCipherCombo

@BeforeClass
public static void checkOpenssl() {
assumeTrue(OpenSsl.isAvailable());
OpenSsl.ensureAvailability();
}

@Override
Expand Down
Expand Up @@ -110,7 +110,7 @@ public OpenSslEngineTest(BufferType type, ProtocolCipherCombo cipherCombo, boole

@BeforeClass
public static void checkOpenSsl() {
assumeTrue(OpenSsl.isAvailable());
OpenSsl.ensureAvailability();
}

@Override
Expand Down Expand Up @@ -1321,6 +1321,7 @@ public void testExtractMasterkeyWorksCorrectly() throws Exception {

@Test(expected = SSLException.class)
public void testNoKeyFound() throws Exception {
checkShouldUseKeyManagerFactory();
clientSslCtx = wrapContext(SslContextBuilder
.forClient()
.trustManager(InsecureTrustManagerFactory.INSTANCE)
Expand Down
Expand Up @@ -33,7 +33,7 @@ public class OpenSslKeyMaterialManagerTest {

@Test
public void testChooseClientAliasReturnsNull() throws SSLException {
Assume.assumeTrue(OpenSsl.isAvailable());
OpenSsl.ensureAvailability();

X509ExtendedKeyManager keyManager = new X509ExtendedKeyManager() {
@Override
Expand Down
Expand Up @@ -42,7 +42,7 @@ public class OpenSslKeyMaterialProviderTest {

@BeforeClass
public static void checkOpenSsl() {
assumeTrue(OpenSsl.isAvailable());
OpenSsl.ensureAvailability();
}

protected KeyManagerFactory newKeyManagerFactory() throws Exception {
Expand Down
Expand Up @@ -30,7 +30,7 @@ public class OpenSslRenegotiateTest extends RenegotiateTest {

@BeforeClass
public static void checkOpenSsl() {
assumeTrue(OpenSsl.isAvailable());
OpenSsl.ensureAvailability();
}

@Override
Expand Down
Expand Up @@ -28,12 +28,11 @@ public class OpenSslServerContextTest extends SslContextTest {

@BeforeClass
public static void checkOpenSsl() {
assumeTrue(OpenSsl.isAvailable());
OpenSsl.ensureAvailability();
}

@Override
protected SslContext newSslContext(File crtFile, File keyFile, String pass) throws SSLException {
Assume.assumeTrue(OpenSsl.isAvailable());
return new OpenSslServerContext(crtFile, keyFile, pass);
}
}
Expand Up @@ -45,7 +45,7 @@ public void testPemEncodedOpenSslRef() throws Exception {
}

private static void testPemEncoded(SslProvider provider) throws Exception {
assumeTrue(OpenSsl.isAvailable());
OpenSsl.ensureAvailability();
assumeFalse(OpenSsl.useKeyManagerFactory());
PemPrivateKey pemKey;
PemX509Certificate pemCert;
Expand Down
Expand Up @@ -48,7 +48,7 @@ protected void cleanupClientSslContext(SslContext ctx) {

@Override
protected void cleanupClientSslEngine(SSLEngine engine) {
ReferenceCountUtil.release(engine);
ReferenceCountUtil.release(unwrapEngine(engine));
}

@Override
Expand All @@ -58,7 +58,7 @@ protected void cleanupServerSslContext(SslContext ctx) {

@Override
protected void cleanupServerSslEngine(SSLEngine engine) {
ReferenceCountUtil.release(engine);
ReferenceCountUtil.release(unwrapEngine(engine));
}

@Test(expected = NullPointerException.class)
Expand Down
Expand Up @@ -47,7 +47,7 @@ public void testClientContextFromFileJdk() throws Exception {

@Test
public void testClientContextFromFileOpenssl() throws Exception {
Assume.assumeTrue(OpenSsl.isAvailable());
OpenSsl.ensureAvailability();
testClientContextFromFile(SslProvider.OPENSSL);
}

Expand All @@ -58,7 +58,7 @@ public void testClientContextJdk() throws Exception {

@Test
public void testClientContextOpenssl() throws Exception {
Assume.assumeTrue(OpenSsl.isAvailable());
OpenSsl.ensureAvailability();
testClientContext(SslProvider.OPENSSL);
}

Expand All @@ -69,7 +69,7 @@ public void testKeyStoreTypeJdk() throws Exception {

@Test
public void testKeyStoreTypeOpenssl() throws Exception {
Assume.assumeTrue(OpenSsl.isAvailable());
OpenSsl.ensureAvailability();
testKeyStoreType(SslProvider.OPENSSL);
}

Expand All @@ -80,7 +80,7 @@ public void testServerContextFromFileJdk() throws Exception {

@Test
public void testServerContextFromFileOpenssl() throws Exception {
Assume.assumeTrue(OpenSsl.isAvailable());
OpenSsl.ensureAvailability();
testServerContextFromFile(SslProvider.OPENSSL);
}

Expand All @@ -91,7 +91,7 @@ public void testServerContextJdk() throws Exception {

@Test
public void testServerContextOpenssl() throws Exception {
Assume.assumeTrue(OpenSsl.isAvailable());
OpenSsl.ensureAvailability();
testServerContext(SslProvider.OPENSSL);
}

Expand All @@ -102,7 +102,7 @@ public void testContextFromManagersJdk() throws Exception {

@Test
public void testContextFromManagersOpenssl() throws Exception {
Assume.assumeTrue(OpenSsl.isAvailable());
OpenSsl.ensureAvailability();
Assume.assumeTrue(OpenSsl.useKeyManagerFactory());
testContextFromManagers(SslProvider.OPENSSL);
}
Expand Down Expand Up @@ -155,13 +155,13 @@ private static void testUnsupportedPrivateKeyFailsFast(boolean server) throws Ex

@Test(expected = IllegalArgumentException.class)
public void testInvalidCipherJdk() throws Exception {
Assume.assumeTrue(OpenSsl.isAvailable());
OpenSsl.ensureAvailability();
testInvalidCipher(SslProvider.JDK);
}

@Test
public void testInvalidCipherOpenSSL() throws Exception {
Assume.assumeTrue(OpenSsl.isAvailable());
OpenSsl.ensureAvailability();
try {
// This may fail or not depending on the OpenSSL version used
// See https://github.com/openssl/openssl/issues/7196
Expand Down
Expand Up @@ -127,7 +127,7 @@ public SslErrorTest(SslProvider serverProvider, SslProvider clientProvider,
public void testCorrectAlert() throws Exception {
// As this only works correctly at the moment when OpenSslEngine is used on the server-side there is
// no need to run it if there is no openssl is available at all.
Assume.assumeTrue(OpenSsl.isAvailable());
OpenSsl.ensureAvailability();

SelfSignedCertificate ssc = new SelfSignedCertificate();

Expand Down
12 changes: 6 additions & 6 deletions handler/src/test/java/io/netty/handler/ssl/SslHandlerTest.java
Expand Up @@ -367,7 +367,7 @@ public void testIncompleteWriteDoesNotCompletePromisePrematurely() throws NoSuch

@Test
public void testReleaseSslEngine() throws Exception {
assumeTrue(OpenSsl.isAvailable());
OpenSsl.ensureAvailability();

SelfSignedCertificate cert = new SelfSignedCertificate();
try {
Expand Down Expand Up @@ -1136,7 +1136,7 @@ public void testSessionTicketsWithTLSv13AndNoKey() throws Throwable {
}

private static void testSessionTickets(SslProvider provider, String protocol, boolean withKey) throws Throwable {
assumeTrue(OpenSsl.isAvailable());
OpenSsl.ensureAvailability();
final SslContext sslClientCtx = SslContextBuilder.forClient()
.trustManager(InsecureTrustManagerFactory.INSTANCE)
.sslProvider(provider)
Expand Down Expand Up @@ -1418,13 +1418,13 @@ public void testHandshakeFailureCipherMissmatchTLSv13Jdk() throws Exception {

@Test
public void testHandshakeFailureCipherMissmatchTLSv12OpenSsl() throws Exception {
Assume.assumeTrue(OpenSsl.isAvailable());
OpenSsl.ensureAvailability();
testHandshakeFailureCipherMissmatch(SslProvider.OPENSSL, false);
}

@Test
public void testHandshakeFailureCipherMissmatchTLSv13OpenSsl() throws Exception {
Assume.assumeTrue(OpenSsl.isAvailable());
OpenSsl.ensureAvailability();
Assume.assumeTrue(SslProvider.isTlsv13Supported(SslProvider.OPENSSL));
Assume.assumeFalse("BoringSSL does not support setting ciphers for TLSv1.3 explicit", OpenSsl.isBoringSSL());
testHandshakeFailureCipherMissmatch(SslProvider.OPENSSL, true);
Expand Down Expand Up @@ -1537,7 +1537,7 @@ public void testHandshakeEventsTls12JDK() throws Exception {

@Test
public void testHandshakeEventsTls12Openssl() throws Exception {
assumeTrue(OpenSsl.isAvailable());
OpenSsl.ensureAvailability();
testHandshakeEvents(SslProvider.OPENSSL, SslUtils.PROTOCOL_TLS_V1_2);
}

Expand All @@ -1549,7 +1549,7 @@ public void testHandshakeEventsTls13JDK() throws Exception {

@Test
public void testHandshakeEventsTls13Openssl() throws Exception {
assumeTrue(OpenSsl.isAvailable());
OpenSsl.ensureAvailability();
assumeTrue(SslProvider.isTlsv13Supported(SslProvider.OPENSSL));
testHandshakeEvents(SslProvider.OPENSSL, SslUtils.PROTOCOL_TLS_V1_3);
}
Expand Down
Expand Up @@ -240,14 +240,25 @@ public void testHandshakeWithExecutorTLSv13() throws Exception {
}

@Test
public void testTrustManagerVerify() throws Exception {
testTrustManagerVerify("TLSv1.2");
public void testTrustManagerVerifyJDK() throws Exception {
testTrustManagerVerify(SslProvider.JDK, "TLSv1.2");
}

@Test
public void testTrustManagerVerifyTLSv13() throws Exception {
public void testTrustManagerVerifyTLSv13JDK() throws Exception {
assumeTrue(SslProvider.isTlsv13Supported(SslProvider.JDK));
testTrustManagerVerify("TLSv1.3");
testTrustManagerVerify(SslProvider.JDK, "TLSv1.3");
}

@Test
public void testTrustManagerVerifyOpenSSL() throws Exception {
testTrustManagerVerify(SslProvider.OPENSSL, "TLSv1.2");
}

@Test
public void testTrustManagerVerifyTLSv13OpenSSL() throws Exception {
assumeTrue(SslProvider.isTlsv13Supported(SslProvider.OPENSSL));
testTrustManagerVerify(SslProvider.OPENSSL, "TLSv1.3");
}

@Test
Expand Down Expand Up @@ -378,9 +389,10 @@ protected void run() {
}
}

private static void testTrustManagerVerify(String tlsVersion) throws Exception {
private static void testTrustManagerVerify(SslProvider provider, String tlsVersion) throws Exception {
final SslContext sslClientCtx =
SslContextBuilder.forClient()
.sslProvider(provider)
.protocols(tlsVersion)
.trustManager(ResourcesUtil.getFile(
NettyBlockHoundIntegrationTest.class, "mutual_auth_ca.pem"))
Expand All @@ -392,6 +404,7 @@ private static void testTrustManagerVerify(String tlsVersion) throws Exception {
ResourcesUtil.getFile(
NettyBlockHoundIntegrationTest.class, "localhost_server.key"),
null)
.sslProvider(provider)
.protocols(tlsVersion)
.build();

Expand Down