diff --git a/deps.edn b/deps.edn index 58dcb4ae..e37930a9 100644 --- a/deps.edn +++ b/deps.edn @@ -7,7 +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"} - crypto-password/crypto-password {:mvn/version "0.3.0"} + ;; crypto-password/crypto-password {:mvn/version "0.3.0"} + crypto-password/crypto-password {:git/url "https://github.com/Flexiana/crypto-password" + :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"} diff --git a/src/xiana/hash.clj b/src/xiana/hash.clj index c0ba6937..56ffae9a 100644 --- a/src/xiana/hash.clj +++ b/src/xiana/hash.clj @@ -3,11 +3,12 @@ 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])) -(def supported [:bcrypt :pbkdf2 :scrypt]) +(def supported [:bcrypt :pbkdf2 :scrypt :argon2]) (defn- dispatch ([state password] @@ -49,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) @@ -61,3 +74,6 @@ (defmethod check :pbkdf2 [_ password encrypted] (hash-p/check password encrypted)) + +(defmethod check :argon2 [_ password encrypted] + (argon2/check password encrypted)) diff --git a/test/xiana/hash_test.clj b/test/xiana/hash_test.clj index e5f1622c..3a51b353 100644 --- a/test/xiana/hash_test.clj +++ b/test/xiana/hash_test.clj @@ -30,9 +30,10 @@ (testing-mistake fragment) (testing-ok fragment))) -(deftest test-assert-functionality +(deftest test-full-functionality-argon2 (let [fragment {:deps {:auth {:hash-algorithm :argon2}}}] - (is (thrown? java.lang.AssertionError (hash/make fragment password))))) + (testing-mistake fragment) + (testing-ok fragment))) (deftest hash-behavior (let [pwd "not_nil"