mimaison commented on code in PR #15246:
URL: https://github.com/apache/kafka/pull/15246#discussion_r1471061523


##########
server-common/src/main/java/org/apache/kafka/security/EncryptingPasswordEncoder.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.kafka.security;
+
+import org.apache.kafka.common.config.ConfigException;
+import org.apache.kafka.common.config.types.Password;
+import org.apache.kafka.server.util.Csv;
+
+import javax.crypto.Cipher;
+import javax.crypto.SecretKeyFactory;
+import javax.crypto.spec.PBEKeySpec;
+import javax.crypto.spec.SecretKeySpec;
+import java.nio.charset.StandardCharsets;
+import java.security.GeneralSecurityException;
+import java.security.NoSuchAlgorithmException;
+import java.security.SecureRandom;
+import java.security.spec.InvalidKeySpecException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+/**
+ * Password encoder and decoder implementation. Encoded passwords are 
persisted as a CSV map
+ * containing the encoded password in base64 and along with the properties 
used for encryption.
+ */
+public class EncryptingPasswordEncoder implements PasswordEncoder {
+
+    private final SecureRandom secureRandom = new SecureRandom();
+
+    private final Password secret;
+    private final Optional<String> keyFactoryAlgorithm;
+    private final String cipherAlgorithm;
+    private final int keyLength;
+    private final int iterations;
+    private final CipherParamsEncoder cipherParamsEncoder;
+
+
+    /**
+     * @param secret The secret used for encoding and decoding
+     * @param keyFactoryAlgorithm  Key factory algorithm if configured. By 
default, PBKDF2WithHmacSHA512 is
+     *                             used if available, PBKDF2WithHmacSHA1 
otherwise.
+     * @param cipherAlgorithm Cipher algorithm used for encoding.
+     * @param keyLength Key length used for encoding. This should be valid for 
the specified algorithms.
+     * @param iterations Iteration count used for encoding.
+     * The provided `keyFactoryAlgorithm`, `cipherAlgorithm`, `keyLength` and 
`iterations` are used for encoding passwords.
+     * The values used for encoding are stored along with the encoded password 
and the stored values are used for decoding.
+     */
+    public EncryptingPasswordEncoder(
+            Password secret,
+            Optional<String> keyFactoryAlgorithm,

Review Comment:
   You're right we don't really need an Optional here. I switched the type to 
String.



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

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to