note 105734 added to function.openssl-x509-parse

From: Date: Sat, 10 Sep 2011 20:07:56 +0000
Subject: note 105734 added to function.openssl-x509-parse
Groups: php.notes 
Request: Send a blank email to php-notes+get-183087@lists.php.net to get a copy of this message
dont use this function to get serialnumber of certificate expedited by SAT Goverment of Mexico (IRS in Mexico) www.sat.gob.mx, because they do a wrong use of the X509 standard. The standar says the serialnumber should be stored in integer value, they stored in the form of a hexadecimal-encoded value of a string of 20 ASCII digits, which represents an extremely large integer. If you examine the test certificate using Microsoft's CERTMGR.EXE program (just double-click on the .CER file in Windows Explorer), you will see that the Serial Number value is given as 30 30 3030 31 30 30 30 3030 30 30 3030 30 30 30 31 31 34 which is what openssl_509_parse hexadecimal-encoded value of the decimal integer 275106190557734483187066766737145316642573594932 (2.75 x 1047), a number almost big enough to count every atom in the planet! Call openssl to get the string and then convert it to integer. /** sat_serialcer ( <filename_pem> ) obtiene el numero de serie de un certificado de acuerdo a la forma en que el SAT lo genero. En lugar de guardar un entero, guardó un string */ function sat_serialcer( $filename_pem ) { // llamar a openssl y obtener el serial en formato string $cmd = "openssl x509 -in $filename_pem -serial -noout"; $seriestr = shell_exec($cmd); // quitar la palabra 'serial=', lf y cr $seriestr = str_replace( 'serial=' , '', $seriestr); $seriestr = str_replace( chr(10) , '', $seriestr); $seriestr = str_replace( chr(13) , '', $seriestr); // recorrer de 2 en 2 hasta que se acabe $retval = ""; while ($seriestr) { // obtener primer numero en hex $hex = substr($seriestr, 0, 2); // ir formando mi valor de regreso, agregando caracteres $retval = $retval . chr( hexdec( $hex)); // quitarle a la serie original los caracteres procesados $seriestr = substr($seriestr, 2); } return $retval; } ---- Server IP: 69.147.83.197 Probable Submitter: 201.143.4.6 ---- Manual Page -- http://www.php.net/manual/en/function.openssl-x509-parse.php Edit -- https://master.php.net/note/edit/105734 Del: integrated -- https://master.php.net/note/delete/105734/integrated Del: useless -- https://master.php.net/note/delete/105734/useless Del: bad code -- https://master.php.net/note/delete/105734/bad+code Del: spam -- https://master.php.net/note/delete/105734/spam Del: non-english -- https://master.php.net/note/delete/105734/non-english Del: in docs -- https://master.php.net/note/delete/105734/in+docs Del: other reasons-- https://master.php.net/note/delete/105734 Reject -- https://master.php.net/note/reject/105734 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#183087) next »