You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
from_pem error for an OpenSSH-format key mentions only PKCS8 — wrong remediation #335
ssh-keygen's default output since OpenSSH 7.8 is -----BEGIN OPENSSH PRIVATE KEY-----, not PKCS8. cryptography.serialization.load_pem_private_key does not parse that format — it requires load_ssh_private_key. A user who generated their Kalshi key with ssh-keygen -t rsa gets KalshiAuthError: Invalid PEM private key: Could not deserialize key data.... The current hint tells them to verify PKCS8 format — but does not tell them their key is actually OpenSSH or how to convert it.
First-run friction; the v2.x passphrase work added password handling but kept the PKCS8-only error string.
Evidence
kalshi/auth.py:137-143:
except (ValueError, UnsupportedAlgorithm) as e:
# Wrong password and malformed PEM both surface here as ValueError.
raise KalshiAuthError(
f"Invalid PEM private key: {e}. Ensure the key is an RSA private key "
"in PKCS8 PEM format (-----BEGIN PRIVATE KEY-----) and that "
"the supplied `password=` (if any) is correct."
) from e
Suggested fix
Before calling load_pem_private_key, peek at the first line of pem_bytes. If it starts with -----BEGIN OPENSSH PRIVATE KEY-----, raise a targeted error:
raise KalshiAuthError(
"OpenSSH private-key format detected. Kalshi requires PKCS8 PEM. "
"Convert in place with: ssh-keygen -p -m PEM -f <path> "
"or: openssl rsa -in <path> -out <path>.pem"
)
Leave the generic PKCS8 message for genuinely malformed bytes. Add a unit test that feeds an OpenSSH-format key and asserts the targeted message.
Activity