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

Fix test_create_with_mac_iter accidently setting keytype not maciter #762

Merged

Conversation

KJTsanaktsidis
Copy link
Contributor

@KJTsanaktsidis KJTsanaktsidis commented Jun 2, 2024

This test was accidentally passing the value 2048 into the keytype parameter of PKCS12_create, not the mac_iter parameter (because it had one too many nils in the call). This value is invalid, and will make OpenSSL perform an out-of-bounds read which is caught when compiling with ASAN.

This commit fixes the tests, and also adds some validation to PKCS12.create to make sure any keytype passed is actually valid. Since there only two valid keytype constants, and the whole feature is an export-grade crypto era thing only ever supported by old MSIE, it seems far more likely that code in the wild is using keytype similarly by mistake rather than as intended. So this validation might catch that.

@KJTsanaktsidis
Copy link
Contributor Author

curl: (6) Could not resolve host: ftp.openssl.org

Looks like their mirror is having a bad day, I'll come back and re-run the tests later.

@KJTsanaktsidis
Copy link
Contributor Author

#763 - this'll fix the build.

Copy link
Member

@rhenium rhenium left a comment

Choose a reason for hiding this comment

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

Good catch!

I think this is where the MSIE keytype is explained.
https://learn.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-pfximportcertstore

An X.509 KeyUsage is supposed to be a 9-bit bit field. But looking at the OpenSSL code, it doesn't seem to intend to support anything other than the two values.

The change looks good to me. Thank you!

This test was accidentally passing the value 2048 into the keytype
parameter of PKCS12_create, not the mac_iter parameter (because it had
one too many `nil`s in the call). This value is invalid, and will make
OpenSSL perform an out-of-bounds read which is caught when compiling
with ASAN.

This commit fixes the tests, and also adds some validation to
PKCS12.create to make sure any keytype passed is actually valid. Since
there only two valid keytype constants, and the whole feature is an
export-grade crypto era thing only ever supported by old MSIE, it seems
far more likely that code in the whild is using keytype similarly by
mistake rather than as intended. So this validation might catch that.
@KJTsanaktsidis KJTsanaktsidis force-pushed the ktsanaktsidis/fix_asan_error branch from d6d4c44 to 4702868 Compare June 5, 2024 00:37
@KJTsanaktsidis
Copy link
Contributor Author

This function would also create an illegal ASN1_BIT_STRING if the lower 8 bits are all zero, which leads to the out-of-bounds read as caught by ASAN.

Ah, thanks for explaining this - I was looking at ossl_i2c_ASN1_BIT_STRING and wondering how this code could be correct with all-zeros, but I didn't realise that was actually an illegal bitstring.

@KJTsanaktsidis KJTsanaktsidis merged commit 600b422 into ruby:master Jun 5, 2024
54 checks passed
@KJTsanaktsidis KJTsanaktsidis deleted the ktsanaktsidis/fix_asan_error branch June 5, 2024 00:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants