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

y2038: some tests are failing if system date is set to 2040 #9370

Closed
kanavin opened this issue Aug 7, 2023 · 7 comments · Fixed by #9964
Closed

y2038: some tests are failing if system date is set to 2040 #9370

kanavin opened this issue Aug 7, 2023 · 7 comments · Fixed by #9964

Comments

@kanavin
Copy link
Contributor

kanavin commented Aug 7, 2023

To test the readiness of Yocto stack for Y2038 we run qemu virtual machines with RTC set to some day in 2040. This causes some tests to fail on both 32 bit and 64 bit systems: the reason is that test certificates seemto set their expiry date to earlier than that or so.

I would propose to set the expiry date to far enough in the future that it won't have to be tweaked in our lifetimes: this way real Y2038 issues in python-cryptography (or in things it depends on) can be exposed and fixed (it's well possible there are none, but that needs confirmation too).

Failure observed (this is one of several similar failures, all of them in test_pkcs7 and relying on _load_cert_key()).


self = <tests.hazmat.primitives.test_pkcs7.TestPKCS7Builder object at 0x7f94f0863610>, backend = <OpenSSLBackend(version: OpenSSL 3.1.1 30 May 2023, FIPS: False, Legacy: True)>

    def test_smime_sign_detached(self, backend):
        data = b"hello world"
        cert, key = _load_cert_key()
        options = [pkcs7.PKCS7Options.DetachedSignature]
        builder = (
            pkcs7.PKCS7SignatureBuilder()
            .set_data(data)
            .add_signer(cert, key, hashes.SHA256())
        )
    
        sig = builder.sign(serialization.Encoding.SMIME, options)
        sig_binary = builder.sign(serialization.Encoding.DER, options)
        assert b"text/plain" not in sig
        # We don't have a generic ASN.1 parser available to us so we instead
        # will assert on specific byte sequences being present based on the
        # parameters chosen above.
        assert b"sha-256" in sig
        # Detached signature means that the signed data is *not* embedded into
        # the PKCS7 structure itself, but is present in the SMIME serialization
        # as a separate section before the PKCS7 data. So we should expect to
        # have data in sig but not in sig_binary
        assert data in sig
        # Parse the message to get the signed data, which is the
        # first payload in the message
        message = email.parser.BytesParser().parsebytes(sig)
        signed_data = message.get_payload()[0].get_payload().encode()
>       _pkcs7_verify(
            serialization.Encoding.SMIME,
            sig,
            signed_data,
            [cert],
            options,
            backend,
        )

tests/hazmat/primitives/test_pkcs7.py:307: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tests/hazmat/primitives/test_pkcs7.py:142: in _pkcs7_verify
    backend.openssl_assert(res == 1)
../../python3.11/site-packages/cryptography/hazmat/backends/openssl/backend.py:173: in openssl_assert
    return binding._openssl_assert(self._lib, ok, errors=errors)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

lib = <module 'lib'>, ok = False, errors = [<OpenSSLError(code=276824181, lib=33, reason=117, reason_text=certificate verify error)>]

    def _openssl_assert(
        lib,
        ok: bool,
        errors: typing.Optional[typing.List[openssl.OpenSSLError]] = None,
    ) -> None:
        if not ok:
            if errors is None:
                errors = openssl.capture_error_stack()
    
>           raise InternalError(
                "Unknown OpenSSL error. This error is commonly encountered when "
                "another library is not cleaning up the OpenSSL error stack. If "
                "you are using cryptography with another library that uses "
                "OpenSSL try disabling it before reporting a bug. Otherwise "
                "please file an issue at https://github.com/pyca/cryptography/"
                "issues with information on how to reproduce "
                "this. ({!r})".format(errors),
                errors,
            )
E           cryptography.exceptions.InternalError: Unknown OpenSSL error. This error is commonly encountered when another library is not cleaning up the OpenSSL error stack. If you are using cryptography with a)

../../python3.11/site-packages/cryptography/hazmat/bindings/openssl/binding.py:29: InternalError
FAIL: tests/hazmat/primitives/test_pkcs7.py:TestPKCS7Builder.test_smime_sign_detached

@alex
Copy link
Member

alex commented Aug 7, 2023

The relevant file is vectors/cryptography_vectors/x509/custom/ca/ca.pem, we could extend the not-after to 2138 or something similarly obscene.

Not sure if there's any tests that'll need to be updated for this.

@alex alex added the testing label Aug 7, 2023
@alex alex added this to the Forty Second Release milestone Aug 7, 2023
@kanavin
Copy link
Contributor Author

kanavin commented Aug 7, 2023

If you can tell how to regenerate that file, I can run tests locally with that.

@alex
Copy link
Member

alex commented Aug 7, 2023 via email

@kanavin
Copy link
Contributor Author

kanavin commented Aug 7, 2023

FWIW, the list of failing tests is:

Failed ptests:
{'python3-cryptography': ['tests/hazmat/primitives/test_pkcs7.py:TestPKCS7Builder.test_smime_sign_detached',
                          'tests/hazmat/primitives/test_pkcs7.py:TestPKCS7Builder.test_sign_byteslike',
                          'tests/hazmat/primitives/test_pkcs7.py:TestPKCS7Builder.test_sign_pem',
                          'tests/hazmat/primitives/test_pkcs7.py:TestPKCS7Builder.test_sign_alternate_digests_der[hash_alg0-\\x06\\t`\\x86H\\x01e\\x03\\x04\\x02\\x01]',
                          'tests/hazmat/primitives/test_pkcs7.py:TestPKCS7Builder.test_sign_alternate_digests_der[hash_alg1-\\x06\\t`\\x86H\\x01e\\x03\\x04\\x02\\x02]',
                          'tests/hazmat/primitives/test_pkcs7.py:TestPKCS7Builder.test_sign_alternate_digests_der[hash_alg2-\\x06\\t`\\x86H\\x01e\\x03\\x04\\x02\\x03]',
                          'tests/hazmat/primitives/test_pkcs7.py:TestPKCS7Builder.test_sign_attached',
                          'tests/hazmat/primitives/test_pkcs7.py:TestPKCS7Builder.test_sign_binary',
                          'tests/hazmat/primitives/test_pkcs7.py:TestPKCS7Builder.test_sign_smime_canonicalization',
                          'tests/hazmat/primitives/test_pkcs7.py:TestPKCS7Builder.test_sign_text',
                          'tests/hazmat/primitives/test_pkcs7.py:TestPKCS7Builder.test_sign_no_capabilities',
                          'tests/hazmat/primitives/test_pkcs7.py:TestPKCS7Builder.test_sign_no_attributes',
                          'tests/hazmat/primitives/test_pkcs7.py:TestPKCS7Builder.test_multiple_signers',
                          'tests/hazmat/primitives/test_pkcs7.py:TestPKCS7Builder.test_multiple_signers_different_hash_algs']}

@alex
Copy link
Member

alex commented Aug 7, 2023 via email

@reaperhulk
Copy link
Member

Regenerating this is a bit of a pain, but definitely doable. However, why set it to 2040? The 2038 bug is triggered for anything past 2038-01-19 and this certificate expires end of December 2038. So you should be able to confirm 2038 readiness without triggering expiry failures.

@kanavin
Copy link
Contributor Author

kanavin commented Aug 7, 2023

It's more about not having to think about what date to set (as long as it's this century), and also about fixing this just once, so this never has to be looked again in our lifetimes.

Where I can submit fixes, I set the expiry date to 2525 ( https://en.wikipedia.org/wiki/In_the_Year_2525 ):
curl/curl#11610
python/cpython#107594

@reaperhulk reaperhulk linked a pull request Dec 5, 2023 that will close this issue
@alex alex closed this as completed in #9964 Dec 5, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 5, 2024
brainhoard-github pushed a commit to distro-core-curated-mirrors/poky-contrib that referenced this issue Sep 7, 2024
A number of items are removed because the issues have already been resolved
with recipe patches (in separate commits).

Some issues were also resolved via upstream version updates:

glib-2.0 update to 2.78.0 that includes:
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3547
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3550

curl update to 8.3.0 that includes
curl/curl#11610

util-linux update to 2.39 that includes
util-linux/util-linux#2430
util-linux/util-linux@3ab9e69
util-linux/util-linux#2435

glib-networking update to 2.78.0 that includes
https://gitlab.gnome.org/GNOME/glib-networking/-/merge_requests/241

python3-cryptography update to 42.0.0 which resolves
pyca/cryptography#9370 via
pyca/cryptography#9964

perl update to 5.40.0 which resolves
Perl/perl5#21379

Signed-off-by: Alexander Kanavin <[email protected]>
brainhoard-github pushed a commit to distro-core-curated-mirrors/poky-contrib that referenced this issue Oct 17, 2024
A number of items are removed because the issues have already been resolved
with recipe patches (in separate commits).

Some issues were also resolved via upstream version updates:

glib-2.0 update to 2.78.0 that includes:
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3547
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3550

curl update to 8.3.0 that includes
curl/curl#11610

util-linux update to 2.39 that includes
util-linux/util-linux#2430
util-linux/util-linux@3ab9e69
util-linux/util-linux#2435

glib-networking update to 2.78.0 that includes
https://gitlab.gnome.org/GNOME/glib-networking/-/merge_requests/241

python3-cryptography update to 42.0.0 which resolves
pyca/cryptography#9370 via
pyca/cryptography#9964

perl update to 5.40.0 which resolves
Perl/perl5#21379

Signed-off-by: Alexander Kanavin <[email protected]>
brainhoard-github pushed a commit to distro-core-curated-mirrors/poky-contrib that referenced this issue Nov 15, 2024
A number of items are removed because the issues have been resolved
with recipe patches (in separate commits).

Some issues were also resolved via upstream version updates:

glib-2.0 update to 2.78.0 that includes:
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3547
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3550

curl update to 8.3.0 that includes
curl/curl#11610

util-linux update to 2.39 that includes
util-linux/util-linux#2430
util-linux/util-linux@3ab9e69
util-linux/util-linux#2435

glib-networking update to 2.78.0 that includes
https://gitlab.gnome.org/GNOME/glib-networking/-/merge_requests/241

python3-cryptography update to 42.0.0 which resolves
pyca/cryptography#9370 via
pyca/cryptography#9964

perl update to 5.40.0 which includes
Perl/perl5#21379

python3 update to 3.13.0 which includes
python/cpython#118425

tcl update to 9.0.0 which includes
tcltk/tcl@4ca6172
(tcl8 recipe has a simple backport of this)

Signed-off-by: Alexander Kanavin <[email protected]>
brainhoard-github pushed a commit to distro-core-curated-mirrors/poky-contrib that referenced this issue Jan 21, 2025
A number of items are removed because the issues have been resolved
with recipe patches (in separate commits).

Some issues were also resolved via upstream version updates:

glib-2.0 update to 2.78.0 that includes:
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3547
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3550

curl update to 8.3.0 that includes
curl/curl#11610

util-linux update to 2.39 that includes
util-linux/util-linux#2430
util-linux/util-linux@3ab9e69
util-linux/util-linux#2435

glib-networking update to 2.78.0 that includes
https://gitlab.gnome.org/GNOME/glib-networking/-/merge_requests/241

python3-cryptography update to 42.0.0 which resolves
pyca/cryptography#9370 via
pyca/cryptography#9964

perl update to 5.40.0 which includes
Perl/perl5#21379

python3 update to 3.13.0 which includes
python/cpython#118425
python3 update to 3.13.1 which includes
python/cpython#124972

tcl update to 9.0.0 which includes
tcltk/tcl@4ca6172
(tcl8 recipe has a simple backport of this)

dbus update to 1.16.0 which includes
https://gitlab.freedesktop.org/dbus/dbus/-/merge_requests/444
https://gitlab.freedesktop.org/dbus/dbus/-/merge_requests/289

Signed-off-by: Alexander Kanavin <[email protected]>
brainhoard-github pushed a commit to distro-core-curated-mirrors/poky-contrib that referenced this issue Feb 17, 2025
A number of items are removed because the issues have been resolved
with recipe patches (in separate commits).

Some issues were also resolved via upstream version updates:

glib-2.0 update to 2.78.0 that includes:
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3547
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3550

curl update to 8.3.0 that includes
curl/curl#11610

util-linux update to 2.39 that includes
util-linux/util-linux#2430
util-linux/util-linux@3ab9e69
util-linux/util-linux#2435

glib-networking update to 2.78.0 that includes
https://gitlab.gnome.org/GNOME/glib-networking/-/merge_requests/241

python3-cryptography update to 42.0.0 which resolves
pyca/cryptography#9370 via
pyca/cryptography#9964

perl update to 5.40.0 which includes
Perl/perl5#21379

python3 update to 3.13.0 which includes
python/cpython#118425
python3 update to 3.13.1 which includes
python/cpython#124972

tcl update to 9.0.0 which includes
tcltk/tcl@4ca6172
(tcl8 recipe has a simple backport of this)

dbus update to 1.16.0 which includes
https://gitlab.freedesktop.org/dbus/dbus/-/merge_requests/444
https://gitlab.freedesktop.org/dbus/dbus/-/merge_requests/289

Signed-off-by: Alexander Kanavin <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

3 participants