-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
InMemoryKmsService - this code will be thrown away.
deploy helm to kube and enable transit secrets engine
- Loading branch information
Showing
24 changed files
with
687 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
.../src/main/java/io/kroxylicious/kms/provider/kroxylicious/inmemory/InMemoryKmsService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright Kroxylicious Authors. | ||
* | ||
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
|
||
package io.kroxylicious.kms.provider.kroxylicious.inmemory; | ||
|
||
import java.util.Map; | ||
import java.util.ServiceLoader; | ||
import java.util.UUID; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import javax.crypto.SecretKey; | ||
|
||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
|
||
import io.kroxylicious.kms.service.KmsService; | ||
import io.kroxylicious.proxy.plugin.Plugin; | ||
|
||
@Plugin(configType = InMemoryKmsService.Config.class) | ||
public class InMemoryKmsService implements KmsService<InMemoryKmsService.Config, UUID, InMemoryEdek> { | ||
|
||
// public static void main(String argv[]) throws Exception { | ||
// String string = UUID.randomUUID().toString(); | ||
// System.out.println(string); | ||
// | ||
// KeyGenerator aes = KeyGenerator.getInstance("AES"); | ||
// aes.init(256); | ||
// var key = aes.generateKey().getEncoded(); | ||
// System.out.println(key.length); | ||
// | ||
// String s = Base64.getEncoder().encodeToString(key); | ||
// System.out.println(s); | ||
// | ||
// } | ||
|
||
public static InMemoryKmsService newInstance() { | ||
return (InMemoryKmsService) ServiceLoader.load(KmsService.class).stream() | ||
.filter(p -> p.type() == InMemoryKmsService.class) | ||
.findFirst() | ||
.map(ServiceLoader.Provider::get) | ||
.orElse(null); | ||
} | ||
|
||
public record Config( | ||
Map<UUID, SecretKey> keys, | ||
Map<String, UUID> aliases) {} | ||
|
||
@NonNull | ||
@Override | ||
public InMemoryKms buildKms(Config options) { | ||
var numGeneratedDeks = new AtomicInteger(); | ||
return new InMemoryKms(12, | ||
128, | ||
options.keys(), | ||
options.aliases(), | ||
numGeneratedDeks); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
kroxylicious-runtime/src/main/java/io/kroxylicious/proxy/config/SecretKeyDeserializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright Kroxylicious Authors. | ||
* | ||
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
|
||
package io.kroxylicious.proxy.config; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.crypto.SecretKey; | ||
import javax.crypto.spec.SecretKeySpec; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.TreeNode; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer; | ||
import com.fasterxml.jackson.databind.node.ValueNode; | ||
|
||
class SecretKeyDeserializer extends StdDeserializer<SecretKey> { | ||
private final ObjectMapper MAPPER = new ObjectMapper(); | ||
|
||
protected SecretKeyDeserializer() { | ||
super(SecretKey.class); | ||
} | ||
|
||
public SecretKey deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { | ||
TreeNode tree = p.getCodec().readTree(p); | ||
TreeNode algoNode = tree.get("algo"); | ||
TreeNode keyNode = tree.get("key"); | ||
if (algoNode != null && algoNode.isValueNode()) { | ||
if (keyNode != null && keyNode.isValueNode()) { | ||
String algo = ((ValueNode) algoNode).textValue(); | ||
byte[] key = ((ValueNode) keyNode).binaryValue(); | ||
return new SecretKeySpec(key, algo); | ||
} | ||
else { | ||
throw new IllegalArgumentException("key field is absent or is not a value"); | ||
} | ||
} | ||
else { | ||
throw new IllegalArgumentException("algo field is absent or is not text"); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
kroxylicious-runtime/src/main/java/io/kroxylicious/proxy/config/SecretKeySerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright Kroxylicious Authors. | ||
* | ||
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
|
||
package io.kroxylicious.proxy.config; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.crypto.SecretKey; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import com.fasterxml.jackson.databind.ser.std.StdSerializer; | ||
|
||
class SecretKeySerializer extends StdSerializer<SecretKey> { | ||
protected SecretKeySerializer() { | ||
super(SecretKey.class); | ||
} | ||
|
||
public void serialize(SecretKey value, JsonGenerator gen, SerializerProvider provider) throws IOException { | ||
gen.writeStringField("algo", value.getAlgorithm()); | ||
gen.writeBinaryField("key", value.getEncoded()); | ||
} | ||
} |
Oops, something went wrong.