You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2022/04/08 01:38:05 UTC
[james-project] branch master updated (607928c9e2 -> 0ee2cae6a9)
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
from 607928c9e2 [PERF] Thread configuration for WebAdmin, redis and some reactor improvments (#950)
new 8aaaf61860 JAMES-3738 Move encryption to protocols/netty
new ed81e1374b JAMES-3738 Encryption should be able to create Ssl handler
new c63d794eb8 JAMES-3738 Hide java details behind encryption
new 8692d3710d JAMES-3738 Encryption: static methods comes first
new c136fbc040 JAMES-3738 Encryption should be an interface with a legacy implementation
new fa93ef5afa JAMES-3738 Encryption: annotates methods visible for testing
new 01f11a4a39 JAMES-3738 Extract Encryption instanciation and configuration out of AbstractConfigurableAsyncServer
new 0ee2cae6a9 JAMES-3738 Send initial STARTTLS reply before pipeline changes
The 8 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../org/apache/james/protocols/api/Encryption.java | 137 ---------------
.../protocols/lmtp/netty/NettyLMTPSServerTest.java | 2 +-
.../AbstractSSLAwareChannelPipelineFactory.java | 14 +-
.../netty/BasicChannelInboundHandler.java | 12 +-
.../apache/james/protocols/netty/Encryption.java | 191 +++++++++++++++++++++
.../protocols/netty/NettyProtocolTransport.java | 18 +-
.../apache/james/protocols/netty/NettyServer.java | 1 -
.../james/protocols/netty/NettyServerTest.java | 1 -
.../protocols/pop3/AbstractPOP3SServerTest.java | 2 +-
.../pop3/AbstractStartTlsPOP3ServerTest.java | 2 +-
.../protocols/pop3/netty/NettyPOP3SServerTest.java | 4 +-
.../pop3/netty/NettyStartTlsPOP3ServerTest.java | 2 +-
.../protocols/smtp/AbstractSMTPSServerTest.java | 2 +-
.../protocols/smtp/netty/NettySMTPSServerTest.java | 2 +-
.../smtp/netty/NettyStartTlsSMTPServerTest.java | 2 +-
.../apache/james/imapserver/netty/IMAPServer.java | 12 +-
.../netty/ImapChannelUpstreamHandler.java | 2 +-
.../james/imapserver/netty/NettyImapSession.java | 10 +-
.../protocols/lib/LegacyJavaEncryptionFactory.java | 81 +++++++++
.../org/apache/james/protocols/lib/SslConfig.java | 145 ++++++++++++++++
.../lib/netty/AbstractConfigurableAsyncServer.java | 103 +----------
.../lib/AbstractConfigurableAsyncServerTest.java | 6 +-
.../netty/ManageSieveChannelUpstreamHandler.java | 7 +-
.../managesieveserver/netty/ManageSieveServer.java | 14 +-
.../netty/SMTPChannelInboundHandler.java | 2 +-
25 files changed, 459 insertions(+), 315 deletions(-)
delete mode 100644 protocols/api/src/main/java/org/apache/james/protocols/api/Encryption.java
create mode 100644 protocols/netty/src/main/java/org/apache/james/protocols/netty/Encryption.java
create mode 100644 server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/LegacyJavaEncryptionFactory.java
create mode 100644 server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/SslConfig.java
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[james-project] 04/08: JAMES-3738 Encryption: static methods comes first
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 8692d3710d9fcd2904b6e87b9d8a5fe0abc46131
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Wed Mar 23 10:26:06 2022 +0700
JAMES-3738 Encryption: static methods comes first
---
.../apache/james/protocols/netty/Encryption.java | 24 +++++++++++-----------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/protocols/netty/src/main/java/org/apache/james/protocols/netty/Encryption.java b/protocols/netty/src/main/java/org/apache/james/protocols/netty/Encryption.java
index f45bed3682..c56742a991 100644
--- a/protocols/netty/src/main/java/org/apache/james/protocols/netty/Encryption.java
+++ b/protocols/netty/src/main/java/org/apache/james/protocols/netty/Encryption.java
@@ -32,18 +32,6 @@ import io.netty.handler.ssl.SslHandler;
*/
public final class Encryption {
- private final SSLContext context;
- private final boolean starttls;
- private final String[] enabledCipherSuites;
- private final ClientAuth clientAuth;
-
- private Encryption(SSLContext context, boolean starttls, String[] enabledCipherSuites, ClientAuth clientAuth) {
- this.context = context;
- this.starttls = starttls;
- this.enabledCipherSuites = enabledCipherSuites;
- this.clientAuth = clientAuth;
- }
-
public static Encryption createTls(SSLContext context) {
return createTls(context, null, ClientAuth.NONE);
}
@@ -78,6 +66,18 @@ public final class Encryption {
return new Encryption(context, true, enabledCipherSuites, clientAuth);
}
+ private final SSLContext context;
+ private final boolean starttls;
+ private final String[] enabledCipherSuites;
+ private final ClientAuth clientAuth;
+
+ private Encryption(SSLContext context, boolean starttls, String[] enabledCipherSuites, ClientAuth clientAuth) {
+ this.context = context;
+ this.starttls = starttls;
+ this.enabledCipherSuites = enabledCipherSuites;
+ this.clientAuth = clientAuth;
+ }
+
/**
* Return the {@link SSLContext} to use
*
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[james-project] 01/08: JAMES-3738 Move encryption to protocols/netty
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 8aaaf618601c0da52ec8ecda2b50914a7885020c
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Wed Mar 23 10:08:38 2022 +0700
JAMES-3738 Move encryption to protocols/netty
---
.../org/apache/james/protocols/lmtp/netty/NettyLMTPSServerTest.java | 2 +-
.../james/protocols/netty/AbstractSSLAwareChannelPipelineFactory.java | 2 --
.../org/apache/james/protocols/netty/BasicChannelInboundHandler.java | 1 -
.../src/main/java/org/apache/james/protocols/netty}/Encryption.java | 3 ++-
.../src/main/java/org/apache/james/protocols/netty/NettyServer.java | 1 -
.../test/java/org/apache/james/protocols/netty/NettyServerTest.java | 1 -
.../java/org/apache/james/protocols/pop3/AbstractPOP3SServerTest.java | 2 +-
.../apache/james/protocols/pop3/AbstractStartTlsPOP3ServerTest.java | 2 +-
.../org/apache/james/protocols/pop3/netty/NettyPOP3SServerTest.java | 4 +---
.../james/protocols/pop3/netty/NettyStartTlsPOP3ServerTest.java | 2 +-
.../java/org/apache/james/protocols/smtp/AbstractSMTPSServerTest.java | 2 +-
.../org/apache/james/protocols/smtp/netty/NettySMTPSServerTest.java | 2 +-
.../james/protocols/smtp/netty/NettyStartTlsSMTPServerTest.java | 2 +-
.../src/main/java/org/apache/james/imapserver/netty/IMAPServer.java | 2 +-
.../org/apache/james/imapserver/netty/ImapChannelUpstreamHandler.java | 2 +-
.../main/java/org/apache/james/imapserver/netty/NettyImapSession.java | 2 +-
.../james/protocols/lib/netty/AbstractConfigurableAsyncServer.java | 2 +-
.../james/protocols/lib/AbstractConfigurableAsyncServerTest.java | 2 +-
.../managesieveserver/netty/ManageSieveChannelUpstreamHandler.java | 2 +-
.../org/apache/james/managesieveserver/netty/ManageSieveServer.java | 2 +-
.../org/apache/james/smtpserver/netty/SMTPChannelInboundHandler.java | 2 +-
21 files changed, 18 insertions(+), 24 deletions(-)
diff --git a/protocols/lmtp/src/test/java/org/apache/james/protocols/lmtp/netty/NettyLMTPSServerTest.java b/protocols/lmtp/src/test/java/org/apache/james/protocols/lmtp/netty/NettyLMTPSServerTest.java
index 43725d0fd8..98d6484384 100644
--- a/protocols/lmtp/src/test/java/org/apache/james/protocols/lmtp/netty/NettyLMTPSServerTest.java
+++ b/protocols/lmtp/src/test/java/org/apache/james/protocols/lmtp/netty/NettyLMTPSServerTest.java
@@ -2,11 +2,11 @@ package org.apache.james.protocols.lmtp.netty;
import java.net.InetSocketAddress;
-import org.apache.james.protocols.api.Encryption;
import org.apache.james.protocols.api.Protocol;
import org.apache.james.protocols.api.ProtocolServer;
import org.apache.james.protocols.api.utils.BogusSslContextFactory;
import org.apache.james.protocols.lmtp.AbstractLMTPSServerTest;
+import org.apache.james.protocols.netty.Encryption;
import org.apache.james.protocols.netty.NettyServer;
public class NettyLMTPSServerTest extends AbstractLMTPSServerTest {
diff --git a/protocols/netty/src/main/java/org/apache/james/protocols/netty/AbstractSSLAwareChannelPipelineFactory.java b/protocols/netty/src/main/java/org/apache/james/protocols/netty/AbstractSSLAwareChannelPipelineFactory.java
index 2292c28401..16b49f2790 100644
--- a/protocols/netty/src/main/java/org/apache/james/protocols/netty/AbstractSSLAwareChannelPipelineFactory.java
+++ b/protocols/netty/src/main/java/org/apache/james/protocols/netty/AbstractSSLAwareChannelPipelineFactory.java
@@ -20,8 +20,6 @@ package org.apache.james.protocols.netty;
import javax.net.ssl.SSLEngine;
-import org.apache.james.protocols.api.Encryption;
-
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
diff --git a/protocols/netty/src/main/java/org/apache/james/protocols/netty/BasicChannelInboundHandler.java b/protocols/netty/src/main/java/org/apache/james/protocols/netty/BasicChannelInboundHandler.java
index 3db739e422..9a8c2a4b46 100644
--- a/protocols/netty/src/main/java/org/apache/james/protocols/netty/BasicChannelInboundHandler.java
+++ b/protocols/netty/src/main/java/org/apache/james/protocols/netty/BasicChannelInboundHandler.java
@@ -31,7 +31,6 @@ import java.util.concurrent.ConcurrentLinkedDeque;
import javax.net.ssl.SSLEngine;
import org.apache.james.protocols.api.CommandDetectionSession;
-import org.apache.james.protocols.api.Encryption;
import org.apache.james.protocols.api.Protocol;
import org.apache.james.protocols.api.ProtocolSession;
import org.apache.james.protocols.api.ProtocolSessionImpl;
diff --git a/protocols/api/src/main/java/org/apache/james/protocols/api/Encryption.java b/protocols/netty/src/main/java/org/apache/james/protocols/netty/Encryption.java
similarity index 98%
rename from protocols/api/src/main/java/org/apache/james/protocols/api/Encryption.java
rename to protocols/netty/src/main/java/org/apache/james/protocols/netty/Encryption.java
index e0618905e1..5841a75f0f 100644
--- a/protocols/api/src/main/java/org/apache/james/protocols/api/Encryption.java
+++ b/protocols/netty/src/main/java/org/apache/james/protocols/netty/Encryption.java
@@ -17,12 +17,13 @@
* under the License. *
****************************************************************/
-package org.apache.james.protocols.api;
+package org.apache.james.protocols.netty;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine;
import org.apache.commons.lang3.ArrayUtils;
+import org.apache.james.protocols.api.ClientAuth;
/**
* This class should be used to setup encrypted protocol handling
diff --git a/protocols/netty/src/main/java/org/apache/james/protocols/netty/NettyServer.java b/protocols/netty/src/main/java/org/apache/james/protocols/netty/NettyServer.java
index 1eda6a5672..a830adcc7d 100644
--- a/protocols/netty/src/main/java/org/apache/james/protocols/netty/NettyServer.java
+++ b/protocols/netty/src/main/java/org/apache/james/protocols/netty/NettyServer.java
@@ -22,7 +22,6 @@ import java.util.Optional;
import javax.inject.Inject;
-import org.apache.james.protocols.api.Encryption;
import org.apache.james.protocols.api.Protocol;
import com.google.common.base.Preconditions;
diff --git a/protocols/netty/src/test/java/org/apache/james/protocols/netty/NettyServerTest.java b/protocols/netty/src/test/java/org/apache/james/protocols/netty/NettyServerTest.java
index 61bf0f658d..9c575784e8 100644
--- a/protocols/netty/src/test/java/org/apache/james/protocols/netty/NettyServerTest.java
+++ b/protocols/netty/src/test/java/org/apache/james/protocols/netty/NettyServerTest.java
@@ -24,7 +24,6 @@ import static org.mockito.Mockito.mock;
import javax.net.ssl.SSLContext;
-import org.apache.james.protocols.api.Encryption;
import org.apache.james.protocols.api.Protocol;
import org.junit.jupiter.api.Test;
diff --git a/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/AbstractPOP3SServerTest.java b/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/AbstractPOP3SServerTest.java
index 6d7984cbc3..f258317145 100644
--- a/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/AbstractPOP3SServerTest.java
+++ b/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/AbstractPOP3SServerTest.java
@@ -20,11 +20,11 @@ package org.apache.james.protocols.pop3;
import org.apache.commons.net.pop3.POP3Client;
import org.apache.commons.net.pop3.POP3SClient;
-import org.apache.james.protocols.api.Encryption;
import org.apache.james.protocols.api.Protocol;
import org.apache.james.protocols.api.ProtocolServer;
import org.apache.james.protocols.api.utils.BogusSslContextFactory;
import org.apache.james.protocols.api.utils.BogusTrustManagerFactory;
+import org.apache.james.protocols.netty.Encryption;
public abstract class AbstractPOP3SServerTest extends AbstractPOP3ServerTest {
diff --git a/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/AbstractStartTlsPOP3ServerTest.java b/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/AbstractStartTlsPOP3ServerTest.java
index 03c1aea80e..bce04f9f00 100644
--- a/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/AbstractStartTlsPOP3ServerTest.java
+++ b/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/AbstractStartTlsPOP3ServerTest.java
@@ -26,13 +26,13 @@ import java.util.Arrays;
import org.apache.commons.net.pop3.POP3Reply;
import org.apache.commons.net.pop3.POP3SClient;
import org.apache.james.metrics.tests.RecordingMetricFactory;
-import org.apache.james.protocols.api.Encryption;
import org.apache.james.protocols.api.Protocol;
import org.apache.james.protocols.api.ProtocolServer;
import org.apache.james.protocols.api.handler.WiringException;
import org.apache.james.protocols.api.utils.BogusSslContextFactory;
import org.apache.james.protocols.api.utils.BogusTrustManagerFactory;
import org.apache.james.protocols.api.utils.ProtocolServerUtils;
+import org.apache.james.protocols.netty.Encryption;
import org.apache.james.protocols.pop3.core.AbstractPassCmdHandler;
import org.apache.james.protocols.pop3.utils.MockMailbox;
import org.apache.james.protocols.pop3.utils.TestPassCmdHandler;
diff --git a/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/netty/NettyPOP3SServerTest.java b/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/netty/NettyPOP3SServerTest.java
index 590381efb7..9f39578b99 100644
--- a/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/netty/NettyPOP3SServerTest.java
+++ b/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/netty/NettyPOP3SServerTest.java
@@ -20,13 +20,11 @@ package org.apache.james.protocols.pop3.netty;
import java.net.InetSocketAddress;
-import org.apache.james.protocols.api.Encryption;
import org.apache.james.protocols.api.Protocol;
import org.apache.james.protocols.api.ProtocolServer;
+import org.apache.james.protocols.netty.Encryption;
import org.apache.james.protocols.netty.NettyServer;
import org.apache.james.protocols.pop3.AbstractPOP3SServerTest;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
public class NettyPOP3SServerTest extends AbstractPOP3SServerTest {
private static final String LOCALHOST_IP = "127.0.0.1";
diff --git a/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/netty/NettyStartTlsPOP3ServerTest.java b/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/netty/NettyStartTlsPOP3ServerTest.java
index 2bcbd72a59..39f64cd09b 100644
--- a/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/netty/NettyStartTlsPOP3ServerTest.java
+++ b/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/netty/NettyStartTlsPOP3ServerTest.java
@@ -20,9 +20,9 @@ package org.apache.james.protocols.pop3.netty;
import java.net.InetSocketAddress;
-import org.apache.james.protocols.api.Encryption;
import org.apache.james.protocols.api.Protocol;
import org.apache.james.protocols.api.ProtocolServer;
+import org.apache.james.protocols.netty.Encryption;
import org.apache.james.protocols.netty.NettyServer;
import org.apache.james.protocols.pop3.AbstractStartTlsPOP3ServerTest;
diff --git a/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/AbstractSMTPSServerTest.java b/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/AbstractSMTPSServerTest.java
index 94249a8a7e..442a3ec87f 100644
--- a/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/AbstractSMTPSServerTest.java
+++ b/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/AbstractSMTPSServerTest.java
@@ -20,11 +20,11 @@ package org.apache.james.protocols.smtp;
import org.apache.commons.net.smtp.SMTPClient;
import org.apache.commons.net.smtp.SMTPSClient;
-import org.apache.james.protocols.api.Encryption;
import org.apache.james.protocols.api.Protocol;
import org.apache.james.protocols.api.ProtocolServer;
import org.apache.james.protocols.api.utils.BogusSslContextFactory;
import org.apache.james.protocols.api.utils.BogusTrustManagerFactory;
+import org.apache.james.protocols.netty.Encryption;
public abstract class AbstractSMTPSServerTest extends AbstractSMTPServerTest {
diff --git a/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/netty/NettySMTPSServerTest.java b/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/netty/NettySMTPSServerTest.java
index 36eb453686..21a0c33532 100644
--- a/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/netty/NettySMTPSServerTest.java
+++ b/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/netty/NettySMTPSServerTest.java
@@ -20,9 +20,9 @@ package org.apache.james.protocols.smtp.netty;
import java.net.InetSocketAddress;
-import org.apache.james.protocols.api.Encryption;
import org.apache.james.protocols.api.Protocol;
import org.apache.james.protocols.api.ProtocolServer;
+import org.apache.james.protocols.netty.Encryption;
import org.apache.james.protocols.netty.NettyServer;
import org.apache.james.protocols.smtp.AbstractSMTPSServerTest;
diff --git a/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/netty/NettyStartTlsSMTPServerTest.java b/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/netty/NettyStartTlsSMTPServerTest.java
index 8cfaf77bdc..394d8baf03 100644
--- a/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/netty/NettyStartTlsSMTPServerTest.java
+++ b/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/netty/NettyStartTlsSMTPServerTest.java
@@ -35,7 +35,6 @@ import javax.mail.internet.MimeMessage;
import org.apache.commons.net.smtp.SMTPReply;
import org.apache.commons.net.smtp.SMTPSClient;
import org.apache.james.metrics.tests.RecordingMetricFactory;
-import org.apache.james.protocols.api.Encryption;
import org.apache.james.protocols.api.Protocol;
import org.apache.james.protocols.api.ProtocolServer;
import org.apache.james.protocols.api.handler.ProtocolHandler;
@@ -46,6 +45,7 @@ import org.apache.james.protocols.api.utils.BogusTrustManagerFactory;
import org.apache.james.protocols.api.utils.ProtocolServerUtils;
import org.apache.james.protocols.netty.AbstractChannelPipelineFactory;
import org.apache.james.protocols.netty.AllButStartTlsLineChannelHandlerFactory;
+import org.apache.james.protocols.netty.Encryption;
import org.apache.james.protocols.netty.NettyServer;
import org.apache.james.protocols.smtp.SMTPConfigurationImpl;
import org.apache.james.protocols.smtp.SMTPProtocol;
diff --git a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServer.java b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServer.java
index 4e3ce1b928..0540a41012 100644
--- a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServer.java
+++ b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServer.java
@@ -32,13 +32,13 @@ import org.apache.james.imap.api.ImapConstants;
import org.apache.james.imap.api.process.ImapProcessor;
import org.apache.james.imap.decode.ImapDecoder;
import org.apache.james.imap.encode.ImapEncoder;
-import org.apache.james.protocols.api.Encryption;
import org.apache.james.protocols.api.OidcSASLConfiguration;
import org.apache.james.protocols.lib.netty.AbstractConfigurableAsyncServer;
import org.apache.james.protocols.netty.AbstractChannelPipelineFactory;
import org.apache.james.protocols.netty.ChannelHandlerFactory;
import org.apache.james.protocols.netty.ConnectionLimitUpstreamHandler;
import org.apache.james.protocols.netty.ConnectionPerIpLimitUpstreamHandler;
+import org.apache.james.protocols.netty.Encryption;
import org.apache.james.protocols.netty.HandlerConstants;
import org.apache.james.util.Size;
import org.slf4j.Logger;
diff --git a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapChannelUpstreamHandler.java b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapChannelUpstreamHandler.java
index d9017cfd02..a34dd6c4bf 100644
--- a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapChannelUpstreamHandler.java
+++ b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapChannelUpstreamHandler.java
@@ -37,7 +37,7 @@ import org.apache.james.imap.encode.ImapResponseComposer;
import org.apache.james.imap.encode.base.ImapResponseComposerImpl;
import org.apache.james.imap.main.ResponseEncoder;
import org.apache.james.metrics.api.Metric;
-import org.apache.james.protocols.api.Encryption;
+import org.apache.james.protocols.netty.Encryption;
import org.apache.james.util.MDCBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/NettyImapSession.java b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/NettyImapSession.java
index e19f2c6750..0099d20af5 100644
--- a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/NettyImapSession.java
+++ b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/NettyImapSession.java
@@ -36,8 +36,8 @@ import org.apache.james.imap.encode.base.ImapResponseComposerImpl;
import org.apache.james.imap.encode.main.DefaultLocalizer;
import org.apache.james.imap.message.Literal;
import org.apache.james.imap.message.response.ImmutableStatusResponse;
-import org.apache.james.protocols.api.Encryption;
import org.apache.james.protocols.api.OidcSASLConfiguration;
+import org.apache.james.protocols.netty.Encryption;
import org.apache.james.protocols.netty.LineHandlerAware;
import io.netty.buffer.Unpooled;
diff --git a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractConfigurableAsyncServer.java b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractConfigurableAsyncServer.java
index a744bdf44f..de8b5f2397 100644
--- a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractConfigurableAsyncServer.java
+++ b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractConfigurableAsyncServer.java
@@ -42,12 +42,12 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.james.filesystem.api.FileSystem;
import org.apache.james.lifecycle.api.Configurable;
import org.apache.james.protocols.api.ClientAuth;
-import org.apache.james.protocols.api.Encryption;
import org.apache.james.protocols.lib.jmx.ServerMBean;
import org.apache.james.protocols.netty.AbstractAsyncServer;
import org.apache.james.protocols.netty.AbstractChannelPipelineFactory;
import org.apache.james.protocols.netty.AbstractSSLAwareChannelPipelineFactory;
import org.apache.james.protocols.netty.ChannelHandlerFactory;
+import org.apache.james.protocols.netty.Encryption;
import org.apache.james.util.concurrent.NamedThreadFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/server/protocols/protocols-library/src/test/java/org/apache/james/protocols/lib/AbstractConfigurableAsyncServerTest.java b/server/protocols/protocols-library/src/test/java/org/apache/james/protocols/lib/AbstractConfigurableAsyncServerTest.java
index b12b7a046e..df072ea1d7 100644
--- a/server/protocols/protocols-library/src/test/java/org/apache/james/protocols/lib/AbstractConfigurableAsyncServerTest.java
+++ b/server/protocols/protocols-library/src/test/java/org/apache/james/protocols/lib/AbstractConfigurableAsyncServerTest.java
@@ -34,10 +34,10 @@ import java.util.Map;
import org.apache.commons.lang3.NotImplementedException;
import org.apache.james.filesystem.api.FileSystem;
import org.apache.james.protocols.api.ClientAuth;
-import org.apache.james.protocols.api.Encryption;
import org.apache.james.protocols.lib.mock.ConfigLoader;
import org.apache.james.protocols.lib.netty.AbstractConfigurableAsyncServer;
import org.apache.james.protocols.netty.ChannelHandlerFactory;
+import org.apache.james.protocols.netty.Encryption;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
diff --git a/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveChannelUpstreamHandler.java b/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveChannelUpstreamHandler.java
index 28c3acb1c3..8687f8df18 100644
--- a/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveChannelUpstreamHandler.java
+++ b/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveChannelUpstreamHandler.java
@@ -27,7 +27,7 @@ import org.apache.james.managesieve.api.SessionTerminatedException;
import org.apache.james.managesieve.transcode.ManageSieveProcessor;
import org.apache.james.managesieve.transcode.NotEnoughDataException;
import org.apache.james.managesieve.util.SettableSession;
-import org.apache.james.protocols.api.Encryption;
+import org.apache.james.protocols.netty.Encryption;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveServer.java b/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveServer.java
index 1254bd2420..492dd1172f 100644
--- a/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveServer.java
+++ b/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveServer.java
@@ -31,13 +31,13 @@ import org.apache.commons.configuration2.HierarchicalConfiguration;
import org.apache.commons.configuration2.ex.ConfigurationException;
import org.apache.commons.configuration2.tree.ImmutableNode;
import org.apache.james.managesieve.transcode.ManageSieveProcessor;
-import org.apache.james.protocols.api.Encryption;
import org.apache.james.protocols.lib.netty.AbstractConfigurableAsyncServer;
import org.apache.james.protocols.netty.AbstractChannelPipelineFactory;
import org.apache.james.protocols.netty.AllButStartTlsLineChannelHandlerFactory;
import org.apache.james.protocols.netty.ChannelHandlerFactory;
import org.apache.james.protocols.netty.ConnectionLimitUpstreamHandler;
import org.apache.james.protocols.netty.ConnectionPerIpLimitUpstreamHandler;
+import org.apache.james.protocols.netty.Encryption;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/SMTPChannelInboundHandler.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/SMTPChannelInboundHandler.java
index 251522675c..44a695473d 100644
--- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/SMTPChannelInboundHandler.java
+++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/SMTPChannelInboundHandler.java
@@ -19,10 +19,10 @@
package org.apache.james.smtpserver.netty;
import org.apache.james.lifecycle.api.LifecycleUtil;
-import org.apache.james.protocols.api.Encryption;
import org.apache.james.protocols.api.Protocol;
import org.apache.james.protocols.api.ProtocolSession.State;
import org.apache.james.protocols.netty.BasicChannelInboundHandler;
+import org.apache.james.protocols.netty.Encryption;
import org.apache.james.protocols.smtp.SMTPSession;
import org.apache.james.protocols.smtp.core.SMTPMDCContextFactory;
import org.apache.james.smtpserver.SMTPConstants;
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[james-project] 02/08: JAMES-3738 Encryption should be able to create Ssl handler
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit ed81e1374b8a2d2347b02f785deca5d6868251ad
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Wed Mar 23 10:15:11 2022 +0700
JAMES-3738 Encryption should be able to create Ssl handler
---
.../netty/AbstractSSLAwareChannelPipelineFactory.java | 10 +---------
.../james/protocols/netty/BasicChannelInboundHandler.java | 11 ++---------
.../java/org/apache/james/protocols/netty/Encryption.java | 12 +++++++++++-
.../james/protocols/netty/NettyProtocolTransport.java | 14 +++++---------
.../java/org/apache/james/imapserver/netty/IMAPServer.java | 10 +---------
.../apache/james/imapserver/netty/NettyImapSession.java | 6 +-----
.../netty/ManageSieveChannelUpstreamHandler.java | 5 +----
.../james/managesieveserver/netty/ManageSieveServer.java | 12 ++----------
8 files changed, 24 insertions(+), 56 deletions(-)
diff --git a/protocols/netty/src/main/java/org/apache/james/protocols/netty/AbstractSSLAwareChannelPipelineFactory.java b/protocols/netty/src/main/java/org/apache/james/protocols/netty/AbstractSSLAwareChannelPipelineFactory.java
index 16b49f2790..74770856f1 100644
--- a/protocols/netty/src/main/java/org/apache/james/protocols/netty/AbstractSSLAwareChannelPipelineFactory.java
+++ b/protocols/netty/src/main/java/org/apache/james/protocols/netty/AbstractSSLAwareChannelPipelineFactory.java
@@ -18,12 +18,9 @@
****************************************************************/
package org.apache.james.protocols.netty;
-import javax.net.ssl.SSLEngine;
-
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
-import io.netty.handler.ssl.SslHandler;
import io.netty.util.concurrent.EventExecutorGroup;
@@ -55,12 +52,7 @@ public abstract class AbstractSSLAwareChannelPipelineFactory<C extends SocketCha
super.initChannel(channel);
if (isSSLSocket()) {
- ChannelPipeline pipeline = channel.pipeline();
- // We need to set clientMode to false.
- // See https://issues.apache.org/jira/browse/JAMES-1025
- SSLEngine engine = secure.createSSLEngine();
- engine.setUseClientMode(false);
- pipeline.addFirst(HandlerConstants.SSL_HANDLER, new SslHandler(engine));
+ channel.pipeline().addFirst(HandlerConstants.SSL_HANDLER, secure.sslHandler());
}
}
diff --git a/protocols/netty/src/main/java/org/apache/james/protocols/netty/BasicChannelInboundHandler.java b/protocols/netty/src/main/java/org/apache/james/protocols/netty/BasicChannelInboundHandler.java
index 9a8c2a4b46..2333a79b81 100644
--- a/protocols/netty/src/main/java/org/apache/james/protocols/netty/BasicChannelInboundHandler.java
+++ b/protocols/netty/src/main/java/org/apache/james/protocols/netty/BasicChannelInboundHandler.java
@@ -28,8 +28,6 @@ import java.util.List;
import java.util.Optional;
import java.util.concurrent.ConcurrentLinkedDeque;
-import javax.net.ssl.SSLEngine;
-
import org.apache.james.protocols.api.CommandDetectionSession;
import org.apache.james.protocols.api.Protocol;
import org.apache.james.protocols.api.ProtocolSession;
@@ -198,13 +196,8 @@ public class BasicChannelInboundHandler extends ChannelInboundHandlerAdapter imp
- protected ProtocolSession createSession(ChannelHandlerContext ctx) throws Exception {
- SSLEngine engine = null;
- if (secure != null) {
- engine = secure.createSSLEngine();
- }
-
- return protocol.newSession(new NettyProtocolTransport(ctx.channel(), engine));
+ protected ProtocolSession createSession(ChannelHandlerContext ctx) {
+ return protocol.newSession(new NettyProtocolTransport(ctx.channel(), secure));
}
@Override
diff --git a/protocols/netty/src/main/java/org/apache/james/protocols/netty/Encryption.java b/protocols/netty/src/main/java/org/apache/james/protocols/netty/Encryption.java
index 5841a75f0f..09982d5fe6 100644
--- a/protocols/netty/src/main/java/org/apache/james/protocols/netty/Encryption.java
+++ b/protocols/netty/src/main/java/org/apache/james/protocols/netty/Encryption.java
@@ -25,6 +25,8 @@ import javax.net.ssl.SSLEngine;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.james.protocols.api.ClientAuth;
+import io.netty.handler.ssl.SslHandler;
+
/**
* This class should be used to setup encrypted protocol handling
*/
@@ -117,7 +119,7 @@ public final class Encryption {
* Create a new {@link SSLEngine} configured according to this class.
* @return sslengine
*/
- public SSLEngine createSSLEngine() {
+ private SSLEngine createSSLEngine() {
SSLEngine engine = context.createSSLEngine();
// We need to copy the String array because of possible security issues.
@@ -135,4 +137,12 @@ public final class Encryption {
}
return engine;
}
+
+ public SslHandler sslHandler() {
+ SSLEngine engine = createSSLEngine();
+ // We need to set clientMode to false.
+ // See https://issues.apache.org/jira/browse/JAMES-1025
+ engine.setUseClientMode(false);
+ return new SslHandler(engine);
+ }
}
diff --git a/protocols/netty/src/main/java/org/apache/james/protocols/netty/NettyProtocolTransport.java b/protocols/netty/src/main/java/org/apache/james/protocols/netty/NettyProtocolTransport.java
index c7509383ea..05a8aa6821 100644
--- a/protocols/netty/src/main/java/org/apache/james/protocols/netty/NettyProtocolTransport.java
+++ b/protocols/netty/src/main/java/org/apache/james/protocols/netty/NettyProtocolTransport.java
@@ -25,8 +25,6 @@ import java.io.InputStream;
import java.net.InetSocketAddress;
import java.nio.channels.FileChannel;
-import javax.net.ssl.SSLEngine;
-
import org.apache.james.protocols.api.AbstractProtocolTransport;
import org.apache.james.protocols.api.ProtocolSession;
import org.apache.james.protocols.api.handler.LineHandler;
@@ -45,11 +43,11 @@ import io.netty.handler.stream.ChunkedStream;
public class NettyProtocolTransport extends AbstractProtocolTransport {
private final Channel channel;
- private final SSLEngine engine;
+ private final Encryption encryption;
- public NettyProtocolTransport(Channel channel, SSLEngine engine) {
+ public NettyProtocolTransport(Channel channel, Encryption encryption) {
this.channel = channel;
- this.engine = engine;
+ this.encryption = encryption;
}
@Override
@@ -69,7 +67,7 @@ public class NettyProtocolTransport extends AbstractProtocolTransport {
@Override
public boolean isStartTLSSupported() {
- return engine != null;
+ return encryption != null && encryption.isStartTLS();
}
@@ -84,9 +82,7 @@ public class NettyProtocolTransport extends AbstractProtocolTransport {
* Add the {@link SslHandler} to the pipeline and start encrypting after the next written message
*/
private void prepareStartTLS() {
- SslHandler filter = new SslHandler(engine, true);
- filter.engine().setUseClientMode(false);
- channel.pipeline().addFirst(HandlerConstants.SSL_HANDLER, filter);
+ channel.pipeline().addFirst(HandlerConstants.SSL_HANDLER, encryption.sslHandler());
}
@Override
diff --git a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServer.java b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServer.java
index 0540a41012..fa73574494 100644
--- a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServer.java
+++ b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServer.java
@@ -22,8 +22,6 @@ import java.net.MalformedURLException;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
-import javax.net.ssl.SSLEngine;
-
import org.apache.commons.configuration2.HierarchicalConfiguration;
import org.apache.commons.configuration2.ex.ConfigurationException;
import org.apache.commons.configuration2.tree.ImmutableNode;
@@ -51,7 +49,6 @@ import com.google.common.collect.ImmutableSet;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelPipeline;
-import io.netty.handler.ssl.SslHandler;
import io.netty.handler.stream.ChunkedWriteHandler;
@@ -235,12 +232,7 @@ public class IMAPServer extends AbstractConfigurableAsyncServer implements ImapC
Encryption secure = getEncryption();
if (secure != null && !secure.isStartTLS()) {
- // We need to set clientMode to false.
- // See https://issues.apache.org/jira/browse/JAMES-1025
- SSLEngine engine = secure.createSSLEngine();
- engine.setUseClientMode(false);
- pipeline.addFirst(SSL_HANDLER, new SslHandler(engine));
-
+ pipeline.addFirst(SSL_HANDLER, secure.sslHandler());
}
pipeline.addLast(CHUNK_WRITE_HANDLER, new ChunkedWriteHandler());
diff --git a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/NettyImapSession.java b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/NettyImapSession.java
index 0099d20af5..c8845ebc24 100644
--- a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/NettyImapSession.java
+++ b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/NettyImapSession.java
@@ -47,7 +47,6 @@ import io.netty.handler.codec.compression.JZlibEncoder;
import io.netty.handler.codec.compression.ZlibDecoder;
import io.netty.handler.codec.compression.ZlibEncoder;
import io.netty.handler.codec.compression.ZlibWrapper;
-import io.netty.handler.ssl.SslHandler;
public class NettyImapSession implements ImapSession, NettyConstants {
private static final int BUFFER_SIZE = 2048;
@@ -161,10 +160,7 @@ public class NettyImapSession implements ImapSession, NettyConstants {
channel.config().setAutoRead(false);
write(statusResponse);
- SslHandler filter = new SslHandler(secure.createSSLEngine(), false);
-
- filter.engine().setUseClientMode(false);
- channel.pipeline().addFirst(SSL_HANDLER, filter);
+ channel.pipeline().addFirst(SSL_HANDLER, secure.sslHandler());
stopDetectingCommandInjection();
channel.config().setAutoRead(true);
diff --git a/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveChannelUpstreamHandler.java b/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveChannelUpstreamHandler.java
index 8687f8df18..2a1098b041 100644
--- a/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveChannelUpstreamHandler.java
+++ b/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveChannelUpstreamHandler.java
@@ -38,7 +38,6 @@ import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.codec.TooLongFrameException;
-import io.netty.handler.ssl.SslHandler;
@ChannelHandler.Sharable
public class ManageSieveChannelUpstreamHandler extends ChannelInboundHandlerAdapter {
@@ -144,9 +143,7 @@ public class ManageSieveChannelUpstreamHandler extends ChannelInboundHandlerAdap
private void turnSSLon(Channel channel) {
if (secure != null) {
channel.config().setAutoRead(false);
- SslHandler filter = new SslHandler(secure.createSSLEngine(), false);
- filter.engine().setUseClientMode(false);
- channel.pipeline().addFirst(SSL_HANDLER, filter);
+ channel.pipeline().addFirst(SSL_HANDLER, secure.sslHandler());
channel.config().setAutoRead(true);
}
}
diff --git a/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveServer.java b/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveServer.java
index 492dd1172f..93ab6ab22c 100644
--- a/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveServer.java
+++ b/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveServer.java
@@ -25,8 +25,6 @@ import static org.apache.james.protocols.netty.HandlerConstants.CONNECTION_LIMIT
import java.util.Optional;
-import javax.net.ssl.SSLEngine;
-
import org.apache.commons.configuration2.HierarchicalConfiguration;
import org.apache.commons.configuration2.ex.ConfigurationException;
import org.apache.commons.configuration2.tree.ImmutableNode;
@@ -46,7 +44,6 @@ import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;
-import io.netty.handler.ssl.SslHandler;
import io.netty.handler.stream.ChunkedWriteHandler;
import io.netty.util.CharsetUtil;
@@ -103,16 +100,11 @@ public class ManageSieveServer extends AbstractConfigurableAsyncServer implement
}
@Override
- public void initChannel(Channel channel) throws Exception {
+ public void initChannel(Channel channel) {
ChannelPipeline pipeline = channel.pipeline();
Encryption secure = getEncryption();
if (secure != null && !secure.isStartTLS()) {
- // We need to set clientMode to false.
- // See https://issues.apache.org/jira/browse/JAMES-1025
- SSLEngine engine = secure.createSSLEngine();
- engine.setUseClientMode(false);
- pipeline.addFirst(SSL_HANDLER, new SslHandler(engine));
-
+ pipeline.addFirst(SSL_HANDLER, secure.sslHandler());
}
connectionLimitUpstreamHandler.ifPresent(handler -> pipeline.addLast(CONNECTION_LIMIT_HANDLER, handler));
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[james-project] 03/08: JAMES-3738 Hide java details behind encryption
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit c63d794eb83f214862680f7c62402f32761c25bc
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Wed Mar 23 10:24:19 2022 +0700
JAMES-3738 Hide java details behind encryption
---
.../james/protocols/netty/AbstractSSLAwareChannelPipelineFactory.java | 2 +-
.../src/main/java/org/apache/james/protocols/netty/Encryption.java | 4 ++++
.../main/java/org/apache/james/imapserver/netty/NettyImapSession.java | 2 +-
.../james/protocols/lib/AbstractConfigurableAsyncServerTest.java | 4 ++--
4 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/protocols/netty/src/main/java/org/apache/james/protocols/netty/AbstractSSLAwareChannelPipelineFactory.java b/protocols/netty/src/main/java/org/apache/james/protocols/netty/AbstractSSLAwareChannelPipelineFactory.java
index 74770856f1..30a4ac914f 100644
--- a/protocols/netty/src/main/java/org/apache/james/protocols/netty/AbstractSSLAwareChannelPipelineFactory.java
+++ b/protocols/netty/src/main/java/org/apache/james/protocols/netty/AbstractSSLAwareChannelPipelineFactory.java
@@ -60,6 +60,6 @@ public abstract class AbstractSSLAwareChannelPipelineFactory<C extends SocketCha
* Return if the socket is using SSL/TLS
*/
protected boolean isSSLSocket() {
- return secure != null && secure.getContext() != null && !secure.isStartTLS();
+ return secure != null && secure.supportsEncryption() && !secure.isStartTLS();
}
}
diff --git a/protocols/netty/src/main/java/org/apache/james/protocols/netty/Encryption.java b/protocols/netty/src/main/java/org/apache/james/protocols/netty/Encryption.java
index 09982d5fe6..f45bed3682 100644
--- a/protocols/netty/src/main/java/org/apache/james/protocols/netty/Encryption.java
+++ b/protocols/netty/src/main/java/org/apache/james/protocols/netty/Encryption.java
@@ -97,6 +97,10 @@ public final class Encryption {
return starttls;
}
+ public boolean supportsEncryption() {
+ return context != null;
+ }
+
/**
* Return the Ciphersuites that are allowed for the {@link Encryption} or
* <code>null</code> if all should be allowed
diff --git a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/NettyImapSession.java b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/NettyImapSession.java
index c8845ebc24..9c63406a3f 100644
--- a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/NettyImapSession.java
+++ b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/NettyImapSession.java
@@ -199,7 +199,7 @@ public class NettyImapSession implements ImapSession, NettyConstants {
@Override
public boolean supportStartTLS() {
- return secure != null && secure.getContext() != null;
+ return secure != null && secure.supportsEncryption();
}
@Override
diff --git a/server/protocols/protocols-library/src/test/java/org/apache/james/protocols/lib/AbstractConfigurableAsyncServerTest.java b/server/protocols/protocols-library/src/test/java/org/apache/james/protocols/lib/AbstractConfigurableAsyncServerTest.java
index df072ea1d7..eee4a1b6ed 100644
--- a/server/protocols/protocols-library/src/test/java/org/apache/james/protocols/lib/AbstractConfigurableAsyncServerTest.java
+++ b/server/protocols/protocols-library/src/test/java/org/apache/james/protocols/lib/AbstractConfigurableAsyncServerTest.java
@@ -203,7 +203,7 @@ class AbstractConfigurableAsyncServerTest {
assertThat(testServer.getEncryption().isStartTLS()).isFalse();
assertThat(testServer.getEncryption().getEnabledCipherSuites()).isEmpty(); // no default constraints
assertThat(testServer.getEncryption().getClientAuth()).isEqualTo(ClientAuth.NONE);
- assertThat(testServer.getEncryption().getContext()).isNotNull();
+ assertThat(testServer.getEncryption().supportsEncryption()).isTrue();
}
@Test
@@ -217,7 +217,7 @@ class AbstractConfigurableAsyncServerTest {
assertThat(testServer.getEncryption().isStartTLS()).isTrue();
assertThat(testServer.getEncryption().getEnabledCipherSuites()).isEmpty(); // no default constraints
assertThat(testServer.getEncryption().getClientAuth()).isEqualTo(ClientAuth.NONE);
- assertThat(testServer.getEncryption().getContext()).isNotNull();
+ assertThat(testServer.getEncryption().supportsEncryption()).isTrue();
}
@Test
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[james-project] 06/08: JAMES-3738 Encryption: annotates methods visible for testing
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit fa93ef5afae14181eba0e8818321bb685c2637b7
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Wed Mar 23 10:30:06 2022 +0700
JAMES-3738 Encryption: annotates methods visible for testing
---
.../src/main/java/org/apache/james/protocols/netty/Encryption.java | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/protocols/netty/src/main/java/org/apache/james/protocols/netty/Encryption.java b/protocols/netty/src/main/java/org/apache/james/protocols/netty/Encryption.java
index 89dbda0d96..95baeda558 100644
--- a/protocols/netty/src/main/java/org/apache/james/protocols/netty/Encryption.java
+++ b/protocols/netty/src/main/java/org/apache/james/protocols/netty/Encryption.java
@@ -25,6 +25,8 @@ import javax.net.ssl.SSLEngine;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.james.protocols.api.ClientAuth;
+import com.google.common.annotations.VisibleForTesting;
+
import io.netty.handler.ssl.SslHandler;
/**
@@ -32,6 +34,7 @@ import io.netty.handler.ssl.SslHandler;
*/
public interface Encryption {
+ @VisibleForTesting
static Encryption createTls(SSLContext context) {
return createTls(context, null, ClientAuth.NONE);
}
@@ -49,6 +52,7 @@ public interface Encryption {
return new Encryption.LegacyJavaEncryption(context, false, enabledCipherSuites, clientAuth);
}
+ @VisibleForTesting
static Encryption createStartTls(SSLContext context) {
return createStartTls(context, null, ClientAuth.NONE);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[james-project] 08/08: JAMES-3738 Send initial STARTTLS reply before pipeline changes
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 0ee2cae6a9d8739902adcd191f90fd41b972a9b2
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Thu Mar 24 10:19:30 2022 +0700
JAMES-3738 Send initial STARTTLS reply before pipeline changes
---
.../java/org/apache/james/protocols/netty/NettyProtocolTransport.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/protocols/netty/src/main/java/org/apache/james/protocols/netty/NettyProtocolTransport.java b/protocols/netty/src/main/java/org/apache/james/protocols/netty/NettyProtocolTransport.java
index 05a8aa6821..994708f5c1 100644
--- a/protocols/netty/src/main/java/org/apache/james/protocols/netty/NettyProtocolTransport.java
+++ b/protocols/netty/src/main/java/org/apache/james/protocols/netty/NettyProtocolTransport.java
@@ -87,11 +87,11 @@ public class NettyProtocolTransport extends AbstractProtocolTransport {
@Override
protected void writeToClient(byte[] bytes, ProtocolSession session, boolean startTLS) {
+ channel.writeAndFlush(Unpooled.wrappedBuffer(bytes));
+
if (startTLS) {
prepareStartTLS();
}
-
- channel.writeAndFlush(Unpooled.wrappedBuffer(bytes));
}
@Override
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[james-project] 07/08: JAMES-3738 Extract Encryption instanciation and configuration out of AbstractConfigurableAsyncServer
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 01f11a4a3960fa07a66725ac53945ec8338855b0
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Wed Mar 23 10:48:45 2022 +0700
JAMES-3738 Extract Encryption instanciation and configuration out of AbstractConfigurableAsyncServer
---
.../apache/james/protocols/netty/Encryption.java | 4 +
.../protocols/lib/LegacyJavaEncryptionFactory.java | 81 ++++++++++++
.../org/apache/james/protocols/lib/SslConfig.java | 145 +++++++++++++++++++++
.../lib/netty/AbstractConfigurableAsyncServer.java | 101 +-------------
4 files changed, 237 insertions(+), 94 deletions(-)
diff --git a/protocols/netty/src/main/java/org/apache/james/protocols/netty/Encryption.java b/protocols/netty/src/main/java/org/apache/james/protocols/netty/Encryption.java
index 95baeda558..19b8b18441 100644
--- a/protocols/netty/src/main/java/org/apache/james/protocols/netty/Encryption.java
+++ b/protocols/netty/src/main/java/org/apache/james/protocols/netty/Encryption.java
@@ -34,6 +34,10 @@ import io.netty.handler.ssl.SslHandler;
*/
public interface Encryption {
+ interface Factory {
+ Encryption create() throws Exception;
+ }
+
@VisibleForTesting
static Encryption createTls(SSLContext context) {
return createTls(context, null, ClientAuth.NONE);
diff --git a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/LegacyJavaEncryptionFactory.java b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/LegacyJavaEncryptionFactory.java
new file mode 100644
index 0000000000..49dcaf643b
--- /dev/null
+++ b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/LegacyJavaEncryptionFactory.java
@@ -0,0 +1,81 @@
+/****************************************************************
+ * 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. *
+ ****************************************************************/
+
+package org.apache.james.protocols.lib;
+
+import java.util.Optional;
+
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.X509ExtendedKeyManager;
+
+import org.apache.james.filesystem.api.FileSystem;
+import org.apache.james.protocols.netty.Encryption;
+
+import nl.altindag.ssl.SSLFactory;
+import nl.altindag.ssl.util.PemUtils;
+
+public class LegacyJavaEncryptionFactory implements Encryption.Factory {
+ private final FileSystem fileSystem;
+ private final SslConfig sslConfig;
+
+ public LegacyJavaEncryptionFactory(FileSystem fileSystem, SslConfig sslConfig) {
+ this.fileSystem = fileSystem;
+ this.sslConfig = sslConfig;
+ }
+
+ @Override
+ public Encryption create() throws Exception {
+ SSLFactory.Builder sslFactoryBuilder = SSLFactory.builder()
+ .withSslContextAlgorithm("TLS");
+ if (sslConfig.getKeystore() != null) {
+ char[] passwordAsCharArray = Optional.ofNullable(sslConfig.getSecret())
+ .orElse("")
+ .toCharArray();
+ sslFactoryBuilder.withIdentityMaterial(
+ fileSystem.getFile(sslConfig.getKeystore()).toPath(),
+ passwordAsCharArray,
+ passwordAsCharArray,
+ sslConfig.getKeystoreType());
+ } else {
+ X509ExtendedKeyManager keyManager = PemUtils.loadIdentityMaterial(
+ fileSystem.getResource(sslConfig.getCertificates()),
+ fileSystem.getResource(sslConfig.getPrivateKey()),
+ Optional.ofNullable(sslConfig.getSecret())
+ .map(String::toCharArray)
+ .orElse(null));
+
+ sslFactoryBuilder.withIdentityMaterial(keyManager);
+ }
+
+ if (sslConfig.getClientAuth() != null && sslConfig.getTruststore() != null) {
+ sslFactoryBuilder.withTrustMaterial(
+ fileSystem.getFile(sslConfig.getTruststore()).toPath(),
+ sslConfig.getTruststoreSecret(),
+ sslConfig.getKeystoreType());
+ }
+
+ SSLContext context = sslFactoryBuilder.build().getSslContext();
+
+ if (sslConfig.useStartTLS()) {
+ return Encryption.createStartTls(context, sslConfig.getEnabledCipherSuites(), sslConfig.getClientAuth());
+ } else {
+ return Encryption.createTls(context, sslConfig.getEnabledCipherSuites(), sslConfig.getClientAuth());
+ }
+ }
+}
diff --git a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/SslConfig.java b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/SslConfig.java
new file mode 100644
index 0000000000..7f5121bedb
--- /dev/null
+++ b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/SslConfig.java
@@ -0,0 +1,145 @@
+/****************************************************************
+ * 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. *
+ ****************************************************************/
+
+package org.apache.james.protocols.lib;
+
+import org.apache.commons.configuration2.HierarchicalConfiguration;
+import org.apache.commons.configuration2.ex.ConfigurationException;
+import org.apache.commons.configuration2.tree.ImmutableNode;
+import org.apache.james.protocols.api.ClientAuth;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SslConfig {
+ private static final Logger LOGGER = LoggerFactory.getLogger(SslConfig.class);
+
+ public static SslConfig parse(HierarchicalConfiguration<ImmutableNode> config) throws ConfigurationException {
+ boolean useStartTLS = config.getBoolean("tls.[@startTLS]", false);
+ boolean useSSL = config.getBoolean("tls.[@socketTLS]", false);
+
+ ClientAuth clientAuth;
+ if (config.getProperty("tls.clientAuth") != null || config.getKeys("tls.clientAuth").hasNext()) {
+ clientAuth = ClientAuth.NEED;
+ } else {
+ clientAuth = ClientAuth.NONE;
+ }
+
+ if (useSSL && useStartTLS) {
+ throw new ConfigurationException("startTLS is only supported when using plain sockets");
+ }
+
+ if (useStartTLS || useSSL) {
+ String[] enabledCipherSuites = config.getStringArray("tls.supportedCipherSuites.cipherSuite");
+ String keystore = config.getString("tls.keystore", null);
+ String privateKey = config.getString("tls.privateKey", null);
+ String certificates = config.getString("tls.certificates", null);
+ String keystoreType = config.getString("tls.keystoreType", "JKS");
+ if (keystore == null && (privateKey == null || certificates == null)) {
+ throw new ConfigurationException("keystore or (privateKey and certificates) needs to get configured");
+ }
+ String secret = config.getString("tls.secret", null);
+
+ String truststore = config.getString("tls.clientAuth.truststore", null);
+ String truststoreType = config.getString("tls.clientAuth.truststoreType", "JKS");
+ char[] truststoreSecret = config.getString("tls.clientAuth.truststoreSecret", "").toCharArray();
+ LOGGER.info("TLS enabled with auth {} using truststore {}", clientAuth, truststore);
+
+ return new SslConfig(useStartTLS, useSSL, clientAuth, keystore, keystoreType, privateKey, certificates, secret, truststore, truststoreType, enabledCipherSuites, truststoreSecret);
+ } else {
+ return new SslConfig(useStartTLS, useSSL, clientAuth, null, null, null, null, null, null, null, null, null);
+ }
+ }
+
+ private final boolean useStartTLS;
+ private final boolean useSSL;
+ private final ClientAuth clientAuth;
+ private final String keystore;
+ private final String keystoreType;
+ private final String privateKey;
+ private final String certificates;
+ private final String secret;
+ private final String truststore;
+ private final String truststoreType;
+ private final String[] enabledCipherSuites;
+ private final char[] truststoreSecret;
+
+ public SslConfig(boolean useStartTLS, boolean useSSL, ClientAuth clientAuth, String keystore, String keystoreType, String privateKey,
+ String certificates, String secret, String truststore, String truststoreType, String[] enabledCipherSuites, char[] truststoreSecret) {
+ this.useStartTLS = useStartTLS;
+ this.useSSL = useSSL;
+ this.clientAuth = clientAuth;
+ this.keystore = keystore;
+ this.keystoreType = keystoreType;
+ this.privateKey = privateKey;
+ this.certificates = certificates;
+ this.secret = secret;
+ this.truststore = truststore;
+ this.truststoreType = truststoreType;
+ this.enabledCipherSuites = enabledCipherSuites;
+ this.truststoreSecret = truststoreSecret;
+ }
+
+ public ClientAuth getClientAuth() {
+ return clientAuth;
+ }
+
+ public boolean useStartTLS() {
+ return useStartTLS;
+ }
+
+ public String[] getEnabledCipherSuites() {
+ return enabledCipherSuites;
+ }
+
+ public boolean useSSL() {
+ return useSSL;
+ }
+
+ public String getKeystore() {
+ return keystore;
+ }
+
+ public String getKeystoreType() {
+ return keystoreType;
+ }
+
+ public String getPrivateKey() {
+ return privateKey;
+ }
+
+ public String getCertificates() {
+ return certificates;
+ }
+
+ public String getSecret() {
+ return secret;
+ }
+
+ public String getTruststore() {
+ return truststore;
+ }
+
+ public String getTruststoreType() {
+ return truststoreType;
+ }
+
+ public char[] getTruststoreSecret() {
+ return truststoreSecret;
+ }
+}
diff --git a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractConfigurableAsyncServer.java b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractConfigurableAsyncServer.java
index de8b5f2397..3935072f87 100644
--- a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractConfigurableAsyncServer.java
+++ b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractConfigurableAsyncServer.java
@@ -31,8 +31,6 @@ import javax.annotation.PreDestroy;
import javax.inject.Inject;
import javax.management.MBeanServer;
import javax.management.ObjectName;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.X509ExtendedKeyManager;
import org.apache.commons.configuration2.Configuration;
import org.apache.commons.configuration2.HierarchicalConfiguration;
@@ -41,7 +39,8 @@ import org.apache.commons.configuration2.tree.ImmutableNode;
import org.apache.commons.lang3.StringUtils;
import org.apache.james.filesystem.api.FileSystem;
import org.apache.james.lifecycle.api.Configurable;
-import org.apache.james.protocols.api.ClientAuth;
+import org.apache.james.protocols.lib.LegacyJavaEncryptionFactory;
+import org.apache.james.protocols.lib.SslConfig;
import org.apache.james.protocols.lib.jmx.ServerMBean;
import org.apache.james.protocols.netty.AbstractAsyncServer;
import org.apache.james.protocols.netty.AbstractChannelPipelineFactory;
@@ -57,8 +56,6 @@ import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelOption;
import io.netty.util.concurrent.DefaultEventExecutorGroup;
import io.netty.util.concurrent.EventExecutorGroup;
-import nl.altindag.ssl.SSLFactory;
-import nl.altindag.ssl.util.PemUtils;
/**
@@ -90,31 +87,13 @@ public abstract class AbstractConfigurableAsyncServer extends AbstractAsyncServe
protected int connPerIP;
- private boolean useStartTLS;
- private boolean useSSL;
-
- private ClientAuth clientAuth;
-
protected int connectionLimit;
private String helloName;
- private String keystore;
- private String keystoreType;
- private String privateKey;
- private String certificates;
-
- private String secret;
-
- private String truststore;
- private String truststoreType;
- private char[] truststoreSecret;
-
+ private SslConfig sslConfig;
protected Encryption encryption;
-
- private String[] enabledCipherSuites;
-
private ChannelHandlerFactory frameHandlerFactory;
private EventExecutorGroup executorGroup;
@@ -231,35 +210,7 @@ public abstract class AbstractConfigurableAsyncServer extends AbstractAsyncServe
}
}
- useStartTLS = config.getBoolean("tls.[@startTLS]", false);
- useSSL = config.getBoolean("tls.[@socketTLS]", false);
-
- if (config.getProperty("tls.clientAuth") != null || config.getKeys("tls.clientAuth").hasNext()) {
- clientAuth = ClientAuth.NEED;
- } else {
- clientAuth = ClientAuth.NONE;
- }
-
- if (useSSL && useStartTLS) {
- throw new ConfigurationException("startTLS is only supported when using plain sockets");
- }
-
- if (useStartTLS || useSSL) {
- enabledCipherSuites = config.getStringArray("tls.supportedCipherSuites.cipherSuite");
- keystore = config.getString("tls.keystore", null);
- privateKey = config.getString("tls.privateKey", null);
- certificates = config.getString("tls.certificates", null);
- keystoreType = config.getString("tls.keystoreType", "JKS");
- if (keystore == null && (privateKey == null || certificates == null)) {
- throw new ConfigurationException("keystore or (privateKey and certificates) needs to get configured");
- }
- secret = config.getString("tls.secret", null);
-
- truststore = config.getString("tls.clientAuth.truststore", null);
- truststoreType = config.getString("tls.clientAuth.truststoreType", "JKS");
- truststoreSecret = config.getString("tls.clientAuth.truststoreSecret", "").toCharArray();
- LOGGER.info("TLS enabled with auth {} using truststore {}", clientAuth, truststore);
- }
+ sslConfig = SslConfig.parse(config);
Optional.ofNullable(config.getBoolean("gracefulShutdown", null)).ifPresent(this::setGracefulShutdown);
@@ -301,10 +252,6 @@ public abstract class AbstractConfigurableAsyncServer extends AbstractAsyncServe
return port;
}
- public boolean useSSL() {
- return useSSL;
- }
-
@PreDestroy
public final void destroy() {
@@ -398,43 +345,9 @@ public abstract class AbstractConfigurableAsyncServer extends AbstractAsyncServe
* @throws Exception
*/
protected void buildSSLContext() throws Exception {
- if (useStartTLS || useSSL) {
- SSLFactory.Builder sslFactoryBuilder = SSLFactory.builder()
- .withSslContextAlgorithm("TLS");
- if (keystore != null) {
- char[] passwordAsCharArray = Optional.ofNullable(secret)
- .orElse("")
- .toCharArray();
- sslFactoryBuilder.withIdentityMaterial(
- fileSystem.getFile(keystore).toPath(),
- passwordAsCharArray,
- passwordAsCharArray,
- keystoreType);
- } else {
- X509ExtendedKeyManager keyManager = PemUtils.loadIdentityMaterial(
- fileSystem.getResource(certificates),
- fileSystem.getResource(privateKey),
- Optional.ofNullable(secret)
- .map(String::toCharArray)
- .orElse(null));
-
- sslFactoryBuilder.withIdentityMaterial(keyManager);
- }
-
- if (clientAuth != null && truststore != null) {
- sslFactoryBuilder.withTrustMaterial(
- fileSystem.getFile(truststore).toPath(),
- truststoreSecret,
- truststoreType);
- }
-
- SSLContext context = sslFactoryBuilder.build().getSslContext();
-
- if (useStartTLS) {
- encryption = Encryption.createStartTls(context, enabledCipherSuites, clientAuth);
- } else {
- encryption = Encryption.createTls(context, enabledCipherSuites, clientAuth);
- }
+ if (sslConfig.useSSL() || sslConfig.useStartTLS()) {
+ encryption = new LegacyJavaEncryptionFactory(fileSystem, sslConfig)
+ .create();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[james-project] 05/08: JAMES-3738 Encryption should be an interface with a legacy implementation
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit c136fbc040cf78b92bdecd54879bb0cc694c68c7
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Wed Mar 23 10:29:20 2022 +0700
JAMES-3738 Encryption should be an interface with a legacy implementation
---
.../apache/james/protocols/netty/Encryption.java | 161 ++++++++++++---------
1 file changed, 96 insertions(+), 65 deletions(-)
diff --git a/protocols/netty/src/main/java/org/apache/james/protocols/netty/Encryption.java b/protocols/netty/src/main/java/org/apache/james/protocols/netty/Encryption.java
index c56742a991..89dbda0d96 100644
--- a/protocols/netty/src/main/java/org/apache/james/protocols/netty/Encryption.java
+++ b/protocols/netty/src/main/java/org/apache/james/protocols/netty/Encryption.java
@@ -30,9 +30,9 @@ import io.netty.handler.ssl.SslHandler;
/**
* This class should be used to setup encrypted protocol handling
*/
-public final class Encryption {
+public interface Encryption {
- public static Encryption createTls(SSLContext context) {
+ static Encryption createTls(SSLContext context) {
return createTls(context, null, ClientAuth.NONE);
}
@@ -45,11 +45,11 @@ public final class Encryption {
* @param clientAuth
* specifies certificate based client authentication mode
*/
- public static Encryption createTls(SSLContext context, String[] enabledCipherSuites, ClientAuth clientAuth) {
- return new Encryption(context, false, enabledCipherSuites, clientAuth);
+ static Encryption createTls(SSLContext context, String[] enabledCipherSuites, ClientAuth clientAuth) {
+ return new Encryption.LegacyJavaEncryption(context, false, enabledCipherSuites, clientAuth);
}
- public static Encryption createStartTls(SSLContext context) {
+ static Encryption createStartTls(SSLContext context) {
return createStartTls(context, null, ClientAuth.NONE);
}
@@ -62,91 +62,122 @@ public final class Encryption {
* @param clientAuth
* specifies certificate based client authentication mode
*/
- public static Encryption createStartTls(SSLContext context, String[] enabledCipherSuites, ClientAuth clientAuth) {
- return new Encryption(context, true, enabledCipherSuites, clientAuth);
- }
-
- private final SSLContext context;
- private final boolean starttls;
- private final String[] enabledCipherSuites;
- private final ClientAuth clientAuth;
-
- private Encryption(SSLContext context, boolean starttls, String[] enabledCipherSuites, ClientAuth clientAuth) {
- this.context = context;
- this.starttls = starttls;
- this.enabledCipherSuites = enabledCipherSuites;
- this.clientAuth = clientAuth;
- }
-
- /**
- * Return the {@link SSLContext} to use
- *
- * @return context
- */
- public SSLContext getContext() {
- return context;
+ static Encryption createStartTls(SSLContext context, String[] enabledCipherSuites, ClientAuth clientAuth) {
+ return new Encryption.LegacyJavaEncryption(context, true, enabledCipherSuites, clientAuth);
}
/**
* Return <code>true</code> if this {@link Encryption} should be used for
* STARTTLS
- *
+ *
* @return starttls
*/
- public boolean isStartTLS() {
- return starttls;
- }
+ boolean isStartTLS();
- public boolean supportsEncryption() {
- return context != null;
- }
+ boolean supportsEncryption();
/**
* Return the Ciphersuites that are allowed for the {@link Encryption} or
* <code>null</code> if all should be allowed
- *
+ *
* @return ciphersuites
*/
- public String[] getEnabledCipherSuites() {
- return enabledCipherSuites;
- }
+ String[] getEnabledCipherSuites();
/**
* Return the client authentication mode for the {@link Encryption}
+ *
* @return authentication mode
*/
- public ClientAuth getClientAuth() {
- return clientAuth;
- }
+ ClientAuth getClientAuth();
- /**
- * Create a new {@link SSLEngine} configured according to this class.
- * @return sslengine
- */
- private SSLEngine createSSLEngine() {
- SSLEngine engine = context.createSSLEngine();
+ SslHandler sslHandler();
- // We need to copy the String array because of possible security issues.
- // See https://issues.apache.org/jira/browse/PROTOCOLS-18
- String[] cipherSuites = ArrayUtils.clone(enabledCipherSuites);
+ class LegacyJavaEncryption implements Encryption {
+ private final SSLContext context;
+ private final boolean starttls;
+ private final String[] enabledCipherSuites;
+ private final ClientAuth clientAuth;
- if (cipherSuites != null && cipherSuites.length > 0) {
- engine.setEnabledCipherSuites(cipherSuites);
+ private LegacyJavaEncryption(SSLContext context, boolean starttls, String[] enabledCipherSuites, ClientAuth clientAuth) {
+ this.context = context;
+ this.starttls = starttls;
+ this.enabledCipherSuites = enabledCipherSuites;
+ this.clientAuth = clientAuth;
}
- if (ClientAuth.NEED.equals(clientAuth)) {
- engine.setNeedClientAuth(true);
+
+ /**
+ * Return the {@link SSLContext} to use
+ *
+ * @return context
+ */
+ public SSLContext getContext() {
+ return context;
}
- if (ClientAuth.WANT.equals(clientAuth)) {
- engine.setWantClientAuth(true);
+
+ /**
+ * Return <code>true</code> if this {@link Encryption} should be used for
+ * STARTTLS
+ *
+ * @return starttls
+ */
+ public boolean isStartTLS() {
+ return starttls;
+ }
+
+ public boolean supportsEncryption() {
+ return context != null;
}
- return engine;
- }
- public SslHandler sslHandler() {
- SSLEngine engine = createSSLEngine();
- // We need to set clientMode to false.
- // See https://issues.apache.org/jira/browse/JAMES-1025
- engine.setUseClientMode(false);
- return new SslHandler(engine);
+ /**
+ * Return the Ciphersuites that are allowed for the {@link Encryption} or
+ * <code>null</code> if all should be allowed
+ *
+ * @return ciphersuites
+ */
+ public String[] getEnabledCipherSuites() {
+ return enabledCipherSuites;
+ }
+
+ /**
+ * Return the client authentication mode for the {@link Encryption}
+ *
+ * @return authentication mode
+ */
+ public ClientAuth getClientAuth() {
+ return clientAuth;
+ }
+
+ /**
+ * Create a new {@link SSLEngine} configured according to this class.
+ *
+ * @return sslengine
+ */
+ private SSLEngine createSSLEngine() {
+ SSLEngine engine = context.createSSLEngine();
+
+ // We need to copy the String array because of possible security issues.
+ // See https://issues.apache.org/jira/browse/PROTOCOLS-18
+ String[] cipherSuites = ArrayUtils.clone(enabledCipherSuites);
+
+ if (cipherSuites != null && cipherSuites.length > 0) {
+ engine.setEnabledCipherSuites(cipherSuites);
+ }
+ if (ClientAuth.NEED.equals(clientAuth)) {
+ engine.setNeedClientAuth(true);
+ }
+ if (ClientAuth.WANT.equals(clientAuth)) {
+ engine.setWantClientAuth(true);
+ }
+ return engine;
+ }
+
+ public SslHandler sslHandler() {
+ SSLEngine engine = createSSLEngine();
+ // We need to set clientMode to false.
+ // See https://issues.apache.org/jira/browse/JAMES-1025
+ engine.setUseClientMode(false);
+ return new SslHandler(engine);
+ }
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org