[vbox-dev] UUID's

James Lucas jimmy at secsme.org.au
Wed Aug 13 10:19:30 GMT 2008


Can someone from VirtualBox/Sun respond? This issue is incredibly 
annoying when developing an external authentication plugin.

I've used two different libraries in two different languages and they 
decode the VirtualBox binary string to the same UUID, however this 
string differs from the VirtualBox decoded string value.

Tests were:
1) Decode client side using libuuid (as explained previously)
2) Base64 encode value and send to the xmlrpc server. Decoded UUID using 
Java java.util.UUID

It appears that the binary representation has the most-significant bits 
(first 64 bits) in a different byte order than the other two libraries 
are expecting. A work around on server side was easy to implement. To me 
this is a bug if the binary storage of the UUID differs from the specs 
(which have a section on byte ordering)

- James

James Lucas wrote:
> Responding to my own post since i've done a little bit more investigation. I
> tend to think that there is an issue with the libuuid implemented in my code
> because the UUID version in the libuuid formatted string is wrong (most
> significant 4bits in 3rd group makes it version 6 not version 4)
>
> libuuid and virtual box seem to implement uuid string formatting a bit
> differently. The first 4 groups are handled differently.
>
> The first 3 groups are ordered differently prior to being printed. Group 4 is
> also ordered differently however Virtual Box prints the values out in a
> different order according to the comments so the byte ordering is undone via
> the print ordering. The 5th group are both implemented in the same byte order.
>
> (Virtual Box) pUuid->Gen.u16ClockSeq & 0xff pUuid->Gen.u16ClockSeq >> 8
> (Libuuid) uuid.clock_seq >> 8, uuid.clock_seq & 0xFF
>
> It would be great if someone at Sun could comment on this because when
> implementing a custom VRDP authentication plugin you are passed a uuid 16 byte
> value and libuuid makes it easy to convert this to a string for further
> authorisation.
> The only other option is to link against the Virtual Box source however I don't
> have experience with cpp source and a c shared library (if at all possible).
>
> Host is Redhat 5u2 x64. Libuuid (e2fsprogs 1.39).
>
> Cheers,
>     James
>
> Relevant source information:
>
> Virtual Box UUID handing
> http://www.virtualbox.org/browser/trunk/src/VBox/Runtime/generic/uuid-generic.cpp
> function RTUuidToStr
>
> e2fsprogs sources (libuuid)
> void uuid_unpack(const uuid_t in, struct uuid *uu)
> {
>         const uint8_t   *ptr = in;
>         uint32_t                tmp;
>
>         tmp = *ptr++;
>         tmp = (tmp << 8) | *ptr++;
>         tmp = (tmp << 8) | *ptr++;
>         tmp = (tmp << 8) | *ptr++;
>         uu->time_low = tmp;
>
>         tmp = *ptr++;
>         tmp = (tmp << 8) | *ptr++;
>         uu->time_mid = tmp;
>
>         tmp = *ptr++;
>         tmp = (tmp << 8) | *ptr++;
>         uu->time_hi_and_version = tmp;
>
>         tmp = *ptr++;
>         tmp = (tmp << 8) | *ptr++;
>         uu->clock_seq = tmp;
>
>         memcpy(uu->node, ptr, 6);
> }
>
> static const char *fmt_lower =
>         "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x";
>
> static void uuid_unparse_x(const uuid_t uu, char *out, const char *fmt)
> {
>         struct uuid uuid;
>
>         uuid_unpack(uu, &uuid);
>         sprintf(out, fmt,
>                 uuid.time_low, uuid.time_mid, uuid.time_hi_and_version,
>                 uuid.clock_seq >> 8, uuid.clock_seq & 0xFF,
>                 uuid.node[0], uuid.node[1], uuid.node[2],
>                 uuid.node[3], uuid.node[4], uuid.node[5]);
> }
>
> Quoting James Lucas <jimmy at secsme.org.au>:
>
>   
>> I'm converting the UUID as represented in VirtualBox in an external auth
>> plugin
>> from the 16 byte representation to a string representation using libuuid (On
>> linux)
>>
>> #include <uuid/uuid.h>
>> char * uuidtemp;
>> uuid_unparse(*pUuid, uuidtemp);
>>
>> Expected results (UUID of machine)
>> 2947d043-0e43-4d6a-4aa5-5488b4af1c32
>>
>> Actual
>> 43d04729-430e-6a4d-4aa5-5488b4af1c32
>>
>> The first three fields are byte swapped. Looking through the VBox source
>> code
>> uuid conversion has been implemented internally and doesn't use an external
>> library (I'm assume portability reasons). Why would the Byte->toString
>> methods
>> differ between VBox internal and libuuid? The VBox sources refer to ext2
>> implementation and libuuid implements to same.
>>
>> I'm sure there is a simple reason, however I'd like to confirm before I put
>> in
>> place some workaround code that may break in the future.
>>
>> Regards,
>>     James
>>
>>     

--
UTS CRICOS Provider Code:  00099F
DISCLAIMER: This email message and any accompanying attachments may contain
confidential information.  If you are not the intended recipient, do not
read, use, disseminate, distribute or copy this message or attachments.  If
you have received this message in error, please notify the sender
immediately and delete this message. Any views expressed in this message
are those of the individual sender, except where the sender expressly, and
with authority, states them to be the views the University of Technology,
Sydney. Before opening any attachments, please check them for viruses and
defects.




More information about the vbox-dev mailing list