jeantil commented on a change in pull request #342:
URL: https://github.com/apache/james-project/pull/342#discussion_r602138875



##########
File path: 
protocols/imap/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java
##########
@@ -372,7 +372,7 @@ public String consumeLiteral(Charset charset) throws 
DecodingException {
             return consumeLiteral(US_ASCII);
         } else {
             try {
-                ImmutablePair<Integer, Literal> literal = 
consumeLiteral(false);
+                ImmutablePair<Integer, Literal> literal = consumeLiteral(true);

Review comment:
       I'm not sure how this change relates to the rest ... 

##########
File path: 
server/blob/blob-aes/src/main/java/org/apache/james/blob/aes/AESBlobStoreDAO.java
##########
@@ -0,0 +1,155 @@
+/****************************************************************
+ * 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.blob.aes;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.GeneralSecurityException;
+import java.security.NoSuchAlgorithmException;
+import java.security.spec.InvalidKeySpecException;
+
+import javax.crypto.SecretKey;
+import javax.crypto.SecretKeyFactory;
+import javax.crypto.spec.PBEKeySpec;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.james.blob.api.BlobId;
+import org.apache.james.blob.api.BlobStoreDAO;
+import org.apache.james.blob.api.BucketName;
+import org.apache.james.blob.api.ObjectNotFoundException;
+import org.apache.james.blob.api.ObjectStoreIOException;
+import org.reactivestreams.Publisher;
+
+import com.github.fge.lambdas.Throwing;
+import com.google.common.base.Preconditions;
+import com.google.common.io.ByteSource;
+import com.google.crypto.tink.Aead;
+import com.google.crypto.tink.aead.AeadConfig;
+import com.google.crypto.tink.subtle.AesGcmJce;
+
+import reactor.core.publisher.Mono;
+import reactor.core.scheduler.Schedulers;
+
+public class AESBlobStoreDAO implements BlobStoreDAO {
+    private static final byte[] EMPTY_ASSOCIATED_DATA = new byte[0];
+    private static final int PBKDF2_ITERATIONS = 65536;
+    private static final int KEY_SIZE = 256;
+    private static final String SECRET_KEY_FACTORY_ALGORITHM = 
"PBKDF2WithHmacSHA256";
+
+    private final BlobStoreDAO underlying;
+    private final Aead aead;
+
+    public AESBlobStoreDAO(BlobStoreDAO underlying, CryptoConfig cryptoConfig) 
{
+        this.underlying = underlying;
+
+        try {
+            AeadConfig.register();
+
+            SecretKey secretKey = deriveKey(cryptoConfig);
+            aead = new AesGcmJce(secretKey.getEncoded());
+        } catch (GeneralSecurityException e) {
+            throw new RuntimeException("Error while starting AESPayloadCodec", 
e);
+        }
+    }
+
+    private static SecretKey deriveKey(CryptoConfig cryptoConfig) throws 
NoSuchAlgorithmException, InvalidKeySpecException {
+        byte[] saltBytes = cryptoConfig.salt();
+        SecretKeyFactory skf = 
SecretKeyFactory.getInstance(SECRET_KEY_FACTORY_ALGORITHM);
+        PBEKeySpec spec = new PBEKeySpec(cryptoConfig.password(), saltBytes, 
PBKDF2_ITERATIONS, KEY_SIZE);
+        return skf.generateSecret(spec);
+    }
+
+    public byte[] encrypt(byte[] input) {
+        try {
+            return aead.encrypt(input, EMPTY_ASSOCIATED_DATA);
+        } catch (GeneralSecurityException e) {
+            throw new RuntimeException("Unable to build payload for object 
storage, failed to encrypt", e);
+        }
+    }
+
+    public byte[] decrypt(byte[] ciphertext) throws IOException {

Review comment:
       This PR sure brings back memories :D 
   
   Sadly this implementation still loads the whole blob data in memory ... The 
corresponding stream based API had issues because of the way Tink is 
implemented and the bug is still open to this day 
https://github.com/google/tink/issues/128

##########
File path: docs/modules/servers/pages/distributed/configure/blobstore.adoc
##########
@@ -35,6 +35,22 @@ Consequently, all the requested deletions will not be 
performed, meaning that bl
 
 NOTE: If you are upgrading from James 3.5 or older, the deduplication was 
enabled.
 
+=== Encryption choice
+
+Data can be optionally encrypted with a symmetric key using AES before being 
stored in the blobStore. As many user relies
+on third party for object storage, a compromised third party will not escalate 
to a data disclosure. Of course, a
+performance price have to be paid, as encryption takes resources.
+
+*encryption.aes.enable* : Optional boolean, defaults to false.
+
+If AES encryption is enabled, then the following properties MUST be present:
+
+ - *encryption.aes.password* : String

Review comment:
       it would be nice to provide sample commands to generate proper values 
for these 
   something like: 
   - generate password with : openssl rand -base64 64 
   - generate salt with : openssl rand -hex 16 
   
   note that I haven't checked if the provided sizes are actually sound or not 
...




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to