-
Notifications
You must be signed in to change notification settings - Fork 534
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1061 from nfephp-org/testes
Incluindo manual para criação de certificados auto assinados de teste
- Loading branch information
Showing
7 changed files
with
123 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# Gerar Certificado auto assinado | ||
|
||
## Para um CNPJ | ||
1 - Gerar chave privada: | ||
``` | ||
openssl genpkey -algorithm RSA -out private.key -pkeyopt rsa_keygen_bits:2048 | ||
``` | ||
|
||
2 - Crie o arquivo de configuração openssl.cnf: | ||
|
||
``` | ||
[ req ] | ||
distinguished_name = req_distinguished_name | ||
x509_extensions = v3_ca | ||
req_extensions = v3_req | ||
[ req_distinguished_name ] | ||
C = BR | ||
ST = São Paulo | ||
L = São Paulo | ||
O = Sua Empresa | ||
OU = Unidade de TI | ||
CN = 05.730.928/0001-45 | ||
emailAddress = email@suaempresa.com.br | ||
[ v3_ca ] | ||
subjectAltName = @alt_names | ||
basicConstraints = CA:TRUE | ||
keyUsage = keyCertSign, cRLSign | ||
[ v3_req ] | ||
basicConstraints = CA:FALSE | ||
keyUsage = nonRepudiation, digitalSignature, keyEncipherment | ||
subjectAltName = @alt_names | ||
2.16.76.1.3.3 = ASN1:UTF8String:05730928000145 | ||
[ alt_names ] | ||
email = email@suaempresa.com.br | ||
``` | ||
|
||
3 - Gere o certificado autoassinado: | ||
|
||
```bash | ||
openssl req -new -x509 -days 3650 -key private.key -out certificate.crt -config openssl.cnf -extensions v3_req | ||
``` | ||
|
||
4 - Converta para o formato PFX: | ||
|
||
```bash | ||
openssl pkcs12 -export -out certificate.pfx -inkey private.key -in certificate.crt -certfile certificate.crt -passout pass:minhasenha | ||
``` | ||
|
||
|
||
## Para um CPF | ||
|
||
Mesmos passos anteriores, exeto o arquivo openssl.cnf será esse abaixo. | ||
Note que o oid 2.16.76.1.3.1 é composto por uma data de nascimento seguido do CPF. | ||
2.16.76.1.3.1 = ASN1:UTF8String:ddddddddccccccccccc | ||
Onde d é data de nascimento e c é o cpf somente números. | ||
|
||
``` | ||
[ req ] | ||
distinguished_name = req_distinguished_name | ||
x509_extensions = v3_ca | ||
req_extensions = v3_req | ||
[ req_distinguished_name ] | ||
C = BR | ||
ST = São Paulo | ||
L = São Paulo | ||
O = SpedNfe | ||
OU = Unidade de TI | ||
CN = 904.839.260-86 | ||
emailAddress = email@suaempresa.com.br | ||
[ v3_ca ] | ||
subjectAltName = @alt_names | ||
basicConstraints = CA:TRUE | ||
keyUsage = keyCertSign, cRLSign | ||
[ v3_req ] | ||
basicConstraints = CA:FALSE | ||
keyUsage = nonRepudiation, digitalSignature, keyEncipherment | ||
subjectAltName = @alt_names | ||
2.16.76.1.3.1 = ASN1:UTF8String:1210198506157250000116 | ||
[ alt_names ] | ||
email = email@suaempresa.com.br | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace NFePHP\NFe\Tests; | ||
|
||
use NFePHP\Common\Certificate; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class CertificateTest extends TestCase | ||
{ | ||
public function test_certificado_pj(): void | ||
{ | ||
$conteudo = file_get_contents(TESTS_FIXTURES . '/certs/cert_cnpj_06157250000116_senha_minhasenha.pfx'); | ||
$certificado = Certificate::readPfx($conteudo, 'minhasenha'); | ||
$this->assertSame('06157250000116', $certificado->getCnpj()); | ||
$this->assertSame('05/06/2034', $certificado->getValidTo()->format('d/m/Y')); | ||
} | ||
|
||
public function test_certificado_pf(): void | ||
{ | ||
$conteudo = file_get_contents(TESTS_FIXTURES . '/certs/cert_cpf_90483926086_minhasenha.pfx'); | ||
$certificado = Certificate::readPfx($conteudo, 'minhasenha'); | ||
$this->assertSame('90483926086', $certificado->getCpf()); | ||
$this->assertSame('03/06/2034', $certificado->getValidTo()->format('d/m/Y')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?php | ||
|
||
include dirname(__DIR__) . '/vendor/autoload.php'; | ||
include __DIR__ . '/constantes.php'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
|
||
define('TESTS_FIXTURES', __DIR__ . '/fixtures'); |
Binary file not shown.
Binary file not shown.