Skip to content
Clojure program to compute your google authenticator OTP using TOTP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
java/src/lockfix 1. Added patch (See java/src/lockfix) to work around the issue - http… May 20, 2019
src/google_authenticator 1. Added patch (See java/src/lockfix) to work around the issue - http… May 20, 2019
Makefile
README.md
project.clj 1. Added patch (See java/src/lockfix) to work around the issue - http… May 20, 2019

README.md

Google Authenticator Tweet

A Clojure program designed to compute your google authenticator otp. I personally use this to automate connecting to VPNs along with apple script. But you could find other use cases where you would want to automate the computation and submission of the OTP.

TOTP

Google authenticator uses Totp (Time based One Time Password) for 2 factor authentication. When you/your app registers with google authenticator, google gives you a shared secret key (could be in the form of QR code). The shared key is a Base32Encoded String that looks like this JBSWY3DPEHPK3PXP

TOTP algorithm computes the Otp by doing a HMAC of the secret key and current time stamp (expressed as steps of 30 seconds from EPOCH). So, the OTP changes every 30 seconds. You can read more about the algorithm here.

Usage (JVM)

This program takes in a file containing your secret key (base32 encoded) as an argument and an optional argument specifying the path of the file where the otp will be written to. If the second argument is not specified it prints the otp to console.

make apply-patch
lein compile
lein uberjar
cd target

Since we are using cli-matic, we can see the ways to run this program by giving

java -jar target/google_authenticator-0.1.0-SNAPSHOT-standalone.jar p --help

You should see an output similar to this

NAME:
 google-authenticator gen-otp - Generates google authenticator otp and prints it to the console

USAGE:
 google-authenticator [gen-otp|p] [command options] [arguments...]

OPTIONS:
   -sk, --secret-key S  Parameter A
   -?, --help

Example 1 - Print OTP on to the console

java -jar target/google_authenticator-0.1.0-SNAPSHOT-standalone.jar p --secret-key j4ok7qmclj23gwa336rrjrv123456789

Example 2 - Read secret key from a file and write otp to a file

java -jar target/google_authenticator-0.1.0-SNAPSHOT-standalone.jar o --secret-key-file-path ~/.secret_key --output-file ~/.otp

Usage (GraalVM)

Please follow the instruction here to generate a native image - https://github.com/BrunoBonacci/graalvm-clojure/blob/master/doc/clojure-graalvm-native-binary.md

Once a native image is generated you can do the following (assuming the name of your native image is google_authenticator)

Example 1 - Print OTP on to the console

./google_authenticator p --secret-key j4ok7qmclj23gwa336rrjrv123456789

Example 2 - Read secret key from a file and write otp to a file

./google_authenticator o --secret-key-file-path ~/.secret_key --output-file ~/.otp
You can’t perform that action at this time.