You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by rc...@apache.org on 2024/02/15 07:50:50 UTC

(james-project) branch master updated: JAMES-3775 Pass SSL information to RspamD scanner mailet

This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git


The following commit(s) were added to refs/heads/master by this push:
     new 2c5c9b771d JAMES-3775 Pass SSL information to RspamD scanner mailet
2c5c9b771d is described below

commit 2c5c9b771dc0f477f6178be787197df221edbedb
Author: Benoit TELLIER <bt...@linagora.com>
AuthorDate: Tue Feb 13 10:51:58 2024 +0100

    JAMES-3775 Pass SSL information to RspamD scanner mailet
---
 mailet/api/src/main/java/org/apache/mailet/Mail.java         |  2 ++
 .../james/smtpserver/AddDefaultAttributesMessageHook.java    |  5 +++++
 .../org/apache/james/rspamd/client/RspamdHttpClient.java     | 12 ++++++++++++
 3 files changed, 19 insertions(+)

diff --git a/mailet/api/src/main/java/org/apache/mailet/Mail.java b/mailet/api/src/main/java/org/apache/mailet/Mail.java
index 2b1ce09472..93527b8110 100644
--- a/mailet/api/src/main/java/org/apache/mailet/Mail.java
+++ b/mailet/api/src/main/java/org/apache/mailet/Mail.java
@@ -103,6 +103,8 @@ public interface Mail extends Serializable, Cloneable {
 
     AttributeName SMTP_AUTH_USER = AttributeName.of("org.apache.james.SMTPAuthUser");
     AttributeName SMTP_HELO = AttributeName.of("org.apache.james.HELO");
+    AttributeName SSL_PROTOCOL = AttributeName.of("org.apache.james.ssl.protocol");
+    AttributeName SSL_CIPHER = AttributeName.of("org.apache.james.ssl.cipher");
     AttributeName SMTP_SESSION_ID = AttributeName.of("org.apache.james.SMTPSessionID");
     AttributeName MAILET_ERROR = AttributeName.of("org.apache.james.MailetError");
     Attribute SENT_BY_MAILET_ATTRIBUTE = Attribute.convertToAttribute("org.apache.james.SentByMailet", true);
diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/AddDefaultAttributesMessageHook.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/AddDefaultAttributesMessageHook.java
index 5b31c518d2..760aea4cdc 100644
--- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/AddDefaultAttributesMessageHook.java
+++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/AddDefaultAttributesMessageHook.java
@@ -49,6 +49,11 @@ public class AddDefaultAttributesMessageHook implements JamesMessageHook {
             session.getAttachment(SMTPSession.CURRENT_HELO_NAME, ProtocolSession.State.Connection)
                 .ifPresent(helo ->  mail.setAttribute(new Attribute(Mail.SMTP_HELO, AttributeValue.of(helo))));
 
+            session.getSSLSession().ifPresent(sslSession -> {
+                mail.setAttribute(new Attribute(Mail.SSL_PROTOCOL, AttributeValue.of(sslSession.getProtocol())));
+                mail.setAttribute(new Attribute(Mail.SSL_CIPHER, AttributeValue.of(sslSession.getCipherSuite())));
+            });
+
             if (session.getUsername() != null) {
                 mail.setAttribute(new Attribute(Mail.SMTP_AUTH_USER, AttributeValue.of(session.getUsername().asString())));
             }
diff --git a/third-party/rspamd/src/main/java/org/apache/james/rspamd/client/RspamdHttpClient.java b/third-party/rspamd/src/main/java/org/apache/james/rspamd/client/RspamdHttpClient.java
index 5a256e9e68..1b78aa8225 100644
--- a/third-party/rspamd/src/main/java/org/apache/james/rspamd/client/RspamdHttpClient.java
+++ b/third-party/rspamd/src/main/java/org/apache/james/rspamd/client/RspamdHttpClient.java
@@ -184,6 +184,18 @@ public class RspamdHttpClient {
             .filter(String.class::isInstance)
             .map(String.class::cast)
             .ifPresent(user -> headers.add("User", user));
+
+        // SSL details
+        mail.getAttribute(Mail.SSL_PROTOCOL)
+            .map(attr -> attr.getValue().value())
+            .filter(String.class::isInstance)
+            .map(String.class::cast)
+            .ifPresent(tlsVersion -> headers.add("TLS-Version", tlsVersion));
+        mail.getAttribute(Mail.SSL_CIPHER)
+            .map(attr -> attr.getValue().value())
+            .filter(String.class::isInstance)
+            .map(String.class::cast)
+            .ifPresent(cipher -> headers.add("TLS-Cipher", cipher));
     }
 
     private HttpClient buildReactorNettyHttpClient(RspamdClientConfiguration configuration) {


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org