Subversion Repositories php_utils

Rev

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

Rev 47 Rev 48
Line 1... Line 1...
1
<?php
1
<?php
2
 
2
 
3
/*
3
/*
4
 * ISO/IEC 7816-5 Application Identifier decoder for PHP
4
 * ISO/IEC 7816 Application Identifier decoder for PHP
5
 * Copyright 2022 Daniel Marschall, ViaThinkSoft
5
 * Copyright 2022 Daniel Marschall, ViaThinkSoft
6
 * Version 2022-09-18
6
 * Version 2022-09-19
7
 *
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
10
 * You may obtain a copy of the License at
11
 *
11
 *
Line 554... Line 554...
554
        $iso3166['732'] = "Western Sahara";
554
        $iso3166['732'] = "Western Sahara";
555
        $iso3166['887'] = "Yemen";
555
        $iso3166['887'] = "Yemen";
556
        $iso3166['894'] = "Zambia";
556
        $iso3166['894'] = "Zambia";
557
        $iso3166['716'] = "Zimbabwe";
557
        $iso3166['716'] = "Zimbabwe";
558
 
558
 
559
        // ISO/IEC 7816-5 AID decoder
-
 
560
 
-
 
561
        $out = array();
559
        $out = array();
562
 
560
 
563
        // A very good source about the coding
-
 
564
        // https://blog.actorsfit.com/a?ID=00250-166ef507-edff-4400-8d0e-9e85d6ae2310
-
 
565
 
-
 
566
        $aid = strtoupper($aid);
561
        $aid = strtoupper($aid);
567
        $aid = trim($aid);
562
        $aid = trim($aid);
568
        $aid = str_replace(' ','',$aid);
563
        $aid = str_replace(' ','',$aid);
569
        $aid = str_replace(':','',$aid);
564
        $aid = str_replace(':','',$aid);
570
 
565
 
Line 579... Line 574...
579
        }
574
        }
580
 
575
 
581
        $aid_hf = implode(':',str_split($aid,2));
576
        $aid_hf = implode(':',str_split($aid,2));
582
        if (strlen($aid)%2 == 1) $aid_hf .= '_';
577
        if (strlen($aid)%2 == 1) $aid_hf .= '_';
583
 
578
 
584
        $out[] = array("$aid", "ISO/IEC 7816-5 Application Identifier (AID)");
579
        $out[] = array("$aid", "ISO/IEC 7816 Application Identifier (AID)");
585
        $out[] = array('', "> $aid_hf <");
580
        $out[] = array('', "> $aid_hf <");
586
        $out[] = array('', c_literal_hexstr($aid));
581
        $out[] = array('', c_literal_hexstr($aid));
587
 
582
 
588
        if ((strlen($aid) == 32) && (substr($aid,-2) == 'FF')) {
583
        if ((strlen($aid) == 32) && (substr($aid,-2) == 'FF')) {
589
                // https://www.kartenbezogene-identifier.de/content/dam/kartenbezogene_identifier/de/PDFs/RID_Antrag_2006.pdf
584
                // Sometimes you read that a 16-byte AID must not end with FF, because it is reserved by ISO.
-
 
585
                // I have only found one official source:
-
 
586
                // ISO/IEC 7816-5 : 1994 (E)
-
 
587
                //        Identification cards - Integrated circuit(s) cards with contacts -
590
                // writes: "Wenn die PIX aus 11 Bytes besteht, muss das letzte Byte einen Hexadezimal-Wert ungleich ´FF´ aufweisen (´FF´ ist von ISO reserviert)."
588
                //        Part 5 : Numbering system and registration procedure for application identifiers
591
                // https://www.etsi.org/deliver/etsi_ts/101200_101299/101220/07.03.00_60/ts_101220v070300p.pdf
589
                //        https://cdn.standards.iteh.ai/samples/19980/8ff6c7ccc9254fe4b7a8a21c0bf59424/ISO-IEC-7816-5-1994.pdf
-
 
590
                // Quote from clause 5.2:
-
 
591
                //        "The PIX has a free coding. If the AID is 16 bytes long,
592
                // writes: According to ISO/IEC 7816-4, if the AID is 16 bytes long, then the value 'FF' for the least significant byte [...] is reserved for future use.
592
                //         then the value 'FF' for the least significant byte is reserved for future use."
-
 
593
                // In the revisions of ISO/IEC 7816, parts of ISO 7816-5 (e.g. the AID categories)
-
 
594
                // have been moved to ISO 7816-4.
-
 
595
                // The "FF" reservation cannot be found in modern versions of 7816-4 or 7816-5.
593
                $out[] = array('',"INVALID: A 16-byte AID must not end with FF. (Reserved by ISO/IEC 7816-4)");
596
                $out[] = array('',"INVALID: A 16-byte AID must not end with FF. (Reserved by ISO/IEC)");
594
        }
597
        }
595
 
598
 
596
        if (strlen($aid) > 32) {
599
        if (strlen($aid) > 32) {
597
                $out[] = array('',"INVALID: An AID must not be longer than 16 bytes");
600
                $out[] = array('',"INVALID: An AID must not be longer than 16 bytes");
598
        }
601
        }