<?php

/**
 * Class Pkcs12Test
 * @author Roberto L. Machado <linux dot rlm at gmail dot com>
 */
use NFePHP\Common\Certificate\Asn;
use NFePHP\Common\Certificate\Pkcs12;

class Pkcs12Test extends PHPUnit_Framework_TestCase
{
    protected $pubPem = '-----BEGIN CERTIFICATE-----
MIIEqzCCA5OgAwIBAgIDMTg4MA0GCSqGSIb3DQEBBQUAMIGSMQswCQYDVQQGEwJC
UjELMAkGA1UECBMCUlMxFTATBgNVBAcTDFBvcnRvIEFsZWdyZTEdMBsGA1UEChMU
VGVzdGUgUHJvamV0byBORmUgUlMxHTAbBgNVBAsTFFRlc3RlIFByb2pldG8gTkZl
IFJTMSEwHwYDVQQDExhORmUgLSBBQyBJbnRlcm1lZGlhcmlhIDEwHhcNMDkwNTIy
MTcwNzAzWhcNMTAxMDAyMTcwNzAzWjCBnjELMAkGA1UECBMCUlMxHTAbBgNVBAsT
FFRlc3RlIFByb2pldG8gTkZlIFJTMR0wGwYDVQQKExRUZXN0ZSBQcm9qZXRvIE5G
ZSBSUzEVMBMGA1UEBxMMUE9SVE8gQUxFR1JFMQswCQYDVQQGEwJCUjEtMCsGA1UE
AxMkTkZlIC0gQXNzb2NpYWNhbyBORi1lOjk5OTk5MDkwOTEwMjcwMIGfMA0GCSqG
SIb3DQEBAQUAA4GNADCBiQKBgQCx1O/e1Q+xh+wCoxa4pr/5aEFt2dEX9iBJyYu/
2a78emtorZKbWeyK435SRTbHxHSjqe1sWtIhXBaFa2dHiukT1WJyoAcXwB1GtxjT
2VVESQGtRiujMa+opus6dufJJl7RslAjqN/ZPxcBXaezt0nHvnUB/uB1K8WT9G7E
S0V17wIDAQABo4IBfjCCAXowIgYDVR0jAQEABBgwFoAUPT5TqhNWAm+ZpcVsvB7m
alDBjEQwDwYDVR0TAQH/BAUwAwEBADAPBgNVHQ8BAf8EBQMDAOAAMAwGA1UdIAEB
AAQCMAAwgawGA1UdEQEBAASBoTCBnqA4BgVgTAEDBKAvBC0yMjA4MTk3Nzk5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zAOBgNVHQ8BAf8EBAMCAQYwDQYJKoZIhvcNAQENBQADggIBAKIgDXqL5JueJlsR
DE0YaWlfuIzCgVBC1j62RbzDGcBR8rn/JkOp+zXRiQePivDA+rMlUecTpUG7O6M8
UFKJqAnEURf8HVTQdYUr8TZs2XycVMaGCmL7lud6NsDTFvFNBKJU9RuJ8lj8k68S
g2XlBl2Bxykm7KrtWfpNWFWq6gr/U60N7fYlCVBLRH6dcCuLNcruvKmPdCgDUQs6
+7ilETF0m2GTGT/R85pBc2ldM0S9j3M8oGvWW7FAFruYozKGLWhHjmsj9LVNrfkJ
DcQ4KG3M7Gx/px+a7b276ehXxzPSr6EjZQLonhtlVUWpQ+4Y1GUrhIekIQYky9Vz
2CZ4MFs+2j9y6NMZa5Efy+GkIhJqdVRCRYWaL9B4dnTi4N2qO+odU4fURaOxcJhj
r7XL9ptxJMrh2Y9c/O+NDU4BUsmdhLHPU3TXHFxQj6W5rO+1KKqyU3ZrBBq47YZ0
kqaS/wPRg+1UwmRyuddceDnmsmx+2b7ocFYNmE0l7qsp8kw1z/PQcijXcp8Tlunu
NYjdmgIThhgdue2Y4CKSHcjdB+sXsgAP9jx0OYdrRVgdAyMt/2LPGQNW3Lhb9B+y
aw6Jcw8PUEIRFSrvhM3gz1S7VJELf0CEw1ED26MduNjPv4/ycpOfkriRYELHT/uF
VURh6kJDAMVhhB5URXSnHhuGrKGi
-----END CERTIFICATE-----
';


    public function testCarregarPfx()
    {
        $pathCerts = '';
        $cnpj = '99999090910270';
        $pubKey = '';
        $priKey = '';
        $certKey = '';
        $pkcs = new Pkcs12($pathCerts, $cnpj, $pubKey, $priKey, $certKey);
        $arquivopfx = dirname(dirname(dirname(__FILE__))) . '/fixtures/certs/certificado_teste.pfx';
        $pfxContent = file_get_contents($arquivopfx);
        $keyPass = 'associacao';
        $createFiles = false;
        $ignoreValidity = true;
        $ignoreOwner = true;
        $resp = $pkcs->loadPfx($pfxContent, $keyPass, $createFiles, $ignoreValidity, $ignoreOwner);
        $this->assertTrue($resp);
        $this->assertEquals($this->pubPem, $pkcs->pubKey);
        $this->assertEquals($this->priPem, $pkcs->priKey);
    }
    
    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 = 'associacao';
        $createFiles = false;
        $ignoreValidity = true;
        $ignoreOwner = true;
        $resp = $pkcs->loadPfxFile($arquivopfx, $keyPass, $createFiles, $ignoreValidity, $ignoreOwner);
        $this->assertTrue($resp);
    }

    /**
     * @expectedException NFePHP\Common\Exception\RuntimeException
     * @expectedExceptionMessage Data de validade vencida! [Valido até 02/10/10]
     */
    public function testValidadeCertificado()
    {
        $cnpj = '99999090910270';
        $pathCerts = '';
        $ignoreValidCert = false;
        new Pkcs12($pathCerts, $cnpj, $this->pubPem, $this->priPem, '', $ignoreValidCert);
    }

    /**
     * @expectedException NFePHP\Common\Exception\InvalidArgumentException
     * @expectedExceptionMessage O Certificado fornecido pertence a outro CNPJ!!
     */
    public function testProprietarioCertificado()
    {
        $pathCerts = '';
        $cnpj = '55599090910270';
        $pubKey = '';
        $priKey = '';
        $certKey = '';
        $pkcs = new Pkcs12($pathCerts, $cnpj, $pubKey, $priKey, $certKey);
        $arquivopfx = dirname(dirname(dirname(__FILE__))) . '/fixtures/certs/certificado_teste.pfx';
        $pfxContent = file_get_contents($arquivopfx);
        $keyPass = 'associacao';
        $createFiles = false;
        $ignoreValidity = true;
        $ignoreOwner = false;
        $pkcs->loadPfx($pfxContent, $keyPass, $createFiles, $ignoreValidity, $ignoreOwner);
    }
    
    public function testAssinarXml()
    {
        $cnpj = '99999090910270';
        $pathCerts = '';
        $ignoreValidCert = true;
        $pkcs = new Pkcs12($pathCerts, $cnpj, $this->pubPem, $this->priPem, '', $ignoreValidCert);
        $xmlpath = dirname(dirname(dirname(__FILE__))) . '/fixtures/xml/NFe/35101158716523000119550010000000011003000000-nfe.xml';
        $docxml = file_get_contents($xmlpath);
        $signedxmlpath = dirname(dirname(dirname(__FILE__))) . '/fixtures/xml/NFe/signed-nfe.xml';
        $docsigned= file_get_contents($signedxmlpath);
        $doc = $pkcs->signXML($docxml, 'infNFe');
        $this->assertEquals($doc, $docsigned);
    }
    
    public function testVerificarAssinatura()
    {
        $cnpj = '99999090910270';
        $pkcs = new Pkcs12('', $cnpj, '', '', '', true);
        $signedxmlpath = dirname(dirname(dirname(__FILE__))) . '/fixtures/xml/NFe/signed-nfe.xml';
        $ret = $pkcs->verifySignature($signedxmlpath, 'infNFe');
        $this->assertTrue($ret);
    }
    
    public function testAdicionarCadeiaCertificados()
    {
        $aCerts[] = dirname(dirname(dirname(__FILE__))) . '/fixtures/certs/ACCertisignG6_v2.cer';
        $aCerts[] = dirname(dirname(dirname(__FILE__))) . '/fixtures/certs/ACCertisignMultiplaG5.cer';
        $aCerts[] = dirname(dirname(dirname(__FILE__))) . '/fixtures/certs/ACRaizBrasileira_v2.cer';
        $cert = $this->priPem . "\r\n" .
            $this->pubPem . "\r\n" .
            $this->accg6 . "\r\n" .
            $this->accmg5 . "\r\n" .
            $this->acraizbr;
        $cert = str_replace(array("\r","\n"), '', $cert);
        $cnpj = '99999090910270';
        $pathCerts = '';
        $ignoreValidCert = true;
        $pkcs = new Pkcs12($pathCerts, $cnpj, $this->pubPem, $this->priPem, '', $ignoreValidCert);
        $pkcs->aadChain($aCerts);
        $cadeiacompleta = str_replace(array("\r","\n"), '', $pkcs->certKey);
        $this->assertEquals($cadeiacompleta, $cert);
    }
}
