{"record":{"id":"e9b7162209b1d02a","repo":"slackhq/nebula","slug":"invalid-integer","errorCode":null,"errorMessage":"invalid integer","messagePattern":"invalid integer","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cert/p256/p256.go","lineNumber":118,"sourceCode":"}\n\nfunc encodeSignature(r, s []byte) ([]byte, error) {\n\tvar b cryptobyte.Builder\n\tb.AddASN1(asn1.SEQUENCE, func(b *cryptobyte.Builder) {\n\t\taddASN1IntBytes(b, r)\n\t\taddASN1IntBytes(b, s)\n\t})\n\treturn b.Bytes()\n}\n\n// addASN1IntBytes encodes in ASN.1 a positive integer represented as\n// a big-endian byte slice with zero or more leading zeroes.\nfunc addASN1IntBytes(b *cryptobyte.Builder, bytes []byte) {\n\tfor len(bytes) > 0 && bytes[0] == 0 {\n\t\tbytes = bytes[1:]\n\t}\n\tif len(bytes) == 0 {\n\t\tb.SetError(errors.New(\"invalid integer\"))\n\t\treturn\n\t}\n\tb.AddASN1(asn1.INTEGER, func(c *cryptobyte.Builder) {\n\t\tif bytes[0]&0x80 != 0 {\n\t\t\tc.AddUint8(0)\n\t\t}\n\t\tc.AddBytes(bytes)\n\t})\n}\n","sourceCodeStart":100,"sourceCodeEnd":128,"githubUrl":"https://github.com/slackhq/nebula/blob/dd8f660c0ac37903ec4080ca4d3c861ba9342ceb/cert/p256/p256.go#L100-L128","documentation":"addASN1IntBytes in cert/p256/p256.go raises 'invalid integer' when asked to encode a big-endian integer whose bytes are all zero (empty after stripping leading zeros). DER integers must carry at least one significant byte, so the builder is put into an error state.","triggerScenarios":"Encoding a signature component (r or s) that is entirely zero — all-zero byte slices passed to encodeSignature via addASN1IntBytes.","commonSituations":"A signing operation that produced a zero component due to a bad or zero private key; corrupted/zeroed signature bytes parsed from storage or the wire; test fixtures containing empty scalar values.","solutions":["Check the signing key is valid and non-zero before signing — a zero r or s indicates a broken scalar","Reject or re-request signatures containing all-zero components at the decoding boundary","Validate signature bytes (non-zero r and s) before attempting to re-encode them"],"exampleFix":"// before\nsig, _ := encodeSignature(zeroR, s) // r all zeroes\n// after\nif isAllZero(r) || isAllZero(s) {\n    return nil, fmt.Errorf(\"invalid signature component\")\n}\nsig, err := encodeSignature(r, s)","handlingStrategy":"validation","validationCode":"func isAllZero(b []byte) bool {\n    for _, x := range b { if x != 0 { return false } }\n    return true\n}\n// reject if isAllZero(r) || isAllZero(s)","typeGuard":"func hasNonZeroComponents(r, s []byte) bool {\n    return !(isAllZero(r) || isAllZero(s))\n}","tryCatchPattern":"sig, err := encodeSignature(r, s)\nif err != nil && err.Error() == \"invalid integer\" {\n    // zero component: signature or key is invalid\n}","preventionTips":["Validate signing keys are non-zero before use","Reject signatures with all-zero r or s at decode time","Use test vectors that exclude empty/zero scalar components"],"tags":["asn1","p256","signature","encoding"],"backgroundTag":"invalid-asn1-signature","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"}