Skip to content

Conversation

reaperhulk
Copy link
Member

but raise a warning every time we see it. also proactively raise on
initial parse of the certificate, not just when accessing the
serial_number attribute

but raise a warning every time we see it. also proactively raise on
initial parse of the certificate, not just when accessing the
serial_number attribute
v: asn1::BigUint<'_>,
v: &'_ [u8],
) -> pyo3::PyResult<&'p pyo3::PyAny> {
let signed = big_byte_slice_is_negative(py, v)?;
Copy link
Member

Choose a reason for hiding this comment

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

This seems like a weird way to solve this, why not just take signed as a parameter that teh caller specifies based on context?

bytes: &'_ [u8],
) -> pyo3::PyResult<bool> {
if bytes[0] & 0x80 != 0 {
let cryptography_warning = py.import("cryptography.utils")?.getattr("DeprecatedIn36")?;
Copy link
Member

Choose a reason for hiding this comment

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

This is not the right place for this warning. This function has an ostensibly generic purpose and instead it's got behavior that's totally specific to serials.

cert_version(py, raw.borrow_value().tbs_cert.version)?;
// determine if the serial is negative and raise a warning if it is. We want to drop support
// for this sort of invalid encoding eventually.
big_byte_slice_is_negative(py, raw.borrow_value().tbs_cert.serial.as_bytes())?;
Copy link
Member

Choose a reason for hiding this comment

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

See! This functions behavior in no way matches it's name.

v: asn1::BigUint<'_>,
v: &'_ [u8],
) -> pyo3::PyResult<&'p pyo3::PyAny> {
warn_if_negative(py, v)?;
Copy link
Member

Choose a reason for hiding this comment

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

I still object to this being part of the behavior of `big_byte_slice_to_py_int.

Functions behavior should be predictable and well factored -- generic functions like type conversion shouldn't have context specific warnings like this. Just put warn_if_negative calls in the serial accessors. And please also name it warn_if_negative_serial based on the warning message.

reaperhulk and others added 2 commits November 20, 2021 09:48
alex
alex previously approved these changes Nov 20, 2021
@alex alex enabled auto-merge (squash) November 20, 2021 01:55
Ok(big_byte_slice_to_py_int(
py,
self.cert_id()?.serial_number.as_bytes(),
)?)
Copy link
Member

Choose a reason for hiding this comment

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

This is uncovered because of silliness. assign self.cert_id()?.serial_number.as_bytes() to a local var

@alex alex linked an issue Nov 20, 2021 that may be closed by this pull request
@alex alex merged commit 458e9eb into pyca:main Nov 20, 2021
@reaperhulk reaperhulk deleted the negative-serials branch October 9, 2022 18:07
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.

Unable to load certificate with negative serial number
2 participants