Repository navigation
feat(consensus/keys): pure-Go key-generation core - #1196
Open
leninmehedy wants to merge 1 commit into
Open
leninmehedy wants to merge 1 commit into
leninmehedy wants to merge 1 commit into
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
leninmehedy
force-pushed
the
01165-consensus-keys-core
branch
from
September 29, 2026 05:12
a26c054 to
89a8526
Compare
leninmehedy
force-pushed
the
01165-consensus-keys-core
branch
3 times, most recently
from
October 13, 2026 11:05
bd46dd5 to
734373a
Compare
leninmehedy
marked this pull request as draft
October 20, 2026 06:23
radkomih
reviewed
Oct 20, 2026
leninmehedy
force-pushed
the
01165-consensus-keys-core
branch
3 times, most recently
from
October 21, 2026 05:18
0874f96 to
9f6e7a7
Compare
Add pkg/consensus/keys, the foundation crypto library for the `consensus node keys` command family (epic #1164): - GenerateGossipKey: RSA-3072 self-signed X.509 (SHA384WithRSA), CN=machine-UUID, optional identity in OU/SAN — the gossip network identity, decoupled from node-id (fits the DAB join flow). - GenerateGrpcKey: self-signed CN=localhost TLS cert; CertHashSHA384 exposes the roster grpc_certificate_hash, a SHA-384 over the PEM-encoded certificate as node_create requires (not over the DER). - Enhanced-PEM encode/parse helpers and a host MachineUUID resolver. - All randomness via crypto/rand (never a deterministic RNG). The node admin key is not generated here: it is created in an external wallet and only its public key is provided to the provisioner. Foundation for #1166 generate, #1167 import/export, #1168 verify, #1195 init. Refs #1165 Signed-off-by: Lenin Mehedy <lenin.mehedy@hashgraph.com>
radkomih
force-pushed
the
01165-consensus-keys-core
branch
from
November 4, 2026 12:20
9f6e7a7 to
ffb8389
Compare
radkomih
marked this pull request as ready for review
November 4, 2026 13:07
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.
Summary
First PR in the stacked series for epic #1164 — Consensus Node Key & Secret Management.
Adds
pkg/consensus/keys, the pure-Go cryptographic core that theconsensus node keyscommand family builds on. No CLI surface yet — this is the foundation (#1165);generate/import/export/verify/initland in the stacked PRs above it.What's in it
GenerateGossipKey— RSA-3072, self-signed X.509 withSHA384WithRSA,CN=<machine-UUID>and an optional human--identitylabel in OU/SAN. This is the node's long-lived gossip identity (rostergossip_ca_certificate), deliberately decoupled from the node-id so it can be generated before the network assigns one during a DAB join. The EC agreement key is auto-derived by the platform at boot and is not produced here.GenerateGrpcKey(GrpcOptions)— self-signed TLS cert,CN=localhostby default.GrpcOptionsoptionally sets the subject CN and O (free text, up to 64 characters, no control characters), adds DNS/IP SANs on top of the always-presentlocalhost,127.0.0.1, and::1, and sets the lifetime in days (1-36500; default 100 years). The gossip cert lifetime stays fixed at 100 years. HAProxy terminates client TLS with its own cert and re-encrypts to the node withssl verify none, so this cert is never hostname/CA-validated; only its SHA-384 hash matters.CertHashSHA384exposes the rostergrpc_certificate_hash: a SHA-384 over the certificate in PEM form (UTF-8 bytes), asnode_createrequires, not over the DER. It equalsopenssl dgst -sha384over the.crtfile.CertPEMHashSHA384(cert)is exported so other packages hash a parsed certificate the same way.ParsePrivateKeyPEM, PKCS#8 for the RSA keys, andParseCertificatePEM) and a hostMachineUUID()resolver, for the upcoming import/verify verbs.crypto/rand— never a deterministic RNG (the hiero reference generator uses one for tests; that must not be copied).Dependencies
None added. Generation uses only the Go standard library.
Testing
go test -race -cover ./pkg/consensus/keys/— passes, 82% statement coverage. Behavioral contracts covered: key formats & sizes, CN rules, cert hash (PEM, not DER), PEM round-trip for the RSA keys, non-determinism (distinct keys across calls), wrong-block-type rejection, and host machine-id resolution. The uncovered remainder is unreachable error branches (rand/marshal failures).Files
pkg/consensus/keys/keys.gopkg/consensus/keys/gossip.goGenerateGossipKeypkg/consensus/keys/grpc.goGenerateGrpcKeyandGrpcOptionspkg/consensus/keys/machineid.goMachineUUID()resolverpkg/consensus/keys/pem.goParsePrivateKeyPEM/ParseCertificatePEMpkg/consensus/keys/keys_test.goCloses #1165.