-
Notifications
You must be signed in to change notification settings - Fork 33
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
Zeros embedded in subject and issuer fields when using certificates generated with makecert (e.g. self-signed for test-signing during driver development) #95
Comments
Thanks for the report! Yeah, I'm not sure if there's a great option for us here:
So, two ideas I have:
Thoughts? |
Ah, never mind -- I forgot that we call |
Isn't |
It's supported by both: from the OpenSSL docs:
From My understanding is that flag should work, but there might be other flags that have similar behavior that have better/more suitable behavior. I haven't gone through all of them 🙂 |
Yep, it does work. PR incoming for that one. |
Ouch, this is trickier than I thought. Getting the name out isn't a problem. But getting it out in the old form is. I can't seem to come up with a combination of flags that could emulate the old behavior of The flag that would seem to make most sense —
The flag
Original form with
The most notable difference being the inverse order. In other words, without going through hoops it will be hard to retain backwards-compatibility. I reckon the correct approach would use One method that may work would be
Without that it still looks like this:
Please advise, @woodruffw ... This code may come in handy when trying it out: static inline bool name_to_string(std::string& strname, X509_NAME *name, unsigned long flags)
{
std::unique_ptr<BIO, decltype(&BIO_free)> name_bio(BIO_new(BIO_s_mem()), BIO_free);
// auto nameptr = impl::OpenSSL_ptr(X509_NAME_oneline(name, nullptr, 0), impl::OpenSSL_free);
// strname = std::string(nameptr.get());
if (-1 != X509_NAME_print_ex(name_bio.get(), name, 0, (flags) & ~(ASN1_STRFLGS_ESC_MSB)))
{
char* data = nullptr;
auto len = BIO_get_mem_data(name_bio.get(), &data);
strname = std::string(data, len);
return true;
}
return false;
} |
Hmm, that's unfortunate. I'm of two minds on this:
So, I think we should do two things here:
For now, (1) is probably fine though. (2) is something we can consider if users actually complain and want low-level access to each name component. |
- Certificate got another ctor which takes the flags to pass when formatting the X509_NAME values - The default formatting changed to XN_FLAG_RFC2253 but can be overridden from the outside by defining UTHENTICODE_DEFAULT_XN_FLAGS - This introduces an incompatibility _if_ the caller assumes that the issuer and subject can be compared in their string form
- Certificate got another ctor which takes the flags to pass when formatting the X509_NAME values - The default formatting changed to XN_FLAG_RFC2253 but can be overridden from the outside by defining UTHENTICODE_DEFAULT_XN_FLAGS - This introduces an incompatibility _if_ the caller assumes that the issuer and subject can be compared in their string form
- Certificate got another ctor which takes the flags to pass when formatting the X509_NAME values - The default formatting changed to XN_FLAG_RFC2253 but can be overridden from the outside by defining UTHENTICODE_DEFAULT_XN_FLAGS - This introduces an incompatibility _if_ the caller assumes that the issuer and subject can be compared in their string form
- Certificate got another ctor which takes the flags to pass when formatting the X509_NAME values - The default formatting changed to XN_FLAG_RFC2253 but can be overridden from the outside by defining UTHENTICODE_DEFAULT_XN_FLAGS - This introduces an incompatibility _if_ the caller assumes that the issuer and subject can be compared in their string form
- Certificate got another ctor which takes the flags to pass when formatting the X509_NAME values - The default formatting changed to XN_FLAG_RFC2253 but can be overridden from the outside by defining UTHENTICODE_DEFAULT_XN_FLAGS - This introduces an incompatibility _if_ the caller assumes that the issuer and subject can be compared in their string form
It appears as if
makecert
writes Windows-stylewchar_t*
into these fields verbatim instead of encoding them as, say, UTF-8. This is an issue as it will lead to the strings being interpreted as single-character string, given every other character is a zero byte.I worked around this locally by creating a function that filters these:
... and using that in the ctor (
Certificate::Certificate
):Not sure this is an issue you'll want to address at all, since it appears that MS and its
makecert
tool deviate from the standard here. Just wanted to bring this to your attention as well as to the attention of those watching the project.Feel free to close this pretty much immediately.
PS: this isn't particularly optimized, because I only ever encountered this with those certificates created by
makecert
and we only use these in testing scenarios. But I'm sure there is still some room for improvement.The text was updated successfully, but these errors were encountered: