Git Product home page Git Product logo

google-authenticator's Introduction

Google Authenticator Tweet

A Clojure program 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://www.graalvm.org/docs/reference-manual/native-image/

Commands executed to generate native image via GraalVM-19.2.1

  1. Download graalvm-19.2.1

  2. Install native image component by executing

    gu install native-image

  3. Copy the standalone jar generated by lein uberjar to the bin directory inside graalvm.

  4. Run the following command to generate a native image (assuming your jar is named google_authenticator.jar)

./native-image --report-unsupported-elements-at-runtime --initialize-at-build-time -jar google_authenticator.jar -H:Name=google_authenticator --no-fallback --enable-all-security-services

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

google-authenticator's People

Contributors

ashwinbhaskar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

google-authenticator's Issues

"Algorithm HmacSHA1 not available" when running the Native Image produced by GraalVM

After the fix mentioned in the comments in #1, the start up time is very fast. But there is a JVM exception thrown when trying to calculate the OTP :

** ERROR: **
JVM Exception: #error {
 :cause Algorithm HmacSHA1 not available
 :via
 [{:type java.security.NoSuchAlgorithmException
   :message Algorithm HmacSHA1 not available
   :at [javax.crypto.Mac getInstance Mac.java 181]}]
 :trace
 [[javax.crypto.Mac getInstance Mac.java 181]
  [google_authenticator.core$hmac invokeStatic core.clj 39]
  [google_authenticator.core$hmac invoke core.clj 35]
  [google_authenticator.core$get_hmac invokeStatic core.clj 68]
  [google_authenticator.core$get_hmac invoke core.clj 68]
  [google_authenticator.core$get_otp invokeStatic core.clj 82]
  [google_authenticator.core$get_otp invoke core.clj 81]
  [google_authenticator.core$print_otp invokeStatic core.clj 94]
  [google_authenticator.core$print_otp invoke core.clj 93]
  [cli_matic.core$invoke_subcmd invokeStatic core.clj 797]
  [cli_matic.core$invoke_subcmd invoke core.clj 785]
  [cli_matic.core$run_cmd_STAR_ invokeStatic core.clj 831]
  [cli_matic.core$run_cmd_STAR_ invoke core.clj 817]
  [cli_matic.core$run_cmd invokeStatic core.clj 841]
  [cli_matic.core$run_cmd invoke core.clj 833]
  [google_authenticator.core$_main invokeStatic core.clj 122]
  [google_authenticator.core$_main doInvoke core.clj 117]
  [clojure.lang.RestFn applyTo RestFn.java 137]
  [google_authenticator.core main nil -1]]}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.