Пример #1
0
 /**
  * Executa a leitura do arquivo de configuração e
  * carrega o certificado
  *
  * @param string $config
  * @param bool   $ignore
  */
 protected function loadConfig($config = '', $ignore = false)
 {
     if (is_file($config)) {
         $config = FilesFolders::readFile($config);
     }
     $result = json_decode($config);
     if (json_last_error() === JSON_ERROR_NONE) {
         $this->objConfig = $result;
     }
     if (!is_object($this->objConfig)) {
         throw new InvalidArgumentException("Uma configuração valida deve ser passada!");
     }
     $this->pkcs = new Pkcs12($this->objConfig->pathCertsFiles, $this->objConfig->cnpj, '', '', '', $ignore);
     $this->pkcs->loadPfxFile($this->objConfig->pathCertsFiles . $this->objConfig->certPfxName, $this->objConfig->certPassword, true, $ignore, false);
 }
Пример #2
0
 /**
  * checkCerts
  * @param string $cnpj
  * @param string $pathCertsFiles
  * @param string $certPfxName
  * @param string $certPassword
  * @return array
  */
 public static function checkCerts($cnpj = '', $pathCertsFiles = '', $certPfxName = '', $certPassword = '')
 {
     $flag = true;
     $msg = '';
     if (strlen($cnpj) != 14) {
         $flag = $flag && false;
         $msg .= "CNPJ incorreto! {$cnpj} \n";
     }
     if (!is_dir($pathCertsFiles)) {
         $flag = $flag && false;
         $msg .= "Diretório não localizado! {$pathCertsFiles} \n";
     }
     if (substr($pathCertsFiles, -1) !== DIRECTORY_SEPARATOR) {
         $pathCertsFiles .= DIRECTORY_SEPARATOR;
     }
     try {
         $cert = new Pkcs12($pathCertsFiles, $cnpj);
         $flag = $cert->loadPfxFile($pathCertsFiles . $certPfxName, $certPassword);
     } catch (InvalidArgumentException $exc) {
         $flag = false;
         $msg .= $exc->getMessage();
     } catch (RuntimeException $exc) {
         $flag = false;
         $msg .= $exc->getMessage();
     }
     if ($msg == '') {
         $msg = 'Certificado Validado, arquivos PEM criados na pasta.';
     }
     return array('cert' => array('status' => $flag, 'msg' => $msg));
 }
Пример #3
0
 public function testCarregarPfxFile()
 {
     $pathCerts = '';
     $cnpj = '99999090910270';
     $pubKey = '';
     $priKey = '';
     $certKey = '';
     $pkcs = new Pkcs12($pathCerts, $cnpj, $pubKey, $priKey, $certKey);
     $arquivopfx = dirname(dirname(dirname(__FILE__))) . '/fixtures/certs/certificado_teste.pfx';
     $keyPass = '******';
     $createFiles = false;
     $ignoreValidity = true;
     $ignoreOwner = true;
     $resp = $pkcs->loadPfxFile($arquivopfx, $keyPass, $createFiles, $ignoreValidity, $ignoreOwner);
     $this->assertTrue($resp);
 }