Skip to content

Commit

Permalink
Gerado Novo Cacert - Gerado Versão 2.10
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel-Oliveira committed May 5, 2023
1 parent 72de44c commit 09399bc
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 56 deletions.
6 changes: 0 additions & 6 deletions .travis.yml

This file was deleted.

File renamed without changes.
File renamed without changes.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Java_Certificado [![MIT License](https://img.shields.io/github/license/Samuel-Oliveira/Java_Certificado.svg)](https://github.com/Samuel-Oliveira/Java_Certificado/blob/master/LICENSE) [![Maven Central](https://img.shields.io/maven-central/v/br.com.swconsultoria/java_certificado.svg?label=Maven%20Central)](https://search.maven.org/artifact/br.com.swconsultoria/java_certificado/2.9/jar)
# Java_Certificado [![MIT License](https://img.shields.io/github/license/Samuel-Oliveira/Java_Certificado.svg)](https://github.com/Samuel-Oliveira/Java_Certificado/blob/master/LICENSE) [![Maven Central](https://img.shields.io/maven-central/v/br.com.swconsultoria/java_certificado.svg?label=Maven%20Central)](https://search.maven.org/artifact/br.com.swconsultoria/java_certificado/2.10/jar)

Projeto Java de Gerenciamentos de Certificado Digital

Expand All @@ -9,14 +9,14 @@ Projeto Java de Gerenciamentos de Certificado Digital
<img src="https://swconsultoria.com.br/pix.png" width="200">

Para Iniciar :
- Caso use Libs baixe o [java-certificado-2.9.jar](https://github.com/Samuel-Oliveira/Java_Certificado/raw/master/java_certificado-2.9.jar) e o adicione às bibliotecas de Seu Projeto.
- Caso use Libs baixe o [java-certificado-2.10.jar](https://github.com/Samuel-Oliveira/Java_Certificado/raw/master/java_certificado-2.10.jar) e o adicione às bibliotecas de Seu Projeto.

- Caso use Maven :
```
<dependency>
<groupId>br.com.swconsultoria</groupId>
<artifactId>java_certificado</artifactId>
<version>2.9</version>
<version>2.10</version>
</dependency>
```

Expand All @@ -25,6 +25,11 @@ Veja a [Wiki](https://Samuel-Oliveira.github.io/Java_Certificado/), para ter um
________________________________________________________________________________________________
# Historico de Versões

## v2.10 - 05/05/2023
- Gerado novo Cacert
- Adicionado numero de serie ao objeto certificado
- Melhorias Exceptions

## v2.9 - 21/01/2023
- Gerado novo Cacert
- Atualizado Versão BouncyCastle para previnir vunerabilidades
Expand Down
Binary file modified cacert
Binary file not shown.
6 changes: 3 additions & 3 deletions docs/docs/index.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![MIT License](https://img.shields.io/github/license/Samuel-Oliveira/Java_Certificado.svg)](https://github.com/Samuel-Oliveira/Java_Certificado/blob/master/LICENSE) [![Maven Central](https://img.shields.io/maven-central/v/br.com.swconsultoria/java_certificado.svg?label=Maven%20Central)](https://search.maven.org/artifact/br.com.swconsultoria/java_certificado/2.9/jar)
[![MIT License](https://img.shields.io/github/license/Samuel-Oliveira/Java_Certificado.svg)](https://github.com/Samuel-Oliveira/Java_Certificado/blob/master/LICENSE) [![Maven Central](https://img.shields.io/maven-central/v/br.com.swconsultoria/java_certificado.svg?label=Maven%20Central)](https://search.maven.org/artifact/br.com.swconsultoria/java_certificado/2.10/jar)

***Projeto Java de Gerenciamentos de Certificado Digital***

Expand All @@ -11,13 +11,13 @@
</p>

Para Iniciar :
- Caso use Libs baixe o java-certificado-2.9.jar (https://github.com/Samuel-Oliveira/Java_Certificado/raw/master/java_certificado-2.9.jar) e o adicione às bibliotecas de Seu Projeto.
- Caso use Libs baixe o java-certificado-2.10.jar (https://github.com/Samuel-Oliveira/Java_Certificado/raw/master/java_certificado-2.10.jar) e o adicione às bibliotecas de Seu Projeto.

- Caso use Maven :
```xml
<dependency>
<groupId>br.com.swconsultoria</groupId>
<artifactId>java_certificado</artifactId>
<version>2.9</version>
<version>2.10</version>
</dependency>
```
Binary file not shown.
26 changes: 0 additions & 26 deletions java_certificado.iml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static void inicia(Certificado certificado, InputStream iSCacert) throws Certifi
cacert = file.getAbsolutePath();
file.deleteOnExit();
} catch (IOException ex) {
throw new CertificadoException(ex.getMessage());
throw new CertificadoException(ex.getMessage(),ex);
}

System.setProperty("javax.net.ssl.trustStore", cacert);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static void inicializaCertificado(Certificado certificado, InputStream ca

if (Logger.getLogger("").isLoggable(Level.SEVERE) && !ultimoLog.equals(certificado.getCnpjCpf())) {
System.err.println("####################################################################");
System.err.println(" Java-Certificado - Versão 2.9 - 21/01/2023 ");
System.err.println(" Java-Certificado - Versão 2.10 - 05/05/2023 ");
if (Logger.getLogger("").isLoggable(Level.WARNING)) {
System.err.println(" Samuel Olivera - samuel@swconsultoria.com.br ");
}
Expand All @@ -64,15 +64,15 @@ public static void inicializaCertificado(Certificado certificado, InputStream ca
}
System.err.println(" Cnpj/Cpf: " + certificado.getCnpjCpf() +
" - Alias: " + certificado.getNome().toUpperCase());
System.err.println(" Arquivo Cacert: " + (cacertProprio ? "Default - Última Atualização: 22/09/2021" : "Customizado"));
System.err.println(" Arquivo Cacert: " + (cacertProprio ? "Default - Última Atualização: 05/05/2023" : "Customizado"));
System.err.println(" Conexão SSL: " + (certificado.isAtivarProperties() ? "Properties (Não Recomendado)" : "Socket Dinãmico") +
" - Protocolo SSL: " + certificado.getSslProtocol());
System.err.println("####################################################################");
ultimoLog = certificado.getCnpjCpf();
}

} catch (KeyStoreException | NoSuchAlgorithmException | KeyManagementException | CertificateException | IOException e) {
throw new CertificadoException(e.getMessage());
throw new CertificadoException(e.getMessage(),e);
}

}
Expand All @@ -87,7 +87,7 @@ public static Certificado certificadoPfxBytes(byte[] certificadoBytes, String se
setDadosCertificado(certificado, null);
} catch (KeyStoreException e) {
throw new CertificadoException("Erro ao carregar informações do certificado:" +
e.getMessage());
e.getMessage(),e);
}

return certificado;
Expand Down Expand Up @@ -132,7 +132,7 @@ public static Certificado certificadoPfx(String caminhoCertificado, String senha
setDadosCertificado(certificado, null);
} catch (KeyStoreException e) {
throw new CertificadoException("Erro ao carregar informações do certificado:" +
e.getMessage());
e.getMessage(),e);
}

return certificado;
Expand Down Expand Up @@ -161,7 +161,7 @@ public static Certificado certificadoA3(String marca, String dll, String senha,
return certificado;
} catch (Exception e) {
throw new CertificadoException("Erro ao carregar informações do certificado:" +
e.getMessage());
e.getMessage(),e);
}

}
Expand Down Expand Up @@ -194,7 +194,7 @@ private static List<Certificado> listaCertificadosRepositorio(TipoCertificadoEnu
}
} catch (KeyStoreException ex) {
throw new CertificadoException("Erro ao Carregar Certificados:" +
ex.getMessage());
ex.getMessage(),ex);
}
return listaCert;
}
Expand Down Expand Up @@ -222,7 +222,7 @@ public static List<String> listaAliasCertificadosA3(String marca, String dll, St
return listaCert;
} catch (KeyStoreException ex) {
throw new CertificadoException("Erro ao Carregar Certificados A3:" +
ex.getMessage());
ex.getMessage(),ex);
}

}
Expand Down Expand Up @@ -296,7 +296,7 @@ public static KeyStore getKeyStore(Certificado certificado) throws CertificadoEx
throw new CertificadoException("Senha do Certificado inválida.");

throw new CertificadoException("Erro Ao pegar KeyStore: " +
e.getMessage());
e.getMessage(),e);
}

}
Expand All @@ -308,7 +308,7 @@ public static X509Certificate getCertificate(Certificado certificado, KeyStore k

} catch (KeyStoreException e) {
throw new CertificadoException("Erro Ao pegar X509Certificate: " +
e.getMessage());
e.getMessage(),e);
}

}
Expand Down Expand Up @@ -356,7 +356,7 @@ private static String getSlot(String libraryPath, String serialNumber) throws IO
tmpPKCS11 = PKCS11.getInstance(libraryPath, functionList, null, true);
} catch (Exception ex) {
throw new CertificadoException("Erro ao pegar Slot A3: " +
e.getMessage());
e.getMessage(),e);
}
}

Expand All @@ -373,7 +373,7 @@ private static String getSlot(String libraryPath, String serialNumber) throws IO
}
} catch (Exception e) {
throw new CertificadoException("Erro Ao pegar SlotA3: " +
e.getMessage());
e.getMessage(),e);
}

return slotSelected;
Expand Down Expand Up @@ -423,7 +423,7 @@ private static String getDocumentoFromCertificado(X509Certificate certificate) t

} catch (Exception e) {
throw new CertificadoException("Erro ao pegar Documento do Certificado: " +
e.getMessage());
e.getMessage(),e);
}
return cnpjCpf[0];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private KeyManager[] createKeyManagers() {

private TrustManager[] createTrustManagers() throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {
final TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
KeyStore trustStore = KeyStore.getInstance("JKS");
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(fileCacerts, "changeit".toCharArray());
trustManagerFactory.init(trustStore);
return trustManagerFactory.getTrustManagers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ public CertificadoException(Throwable e) {
super(e);
}


public CertificadoException(String message, Throwable cause) {
super(message, cause);
}

/**
* Construtor da classe.
*
Expand Down
Binary file modified src/main/resources/cacert
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.junit.jupiter.api.Test;

import java.io.*;
import java.math.BigInteger;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.time.LocalDate;
Expand All @@ -23,8 +24,8 @@

class CertificadoServiceTest {

private final String CERTIFICADO_CPF = "CertificadoTesteCPF.pfx";
private final String CERTIFICADO_CNPJ = "CertificadoTesteCNPJ.pfx";
private final String CERTIFICADO_CPF = "NaoUsar_CPF.pfx";
private final String CERTIFICADO_CNPJ = "NaoUsar_CNPJ.pfx";
private final String CPF = "99999999999";
private final String CNPJ = "99999999999999";
private final String SENHA = "123456";
Expand Down Expand Up @@ -72,6 +73,7 @@ void certificadoPfxCPF() throws CertificadoException, FileNotFoundException {
assertEquals(certificado.getSslProtocol(), "TLSv1.2");
assertFalse(certificado.isAtivarProperties());
assertEquals(certificado.getTipoCertificado(), TipoCertificadoEnum.ARQUIVO);
assertEquals(certificado.getNumeroSerie(), new BigInteger("219902325555"));
}

@Test
Expand All @@ -86,6 +88,7 @@ void certificadoPfxCNPJ() throws CertificadoException, FileNotFoundException {
assertEquals(certificado.getSslProtocol(), "TLSv1.2");
assertFalse(certificado.isAtivarProperties());
assertEquals(certificado.getTipoCertificado(), TipoCertificadoEnum.ARQUIVO);
assertEquals(certificado.getNumeroSerie(), new BigInteger("219902325555"));
}

@Test
Expand Down Expand Up @@ -129,6 +132,7 @@ void certificadoPfxBytes() throws CertificadoException, IOException {
assertEquals(certificado.getSslProtocol(), "TLSv1.3");
assertEquals(certificado.isAtivarProperties(), false);
assertEquals(certificado.getTipoCertificado(), TipoCertificadoEnum.ARQUIVO_BYTES);
assertEquals(certificado.getNumeroSerie(), new BigInteger("219902325555"));
}

@Test
Expand Down

0 comments on commit 09399bc

Please sign in to comment.