-
-
Notifications
You must be signed in to change notification settings - Fork 140
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
Misbehaving URIs #195
Comments
Sounds related to #33. https://github.com/wbond/asn1crypto/blob/master/asn1crypto/_iri.py should contain the code which modifies your URIs. |
I tracked it down to use of urlunsplit from urllib/parse.py. If I add 'ldap' to its uses_netloc list, then it produces the correct output. urllib has no specific support for an ldap uri. As much as I would love to kick ldap to the curb myself, this seems somewhat problematic given ldap is definitely still in use for PKI, particularly PKI from Redmond. I haven't followed these changes, but do we really need this level of data manipulation (i.e. breaking every URI into all its components and reassembling them) to populate the .native field? Perhaps it's not unreasonable to assume URIs should be processed using whatever library is responsible for handling the scheme outside of the certificate implementation. At this point the only resolution I can see is getting support for ldap in urllib, or, not using this functionality from urllib, at least not in the way it's being used today. |
The I would imagine we should be able to fix the issue with the ldap URIs without too much work.
In this case, I would say the |
Thanks Will, using .contents is in fact exactly what I did on the read side. The reason this behavior became more problematic for me was the tbs.dump(force=True) resulted in an invalid URL in the output. For now I have sidestepped the observed problem by adding urllib.parse.uses_netloc.append('ldap') to my own |
If you've got a fix and the time to submit it, I'm sure @joernheissler or myself can review it. More robust tests for ldap is certainly welcome if you've got some fixtures you can provide. |
A full test case, or even just a certificate, would help too. |
I do have that band-aide.. not sure runtime modification of urllib's behavior rises to the level of fix? All I did was add this:
Attached is a sample domain controller certificate with affected URIs in both CRLDP and AIA. I'm afraid I don't have time to dedicate to adding tests right now, but I may be able to carve out some time over the holidays. |
Hi,
|
I’m happy to review a PR for this if it includes tests. |
Incidentally, there's a separate but related issue that will cause capitalisation in certain parts of an URI to be normalised when So, while I agree that the parsing issue needs to be fixed, I'd potentially approach the reencoding part of the story a little more generally: IMO the behaviour of What do you think? |
After some investigation today I found a bug, that causes exhibition of this URI LDAP bug. So maybe another issue should be created for it. This problem with ldap slashes should not occur in normal situation after loading of a X509 certificate, because it is DER encoded and there is no reason for its reencoding. I have 851 certificates in AD and failure occurs for 6 of them. By tracing of parsing X509 certificates affected and not affected by the bug a difference is on the lines
The above code is in
The contents length is 2176 (0x880) octets. The condition above tries probably detect indefinite encoding, but indefinite encoding has value 0x80 at the first and only length octet, not last octet if I comprehend correctly BER. |
That sounds like a possible bug, but the core bug here is that the DER re-encoding is changing the URL due to a bug in the Python URL functionality in the stdlib. |
Yes the issue is already created #249 ... |
It seems that when a certificate contains a URI that lacks a hostname (e.g. ldap:///cn=xyz) there is some misbehavior decoding it. Specifically, the .native ends up with "ldap:/cn=xyz" - two of the three slashes were removed. calling tbs_cert.dump(force=True) also results in the URI being encoded with only one slash. I spent a little time stepping into the code, but quickly became frustrated trying to figure out where it was coming from. I'm hoping you'll read this and say 'Aha I know exactly why that is happening' and be able to easily patch it.
The text was updated successfully, but these errors were encountered: