Skip to content

Add RSA support for smartcard-backed SSH authentication (fixes: Issue #4) - #5

Merged
valasiadis merged 1 commit into
valasiadis:developfrom
norbusan:rsa-ssh
Jul 22, 2026
Merged

Add RSA support for smartcard-backed SSH authentication (fixes: Issue #4)#5
valasiadis merged 1 commit into
valasiadis:developfrom
norbusan:rsa-ssh

Conversation

@norbusan

Copy link
Copy Markdown

Previously the OpenPGP card SSH auth path handled only Ed25519 and ECDSA keys and rejected RSA. Adding RSA required two changes:

  • Algorithm negotiation. sshj advertises RSA keys under a negotiated algorithm name (rsa-sha2-512, rsa-sha2-256 or ssh-rsa) that differs from the key's base type, and the name in the signature blob must match the one in the request. The old override signed with KeyType.toString(), which is always ssh-rsa (SHA-1) and mismatches what putPubKey advertised. Because the card replaces both putPubKey and putSig, CardSshAuthPublickey now tracks its own copy of sshj's KeyAlgorithm queue (peeked for the current algorithm, dropped in shouldRetry) so the advertised algorithm, the signed algorithm and the retry fallback stay in lockstep.

  • Card signing input. For RSA the signer builds a PKCS#1 v1.5 DigestInfo (DER hash prefix plus digest, hash chosen from the negotiated algorithm) and hands it to INTERNAL AUTHENTICATE; the card applies the PKCS#1 padding and modular exponentiation and returns the raw modulus-sized signature, which is used directly as the SSH rsa_signature_blob.

Previously the OpenPGP card SSH auth path handled only Ed25519 and ECDSA
keys and rejected RSA. Adding RSA required two changes:

- Algorithm negotiation. sshj advertises RSA keys under a negotiated
  algorithm name (rsa-sha2-512, rsa-sha2-256 or ssh-rsa) that differs from
  the key's base type, and the name in the signature blob must match the one
  in the request. The old override signed with KeyType.toString(), which is
  always ssh-rsa (SHA-1) and mismatches what putPubKey advertised. Because
  the card replaces both putPubKey and putSig, CardSshAuthPublickey now
  tracks its own copy of sshj's KeyAlgorithm queue (peeked for the current
  algorithm, dropped in shouldRetry) so the advertised algorithm, the signed
  algorithm and the retry fallback stay in lockstep.

- Card signing input. For RSA the signer builds a PKCS#1 v1.5 DigestInfo
  (DER hash prefix plus digest, hash chosen from the negotiated algorithm)
  and hands it to INTERNAL AUTHENTICATE; the card applies the PKCS#1 padding
  and modular exponentiation and returns the raw modulus-sized signature,
  which is used directly as the SSH rsa_signature_blob.
@norbusan norbusan mentioned this pull request Jul 18, 2026
@norbusan

Copy link
Copy Markdown
Author

I can confirm that with this change, I was:

  • able to import an RSA key from a Yubikey
  • able to use the RSA key to clone a remote pass repo
  • able to use the RSA key to decrypt a secret

@norbusan

Copy link
Copy Markdown
Author

I have now restructured the code, added a few commits regarding security rework, and created a PR agrahn#977
The original code changes are still attributed to you.

@valasiadis

valasiadis commented Jul 22, 2026

Copy link
Copy Markdown
Owner

I'm very sorry this went past me. I'm still going to review this in a couple of hours when I get home and merge it. That way, there's still a downloadable app version with RSA support until your PR is merged upstream

@valasiadis
valasiadis self-requested a review July 22, 2026 09:01
@valasiadis
valasiadis merged commit c4504c1 into valasiadis:develop Jul 22, 2026
3 of 4 checks passed
@valasiadis

Copy link
Copy Markdown
Owner

@norbusan I've reviewed the changes and merged them. If you want to, I'd like to merge your other changes too, to keep this repo in a consistent state until your upstream PR is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants