You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@zookeeper.apache.org by GitBox <gi...@apache.org> on 2021/03/28 15:12:51 UTC
[GitHub] [zookeeper] MuktiKrishnan opened a new pull request #1658: ZOOKEEPER-4263 : Provided an option to encrypt keystore password
MuktiKrishnan opened a new pull request #1658:
URL: https://github.com/apache/zookeeper/pull/1658
--
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:
users@infra.apache.org
[GitHub] [zookeeper] anmolnar commented on a change in pull request #1658: ZOOKEEPER-4263 : Provided an option to encrypt keystore password
Posted by GitBox <gi...@apache.org>.
anmolnar commented on a change in pull request #1658:
URL: https://github.com/apache/zookeeper/pull/1658#discussion_r604213698
##########
File path: zookeeper-server/src/main/java/org/apache/zookeeper/common/SSLUtil.java
##########
@@ -0,0 +1,90 @@
+/*
+ * 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.zookeeper.common;
+
+import org.apache.zookeeper.common.crypto.Crypt;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SSLUtil {
+
+ private static final Logger LOG = LoggerFactory.getLogger(SSLUtil.class);
+ private static Crypt crypt;
+
+ /**
+ * This method will return an instance of the user configured Crypto class
+ * value for {@value ZKConfig#CONFIG_CRYPT_CLASS}.
+ *
+ * @return an instance of the Crypto class configured
+ */
+ private static Crypt getCrypt() throws ReflectiveOperationException {
Review comment:
If you wanted to make this lazy-initialized, I think it would be beneficial to make this method thread-safe. Otherwise you could just do this in the static constructor.
##########
File path: zookeeper-server/src/main/java/org/apache/zookeeper/common/SSLUtil.java
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.zookeeper.common;
+
+import java.lang.reflect.InvocationTargetException;
+import org.apache.zookeeper.common.crypto.Crypt;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SSLUtil {
+
+ private static final Logger LOG = LoggerFactory.getLogger(SSLUtil.class);
+ private static Crypt crypt;
+
+ /**
+ * This method will return an instance of the user configured Crypto class
+ * value for {@value ZKConfig#CONFIG_CRYPT_CLASS}.
+ *
+ * @return an instance of the Crypto class configured
+ */
+ private static Crypt getCrypt() {
+ if (crypt == null) {
+ String cryptClassName = System
+ .getProperty(ZKConfig.CONFIG_CRYPT_CLASS);
+ Class<?> cryptClass = null;
+ if (cryptClassName != null && !cryptClassName.isEmpty()) {
+ try {
+ cryptClass = Class.forName(cryptClassName.trim());
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException("Class configured for "
+ + ZKConfig.CONFIG_CRYPT_CLASS + " is not found ", e);
+ }
+ try {
+ crypt = (Crypt) cryptClass.getConstructor().newInstance();
+ } catch (NoSuchMethodException | InstantiationException
+ | IllegalAccessException | InvocationTargetException e) {
+ throw new RuntimeException(
+ "Could not access default constructor for the Class which is configured for "
+ + ZKConfig.CONFIG_CRYPT_CLASS
+ + " property ", e);
+ }
+
+ } else {
+ throw new RuntimeException(
+ "Class to decrypt the encrypted text is not configured for "
+ + ZKConfig.CONFIG_CRYPT_CLASS + " property ");
+ }
+ }
+ return crypt;
+ }
+
+ /**
+ * This method will decrypt the given text using the Crypto class client
+ * has configured if client has set the password encryption to true
+ *
+ * @param pwd string to decrypt
+ * @param decrypt client configured value whether the text is in plain or
+ * encrypted format
+ * @return decrypted text
+ */
+ public static String getDecryptedText(String pwd, boolean decrypt) {
+ if (decrypt) {
+ try {
+ getCrypt();
+ } catch (Exception e) {
+ throw new RuntimeException(
+ "Failed to get the Crypt reference used for decrypting a text.",
+ e);
+ }
+ try {
+ pwd = crypt.decrypt(pwd);
+ } catch (Exception e) {
+ throw new RuntimeException(
Review comment:
I don't see benefit in catching exception for each call. I think you could just remove the catch blocks altogether, or create only a single one at the end of this method.
--
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:
users@infra.apache.org
[GitHub] [zookeeper] anmolnar commented on pull request #1658: ZOOKEEPER-4263 : Provided an option to encrypt keystore password
Posted by GitBox <gi...@apache.org>.
anmolnar commented on pull request #1658:
URL: https://github.com/apache/zookeeper/pull/1658#issuecomment-809227478
> > I think the idea makes sense to me. Would you please provide a real life example of a `Crypt` class that could be used in production with your patch?
>
> I think it is not good to add any concrete implementation otherwise there will be too many security concerns. I can add a reference implementation in test class, but for that I need to add test dependencies
You don't need to add it to the code. Just paste it here.
--
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:
users@infra.apache.org
[GitHub] [zookeeper] anmolnar commented on a change in pull request #1658: ZOOKEEPER-4263 : Provided an option to encrypt keystore password
Posted by GitBox <gi...@apache.org>.
anmolnar commented on a change in pull request #1658:
URL: https://github.com/apache/zookeeper/pull/1658#discussion_r602930897
##########
File path: zookeeper-server/src/main/java/org/apache/zookeeper/common/SSLUtil.java
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.zookeeper.common;
+
+import java.lang.reflect.InvocationTargetException;
+import org.apache.zookeeper.common.crypto.Crypt;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SSLUtil {
+
+ private static final Logger LOG = LoggerFactory.getLogger(SSLUtil.class);
+ private static Crypt crypt;
+
+ /**
+ * This method will return an instance of the user configured Crypto class
+ * value for {@value ZKConfig#CONFIG_CRYPT_CLASS}.
+ *
+ * @return an instance of the Crypto class configured
+ */
+ private static Crypt getCrypt() {
+ if (crypt == null) {
+ String cryptClassName = System
+ .getProperty(ZKConfig.CONFIG_CRYPT_CLASS);
+ Class<?> cryptClass = null;
+ if (cryptClassName != null && !cryptClassName.isEmpty()) {
+ try {
+ cryptClass = Class.forName(cryptClassName.trim());
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException("Class configured for "
+ + ZKConfig.CONFIG_CRYPT_CLASS + " is not found ", e);
+ }
+ try {
+ crypt = (Crypt) cryptClass.getConstructor().newInstance();
+ } catch (NoSuchMethodException | InstantiationException
Review comment:
All of these exception (and ClassNotFound above) are `ReflectiveOperationException`s. Why do you convert them to RuntimeException?
I think I would rather just let them thrown by the method and add ReflectiveOperationException to the method signature.
(Clean code: if you can't do anything with the exception other then re-throwing it, you probably don't need to catch it.)
##########
File path: zookeeper-server/src/main/java/org/apache/zookeeper/common/SSLUtil.java
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.zookeeper.common;
+
+import java.lang.reflect.InvocationTargetException;
+import org.apache.zookeeper.common.crypto.Crypt;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SSLUtil {
+
+ private static final Logger LOG = LoggerFactory.getLogger(SSLUtil.class);
+ private static Crypt crypt;
+
+ /**
+ * This method will return an instance of the user configured Crypto class
+ * value for {@value ZKConfig#CONFIG_CRYPT_CLASS}.
+ *
+ * @return an instance of the Crypto class configured
+ */
+ private static Crypt getCrypt() {
+ if (crypt == null) {
+ String cryptClassName = System
+ .getProperty(ZKConfig.CONFIG_CRYPT_CLASS);
+ Class<?> cryptClass = null;
+ if (cryptClassName != null && !cryptClassName.isEmpty()) {
+ try {
+ cryptClass = Class.forName(cryptClassName.trim());
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException("Class configured for "
+ + ZKConfig.CONFIG_CRYPT_CLASS + " is not found ", e);
+ }
+ try {
+ crypt = (Crypt) cryptClass.getConstructor().newInstance();
+ } catch (NoSuchMethodException | InstantiationException
+ | IllegalAccessException | InvocationTargetException e) {
+ throw new RuntimeException(
+ "Could not access default constructor for the Class which is configured for "
+ + ZKConfig.CONFIG_CRYPT_CLASS
+ + " property ", e);
+ }
+
+ } else {
+ throw new RuntimeException(
+ "Class to decrypt the encrypted text is not configured for "
+ + ZKConfig.CONFIG_CRYPT_CLASS + " property ");
+ }
+ }
+ return crypt;
+ }
+
+ /**
+ * This method will decrypt the given text using the Crypto class client
+ * has configured if client has set the password encryption to true
+ *
+ * @param pwd string to decrypt
+ * @param decrypt client configured value whether the text is in plain or
+ * encrypted format
+ * @return decrypted text
+ */
+ public static String getDecryptedText(String pwd, boolean decrypt) {
+ if (decrypt) {
+ try {
+ getCrypt();
+ } catch (Exception e) {
+ throw new RuntimeException(
Review comment:
You caught a RuntimeException here and thrown an other.
##########
File path: zookeeper-server/src/main/java/org/apache/zookeeper/common/SSLUtil.java
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.zookeeper.common;
+
+import java.lang.reflect.InvocationTargetException;
+import org.apache.zookeeper.common.crypto.Crypt;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SSLUtil {
+
+ private static final Logger LOG = LoggerFactory.getLogger(SSLUtil.class);
+ private static Crypt crypt;
+
+ /**
+ * This method will return an instance of the user configured Crypto class
+ * value for {@value ZKConfig#CONFIG_CRYPT_CLASS}.
+ *
+ * @return an instance of the Crypto class configured
+ */
+ private static Crypt getCrypt() {
+ if (crypt == null) {
+ String cryptClassName = System
+ .getProperty(ZKConfig.CONFIG_CRYPT_CLASS);
+ Class<?> cryptClass = null;
+ if (cryptClassName != null && !cryptClassName.isEmpty()) {
+ try {
+ cryptClass = Class.forName(cryptClassName.trim());
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException("Class configured for "
+ + ZKConfig.CONFIG_CRYPT_CLASS + " is not found ", e);
+ }
+ try {
+ crypt = (Crypt) cryptClass.getConstructor().newInstance();
+ } catch (NoSuchMethodException | InstantiationException
+ | IllegalAccessException | InvocationTargetException e) {
+ throw new RuntimeException(
+ "Could not access default constructor for the Class which is configured for "
+ + ZKConfig.CONFIG_CRYPT_CLASS
+ + " property ", e);
+ }
+
+ } else {
+ throw new RuntimeException(
+ "Class to decrypt the encrypted text is not configured for "
+ + ZKConfig.CONFIG_CRYPT_CLASS + " property ");
+ }
+ }
+ return crypt;
+ }
+
+ /**
+ * This method will decrypt the given text using the Crypto class client
+ * has configured if client has set the password encryption to true
+ *
+ * @param pwd string to decrypt
+ * @param decrypt client configured value whether the text is in plain or
+ * encrypted format
+ * @return decrypted text
+ */
+ public static String getDecryptedText(String pwd, boolean decrypt) {
+ if (decrypt) {
+ try {
+ getCrypt();
+ } catch (Exception e) {
+ throw new RuntimeException(
+ "Failed to get the Crypt reference used for decrypting a text.",
+ e);
+ }
+ try {
+ pwd = crypt.decrypt(pwd);
+ } catch (Exception e) {
+ throw new RuntimeException(
Review comment:
Don't swallow the original exception. There won't be any info in the logs about what happened originally.
##########
File path: zookeeper-server/src/main/java/org/apache/zookeeper/common/SSLUtil.java
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.zookeeper.common;
+
+import java.lang.reflect.InvocationTargetException;
+import org.apache.zookeeper.common.crypto.Crypt;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SSLUtil {
+
+ private static final Logger LOG = LoggerFactory.getLogger(SSLUtil.class);
+ private static Crypt crypt;
+
+ /**
+ * This method will return an instance of the user configured Crypto class
+ * value for {@value ZKConfig#CONFIG_CRYPT_CLASS}.
+ *
+ * @return an instance of the Crypto class configured
+ */
+ private static Crypt getCrypt() {
+ if (crypt == null) {
+ String cryptClassName = System
+ .getProperty(ZKConfig.CONFIG_CRYPT_CLASS);
+ Class<?> cryptClass = null;
+ if (cryptClassName != null && !cryptClassName.isEmpty()) {
+ try {
+ cryptClass = Class.forName(cryptClassName.trim());
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException("Class configured for "
+ + ZKConfig.CONFIG_CRYPT_CLASS + " is not found ", e);
+ }
+ try {
+ crypt = (Crypt) cryptClass.getConstructor().newInstance();
+ } catch (NoSuchMethodException | InstantiationException
+ | IllegalAccessException | InvocationTargetException e) {
+ throw new RuntimeException(
+ "Could not access default constructor for the Class which is configured for "
+ + ZKConfig.CONFIG_CRYPT_CLASS
+ + " property ", e);
+ }
+
+ } else {
+ throw new RuntimeException(
Review comment:
`IllegalArgumentException`
--
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:
users@infra.apache.org
[GitHub] [zookeeper] MuktiKrishnan commented on a change in pull request #1658: ZOOKEEPER-4263 : Provided an option to encrypt keystore password
Posted by GitBox <gi...@apache.org>.
MuktiKrishnan commented on a change in pull request #1658:
URL: https://github.com/apache/zookeeper/pull/1658#discussion_r603373160
##########
File path: zookeeper-server/src/main/java/org/apache/zookeeper/common/SSLUtil.java
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.zookeeper.common;
+
+import java.lang.reflect.InvocationTargetException;
+import org.apache.zookeeper.common.crypto.Crypt;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SSLUtil {
+
+ private static final Logger LOG = LoggerFactory.getLogger(SSLUtil.class);
+ private static Crypt crypt;
+
+ /**
+ * This method will return an instance of the user configured Crypto class
+ * value for {@value ZKConfig#CONFIG_CRYPT_CLASS}.
+ *
+ * @return an instance of the Crypto class configured
+ */
+ private static Crypt getCrypt() {
+ if (crypt == null) {
+ String cryptClassName = System
+ .getProperty(ZKConfig.CONFIG_CRYPT_CLASS);
+ Class<?> cryptClass = null;
+ if (cryptClassName != null && !cryptClassName.isEmpty()) {
+ try {
+ cryptClass = Class.forName(cryptClassName.trim());
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException("Class configured for "
+ + ZKConfig.CONFIG_CRYPT_CLASS + " is not found ", e);
+ }
+ try {
+ crypt = (Crypt) cryptClass.getConstructor().newInstance();
+ } catch (NoSuchMethodException | InstantiationException
+ | IllegalAccessException | InvocationTargetException e) {
+ throw new RuntimeException(
+ "Could not access default constructor for the Class which is configured for "
+ + ZKConfig.CONFIG_CRYPT_CLASS
+ + " property ", e);
+ }
+
+ } else {
+ throw new RuntimeException(
+ "Class to decrypt the encrypted text is not configured for "
+ + ZKConfig.CONFIG_CRYPT_CLASS + " property ");
+ }
+ }
+ return crypt;
+ }
+
+ /**
+ * This method will decrypt the given text using the Crypto class client
+ * has configured if client has set the password encryption to true
+ *
+ * @param pwd string to decrypt
+ * @param decrypt client configured value whether the text is in plain or
+ * encrypted format
+ * @return decrypted text
+ */
+ public static String getDecryptedText(String pwd, boolean decrypt) {
+ if (decrypt) {
+ try {
+ getCrypt();
+ } catch (Exception e) {
+ throw new RuntimeException(
Review comment:
Catching ReflectiveOperationException instead of Exception
--
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:
users@infra.apache.org
[GitHub] [zookeeper] MuktiKrishnan commented on pull request #1658: ZOOKEEPER-4263 : Provided an option to encrypt keystore password
Posted by GitBox <gi...@apache.org>.
MuktiKrishnan commented on pull request #1658:
URL: https://github.com/apache/zookeeper/pull/1658#issuecomment-809415635
> > > I think the idea makes sense to me. Would you please provide a real life example of a `Crypt` class that could be used in production with your patch?
> >
> >
> > I think it is not good to add any concrete implementation otherwise there will be too many security concerns. I can add a reference implementation in test class, but for that I need to add test dependencies
>
> You don't need to add it to the code. Just paste it here.
// An implementation of Crypt class.
public class DemoCrypt implements Crypt {
private static final byte[] AES_IV = { 23, 37, -3, 20, -42, 19, 77, -6,
-12, 8, -12, 1, 3, -14, 39, -25 };
private static String AES_KEY_IN_HEX = "9665189195944541061733242962480165010686234024933581821496679159916027000716725228235751093878445517";
private static byte[] AES_KEY;
private static final String AES_ALGORITHM = "AES";
private static final String AES_PADDING = "AES/CBC/PKCS5Padding";
/** Config for encrypt and decrypt key offset */
public static final String ENCRYPT_DECRYPT_KEY_OFFSET = "zookeeeper.config.encrypt.decrypt.key.offset";
static {
int keyOffset = 0;
String offset = System.getProperty(ENCRYPT_DECRYPT_KEY_OFFSET);
if (offset != null && !offset.isEmpty()) {
keyOffset = Integer.valueOf(offset.trim());
}
String userRequestedKey;
try {
userRequestedKey = AES_KEY_IN_HEX.substring(keyOffset,
keyOffset + 32);
} catch (IndexOutOfBoundsException e) {
throw new IllegalArgumentException("Supported value for "
+ ENCRYPT_DECRYPT_KEY_OFFSET + " is only between 0 to 68");
}
int len = userRequestedKey.length();
byte[] data = new byte[len / 2];
for (int i = 0; i < len; i += 2) {
data[i / 2] = (byte) ((Character.digit(userRequestedKey.charAt(i),
16) << 4) + Character.digit(userRequestedKey.charAt(i + 1),
16));
}
AES_KEY = data;
}
public String encrypt(String plainText) throws Exception {
if (null == plainText || plainText.trim().length() == 0) {
throw new IllegalArgumentException(
"The specified string to be encrypted[" + plainText
+ "] is either null or empty");
}
IvParameterSpec ivParamSpec = new IvParameterSpec(AES_IV);
SecretKeySpec secretKeySpec = new SecretKeySpec(AES_KEY, AES_ALGORITHM);
Cipher cipher = Cipher.getInstance(AES_PADDING);
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, ivParamSpec);
return new String(Base64.encodeBase64(cipher.doFinal(plainText
.getBytes())));
}
@Override
public String decrypt(String cipherText) throws Exception {
if (null == cipherText || cipherText.trim().length() == 0) {
throw new IllegalArgumentException(
"The specified string to be decrypted[" + cipherText
+ "] is either null or empty");
}
IvParameterSpec ivParamSpec = new IvParameterSpec(AES_IV);
SecretKeySpec secretKeySpec = new SecretKeySpec(AES_KEY, AES_ALGORITHM);
Cipher cipher = Cipher.getInstance(AES_PADDING);
cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, ivParamSpec);
return new String(cipher.doFinal(Base64.decodeBase64(cipherText
.getBytes())));
}
}
--
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:
users@infra.apache.org
[GitHub] [zookeeper] MuktiKrishnan commented on pull request #1658: ZOOKEEPER-4263 : Provided an option to encrypt keystore password
Posted by GitBox <gi...@apache.org>.
MuktiKrishnan commented on pull request #1658:
URL: https://github.com/apache/zookeeper/pull/1658#issuecomment-809100967
> I think the idea makes sense to me. Would you please provide a real life example of a `Crypt` class that could be used in production with your patch?
I think it is not good to add any concrete implementation otherwise there will be too many security concerns. I can add a reference implementation in test class, but for that I need to add test dependencies
--
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:
users@infra.apache.org