awslabs / awslabs/aws-crt-python

Test failures in test_crypto.py on CentOS Stream 9

Open
#677 4 comments 0 reactions 0 assignees View on GitHub
bug needs-triage
Dominant language
Python
Stars
100
Forks
58
Avg merge
13h 51m
Merged PRs (30d)
2

Description

### Describe the bug

Package fails to build on CentOS Stream 9 - tests in test_crypto.py are failing with `AWS_ERROR_CAL_MALFORMED_ASN1_ENCOUNTERED`

### Regression Issue

- [ ] Select this option if this issue appears to be a regression.

### Expected Behavior

- Tests pass
- RPM builds successfully

### Current Behavior

tests in test_crypto.py are failing with errors:

``` ======================================================================
ERROR: test_rsa_encryption_roundtrip_pkcs8 (test.test_crypto.TestCredentials) [RSA Encryption Roundtrip using algo p] (p=)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/awscrt-0.27.2/test/test_crypto.py", line 212, in test_rsa_encryption_roundtrip_pkcs8
rsa = RSA.new_private_key_from_pem_data(RSA_PRIVATE_KEY_PEM_PKCS8)
File "/home/awscrt-0.27.2/awscrt/crypto.py", line 116, in new_private_key_from_pem_data
return RSA(binding=_awscrt.rsa_private_key_from_pem_data(pem_data))
RuntimeError: 7172 (AWS_ERROR_CAL_MALFORMED_ASN1_ENCOUNTERED): An ASN.1 DER decoding operation failed on malformed input.

======================================================================
ERROR: test_rsa_encryption_roundtrip_pkcs8 (test.test_crypto.TestCredentials) [RSA Encryption Roundtrip using algo p] (p=)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/awscrt-0.27.2/test/test_crypto.py", line 212, in test_rsa_encryption_roundtrip_pkcs8
rsa = RSA.new_private_key_from_pem_data(RSA_PRIVATE_KEY_PEM_PKCS8)
File "/home/awscrt-0.27.2/awscrt/crypto.py", line 116, in new_private_key_from_pem_data
return RSA(binding=_awscrt.rsa_private_key_from_pem_data(pem_data))
RuntimeError: 7172 (AWS_ERROR_CAL_MALFORMED_ASN1_ENCOUNTERED): An ASN.1 DER decoding operation failed on malformed input.

======================================================================
ERROR: test_rsa_encryption_roundtrip_pkcs8 (test.test_crypto.TestCredentials) [RSA Encryption Roundtrip using algo p] (p=)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/awscrt-0.27.2/test/test_crypto.py", line 212, in test_rsa_encryption_roundtrip_pkcs8
rsa = RSA.new_private_key_from_pem_data(RSA_PRIVATE_KEY_PEM_PKCS8)
File "/home/awscrt-0.27.2/awscrt/crypto.py", line 116, in new_private_key_from_pem_data
return RSA(binding=_awscrt.rsa_private_key_from_pem_data(pem_data))
RuntimeError: 7172 (AWS_ERROR_CAL_MALFORMED_ASN1_ENCOUNTERED): An ASN.1 DER decoding operation failed on malformed input.

======================================================================
ERROR: test_rsa_signing_roundtrip_pkcs8 (test.test_crypto.TestCredentials) [RSA Signing Roundtrip using algo p] (p=)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/awscrt-0.27.2/test/test_crypto.py", line 264, in test_rsa_signing_roundtrip_pkcs8
rsa = RSA.new_private_key_from_pem_data(RSA_PRIVATE_KEY_PEM_PKCS8)
File "/home/awscrt-0.27.2/awscrt/crypto.py", line 116, in new_private_key_from_pem_data
return RSA(binding=_awscrt.rsa_private_key_from_pem_data(pem_data))
RuntimeError: 7172 (AWS_ERROR_CAL_MALFORMED_ASN1_ENCOUNTERED): An ASN.1 DER decoding operation failed on malformed input.

======================================================================
ERROR: test_rsa_signing_roundtrip_pkcs8 (test.test_crypto.TestCredentials) [RSA Signing Roundtrip using algo p] (p=)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/awscrt-0.27.2/test/test_crypto.py", line 264, in test_rsa_signing_roundtrip_pkcs8
rsa = RSA.new_private_key_from_pem_data(RSA_PRIVATE_KEY_PEM_PKCS8)
File "/home/awscrt-0.27.2/awscrt/crypto.py", line 116, in new_private_key_from_pem_data
return RSA(binding=_awscrt.rsa_private_key_from_pem_data(pem_data))
RuntimeError: 7172 (AWS_ERROR_CAL_MALFORMED_ASN1_ENCOUNTERED): An ASN.1 DER decoding operation failed on malformed input.

======================================================================
ERROR: test_rsa_signing_roundtrip_pkcs8 (test.test_crypto.TestCredentials)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/awscrt-0.27.2/test/__init__.py", line 56, in tearDown
check_for_leaks(timeout_sec=TIMEOUT)
File "/home/awscrt-0.27.2/awscrt/_test.py", line 146, in check_for_leaks
raise RuntimeError("awscrt leak check failed. {} NativeResource objects. {} bytes native memory".format(
RuntimeError: awscrt leak check failed. 0 NativeResource objects. 40 bytes native memory

----------------------------------------------------------------------
Ran 18 tests in 30.165s
FAILED (errors=6)
```

### Reproduction Steps

Can be reproduced in a CentOS Stream 9 container:

- Run the container
`podman run --rm -it centos:stream9 /bin/bash`

- Download the sources from PyPI
`curl -LO https://files.pythonhosted.org/packages/2c/6d/570d1feba08c1006c8f47de3725e87b7b968a875e52a792b74d6598bef08/awscrt-0.27.2.tar.gz`

- Apply [this patch](https://src.fedoraproject.org/rpms/python-awscrt/blob/rawhide/f/skip-SHA1-in-test_crypto.patch) to get past SHA1 issues mentioned in [related issue](https://github.com/awslabs/aws-crt-python/issues/668)
`patch -p1 < skip-SHA1-in-test_crypto.patch`

- Install dependencies
`dnf install gcc gcc-c++ cmake openssl-devel python3-devel python3-pip`
`pip install wheel`

- Build the package specifying build flags from CentOS Stream 9 and enabling OpenSSL
`CFLAGS="-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -march=x86-64-v2 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection" AWS_CRT_BUILD_USE_SYSTEM_LIBCRYPTO=1 python3 -m pip wheel --no-deps --use-pep517 --no-build-isolation --disable-pip-version-check --no-clean --progress-bar off --verbose .`

- Run the tests
`PYTHONPATH=$(pwd)/build/lib.linux-x86_64-3.9 python3 -m unittest test/test_crypto.py`

### Possible Solution

_No response_

### Additional Information/Context

The same issue can be observed on Fedora, but only on i686, on CentOS Stream 9 it happens on all - x86_64, aarch64, and ppc64le

### aws-crt-python version used

0.27.2

### Python version used

3.9

### Operating System and version

CentOS Stream 9

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.