Do not assume that ASN1_STRING is null terminated. - #1529
Conversation
The OpenSSL docs say: > In general it cannot be assumed that the data returned by > ASN1_STRING_data() is null terminated or does not contain embedded > nulls. The actual format of the data will depend on the actual string > type itself: for example for an IA5String the data will be ASCII, for a > BMPString two bytes per character in big endian format, and for a > UTF8String it will be in UTF8 format. This ASN1 timestamp function was the only remaining function in pyOpenSSL that assumed null termination.
alex
left a comment
There was a problem hiding this comment.
is it possible to add a test case?
Good question; right now I do not know how to best test this. The only "official" way to create such a string right now (before the planned change to BoringSSL that will make all strings like this) is using |
|
Is it possible to construct this scenario with our public APIs? |
|
It is not possible to use public APIs to construct this scenario, as pyOpenSSL nowhere calls Both BoringSSL and OpenSSL have been holding off from ever making a non null terminated Relevant comments: BoringSSL OpenSSL has in the same place: Here's my problem now: this sounds like the pyOpenSSL code is already broken right now against current OpenSSL:
As such, I strongly suspect that pyOpenSSL is already broken with existing tests (assuming we at least sometimes have an |
|
Gotcha, so this is correctness/hardening, but not bug fix. |
|
Thanks! |
|
Oh, and the reason why this wasn't hit yet: OpenSSL only moved to not null terminating all ASN1_STRINGs in commit 28179061bfcdfe579f63a129bf0b97766a5d90a7, which is in no released version yet. |
The OpenSSL docs say:
This ASN1 timestamp function was the only remaining function in pyOpenSSL that assumed null termination.