VOMS-Lite

 view release on metacpan or  search on metacpan

misc/PROXYINFO.pl  view on Meta::CPAN


@bits = split(//, unpack("B*", $decoded));

my @ConLen=();
my @LenStart=();
my $inheader=1;
my $lenlen=0;
my $reallen=0;

my $Class;
my $Constructed=0;
my $Tag=0;
my $oid="";

for ( my $i = 0 ; $i < $certlen ; $i++ ) {
#  printf "%d\t0x%02x\t",$i,ord(substr($decoded, $i,1));
  printf "0x%02x\t",ord(substr($decoded, $i,1));
  for(my $a=0;$a<8;$a++) { print $bits[($i*8+$a)]; }

  print " ";
  if (@ConLen < 20) {
    print "|" x scalar(@ConLen);
    print " " x (21 - scalar(@ConLen));
  } else {
    print "                  -> ";
  }
  if ( $inheader!=1 ) { print "\t";} 

  if ( $inheader==1 ) { # ID
    $Class= $bits[($i*8)]*2 + $bits[($i*8 + 1)];
    $Constructed=$bits[($i*8 + 2)];

    print "U "  if ($Class == 0);
    print "A "  if ($Class == 1);
    print "C "  if ($Class == 2);
    print "P "  if ($Class == 3);
    print "P " if ($Constructed == 0);
    print "C " if ($Constructed == 1);

    $Tag=0;
    for (my $a=3;$a<8;$a++) { $Tag += $bits[($i*8+$a)]*(2**(7-$a)); } #Tag from these 5 bits

    $lenlen=0;
    if ($Tag==31) {
      $inheader=2;
      print "\"Tag (next byte)\"\t";
      $Tag=0;
    } else {
      $inheader=3;
        if ($Class == 0 ) {
         if ( $Tag == 1 ) { print "[BOOLEAN]\t"; }
      elsif ( $Tag == 2 ) { print "[INTEGER]\t"; }
      elsif ( $Tag == 3 ) { print "[BIT STRING]\t"; }
      elsif ( $Tag == 4 ) { print "[OCTET STRING]\t"; }
      elsif ( $Tag == 5 ) { print "[NULL]\t"; }
      elsif ( $Tag == 6 ) { print "[OID]\t"; }
      elsif ( $Tag == 7 ) { print "[ODT]\t"; }
      elsif ( $Tag == 8 ) { print "[EXTERNAL/INSTANCE]\t"; }
      elsif ( $Tag == 9 ) { print "[REAL]\t"; }
      elsif ( $Tag == 10 ) { print "[ENUM]\t"; }
      elsif ( $Tag == 11 ) { print "[EMBEDDED-PDV]\t"; }
      elsif ( $Tag == 12 ) { print "[UTF-8 String]\t"; }
      elsif ( $Tag == 13 ) { print "[ROID]\t"; }
      elsif ( $Tag == 16 ) { print "[SEQUENCE]\t"; }
      elsif ( $Tag == 17 ) { print "[SET]\t"; }
      elsif ( $Tag == 19 ) { print "[PRINTABLESTRING]\t"; }
      elsif ( $Tag == 22 ) { print "[IA5String]\t"; }
      elsif ( $Tag == 23 ) { print "[UTCTIME]\t"; }
      elsif ( $Tag == 24 ) { print "[GENERALISED TIME]\t"; }
      elsif ( $Tag>=18 && $Tag<=22 ) { print "[UNKNOWN STRING]\t"; }
      elsif ( $Tag>=25 && $Tag<=30 ) { print "[UNKNOWN STRING]\t"; }
      else { print "[Tag=$Tag]\t"; }
        } else {print "[Tag=$Tag]\t"; }
    }
  } elsif ( $inheader==2 ) {
    $Tag *= 128; #Shift by 7 bits!
    for (my $a=1;$a<8;$a++) { $Tag += $bits[($i*8+$a)]*(2**(7-$a)); } #Add these 7 bits
 
    if ($bits[($i*8)] == 0) {
      $inheader=3;
      print "\"Tag=$Tag\"\t";
    } else {
      print "\"Tag (next byte)\"\t";
    }
  } elsif ( $inheader==3 ) { # Length
    for (my $a=1;$a<8;$a++) { $lenlen += $bits[($i*8+$a)]*(2**(7-$a)); }

    $reallen=0;
    if ( $bits[($i*8 + 0)] == 0 ) { #encoded here
      print "Length = $lenlen\t";
      $inheader=-1;
      $reallen=$lenlen;
      push @ConLen,$reallen;
      push @LenStart,$i;
    } else {
      print "Length (encoded $lenlen bytes) =\t";
      $inheader=4;
    }
  } elsif ( $inheader==4 ) {
    $lenlen--;
    my $len=0;
    for (my $a=0;$a<8;$a++) { $len += $bits[($i*8+$a)]*(2**(7-$a)); }
    $len*=(256**$lenlen);
    $reallen+=$len;
    if ( $lenlen == 0 ) { 
      $inheader=-1;
      push @ConLen,$reallen;
      push @LenStart,$i;
      print "$len = $reallen\t";
    } else {
      print "$len + ";
    }
  } else {
    print "\t";
    my $char=substr $decoded,$i,1;
    if ( $Tag == 1 ) {                     ################# Boolean type
      print (( ord($char) == 0 )?"FALSE":"TRUE")."\t";

    } elsif ( $Tag == 2 ) {                ################# Integer type
      printf "0x%02X\t",ord($char);
      if ( $i - $LenStart[-1] == $ConLen[-1] ) { 



( run in 3.305 seconds using v1.01-cache-2.11-cpan-0b58ddf2af1 )