Compare commits
7 Commits
v1.2
...
3a6fd107c0
| Author | SHA1 | Date | |
|---|---|---|---|
| 3a6fd107c0 | |||
| 4c31950a88 | |||
| aa71cb1d76 | |||
| c746675045 | |||
| 4052995ba8 | |||
| 44f48fced8 | |||
| c78e89a94b |
@@ -17,6 +17,8 @@ You can read more about the algorithm here:
|
||||
|
||||
## How to use
|
||||
|
||||

|
||||
|
||||
First, you must have installed a Java Runtime Environment. Check https://adoptium.net/es if you are
|
||||
unsure how to install.
|
||||
|
||||
@@ -145,11 +147,16 @@ clj-totp.sh import <alias> "<url>"
|
||||
- [x] Show several OTPs at once
|
||||
|
||||
### v1.2
|
||||
- [x] Show progress bar
|
||||
- [x] Styles for progress bar
|
||||
- [x] Native compilation script corrections
|
||||
|
||||
### v2
|
||||
- [ ] REST API
|
||||
- [ ] User management
|
||||
- [ ] Robust BD backend (H2, datomic, or similar)
|
||||
|
||||
### v1.3
|
||||
### v3
|
||||
- [ ] Simple web connected to REST API
|
||||
|
||||
|
||||
|
||||
122
build.clj
122
build.clj
@@ -1,37 +1,101 @@
|
||||
(ns build
|
||||
(:require [clojure.tools.build.api :as b]))
|
||||
(:refer-clojure :exclude [test])
|
||||
(:require [clojure.tools.build.api :as b]
|
||||
[clojure.java.io :as io]))
|
||||
|
||||
(def lib 'es.rcorral/clj-totp)
|
||||
(def version (format "1.2.%s" (b/git-count-revs nil)))
|
||||
(def target-dir "target")
|
||||
(def class-dir (str target-dir "/classes"))
|
||||
(def uber-file (format "target/%s-%s-standalone.jar" (name lib) version))
|
||||
(def lib-group "es.rcorral")
|
||||
(def artifact-prefix "clj-totp")
|
||||
(def curr-version (format "2.0.%s" (b/git-count-revs nil)))
|
||||
|
||||
;; delay to defer side effects (artifact downloads)
|
||||
(def basis (delay (b/create-basis {:project "deps.edn"})))
|
||||
;; Builds artifact's full descriptor for each subproject
|
||||
(defn lib [subproj]
|
||||
(symbol (str lib-group "/" artifact-prefix "-" subproj )))
|
||||
|
||||
(defn clean [_]
|
||||
(b/delete {:path "target"}))
|
||||
;; Basis for each subproject, using their own deps.edn
|
||||
(defn basis [subproj]
|
||||
;(b/create-basis {:project (str subproj "/deps.edn")}))
|
||||
(delay (b/create-basis {:project (str "projects/" subproj "/deps.edn")})))
|
||||
|
||||
(defn compile-java [_]
|
||||
(b/javac {:src-dirs ["java"]
|
||||
:class-dir class-dir
|
||||
;; Target dir for each subproject
|
||||
(defn target-dir [subproj]
|
||||
(str "target/" subproj))
|
||||
|
||||
;; Path for compiled classes
|
||||
(defn class-dir [subproj]
|
||||
(str (target-dir subproj) "/" "classes"))
|
||||
|
||||
;; Jar file for each subproject. :uber type adds -standalone suffix
|
||||
(defn jar-file [subproj version type]
|
||||
(format "target/%s-%s-%s%s.jar" artifact-prefix subproj version
|
||||
(if (= type :uber) "-standalone" "")))
|
||||
|
||||
;; Clean target dir for subproject
|
||||
(defn clean [{:keys [subproj]}]
|
||||
(b/delete {:path (target-dir subproj)})
|
||||
(println "Project" subproj "cleaned"))
|
||||
|
||||
;; Compile java classes, only if java subdir exists
|
||||
(defn compile-java [subproj]
|
||||
(let [java-dir (str "projects/" subproj "/java")]
|
||||
(if (.exists (io/file java-dir))
|
||||
(do
|
||||
(println "Compiling java code for" subproj)
|
||||
(b/javac {:src-dirs [java-dir]
|
||||
:class-dir (class-dir subproj)
|
||||
:basis @(basis subproj)
|
||||
:javac-opts ["-source" "11" "--target" "11" "-proc:none"]}))
|
||||
(println "No java code for" subproj ", skipping compilation"))))
|
||||
|
||||
;; Create a jar file
|
||||
(defn jar
|
||||
"Build a simple jar file, with no dependencies included."
|
||||
[{:keys [subproj version]}]
|
||||
(let [real-version (if version version curr-version)
|
||||
target-dir (target-dir subproj)
|
||||
class-dir (class-dir subproj)
|
||||
src-dir (str "projects/" subproj "/src")
|
||||
resources-dir (str "projects/" subproj "/resources")
|
||||
basis (basis subproj)
|
||||
jar-file (jar-file subproj real-version :plain)]
|
||||
;; Clean only class dir
|
||||
(b/delete {:path class-dir})
|
||||
;; Copy code
|
||||
(b/copy-dir {:src-dirs [src-dir]
|
||||
:target-dir class-dir})
|
||||
;; Copy resources
|
||||
(b/copy-dir {:src-dirs [resources-dir]
|
||||
:target-dir target-dir})
|
||||
;; Compile java code, if exists
|
||||
(compile-java subproj)
|
||||
;; Build jar
|
||||
(b/jar {:class-dir class-dir
|
||||
:basis @basis
|
||||
:javac-opts ["-source" "11" "--target" "11" "-proc:none"]}))
|
||||
:jar-file jar-file
|
||||
:lib (lib subproj)
|
||||
:version real-version})
|
||||
(println "Generated jar file:" jar-file)))
|
||||
|
||||
;; Create an uber jar, with all dependencies inside
|
||||
(defn uber
|
||||
"Build a uberjar with all dependencies included"
|
||||
[{:keys [subproj version main-ns]}]
|
||||
(let [real-version (if version version curr-version)target-dir (target-dir subproj)
|
||||
basis (basis subproj)
|
||||
class-dir (class-dir subproj)
|
||||
src-dir (str "projects/" subproj "/src")
|
||||
resources-dir (str "projects/" subproj "/resources")
|
||||
uber-file (jar-file subproj real-version :uber)]
|
||||
(b/delete {:path class-dir})
|
||||
(b/copy-dir {:src-dirs [src-dir]
|
||||
:target-dir class-dir})
|
||||
(b/copy-dir {:src-dirs [resources-dir]
|
||||
:target-dir target-dir})
|
||||
(compile-java subproj)
|
||||
(b/compile-clj {:basis @basis
|
||||
:src-dirs [src-dir] :class-dir class-dir})
|
||||
(b/uber {:class-dir class-dir
|
||||
:uber-file uber-file
|
||||
:basis @basis
|
||||
:main main-ns})
|
||||
(println "Generated uberjar executable:" uber-file)))
|
||||
|
||||
#_{:clojure-lsp/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn uber [_]
|
||||
(clean nil)
|
||||
(b/copy-dir {:src-dirs ["src"]
|
||||
:target-dir class-dir})
|
||||
(b/copy-file {:src "resources/clj-totp.sh"
|
||||
:target "target/clj-totp.sh"})
|
||||
(compile-java nil)
|
||||
(b/compile-clj {:basis @basis
|
||||
:ns-compile '[totp.app]
|
||||
:class-dir class-dir})
|
||||
(b/uber {:class-dir class-dir
|
||||
:uber-file uber-file
|
||||
:basis @basis
|
||||
:main 'totp.app}))
|
||||
|
||||
42
clj-totp.iml
42
clj-totp.iml
@@ -1,42 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="BuildSystem">
|
||||
<option name="buildSystemId" value="CLOJURE_DEPS" />
|
||||
<option name="displayName" value="clj-totp" />
|
||||
</component>
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Deps: org.clojure/clojure:1.12.1" level="project" />
|
||||
<orderEntry type="library" name="Deps: lambdaisland/deep-diff2:2.11.216" level="project" />
|
||||
<orderEntry type="library" name="Deps: org.clojure/core.specs.alpha:0.4.74" level="project" />
|
||||
<orderEntry type="library" name="Deps: lambdaisland/kaocha:1.91.1392" level="project" />
|
||||
<orderEntry type="library" name="Deps: expound:0.9.0" level="project" />
|
||||
<orderEntry type="library" name="Deps: org.clojure/spec.alpha:0.5.238" level="project" />
|
||||
<orderEntry type="library" name="Deps: org.clojure/tools.cli:1.1.230" level="project" />
|
||||
<orderEntry type="library" name="Deps: lambdaisland/clj-diff:1.4.78" level="project" />
|
||||
<orderEntry type="library" name="Deps: net.incongru.watchservice/barbary-watchservice:1.0" level="project" />
|
||||
<orderEntry type="library" name="Deps: slingshot:0.12.2" level="project" />
|
||||
<orderEntry type="library" name="Deps: fipp:0.6.26" level="project" />
|
||||
<orderEntry type="library" name="Deps: com.nextjournal/beholder:1.0.2" level="project" />
|
||||
<orderEntry type="library" name="Deps: aero:1.1.6" level="project" />
|
||||
<orderEntry type="library" name="Deps: lambdaisland/tools.namespace:0.3.256" level="project" />
|
||||
<orderEntry type="library" name="Deps: mvxcvi/arrangement:2.1.0" level="project" />
|
||||
<orderEntry type="library" name="Deps: io.methvin/directory-watcher:0.17.3" level="project" />
|
||||
<orderEntry type="library" name="Deps: progrock:0.1.2" level="project" />
|
||||
<orderEntry type="library" name="Deps: org.clojure/java.classpath:1.0.0" level="project" />
|
||||
<orderEntry type="library" name="Deps: clojure.java-time:1.4.3" level="project" />
|
||||
<orderEntry type="library" name="Deps: org.clojure/core.rrb-vector:0.1.2" level="project" />
|
||||
<orderEntry type="library" name="Deps: net.java.dev.jna/jna:5.12.1" level="project" />
|
||||
<orderEntry type="library" name="Deps: org.clojure/tools.reader:1.3.6" level="project" />
|
||||
<orderEntry type="library" name="Deps: org.tcrawley/dynapath:1.1.0" level="project" />
|
||||
<orderEntry type="library" name="Deps: org.slf4j/slf4j-api:1.7.36" level="project" />
|
||||
<orderEntry type="library" name="Deps: hawk:0.2.11" level="project" />
|
||||
<orderEntry type="library" name="Deps: meta-merge:1.0.0" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
60
deps.edn
60
deps.edn
@@ -1,22 +1,9 @@
|
||||
{:paths ["src" "resources" "target/classes"]
|
||||
:deps {org.clojure/clojure {:mvn/version "1.12.1"}
|
||||
io.github.clojure/tools.build {:mvn/version "0.10.10"}
|
||||
mvxcvi/alphabase {:mvn/version "3.0.185"} ;; https://github.com/greglook/alphabase
|
||||
cli-matic/cli-matic {:mvn/version "0.5.4"} ;; https://github.com/l3nz/cli-matic
|
||||
;; For SQLite
|
||||
com.github.seancorfield/next.jdbc {:mvn/version "1.3.1048"}
|
||||
org.xerial/sqlite-jdbc {:mvn/version "3.50.3.0"}
|
||||
;; For Datomic local
|
||||
com.datomic/local {:mvn/version "1.0.291"};; https://docs.datomic.com/datomic-local.html
|
||||
;; Native image (GraalVM)
|
||||
com.github.clj-easy/graal-build-time {:mvn/version "1.0.5"};; Tutorial: https://shagunagrawal.me/posts/setup-clojure-with-graalvm-for-native-image/
|
||||
;; Protobuf for java
|
||||
com.google.protobuf/protobuf-java {:mvn/version "3.25.8"}
|
||||
;; Progress bar
|
||||
com.github.pmonks/spinner {:mvn/version "2.0.284"}
|
||||
}
|
||||
com.github.clj-easy/graal-build-time {:mvn/version "1.0.5"}}
|
||||
|
||||
:aliases {;; Execute the app
|
||||
:aliases {;; Execute the app. Tutorial: https://shagunagrawal.me/posts/setup-clojure-with-graalvm-for-native-image/
|
||||
:run {:main-opts ["-m" "totp.app"]}
|
||||
|
||||
;; Kaocha runner. You can use the 'kaocha' wrapper located in ~/bin/kaocha
|
||||
@@ -26,5 +13,46 @@
|
||||
|
||||
;; Run with clj -T:build function-in-build
|
||||
:build {:deps {io.github.clojure/tools.build {:mvn/version "0.10.10"}}
|
||||
:ns-default build}}}
|
||||
:ns-default build}
|
||||
|
||||
|
||||
;; COMMON ALIASES FOR ALL PROJECTS
|
||||
:root/run-x {:exec-fn -main}
|
||||
:root/extra-paths [:totp.core/extra-paths
|
||||
:totp.cli/extra-paths
|
||||
:totp.web/extra-paths]
|
||||
|
||||
:root/all {:extra-paths ["src" "resources"
|
||||
:root/extra-paths]}
|
||||
|
||||
:root/test {:extra-paths ["test"]
|
||||
:extra-deps {lambdaisland/kaocha {:mvn/version "1.91.1392"}}
|
||||
:main-opts ["-m" "kaocha.runner"]}
|
||||
|
||||
:boot/build {:extra-paths ["build"]
|
||||
:deps {io.github.clojure/tools.build {:mvn/version "0.10.10"}}
|
||||
:ns-default build
|
||||
;:exec-fn ci
|
||||
;:exec-args {:app-alias :com.example.core}
|
||||
}
|
||||
|
||||
:totp.core/extra-paths ["projects/core/src"
|
||||
"projects/core/test"
|
||||
"projects/core/java"
|
||||
"projects/core/resources"]
|
||||
:totp.core {:ns-default totp.core
|
||||
:main-opts ["-m" "totp.core"]
|
||||
:extra-deps {projects/core {:local/root "projects/core"}}
|
||||
:exec-args {:dirs ["projects/core"]}}
|
||||
|
||||
|
||||
:totp.cli/extra-paths ["projects/app/src"]
|
||||
:totp.cli {:ns-default totp.cli
|
||||
:main-opts ["-m" "totp.cli"]
|
||||
:extra-deps {;; does not use parts/grugstack {:local/root "parts"}
|
||||
projects/cli {:local/root "projects/cli"}}
|
||||
:exec-args {:dirs ["projects/cli"]}}
|
||||
|
||||
:totp.web/extra-paths ["projects/web/src"]
|
||||
}}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ for /f "delims=" %%a in ('dir /b /s target\clj-totp-*-standalone.jar') do @set U
|
||||
echo Created uberjar: %UBERJAR%
|
||||
|
||||
echo "Creating native image"
|
||||
cmd /c %NATIVE% -jar %UBERJAR% -o target\%BIN_FILE% -H:+ReportExceptionStackTraces --features=clj_easy.graal_build_time.InitClojureClasses --report-unsupported-elements-at-runtime --verbose --no-fallback -H:ReflectionConfigurationFiles=reflect_config.json -H:-CheckToolchain
|
||||
cmd /c %NATIVE% -jar %UBERJAR% -o target\%BIN_FILE% -H:+ReportExceptionStackTraces --features=clj_easy.graal_build_time.InitClojureClasses --report-unsupported-elements-at-runtime --verbose --no-fallback -H:ReflectionConfigurationFiles=reflect_config.json -H:-CheckToolchain --initialize-at-build-time=org.fusesource.jansi.Ansi
|
||||
|
||||
|
||||
echo Executable created: target\%BIN_FILE%.exe
|
||||
|
||||
10
native.sh
10
native.sh
@@ -14,9 +14,17 @@ $NATIVE -jar target/$UBERJAR -o target/$BIN_FILE\
|
||||
--verbose --no-fallback\
|
||||
--features=clj_easy.graal_build_time.InitClojureClasses\
|
||||
--report-unsupported-elements-at-runtime\
|
||||
--strict-image-heap\
|
||||
-march=native\
|
||||
-R:MaxHeapSize=10m\
|
||||
--initialize-at-build-time=org.fusesource.jansi.Ansi\
|
||||
#--trace-class-initialization=org.fusesource.jansi.Ansi
|
||||
--initialize-at-build-time='org.fusesource.jansi.Ansi$Color'\
|
||||
--initialize-at-build-time='org.fusesource.jansi.Ansi$Attribute'\
|
||||
'--initialize-at-build-time=org.fusesource.jansi.Ansi$1'
|
||||
|
||||
echo "Executable created on target/$BIN_FILE"
|
||||
cp target/$BIN_FILE ~/bin
|
||||
echo "Copied to ~/bin/$BIN_FILE"
|
||||
|
||||
echo "Compress executable for distribution"
|
||||
xz -fv target/$BIN_FILE
|
||||
|
||||
16
projects/cli/deps.edn
Executable file
16
projects/cli/deps.edn
Executable file
@@ -0,0 +1,16 @@
|
||||
{:paths ["src" "resources" "target/classes"]
|
||||
:deps {clj-totp/core {:local/root "projects/core"}
|
||||
org.clojure/clojure {:mvn/version "1.12.1"}
|
||||
io.github.clojure/tools.build {:mvn/version "0.10.10"}
|
||||
cli-matic/cli-matic {:mvn/version "0.5.4"} ;; https://github.com/l3nz/cli-matic
|
||||
;; Progress bar
|
||||
com.github.pmonks/spinner {:mvn/version "2.0.284"}}
|
||||
|
||||
:aliases {;; Execute the app
|
||||
:run {:main-opts ["-m" "totp.app"]}
|
||||
|
||||
;; Kaocha runner. You can use the 'kaocha' wrapper located in ~/bin/kaocha
|
||||
:test {:extra-paths ["test"]
|
||||
:extra-deps {lambdaisland/kaocha {:mvn/version "1.91.1392"}}
|
||||
:main-opts ["-m" "kaocha.runner"]}}}
|
||||
|
||||
1
projects/cli/tests.edn
Normal file
1
projects/cli/tests.edn
Normal file
@@ -0,0 +1 @@
|
||||
#kaocha/v1 {}
|
||||
1
projects/core/.cpcache/4091673994.basis
Normal file
1
projects/core/.cpcache/4091673994.basis
Normal file
File diff suppressed because one or more lines are too long
1
projects/core/.cpcache/4091673994.cp
Normal file
1
projects/core/.cpcache/4091673994.cp
Normal file
File diff suppressed because one or more lines are too long
1
projects/core/.cpcache/425892293.basis
Normal file
1
projects/core/.cpcache/425892293.basis
Normal file
File diff suppressed because one or more lines are too long
1
projects/core/.cpcache/425892293.cp
Normal file
1
projects/core/.cpcache/425892293.cp
Normal file
File diff suppressed because one or more lines are too long
2
projects/core/.cpcache/425892293.main
Normal file
2
projects/core/.cpcache/425892293.main
Normal file
@@ -0,0 +1,2 @@
|
||||
-m
|
||||
kaocha.runner
|
||||
14
projects/core/deps.edn
Executable file
14
projects/core/deps.edn
Executable file
@@ -0,0 +1,14 @@
|
||||
{:paths ["src" "resources" "target/classes"]
|
||||
:deps {org.clojure/clojure {:mvn/version "1.12.1"}
|
||||
io.github.clojure/tools.build {:mvn/version "0.10.10"}
|
||||
mvxcvi/alphabase {:mvn/version "3.0.185"} ;; https://github.com/greglook/alphabase
|
||||
cli-matic/cli-matic {:mvn/version "0.5.4"} ;; https://github.com/l3nz/cli-matic
|
||||
;; Protobuf for java
|
||||
com.google.protobuf/protobuf-java {:mvn/version "3.25.8"}
|
||||
}
|
||||
|
||||
:aliases {;; Kaocha runner. You can use the 'kaocha' wrapper located in ~/bin/kaocha
|
||||
:test {:extra-paths ["test"]
|
||||
:extra-deps {lambdaisland/kaocha {:mvn/version "1.91.1392"}}
|
||||
:main-opts ["-m" "kaocha.runner"]}}}
|
||||
|
||||
BIN
projects/core/target/classes/alphabase/base32$decode.class
Normal file
BIN
projects/core/target/classes/alphabase/base32$decode.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
projects/core/target/classes/alphabase/base32$decode_STAR_.class
Normal file
BIN
projects/core/target/classes/alphabase/base32$decode_STAR_.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/alphabase/base32$encode.class
Normal file
BIN
projects/core/target/classes/alphabase/base32$encode.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
projects/core/target/classes/alphabase/base32$encode_STAR_.class
Normal file
BIN
projects/core/target/classes/alphabase/base32$encode_STAR_.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/alphabase/base32$fn__170.class
Normal file
BIN
projects/core/target/classes/alphabase/base32$fn__170.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
projects/core/target/classes/alphabase/base32__init.class
Normal file
BIN
projects/core/target/classes/alphabase/base32__init.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/alphabase/base64$decode.class
Normal file
BIN
projects/core/target/classes/alphabase/base64$decode.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/alphabase/base64$encode.class
Normal file
BIN
projects/core/target/classes/alphabase/base64$encode.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/alphabase/base64$fn__230.class
Normal file
BIN
projects/core/target/classes/alphabase/base64$fn__230.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
projects/core/target/classes/alphabase/base64__init.class
Normal file
BIN
projects/core/target/classes/alphabase/base64__init.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/alphabase/bytes$byte_array.class
Normal file
BIN
projects/core/target/classes/alphabase/bytes$byte_array.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/alphabase/bytes$byte_seq.class
Normal file
BIN
projects/core/target/classes/alphabase/bytes$byte_seq.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/alphabase/bytes$bytes_EQ_.class
Normal file
BIN
projects/core/target/classes/alphabase/bytes$bytes_EQ_.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/alphabase/bytes$bytes_QMARK_.class
Normal file
BIN
projects/core/target/classes/alphabase/bytes$bytes_QMARK_.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/alphabase/bytes$compare.class
Normal file
BIN
projects/core/target/classes/alphabase/bytes$compare.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
projects/core/target/classes/alphabase/bytes$concat.class
Normal file
BIN
projects/core/target/classes/alphabase/bytes$concat.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/alphabase/bytes$copy.class
Normal file
BIN
projects/core/target/classes/alphabase/bytes$copy.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/alphabase/bytes$copy_slice.class
Normal file
BIN
projects/core/target/classes/alphabase/bytes$copy_slice.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/alphabase/bytes$fn__144.class
Normal file
BIN
projects/core/target/classes/alphabase/bytes$fn__144.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/alphabase/bytes$from_byte.class
Normal file
BIN
projects/core/target/classes/alphabase/bytes$from_byte.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/alphabase/bytes$from_string.class
Normal file
BIN
projects/core/target/classes/alphabase/bytes$from_string.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/alphabase/bytes$get_byte.class
Normal file
BIN
projects/core/target/classes/alphabase/bytes$get_byte.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/alphabase/bytes$init_bytes.class
Normal file
BIN
projects/core/target/classes/alphabase/bytes$init_bytes.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
projects/core/target/classes/alphabase/bytes$random_bytes.class
Normal file
BIN
projects/core/target/classes/alphabase/bytes$random_bytes.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/alphabase/bytes$set_byte.class
Normal file
BIN
projects/core/target/classes/alphabase/bytes$set_byte.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/alphabase/bytes$to_byte.class
Normal file
BIN
projects/core/target/classes/alphabase/bytes$to_byte.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/alphabase/bytes$to_string.class
Normal file
BIN
projects/core/target/classes/alphabase/bytes$to_string.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/alphabase/bytes__init.class
Normal file
BIN
projects/core/target/classes/alphabase/bytes__init.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/totp/core$bytes__GT_int.class
Normal file
BIN
projects/core/target/classes/totp/core$bytes__GT_int.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/totp/core$bytes_array_QMARK_.class
Normal file
BIN
projects/core/target/classes/totp/core$bytes_array_QMARK_.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/totp/core$fn__195.class
Normal file
BIN
projects/core/target/classes/totp/core$fn__195.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/totp/core$fn__203$fn__204.class
Normal file
BIN
projects/core/target/classes/totp/core$fn__203$fn__204.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/totp/core$fn__203.class
Normal file
BIN
projects/core/target/classes/totp/core$fn__203.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/totp/core$fn__213.class
Normal file
BIN
projects/core/target/classes/totp/core$fn__213.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/totp/core$fn__215.class
Normal file
BIN
projects/core/target/classes/totp/core$fn__215.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/totp/core$fn__219.class
Normal file
BIN
projects/core/target/classes/totp/core$fn__219.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/totp/core$get_alg.class
Normal file
BIN
projects/core/target/classes/totp/core$get_alg.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/totp/core$get_otp.class
Normal file
BIN
projects/core/target/classes/totp/core$get_otp.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
projects/core/target/classes/totp/core$long__GT_bytes.class
Normal file
BIN
projects/core/target/classes/totp/core$long__GT_bytes.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/totp/core$timestamp__GT_steps.class
Normal file
BIN
projects/core/target/classes/totp/core$timestamp__GT_steps.class
Normal file
Binary file not shown.
101
projects/core/target/classes/totp/core.clj
Normal file
101
projects/core/target/classes/totp/core.clj
Normal file
@@ -0,0 +1,101 @@
|
||||
(ns totp.core
|
||||
(:require [alphabase.base32 :as b32]
|
||||
[clojure.math :as m])
|
||||
(:import (javax.crypto Mac)
|
||||
(javax.crypto.spec SecretKeySpec)
|
||||
(java.util Base64 Arrays)
|
||||
(java.nio ByteBuffer)))
|
||||
|
||||
(def ^:private byte-array-type (type (.getBytes "")))
|
||||
|
||||
(defn timestamp->steps
|
||||
"Converts from UNIX timestamp in milliseconds to a number os steps of 's' seconds of duration"
|
||||
[time, step-size]
|
||||
(if (or (nil? time) (nil? step-size) (zero? step-size))
|
||||
0
|
||||
(int (quot time (* 1000 step-size)))))
|
||||
|
||||
|
||||
(defn bytes-array?
|
||||
"Return true if x is a byte[]"
|
||||
[x]
|
||||
(= byte-array-type (type x)))
|
||||
|
||||
|
||||
(defn get-alg
|
||||
[alg]
|
||||
(case alg
|
||||
"sha1" "HmacSHA1"
|
||||
"sha256" "HmacSHA256"
|
||||
"sha512" "HmacSHA512"
|
||||
""))
|
||||
|
||||
|
||||
(defmulti hmac
|
||||
"Generates an HMAC. Algorithms supported: sha1, sha256, sha512.
|
||||
The key and the message can be (both) string or array of bytes, nil otherwise"
|
||||
(fn [algorithm key message]
|
||||
(cond
|
||||
(and (string? key) (string? message) (some? (get-alg algorithm))) :string
|
||||
(and (bytes-array? key) (bytes-array? message) (some? (get-alg algorithm))) :byte
|
||||
:else :nil)))
|
||||
|
||||
;; By default
|
||||
(defmethod hmac :nil [_ _ _]
|
||||
nil)
|
||||
|
||||
;; When key and message are strings
|
||||
(defmethod hmac :string [algorithm key message]
|
||||
(if (or (empty? key) (empty? message))
|
||||
""
|
||||
(let [mac (doto (Mac/getInstance (get-alg algorithm)) (.init (SecretKeySpec. (.getBytes key) (get-alg algorithm))))
|
||||
hmac-bytes (.doFinal mac (.getBytes message))]
|
||||
;; Return the Base64 encoded HMAC
|
||||
(.encodeToString (Base64/getEncoder) hmac-bytes))))
|
||||
|
||||
;; When key and message are arrays of bytes
|
||||
(defmethod hmac :byte [algorithm key message]
|
||||
(if (nil? message)
|
||||
(bytes (byte-array 0))
|
||||
(let [mac (doto (Mac/getInstance (get-alg algorithm)) (.init (SecretKeySpec. key (get-alg algorithm))))
|
||||
hmac-bytes (.doFinal mac message)]
|
||||
;; Return the Base64 encoded HMAC
|
||||
(Base64/getEncoder) hmac-bytes)))
|
||||
|
||||
|
||||
(defn long->bytes
|
||||
"Converts a long to an array of 8 bytes"
|
||||
[l]
|
||||
;;Java equivalent: ByteBuffer.allocate(Long.SIZE / Byte.SIZE).putLong(someLong).array();
|
||||
(when (integer? l)
|
||||
(-> (ByteBuffer/allocate (/ Long/SIZE Byte/SIZE))
|
||||
(.putLong l)
|
||||
(.array))))
|
||||
|
||||
|
||||
(defn bytes->int
|
||||
"Converts an array of 4 bytes to an integer"
|
||||
[bytes]
|
||||
;;Java equivalent: ByteBuffer.wrap(data).getInt()
|
||||
(when (some? bytes)
|
||||
(.getInt (ByteBuffer/wrap bytes))))
|
||||
|
||||
|
||||
(defn get-otp
|
||||
"Generate an OTP with the given secret (in base32) for the specified timestep"
|
||||
([secret algorithm digits period] ;;algorithm digits period
|
||||
(when (and secret period)
|
||||
(let [step (timestamp->steps (System/currentTimeMillis) period)
|
||||
k (b32/decode secret)
|
||||
c (long->bytes step)
|
||||
hs (hmac algorithm k c)
|
||||
offset (bit-and (get hs (dec (count hs))) 0x0f) ;; int offset = hs[hs.length-1] & 0xf;
|
||||
chunk (Arrays/copyOfRange hs offset (+ offset 4)) ;(take 4 (drop offset hs)) ;; byte[] chunk = Arrays.copyOfRange(hs, offset, offset+4)
|
||||
]
|
||||
(format (str "%0" digits "d")
|
||||
(-> chunk
|
||||
(bytes->int)
|
||||
(bit-and 0x7fffffff)
|
||||
(rem (int (m/pow 10 digits))))))))
|
||||
([secret]
|
||||
(get-otp secret "sha1" 6 30)))
|
||||
BIN
projects/core/target/classes/totp/core__init.class
Normal file
BIN
projects/core/target/classes/totp/core__init.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/totp/data$add_app.class
Normal file
BIN
projects/core/target/classes/totp/data$add_app.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/totp/data$create_app.class
Normal file
BIN
projects/core/target/classes/totp/data$create_app.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/totp/data$create_cfg_QMARK_.class
Normal file
BIN
projects/core/target/classes/totp/data$create_cfg_QMARK_.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/totp/data$create_cfg_file.class
Normal file
BIN
projects/core/target/classes/totp/data$create_cfg_file.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/totp/data$delete_app$fn__250.class
Normal file
BIN
projects/core/target/classes/totp/data$delete_app$fn__250.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/totp/data$delete_app.class
Normal file
BIN
projects/core/target/classes/totp/data$delete_app.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/totp/data$exists_config.class
Normal file
BIN
projects/core/target/classes/totp/data$exists_config.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/totp/data$fn__235.class
Normal file
BIN
projects/core/target/classes/totp/data$fn__235.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/totp/data$get_app$fn__260.class
Normal file
BIN
projects/core/target/classes/totp/data$get_app$fn__260.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/totp/data$get_app.class
Normal file
BIN
projects/core/target/classes/totp/data$get_app.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
projects/core/target/classes/totp/data$join_path.class
Normal file
BIN
projects/core/target/classes/totp/data$join_path.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/totp/data$list_apps$fn__256.class
Normal file
BIN
projects/core/target/classes/totp/data$list_apps$fn__256.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/totp/data$list_apps.class
Normal file
BIN
projects/core/target/classes/totp/data$list_apps.class
Normal file
Binary file not shown.
BIN
projects/core/target/classes/totp/data$load_config.class
Normal file
BIN
projects/core/target/classes/totp/data$load_config.class
Normal file
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user