From 4e335796ba4bf7c6898f955d63a761bc0334d647 Mon Sep 17 00:00:00 2001 From: Suresh Srinivas Date: Thu, 1 Sep 2022 14:10:50 -0700 Subject: [PATCH] Deleting CipherText introduced for building pagination cursors is no longer used (#7142) --- .../openmetadata/common/utils/CipherText.java | 72 ------------------- .../common/utils/CipherTextTest.java | 32 --------- .../openmetadata/core/util/CipherText.java | 70 ------------------ .../core/util/CipherTextTest.java | 32 --------- 4 files changed, 206 deletions(-) delete mode 100644 common/src/main/java/org/openmetadata/common/utils/CipherText.java delete mode 100644 common/src/test/java/org/openmetadata/common/utils/CipherTextTest.java delete mode 100644 openmetadata-core/src/main/java/org/openmetadata/core/util/CipherText.java delete mode 100644 openmetadata-core/src/test/java/org/openmetadata/core/util/CipherTextTest.java diff --git a/common/src/main/java/org/openmetadata/common/utils/CipherText.java b/common/src/main/java/org/openmetadata/common/utils/CipherText.java deleted file mode 100644 index 86586da8fd1..00000000000 --- a/common/src/main/java/org/openmetadata/common/utils/CipherText.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2021 Collate - * Licensed 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.openmetadata.common.utils; - -import java.nio.charset.StandardCharsets; -import java.security.GeneralSecurityException; -import java.security.InvalidKeyException; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.Arrays; -import java.util.Base64; -import java.util.Random; -import javax.crypto.BadPaddingException; -import javax.crypto.Cipher; -import javax.crypto.IllegalBlockSizeException; -import javax.crypto.NoSuchPaddingException; -import javax.crypto.spec.SecretKeySpec; - -/** Class that uses AEC encryption to encrypt and decrypt plain text */ -public final class CipherText { - private static CipherText instance = null; - private static SecretKeySpec secretKey; - - private CipherText() throws NoSuchAlgorithmException { - // Generate random set of bytes to be used as secret key - byte[] bytes = new byte[16]; - new Random().nextBytes(bytes); - - // Generate secret key from random bytes - bytes = MessageDigest.getInstance("SHA-1").digest(bytes); - secretKey = new SecretKeySpec(Arrays.copyOf(bytes, 16), "AES"); - } - - public static CipherText instance() throws NoSuchAlgorithmException { - if (instance == null) { - instance = new CipherText(); - } - return instance; - } - - public String encrypt(String strToEncrypt) - throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, IllegalBlockSizeException, - BadPaddingException { - if (strToEncrypt == null) { - return null; - } - // Initialize Cipher with the secret key - Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); - cipher.init(Cipher.ENCRYPT_MODE, secretKey); - return Base64.getUrlEncoder().encodeToString(cipher.doFinal(strToEncrypt.getBytes(StandardCharsets.UTF_8))); - } - - public String decrypt(String strToDecrypt) throws GeneralSecurityException { - if (strToDecrypt == null) { - return null; - } - Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5PADDING"); - cipher.init(Cipher.DECRYPT_MODE, secretKey); - return new String(cipher.doFinal(Base64.getUrlDecoder().decode(strToDecrypt))); - } -} diff --git a/common/src/test/java/org/openmetadata/common/utils/CipherTextTest.java b/common/src/test/java/org/openmetadata/common/utils/CipherTextTest.java deleted file mode 100644 index 3fb6c2fbadc..00000000000 --- a/common/src/test/java/org/openmetadata/common/utils/CipherTextTest.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2021 Collate - * Licensed 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.openmetadata.common.utils; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.io.UnsupportedEncodingException; -import java.security.GeneralSecurityException; -import org.junit.jupiter.api.Test; - -class CipherTextTest { - @Test - void encryptDecryptTest() throws GeneralSecurityException, UnsupportedEncodingException { - CipherText cipherText = CipherText.instance(); - String[] strings = {"test1", "test2", "service.dwh.fact_trip", "random text", "user@domain.com"}; - for (String str : strings) { - String encryptedStr = cipherText.encrypt(str); - assertEquals(str, cipherText.decrypt(encryptedStr)); - } - } -} diff --git a/openmetadata-core/src/main/java/org/openmetadata/core/util/CipherText.java b/openmetadata-core/src/main/java/org/openmetadata/core/util/CipherText.java deleted file mode 100644 index eb563410528..00000000000 --- a/openmetadata-core/src/main/java/org/openmetadata/core/util/CipherText.java +++ /dev/null @@ -1,70 +0,0 @@ -package org.openmetadata.core.util; /* - * Copyright 2021 Collate - * Licensed 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. - */ - -import java.nio.charset.StandardCharsets; -import java.security.GeneralSecurityException; -import java.security.InvalidKeyException; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.Arrays; -import java.util.Base64; -import java.util.Random; -import javax.crypto.BadPaddingException; -import javax.crypto.Cipher; -import javax.crypto.IllegalBlockSizeException; -import javax.crypto.NoSuchPaddingException; -import javax.crypto.spec.SecretKeySpec; - -/** Class that uses AEC encryption to encrypt and decrypt plain text */ -public final class CipherText { - private static CipherText instance = null; - private static SecretKeySpec secretKey; - - private CipherText() throws NoSuchAlgorithmException { - // Generate random set of bytes to be used as secret key - byte[] bytes = new byte[16]; - new Random().nextBytes(bytes); - - // Generate secret key from random bytes - bytes = MessageDigest.getInstance("SHA-1").digest(bytes); - secretKey = new SecretKeySpec(Arrays.copyOf(bytes, 16), "AES"); - } - - public static CipherText instance() throws NoSuchAlgorithmException { - if (instance == null) { - instance = new CipherText(); - } - return instance; - } - - public String encrypt(String strToEncrypt) - throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, IllegalBlockSizeException, - BadPaddingException { - if (strToEncrypt == null) { - return null; - } - // Initialize Cipher with the secret key - Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); - cipher.init(Cipher.ENCRYPT_MODE, secretKey); - return Base64.getUrlEncoder().encodeToString(cipher.doFinal(strToEncrypt.getBytes(StandardCharsets.UTF_8))); - } - - public String decrypt(String strToDecrypt) throws GeneralSecurityException { - if (strToDecrypt == null) { - return null; - } - Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5PADDING"); - cipher.init(Cipher.DECRYPT_MODE, secretKey); - return new String(cipher.doFinal(Base64.getUrlDecoder().decode(strToDecrypt))); - } -} diff --git a/openmetadata-core/src/test/java/org/openmetadata/core/util/CipherTextTest.java b/openmetadata-core/src/test/java/org/openmetadata/core/util/CipherTextTest.java deleted file mode 100644 index b15df3459bc..00000000000 --- a/openmetadata-core/src/test/java/org/openmetadata/core/util/CipherTextTest.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2021 Collate - * Licensed 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.openmetadata.core.util; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.io.UnsupportedEncodingException; -import java.security.GeneralSecurityException; -import org.junit.jupiter.api.Test; - -class CipherTextTest { - @Test - void encryptDecryptTest() throws GeneralSecurityException, UnsupportedEncodingException { - CipherText cipherText = CipherText.instance(); - String[] strings = {"test1", "test2", "service.dwh.fact_trip", "random text", "user@domain.com"}; - for (String str : strings) { - String encryptedStr = cipherText.encrypt(str); - assertEquals(str, cipherText.decrypt(encryptedStr)); - } - } -}