1

I have been looking for a way to convert the ObjectGuid out of Active Directory is a special type that gets converted to a string, which is odd looking, using libraries such as ldapjs and or adding it as a claim using ping federate. An example of this is the following:

const ldapjs = require("ldapjs");
let _client = ldapjs.createClient({
        "url": this._ldap_uri
      });
_client.search(this._search_dn, opts, (error, res) => {
          res.on("searchEntry", (entry) => {
              console.log(entry.object.objectGUID)
          }

Here is an example of the output that comes out of ldapjs. The same comes out of a ping federate when you add it as a claim.

H�Y��fB�_-_���

However, this is equivalent to a valid UUID.

b9****48-6***-42**-a**f-2d5f*****40b

What I am trying to do is convert this strange value to a the correct UUID. I have scoured and tested a few different postings and websites but I have not found a valid solution.

Here are a few I researched:

If anyone has a solution to this it would be appreciated.

thxmike
  • 614
  • 1
  • 7
  • 25
  • Can you show the code you used to get the value you're seeing? Did you try the code in the answer to the [Read objectGUID from active directory](https://stackoverflow.com/questions/46810881/read-objectguid-from-active-directory) question? – Gabriel Luci Jul 16 '19 at 13:32
  • @GabrielLuci - This comes straight out of PING federate as a JWT claim and the client library ldapjs library in this format so there is not much to show. However, I will add more information if it would be helpful – thxmike Jul 16 '19 at 16:23
  • I ended up working with the PING federate administrator and they were able to convert it to Hex encoded format, which allowed me to convert it to a UUID. This solves the immediate problem but it would be nice to have an solution to the conversion problem – thxmike Oct 16 '19 at 21:30
  • That "strange value" just looks like a byte array. Did you try the code in [that other answer](https://stackoverflow.com/a/46812034/1202807)? Particularly the `.toString('hex').replace( ... )`. If that doesn't work, I think the question you really need the answer to is how do you convert a GUID byte array to a string. – Gabriel Luci Oct 16 '19 at 22:09

1 Answers1

0

experiment with this code (read GUID) :

String.prototype.padLeft = function( len, str ) {
        //return Array( len - String(this).length + 1 ).join(str) + this;
        var s = this;
        str = str || '0';
        if ( str.length > 0 ) {
            while ( s.length < len ) {
                s = ( str + s );
            };
        }
        return s;
    }

var destAD = GetObject("LDAP://dc.yourdomain.pl/cn=Administrator,cn=Users,dc=yourdomain,dc=pl");
var guidValueArr = destAD.Get("objectguid").toArray();
var guid = "", i;
for ( i = 0; i < guidValueArr.length; i ++ ) {
    guid += guidValueArr[i].toString(16).padLeft(2,"0");
}
var guidFormated = guid.replace(/(.{2})(.{2})(.{2})(.{2})(.{2})(.{2})(.{2})(.{2})(.{4})(.{12})/, "$4$3$2$1-$6$5-$8$7-$9-$10");
alert( guidFormated );

Universally unique identifier

Paweł Piwowar
  • 174
  • 2
  • 8