Plan 9: Password Management

 An authentication server manages users credentials in a Plan 9 grid. However, if you are just getting started, probably it would be a better idea to directly use factotum for managing credentials for various services.

Create a file keys with the following content. 

key proto=pass        service=ftp server=10.0.2.2 user=anand !password=<password>
key proto=wpapsk service=wpa essid=Tomato24 !password=<password>
 

Load the keys in factotum. 

read -m keys > /mnt/factotum/ctl
 
# Verify
cat  /mnt/factotum/ctl
 


Now you can log into the services without manually entering the password.

ftpfs 10.0.2.2
aux/wpa -s Tomato24 /net/ether1 

Finally, you can add the command to $home/lib/profile so that it will be executed automatically during bootup.


If you have the authentication server configured, you can use the following commands to manage your credentials. (Secstore files are stored at "/adm/secstore/user/" on the authserver).

% ramfs -p; cd /tmp
% auth/secstore -vg factotum
secstore password:

# Append new key 
% echo 'key proto=apop dom=x.com user=ehg !password=hi' >> factotum
 
# Verify all the credentials are available
% cat factotum

% auth/secstore -vp factotum
secstore password:

# Load credentials in the current factotum process 
% read -m factotum > /mnt/factotum/ctl
 
# Toggle debug. Log is in /mnt/factotum/log
echo debug > /mnt/factotum/ctl
 

 

Time-Based One-Time Password (TOTP) Authenticator


 Time-Based One-Time Password (TOTP) is increasingly the preferred way for securing accounts with Two-factor authentication. This program allows you to access TOTP using GUI and CLI. Use mouse-2 to copy the code in the GUI.

Note: The demo uses a modified version (notice aux/totp vs auth/totp in 9front).

Sample factotum key: 

key proto=totp role=client label=google secret=JBSWY3DPEHPK3PXP
 

TOTP is time-sensitive. You must keep the time synchronized for codes to work.

aux/timesync -n pool.ntp.org
 

 

Key Formats

  • otpauth://: The official open standard used by almost all TOTP apps for a single secret. e.g. otpauth://totp/{label}?secret={secret}&issuer={issuer}
  • otpauth-migration://offline?data=<base64 string>: A Google authenticator custom protocol that encapsulates multiple secrets into a single string using Google Protocol Buffers (Protobuf) and Base64 encoding.

 

# Export 
aux/totp -e
 
# Import 
aux/totp -i 'otpauth://totp/label1?secret=JBSWY3DPEHPK3PXP&issuer=issuer1'

# Import data from Google authenticator
aux/totpga 'otpauth-migration://offline?data=JBSWY3DPEHPK3PXP'
 

 

Quick Response (QR) code

QR code can be generated using qr command.

echo test | qr | page
 
# Decode
qr -d < p9-image 

  

Code


Lessons Learnt

  1. Secret fields in factotum can only be accessed via RPC. factotum/totp.c and factotum/pass.c are the implementation for password and TOTP respectively.

 

References

  1. utotp code
  2. totp code 
  3. TOTP Algorithm 
  4. QR code standard 
  5. Decode a QR code by hand  

 

Comments

Popular posts from this blog

Plan 9 : The Infinity Notebook

Emacs: Binary File Viewer

Plan 9 Remote File Access from Emacs