OpenNHP/opennhp · error
unsupported key type, expect RSA
Error message
unsupported key type, expect RSA
What it means
parseTeePubkey only supports RSA keys when converting a TEE attestation's COSE/CBOR public key into an *rsa.PublicKey. If the key type (kty) field of the attested TEE pubkey is anything other than "RSA" (e.g. EC2/EC, OKP), attestation is rejected.
Solutions
- Configure the TEE/attester to generate RSA keys for its attestation public key
- Extend parseTeePubkey to handle the kty you actually use (e.g. EC2 -> ecdsa.PublicKey)
- Verify the pubkey JSON/N/E fields come from the expected attestation format
- Check the attestation SDK version didn't change the default key type
Example fix
// before
if pubkey.Kty != "RSA" {
return nil, errors.New("unsupported key type, expect RSA")
}
// after
switch pubkey.Kty {
case "RSA":
return parseRSAPubkey(pubkey)
case "EC2":
return parseECPubkey(pubkey)
default:
return nil, fmt.Errorf("unsupported key type: %s", pubkey.Kty)
} Defensive patterns
Strategy: validation
Validate before calling
pubkey, err := extractTeePubkey(evidence)
if err != nil { return err }
if pubkey.Kty != "RSA" {
return fmt.Errorf("TEE produced %q key; configure RSA or extend parser", pubkey.Kty)
} Type guard
func isRSATeePubkey(k TeePubkey) bool { return k.Kty == "RSA" && k.N != "" && k.E != "" } Try / catch
pk, err := parseTeePubkey(tp)
if err != nil {
if strings.Contains(err.Error(), "unsupported key type") {
log.Errorf("attester must emit RSA keys: %v", err)
}
return err
} Prevention
- Pin the attestation SDK/key-algorithm config to RSA
- Add an integration test attesting with the real TEE to catch key-type drift
- Log the received kty before failing to ease diagnosis
When it happens
Trigger: Attest() receives a TEE evidence token whose pubkey.kty is not "RSA" — e.g. the TEE (or its signing attester) was configured to produce EC keys, or a malformed/forged token supplies a different kty.
Common situations: Migrating confidential-computing workloads (SEV-SNP/TDX guests) that emit EC P-256 keys, upgrading attestation SDKs that changed the default key algorithm, or testing with keys generated by a crypto library defaulting to elliptic curves.
Related errors
- TEE public key is not found for specified token
- JWT signing key is not initialized
- invalid n
- invalid e
- invalid public key length: got
AI-assisted analysis of OpenNHP/opennhp@6e04ca5ff0 (2026-09-07).
Data as JSON: /api/errors/a690b43fec8f5813.
Report an issue: GitHub.
Appendix: source
Thrown at endpoints/server/kbs/attest/attest.go:103
teePubKeys.Lock()
teePubKeys.data[token] = teePubKey
teePubKeys.Unlock()
c.SetCookie(
"kbs-session-id",
sessionID,
3600,
"/", "", true, true, // Secure: only send over HTTPS
)
c.JSON(http.StatusOK, gin.H{
"token": token,
})
}
func parseTeePubkey(pubkey TeePubkey) (*rsa.PublicKey, error) {
if pubkey.Kty != "RSA" {
return nil, errors.New("unsupported key type, expect RSA")
}
nBytes, err := base64.RawURLEncoding.DecodeString(pubkey.N)
if err != nil {
return nil, fmt.Errorf("invalid n: %w", err)
}
eBytes, err := base64.RawURLEncoding.DecodeString(pubkey.E)
if err != nil {
return nil, fmt.Errorf("invalid e: %w", err)
}
e := 0
for _, b := range eBytes {
e = e<<8 | int(b)
}
return &rsa.PublicKey{View on GitHub (pinned to 6e04ca5ff0)