[ 
https://issues.apache.org/jira/browse/QPID-8504?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17284100#comment-17284100
 ] 

ASF GitHub Bot commented on QPID-8504:
--------------------------------------

Dedeepya-T commented on a change in pull request #81:
URL: https://github.com/apache/qpid-broker-j/pull/81#discussion_r575632440



##########
File path: 
broker-core/src/main/java/org/apache/qpid/server/security/encryption/AESGCMKeyFileEncrypterFactory.java
##########
@@ -0,0 +1,383 @@
+/*
+ * 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.qpid.server.security.encryption;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.attribute.AclEntry;
+import java.nio.file.attribute.AclEntryPermission;
+import java.nio.file.attribute.AclEntryType;
+import java.nio.file.attribute.AclFileAttributeView;
+import java.nio.file.attribute.FileAttribute;
+import java.nio.file.attribute.PosixFileAttributeView;
+import java.nio.file.attribute.PosixFilePermission;
+import java.nio.file.attribute.PosixFilePermissions;
+import java.nio.file.attribute.UserPrincipal;
+import java.security.NoSuchAlgorithmException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+import java.util.Set;
+
+import javax.crypto.Cipher;
+import javax.crypto.KeyGenerator;
+import javax.crypto.SecretKey;
+import javax.crypto.spec.SecretKeySpec;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.SystemConfig;
+import org.apache.qpid.server.plugin.ConditionallyAvailable;
+import org.apache.qpid.server.plugin.ConfigurationSecretEncrypterFactory;
+import org.apache.qpid.server.plugin.PluggableService;
+
+@PluggableService
+public class AESGCMKeyFileEncrypterFactory implements 
ConfigurationSecretEncrypterFactory, ConditionallyAvailable
+{
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(AESGCMKeyFileEncrypterFactory.class);
+
+    static final String ENCRYPTER_KEY_FILE = "encrypter.key.file";
+
+    private static final int AES_KEY_SIZE_BITS = 256;
+    private static final int AES_KEY_SIZE_BYTES = AES_KEY_SIZE_BITS / 8;
+    private static final String AES_ALGORITHM = "AES";
+
+    public static final String TYPE = "AESGCMKeyFile";
+
+    static final String DEFAULT_KEYS_SUBDIR_NAME = ".keys";
+
+    private static final boolean IS_AVAILABLE;
+
+    private static final String ILLEGAL_ARG_EXCEPTION = "Unable to determine a 
mechanism to protect access to the key file on this filesystem";
+
+    static
+    {
+        boolean isAvailable;
+        try
+        {
+            final int allowedKeyLength = 
Cipher.getMaxAllowedKeyLength(AES_ALGORITHM);
+            isAvailable = allowedKeyLength >=AES_KEY_SIZE_BITS;
+            if(!isAvailable)
+            {
+                LOGGER.warn("The {} configuration encryption encryption 
mechanism is not available. "
+                            + "Maximum available AES key length is {} but {} 
is required. "
+                            + "Ensure the full strength JCE policy has been 
installed into your JVM.", TYPE, allowedKeyLength, AES_KEY_SIZE_BITS);
+            }
+        }
+        catch (NoSuchAlgorithmException e)
+        {
+            isAvailable = false;
+
+            LOGGER.error("The " + TYPE + " configuration encryption encryption 
mechanism is not available. "
+                        + "The " + AES_ALGORITHM + " algorithm is not 
available within the JVM (despite it being a requirement).");
+        }
+
+        IS_AVAILABLE = isAvailable;
+    }
+
+    @Override
+    public ConfigurationSecretEncrypter createEncrypter(final 
ConfiguredObject<?> object)

Review comment:
       Created a Abstract factory to have the common code




----------------------------------------------------------------
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]


> Usage of default mode for "AES" is insecure
> -------------------------------------------
>
>                 Key: QPID-8504
>                 URL: https://issues.apache.org/jira/browse/QPID-8504
>             Project: Qpid
>          Issue Type: Improvement
>            Reporter: Md Mahir Asef Kabir
>            Priority: Major
>
> In file 
> https://github.com/apache/qpid-broker-j/blob/a70ed6f5edbcf0e8690447d48a1fe64e599cb703/broker-core/src/main/java/org/apache/qpid/server/security/encryption/AESKeyFileEncrypter.java
>  (at Line 55), the default "AES" algorithm has been used which imposes 
> insecure "ECB" mode.
> *Security Impact*:
> ECB mode allows the attacker to do the following -
> detect whether two ECB-encrypted messages are identical;
> detect whether two ECB-encrypted messages share a common prefix;
> detect whether two ECB-encrypted messages share other common substrings, as 
> long as those substrings are aligned at block boundaries; or
> detect whether (and where) a single ECB-encrypted message contains repetitive 
> data (such as long runs of spaces or null bytes, repeated header fields, or 
> coincidentally repeated phrases in the text). - Collected from 
> [here|https://crypto.stackexchange.com/questions/20941/why-shouldnt-i-use-ecb-encryption#:~:text=The%20main%20reason%20not%20to,will%20leak%20to%20some%20extent).]
> *Useful Resources*:
> https://blog.filippo.io/the-ecb-penguin/
> *Solution we suggest*:
> Use GCM mode instead of default or ECB mode.
> *Please share with us your opinions/comments if there is any*:
> Is the bug report helpful?



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

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

Reply via email to