{"record":{"id":"ad4d97e3d41cb128","repo":"slackhq/nebula","slug":"bytes-did-not-contain-a-proper-ed25519-ecdsa-publi","errorCode":null,"errorMessage":"bytes did not contain a proper Ed25519/ECDSA public key banner","messagePattern":"bytes did not contain a proper Ed25519/ECDSA public key banner","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cert/pem.go","lineNumber":197,"sourceCode":"// consumed data or an error on failure. Only Ed25519/ECDSA public key banners are accepted.\n// Use UnmarshalPublicKeyFromPEM for X25519/P256 (ECDH) banners.\nfunc UnmarshalSigningPublicKeyFromPEM(b []byte) ([]byte, []byte, Curve, error) {\n\tk, r := pem.Decode(b)\n\tif k == nil {\n\t\treturn nil, r, 0, fmt.Errorf(\"input did not contain a valid PEM encoded block\")\n\t}\n\tvar expectedLen int\n\tvar curve Curve\n\tswitch k.Type {\n\tcase Ed25519PublicKeyBanner:\n\t\texpectedLen = 32\n\t\tcurve = Curve_CURVE25519\n\tcase ECDSAP256PublicKeyBanner:\n\t\t// Uncompressed\n\t\texpectedLen = 65\n\t\tcurve = Curve_P256\n\tdefault:\n\t\treturn nil, r, 0, fmt.Errorf(\"bytes did not contain a proper Ed25519/ECDSA public key banner\")\n\t}\n\tif len(k.Bytes) != expectedLen {\n\t\treturn nil, r, 0, fmt.Errorf(\"key was not %d bytes, is invalid %s public key\", expectedLen, curve)\n\t}\n\treturn k.Bytes, r, curve, nil\n}\n\nfunc MarshalPrivateKeyToPEM(curve Curve, b []byte) []byte {\n\tswitch curve {\n\tcase Curve_CURVE25519:\n\t\treturn pem.EncodeToMemory(&pem.Block{Type: X25519PrivateKeyBanner, Bytes: b})\n\tcase Curve_P256:\n\t\treturn pem.EncodeToMemory(&pem.Block{Type: P256PrivateKeyBanner, Bytes: b})\n\tdefault:\n\t\treturn nil\n\t}\n}\n","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/slackhq/nebula/blob/dd8f660c0ac37903ec4080ca4d3c861ba9342ceb/cert/pem.go#L179-L215","documentation":"The PEM block decoded but its Type banner is not Ed25519PublicKeyBanner or ECDSAP256PublicKeyBanner, the only banners UnmarshalSigningPublicKeyFromPEM accepts. The function deliberately rejects key-agreement banners and directs callers to UnmarshalPublicKeyFromPEM for those.","triggerScenarios":"Calling UnmarshalSigningPublicKeyFromPEM with a PEM block typed 'NEBULA X25519 PUBLIC KEY', 'CERTIFICATE', 'NEBULA ED25519 ENCRYPTED PRIVATE KEY', or any other non-signing-public-key banner.","commonSituations":"Swapping the two key-loading functions — passing an X25519 ECDH public key where an Ed25519 signing public key is needed (e.g. when verifying certificate signatures or loading the CA signing key's public half), or passing a full certificate PEM instead of the extracted public key.","solutions":["Use UnmarshalPublicKeyFromPEM if the PEM type is an X25519/P256 key-agreement banner","Ensure the input banner is '-----BEGIN NEBULA ED25519 PUBLIC KEY-----' or '-----BEGIN NEBULA ECDSA P256 PUBLIC KEY-----'","Extract the signing public key from the certificate object (e.g. cert.GetPublicKey) instead of feeding the certificate PEM into this function"],"exampleFix":"// before\n_, rest, curve, err := cert.UnmarshalSigningPublicKeyFromPEM(x25519PubPEM) // ECDH banner\n// after\n_, rest, curve, err := cert.UnmarshalPublicKeyFromPEM(x25519PubPEM)","handlingStrategy":"validation","validationCode":"func isSigningBanner(b []byte) bool {\n\tblk, _ := pem.Decode(b)\n\tif blk == nil {\n\t\treturn false\n\t}\n\treturn blk.Type == cert.Ed25519PublicKeyBanner || blk.Type == cert.ECDSAP256PublicKeyBanner\n}","typeGuard":null,"tryCatchPattern":"pub, rest, curve, err := cert.UnmarshalSigningPublicKeyFromPEM(b)\nif err != nil {\n\tif strings.Contains(err.Error(), \"Ed25519/ECDSA public key banner\") {\n\t\tif blk, _ := pem.Decode(b); blk != nil && (blk.Type == cert.X25519PublicKeyBanner || blk.Type == cert.P256PublicKeyBanner) {\n\t\t\t_, _, _, err = cert.UnmarshalPublicKeyFromPEM(b)\n\t\t\treturn err\n\t\t}\n\t}\n\treturn err\n}","preventionTips":["Route X25519/P256 ECDH banners to UnmarshalPublicKeyFromPEM instead","Do not feed certificate PEM blocks into signing-public-key parsing; extract the key via the certificate API","Label key material (signing vs encryption) consistently in configs and filenames"],"tags":["pem","banner-mismatch","public-key","signing","go"],"backgroundTag":"pem-banner-mismatch","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"}