{"record":{"id":"7dc33627ed48423d","repo":"slackhq/nebula","slug":"error-while-generating-ecdsa-keys-s","errorCode":null,"errorMessage":"error while generating ecdsa keys: %s","messagePattern":"error while generating ecdsa keys: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/nebula-cert/ca.go","lineNumber":284,"sourceCode":"\t\t\treturn fmt.Errorf(\"error while getting public key with PKCS#11: %w\", err)\n\t\t}\n\t} else {\n\t\tswitch *cf.curve {\n\t\tcase \"25519\", \"X25519\", \"Curve25519\", \"CURVE25519\":\n\t\t\tif fips140.Enforced() {\n\t\t\t\treturn errors.New(\"use of Curve25519 is not allowed in FIPS 140-only mode\")\n\t\t\t}\n\t\t\tcurve = cert.Curve_CURVE25519\n\t\t\tpub, rawPriv, err = ed25519.GenerateKey(rand.Reader)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"error while generating ed25519 keys: %s\", err)\n\t\t\t}\n\t\tcase \"P256\":\n\t\t\tvar key *ecdsa.PrivateKey\n\t\t\tcurve = cert.Curve_P256\n\t\t\tkey, err = ecdsa.GenerateKey(elliptic.P256(), rand.Reader)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"error while generating ecdsa keys: %s\", err)\n\t\t\t}\n\n\t\t\t// ecdh.PrivateKey lets us get at the encoded bytes, even though\n\t\t\t// we aren't using ECDH here.\n\t\t\teKey, err := key.ECDH()\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"error while converting ecdsa key: %s\", err)\n\t\t\t}\n\t\t\trawPriv = eKey.Bytes()\n\t\t\tpub = eKey.PublicKey().Bytes()\n\t\tdefault:\n\t\t\treturn fmt.Errorf(\"invalid curve: %s\", *cf.curve)\n\t\t}\n\t}\n\n\tt := &cert.TBSCertificate{\n\t\tVersion:        version,\n\t\tName:           *cf.name,","sourceCodeStart":266,"sourceCodeEnd":302,"githubUrl":"https://github.com/slackhq/nebula/blob/dd8f660c0ac37903ec4080ca4d3c861ba9342ceb/cmd/nebula-cert/ca.go#L266-L302","documentation":"Wraps a failure from ecdsa.GenerateKey(elliptic.P256(), rand.Reader) when generating a P256 CA key in `nebula-cert ca`. Like the ed25519 case, this normally fails only when the OS cryptographic random source is unavailable, though P256 generation can additionally fail on malformed key rejection by the crypto stack.","triggerScenarios":"nebula-cert ca -curve P256 when crypto/rand.Reader fails (getrandom(2) error, /dev/urandom inaccessible) or the ecdsa key generation loop cannot produce a valid key.","commonSituations":"Containers blocking /dev/urandom; kernels without getrandom; FIPS/libcrypto conflicts affecting P256; embedded systems with entropy starvation.","solutions":["Inspect the wrapped error for the underlying rand/ecdsa failure reason","Ensure /dev/urandom is present and readable in the execution environment","Upgrade kernel/container so getrandom(2) works","Retry the command; failures are almost always environmental and transient"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// preflight: ensure the OS random source is readable\nif _, err := os.ReadFile(\"/dev/urandom\"); err != nil {\n\treturn fmt.Errorf(\"entropy source unavailable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"out, err := exec.Command(\"nebula-cert\", \"ca\", \"-curve\", \"P256\", ...).CombinedOutput()\nif err != nil && strings.Contains(string(out), \"error while generating ecdsa keys\") {\n\tlog.Printf(\"P256 key generation failed: %s\", out)\n\t// check environment, then retry\n}","preventionTips":["Check /dev/urandom availability in sandboxed runners","Use stock Go builds; custom crypto builds can break ECDSA generation","Retry once on transient entropy failures before alerting"],"tags":["crypto","ecdsa","p256","entropy","cli"],"backgroundTag":"random-source-unavailable","analyzedSha":"dd8f660c0ac37903ec4080ca4d3c861ba9342ceb","analyzedAt":"2026-09-03T11:13:55.444Z","contentChangedAt":"2026-09-03T11:13:55.444Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}