Skip to content

RSA Verify Refactor#709

Merged
dgarske merged 1 commit intowolfSSL:masterfrom
ejohnstown:rsa-verify-refactor
Jun 5, 2024
Merged

RSA Verify Refactor#709
dgarske merged 1 commit intowolfSSL:masterfrom
ejohnstown:rsa-verify-refactor

Conversation

@ejohnstown
Copy link
Copy Markdown
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.

Comment thread src/internal.c Outdated

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

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
Copy Markdown
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.

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

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
@ejohnstown ejohnstown deleted the rsa-verify-refactor branch June 5, 2024 22:34
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