Add 2fa: Zig port of rsc/2fa two-factor authentication agent#67
Open
Add 2fa: Zig port of rsc/2fa two-factor authentication agent#67
Conversation
Co-authored-by: jiacai2050 <3848910+jiacai2050@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add 2fa port feature
Add 2fa: Zig port of rsc/2fa two-factor authentication agent
Mar 16, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a new 2fa binary — a Zig port of rsc/2fa — implementing a CLI tool for managing TOTP/HOTP two-factor authentication codes stored in ~/.2fa. It includes base32 decoding, HOTP/TOTP computation, keychain file I/O, clipboard support, and unit tests.
Changes:
- New
src/bin/2fa.zigimplementing the full 2FA CLI (add, list, show codes with optional clipboard copy). - Registration of the
2fabinary inbuild.zig'sbuildBinaries()list. - 9 unit tests covering base32 decoding, HOTP vectors, code formatting, keychain parsing, and type-string generation.
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/bin/2fa.zig |
New binary implementing TOTP/HOTP 2FA agent with CLI, keychain file management, and tests. |
build.zig |
Adds "2fa" to the binary list so it gets run-, install-, and test- build steps. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Owner
|
@copilot fix conflict. |
…lot/add-2fa-port # Conflicts: # build.zig
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ports rsc/2fa to Zig as a new
src/bin/2fa.zigbinary — a CLI tool for managing TOTP/HOTP two-factor authentication codes stored in~/.2fa.Algorithms
std.crypto.auth.hmac.HmacSha1⌊unix_time / 30⌋CLI
Short flags:
-a/-l/-c/-7/-8/-tKeychain format (
~/.2fa)Compatible with rsc/2fa's file format:
Lines:
name [7|8]totp|[7|8]hotp base32secret [counter]. HOTP counter is incremented and persisted on each code display.Tests
9 unit tests covering RFC 4648 base32 vectors, all 10 RFC 4226 Appendix D HOTP vectors, zero-padded code formatting, keychain parsing, and
keyTypeString.Build
Added
"2fa"tobuildBinaries()inbuild.zig, wiring uprun-2fa,install-2fa, andtest-2fasteps.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
cs.opensource.google/home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js(dns block)ziglang.org/usr/bin/curl curl -s REDACTED -o /tmp/zig.tar.xz --max-time 60(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.