slackhq/nebula · error
unknown public key length
Error message
unknown public key length: %d
What it means
GetPubKey accepts EC points of 65 bytes (raw uncompressed 0x04 || X || Y for P-256) or 67 bytes (same point with a 2-byte DER header, which it strips). Any other length means the token returned an unrecognized EC point encoding, so this error is thrown with the actual length.
Solutions
- Configure the HSM to emit uncompressed EC points (disable point compression).
- Ensure the certificate/key uses the P-256 curve — other curves yield different point lengths.
- Inspect the returned bytes and, if the module adds a fixed header, adjust provisioning rather than the client.
- Regenerate the keypair with standard uncompressed encoding.
Defensive patterns
Strategy: validation
Validate before calling
// Only expect P-256 uncompressed points (65) or DER-wrapped (67)
func expectP256Point(d []byte) error {
switch len(d) {
case 65, 67: return nil
default: return fmt.Errorf("token returned %d-byte EC point; configure uncompressed P-256", len(d))
}
} Try / catch
pub, err := client.GetPubKey()
if err != nil {
var lenErr interface{ Error() string }
if errors.As(err, &lenErr) && strings.Contains(err.Error(), "unknown public key length") {
return fmt.Errorf("HSM point compression or non-P256 curve in use; fix token config: %w", err)
}
return err
} Prevention
- Disable EC point compression on the HSM.
- Use only P-256 keys with this client (other curves produce different point lengths).
- Provision keys with uncompressed public point encoding.
- Catch this in staging by calling GetPubKey and validating len==65 before rollout.
When it happens
Trigger: Calling GetPubKey when CKA_EC_POINT has a length other than 65 or 67 — e.g. a compressed point (33 bytes), a point with a DER BIT STRING wrapper of a different length, or trailing garbage added by the module.
Common situations: HSM configured for point compression; curves other than P-256 (e.g. P-384 producing 97-byte points) used with this client; vendor module wrapping the point in an unexpected encoding; corruption between token and client.
Related errors
- invalid curve for PKCS#11
- invalid curve for PKCS#11
- certificate curve does not match expected
- curve in cert and private key supplied don't match
- error while creating PKCS#11 client
AI-assisted analysis of slackhq/nebula@dd8f660c0a (2026-09-03).
Data as JSON: /api/errors/0d799b1610ecff4d.
Report an issue: GitHub.
Appendix: source
Thrown at pkclient/pkclient_cgo.go:228
}
c.pubKeyObj, err = c.findDeriveKey(c.id, c.label, false)
if err != nil {
return nil, fmt.Errorf("pkcs11 module gave us a nil CKA_PUBLIC_KEY_INFO, and looking up the public key also failed: %w", err)
}
d, err = c.pubKeyObj.Attribute(pkcs11.CKA_EC_POINT)
if err != nil {
return nil, fmt.Errorf("pkcs11 module gave us a nil CKA_PUBLIC_KEY_INFO, and reading CKA_EC_POINT also failed: %w", err)
}
if d == nil || len(d) < 1 {
return nil, fmt.Errorf("pkcs11 module gave us a nil or empty CKA_EC_POINT")
}
switch len(d) {
case 65: //length of 0x04 + len(X) + len(Y)
return d, nil
case 67: //as above, DER-encoded IIRC?
return d[2:], nil
default:
return nil, fmt.Errorf("unknown public key length: %d", len(d))
}
}
View on GitHub (pinned to dd8f660c0a)