You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2022/01/14 22:20:25 UTC
[httpcomponents-core] branch master updated: Add empty constructor with the default SSL context based on system properties.
This is an automated email from the ASF dual-hosted git repository.
olegk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git
The following commit(s) were added to refs/heads/master by this push:
new 0b1a635 Add empty constructor with the default SSL context based on system properties.
0b1a635 is described below
commit 0b1a6355eb721c4fbe716aee14c2bad46e74b98f
Author: Arturo Bernal <ar...@gmail.com>
AuthorDate: Tue Jan 11 08:18:46 2022 +0100
Add empty constructor with the default SSL context based on system properties.
---
.../http2/ssl/ConscryptClientTlsStrategy.java | 19 +++++++
.../http2/ssl/ConscryptServerTlsStrategy.java | 21 ++++++++
.../hc/core5/http2/ssl/H2ClientTlsStrategy.java | 10 ++++
.../http2/ssl/ConscryptClientTlsStrategyTest.java | 59 ++++++++++++++++++++++
.../core5/http/nio/ssl/BasicClientTlsStrategy.java | 10 ++++
.../core5/http/nio/ssl/BasicServerTlsStrategy.java | 9 ++++
.../http/nio/ssl/BasicClientTlsStrategyTest.java | 54 ++++++++++++++++++++
.../http/nio/ssl/BasicServerTlsStrategyTest.java | 54 ++++++++++++++++++++
8 files changed, 236 insertions(+)
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/ConscryptClientTlsStrategy.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/ConscryptClientTlsStrategy.java
index e6ad019..a880fa3 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/ConscryptClientTlsStrategy.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/ConscryptClientTlsStrategy.java
@@ -40,6 +40,7 @@ import org.apache.hc.core5.reactor.ssl.SSLBufferMode;
import org.apache.hc.core5.reactor.ssl.SSLSessionInitializer;
import org.apache.hc.core5.reactor.ssl.SSLSessionVerifier;
import org.apache.hc.core5.reactor.ssl.TransportSecurityLayer;
+import org.apache.hc.core5.ssl.SSLContexts;
import org.apache.hc.core5.util.Args;
import org.apache.hc.core5.util.Timeout;
@@ -84,6 +85,24 @@ public class ConscryptClientTlsStrategy implements TlsStrategy {
this(sslContext, null, null, null);
}
+ /**
+ * Empty constructor with the default SSL context based on system properties.
+ * @see SSLContext
+ * @since 5.2
+ */
+ public ConscryptClientTlsStrategy() {
+ this(SSLContexts.createSystemDefault(), null, null, null);
+ }
+
+ /**
+ * Constructor with the default SSL context based on system properties and custom {@link SSLSessionVerifier} verifier.
+ * @param verifier the custom {@link SSLSessionVerifier}.
+ * @since 5.2
+ */
+ public ConscryptClientTlsStrategy(final SSLSessionVerifier verifier) {
+ this(SSLContexts.createSystemDefault(), verifier);
+ }
+
@Override
public void upgrade(
final TransportSecurityLayer tlsSession,
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/ConscryptServerTlsStrategy.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/ConscryptServerTlsStrategy.java
index 2b6e9e6..abacfeb 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/ConscryptServerTlsStrategy.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/ConscryptServerTlsStrategy.java
@@ -41,6 +41,7 @@ import org.apache.hc.core5.reactor.ssl.SSLBufferMode;
import org.apache.hc.core5.reactor.ssl.SSLSessionInitializer;
import org.apache.hc.core5.reactor.ssl.SSLSessionVerifier;
import org.apache.hc.core5.reactor.ssl.TransportSecurityLayer;
+import org.apache.hc.core5.ssl.SSLContexts;
import org.apache.hc.core5.util.Args;
import org.apache.hc.core5.util.Timeout;
@@ -142,10 +143,30 @@ public class ConscryptServerTlsStrategy implements TlsStrategy {
this(sslContext, (SSLBufferMode) null, null, null);
}
+ /**
+ * Empty constructor with the default SSL context based on system properties.
+ * @see SSLContext
+ * @since 5.2
+ */
+ public ConscryptServerTlsStrategy() {
+ this(SSLContexts.createSystemDefault(), (SSLBufferMode) null, null, null);
+ }
+
+ /**
+ * Constructor with the default SSL context based on system properties and custom {@link SSLSessionVerifier}.
+ * @param verifier the custom {@link SSLSessionVerifier}.
+ * @see SSLContext
+ * @since 5.2
+ */
+ public ConscryptServerTlsStrategy(final SSLSessionVerifier verifier) {
+ this(SSLContexts.createSystemDefault(), (SSLBufferMode) null, null, verifier);
+ }
+
private boolean isApplicable(final SocketAddress localAddress) {
return securePortStrategy == null || securePortStrategy.isSecure(localAddress);
}
+
@Override
public void upgrade(
final TransportSecurityLayer tlsSession,
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ClientTlsStrategy.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ClientTlsStrategy.java
index a3f0d88..dea438b 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ClientTlsStrategy.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ClientTlsStrategy.java
@@ -89,6 +89,16 @@ public class H2ClientTlsStrategy implements TlsStrategy {
this(SSLContexts.createSystemDefault());
}
+ /**
+ * Constructor with the default SSL context based on system properties and custom {@link SSLSessionVerifier}.
+ * @param verifier the custom {@link SSLSessionVerifier}.
+ * @see SSLContext
+ * @since 5.2
+ */
+ public H2ClientTlsStrategy( final SSLSessionVerifier verifier) {
+ this(SSLContexts.createSystemDefault(), null, null, verifier);
+ }
+
@Override
public void upgrade(
final TransportSecurityLayer tlsSession,
diff --git a/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/ssl/ConscryptClientTlsStrategyTest.java b/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/ssl/ConscryptClientTlsStrategyTest.java
new file mode 100644
index 0000000..4526ce0
--- /dev/null
+++ b/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/ssl/ConscryptClientTlsStrategyTest.java
@@ -0,0 +1,59 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.core5.http2.ssl;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import org.apache.hc.core5.reactor.ssl.SSLSessionVerifier;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+class ConscryptClientTlsStrategyTest {
+
+ @Mock
+ private SSLSessionVerifier sslSessionVerifier;
+
+ @BeforeEach
+ public void prepareMocks() {
+ MockitoAnnotations.openMocks(this);
+ }
+
+ @Test
+ void test_valid_tls_strategy_creation() {
+ final ConscryptClientTlsStrategy strategy = new ConscryptClientTlsStrategy();
+ assertNotNull(strategy);
+ }
+
+ @Test
+ void test_valid_tls_strategy_creation_with_verifier() {
+ final ConscryptClientTlsStrategy strategy = new ConscryptClientTlsStrategy(sslSessionVerifier);
+ assertNotNull(strategy);
+ }
+}
\ No newline at end of file
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicClientTlsStrategy.java b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicClientTlsStrategy.java
index 3386708..1ba874f 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicClientTlsStrategy.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicClientTlsStrategy.java
@@ -88,6 +88,16 @@ public class BasicClientTlsStrategy implements TlsStrategy {
this(SSLContexts.createSystemDefault());
}
+ /**
+ * Constructor with the default SSL context based on system properties and custom {@link SSLSessionVerifier} verifier.
+ * @param verifier the custom {@link SSLSessionVerifier}.
+ * @see SSLContext
+ * @since 5.2
+ */
+ public BasicClientTlsStrategy(final SSLSessionVerifier verifier) {
+ this(SSLContexts.createSystemDefault(), verifier);
+ }
+
@Override
public void upgrade(
final TransportSecurityLayer tlsSession,
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicServerTlsStrategy.java b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicServerTlsStrategy.java
index 63c0025..dace253 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicServerTlsStrategy.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicServerTlsStrategy.java
@@ -113,6 +113,15 @@ public class BasicServerTlsStrategy implements TlsStrategy {
this(SSLContexts.createSystemDefault(), securePortStrategy);
}
+ /**
+ * Constructor with the default SSL context based on system properties and custom {@link SSLSessionVerifier} verifier.
+ * @param verifier the custom {@link SSLSessionVerifier}.
+ * @since 5.2
+ */
+ public BasicServerTlsStrategy(final SSLSessionVerifier verifier) {
+ this(SSLContexts.createSystemDefault(), verifier);
+ }
+
public BasicServerTlsStrategy(
final SSLContext sslContext,
final SSLBufferMode sslBufferMode,
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/nio/ssl/BasicClientTlsStrategyTest.java b/httpcore5/src/test/java/org/apache/hc/core5/http/nio/ssl/BasicClientTlsStrategyTest.java
new file mode 100644
index 0000000..93aed83
--- /dev/null
+++ b/httpcore5/src/test/java/org/apache/hc/core5/http/nio/ssl/BasicClientTlsStrategyTest.java
@@ -0,0 +1,54 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.core5.http.nio.ssl;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import org.apache.hc.core5.reactor.ssl.SSLSessionVerifier;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+class BasicClientTlsStrategyTest {
+
+ @Mock
+ private SSLSessionVerifier sslSessionVerifier;
+
+ @BeforeEach
+ public void prepareMocks() {
+ MockitoAnnotations.openMocks(this);
+ }
+
+ @Test
+ void test_valid_tls_strategy_creation_with_verifier() {
+ final BasicClientTlsStrategy strategy = new BasicClientTlsStrategy(sslSessionVerifier);
+ assertNotNull(strategy);
+ }
+
+}
\ No newline at end of file
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/nio/ssl/BasicServerTlsStrategyTest.java b/httpcore5/src/test/java/org/apache/hc/core5/http/nio/ssl/BasicServerTlsStrategyTest.java
new file mode 100644
index 0000000..eca9522
--- /dev/null
+++ b/httpcore5/src/test/java/org/apache/hc/core5/http/nio/ssl/BasicServerTlsStrategyTest.java
@@ -0,0 +1,54 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.core5.http.nio.ssl;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import org.apache.hc.core5.reactor.ssl.SSLSessionVerifier;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+class BasicServerTlsStrategyTest {
+
+ @Mock
+ private SSLSessionVerifier sslSessionVerifier;
+
+ @BeforeEach
+ public void prepareMocks() {
+ MockitoAnnotations.openMocks(this);
+ }
+
+ @Test
+ void test_valid_tls_strategy_creation_with_verifier() {
+ final BasicServerTlsStrategy strategy = new BasicServerTlsStrategy(sslSessionVerifier);
+ assertNotNull(strategy);
+ }
+
+}
\ No newline at end of file