On 03/23/2015 09:57 AM, Jim Willeke wrote:
> Well, our scenario is in a large LDAP instance (>25M), where they (against
> my advice) allow the user to make up the RDN.
>
> When the user returns to the site and provides "valuewithnulls" as the
> userid (We assume they did not mean to enter the nulls) a LDAP search is
> done for the user, (uid=valuewithnulls), which fails.
>
> Our objective is to identify these "value\00with\00nulls" and rename them
> to "valuewithnulls".
>
> -jim
OK. So the issue is trying to use a value with nulls in a search filter
rather than in a DN or RDN. In that case, the LDAP SDK makes it easy to
construct the filter. If you have "value\u0000with\u0000nulls" as a
string or as a byte array, then the best way to construct a filter in
which the string representation has the appropriate spacing is to use:
Filter searchFilter = Filter.createEqualityFilter("uid",
"value\u0000with\u0000nulls");
If you call the toString() method on this filter, then you will get the
properly-escaped filter (uid=value\00with\00nulls). However, it is
important to note that LDAP filters aren't transferred between the
client and the server as strings but rather as binary values and in that
case no escaping is required.
At any rate, the best way to create any kind of filter in an
LDAP-enabled application is to use the Filter.create* methods instead of
trying to construct a filter yourself using the string representation.
This is true for two reasons:
- The LDAP SDK will always perform the appropriate escaping for any
special characters contained in the assertion value. This can help
thwart attacks from clients trying to use the LDAP equivalent of an SQL
injection (e.g., by trying to trick the application into performing a
substring or presence search when the intent was to perform an equality
search).
- It is faster. The LDAP SDK doesn't have to parse the string
representation in order to get the components to use in the binary encoding.
>
>
> ᐧ
>
> --
> -jim
> Jim Willeke
>
> On Thu, Mar 19, 2015 at 4:17 PM, Neil A. Wilson <nei...@un...>
> wrote:
>
>> On 03/19/2015 01:39 PM, Jim Willeke wrote:
>>> Trying to find a method to obtain RDN value which contain null values.
>>>
>>> If I use,
>>>
>>> byte[] uidBytes = entry.getAttributeValueBytes("uid");
>>>
>>> It appears the nulls appears as "." (periods)
>>>
>>> What am I missing?
>>>
>>> --
>>> -jim
>>> Jim Willeke
>>> ᐧ
>>
>> From the context of your question, it sounds like you're talking about
>> values that contain the null character (whose UTF-8 representation is a
>> single byte with all bits set to zero, and is represented with the
>> Unicode escape sequence \u0000), rather than attributes that don't have
>> values at all or attributes with zero-length values. For example, the
>> Java string "value\u0000with\u0000nulls".
>>
>> If you use this in a DN, then the correct encoding is to escape the
>> hexadecimal representation of each byte in the UTF-8 representation. So
>> if you have an RDN with an attribute type of uid and a value that is
>> "value\u0000with\u0000nulls", then the correct string representation of
>> that would be "uid=value\00with\00nulls". If you create a DN like:
>>
>> ByteStringBuffer valueBuffer = new ByteStringBuffer();
>> valueBuffer.append("value");
>> valueBuffer.append((byte) 0x00);
>> valueBuffer.append("with");
>> valueBuffer.append((byte) 0x00);
>> valueBuffer.append("nulls");
>>
>> DN dn = new DN(
>> new RDN("uid", valueBuffer.toByteArray()),
>> new RDN("ou", "People"),
>> new RDN("dc", "example"),
>> new RDN("dc", "com"));
>>
>> then calling dn.toString() will result in:
>>
>> uid=value\00with\00nulls,ou=People,dc=example,dc=com
>>
>>
>> But if you're talking about the attribute as it appears in the entry,
>> then no special encoding is required for LDAP communication (the LDIF
>> representation would require the value to be base64-encoded). For
>> example, if you create an entry like:
>>
>> Entry e = new Entry(dn,
>> new Attribute("objectClass", "top", "person",
>> "organizationalPerson", "inetOrgPerson"),
>> new Attribute("uid", valueBuffer.toByteArray()),
>> new Attribute("givenName", "Test"),
>> new Attribute("sn", "User"),
>> new Attribute("cn", "Test User"));
>>
>> then calling e.getAttributeValueByte("uid") will return a byte array
>> with the following contents:
>>
>> 76 61 6c 75 65 00 77 69 74 68 00 6e 75 6c 6c 73
>>
>> In this case, the nulls are properly represented as bytes of 0x00.
>>
>> This is also the case for an entry retrieved from a directory server
>> over LDAP rather than one that is constructed in Java code.
>>
>> Could you provide an example of the behavior that you're seeing?
>>
>>
>>
>> Neil
>>
>>
>>
>
>
>
> ------------------------------------------------------------------------------
> Dive into the World of Parallel Programming The Go Parallel Website, sponsored
> by Intel and developed in partnership with Slashdot Media, is your hub for all
> things parallel software development, from weekly thought leadership blogs to
> news, videos, case studies, tutorials and more. Take a look and join the
> conversation now. http://goparallel.sourceforge.net/
>
>
>
> _______________________________________________
> ldap-sdk-discuss mailing list
> lda...@li...
> https://lists.sourceforge.net/lists/listinfo/ldap-sdk-discuss
>
|