note 105734 deleted from function.openssl-x509-parse by danbrown

From: Date: Sat, 10 Sep 2011 20:25:06 +0000
Subject: note 105734 deleted from function.openssl-x509-parse by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-183088@lists.php.net to get a copy of this message
Note Submitter: nash-php at gmail dot com ---- 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; }

« previous php.notes (#183088) next »