gravitational/teleport · error

public key representation starts with unexpected byte (%#x v

Error message

public key representation starts with unexpected byte (%#x vs 0x4)

What it means

Guard in ECDSAPublicKeyFromRaw (lib/darwin/pub_key.go) raised by Register, ListCredentials, and pubKeyToCredential. Apple's SecKeyCopyExternalRepresentation returns raw ECDSA public keys with a 0x04 (uncompressed point) leading byte; this error fires when the raw key bytes instead start with an unexpected byte, meaning the key blob is not a standard uncompressed EC point — corrupt stored credential data or an unexpected key representation from the Secure Enclave/keychain.

Source

Thrown at lib/darwin/pub_key.go:41

	"crypto/elliptic"
	"fmt"
	"math/big"
)

// ECDSAPublicKeyFromRaw reads an ECDSA public key from a raw Apple public key,
// as returned by SecKeyCopyExternalRepresentation.
func ECDSAPublicKeyFromRaw(pubKeyRaw []byte) (*ecdsa.PublicKey, error) {
	// Verify key length to avoid a potential panic below.
	// 3 is the smallest number that clears it, but in practice 65 is the more
	// common length.
	// Apple's docs make no guarantees, hence no assumptions are made here.
	switch l := len(pubKeyRaw); {
	case l < 3:
		return nil, fmt.Errorf("public key representation too small (%v bytes)", l)
	case l%2 != 1: // 0x4+keyLen+keyLen is always odd, see explanation below.
		return nil, fmt.Errorf("public key representation has unexpected length (%v bytes)", l)
	case pubKeyRaw[0] != 0x04: // See explanation below.
		return nil, fmt.Errorf("public key representation starts with unexpected byte (%#x vs 0x4)", pubKeyRaw[0])
	}

	// "For an elliptic curve public key, the format follows the ANSI X9.63
	// standard using a byte string of 04 || X || Y. (...) All of these
	// representations use constant size integers, including leading zeros as
	// needed."
	// https://developer.apple.com/documentation/security/1643698-seckeycopyexternalrepresentation?language=objc
	pubKeyRaw = pubKeyRaw[1:] // skip 0x4
	l := len(pubKeyRaw) / 2
	x := pubKeyRaw[:l]
	y := pubKeyRaw[l:]

	return &ecdsa.PublicKey{
		Curve: elliptic.P256(),
		X:     (&big.Int{}).SetBytes(x),
		Y:     (&big.Int{}).SetBytes(y),
	}, nil
}

View on GitHub (pinned to 1283425b60)

Solutions

  1. Ensure the credential is an ECDSA key exported in uncompressed form
  2. Re-register the credential to obtain a valid uncompressed representation
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at lib/darwin/pub_key.go:41 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of gravitational/teleport@1283425b60 (2026-09-02). Data as JSON: /api/errors/dbbdd595e031e71b. Report an issue: GitHub.