farmfa

command module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2026 License: Apache-2.0 Imports: 2 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README ¶

farMFA

Secure, distributed Multi-Factor Authentication system based on TOTP and Shamir's Secret Sharing.

License
Go Report Card
PkgGoDev

🚧 DISCLAIMER 🚧

WIP! farMFA is still in development and may not be suitable for production use.

under contruction GIF from the 90s

The user experience is terrible, the code is not tested, and the documentation is incomplete.

It's here for Umarells as myself, who like to take a look at half-baked projects.

I believe you can trust the decryption to work in the future, as it's based on the age encryption tool. So it's unlikely that your secrets will be lost or leaked.

You may also trust the Shamir's Secret Sharing implementation, as it's coming from the HashiCorp Vault project.

However, if you do feel like using this tool right now, please keep a copy of the code and the encrypted secrets in a safe place.

💡 Concept

a desk with a six-digit combination lock on it, a clock, and pieces of papers with random ASCII strings on them

Multi-Factor Authentication (MFA) is often implemented using the TOTP standard (RFC6238) from OATH.

  1. The authentication server generates a secret key, stores it, and shows it to the user as a QR code or a Base32 string. The user stores it in a mobile app or password manager.
  2. Upon login, the user inputs a One-Time Password (OTP). The authenticator app or password manager generates this password by applying the TOTP algorithm to the secret key and the current time.
  3. The authentication server performs the same algorithm on the secret key and current time. If the output matches the user’s TOTP, the authentication is successful.

The generated One-Time Password may only be used once, or within a certain timeframe, depending on the server implementation.

farMFA is designed for shared environments where access to certain accounts should be restricted to very special occasions, such as accessing the root user of an AWS account. The goal is to restrict access so that multiple individuals are needed to grant authorization.

First, we apply the Shamir’s Secret Sharing scheme (Shamir 1979) to the original TOTP secret key. For instance, at least 3 out of 5 holders must combine their shares to reconstruct the secret.

Additionally, farMFA implements a workflow to reassemble the TOTP secret on a server, allowing users to access only the generated TOTP code without risking accidental leaks of the secret.

🚀 Getting Started

The two main workflows are:

  1. Getting the TOTP secret, splitting it, and sharing it with multiple parties (players). This is done locally.
  2. Combining the shares (Tocs) and generating the TOTP. This is done by the server/oracle.
Split TOTP Secret and Share

a diagram of the initial phase where TOTP secrets are split

During this phase, farMFA encrypts the Tocs based on the intended recipient (player). The current encryption strategy uses age.

Each player generates their age keypair via age-keygen:

age-keygen -o player_1.txt

# And if you're now testing by yourself, generate a few more keys
age-keygen -o player_2.txt
age-keygen -o player_3.txt

Players then share their public key with the dealer.

The dealer starts the process, usually providing their own age public key and keeping one Toc for themselves. The TOTP secret is read from standard input (or FARMFA_TOTP_SECRET), so it doesn't end up in your shell history:

farmfa dealer --threshold 2 \
  -p player_1=age1ct885ya9458q63ea6fdl42ajl3rpkasj45c5hkkp5ccpf7c80cssk688fr \
  -p player_2=age1emv0n3j90658ke68ktrl7ne9w5gqwrcuetww5ac5rhdkeg638ykqg7uuhd \
  -p player_3=age1rl2ranstxv2dd8pmamvwukz35zrcv9p3knthp0kal3q47gyyea5qk0cl4q \
  > tocs.json
TOTP secret: HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ

This generates encrypted Tocs, one per player, as a JSON object:

{
  "player_1": "-----BEGIN AGE ENCRYPTED FILE-----\nYWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSAvQ1R3YUJPdWlnajRlSjV2...",
  "player_2": "-----BEGIN AGE ENCRYPTED FILE-----\n...",
  "player_3": "-----BEGIN AGE ENCRYPTED FILE-----\n..."
}

Each player then receives their encrypted Toc, and decrypts and inspects it using the age CLI:

jq -r .player_1 tocs.json > player_1.age  # done by the dealer, before sending it to player_1
age -i player_1.txt --decrypt player_1.age

{"group_id":"I5QROLFXIB7PQGLNWSQSYLCZ6M","group_key":"7Uresn0bxGI6sB1pOE9wGl6k/v2HyNPdEqGyb7/MksE=","group_size":3,"group_threshold":2,"note":"","share":"tDR7Jbitg8INjAzSEysgGoaP3KaLHDz/xAlFkJodGNau","signature":"quCWb93pgwDVedaLb4qS1/HGmS2IeIpBpPI/0THLWJ+qukFGZyjH2pB4nUPS0PaPKSNmS4gWm5B0cB2SNLf5Dw==","toc_id":"bMcAIIAFzQfFO/b4dLXH1GCMgmOT1M/r/9e8"}

Players must store their Toc securely.

Each Toc carries the dealer's signature (group_key and signature): the dealer signs every Toc of a group with a key generated for that deal, then discards it. The oracle ignores Tocs that are not signed with the same key as the Toc that started a session, so nobody can break a session with a forged Toc. Tocs dealt by older versions of farMFA have no signature: deal them again to get this protection.

Generate a TOTP

a diagram showing the TOTP code generation phase

When a user wants to log in, they start a session. The user initiating the login is called the applicant.

# For testing purposes, we'll now start the server locally - in production, this should be a remote server
farmfa server &
# Point the CLI at the oracle (the default is http://localhost:8080)
export FARMFA_ADDRESS=http://localhost:8080

age -i player_1.txt --decrypt player_1.age | farmfa session start > session.json
cat session.json
{
  "complete": false,
  "created_at": "2026-11-28T10:18:50.438007+01:00",
  "expires_at": "2026-11-28T11:18:50.438007+01:00",
  "id": "3XZVIOFXHLTJ67FLFZMRDC7KTV",
  "kek": "X3xRPZaWtHQ/MCRTxwVrvcko3umlwRrbyM1XbK1YGbp3HgnEGwfoYNxm6oVlgTx52KmbKeOgI+QuY64pDo4s+ks273C+SDytvjY=",
  "tek": "age12c2zmuuwe8wj78jt2a5wltc43av0ky34fwrhauxrcssqna46sqfq549l4r",
  "toc_group_id": "I5QROLFXIB7PQGLNWSQSYLCZ6M",
  "toc_group_key": "7Uresn0bxGI6sB1pOE9wGl6k/v2HyNPdEqGyb7/MksE=",
  "tocs_in_group": 3,
  "tocs_provided": 1,
  "tocs_threshold": 2,
  "ttl": 60
}

The oracle returns:

  • A session ID.
  • A Toc Encryption Key (TEK) - a public key to encrypt individual Tocs.
  • A Key Encryption Key (KEK) - to decrypt the private part of the TEK. Keep session.json secret.

A session expires after one hour, or ttl seconds after the first TOTP is generated (farmfa session start --ttl), whichever comes first.

The applicant shares the session ID and TEK with team members holding the other Tocs. These team members, who can authorize the applicant, are called constituents.

Constituents join the session with their Toc. farMFA encrypts it with the TEK before uploading it to the oracle:

age -i player_2.txt --decrypt player_2.age | farmfa session join 3XZVIOFXHLTJ67FLFZMRDC7KTV age12c2zmuuwe8wj78jt2a5wltc43av0ky34fwrhauxrcssqna46sqfq549l4r
Joined session 3XZVIOFXHLTJ67FLFZMRDC7KTV

Anyone can check how many Tocs a session has with farmfa session status 3XZVIOFXHLTJ67FLFZMRDC7KTV.

Once the oracle has enough Tocs, the applicant generates the TOTP. The CLI sends the KEK from session.json, so the oracle can decrypt the Tocs:

farmfa session totp session.json
{
  "session_expires_at": "2026-11-28T10:19:50.507076+01:00",
  "totp": "501848",
  "totp_expires_at": "2026-11-28T10:19:00+01:00"
}

📖 References

  • RFC6238: M’Raihi, D., Machani, S., Pei, M., and J. Rydell, "TOTP: Time-Based One-Time Password Algorithm", RFC 6238, DOI 10.17487/RFC6238, May 2011.
  • Shamir's Secret Sharing: Adi Shamir. 1979. "How to share a secret". Commun. ACM 22, 11 (Nov. 1979), 612–613.

🔠 Glossary

  • Secret: A TOTP is a hash generated from a secret. This secret is usually shown as a QR code and shared between the prover and verifier. In farMFA, the prover is distributed among recipients who share the key material and an oracle that generates the TOTP.
  • Toc: The "pieces" in which a TOTP secret gets split.
  • Deal: The workflow in which a dealer splits a secret into Tocs and shares them with multiple players.
  • Dealer: Creates Tocs from a secret and shares them with players.
  • Player: Individuals who receive one of the Tocs during the Tocs creation phase.
  • Session: The workflow in which an applicant requires combining Tocs to generate a TOTP.
  • Applicant: Initiates a session to request access to a TOTP.
  • Constituent: Individuals who join a session to authorize an applicant to generate a TOTP by reaching a quorum/threshold.
  • Oracle: The entity that reconstructs Tocs into TOTP secrets and generates one-time passwords. Also called the prover, as defined in RFC6238.
  • Server: Synonym for oracle in this context.
  • TOTP: As defined in RFC6238: "an extension of the One-Time Password (OTP) algorithm to support the time-based moving factor". Used by many applications as a second authentication factor.

Documentation ¶

The Go Gopher

There is no documentation for this package.

Directories ¶

Path Synopsis
Package api provides primitives to interact with the openapi HTTP API.
Package api provides primitives to interact with the openapi HTTP API.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL