go-ldap / ldap

Basic LDAP v3 functionality for the GO programming language.
Other
2.19k stars 352 forks source link

fix: Replace DER with ASN1 BER encoding when parsing distinguishedNames #505

Closed cpuschma closed 2 months ago

cpuschma commented 2 months ago

This PR replaces the Go asn1 library in the decodeEncodedString function to decode values with ASN1 BER instead. The replacement of the returned error should be ok, as there hasn't been a release with the new implementation of `ParseDN' yet.

See RFC4514 Section 2.4:

If the AttributeType is of the dotted-decimal form, the AttributeValue is represented by an number sign ('#' U+0023) character followed by the hexadecimal encoding of each of the octets of the BER encoding of the X.500 AttributeValue. This form is also used when the syntax of the AttributeValue does not have an LDAP- specific ([RFC4517], Section 3.1) string encoding defined for it, or the LDAP-specific string encoding is not restricted to UTF-8-encoded Unicode characters. This form may also be used in other cases, such as when a reversible string representation is desired (see Section 5.2).

inteon commented 2 months ago

@cpuschma FYI: I found a fix for the bug in the ber package that causes the high memory usage: https://github.com/go-asn1-ber/asn1-ber/pull/42

cpuschma commented 2 months ago

I don't have permissions to review and merge your PR in go-asn1-ber. @johnweldon Can you have a look?