Changeset 3232 for branches/2.2/security/classes/funcoes_auxiliares.php
- Timestamp:
- 09/13/10 15:01:56 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2/security/classes/funcoes_auxiliares.php
r1574 r3232 34 34 } 35 35 36 function ler_certificados_CAS($path) 37 { 38 // Ler o arquivo contendo certificados das Cas. 39 // Retorna array com os certificados formato PEM ... 40 $retorno = array(); 41 if(file_exists($path)) 42 { 43 $dados_do_arquivo = file_get_contents($path); 44 $inicio = '-----BEGIN CERTIFICATE-----'; 45 $fim = '-----END CERTIFICATE-----'; 46 $aux1 = explode($inicio,$dados_do_arquivo); 47 foreach($aux1 as $aux2) 48 { 49 if($aux2) 50 { 51 $aux3 = explode($fim,$aux2); 52 $retorno[] =$inicio . $aux3[0] . $fim; 53 } 54 } 55 } 56 return $retorno; 57 } 58 36 function ler_certificados_CAS($path,$flag=false) 37 { 38 // Ler o arquivo contendo certificados das Cas. 39 // Retorna array com os certificados formato PEM ... 40 $retorno = array(); 41 if($flag === false) 42 { 43 if(!file_exists($path)) 44 { 45 return $retorno; 46 } 47 $dados_do_arquivo = file_get_contents($path); 48 } 49 else 50 { 51 $dados_do_arquivo = $path; 52 } 53 $inicio = '-----BEGIN CERTIFICATE-----'; 54 $fim = '-----END CERTIFICATE-----'; 55 $aux1 = explode($inicio,$dados_do_arquivo); 56 foreach($aux1 as $aux2) 57 { 58 if($aux2) 59 { 60 $aux3 = explode($fim,$aux2); 61 $retorno[] =$inicio . $aux3[0] . $fim; 62 } 63 } 64 return $retorno; 65 } 66 59 67 function gera_xml_com_dados_do_certificado($dados) 60 68 { 61 // Recebe array com dados de um certificado e gera o xml com estes dados. 62 // As chaves formam os tags e os dados o conteudo do tag .... 63 $aux_xml = "<certificado>"; 64 if(is_array($dados)) 65 { 66 foreach($dados as $K => $valor) 67 { 68 if(!is_array($valor)) 69 { 70 $aux_xml .= ' <' . $K . '>'.$valor.'</' . $K . '>'; 71 } 72 else 73 { 74 $aux_xml .= ' <' . $K . '>'; 75 foreach($valor as $KX => $valorx) 76 { 77 if(is_int($KX)) $KX = 'D' . $KX; 78 $aux_xml .= ' <' . $KX . '>'.$valorx.'</' . $KX . '>'; 79 } 80 $aux_xml .= ' </' . $K . '>'; 81 } 82 } 83 } 84 $aux_xml .= "</certificado>"; 85 return $aux_xml; 69 // Recebe array com dados de um certificado e gera o xml com estes dados. 70 // As chaves formam os tags e os dados o conteudo do tag .... 71 $aux_xml = "<certificado>"; 72 if(is_array($dados)) 73 { 74 foreach($dados as $K => $valor) 75 { 76 $aux_x = substr($K,0,1); 77 if(is_numeric($aux_x)) $K = 'oid-' . $K; 78 $K = trim($K); 79 if(!is_array($valor)) 80 { 81 $aux_xml .= '<' . $K . '>'.$valor.'</' . $K . '>'; 82 } 83 else 84 { 85 $aux_xml .= '<' . $K . '>'; 86 foreach($valor as $KX => $valorx) 87 { 88 //$KX = trim($KX); 89 if(is_int($KX)) $KX = 'D' . $KX; 90 $KX = trim($KX); 91 $aux_xml .= '<' . $KX . '>'.$valorx.'</' . $KX . '>'; 92 } 93 $aux_xml .= '</' . $K . '>'; 94 } 95 } 96 } 97 $aux_xml .= "</certificado>"; 98 return $aux_xml; 86 99 } 87 100 … … 1164 1177 $integer_data = substr($data, 2 + $bytes, $len); 1165 1178 $data = substr($data, 2 + $bytes + $len); 1179 $result[] = array('integer(' . $len . ')', print_hex($integer_data)); 1180 break; 1181 /* 1166 1182 if($len == 16) 1167 1183 { … … 1198 1214 break; 1199 1215 } 1200 1216 */ 1201 1217 case 0x03: 1202 1218 // Bitstring type … … 1354 1370 1355 1371 case 0xa0: 1372 case 0xa4: 1356 1373 // Extensions 1357 1374 $len = ord($data[1]); … … 1608 1625 { 1609 1626 $AUX = recupera_dados_oid($certificado_digital_formato_der,'2.5.29.31'); 1627 echo '<br/><br/><br/><pre>'; 1628 print_r($AUX); 1629 echo '</pre><br/><br/>'; 1630 exit(); 1631 1632 1610 1633 $i=1; 1611 1634 if(substr($AUX[0][1][0],0,7) == 'boolean') … … 1634 1657 foreach($AUX[0][$i][1][1] as $crl) 1635 1658 { 1636 if(substr($crl[1][0][1][0][1][0][1],0,4) == 'http' )1659 if(substr($crl[1][0][1][0][1][0][1],0,4) == 'http' || substr($crl[1][0][1][0][1][0][1],0,4) == 'ldap') 1637 1660 { 1638 1661 $ret[] = $crl[1][0][1][0][1][0][1]; … … 1640 1663 } 1641 1664 } 1642 } 1665 } 1666 1667 // Se $ret esta vazio tenta obter crls em outra estrutura(outro layout). 1668 if(count($ret) == 0) 1669 { 1670 if(is_array($AUX[0][1][1][1][0][1][0][1][0][1][0])) 1671 { 1672 //Pode existir mais de um local para obter a CRL. 1673 foreach($AUX[0][1][1][1][0][1][0][1][0][1][0]as $crl) 1674 { 1675 if(substr($crl[1],0,4) == 'http' || substr($crl[1],0,4) == 'ldap') 1676 { 1677 $ret[] = $crl[1]; 1678 } 1679 } 1680 } 1681 } 1682 1643 1683 return array('CRLDISTRIBUTIONPOINTS' => $ret); 1644 1684 } 1645 1685 1646 1686 1647 1687 function SERIALNUMBER($cert_data,$KK) 1648 1688 { … … 1671 1711 { 1672 1712 $dados = array(); 1673 $AUX0 = '/';1674 1713 $dados['EMISSOR_CAMINHO_COMPLETO'] = array(); 1675 1714 … … 1682 1721 } 1683 1722 1684 1723 1685 1724 function BEFOREAFTER($cert_data,$KK) 1686 1725 {
Note: See TracChangeset
for help on using the changeset viewer.