Skip to content

k3karthic/totp-generator-web

Repository files navigation

TOTP Web Generator

Generate TOTP codes right from your browser for Two-Factor Authentication (2FA). Compatible with authenticator applications like Google Authenticator, Authy and Microsoft Authenticator.

Demo,

Application Screenshot

Design

The application only uses the JavaScript APIs provided by the browser. It consists of only a single HTML file, which allows it to work offline by running it from disk. The design allows it to work without installation and in environments like Tails.

Assumption: Possible to input the TOTP key into the web application's input field. (e.g, Copy/Paste or Manual typing using a hardware/virtual keyboard based on the threat model).

Settings

The default settings are compatible with Google Authenticator,

  • HMAC Algorithm: SHA-1
  • Period: 30 seconds
  • Digits: 6

Use the “Advanced Options” menu to change the above values.

The application supports secret keys in the following formats,

  • Base32 (case-insensitive) — e.g, XY7MXDNK5ZEKJT4Y or xy7mxdnk5zekjt4y
  • Base32 with spaces (case-insensitive) — e.g, g5od kqdo hqkd 4kup qr2d txc2 2cfh wylh

Web Technologies Used

  1. Web Crypto — Used to calculate the HMAC. Browser Support.
  2. Uint8Array — Used to store and process binary data according to RFC 6238 (TOTP) and RFC 4226 (HOTP). Browser Support.
  3. Async/Await — Easier to work with promises. Browser Support.
  4. Custom Elements — Build the UI out of components without a JavaScript framework. Browser Support.

Development

Tools

Content Security Policy whitelists assets (e.g, JavaScript, CSS) by their SHA-256 hash. A minimal build tool (watch.js) updates the CSP hashes. A meta tag is the preferred method of policy configuration as Netlify and CloudFlare host the site.

Use the following command to start the build tool which watches for changes to src/index.html,

$ npm run watch

Use the following command to start live-server,

$ npm run start

Environment

Get started working on this repository from your browser using Gitpod. Click on the button below to create a GitPod environment,

Open in Gitpod

Code Mirrors

Deployment

Development happens on the devel branch and merged with main for a release. A GitHub build hook pushes a new version for every update of the main branch using the contents of the dist folder.

Use the following command to update the dist folder. The command removes CSP configurations which are only required for development.

$ npm run build

Acknowledgements

References used during development,