walking
walking

Reputation: 960

What UUID algorithm do Android and iPhone use for advertising IDs?

I've read about the different versions of UUIDs available and in some UUIDs you can reverse-engineer the timestamp the UUID was generated by extracting several bits from the string.

I've successfully managed to do that for uuid1 but failed for Android and iPhone advertising ids.
I'm assuming they don't use uuid1 in that case, but what IS the UUID generating algorithm they use? can the timestamp be extracted from it?

Thanks!

in the code below you can see my failed attempt at extracting the timestamp from Android Ad ID.

from datetime import timedelta, date

def get_timestamp_from_uuid(uid):
    split_uid = uid.split("-")

    time_low = bin(int(split_uid[0], 16)).replace('0b', '').zfill(32)
    time_mid = bin(int(split_uid[1], 16)).replace('0b', '').zfill(16)
    time_high = bin(int(split_uid[2], 16)).replace('0b', '').zfill(16)[4:]

    interval = int(time_high + time_mid + time_low, 2) / (10 ** 7) 
    return date(1582, 10, 15) + timedelta(seconds = interval)

my_uuids = [
    "590512f6-16ed-11ed-9181-98e0d987bee7", # random uuid1
    "07810065-6ba3-4d07-89b4-472af4a3d77f"  # my android advertising id   
]

get_timestamp_from_uuid(my_uuids[0])
# 2022-08-08

get_timestamp_from_uuid(my_uuids[1])
# 4557-11-04

Upvotes: 2

Views: 880

Answers (1)

Jordan Breton
Jordan Breton

Reputation: 1327

You can check the UUID version by watching the first digit of the third block, starting from the left :

590512f6-16ed- **1** 1ed-9181-98e0d987bee7 -> version 1

07810065-6ba3- **4** d07-89b4-472af4a3d77f -> version 4

While UUID V1 are time based, UUID v4 are completly random. Thus, you can't extract any usefull information from them, apart their version number.

If you want to extract some data from UUIDs, you must first check their version. All UUIDs are not time-based.

To summarize :

  • Version 1 : mac address of the generator + timestamp
  • Version 2 : Distributed Computing environment based on posix UIDs
  • Version 3 : md5 hash of a specific name, thus it will be always identical with the same generation name
  • Version 4 : Totaly random
  • Version 5 : Same as version 3, but with sha1 algorythm
  • Version 6 : Not official. It's a mix between version 1 and version 4 : semi-sequential random UUIDs are usefull to take advantages of indexes in relational databases. The first part is time-based, the last one is random.

The V6 is not official, and I don't remember where I found documentation about it, it was a long-time ago.

It's not as efficient as v4 to be sure to get a unique identifier if you generate enough of them in a very short period of time, but in most cases, it's sufficient.

Upvotes: 2

Related Questions