From 96eb8f3240f00aa6b6672d1c196ec3d24286cd7a Mon Sep 17 00:00:00 2001 From: laughingman7743 Date: Wed, 8 Mar 2023 19:35:37 +0900 Subject: [PATCH] Redesigned package structure --- .../kafka/connect/transforms/kryptonite/CipherField.java | 6 +++--- .../java/com/github/hpgrahsl/kryptonite/Kryptonite.java | 3 +++ .../hpgrahsl/kryptonite/{ => crypto}/AesGcmNoPadding.java | 2 +- .../hpgrahsl/kryptonite/{ => crypto}/CryptoAlgorithm.java | 2 +- .../hpgrahsl/kryptonite/{ => key}/ConfigDataKeyVault.java | 2 +- .../github/hpgrahsl/kryptonite/{ => key}/KeyException.java | 2 +- .../hpgrahsl/kryptonite/{ => key}/KeyInvalidException.java | 2 +- .../hpgrahsl/kryptonite/{ => key}/KeyNotFoundException.java | 2 +- .../github/hpgrahsl/kryptonite/{ => key}/KeyStrategy.java | 4 ++-- .../com/github/hpgrahsl/kryptonite/{ => key}/KeyVault.java | 6 +++--- .../hpgrahsl/kryptonite/{ => key}/NoOpKeyStrategy.java | 2 +- .../kryptonite/{ => key/gcp}/GcpKmsKeyStrategy.java | 5 +++-- .../kryptonite/{ => key/gcp}/GcpSecretManagerKeyVault.java | 6 ++++-- 13 files changed, 25 insertions(+), 19 deletions(-) rename kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/{ => crypto}/AesGcmNoPadding.java (98%) rename kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/{ => crypto}/CryptoAlgorithm.java (94%) rename kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/{ => key}/ConfigDataKeyVault.java (96%) rename kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/{ => key}/KeyException.java (96%) rename kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/{ => key}/KeyInvalidException.java (96%) rename kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/{ => key}/KeyNotFoundException.java (96%) rename kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/{ => key}/KeyStrategy.java (87%) rename kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/{ => key}/KeyVault.java (84%) rename kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/{ => key}/NoOpKeyStrategy.java (94%) rename kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/{ => key/gcp}/GcpKmsKeyStrategy.java (84%) rename kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/{ => key/gcp}/GcpSecretManagerKeyVault.java (94%) diff --git a/kafka-connect-transform-kryptonite-gcp/src/main/java/com/github/hpgrahsl/kafka/connect/transforms/kryptonite/CipherField.java b/kafka-connect-transform-kryptonite-gcp/src/main/java/com/github/hpgrahsl/kafka/connect/transforms/kryptonite/CipherField.java index 6095934..8137802 100644 --- a/kafka-connect-transform-kryptonite-gcp/src/main/java/com/github/hpgrahsl/kafka/connect/transforms/kryptonite/CipherField.java +++ b/kafka-connect-transform-kryptonite-gcp/src/main/java/com/github/hpgrahsl/kafka/connect/transforms/kryptonite/CipherField.java @@ -33,10 +33,10 @@ import com.github.hpgrahsl.kafka.connect.transforms.kryptonite.validators.KeySourceValidator; import com.github.hpgrahsl.kafka.connect.transforms.kryptonite.validators.TimeUnitValidator; import com.github.hpgrahsl.kryptonite.CipherMode; -import com.github.hpgrahsl.kryptonite.ConfigDataKeyVault; -import com.github.hpgrahsl.kryptonite.GcpSecretManagerKeyVault; import com.github.hpgrahsl.kryptonite.Kryptonite; -import com.github.hpgrahsl.kryptonite.NoOpKeyStrategy; +import com.github.hpgrahsl.kryptonite.key.ConfigDataKeyVault; +import com.github.hpgrahsl.kryptonite.key.NoOpKeyStrategy; +import com.github.hpgrahsl.kryptonite.key.gcp.GcpSecretManagerKeyVault; import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; diff --git a/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/Kryptonite.java b/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/Kryptonite.java index e9e651c..295bccd 100644 --- a/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/Kryptonite.java +++ b/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/Kryptonite.java @@ -16,6 +16,9 @@ package com.github.hpgrahsl.kryptonite; +import com.github.hpgrahsl.kryptonite.crypto.AesGcmNoPadding; +import com.github.hpgrahsl.kryptonite.crypto.CryptoAlgorithm; +import com.github.hpgrahsl.kryptonite.key.KeyVault; import java.util.Base64; import java.util.LinkedHashMap; import java.util.Map; diff --git a/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/AesGcmNoPadding.java b/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/crypto/AesGcmNoPadding.java similarity index 98% rename from kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/AesGcmNoPadding.java rename to kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/crypto/AesGcmNoPadding.java index 7422c57..de5e5ea 100644 --- a/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/AesGcmNoPadding.java +++ b/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/crypto/AesGcmNoPadding.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.github.hpgrahsl.kryptonite; +package com.github.hpgrahsl.kryptonite.crypto; import java.nio.ByteBuffer; import java.security.SecureRandom; diff --git a/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/CryptoAlgorithm.java b/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/crypto/CryptoAlgorithm.java similarity index 94% rename from kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/CryptoAlgorithm.java rename to kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/crypto/CryptoAlgorithm.java index 81d8823..2a0f4b4 100644 --- a/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/CryptoAlgorithm.java +++ b/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/crypto/CryptoAlgorithm.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.github.hpgrahsl.kryptonite; +package com.github.hpgrahsl.kryptonite.crypto; public interface CryptoAlgorithm { diff --git a/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/ConfigDataKeyVault.java b/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/key/ConfigDataKeyVault.java similarity index 96% rename from kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/ConfigDataKeyVault.java rename to kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/key/ConfigDataKeyVault.java index 32d98a5..e3e3353 100644 --- a/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/ConfigDataKeyVault.java +++ b/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/key/ConfigDataKeyVault.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.github.hpgrahsl.kryptonite; +package com.github.hpgrahsl.kryptonite.key; import java.util.Map; diff --git a/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/KeyException.java b/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/key/KeyException.java similarity index 96% rename from kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/KeyException.java rename to kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/key/KeyException.java index 0d410e3..469ffbd 100644 --- a/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/KeyException.java +++ b/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/key/KeyException.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.github.hpgrahsl.kryptonite; +package com.github.hpgrahsl.kryptonite.key; @SuppressWarnings("serial") public class KeyException extends RuntimeException { diff --git a/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/KeyInvalidException.java b/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/key/KeyInvalidException.java similarity index 96% rename from kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/KeyInvalidException.java rename to kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/key/KeyInvalidException.java index 81ca722..93a05d7 100644 --- a/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/KeyInvalidException.java +++ b/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/key/KeyInvalidException.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.github.hpgrahsl.kryptonite; +package com.github.hpgrahsl.kryptonite.key; @SuppressWarnings("serial") public class KeyInvalidException extends KeyException { diff --git a/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/KeyNotFoundException.java b/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/key/KeyNotFoundException.java similarity index 96% rename from kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/KeyNotFoundException.java rename to kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/key/KeyNotFoundException.java index b20e012..2649426 100644 --- a/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/KeyNotFoundException.java +++ b/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/key/KeyNotFoundException.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.github.hpgrahsl.kryptonite; +package com.github.hpgrahsl.kryptonite.key; @SuppressWarnings("serial") public class KeyNotFoundException extends KeyException { diff --git a/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/KeyStrategy.java b/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/key/KeyStrategy.java similarity index 87% rename from kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/KeyStrategy.java rename to kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/key/KeyStrategy.java index 1c549d3..426c1b5 100644 --- a/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/KeyStrategy.java +++ b/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/key/KeyStrategy.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.github.hpgrahsl.kryptonite; +package com.github.hpgrahsl.kryptonite.key; import java.util.HashMap; import java.util.Map; @@ -27,5 +27,5 @@ public Map getKeyCache() { return keyCache; } - abstract byte[] processKey(byte[] origKeyBytes, String identifier); + public abstract byte[] processKey(byte[] origKeyBytes, String identifier); } diff --git a/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/KeyVault.java b/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/key/KeyVault.java similarity index 84% rename from kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/KeyVault.java rename to kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/key/KeyVault.java index 5a99620..cf4a948 100644 --- a/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/KeyVault.java +++ b/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/key/KeyVault.java @@ -14,15 +14,15 @@ * limitations under the License. */ -package com.github.hpgrahsl.kryptonite; +package com.github.hpgrahsl.kryptonite.key; public abstract class KeyVault { - KeyStrategy keyStrategy; + protected KeyStrategy keyStrategy; public KeyVault(KeyStrategy keyStrategy) { this.keyStrategy = keyStrategy; } - abstract byte[] readKey(String identifier); + public abstract byte[] readKey(String identifier); } diff --git a/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/NoOpKeyStrategy.java b/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/key/NoOpKeyStrategy.java similarity index 94% rename from kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/NoOpKeyStrategy.java rename to kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/key/NoOpKeyStrategy.java index c071244..cb7673f 100644 --- a/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/NoOpKeyStrategy.java +++ b/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/key/NoOpKeyStrategy.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.github.hpgrahsl.kryptonite; +package com.github.hpgrahsl.kryptonite.key; public class NoOpKeyStrategy extends KeyStrategy { diff --git a/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/GcpKmsKeyStrategy.java b/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/key/gcp/GcpKmsKeyStrategy.java similarity index 84% rename from kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/GcpKmsKeyStrategy.java rename to kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/key/gcp/GcpKmsKeyStrategy.java index cc2396b..c46e444 100644 --- a/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/GcpKmsKeyStrategy.java +++ b/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/key/gcp/GcpKmsKeyStrategy.java @@ -1,5 +1,6 @@ -package com.github.hpgrahsl.kryptonite; +package com.github.hpgrahsl.kryptonite.key.gcp; +import com.github.hpgrahsl.kryptonite.key.KeyStrategy; import com.google.cloud.kms.v1.CryptoKeyName; import com.google.cloud.kms.v1.DecryptResponse; import com.google.cloud.kms.v1.KeyManagementServiceClient; @@ -21,7 +22,7 @@ public GcpKmsKeyStrategy(String keyName) throws IOException { } @Override - byte[] processKey(byte[] origKeyBytes, String identifier) { + public byte[] processKey(byte[] origKeyBytes, String identifier) { LOGGER.info("Process key: " + identifier); LOGGER.info("KEK name: " + keyName); DecryptResponse resp = client.decrypt(keyName, ByteString.copyFrom(origKeyBytes)); diff --git a/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/GcpSecretManagerKeyVault.java b/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/key/gcp/GcpSecretManagerKeyVault.java similarity index 94% rename from kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/GcpSecretManagerKeyVault.java rename to kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/key/gcp/GcpSecretManagerKeyVault.java index 12e9f14..6d8ea24 100644 --- a/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/GcpSecretManagerKeyVault.java +++ b/kryptonite/src/main/java/com/github/hpgrahsl/kryptonite/key/gcp/GcpSecretManagerKeyVault.java @@ -1,9 +1,11 @@ -package com.github.hpgrahsl.kryptonite; +package com.github.hpgrahsl.kryptonite.key.gcp; import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.LoadingCache; import com.github.benmanes.caffeine.cache.RemovalCause; import com.github.benmanes.caffeine.cache.RemovalListener; +import com.github.hpgrahsl.kryptonite.key.KeyStrategy; +import com.github.hpgrahsl.kryptonite.key.KeyVault; import com.google.cloud.secretmanager.v1.AccessSecretVersionResponse; import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; import com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretVersionsPagedResponse; @@ -79,7 +81,7 @@ private byte[] accessSecretVersion(String identifier) { } @Override - byte[] readKey(String identifier) { + public byte[] readKey(String identifier) { byte[] keyBytes = secretCache.get(identifier); if (keyBytes == null) { LOGGER.info("Read key: " + identifier);