Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RSA Verify Refactor #709

Merged
merged 1 commit into from
Jun 5, 2024
Merged

Conversation

ejohnstown
Copy link
Contributor

Description

Some implementations of SSH will remove all leading zeros from an encoded RSA signature, which is allowed per the RFCs. Our verify function requires the signature to be the same size as the key. This refactor will pad a signature with leading zeros if it is short. (ZD 18095)

Testing

Run the echoserver and the PuTTY plink tools:

./examples/echoserver/echoserver -I putty:keys/putty_rsa.pub
plink -batch -P 22222 -l putty -i keys/putty_rsa.ppk localhost
while $(echo | plink -batch -P 22222 -l putty -i keys/putty_rsa.ppk localhost) ; do : ; done

The while version will repeatedly call the command. There's a 1/256 chance of the signature failing before the fix.

src/internal.c Outdated

if (ret == WS_SUCCESS) {
if (publicKeyTypeSz != 14 &&
WMEMCMP(publicKeyType, "x509v3-ssh-rsa", 14) != 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to have the "x509v3-ssh-rsa" as a macro and also use XSTRLEN. Is this a new check? Do you expect any compatibility issues?

This comment was marked as off-topic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do want to double check the strings and use names for the strings in general, I think that's outside the scope of this PR.

src/internal.c Outdated
WFREE(checkDigest, heap, DYNTYPE_BUFFER);
#endif
if (checkSig)
WFREE(checkSig, heap, DYNTYPE_BUFFER);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be DYNTYPE_TEMP

JacobBarthelmeh
JacobBarthelmeh previously approved these changes Jun 5, 2024
1. If the signature to verify is short, pad it to the key length with
   leading zeros. Some implementations of SSH will prune leading zeros
   from an mpint value as a string for the signature.
2. Change some of the GetSize() and play with pointers to using
   GetStringRef() or GetMpint().
3. Added an RSA private key for testing with PuTTY client.
@ejohnstown ejohnstown force-pushed the rsa-verify-refactor branch from e1439e3 to 12b0a43 Compare June 5, 2024 21:36
@dgarske dgarske merged commit 2e0f509 into wolfSSL:master Jun 5, 2024
24 checks passed
@ejohnstown ejohnstown deleted the rsa-verify-refactor branch June 5, 2024 22:34
jefferyq2 pushed a commit to jefferyq2/wolfssh that referenced this pull request Sep 24, 2024
jefferyq2 pushed a commit to jefferyq2/wolfssh that referenced this pull request Oct 18, 2024
jefferyq2 pushed a commit to jefferyq2/wolfssh that referenced this pull request Oct 29, 2024
jefferyq2 pushed a commit to jefferyq2/wolfssh that referenced this pull request Oct 29, 2024
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.

4 participants