Skip to content

Fix CRL nextUpdate handling.#1169

Merged
alex merged 3 commits into
pyca:mainfrom
davidben:fix-crl-last-update
Dec 16, 2022
Merged

Fix CRL nextUpdate handling.#1169
alex merged 3 commits into
pyca:mainfrom
davidben:fix-crl-last-update

Conversation

@davidben

Copy link
Copy Markdown
Contributor

When setting the nextUpdate field of a CRL, this code grabbed the nextUpdate ASN1_TIME field from the CRL and set its time. But nextUpdate is optional in a CRL so that field is usually NULL. But OpenSSL's ASN1_TIME_set_string succeeds when the destination argument is NULL, so it was silently a no-op.

Given that, the call in a test to set the nextUpdate field suddenly starts working and sets the time to 2018, thus causing the CRL to be considered expired and breaking the test. So this change also changes the expiry year far into the future.

Additionally, the other CRL and Revoked setters violate const in the API.

Fixes #1168.

When setting the nextUpdate field of a CRL, this code grabbed the
nextUpdate ASN1_TIME field from the CRL and set its time. But nextUpdate
is optional in a CRL so that field is usually NULL. But OpenSSL's
ASN1_TIME_set_string succeeds when the destination argument is NULL, so
it was silently a no-op.

Given that, the call in a test to set the nextUpdate field suddenly
starts working and sets the time to 2018, thus causing the CRL to be
considered expired and breaking the test. So this change also changes
the expiry year far into the future.

Additionally, the other CRL and Revoked setters violate const in the
API.

Fixes pyca#1168.
Comment thread src/OpenSSL/crypto.py
ret = _lib.ASN1_TIME_new()
_openssl_assert(ret != _ffi.NULL)
ret = _ffi.gc(ret, _lib.ASN1_TIME_free)
_set_asn1_time(ret, when)

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.

We almost could delete _set_asn1_time and inline it in here. But the problem is the setters for X509 aren't bound. I've left it alone for now, but that could be a small bit of cleanup if you want to do the whole multi-sided change. :-)

Comment thread src/OpenSSL/crypto.py
ret = _lib.ASN1_TIME_new()
_openssl_assert(ret != _ffi.NULL)
ret = _ffi.gc(ret, _lib.ASN1_TIME_free)
_set_asn1_time(ret, when)

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.

This doesn't appear to have any callers left, should it just be inlinined here? I think there's a bunch of checks in it that are now unreachable

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.

Ignore me, there's still 1 caller

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.

Yeah, see comment above. :-) We could get rid of it if we did a multi-project thing and bound some more APIs.

alex
alex previously approved these changes Dec 16, 2022
Comment thread src/OpenSSL/crypto.py Outdated
alex
alex previously approved these changes Dec 16, 2022
Comment thread src/OpenSSL/crypto.py Outdated

def _new_asn1_time(when: bytes) -> Any:
"""
Behaves like _set_asn1_time bit returns a new ASN1_TIME object.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

s/bit/but/

Comment thread src/OpenSSL/crypto.py Outdated
Co-authored-by: Alex Gaynor <alex.gaynor@gmail.com>
@alex alex merged commit d2f0aec into pyca:main Dec 16, 2022
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.

CRL.set_nextUpdate sometimes doesn't work and other setters violate const-correctness

3 participants