Ignore:
Timestamp:
09/13/10 15:01:56 (14 years ago)
Author:
rafaelraymundo
Message:

Ticket #1237 - Atualizados componentes de suporte ao uso do Certificado Digital.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2/security/security.php

    r1174 r3232  
    11<?php 
    2         require_once('classes/CertificadoB.php'); 
    3  
    4         $Linhas = explode(chr(0x0A),file_get_contents($_SERVER["DOCUMENT_ROOT"] . '/security/crl_admin/crl_admin_confg.py')); 
    5          
    6         foreach($Linhas as $linha) 
    7                 { 
    8                         $path = pega_path(array( 'arquivo =', 'arquivo='),$linha); 
    9                         if($path) $path1 = $path; 
    10                         $path = pega_path(array( 'log =', 'log='),$linha); 
    11                         if($path) $path2 = $path; 
    12                         $path = pega_path(array( 'CAfile =', 'CAfile='),$linha); 
    13                         if($path) $path3 = $path; 
    14                 } 
    15  
    16         if($path3) 
    17                 { 
    18                 $item = 1; 
    19                 $todos_certificados =  ler_certificados_CAS($path3); 
    20                 $aux_emissores= array(); 
    21                 $tab_certs = array(); 
    22                 $CB = new CertificadoB(); 
    23                 foreach($todos_certificados as $certificados) 
    24                         { 
    25                                 $CB -> certificado($certificados); 
    26                                 $df = $CB->dados['FIM_VALIDADE']; 
    27                                 $di =  $CB->dados['INICIO_VALIDADE']; 
    28                                 if(gmdate("YmdHis") > $df) 
    29                                         {        
    30                                                 $cor = '<label style="color: #FF0000" >Expirado em: </label>'; 
    31                                         } 
    32                                 else 
    33                                         { 
    34                                                 $cor = '<label>Valido at&eacute; </label>'; 
    35                                         } 
    36                                 $info = $cor . substr($df,0,4) . '/' . substr($df,4,2) . '/' . substr($df,6,2) . '  -  ' . substr($df,8,2) . ':' . substr($df,10,2) . ':' . substr($df,12,2) . ' GMT'; 
    37                                 $info = '<font size="1"' . $info . '</font>'; 
    38                                 // Armazena alguns dados do certificado. $tabs_certs esta na mesma ordem em que os certificados aparecem no arquivo todos.cer..... 
    39                                 $tab_certs[$CB->dados['SUBJECT']['CN']]['item'] = $item++; 
    40                                 $tab_certs[$CB->dados['SUBJECT']['CN']]['emissor'] =  $CB->dados['EMISSOR_CAMINHO_COMPLETO']['CN']; 
    41                                 $tab_certs[$CB->dados['SUBJECT']['CN']]['fim_validade'] = $info; 
    42                                 $tab_certs[$CB->dados['SUBJECT']['CN']]['inicio_validade'] = $di; 
    43                                 if($CB->dados['EMISSOR_CAMINHO_COMPLETO']['CN'] !=  $CB->dados['SUBJECT']['CN']) 
    44                                         { 
    45                                                 // Se nao he um auto assinado (identifica um raiz), salva emissor , faz a chave a tdata de inicio de validade do certificado... 
    46                                                 $aux_emissores[$di][$CB->dados['EMISSOR_CAMINHO_COMPLETO']['CN']][$CB->dados['SUBJECT']['CN']] = '9' ; 
    47                                         } 
    48                         } 
    49                 // ordena certificados pela data de inicio de validade ......                    
    50                 ksort($aux_emissores); 
    51                 $NOVO = array(); 
    52                 $AUX3 = array(); 
    53                 $emissores = array(); 
    54  
    55                 foreach($aux_emissores as $kchave1 => $emis1) 
    56                         { 
    57                                 foreach($emis1 as $Kchave2 => $emis2) 
    58                                         { 
    59                                                 foreach($emis2 as $Kchave3 => $emis3) 
    60                                                         { 
    61                                                                         $emissores[$Kchave2][$Kchave3] = '9'; 
    62                                                         } 
    63                                         } 
    64                         } 
    65  
    66                 // O array $NOVO vai conter a cadeia dos certificados de CAs .... 
    67                 foreach($emissores as $K => $V) 
    68                         { 
    69                                 if($AUX3[$K] != '0') 
    70                                 { 
    71                                         foreach($V as $K1 => $V1) 
    72                                                 { 
    73                                                                         if($emissores[$K1]) 
    74                                                                                 { 
    75                                                                                         $NOVO[$K][$K1] = $emissores[$K1]; 
    76                                                                                         $AUX3[$K1] = '0'; 
    77                                                                                 } 
    78                                                                         else 
    79                                                                                 { 
    80                                                                                         $NOVO[$K][$K1] = '0'; 
    81                                                                                 } 
    82                                                 }        
    83                                 } 
    84                         }  
    85                  
    86                 // Valores auxiliares para fazer a identacao ..... 
    87                 $prefixo0 = '&nbsp;&nbsp;' . '|'; 
    88                 $prefixo1 =  '&nbsp;&nbsp;' .  '|' .  '____' ; 
    89                 $prefixo2 =  '&nbsp;&nbsp;' . '|' .  '&nbsp;&nbsp;' . '&nbsp;&nbsp;' .  '&nbsp;&nbsp;' .  '&nbsp;&nbsp;' . '|' ; 
    90                 $prefixo2A =  '&nbsp;&nbsp;' . '&nbsp;&nbsp;' .  '&nbsp;&nbsp;' . '&nbsp;&nbsp;' .  '&nbsp;&nbsp;' .  '&nbsp;&nbsp;' . '|' ; 
    91                 $prefixo3 =  '&nbsp;&nbsp;' . '|' .  '&nbsp;&nbsp;' . '&nbsp;&nbsp;' .  '&nbsp;&nbsp;' .  '&nbsp;&nbsp;' . '|'  . '____' ; 
    92                 $prefixo3A =  '&nbsp;&nbsp;' .  '&nbsp;&nbsp;'  .  '&nbsp;&nbsp;' . '&nbsp;&nbsp;' .  '&nbsp;&nbsp;' .  '&nbsp;&nbsp;' . '|'  . '____' ; 
    93  
    94                 echo '<script type="text/javascript" src="certificados.js"></script>'; 
    95                 echo '<h2 style="color: #000066">Cadeias de certificados AC\'s configuradas:</h2>';      
    96                 echo '<div style="border: #000000 1px solid; overflow: auto; width: 770px; height: 400px; white-space: pre;  padding: 3px; " >'; 
    97                 echo '<pre>'; 
    98                 foreach($NOVO as $K => $V) 
    99                         { 
    100                                 if($tab_certs[$K]['fim_validade']) 
    101                                         { 
    102                                                 $msg =  $tab_certs[$K]['fim_validade']; 
    103                                         } 
    104                                 else 
    105                                         { 
    106                                                 $msg =  '<font color="FF0000" size="4"><b>Certificado ausente da cadeia.</b></font> '; 
    107                                         } 
    108                                 echo '<br/><font color="0000FF" size="4"><b><a href="javascript:Um_Certificado(\''. $tab_certs[$K]['item']  . ' - ' . $K .'\')" style="text-decoration: none" >' . $K . '</a></b></font>  ' . $msg . '<br/>'; 
    109                                 if(is_array($V)) 
    110                                         { 
    111                                                 $num = count($V); 
    112                                                 $item = 0; 
    113                                                 foreach($V as $K1 => $V1) 
    114                                                         { 
    115                                                                 $item = $item + 1; 
    116                                                                 echo $prefixo0 . '<br/>'; 
    117                                                                 if($tab_certs[$K1]['fim_validade']) 
    118                                                                         { 
    119                                                                                 $msg =  $tab_certs[$K1]['fim_validade']; 
    120                                                                         } 
    121                                                                 else 
    122                                                                         { 
    123                                                                                 $msg =  '<font color="FF0000" ><b>Certificado ausente da cadeia.</b></font> '; 
    124                                                                         } 
    125                                                                 echo $prefixo1 .  '<font color="#000000" ><a href="javascript:Um_Certificado(\''. $tab_certs[$K1]['item']  . ' - ' . $K1 .'\')" style="text-decoration: none" >' . $K1 . '</a></font> ' .  '  ' . $msg . '<br/>'; 
    126                                                                 if(is_array($V1)) 
    127                                                                         { 
    128                                                                                 foreach($V1 as $K2 => $V2) 
    129                                                                                         { 
    130                                                                                                 if($tab_certs[$K1]['fim_validade']) 
    131                                                                                                         { 
    132                                                                                                                 $msg =  $tab_certs[$K1]['fim_validade']; 
    133                                                                                                         } 
    134                                                                                                 else 
    135                                                                                                         { 
    136                                                                                                                 $msg =  '<font color="FF0000" ><b>Certificado ausente da cadeia.</b></font> '; 
    137                                                                                                         } 
    138                                                                                                 if($num>$item) 
    139                                                                                                         { 
    140                                                                                                                 echo  $prefixo2 . '<br/>'; 
    141                                                                                                                 echo$prefixo3 . '<font color="#000000" ><a href="javascript:Um_Certificado(\''. $tab_certs[$K2]['item']  . ' - ' . $K2 .'\')" style="text-decoration: none" >' . $K2 . '</a></font> ' .  '  ' . $msg . '<br/>'; 
    142                                                                                                         } 
    143                                                                                                 else 
    144                                                                                                         { 
    145                                                                                                                 echo  $prefixo2A . '<br/>'; 
    146                                                                                                                 echo $prefixo3A .  '<font color="#000000" ><a href="javascript:Um_Certificado(\''. $tab_certs[$K2]['item']  . ' - ' . $K2 .'\')" style="text-decoration: none" >' . $K2 . '</a></font> ' .  '  ' . $msg . '<br/>';                                                                               
    147                                                                                                         } 
    148                                                                                         } 
    149                                                                         } 
    150                                                         } 
    151                                         } 
    152                         } 
    153                 echo '</pre>'; 
    154                 echo '</div><br/>';              
    155                 } 
    156         if($path1) 
    157                 { 
    158                         $Linhas = explode(chr(0x0A),file_get_contents($path1)); 
    159                         echo '<h2  style="color: #000066">LCR\'s configuradas:</h2>';    
    160                         echo '<table border ="1" style="margin-top: 8px; width: 770px">'; 
    161                         echo '<th nowrap align="left" style=" padding: 5px">Lista de Certificados revogados obtida em:</th><th nowrap align="left" style=" padding: 5px">Onde é salva a LCR:</th>'; 
    162                         foreach($Linhas as $linha) 
    163                                 { 
    164                                         if($linha[0] != '#' && $linha != '') 
    165                                                 { 
    166                                                         $c = explode(';', $linha); 
    167                                                         $n = explode('/',$c[0]); 
    168                                                         $f = $c[1] . $n[count($n)-1]; 
    169                                                         echo '<tr><td nowrap valign="top" style=" padding: 5px">' . $c[0] . '</td><td nowrap style=" padding: 5px">'; 
    170                                                         echo $f; 
    171                                                         if(!is_file($f)) 
    172                                                                 { 
    173                                                                         echo '<p style="margin-bottom: 5px"><b  style="color: #FF0000">Arquivo n&atilde;o localizado.</b></p>';  
    174                                                                 } 
    175                                                         else 
    176                                                                 { 
    177                                                                         $data = file_get_contents($f); 
    178                                                                         $dados = Crl_parseASN($data); 
    179                                                                         echo '<br/><br/>Emitido por: '; 
    180                                                                         $aux = $dados[1][0][1][2][1]; // pega dados do emissor. 
    181                                                                         $aux = $aux[count($aux)-1];  // ultimo item he o do CN..... 
    182                                                                         echo $aux[1][1][1][1]; 
    183                                                                         echo '<br/>Num. certificados: '; 
    184                                                                         $num = 0; 
    185                                                                         if(count($dados[1][0][1]) > 6)        // qtd de itens esperado he 7. o 6 contem os certificados revogados. 
    186                                                                                 { 
    187                                                                                         $num = count($dados[1][0][1][5][1]);  // pega o numero de certificados revogados na LCR. 
    188                                                                                 } 
    189                                                                         echo $num;  
    190                                                                         echo '<br/>LCR num. : '; 
    191                                                                         $oid_Num_crl = recupera_dados_oid($data,'2.5.29.20');  // oid que informa o numero de geracao da LCR. 
    192                                                                         $num = $oid_Num_crl[0][1][1][1]; 
    193                                                                         if($num) 
    194                                                                                 { 
    195                                                                                         echo $num;  
    196                                                                                 } 
    197                                                                         else  
    198                                                                                 { 
    199                                                                                         echo '0'; 
    200                                                                                 } 
    201                                                                         echo '<br>'; 
    202                                                                         $di = data_hora($dados[1][0][1][3][1]);             // data, hora em que foi gerada a LCR. 
    203                                                                         $df = data_hora($dados[1][0][1][4][1]);            // data, hora em que expira a LCR.                                                    
    204                                                                         if(gmdate("YmdHis") < $di) 
    205                                                                                 { 
    206                                                                                         $cor = 'style="color: #FF0000"'; 
    207                                                                                 } 
    208                                                                         else 
    209                                                                                 { 
    210                                                                                         $cor = 'style="color: #000066"'; 
    211                                                                                 } 
    212                                                                         echo '<p><b  ' . $cor . '>Gerada em : </b>' . substr($di,0,4) . '/' . substr($di,4,2) . '/' . substr($di,6,2) . '  -  ' . substr($di,8,2) . ':' . substr($di,10,2) . ':' . substr($di,12,2) . ' GMT</p>'; 
    213                                                                         if(gmdate("YmdHis") > $df) 
    214                                                                                 { 
    215                                                                                         $cor = 'style="color: #FF0000" >Expirada em: '; 
    216                                                                                 } 
    217                                                                         else 
    218                                                                                 { 
    219                                                                                         $cor = 'style="color: #000066" >Expira em: '; 
    220                                                                                 } 
    221                                                                         echo '<p><b  ' . $cor . ' </b>' . substr($df,0,4) . '/' . substr($df,4,2) . '/' . substr($df,6,2) . '  -  ' . substr($df,8,2) . ':' . substr($df,10,2) . ':' . substr($df,12,2) . ' GMT</p>';                                                                    
    222                                                                 } 
    223                                                         echo  '</td></tr>'; 
    224                                                 } 
    225                                 } 
    226                         echo '</table><br><br><br>'; 
    227                 } 
    228          
    229  
    230                  
    231                  
    232         if($path2) 
    233                 { 
    234                         echo '<br><h2  style="color: #000066">Log da atualiza&ccedil;&atilde;o das LCR\'s:</h2>';        
    235                         echo '<div style="border: #000000 1px solid; overflow: auto; width: 770px; height:290px; white-space: pre; padding: 5px" >'; 
    236                         echo '<pre>'; 
    237                         if(is_file($path2)) 
    238                                 { 
    239                                         $saida = array(); 
    240                                         $ret = exec('cat ' . $path2 . ' | grep ' . date('Y-m-d') ,$saida); 
    241                                         foreach($saida as $linha) 
    242                                                 { 
    243                                                         echo $linha . chr(0x0A); 
    244                                                 } 
    245                                 } 
    246                         else 
    247                                 { 
    248                                         echo '<p style="margin-bottom: 5px"><b  style="color: #FF0000">Arquivo  ' . $path2 . '  n&atilde;o localizado.</b></p>';  
    249                                 } 
    250                         echo '</pre>'; 
    251                         echo '</div><br><br>'; 
    252                 } 
    2532?> 
     3        <div style="padding-left:90px" > 
     4            <br/><br/> 
     5            <span> 
     6                <a href="security-cas.php" style="text-decoration:none"><b><?php echo lang('ACs (Autoridades Certificadoras)') ?></b></a> 
     7            </span> 
     8            <br/><br/> 
     9            <span> 
     10                <a href="security-clr.php" style="text-decoration:none"><b><?php echo lang('LCRs(Listas de Certificados Revogados)') ?></b></a> 
     11            </span> 
     12            <br/><br/> 
     13            <span> 
     14                <a href="security-cfg.php" style="text-decoration:none"><b><?php echo lang('Visualizar Configuracao em uso') ?></b></a> 
     15            </span> 
     16            <br/><br/><br/><br/> 
     17            <a href="../admin/index.php" style="text-decoration:none"><input type="button" value="<?php echo lang('Cancelar') ?>"/></a> 
     18            <br/><br/> 
     19        </div> 
Note: See TracChangeset for help on using the changeset viewer.