Es importante verificar la caducidad de los certificados del SAT

Pues al hacer mi reporte mensual ví que el sistema del SAT me denegó el servicio ya que mi FIEL (Firma electrónica avanzada) caducó hace 3 días. Ahora tengo que hacer un trámite engorroso en el SAT para que me den la renovación, siendo que si la FIEl está aún vigente, es muy fácil el trámite de reposición.

Por eso les dejo un pequeño programa que hice en Perl para verificar los datos de sus certificados del SAT (y de cualquier certificado que use x509):

#!/usr/bin/perl
 
use strict;
use File::Copy; 
use File::Path;
 
sub SAT_Path {
    my $file = shift;
    return substr($file,0,6) .
           '/' .
           substr($file,6,6) .
           '/' .
           substr($file,12,2) .
           '/' .
           substr($file,14,2) .
           '/' .
           substr($file,16,2) .
           '/';
}
 
sub Cert_Info {
    my $cert_file = shift;
    my $cert_info = qx(openssl x509 -inform DER -in $cert_file -serial -subject -startdate -enddate -noout);
    $cert_info =~ s/\\xD1/Ñ/g;
    $cert_info =~ s/\\xF1/ñ/g;
    $cert_info =~ s/\\xC1/Á/g;
    $cert_info =~ s/\\xC9/É/g;
    $cert_info =~ s/\\xCD/Í/g;
    $cert_info =~ s/\\xD3/Ó/g;
    $cert_info =~ s/\\xDA/Ú/g;
    $cert_info =~ s/\\xE1/á/g;
    $cert_info =~ s/\\xE9/é/g;
    $cert_info =~ s/\\xED/í/g;
    $cert_info =~ s/\\xF3/ó/g;
    $cert_info =~ s/\\xFA/ú/g;
    my ($serial_cn) = $cert_info =~ /subject\=.*\/CN=(.*?)(\/OU\=|\/O\=|\/name\=|\/serialNumber\=|\/x500UniqueIdentifier\=|\n)/;
    my ($rfc) = $cert_info =~ /subject\=.*\/x500UniqueIdentifier=(.*?)(\/CN\=|\/OU\=|\/O\=|\/name\=|\/serialNumber\=|\n)/;
    my ($curp) = $cert_info =~ /subject\=.*\/serialNumber=(.*?)(\/CN\=|\/OU\=|\/O\=|\/name\=|\/x500UniqueIdentifier\=|\n)/;
    my ($sucursal) = $cert_info =~ /subject.*\/OU=(.*?)(\/CN\=|\/O\=|\/name\=|\/serialNumber\=|\/x500UniqueIdentifier\=|\n)/;
    $curp =~ s/\s//g;
    $curp =~ s/^\///;
    my $rfc_rep = '';
    $rfc =~ s/\s//g;
    if ($rfc =~ /\//) {
        ($rfc, $rfc_rep) = split(/\//, $rfc);
    }
    my ($serial_hex) = $cert_info =~ /serial\=(.*)/;
    my ($notBefore) = $cert_info =~ /notBefore=(.*)/;
    my ($notAfter) = $cert_info =~ /notAfter=(.*)/;
    my $public_key = qx(openssl x509 -inform DER -in $cert_file -noout -pubkey);
    my $certificate = qx(openssl x509 -inform DER -in $cert_file);
    my $serial = '';
    my @pairs = $serial_hex =~ /(\d\d)/g;
    foreach my $hex (@pairs) {
        $serial = $serial . chr(hex($hex));
    }
        print "-" x 65;
        print "\n";
        print "RFC        => $rfc\n";
        print "Serial     => $serial\n";
        print "Nombre     => $serial_cn\n";
        print "RFC Rep.   => $rfc_rep\n";
        print "CURP       => $curp\n";
        print "sucursal   => $sucursal\n";
        print "Begin date => $notBefore\n";
        print "End date   => $notAfter\n";
        print "-" x 65;
        print "\n";
        print "$public_key\n$certificate\n";
        print "SAT file:  => ftp://ftp2.sat.gob.mx/Certificados/FEA/" . SAT_Path($serial) . "$serial.cer\n";
}
 
chomp;
my @Fields = split(/\|/,$_);
if ($ARGV[0] =~ /\.cer/) {
    if ( -e "$ARGV[0]" ) {
        Cert_Info("$ARGV[0]");
    }
}

Para usarlo sol le dan:

./cert_info.pl 00001000000103469712.cer

y les dará la siguiente información:

-----------------------------------------------------------------
RFC        => CAJU641218Q96
Serial     => 00001000000103469712
Nombre     => CAMANEI SA DE CV
RFC Rep.   => CAJU641218Q96
CURP       => CAJU641218HDFMLR54
sucursal   => 
Begin date => Dec  3 17:48:18 2010 GMT
End date   => Mar  2 17:48:18 2013 GMT
-----------------------------------------------------------------
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCqIIggmHT4qclfBRsIO7fzgDUd
iYcSF46wqFu1cetJU+O/2G/E5o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5fr034OM/Mqj18
o2dpSX3HKZyHnTgyaIxWVP9zSPrm2L4lwSdFS29kkQxx+VzEewj0b1mJAtghZuLM
5QIDAQABo08wTTAMBgNVHRMBAf8EAjAAMAsGA1UdDwQEAwID2DARBglghkgBhvhC
AQEEBAMCBaAwHQYDVR0lBBYwFAYIKwYBBQUHAwQGCCsGAQUFBwMCMA0GCSqGSIb3
DQEBBQUAA4IBAQBLcKX2vawNdSjOZoA9lX5+KdBMCuKV74y4gQNnC+xNrN0Srjlr
1T7kwqdQJvQmz29RV9zc0dX7riM1S0xCrSzSrang9B6Actipz8QBFyCYvw1FDEZi
YOf89Z4pA7YlhuNOI7+nDgfJa3DXrW5lB2totGPZ82dfSSaSB5NHJGeUTqESel0G
7GpGowO+tEz8KAky54lAuod8kPlkEpo5rh2K3zFeFLHoG6MYIcFAhirt3b13ABuq
2ZWzcTaht87bCam1H4zMAOZF5xTHCfBNN7NSV+yAeb0Ssp48N6nstsZBIvIKF7JV
jW8PcylnhWsdW/3IQ7ENXE1S7fjKstDfkCdB
-----END CERTIFICATE-----

2 votes, average: 3.50 out of 52 votes, average: 3.50 out of 52 votes, average: 3.50 out of 52 votes, average: 3.50 out of 52 votes, average: 3.50 out of 5 (2 votes, average: 3.50 out of 5)
You need to be a registered member to rate this post.
Loading...
Perl, Programacion, Tips técnicos | RSS 2.0 |     1,396 views

RSS feed

Comments »

No comments yet.

Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> in your comment.

Trackback responses to this post