Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5651cc1ab2 | |||
| 96ed6ae1e9 | |||
| d8c3f5ee67 |
53
README.md
53
README.md
@@ -1,40 +1,55 @@
|
||||
# clj-totp
|
||||
|
||||
TOTP (Time-based One Time Password) in clojure. It can be used in the command line, web API o simple embedded web.
|
||||
TOTP (Timebased One Time Password) in clojure. It can be used in the command line, web API o simple embeded web.
|
||||
|
||||
## What is TOPT
|
||||
|
||||
The TOPT is a standard used to generate a time-based password. Usually, this password is used as a second
|
||||
The TOPT is an standad used to generate a time-based password. Usually, this password is used as a second
|
||||
factor authentication.
|
||||
|
||||
You can read more about the algorithm here:
|
||||
You can red more about the algorith here:
|
||||
|
||||
- Wikipedia: https://en.wikipedia.org/wiki/Time-based_one-time_password
|
||||
- TOTP RFC: https://web.archive.org/web/20110711124823/http://tools.ietf.org/html/rfc6238
|
||||
- HOTP RFC: https://www.ietf.org/rfc/rfc4226.txt
|
||||
|
||||
|
||||
## The inside
|
||||
|
||||
This project is done 100% in clojure. It uses `deps.edn` for configuring the project and `build.clj` for compiling.
|
||||
This project is done 100% in clojure. It uses `deps.edn` for configuring the project.
|
||||
|
||||
## Implementation timeline
|
||||
## Features
|
||||
|
||||
### v1.0
|
||||
- [x] Functional TOTP generation
|
||||
- [x] Get TOTP from command line
|
||||
- [x] Continuous generation
|
||||
- [ ] Store configuration in a properties file or simple DB
|
||||
- Functional TOTP generation
|
||||
- Get TOTP from command line
|
||||
- Continuous update every 30 seconds
|
||||
|
||||
### v1.1
|
||||
- [ ] REST API
|
||||
- [ ] User management
|
||||
- [ ] Robust BD backend (H2, datomic, or similar)
|
||||
## Usage
|
||||
You can use the `clojure` command to run the program:
|
||||
```
|
||||
clojure -M:run <params>
|
||||
```
|
||||
|
||||
### v1.2
|
||||
- [ ] Simple web connected to REST API
|
||||
If you prefer using the distributed jar:
|
||||
```
|
||||
java -jar clj-topt-1.0.35-standalone.jar <params>
|
||||
```
|
||||
|
||||
## Ideas
|
||||
- Import from google auth URL: https://github.com/dim13/otpauth
|
||||
- Store passwords securely: https://github.com/weavejester/crypto-password
|
||||
You can use the binary (compiled with GraalVM) in linux environments:
|
||||
```
|
||||
totp <params>
|
||||
```
|
||||
|
||||
All three methods are equivalent.
|
||||
|
||||
### Generate a single TOTP
|
||||
You can simple run:
|
||||
```
|
||||
totp generate <secret in BASE32>
|
||||
```
|
||||
|
||||
If want to update coninously the generated TOTP, you cand add the `-s` param:
|
||||
```
|
||||
totp generate <secret in BASE32> -s
|
||||
```
|
||||
|
||||
|
||||
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>
|
||||
5
deps.edn
5
deps.edn
@@ -3,11 +3,6 @@
|
||||
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/
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
(ns totp.app
|
||||
(:require [totp.core :refer :all]
|
||||
[totp.data :refer :all]
|
||||
[cli-matic.core :refer [run-cmd]]
|
||||
[cli-matic.utils :as U]
|
||||
[clojure.pprint :as pp])
|
||||
@@ -39,13 +38,15 @@
|
||||
|
||||
(def cli-options
|
||||
{:app {:command "totp"
|
||||
:version "1.0.0"
|
||||
:version "1.0"
|
||||
:description ["Generate a TOTP"]}
|
||||
|
||||
:commands [{:command "generate" :short "g"
|
||||
:description "Generate one TOTP with a given secret in BASE32"
|
||||
:examples ["totp generate \"MJXW42LBORXQ====\""
|
||||
"totp g \"MJXW42LBORXQ====\""]
|
||||
:examples ["Generate one TOTP and exit:"
|
||||
" totp generate \"MJXW42LBORXQ====\""
|
||||
"Generate one TOTP, update each 30 seconds:"
|
||||
" totp g -c \"MJXW42LBORXQ====\""]
|
||||
:opts [{:option "secret"
|
||||
:short 0
|
||||
:as "Secret codified in BASE32"
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
(ns totp.db.datomic
|
||||
(:require [datomic.client.api :as d]))
|
||||
|
||||
(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