From e04d1b7ed9e4d2f7faf73122357f12014ff7ad1a Mon Sep 17 00:00:00 2001 From: Theodor Meresescu Date: Thu, 1 Feb 2024 15:44:10 +0100 Subject: [PATCH 1/9] temporary solution --- deps.edn | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/deps.edn b/deps.edn index 58dcb4ae..249fc7cc 100644 --- a/deps.edn +++ b/deps.edn @@ -7,7 +7,23 @@ com.draines/postal {:mvn/version "2.0.5"} com.flexiana/tiny-rbac {:mvn/version "0.1.1"} com.taoensso/timbre {:mvn/version "5.2.1"} - crypto-password/crypto-password {:mvn/version "0.3.0"} + + ;; This is a temporary solution: the reference repo does not + ;; contain a deps.edn or pom.xml manifest. + ;; This solution overrides the reference repo as an empty deps.edn + ;; file, so the transitive dependencies have been added below. + ;; https://clojure.org/reference/deps_edn#deps_deps_manifest + crypto-random/crypto-random {:mvn/version "1.2.1"} + crypto-equality/crypto-equality {:mvn/version "1.0.1"} + org.clojars.amit/commons-codec {:mvn/version "1.8.0"} + at.favre.lib/bcrypt {:mvn/version "0.7.0"} + com.lambdaworks/scrypt {:mvn/version "1.4.0"} + de.mkammerer/argon2-jvm {:mvn/version "2.11"} + ;; crypto-password/crypto-password {:mvn/version "0.3.0"} + crypto-password/crypto-password {:git/url "https://github.com/Flexiana/crypto-password" + :sha "e3f6719b33cd04033ce0c0328b6aef611675e0b6" + :deps/manifest :deps} + funcool/cuerdas {:mvn/version "2.2.1"} info.sunng/ring-jetty9-adapter {:mvn/version "0.30.1"} metosin/malli {:mvn/version "0.8.4"} From b17523ed4c65adcff562e216786fa542290919af Mon Sep 17 00:00:00 2001 From: Theodor Meresescu Date: Thu, 1 Feb 2024 15:44:38 +0100 Subject: [PATCH 2/9] import argon2 functionality --- src/xiana/hash.clj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/xiana/hash.clj b/src/xiana/hash.clj index c0ba6937..29a50a5d 100644 --- a/src/xiana/hash.clj +++ b/src/xiana/hash.clj @@ -5,7 +5,8 @@ (:require [crypto.password.bcrypt :as hash-b] [crypto.password.pbkdf2 :as hash-p] - [crypto.password.scrypt :as hash-s])) + [crypto.password.scrypt :as hash-s] + [crypto.password.argon2 :as argon2])) (def supported [:bcrypt :pbkdf2 :scrypt]) From fcff589597d5705589fa007389e599a243c1987c Mon Sep 17 00:00:00 2001 From: Theodor Meresescu Date: Thu, 1 Feb 2024 15:45:02 +0100 Subject: [PATCH 3/9] add argon2 keyword to supported list for dispatch check --- src/xiana/hash.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xiana/hash.clj b/src/xiana/hash.clj index 29a50a5d..0c2d04ce 100644 --- a/src/xiana/hash.clj +++ b/src/xiana/hash.clj @@ -8,7 +8,7 @@ [crypto.password.scrypt :as hash-s] [crypto.password.argon2 :as argon2])) -(def supported [:bcrypt :pbkdf2 :scrypt]) +(def supported [:bcrypt :pbkdf2 :scrypt :argon2]) (defn- dispatch ([state password] From 8f8f3623ff78fbab2e37c7e9b05067f46c64b5e0 Mon Sep 17 00:00:00 2001 From: Theodor Meresescu Date: Thu, 1 Feb 2024 15:45:31 +0100 Subject: [PATCH 4/9] make feature --- src/xiana/hash.clj | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/xiana/hash.clj b/src/xiana/hash.clj index 0c2d04ce..ca0a07ec 100644 --- a/src/xiana/hash.clj +++ b/src/xiana/hash.clj @@ -50,6 +50,18 @@ (if (= :sha1 (:type pbkdf2-settings)) "HMAC-SHA1" "HMAC-SHA256"))) +(defmethod make :argon2 + [{{:keys [argon2-settings] + :or {argon2-settings {:iterations 22 + :memory-cost 65536 + :parallelization 1}}} :deps/auth} + password] + (argon2/encrypt + password + (:iterations argon2-settings) + (:memory-cost argon2-settings) + (:parallelization argon2-settings))) + (defmulti check "Validating password." dispatch) From 7275f350f1e680b9cdab0bd1596e8fdf6170fde3 Mon Sep 17 00:00:00 2001 From: Theodor Meresescu Date: Thu, 1 Feb 2024 15:45:37 +0100 Subject: [PATCH 5/9] check feature --- src/xiana/hash.clj | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/xiana/hash.clj b/src/xiana/hash.clj index ca0a07ec..732ec713 100644 --- a/src/xiana/hash.clj +++ b/src/xiana/hash.clj @@ -74,3 +74,6 @@ (defmethod check :pbkdf2 [_ password encrypted] (hash-p/check password encrypted)) + +(defmethod check :argon2 [_ password encrypted] + (argon2/check password encrypted)) From 71e6c4cdc732ad0151f6c8f9237c1dfd7377afba Mon Sep 17 00:00:00 2001 From: Theodor Meresescu Date: Thu, 1 Feb 2024 15:48:04 +0100 Subject: [PATCH 6/9] remove redundant test --- test/xiana/hash_test.clj | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/xiana/hash_test.clj b/test/xiana/hash_test.clj index e5f1622c..17f6d685 100644 --- a/test/xiana/hash_test.clj +++ b/test/xiana/hash_test.clj @@ -30,10 +30,6 @@ (testing-mistake fragment) (testing-ok fragment))) -(deftest test-assert-functionality - (let [fragment {:deps {:auth {:hash-algorithm :argon2}}}] - (is (thrown? java.lang.AssertionError (hash/make fragment password))))) - (deftest hash-behavior (let [pwd "not_nil" state {:deps {:auth {:hash-algorithm :bcrypt From ad7e35ecbf88ab8ad0e0e9cf46d0de1e3cf5097c Mon Sep 17 00:00:00 2001 From: Theodor Meresescu Date: Thu, 1 Feb 2024 15:48:25 +0100 Subject: [PATCH 7/9] argon2 functionality test --- test/xiana/hash_test.clj | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/xiana/hash_test.clj b/test/xiana/hash_test.clj index 17f6d685..3a51b353 100644 --- a/test/xiana/hash_test.clj +++ b/test/xiana/hash_test.clj @@ -30,6 +30,11 @@ (testing-mistake fragment) (testing-ok fragment))) +(deftest test-full-functionality-argon2 + (let [fragment {:deps {:auth {:hash-algorithm :argon2}}}] + (testing-mistake fragment) + (testing-ok fragment))) + (deftest hash-behavior (let [pwd "not_nil" state {:deps {:auth {:hash-algorithm :bcrypt From 809169ae6707bb7b4a6fd0b68f603d132ab3f974 Mon Sep 17 00:00:00 2001 From: Theodor Meresescu Date: Thu, 8 Feb 2024 12:40:13 +0100 Subject: [PATCH 8/9] deps.edn imports last change --- deps.edn | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/deps.edn b/deps.edn index 249fc7cc..e37930a9 100644 --- a/deps.edn +++ b/deps.edn @@ -7,23 +7,9 @@ com.draines/postal {:mvn/version "2.0.5"} com.flexiana/tiny-rbac {:mvn/version "0.1.1"} com.taoensso/timbre {:mvn/version "5.2.1"} - - ;; This is a temporary solution: the reference repo does not - ;; contain a deps.edn or pom.xml manifest. - ;; This solution overrides the reference repo as an empty deps.edn - ;; file, so the transitive dependencies have been added below. - ;; https://clojure.org/reference/deps_edn#deps_deps_manifest - crypto-random/crypto-random {:mvn/version "1.2.1"} - crypto-equality/crypto-equality {:mvn/version "1.0.1"} - org.clojars.amit/commons-codec {:mvn/version "1.8.0"} - at.favre.lib/bcrypt {:mvn/version "0.7.0"} - com.lambdaworks/scrypt {:mvn/version "1.4.0"} - de.mkammerer/argon2-jvm {:mvn/version "2.11"} ;; crypto-password/crypto-password {:mvn/version "0.3.0"} crypto-password/crypto-password {:git/url "https://github.com/Flexiana/crypto-password" - :sha "e3f6719b33cd04033ce0c0328b6aef611675e0b6" - :deps/manifest :deps} - + :sha "cfd90d519e09797a97ded565a1e27c0b938771f1"} funcool/cuerdas {:mvn/version "2.2.1"} info.sunng/ring-jetty9-adapter {:mvn/version "0.30.1"} metosin/malli {:mvn/version "0.8.4"} From 865ce76e47f4fbb8071eb6792c3876c4c417269d Mon Sep 17 00:00:00 2001 From: Theodor Meresescu Date: Thu, 8 Feb 2024 12:47:59 +0100 Subject: [PATCH 9/9] cljstyle fix --- src/xiana/hash.clj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/xiana/hash.clj b/src/xiana/hash.clj index 732ec713..56ffae9a 100644 --- a/src/xiana/hash.clj +++ b/src/xiana/hash.clj @@ -3,10 +3,10 @@ Supported algorithms are bcrypr, pbkdf2, and scrypt. The required algorithm should be in (-> state :deps :auth :hash-algorithm)" (:require + [crypto.password.argon2 :as argon2] [crypto.password.bcrypt :as hash-b] [crypto.password.pbkdf2 :as hash-p] - [crypto.password.scrypt :as hash-s] - [crypto.password.argon2 :as argon2])) + [crypto.password.scrypt :as hash-s])) (def supported [:bcrypt :pbkdf2 :scrypt :argon2])