jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From am...@apache.org
Subject svn commit: r1785225 - in /jackrabbit/trunk: jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/ jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/ jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/db/
Date Fri, 03 Mar 2017 08:09:00 GMT
Author: amitj
Date: Fri Mar  3 08:09:00 2017
New Revision: 1785225

URL: http://svn.apache.org/viewvc?rev=1785225&view=rev
Log:
JCR-4115: Don't use SHA-1 for new DataStore binaries (Jackrabbit)

- Using SHA-256 instead of SHA-1 to create blob record ids

Modified:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/DataStoreTest.java
    jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/AbstractDataStore.java
    jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/CachingDataStore.java
    jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java
    jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/DataStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/DataStoreTest.java?rev=1785225&r1=1785224&r2=1785225&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/DataStoreTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/DataStoreTest.java
Fri Mar  3 08:09:00 2017
@@ -26,6 +26,9 @@ import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.ByteBuffer;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
 import java.sql.DriverManager;
 import java.sql.SQLException;
 import java.util.ArrayList;
@@ -103,14 +106,35 @@ public class DataStoreTest extends JUnit
         }
     }
 
+    public static void main(String... args) throws NoSuchAlgorithmException {
+        // create and print a "directory-collision", that is, two byte arrays
+        // where the hash starts with the same bytes
+        // those values can be used for testDeleteRecordWithParentCollision
+        HashMap<Long, Long> map = new HashMap<Long, Long>();
+        MessageDigest digest = MessageDigest.getInstance("SHA-256");
+        ByteBuffer input = ByteBuffer.allocate(8);
+        byte[] array = input.array();
+        for(long x = 0;; x++) {
+            input.putLong(x).flip();
+            long h = ByteBuffer.wrap(digest.digest(array)).getLong();
+            Long old = map.put(h & 0xffffffffff000000L, x);
+            if (old != null) {
+                System.out.println(Long.toHexString(old) + " " + Long.toHexString(x));
+                break;
+            }
+        }
+    }
+
     public void testDeleteRecordWithParentCollision() throws Exception {
         FileDataStore fds = new FileDataStore();
         fds.init(testDir + "/fileDeleteCollision");
 
-        String c1 = "06b2f82fd81b2c20";
-        String c2 = "02c60cb75083ceef";
-        DataRecord d1 = fds.addRecord(IOUtils.toInputStream(c1));
-        DataRecord d2 = fds.addRecord(IOUtils.toInputStream(c2));
+        ByteArrayInputStream c1 = new ByteArrayInputStream(ByteBuffer
+                .allocate(8).putLong(0x181c7).array());
+        ByteArrayInputStream c2 = new ByteArrayInputStream(ByteBuffer
+                .allocate(8).putLong(0x11fd78).array());
+        DataRecord d1 = fds.addRecord(c1);
+        DataRecord d2 = fds.addRecord(c2);
         fds.deleteRecord(d1.getIdentifier());
         DataRecord testRecord = fds.getRecordIfStored(d2.getIdentifier());
 

Modified: jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/AbstractDataStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/AbstractDataStore.java?rev=1785225&r1=1785224&r2=1785225&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/AbstractDataStore.java
(original)
+++ jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/AbstractDataStore.java
Fri Mar  3 08:09:00 2017
@@ -37,6 +37,11 @@ public abstract class AbstractDataStore
     private static final char[] HEX = "0123456789abcdef".toCharArray();
 
     /**
+     * The digest algorithm used to uniquely identify records.
+     */
+    protected String DIGEST = System.getProperty("ds.digest.algorithm", "SHA-256");
+
+    /**
      * Cached copy of the reference key of this data store. Initialized in
      * {@link #getReferenceKey()} when the key is first accessed.
      */
@@ -138,4 +143,4 @@ public abstract class AbstractDataStore
         return referenceKey;
     }
 
-}
\ No newline at end of file
+}

Modified: jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/CachingDataStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/CachingDataStore.java?rev=1785225&r1=1785224&r2=1785225&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/CachingDataStore.java
(original)
+++ jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/CachingDataStore.java
Fri Mar  3 08:09:00 2017
@@ -90,11 +90,6 @@ public abstract class CachingDataStore e
      */
     private static final Logger LOG = LoggerFactory.getLogger(CachingDataStore.class);
 
-    /**
-     * The digest algorithm used to uniquely identify records.
-     */
-    private static final String DIGEST = "SHA-1";
-
     private static final String DS_STORE = ".DS_Store";
 
     /**
@@ -389,9 +384,9 @@ public abstract class CachingDataStore e
 
     /**
      * Creates a new data record in {@link Backend}. The stream is first
-     * consumed and the contents are saved in a temporary file and the SHA-1
+     * consumed and the contents are saved in a temporary file and the {@link #DIGEST}
      * message digest of the stream is calculated. If a record with the same
-     * SHA-1 digest (and length) is found then it is returned. Otherwise new
+     * {@link #DIGEST} digest (and length) is found then it is returned. Otherwise new
      * record is created in {@link Backend} and the temporary file is moved in
      * place to {@link LocalCache}.
      * 
@@ -423,7 +418,7 @@ public abstract class CachingDataStore e
             long currTime = System.currentTimeMillis();
             DataIdentifier identifier = new DataIdentifier(
                 encodeHexString(digest.digest()));
-            LOG.debug("SHA1 of [{}], length =[{}] took [{}]ms ",
+            LOG.debug("Digest of [{}], length =[{}] took [{}]ms ",
                 new Object[] { identifier, length, (currTime - startTime) });
             String fileName = getFileName(identifier);
             AsyncUploadCacheResult result = null;

Modified: jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java?rev=1785225&r1=1785224&r2=1785225&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java
(original)
+++ jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java
Fri Mar  3 08:09:00 2017
@@ -69,11 +69,6 @@ public class FileDataStore extends Abstr
     private static Logger log = LoggerFactory.getLogger(FileDataStore.class);
 
     /**
-     * The digest algorithm used to uniquely identify records.
-     */
-    private static final String DIGEST = "SHA-1";
-
-    /**
      * The default value for the minimum object size.
      */
     private static final int DEFAULT_MIN_RECORD_LENGTH = 100;
@@ -163,8 +158,8 @@ public class FileDataStore extends Abstr
     /**
      * Creates a new data record.
      * The stream is first consumed and the contents are saved in a temporary file
-     * and the SHA-1 message digest of the stream is calculated. If a
-     * record with the same SHA-1 digest (and length) is found then it is
+     * and the {@link #DIGEST} message digest of the stream is calculated. If a
+     * record with the same {@link #DIGEST} digest (and length) is found then it is
      * returned. Otherwise the temporary file is moved in place to become
      * the new data record that gets returned.
      *

Modified: jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java?rev=1785225&r1=1785224&r2=1785225&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java
(original)
+++ jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java
Fri Mar  3 08:09:00 2017
@@ -126,11 +126,6 @@ public class DbDataStore extends Abstrac
     public static final String STORE_SIZE_MAX = "max";
 
     /**
-     * The digest algorithm used to uniquely identify records.
-     */
-    protected static final String DIGEST = "SHA-1";
-
-    /**
      * The prefix used for temporary objects.
      */
     protected static final String TEMP_PREFIX = "TEMP_";



Mime
View raw message