You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ad...@apache.org on 2017/11/08 10:42:54 UTC

[4/4] james-project git commit: JAMES-2201 Switch to SHA-256 for attachments indexing

JAMES-2201 Switch to SHA-256 for attachments indexing

This is in reaction to rising threats of SHA-1 collisions (see SHAttered
from Google).


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/fc992394
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/fc992394
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/fc992394

Branch: refs/heads/master
Commit: fc992394942e191c158c379dee88d580481b0612
Parents: 0e99fb1
Author: Thibaut SAUTEREAU <ts...@linagora.com>
Authored: Mon Oct 23 10:09:15 2017 +0700
Committer: Thibaut SAUTEREAU <ts...@linagora.com>
Committed: Wed Nov 8 17:26:58 2017 +0700

----------------------------------------------------------------------
 .../java/org/apache/james/mailbox/model/AttachmentId.java    | 4 ++--
 .../org/apache/james/mailbox/model/AttachmentIdTest.java     | 8 ++++----
 2 files changed, 6 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/fc992394/mailbox/api/src/main/java/org/apache/james/mailbox/model/AttachmentId.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/AttachmentId.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/AttachmentId.java
index 81a5588..38aee93 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/AttachmentId.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/AttachmentId.java
@@ -47,10 +47,10 @@ public class AttachmentId {
     }
 
     private static String computeRawId(final byte[] payload, final String contentType) {
-        return DigestUtils.sha1Hex(
+        return DigestUtils.sha256Hex(
             Bytes.concat(
                 asMimeType(contentType).getBytes(StandardCharsets.UTF_8),
-                DigestUtils.sha1Hex(payload).getBytes(StandardCharsets.UTF_8)));
+                DigestUtils.sha256Hex(payload).getBytes(StandardCharsets.UTF_8)));
     }
 
     @VisibleForTesting static String asMimeType(String contentType) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/fc992394/mailbox/api/src/test/java/org/apache/james/mailbox/model/AttachmentIdTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/AttachmentIdTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/AttachmentIdTest.java
index 148149e..3e462b6 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/AttachmentIdTest.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/AttachmentIdTest.java
@@ -29,21 +29,21 @@ import org.junit.Test;
 public class AttachmentIdTest {
 
     @Test
-    public void forPayloadAndTypeShouldCalculateTheUnderlyingSha1() {
+    public void forPayloadAndTypeShouldCalculateTheUnderlyingSha256() {
         AttachmentId attachmentId = AttachmentId.forPayloadAndType("payload".getBytes(), "text/plain");
-        String expectedId = "826b0786f04e07525a36be70f84c647af7b73059";
+        String expectedId = "d3a2642ee092a1b32c0a83cf94fc2499f7495b7b91b1bd434302a0a4c2aa4278";
         assertThat(attachmentId.getId()).isEqualTo(expectedId);
     }
 
     @Test
-    public void forPayloadAndTypeShouldCalculateDifferentSha1WhenContentTypeIsDifferent() {
+    public void forPayloadAndTypeShouldCalculateDifferentSha256WhenContentTypeIsDifferent() {
         AttachmentId attachmentId = AttachmentId.forPayloadAndType("payload".getBytes(), "text/plain");
         AttachmentId attachmentId2 = AttachmentId.forPayloadAndType("payload".getBytes(), "text/html");
         assertThat(attachmentId.getId()).isNotEqualTo(attachmentId2.getId());
     }
 
     @Test
-    public void forPayloadAndTypeShouldCalculateSameSha1WhenMimeTypeIsSameButNotParameters() {
+    public void forPayloadAndTypeShouldCalculateSameSha256WhenMimeTypeIsSameButNotParameters() {
         AttachmentId attachmentId = AttachmentId.forPayloadAndType("payload".getBytes(), "text/html; charset=UTF-8");
         AttachmentId attachmentId2 = AttachmentId.forPayloadAndType("payload".getBytes(), "text/html; charset=UTF-16");
         assertThat(attachmentId.getId()).isEqualTo(attachmentId2.getId());


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