diff --git a/gradle.properties b/gradle.properties index b376c62..ee6557f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,10 +1,10 @@ group = org.xbib name = netty-http -version = 4.1.45.0 +version = 4.1.47.0 # netty -netty.version = 4.1.45.Final -tcnative.version = 2.0.28.Final +netty.version = 4.1.47.Final +tcnative.version = 2.0.29.Final tcnative-legacy-macosx.version = 2.0.26.Final # for netty-http-common @@ -28,7 +28,6 @@ junit4.version = 4.12 conscrypt.version = 2.2.1 jackson.version = 2.9.10 hamcrest.version = 2.1 -#mockito.version = 1.10.19 mockito.version = 3.1.0 # doc diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2d486e8..e65dbed 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ -#Sun Aug 18 22:06:23 CEST 2019 -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6-all.zip +#Mon Mar 09 11:04:01 CET 2020 +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStorePath=wrapper/dists diff --git a/netty-http-bouncycastle/src/main/java/org/xbib/netty/http/bouncycastle/BouncyCastleSelfSignedCertificateProvider.java b/netty-http-bouncycastle/src/main/java/org/xbib/netty/http/bouncycastle/BouncyCastleSelfSignedCertificateProvider.java index b5cb02d..8fb1726 100644 --- a/netty-http-bouncycastle/src/main/java/org/xbib/netty/http/bouncycastle/BouncyCastleSelfSignedCertificateProvider.java +++ b/netty-http-bouncycastle/src/main/java/org/xbib/netty/http/bouncycastle/BouncyCastleSelfSignedCertificateProvider.java @@ -1,7 +1,12 @@ package org.xbib.netty.http.bouncycastle; +import org.bouncycastle.operator.OperatorCreationException; import org.xbib.netty.http.common.ServerCertificateProvider; +import java.io.IOException; import java.io.InputStream; +import java.io.UncheckedIOException; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; import java.security.SecureRandom; public class BouncyCastleSelfSignedCertificateProvider implements ServerCertificateProvider { @@ -13,8 +18,12 @@ public class BouncyCastleSelfSignedCertificateProvider implements ServerCertific } @Override - public void prepare(String fqdn) throws Exception { - selfSignedCertificate.generate(fqdn, new SecureRandom(), 2048); + public void prepare(String fqdn) { + try { + selfSignedCertificate.generate(fqdn, new SecureRandom(), 2048); + } catch (IOException | NoSuchProviderException | NoSuchAlgorithmException | OperatorCreationException e) { + throw new UncheckedIOException(new IOException(e)); + } } @Override diff --git a/netty-http-client-api/src/main/java/org/xbib/netty/http/client/api/Request.java b/netty-http-client-api/src/main/java/org/xbib/netty/http/client/api/Request.java index aa760ca..44b125a 100644 --- a/netty-http-client-api/src/main/java/org/xbib/netty/http/client/api/Request.java +++ b/netty-http-client-api/src/main/java/org/xbib/netty/http/client/api/Request.java @@ -30,6 +30,7 @@ import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.util.ArrayList; +import java.util.Base64; import java.util.Collection; import java.util.Collections; import java.util.HashSet; @@ -478,6 +479,12 @@ public final class Request { return this; } + public Builder addBasicAuthorization(String name, String password) { + String encoding = Base64.getEncoder().encodeToString((name + ":" + password).getBytes(StandardCharsets.UTF_8)); + this.headers.add(HttpHeaderNames.AUTHORIZATION, "Basic " + encoding); + return this; + } + public Builder addBodyData(InterfaceHttpData data) { bodyData.add(data); return this; diff --git a/netty-http-client/src/main/java/org/xbib/netty/http/client/Client.java b/netty-http-client/src/main/java/org/xbib/netty/http/client/Client.java index 0498c58..bbb02f1 100644 --- a/netty-http-client/src/main/java/org/xbib/netty/http/client/Client.java +++ b/netty-http-client/src/main/java/org/xbib/netty/http/client/Client.java @@ -79,6 +79,7 @@ public final class Client implements AutoCloseable { System.setProperty("io.netty.noKeySetOptimization", Boolean.toString(true)); } } + private final AtomicLong requestCounter; private final AtomicLong responseCounter; @@ -219,7 +220,6 @@ public final class Client implements AutoCloseable { logger.log(level, () -> "JDK ciphers: " + SecurityUtil.Defaults.JDK_CIPHERS); logger.log(level, () -> "OpenSSL ciphers: " + SecurityUtil.Defaults.OPENSSL_CIPHERS); logger.log(level, () -> "OpenSSL available: " + OpenSsl.isAvailable()); - logger.log(level, () -> "OpenSSL ALPN support: " + OpenSsl.isAlpnSupported()); logger.log(level, () -> "Candidate ciphers on client: " + clientConfig.getCiphers()); logger.log(level, () -> "Local host name: " + NetworkUtils.getLocalHostName("localhost")); logger.log(level, () -> "Event loop group: " + eventLoopGroup + " threads=" + clientConfig.getThreadCount()); diff --git a/netty-http-common/src/main/java/org/xbib/netty/http/common/ServerCertificateProvider.java b/netty-http-common/src/main/java/org/xbib/netty/http/common/ServerCertificateProvider.java index 1a33603..19071da 100644 --- a/netty-http-common/src/main/java/org/xbib/netty/http/common/ServerCertificateProvider.java +++ b/netty-http-common/src/main/java/org/xbib/netty/http/common/ServerCertificateProvider.java @@ -9,7 +9,7 @@ public interface ServerCertificateProvider { * * @param fqdn the full qualified domain name. */ - void prepare(String fqdn) throws Exception; + void prepare(String fqdn); /** * Returns the generated RSA private key file in PEM format. diff --git a/netty-http-server/src/main/java/org/xbib/netty/http/server/Domain.java b/netty-http-server/src/main/java/org/xbib/netty/http/server/Domain.java index 0f51c34..1a8258f 100644 --- a/netty-http-server/src/main/java/org/xbib/netty/http/server/Domain.java +++ b/netty-http-server/src/main/java/org/xbib/netty/http/server/Domain.java @@ -263,7 +263,7 @@ public class Domain { return this; } - public Builder setSelfCert() throws Exception { + public Builder setSelfCert() { ServiceLoader serverCertificateProviders = ServiceLoader.load(ServerCertificateProvider.class); for (ServerCertificateProvider serverCertificateProvider : serverCertificateProviders) { if ("org.xbib.netty.http.bouncycastle.BouncyCastleSelfSignedCertificateProvider".equals(serverCertificateProvider.getClass().getName())) { diff --git a/netty-http-server/src/main/java/org/xbib/netty/http/server/Server.java b/netty-http-server/src/main/java/org/xbib/netty/http/server/Server.java index 0840093..5c81f6b 100644 --- a/netty-http-server/src/main/java/org/xbib/netty/http/server/Server.java +++ b/netty-http-server/src/main/java/org/xbib/netty/http/server/Server.java @@ -233,7 +233,6 @@ public final class Server implements AutoCloseable { logger.log(level, () -> "JDK ciphers: " + SecurityUtil.Defaults.JDK_CIPHERS); logger.log(level, () -> "OpenSSL ciphers: " + SecurityUtil.Defaults.OPENSSL_CIPHERS); logger.log(level, () -> "OpenSSL available: " + OpenSsl.isAvailable()); - logger.log(level, () -> "OpenSSL ALPN support: " + OpenSsl.isAlpnSupported()); logger.log(level, () -> "Installed ciphers on default server: " + (serverConfig.getAddress().isSecure() ? serverConfig.getDefaultDomain().getSslContext().cipherSuites() : "")); logger.log(level, () -> "Local host name: " + NetworkUtils.getLocalHostName("localhost")); diff --git a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/http1/BasicAuthTest.java b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/http1/BasicAuthTest.java new file mode 100644 index 0000000..a993449 --- /dev/null +++ b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/http1/BasicAuthTest.java @@ -0,0 +1,42 @@ +package org.xbib.netty.http.server.test.http1; + +import io.netty.handler.codec.http.HttpResponseStatus; +import io.netty.handler.codec.http.HttpVersion; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.xbib.net.URL; +import org.xbib.netty.http.client.Client; +import org.xbib.netty.http.client.api.Request; +import org.xbib.netty.http.client.api.ResponseListener; +import org.xbib.netty.http.common.HttpResponse; +import java.nio.charset.StandardCharsets; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class BasicAuthTest { + + private static final Logger logger = Logger.getLogger(PostTest.class.getName()); + + @Disabled + void testBasicAuth() throws Exception { + Client client = Client.builder() + .build(); + try { + ResponseListener responseListener = (resp) -> { + if (resp.getStatus().getCode() == HttpResponseStatus.OK.code()) { + logger.log(Level.INFO, "got response " + resp.getBodyAsString(StandardCharsets.UTF_8)); + } + }; + URL serverUrl = URL.from(""); + Request postRequest = Request.post().setVersion(HttpVersion.HTTP_1_1) + .url(serverUrl) + .addBasicAuthorization("", "") + .setResponseListener(responseListener) + .build(); + client.execute(postRequest).get(); + } finally { + client.shutdownGracefully(); + logger.log(Level.INFO, "server and client shut down"); + } + } +}