Compare commits
11 Commits
6c017b3262
...
v1.2
| Author | SHA1 | Date | |
|---|---|---|---|
| 1b33e18be5 | |||
| 173793caa3 | |||
| 01842dbc8d | |||
| cec35fc16b | |||
| e5fb6e7231 | |||
| 8698e6b57b | |||
| 386d4f7434 | |||
| 82b1407489 | |||
| 5651cc1ab2 | |||
| 96ed6ae1e9 | |||
| d8c3f5ee67 |
@@ -145,11 +145,16 @@ clj-totp.sh import <alias> "<url>"
|
|||||||
- [x] Show several OTPs at once
|
- [x] Show several OTPs at once
|
||||||
|
|
||||||
### v1.2
|
### v1.2
|
||||||
|
- [x] Show progress bar
|
||||||
|
- [x] Styles for progress bar
|
||||||
|
- [x] Native compilation script corrections
|
||||||
|
|
||||||
|
### v2
|
||||||
- [ ] REST API
|
- [ ] REST API
|
||||||
- [ ] User management
|
- [ ] User management
|
||||||
- [ ] Robust BD backend (H2, datomic, or similar)
|
- [ ] Robust BD backend (H2, datomic, or similar)
|
||||||
|
|
||||||
### v1.3
|
### v3
|
||||||
- [ ] Simple web connected to REST API
|
- [ ] Simple web connected to REST API
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
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>
|
|
||||||
6
deps.edn
6
deps.edn
@@ -3,12 +3,6 @@
|
|||||||
io.github.clojure/tools.build {:mvn/version "0.10.10"}
|
io.github.clojure/tools.build {:mvn/version "0.10.10"}
|
||||||
mvxcvi/alphabase {:mvn/version "3.0.185"} ;; https://github.com/greglook/alphabase
|
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
|
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/
|
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
|
;; Protobuf for java
|
||||||
com.google.protobuf/protobuf-java {:mvn/version "3.25.8"}
|
com.google.protobuf/protobuf-java {:mvn/version "3.25.8"}
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
@startuml
|
|
||||||
' configuration
|
|
||||||
skinparam linetype ortho
|
|
||||||
|
|
||||||
entity "user" as user {
|
|
||||||
id: number
|
|
||||||
--
|
|
||||||
login: varchar(64)
|
|
||||||
passw: varchar(512)
|
|
||||||
active: shortint
|
|
||||||
desc: varchar(512)
|
|
||||||
config: varchar(512)
|
|
||||||
}
|
|
||||||
|
|
||||||
entity "app" as app {
|
|
||||||
id: number
|
|
||||||
--
|
|
||||||
name: varchar(32)
|
|
||||||
desc: varchar(512)
|
|
||||||
secret: varchar(512)
|
|
||||||
period: int
|
|
||||||
config: varchar(512)
|
|
||||||
}
|
|
||||||
|
|
||||||
entity "user_app" as user_app {
|
|
||||||
user_id: number
|
|
||||||
app_id: number
|
|
||||||
--
|
|
||||||
}
|
|
||||||
|
|
||||||
user ||--o{ user_app
|
|
||||||
app ||--o{ user_app
|
|
||||||
|
|
||||||
@enduml
|
|
||||||
BIN
doc/db.png
BIN
doc/db.png
Binary file not shown.
|
Before Width: | Height: | Size: 7.9 KiB |
@@ -8,7 +8,14 @@ clojure -T:build uber
|
|||||||
UBERJAR=$(realpath --relative-to=target target/clj-totp-*-standalone.jar)
|
UBERJAR=$(realpath --relative-to=target target/clj-totp-*-standalone.jar)
|
||||||
|
|
||||||
echo "Creating native image"
|
echo "Creating native image"
|
||||||
$NATIVE -jar target/$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
|
$NATIVE -jar target/$UBERJAR -o target/$BIN_FILE\
|
||||||
|
-H:+ReportExceptionStackTraces\
|
||||||
|
-H:ReflectionConfigurationFiles=./reflect_config.json\
|
||||||
|
--verbose --no-fallback\
|
||||||
|
--features=clj_easy.graal_build_time.InitClojureClasses\
|
||||||
|
--report-unsupported-elements-at-runtime\
|
||||||
|
--initialize-at-build-time=org.fusesource.jansi.Ansi\
|
||||||
|
#--trace-class-initialization=org.fusesource.jansi.Ansi
|
||||||
|
|
||||||
echo "Executable created on target/$BIN_FILE"
|
echo "Executable created on target/$BIN_FILE"
|
||||||
cp target/$BIN_FILE ~/bin
|
cp target/$BIN_FILE ~/bin
|
||||||
|
|||||||
@@ -9,17 +9,18 @@
|
|||||||
(:import [java.util TimerTask Timer])
|
(:import [java.util TimerTask Timer])
|
||||||
(:gen-class))
|
(:gen-class))
|
||||||
|
|
||||||
|
(def DEFAULT_BAR_STYLE :coloured-ascii-boxes)
|
||||||
|
|
||||||
(defn print-timer
|
(defn print-timer
|
||||||
([] (print-timer 1 30))
|
([] (print-timer 1 30 DEFAULT_BAR_STYLE))
|
||||||
([start] (print-timer start 30))
|
([bar-style] (print-timer 1 30 bar-style))
|
||||||
([start period]
|
([start period bar-style]
|
||||||
(let [a (atom start)]
|
(let [a (atom start)]
|
||||||
(pd/animate! a :opts {:total period
|
(pd/animate! a :opts {:total period
|
||||||
;:line 1
|
;:line 1
|
||||||
:label "Next TOTP: "
|
:label "Next TOTP: "
|
||||||
;:redraw-rate 60 ;; updates per second
|
;:redraw-rate 60 ;; updates per second
|
||||||
:style (:coloured-ascii-boxes pd/styles)}
|
:style (get pd/styles bar-style)}
|
||||||
;(println)
|
;(println)
|
||||||
(run! (fn [_] (Thread/sleep 1000) (swap! a inc)) (range start (inc period)))
|
(run! (fn [_] (Thread/sleep 1000) (swap! a inc)) (range start (inc period)))
|
||||||
;(println)
|
;(println)
|
||||||
@@ -27,8 +28,8 @@
|
|||||||
|
|
||||||
|
|
||||||
(defn- print-confinuous
|
(defn- print-confinuous
|
||||||
([secret] (print-confinuous secret "sha1" 6 30 true))
|
([secret] (print-confinuous secret "sha1" 6 30 true DEFAULT_BAR_STYLE))
|
||||||
([secret algorithm digits period bar]
|
([secret algorithm digits period bar bar-style]
|
||||||
(let [step-millis (* 1000 period)
|
(let [step-millis (* 1000 period)
|
||||||
now (System/currentTimeMillis)
|
now (System/currentTimeMillis)
|
||||||
delay (int (- step-millis (rem now step-millis)))
|
delay (int (- step-millis (rem now step-millis)))
|
||||||
@@ -39,9 +40,9 @@
|
|||||||
task (proxy [TimerTask] []
|
task (proxy [TimerTask] []
|
||||||
(run [] (println) (fn-show secret)))
|
(run [] (println) (fn-show secret)))
|
||||||
task-bar (proxy [TimerTask] []
|
task-bar (proxy [TimerTask] []
|
||||||
(run [] (print-timer)))
|
(run [] (print-timer bar-style)))
|
||||||
task-init (proxy [TimerTask] []
|
task-init (proxy [TimerTask] []
|
||||||
(run [] (print-timer (- period delay-sec) period)))]
|
(run [] (print-timer (- period delay-sec) period bar-style)))]
|
||||||
(println "\n <Generating continuosly, press enter to stop>\n")
|
(println "\n <Generating continuosly, press enter to stop>\n")
|
||||||
;; (println "Now:" now ", Delay:" delay ", Next execution: " (+ now delay))
|
;; (println "Now:" now ", Delay:" delay ", Next execution: " (+ now delay))
|
||||||
(println "Refresing in" delay-sec "seconds")
|
(println "Refresing in" delay-sec "seconds")
|
||||||
@@ -56,10 +57,10 @@
|
|||||||
|
|
||||||
|
|
||||||
(defn cmd-generate
|
(defn cmd-generate
|
||||||
[& {:keys [secret continuous algorithm digits period bar]}]
|
[& {:keys [secret continuous algorithm digits period bar bar-style]}]
|
||||||
;;(pp/pprint opts)
|
;;(pp/pprint opts)
|
||||||
(if continuous
|
(if continuous
|
||||||
(print-confinuous secret algorithm digits period bar)
|
(print-confinuous secret algorithm digits period bar bar-style)
|
||||||
(println (get-otp secret algorithm digits period))))
|
(println (get-otp secret algorithm digits period))))
|
||||||
|
|
||||||
|
|
||||||
@@ -96,7 +97,7 @@
|
|||||||
|
|
||||||
|
|
||||||
(defn cmd-get-multi
|
(defn cmd-get-multi
|
||||||
[& {:keys [continuous bar _arguments]}]
|
[& {:keys [continuous bar bar-style _arguments]}]
|
||||||
;(pp/pprint opts)
|
;(pp/pprint opts)
|
||||||
(with-config
|
(with-config
|
||||||
(let [apps (filter some? #_{:clj-kondo/ignore [:unresolved-symbol]}
|
(let [apps (filter some? #_{:clj-kondo/ignore [:unresolved-symbol]}
|
||||||
@@ -109,9 +110,9 @@
|
|||||||
delay (int (- step-millis (rem now step-millis)))
|
delay (int (- step-millis (rem now step-millis)))
|
||||||
delay-sec (int (/ delay 1000))
|
delay-sec (int (/ delay 1000))
|
||||||
task-bar (proxy [TimerTask] []
|
task-bar (proxy [TimerTask] []
|
||||||
(run [] (print-timer)))
|
(run [] (print-timer bar-style)))
|
||||||
task-init (proxy [TimerTask] []
|
task-init (proxy [TimerTask] []
|
||||||
(run [] (print-timer (- period delay-sec) period)))]
|
(run [] (print-timer (- period delay-sec) period bar-style)))]
|
||||||
(print-app-continuous period apps)
|
(print-app-continuous period apps)
|
||||||
(when bar
|
(when bar
|
||||||
(. (new Timer) (schedule task-init 0))
|
(. (new Timer) (schedule task-init 0))
|
||||||
@@ -232,7 +233,11 @@
|
|||||||
{:option "bar" :short "b"
|
{:option "bar" :short "b"
|
||||||
:as "Show progress bar"
|
:as "Show progress bar"
|
||||||
:type :with-flag
|
:type :with-flag
|
||||||
:default true}]
|
:default true}
|
||||||
|
{:option "bar-style" :short "s"
|
||||||
|
:as "Progress bar style"
|
||||||
|
:type #{:ascii-basic :ascii-boxes :coloured-ascii-boxes :emoji-circles :emoji-boxes}
|
||||||
|
:default :coloured-ascii-boxes}]
|
||||||
:runs cmd-generate}
|
:runs cmd-generate}
|
||||||
;; Generate a TOTP for a configured app
|
;; Generate a TOTP for a configured app
|
||||||
{:command "get" :short "g"
|
{:command "get" :short "g"
|
||||||
@@ -252,7 +257,11 @@
|
|||||||
{:option "bar" :short "b"
|
{:option "bar" :short "b"
|
||||||
:as "Show progress bar"
|
:as "Show progress bar"
|
||||||
:type :with-flag
|
:type :with-flag
|
||||||
:default true}]
|
:default true}
|
||||||
|
{:option "bar-style" :short "s"
|
||||||
|
:as "Progress bar style"
|
||||||
|
:type #{:ascii-basic :ascii-boxes :coloured-ascii-boxes :emoji-circles :emoji-boxes}
|
||||||
|
:default :coloured-ascii-boxes}]
|
||||||
:runs cmd-get-multi}
|
:runs cmd-get-multi}
|
||||||
;; Check and init your config file
|
;; Check and init your config file
|
||||||
{:command "config" :short "c"
|
{:command "config" :short "c"
|
||||||
|
|||||||
@@ -1,68 +0,0 @@
|
|||||||
(ns totp.db.datomic
|
|
||||||
(:require [totp.data :as data]
|
|
||||||
[datomic.client.api :as d]))
|
|
||||||
|
|
||||||
|
|
||||||
(def cfg-path (data/join-path (System/getProperty "user.home") ".config" "totp"))
|
|
||||||
(def db-path (str cfg-path java.io.File/separator "data"))
|
|
||||||
|
|
||||||
(def cfg {:server-type :datomic-local
|
|
||||||
:system "local-data"
|
|
||||||
:storage-dir db-path})
|
|
||||||
|
|
||||||
(def client (d/client cfg))
|
|
||||||
|
|
||||||
;; Schema for our database
|
|
||||||
|
|
||||||
(def totp-schema [{:db/ident :app/name
|
|
||||||
:db/valueType :db.type/string
|
|
||||||
:db/cardinality :db.cardinality/one
|
|
||||||
:db/unique :db.unique/identity
|
|
||||||
:db/doc "Unique name of the application. Between 2 and 32 chars"
|
|
||||||
:db.attr/preds (fn [s] (<= 3 (count s) 15))}
|
|
||||||
{:db/ident :app/desc
|
|
||||||
:db/valueType :db.type/string
|
|
||||||
:db/cardinality :db.cardinality/one
|
|
||||||
:db/doc "(optional) Description of the application"}
|
|
||||||
{:db/ident :app/secret
|
|
||||||
:db/valueType :db.type/string
|
|
||||||
:db/cardinality :db.cardinality/one
|
|
||||||
:db/doc "Secret BASE32"}
|
|
||||||
{:db/ident :app/period
|
|
||||||
:db/valueType :db.type/long
|
|
||||||
:db/cardinality :db.cardinality/one
|
|
||||||
:db/doc "Time slice in seconds (30 by default)"}
|
|
||||||
{:db/ident :app/config
|
|
||||||
:db/valueType :db.type/string
|
|
||||||
:db/cardinality :db.cardinality/one
|
|
||||||
:db/doc "(Optional) Extra config"}
|
|
||||||
|
|
||||||
{:db/ident :user/login
|
|
||||||
:db/valueType :db.type/string
|
|
||||||
:db/cardinality :db.cardinality/one
|
|
||||||
:db/unique :db.unique/identity
|
|
||||||
:db/doc "Identifier for the user"}
|
|
||||||
{:db/ident :user/passwd
|
|
||||||
:db/valueType :db.type/string
|
|
||||||
:db/cardinality :db.cardinality/one
|
|
||||||
:db/doc "Password"}
|
|
||||||
{:db/ident :user/active
|
|
||||||
:db/valueType :db.type/boolean
|
|
||||||
:db/cardinality :db.cardinality/one
|
|
||||||
:db/doc "Is the user active?"}
|
|
||||||
{:db/ident :user/desc
|
|
||||||
:db/valueType :db.type/string
|
|
||||||
:db/cardinality :db.cardinality/one
|
|
||||||
:db/doc "(Optional) Description of the user"}
|
|
||||||
{:db/ident :user/config
|
|
||||||
:db/valueType :db.type/string
|
|
||||||
:db/cardinality :db.cardinality/one
|
|
||||||
:db/doc "(Optional) Extra config"}
|
|
||||||
{:db/ident :user/apps
|
|
||||||
:db/valueType :db.type/ref
|
|
||||||
:db/cardinality :db.cardinality/many
|
|
||||||
:db/doc "Applications for this user"}])
|
|
||||||
|
|
||||||
(defn init-db
|
|
||||||
[client]
|
|
||||||
(d/create-database client {:db-name "totp"}))
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
(ns totp.db.sqlite
|
|
||||||
(:require [next.jdbc :as jdbc]))
|
|
||||||
|
|
||||||
;; DB configuration
|
|
||||||
(def db {:dbname "totp-data.sqlite"
|
|
||||||
:dbtype "sqlite"})
|
|
||||||
|
|
||||||
;; DB parsed config
|
|
||||||
(def data-source (jdbc/get-datasource db))
|
|
||||||
|
|
||||||
(defn init-db
|
|
||||||
"Create an empty DB"
|
|
||||||
[]
|
|
||||||
(jdbc/execute! data-source ["
|
|
||||||
create table apps (
|
|
||||||
id int auto_increment primary key,
|
|
||||||
name varchar(32),
|
|
||||||
desc varchar(255)
|
|
||||||
)"]))
|
|
||||||
|
|
||||||
(comment
|
|
||||||
(init-db)
|
|
||||||
)
|
|
||||||
BIN
totp-data.sqlite
BIN
totp-data.sqlite
Binary file not shown.
Reference in New Issue
Block a user