[
https://issues.apache.org/jira/browse/QPID-8504?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17284101#comment-17284101
]
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_r575632613
##########
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)
+ {
+ String fileLocation;
+ if(object.getContextKeys(false).contains(ENCRYPTER_KEY_FILE))
+ {
+ fileLocation = object.getContextValue(String.class,
ENCRYPTER_KEY_FILE);
+ }
+ else
+ {
+
+ fileLocation = object.getContextValue(String.class,
SystemConfig.QPID_WORK_DIR)
+ + File.separator + DEFAULT_KEYS_SUBDIR_NAME +
File.separator
+ + object.getCategoryClass().getSimpleName() + "_"
+ + object.getName() + ".key";
+
+ Map<String, String> context = object.getContext();
+ Map<String, String> modifiedContext = new LinkedHashMap<>(context);
+ modifiedContext.put(ENCRYPTER_KEY_FILE, fileLocation);
+
+ object.setAttributes(Collections.<String,
Object>singletonMap(ConfiguredObject.CONTEXT, modifiedContext));
+ }
+ File file = new File(fileLocation);
+ if(!file.exists())
+ {
+ LOGGER.warn("Configuration encryption is enabled, but no
configuration secret was found. A new configuration secret will be created at
'{}'.", fileLocation);
+ createAndPopulateKeyFile(file);
+ }
+ if(!file.isFile())
+ {
+ throw new IllegalArgumentException("File '"+fileLocation+"' is not
a regular file.");
+ }
+ try
+ {
+ checkFilePermissions(fileLocation, file);
+ if(Files.size(file.toPath()) != AES_KEY_SIZE_BYTES)
+ {
+ throw new IllegalArgumentException("Key file '" + fileLocation
+ "' contains an incorrect about of data");
+ }
+
+ try(FileInputStream inputStream = new FileInputStream(file))
+ {
+ byte[] key = new byte[AES_KEY_SIZE_BYTES];
+ int pos = 0;
+ int read;
+ while(pos < key.length && -1 != ( read = inputStream.read(key,
pos, key.length - pos)))
+ {
+ pos += read;
+ }
+ if(pos != key.length)
+ {
+ throw new IllegalConfigurationException("Key file '" +
fileLocation + "' contained an incorrect about of data");
+ }
+ SecretKeySpec keySpec = new SecretKeySpec(key, AES_ALGORITHM);
+ return new AESKeyFileEncrypter(keySpec);
+ }
+ }
+ catch (IOException e)
+ {
+ throw new IllegalConfigurationException("Unable to get file
permissions: " + e.getMessage(), e);
+ }
+ }
+
+ private void checkFilePermissions(String fileLocation, File file) throws
IOException
+ {
+ if(isPosixFileSystem(file))
Review comment:
ok removed group from the check
----------------------------------------------------------------
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]