question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

objectGUID: Buffer encoding issue

See original GitHub issue

Hey there, seems like the returned objectGUID during a search on the active directory has an encoding issue.

Once returned and converted to a readable UUID, it doesn’t matched the real value provided by the AD. Is it a know issue or something wrong on my side?

Search response:

// Excepted
{ objectGUID: 'â\u0018!;œóì@¯Wa8–`ß' }
// 3b2118e2-f39c-40ec-af57-6190389660df

// Returned
{ objectGUID: '�\u0018!;���@�Wa�8�`�' }
// 3b2118fd-fdfd-40fd-fd57-61fd38fd60fd

Temporary workaround:

export const formatEntry = entryObject => {
    const { object, attributes } = entryObject;
    const objectGUIDAttribute = attributes.find(
        attr => attr.type === 'objectGUID'
    );

    return {
        ...object,
        objectGUID: Buffer.from(
            objectGUIDAttribute.buffers[0],
            'hex'
        ).toString('binary')
    };
};

Convert objectGUID to readable UUID:

export const objectGUIDToUUID = objectGUID => {
    const hex = Buffer.from(objectGUID, 'binary').toString('hex');

    const p1 =
        hex.substr(-26, 2) +
        hex.substr(-28, 2) +
        hex.substr(-30, 2) +
        hex.substr(-32, 2);

    const p2 = hex.substr(-22, 2) + hex.substr(-24, 2);
    const p3 = hex.substr(-18, 2) + hex.substr(-20, 2);
    const p4 = hex.substr(-16, 4);
    const p5 = hex.substr(-12, 12);

    return [p1, p2, p3, p4, p5].join('-');
};

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:13 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
crazyx13thcommented, Jul 21, 2021

this is my small transfer-function (you can remove the comment… only for understanding)

export const objectGUIDToUUID = (objectGUID)=>
{
  const hexValue = Buffer.from(objectGUID, 'binary').toString('hex')

  return hexValue.replace(
  //   (   $1:A4   )(   $2:A3   )(   $3:A2   )(   $4:A1   )(   $5:B2   )(   $6:B1   )(   $7:C2   )(   $8:C1   )(   $9:D    )(   $10:F    )
      /([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{4})([0-9a-f]{10})/,
      '$4$3$2$1-$6$5-$8$7-$9-$10',
  )
}
2reactions
tastypacketscommented, Apr 2, 2020

Could this issue possibly be revisited? The binary data gets converted as a UTF-8 string, which does not translate 1-to-1 with raw binary data, because the leading bits contain meta data. Bytes with a decimal value < 128 will work fine, but the other half will not; which is why some of the values in the GUID look fine but others get changed in unexpected (and apparently unrecoverable) ways.

You can get the bin data from attributes on the response.

Like this:

const binaryGUID = entry.attributes.find(attribute => attribute.type === 'objectGUID').buffers[0]
Read more comments on GitHub >

github_iconTop Results From Across the Web

objectGUID: Buffer encoding issue #481 - ldapjs/node-ldapjs
Hey there, seems like the returned objectGUID during a search on the active directory has an encoding issue.
Read more >
encoding - Issue with ldapjs and string base64 format
I have a LDAP server and the users have a property which is a jpeg photo in base64 format. When I search for...
Read more >
Chapter 4, Searching and Manipulating Objects - O'Reilly
Connecting to an Object GUID. Problem. You want to bind to a container using its Globally Unique Identifier (GUID) ...
Read more >
Buffer | Node.js v19.3.0 Documentation
When encoding a Buffer to a string, this encoding will omit padding. 'hex' : Encode each byte as two hexadecimal characters. Data truncation...
Read more >
How was this value of ObjectGUID encoded? - Super User
I basically have to decode the applications encoding of objectGUID .. to identify the corresponding MSAD entries.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found