go>> g>> 返回
项目作者: unix4fun

项目描述 :
A Simple "google authenticator" / TOTP client tool
高级语言: Go
项目地址: git://github.com/unix4fun/g.git
创建时间: 2018-07-26T15:18:50Z
项目社区:https://github.com/unix4fun/g

开源协议:BSD 3-Clause "New" or "Revised" License

下载


g

A Simple “google authenticator” / TOTP client tool

Purpose

a simple TOTP / google authenticator client.
it will generate TOTP tokens for the configured accounts and secure data at rest.

WARNING
This is a project in development, some trivial backup/rollback strategies are being implemented,
but it seems reliable enough that i use it everyday on various accounts.

Installation

make sure you have a properly installed golang and $GOPATH etc..
then :

  1. $ go get github.com/unix4fun/g
  2. $ g -h
  3. Usage of g:
  4. -add string
  5. add entry <name>
  6. -dec
  7. decrypt PEM file and output on stdout
  8. -digit int
  9. TOTP token size (valid: {6,7,8}) (default 6)
  10. -enc
  11. encrypt PEM file and output on stdout
  12. -hmac string
  13. TOTP hmac function (valid {sha1|sha256|sha512}) (default: sha1) (default "sha1")
  14. -init
  15. initialize the PEM file (will truncate if existing)
  16. -pass
  17. update PEM file password
  18. -pem string
  19. PEM filename to use (default "/home/rival/.config/g.pem")
  20. -period int
  21. TOTP window (default: 30) (default 30)
  22. -qr string
  23. scan & add from QRcode image file
  24. -rm string
  25. remove entry <name>
  26. -sec string
  27. TOTP shared secret (valid: len>0)
  28. -upd string
  29. update entry <name>

Usage

the default secret storage lies in ~/.config/g.pem but you can ALWAYS give the pem file you want to operate on by using:

  1. ... -pem <pemfile>

Initialize Secret Storage

to access your tokens, you will be asked your password/passphrase whatever..

  1. $ g -init
  2. Init Password: <type your password>
  3. Retype Init Password: <type your password again>

Add Entry with QrCode

Save the QRcode PNG file then thanks to an external qrdecoding module we can read QR code directly,
note that it has not been extensively tested yet.

  1. $ g -qr /path/to/qrcode.png
  2. qr code add: /path/to/qrcode.png
  3. Password:

Add Entry Manually

like you’re setting up your 2FA for your gmail account.
WARNING
Remember if you have an history file, THIS WILL BE IN YOUR HISTORY.
Most shells allows to execute a command without being history logged check your shell documentation.

Example, for now with bash, you can tell history to NOT log this command:

  1. export HISTIGNORE="g *"

or setup a no history space prefix like :

  1. export HISTCONTROL=ignorespace

and prefix your commands for token by a space.

This might be the reason for a format/editing change later.

  1. $ g -add gmail -sec <google 2fa secret>
  2. Password:
  3. .. debug message to say it's ok...

Get Tokens

  1. $ g
  2. Password:
  3. account | totp
  4. ---------- | ----
  5. gmail | 357119
  6. [== ] TTL

now you can add all your tokens one by one when necessary.
tokens by default adopts google authenticator baseline (sha1 / 6 digits)

but some services provides even higher baseline, like sha256 / 8 digits token, which is also supported:

  1. $ g -add patatra -sec <my secret> -hmac sha256 -digit 8
  2. ...
  3. $ g
  4. Password:
  5. account | totp
  6. ---------- | ----
  7. gmail | 707792
  8. patatra | 71997833
  9. [========= ] TTL

Data at rest

token config are in a JSON format encrypted using PEMAEAD
you can decrypt them at any moment to peek if necessary and re-encrypt a payload as necessary too

  1. $ g -dec
  2. Password:
  3. {
  4. "gmail": {
  5. "secret": "proutpro",
  6. "hash": "sha1",
  7. "digit": 6
  8. },
  9. "patatra": {
  10. "secret": "geonimo",
  11. "hash": "sha256",
  12. "digit": 8
  13. }
  14. }

No particular reason for using JSON, i guess i was brainwashed by the whole JSON crap craze everywhere instead of using a simpler format (CSV?), which mean i might move to a simpler format later, but the tool will manage to handle backward compatibility so don’t worry.

TODO

  • remove debug messages.
  • might move the secret input as a terminal input instead of command line (to avoid people leave their history full of secret)
  • cleaner CLI.
  • rewrite help messages.
  • implement unit test everywhere.
  • implement QR code reader (from jpg)