PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/security/vercert.php

https://github.com/muchael/expressolivre
PHP | 91 lines | 91 code | 0 blank | 0 comment | 12 complexity | 98d70b0660c2fb1b21c246a6c88eed2f MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, BSD-2-Clause, BSD-3-Clause, AGPL-3.0
  1. <?php
  2. $GLOBALS['phpgw_info']['flags'] = array(
  3. 'disable_Template_class' => True,
  4. 'login' => True,
  5. 'currentapp' => 'login',
  6. 'noheader' => True
  7. );
  8. if(file_exists('../header.inc.php'))
  9. {
  10. include('../header.inc.php');
  11. }
  12. else
  13. {
  14. echo '1'.chr(0x0D).chr(0x0A).lang('Error. header.inc.php not found');
  15. exit();
  16. }
  17. if(!$_POST['certificado'])
  18. {
  19. echo '2'.chr(0x0D).chr(0x0A).lang('Fail to get certificate');
  20. exit();
  21. }
  22. require_once('classes/CertificadoB.php');
  23. require_once('classes/Verifica_Certificado.php');
  24. include('classes/Verifica_Certificado_conf.php');
  25. $cert = troca_espaco_por_mais(str_replace(chr(0x0D).chr(0x0A),chr(0x0A),str_replace(chr(0x0A).chr(0x0A),chr(0x0A),$_POST['certificado'])));
  26. $c = new certificadoB();
  27. $c->certificado($cert);
  28. if (!$c->apresentado)
  29. {
  30. echo '3'.chr(0x0D).chr(0x0A).lang('Fail to get certificate');
  31. exit();
  32. }
  33. $b = new Verifica_Certificado($c->dados,$cert);
  34. if(!$b->status)
  35. {
  36. $msg = '4'.chr(0x0D).chr(0x0A).$b->msgerro;
  37. foreach($b->erros_ssl as $linha)
  38. {
  39. $msg .= "\n" . $linha;
  40. }
  41. echo $msg;
  42. exit();
  43. }
  44. if ( (!empty($GLOBALS['phpgw_info']['server']['ldap_master_host'])) &&
  45. (!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_dn'])) &&
  46. (!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_pw'])) )
  47. {
  48. $ds = $GLOBALS['phpgw']->common->ldapConnect($GLOBALS['phpgw_info']['server']['ldap_master_host'],
  49. $GLOBALS['phpgw_info']['server']['ldap_master_root_dn'],
  50. $GLOBALS['phpgw_info']['server']['ldap_master_root_pw']);
  51. }
  52. else
  53. {
  54. $ds = $GLOBALS['phpgw']->common->ldapConnect();
  55. }
  56. if (!$ds)
  57. {
  58. echo '5'.chr(0x0D).chr(0x0A).lang('Failure when get user data to login');
  59. exit();
  60. }
  61. $cert_atrib_cpf = isset($GLOBALS['phpgw_info']['server']['certificado_atributo_cpf'])&&$GLOBALS['phpgw_info']['server']['certificado_atributo_cpf']!=''?$GLOBALS['phpgw_info']['server']['certificado_atributo_cpf']:"uid";
  62. $filtro = $cert_atrib_cpf .'='. $c->dados['2.16.76.1.3.1']['CPF'];
  63. $atributos = array();
  64. $atributos[] = "usercertificate";
  65. $atributos[] = "phpgwaccountstatus";
  66. $atributos[] = "cryptpassword";
  67. $atributos[] = "uid";
  68. $sr=ldap_search($ds, $GLOBALS['phpgw_info']['server']['ldap_context'],$filtro,$atributos);
  69. $info = ldap_get_entries($ds, $sr);
  70. if($info["count"]!=1)
  71. {
  72. echo '6'.chr(0x0D).chr(0x0A).lang('Invalid data from users directory');
  73. ldap_close($ds);
  74. exit();
  75. }
  76. if($info[0]['phpgwaccountstatus'][0]!='A')
  77. {
  78. echo '7'.chr(0x0D).chr(0x0A).lang('User account is inactive in Expresso');
  79. ldap_close($ds);
  80. exit();
  81. }
  82. if($info[0]["cryptpassword"][0] && $info[0]["usercertificate"][0] && $cert == $info[0]["usercertificate"][0] )
  83. {
  84. echo '0'.chr(0x0D).chr(0x0A).$info[0]["uid"][0].chr(0x0D).chr(0x0A).$info[0]["cryptpassword"][0];
  85. }
  86. else
  87. {
  88. echo '8'.chr(0x0D).chr(0x0A).lang('The current certificate not registered to login');
  89. }
  90. ldap_close($ds);
  91. ?>