How zsrv/supermicro-product-key works
Project Type and Purpose
• This is a Go-based command-line utility (CLI tool) for encoding, decoding, verifying, and brute-forcing Supermicro BMC product keys in three formats: OOB, Non-JSON, and JSON.
• It consists of a set of subcommands (oob, nonjson, json) each implementing key format–specific logic, backed by shared crypto and network helper libraries.
File Structure Analysis
• Top level:
• cmd/ → cobra-style CLI entrypoints and subcommand wiring (root.go, json.go, nonjson.go, oob.go).
• main.go → invokes the cobra command tree.
• pkg/ → reusable packages:
– pkg/build/version.go → versioning info injected at build time.
– pkg/crypto/… → big‐integer arithmetic (assembly + Go) and RSA routines for signatures.
– pkg/net/parse.go, mac.go → MAC‐address parsing, formatting, and brute-force scanning.
– pkg/json/, pkg/nonjson/, pkg/oob/ → format-specific encode/decode/brute-force implementations.
• Configuration & CI:
• .github/workflows/main.yml → GitHub Actions for build/test/release.
• .goreleaser.yaml → goreleaser config for cross-platform binaries.
• Dependencies managed via go.mod/go.sum.
README Insights
• Details usage patterns for each subcommand, key formats, SKU lists, and algorithmic steps.
• Describes how each format binds to a MAC address, what fields are encoded, and signature verification for JSON keys.
• Mentions external consumer (the BMC firmware) that verifies/activates keys.
a. Main Components
• User & CLI Interface: Parses args, displays help/usage.
• Command Dispatcher: Routes to oob/nonjson/json handlers.
• Format Handlers: Each implements:
• Input normalization (MAC, JSON payload).
• Encode/Decode logic.
• Brute-force loop if requested.
• Crypto Engine: BigMod math and RSA signature/verification.
• Network Utility: MAC parsing/generation helpers.
• Build/Version Service: Embeds version metadata.
• CI/CD Pipeline: GitHub Actions + goreleaser producing cross-compiled binaries.
b. Relationships & Data Flow
• User invokes CLI → cobra parser → dispatch to Format Handler.
• Format Handler calls Crypto Engine + Network Utility.
• Crypto Engine may call internal bigmod assembly or RSA code.
• Brute-force loops iterate MAC address candidates via Network Utility → feed into encode/verify functions.
• Output formatted back to CLI (text, JSON).
• Code changes trigger CI pipeline → automated tests → release artifacts.
c. Architectural Patterns
• Modular package separation (single-responsibility for each format).
• Command Pattern via cobra for subcommands.
• Layered approach: CLI layer → application (handlers) → infrastructure (crypto, net).
• Use of internal packages for low-level performance code.
d. Key Technologies & Libraries
• Go and go-modules for dependency management.
• Cobra (implied) for CLI command wiring.
• Assembly and pure-Go big integer math in pkg/crypto/internal/bigmod.
• RSA routines in pkg/crypto/rsa.
• goreleaser for artifact publishing.
• GitHub Actions for CI.