Subversion Repositories uuid_mac_utils

Rev

Rev 46 | Rev 48 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 46 Rev 47
Line 25... Line 25...
25
else if (file_exists($f = __DIR__ . '/mac_utils.inc.phps')) include_once $f;
25
else if (file_exists($f = __DIR__ . '/mac_utils.inc.phps')) include_once $f;
26
 
26
 
27
if (file_exists($f = __DIR__ . '/gmp_supplement.inc.php')) include_once $f;
27
if (file_exists($f = __DIR__ . '/gmp_supplement.inc.php')) include_once $f;
28
else if (file_exists($f = __DIR__ . '/gmp_supplement.inc.phps')) include_once $f;
28
else if (file_exists($f = __DIR__ . '/gmp_supplement.inc.phps')) include_once $f;
29
 
29
 
30
if (file_exists($f = __DIR__ . '/includes/OidDerConverter.class.php')) include_once $f;
30
if (file_exists($f = __DIR__ . '/OidDerConverter.class.php')) include_once $f;
31
else if (file_exists($f = __DIR__ . '/includes/OidDerConverter.class.phps')) include_once $f;
31
else if (file_exists($f = __DIR__ . '/OidDerConverter.class.phps')) include_once $f;
32
 
32
 
33
const UUID_NAMEBASED_NS_DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8'; // FQDN
33
const UUID_NAMEBASED_NS_DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8'; // FQDN
34
const UUID_NAMEBASED_NS_URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';
34
const UUID_NAMEBASED_NS_URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';
35
const UUID_NAMEBASED_NS_OID = '6ba7b812-9dad-11d1-80b4-00c04fd430c8';
35
const UUID_NAMEBASED_NS_OID = '6ba7b812-9dad-11d1-80b4-00c04fd430c8';
36
const UUID_NAMEBASED_NS_X500_DN = '6ba7b814-9dad-11d1-80b4-00c04fd430c8'; // "DER or text encoding" according to RFC4122bis
36
const UUID_NAMEBASED_NS_X500_DN = '6ba7b814-9dad-11d1-80b4-00c04fd430c8'; // "DER or text encoding" according to RFC4122bis
Line 331... Line 331...
331
                                        -  2 bit Variant (fix 0b10)
331
                                        -  2 bit Variant (fix 0b10)
332
                                        -  6 bit Clock Sequence High
332
                                        -  6 bit Clock Sequence High
333
                                        -  8 bit Clock Sequence Low
333
                                        -  8 bit Clock Sequence Low
334
                                        - 48 bit MAC Address
334
                                        - 48 bit MAC Address
335
                                        */
335
                                        */
336
                                        echo sprintf("%-32s %s\n", "Version:", "[6] Reordered Time");
336
                                        echo sprintf("%-32s %s\n", "Version:", "[0x6] Reordered Time-Based");
337
                                        $uuid = substr($uuid,  0, 8).'-'.
337
                                        $uuid = substr($uuid,  0, 8).'-'.
338
                                                substr($uuid,  8, 4).'-'.
338
                                                substr($uuid,  8, 4).'-'.
339
                                                substr($uuid, 12, 4).'-'.
339
                                                substr($uuid, 12, 4).'-'.
340
                                                substr($uuid, 16, 4).'-'.
340
                                                substr($uuid, 16, 4).'-'.
341
                                                substr($uuid, 20, 12);
341
                                                substr($uuid, 20, 12);
Line 354... Line 354...
354
                                        -  6 bit Clock Sequence High
354
                                        -  6 bit Clock Sequence High
355
                                        -  8 bit Clock Sequence Low
355
                                        -  8 bit Clock Sequence Low
356
                                        - 48 bit MAC Address
356
                                        - 48 bit MAC Address
357
                                        */
357
                                        */
358
 
358
 
359
                                        if ($version == 1) echo sprintf("%-32s %s\n", "Version:", "[1] Time-based with unique host identifier");
359
                                        if ($version == 1) echo sprintf("%-32s %s\n", "Version:", "[0x1] Time-based with unique host identifier");
360
 
360
 
361
                                        # Timestamp: Count of 100ns intervals since 15 Oct 1582 00:00:00
361
                                        # Timestamp: Count of 100ns intervals since 15 Oct 1582 00:00:00
362
                                        # 1/0,0000001 = 10000000
362
                                        # 1/0,0000001 = 10000000
363
                                        $timestamp = substr($uuid, 13, 3).substr($uuid, 8, 4).substr($uuid, 0, 8);
363
                                        $timestamp = substr($uuid, 13, 3).substr($uuid, 8, 4).substr($uuid, 0, 8);
364
                                        $ts = gmp_init($timestamp, 16);
364
                                        $ts = gmp_init($timestamp, 16);
Line 402... Line 402...
402
                                        - 48 bit MAC Address
402
                                        - 48 bit MAC Address
403
                                        */
403
                                        */
404
 
404
 
405
                                        // see also https://unicorn-utterances.com/posts/what-happened-to-uuid-v2
405
                                        // see also https://unicorn-utterances.com/posts/what-happened-to-uuid-v2
406
 
406
 
407
                                        echo sprintf("%-32s %s\n", "Version:", "[2] DCE Security version");
407
                                        echo sprintf("%-32s %s\n", "Version:", "[0x2] DCE Security version");
408
 
408
 
409
                                        # The clock_seq_low field (which represents an integer in the range [0, 28-1]) is interpreted as a local domain (as represented by sec_rgy_domain_t; see sec_rgy_domain_t ); that is, an identifier domain meaningful to the local host. (Note that the data type sec_rgy_domain_t can potentially hold values outside the range [0, 28-1]; however, the only values currently registered are in the range [0, 2], so this type mismatch is not significant.) In the particular case of a POSIX host, the value sec_rgy_domain_person is to be interpreted as the "POSIX UID domain", and the value sec_rgy_domain_group is to be interpreted as the "POSIX GID domain".
409
                                        # The clock_seq_low field (which represents an integer in the range [0, 28-1]) is interpreted as a local domain (as represented by sec_rgy_domain_t; see sec_rgy_domain_t ); that is, an identifier domain meaningful to the local host. (Note that the data type sec_rgy_domain_t can potentially hold values outside the range [0, 28-1]; however, the only values currently registered are in the range [0, 2], so this type mismatch is not significant.) In the particular case of a POSIX host, the value sec_rgy_domain_person is to be interpreted as the "POSIX UID domain", and the value sec_rgy_domain_group is to be interpreted as the "POSIX GID domain".
410
                                        $x = substr($uuid, 18, 2);
410
                                        $x = substr($uuid, 18, 2);
411
                                        if ($x == '00') $domain_info = 'Person (e.g. POSIX UID)';
411
                                        if ($x == '00') $domain_info = 'Person (e.g. POSIX UID)';
412
                                        else if ($x == '01') $domain_info = 'Group (e.g. POSIX GID)';
412
                                        else if ($x == '01') $domain_info = 'Group (e.g. POSIX GID)';
Line 469... Line 469...
469
                                        - 12 bit Hash Mid
469
                                        - 12 bit Hash Mid
470
                                        -  2 bit Variant (fix 0b10)
470
                                        -  2 bit Variant (fix 0b10)
471
                                        - 62 bit Hash Low
471
                                        - 62 bit Hash Low
472
                                        */
472
                                        */
473
 
473
 
474
                                        echo sprintf("%-32s %s\n", "Version:", "[3] Name-based (MD5 hash)");
474
                                        echo sprintf("%-32s %s\n", "Version:", "[0x3] Name-based (MD5 hash)");
475
 
475
 
476
                                        $hash = str_replace('-', '', strtolower($uuid));
476
                                        $hash = str_replace('-', '', strtolower($uuid));
477
 
477
 
478
                                        $hash[12] = '?'; // was overwritten by version
478
                                        $hash[12] = '?'; // was overwritten by version
479
 
479
 
Line 496... Line 496...
496
                                        - 12 bit Random Mid
496
                                        - 12 bit Random Mid
497
                                        -  2 bit Variant (fix 0b10)
497
                                        -  2 bit Variant (fix 0b10)
498
                                        - 62 bit Random Low
498
                                        - 62 bit Random Low
499
                                        */
499
                                        */
500
 
500
 
501
                                        echo sprintf("%-32s %s\n", "Version:", "[4] Random");
501
                                        echo sprintf("%-32s %s\n", "Version:", "[0x4] Random");
502
 
502
 
503
                                        $rand_line1 = '';
503
                                        $rand_line1 = '';
504
                                        $rand_line2 = '';
504
                                        $rand_line2 = '';
505
                                        for ($i=0; $i<16; $i++) {
505
                                        for ($i=0; $i<16; $i++) {
506
                                                $bin = base_convert(substr($uuid, $i*2, 2), 16, 2);
506
                                                $bin = base_convert(substr($uuid, $i*2, 2), 16, 2);
Line 545... Line 545...
545
                                        - 12 bit Hash Mid
545
                                        - 12 bit Hash Mid
546
                                        -  2 bit Variant (fix 0b10)
546
                                        -  2 bit Variant (fix 0b10)
547
                                        - 62 bit Hash Low
547
                                        - 62 bit Hash Low
548
                                        */
548
                                        */
549
 
549
 
550
                                        echo sprintf("%-32s %s\n", "Version:", "[5] Name-based (SHA-1 hash)");
550
                                        echo sprintf("%-32s %s\n", "Version:", "[0x5] Name-based (SHA-1 hash)");
551
 
551
 
552
                                        $hash = str_replace('-', '', strtolower($uuid));
552
                                        $hash = str_replace('-', '', strtolower($uuid));
553
 
553
 
554
                                        $hash[12] = '?'; // was overwritten by version
554
                                        $hash[12] = '?'; // was overwritten by version
555
 
555
 
Line 574... Line 574...
574
                                        - 12 bit Random
574
                                        - 12 bit Random
575
                                        -  2 bit Variant (fix 0b10)
575
                                        -  2 bit Variant (fix 0b10)
576
                                        - 62 bit Random
576
                                        - 62 bit Random
577
                                        */
577
                                        */
578
 
578
 
579
                                        echo sprintf("%-32s %s\n", "Version:", "[7] Unix Epoch Time");
579
                                        echo sprintf("%-32s %s\n", "Version:", "[0x7] Unix Epoch Time");
580
 
580
 
581
                                        $timestamp = substr($uuid, 0, 12);
581
                                        $timestamp = substr($uuid, 0, 12);
582
 
582
 
583
                                        // Timestamp: Split into seconds and milliseconds
583
                                        // Timestamp: Split into seconds and milliseconds
584
                                        $ts = gmp_init($timestamp, 16);
584
                                        $ts = gmp_init($timestamp, 16);
Line 634... Line 634...
634
                                        - 12 bit Custom data
634
                                        - 12 bit Custom data
635
                                        -  2 bit Variant (fix 0b10)
635
                                        -  2 bit Variant (fix 0b10)
636
                                        - 62 bit Custom data
636
                                        - 62 bit Custom data
637
                                        */
637
                                        */
638
 
638
 
639
                                        echo sprintf("%-32s %s\n", "Version:", "[8] Custom implementation");
639
                                        echo sprintf("%-32s %s\n", "Version:", "[0x8] Custom implementation");
640
 
640
 
641
                                        $custom_data = substr($uuid,0,12).substr($uuid,13); // exclude version nibble
641
                                        $custom_data = substr($uuid,0,12).substr($uuid,13); // exclude version nibble
642
                                        $custom_data[15] = dechex(hexdec($custom_data[15]) & 0b0011); // nibble was partially overwritten by variant
642
                                        $custom_data[15] = dechex(hexdec($custom_data[15]) & 0b0011); // nibble was partially overwritten by variant
643
                                        $custom_data = strtolower($custom_data);
643
                                        $custom_data = strtolower($custom_data);
644
 
644
 
Line 658... Line 658...
658
                                        echo sprintf("%-32s %s\n", "Custom block4 (14 bit):", "[0x$custom_block4]");
658
                                        echo sprintf("%-32s %s\n", "Custom block4 (14 bit):", "[0x$custom_block4]");
659
                                        echo sprintf("%-32s %s\n", "Custom block5 (48 bit):", "[0x$custom_block5]");
659
                                        echo sprintf("%-32s %s\n", "Custom block5 (48 bit):", "[0x$custom_block5]");
660
 
660
 
661
                                        break;
661
                                        break;
662
                                default:
662
                                default:
663
                                        echo sprintf("%-32s %s\n", "Version:", "[$version] Unknown");
663
                                        echo sprintf("%-32s %s\n", "Version:", "[0x".dechex($version)."] Unknown");
664
                                        break;
664
                                        break;
665
                        }
665
                        }
666
 
666
 
667
                        break;
667
                        break;
668
                case 2:
668
                case 2: