From f27c8c58c81535bfa8896023e5c2e28c2696cc32 Mon Sep 17 00:00:00 2001 From: d-t-w Date: Tue, 6 Dec 2022 23:40:42 +1100 Subject: [PATCH] rm decoder class --- CHANGELOG.md | 8 ++++ README.md | 56 +--------------------------- project.clj | 2 +- src-java/io/kpow/secure/Decoder.java | 48 ------------------------ test/kpow/secure_test.clj | 21 ++--------- 5 files changed, 13 insertions(+), 122 deletions(-) delete mode 100644 src-java/io/kpow/secure/Decoder.java diff --git a/CHANGELOG.md b/CHANGELOG.md index ed27eb8..3fb19c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ # Change Log All notable changes to this project will be documented in this file. This change log follows the conventions of [keepachangelog.com](http://keepachangelog.com/). +## [1.0.3] - 2022-12-06 + +- rm Decoder class entirely + +## [1.0.2] - 2022-12-06 + +- rm java src path + ## [1.0.1] - 2022-12-06 - rm AOT diff --git a/README.md b/README.md index 5a63f87..62984a1 100644 --- a/README.md +++ b/README.md @@ -328,58 +328,4 @@ SECURITY_PROTOCOL=SASL_PLAINTEXT SASL_MECHANISM=PLAIN SASL_JAAS_CONFIG=org.apache.kafka.common.security.plain.PlainLoginModule required username="kpow" password="kpow-secret"; SSL_TRUSTSTORE_LOCATION=/ssl/truststore.jks``` -``` - -## Java API - -Kpow Secure is implemented in our langauge of choice, Clojure. - -Use the Java `io.kpow.secure.Decoder` to decrypt payloads `java.lang.String` or `java.util.Properties`. - -#### Decrypt payload to java.lang.String with base64 key text - -```java -String plainText = Decoder.text("//iQh9KYe7pM+mevjifZPrm7YE2+rRloG1E15zzjR88=", "ARAOGa3BAZ2TMxbU1aj+tFYfNHNwnRh3r/w2sG7FA4L7fVRzArpzrxAd2dUovyDfel++FHgW1IFrinZddTo+KiYFYm2rsn+ul65eQ1L5t9MsBq3LpuGjoFDSxkYFZweo/w0="); -``` - -``` -=> -SSL_KEYSTORE_PASSWORD=keypass1234\nSSL_TRUSTSTORE_PASSWORD=trustpass1234 -``` - -#### Decrypt payload to java.lang.String where key is expected in KPOW_SECURE_KEY environment variable or at KPOW_SECURE_KEY_LOCATION - -```java -String plainText = Decoder.text( "ARAOGa3BAZ2TMxbU1aj+tFYfNHNwnRh3r/w2sG7FA4L7fVRzArpzrxAd2dUovyDfel++FHgW1IFrinZddTo+KiYFYm2rsn+ul65eQ1L5t9MsBq3LpuGjoFDSxkYFZweo/w0="); -``` - -``` -=> -SSL_KEYSTORE_PASSWORD=keypass1234\nSSL_TRUSTSTORE_PASSWORD=trustpass1234 -``` - -#### Decrypt payload to java.util.Properties with base64 key text - -```java -Properties myProps = Decoder.properties("//iQh9KYe7pM+mevjifZPrm7YE2+rRloG1E15zzjR88=", "ARAOGa3BAZ2TMxbU1aj+tFYfNHNwnRh3r/w2sG7FA4L7fVRzArpzrxAd2dUovyDfel++FHgW1IFrinZddTo+KiYFYm2rsn+ul65eQ1L5t9MsBq3LpuGjoFDSxkYFZweo/w0="); -``` - -```clojure -;; Java API returns this as a java.util.Properties object -=> -{"SSL_TRUSTSTORE_PASSWORD" "trustpass1234" - "SSL_KEYSTORE_PASSWORD" "keypass1234"} -``` - -#### Decrypt payload to java.util.Properties where key is expected in KPOW_SECURE_KEY environment variable or at KPOW_SECURE_KEY_LOCATION - -```java -Properties myProps = Decoder.properties("ARAOGa3BAZ2TMxbU1aj+tFYfNHNwnRh3r/w2sG7FA4L7fVRzArpzrxAd2dUovyDfel++FHgW1IFrinZddTo+KiYFYm2rsn+ul65eQ1L5t9MsBq3LpuGjoFDSxkYFZweo/w0="); -``` - -```clojure -;; Java API returns this as a java.util.Properties object -=> -{"SSL_TRUSTSTORE_PASSWORD" "trustpass1234" - "SSL_KEYSTORE_PASSWORD" "keypass1234"} -``` +``` \ No newline at end of file diff --git a/project.clj b/project.clj index 9a982e2..a04ca9b 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject io.factorhouse/kpow-secure "1.0.2" +(defproject io.factorhouse/kpow-secure "1.0.3" :description "Secure Key Generation and Payload Encryption" diff --git a/src-java/io/kpow/secure/Decoder.java b/src-java/io/kpow/secure/Decoder.java deleted file mode 100644 index 3e42b13..0000000 --- a/src-java/io/kpow/secure/Decoder.java +++ /dev/null @@ -1,48 +0,0 @@ -package io.kpow.secure; - -import clojure.java.api.Clojure; -import clojure.lang.IFn; - -import java.util.Properties; - -public class Decoder { - - /** - * Decode payload > text with key taken from environment variable KPOW_SECURE_KEY - **/ - public static String text(String payload) { - IFn require = Clojure.var("clojure.core", "require"); - require.invoke(Clojure.read("kpow.secure")); - return (String) Clojure.var("kpow.secure", "decrypted").invoke(payload); - } - - /** - * Decode payload > text with key provided - **/ - public static String text(String key, String payload) { - IFn require = Clojure.var("clojure.core", "require"); - require.invoke(Clojure.read("kpow.secure")); - return (String) Clojure.var("kpow.secure", "decrypted").invoke(key, payload); - } - - /** - * Decode payload > properties with key taken from environment variable KPOW_SECURE_KEY - **/ - public static Properties properties(String payload) { - IFn require = Clojure.var("clojure.core", "require"); - require.invoke(Clojure.read("kpow.secure")); - String text = (String) Clojure.var("kpow.secure", "decrypted").invoke(payload); - return (Properties) Clojure.var("kpow.secure", "->props").invoke(text); - } - - /** - * Decode payload > properties with key provided - **/ - public static Properties properties(String key, String payload) { - IFn require = Clojure.var("clojure.core", "require"); - require.invoke(Clojure.read("kpow.secure")); - String text = (String) Clojure.var("kpow.secure", "decrypted").invoke(key, payload); - return (Properties) Clojure.var("kpow.secure", "->props").invoke(text); - } - -} \ No newline at end of file diff --git a/test/kpow/secure_test.clj b/test/kpow/secure_test.clj index 546b54d..3c67900 100644 --- a/test/kpow/secure_test.clj +++ b/test/kpow/secure_test.clj @@ -1,8 +1,7 @@ (ns kpow.secure-test - (:require [clojure.test :refer [deftest is testing]] + (:require [clojure.test :refer [deftest is]] [kpow.secure :as secure] - [kpow.secure.key :as key]) - (:import (io.kpow.secure Decoder))) + [kpow.secure.key :as key])) (def sample-input (str "SSL_KEYSTORE_PASSWORD=keypass1234\n" "SSL_TRUSTSTORE_PASSWORD=trustpass1234")) @@ -101,21 +100,7 @@ "ssl.truststore.location" "/ssl/truststore.jks" "ssl.truststore.password" "1234"} (-> (secure/decrypted (slurp "dev-resources/secure/passphrase.key") (slurp "dev-resources/secure/props.env.aes")) - (secure/->map)))) - - (testing "interop" - - (is (= {"SASL_JAAS_CONFIG" "org.apache.kafka.common.security.plain.PlainLoginModule required username=\"kpow\" password=\"kpow-secret\";" - "SASL_MECHANISM" "PLAIN" - "SECURITY_PROTOCOL" "SASL_PLAINTEXT" - "SSL_TRUSTSTORE_LOCATION" "/ssl/truststore.jks" - "SSL_TRUSTSTORE_PASSWORD" "password1234"} - (into {} (Decoder/properties (slurp "dev-resources/secure/passphrase.key") (slurp "dev-resources/secure/config.env.aes"))))) - - (is (= sample-input - (Decoder/text - "//iQh9KYe7pM+mevjifZPrm7YE2+rRloG1E15zzjR88=" - "ARDuFSOqVc5l8dPe2l8jLnRvf2Y2/ZnhWNtkuZuoP1Updxo4cFAsFr+eM4WVcH/yIogK3ypO4sLp7sSXjkXv3L5Ci/5poJG2U/+No5ySBR1BhDjcV3mkO3TBYp4nQu65mpA=")))))) + (secure/->map)))))) (deftest special-characters