Skip to content

Commit

Permalink
Merge branch 'release/3.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel-Oliveira committed Jul 11, 2024
2 parents c8d8545 + 1cd744f commit 5d79258
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 13 deletions.
Binary file modified cacert
Binary file not shown.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>br.com.swconsultoria</groupId>
<artifactId>java_certificado</artifactId>
<version>3.7-SNAPSHOT</version>
<version>3.8-SNAPSHOT</version>
<name>Java_Certificado</name>
<description>Api java para gerenciamento de certificados digitais</description>
<url>https://github.com/Samuel-Oliveira/Java_Certificado</url>
Expand All @@ -19,7 +19,7 @@
<url>https://github.com/Samuel-Oliveira/Java_Certificado</url>
<connection>scm:git:[email protected]:Samuel-Oliveira/Java_Certificado.git</connection>
<developerConnection>scm:git:[email protected]:Samuel-Oliveira/Java_Certificado.git</developerConnection>
<tag>java_certificado-3.4</tag>
<tag>java_certificado-a-3.7</tag>
</scm>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public static void inicializaCertificado(Certificado certificado, InputStream ca

log.info(String.format("JAVA-CERTIFICADO | Samuel Oliveira | [email protected] " +
"| VERSAO=%s | DATA_VERSAO=%s | CNPJ/CPF=%s | VENCIMENTO=%s | ALIAS=%s | TIPO=%s | CAMINHO=%s | CACERT=%s | SSL=%s",
"3.6",
"08/06/2024",
"3.7",
"11/07/2024",
certificado.getCnpjCpf(),
certificado.getDataHoraVencimento(),
certificado.getNome().toUpperCase(),
Expand Down Expand Up @@ -144,15 +144,23 @@ public static Certificado certificadoA3(String senha, Provider provider) throws

}

public static List<Certificado> listaCertificadosWindows(boolean listarVencidos) throws CertificadoException {
return listaCertificadosRepositorio(TipoCertificadoEnum.REPOSITORIO_WINDOWS, listarVencidos);
}

public static List<Certificado> listaCertificadosMac(boolean listarVencidos) throws CertificadoException {
return listaCertificadosRepositorio(TipoCertificadoEnum.REPOSITORIO_MAC, listarVencidos);
}

public static List<Certificado> listaCertificadosWindows() throws CertificadoException {
return listaCertificadosRepositorio(TipoCertificadoEnum.REPOSITORIO_WINDOWS);
return listaCertificadosRepositorio(TipoCertificadoEnum.REPOSITORIO_WINDOWS, true);
}

public static List<Certificado> listaCertificadosMac() throws CertificadoException {
return listaCertificadosRepositorio(TipoCertificadoEnum.REPOSITORIO_MAC);
return listaCertificadosRepositorio(TipoCertificadoEnum.REPOSITORIO_MAC, true);
}

private static List<Certificado> listaCertificadosRepositorio(TipoCertificadoEnum tipo) throws CertificadoException {
private static List<Certificado> listaCertificadosRepositorio(TipoCertificadoEnum tipo, boolean listarVencidos) throws CertificadoException {

List<Certificado> listaCert = new ArrayList<>();
Certificado cert = new Certificado();
Expand All @@ -167,7 +175,13 @@ private static List<Certificado> listaCertificadosRepositorio(TipoCertificadoEnu
certificado.setTipoCertificado(tipo);
certificado.setNome(aliasKey);
setDadosCertificado(certificado, ks);
listaCert.add(certificado);
if (listarVencidos) {
listaCert.add(certificado);
} else {
if (certificado.isValido()) {
listaCert.add(certificado);
}
}
}
}
} catch (KeyStoreException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;

class SocketFactoryDinamico implements ProtocolSocketFactory {
public class SocketFactoryDinamico implements ProtocolSocketFactory {

private static final char[] SENHA_CACERT = "changeit".toCharArray();
private final KeyStore keyStore;
private final String alias;
private final String senha;
private final InputStream fileCacerts;
private SSLContext ssl;
private final SSLContext ssl;

SocketFactoryDinamico(KeyStore keyStore, String alias, String senha, InputStream fileCacerts, String sslProtocol) throws KeyManagementException,
public SocketFactoryDinamico(KeyStore keyStore, String alias, String senha, InputStream fileCacerts, String sslProtocol) throws KeyManagementException,
CertificateException,
NoSuchAlgorithmException, KeyStoreException, IOException {
this.keyStore = keyStore;
Expand Down Expand Up @@ -66,15 +66,19 @@ private SSLContext createSSLContext(String sslProtocol) throws CertificateExcept
return sslContext;
}

private KeyManager[] createKeyManagers() {
public KeyManager[] createKeyManagers() {
return new KeyManager[]{new AliasKeyManager(keyStore, alias, senha)};
}

private TrustManager[] createTrustManagers() throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {
public TrustManager[] createTrustManagers() throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {
final TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(fileCacerts, SENHA_CACERT);
trustManagerFactory.init(trustStore);
return trustManagerFactory.getTrustManagers();
}

public SSLContext getSsl() {
return ssl;
}
}
Binary file modified src/main/resources/cacert
Binary file not shown.

0 comments on commit 5d79258

Please sign in to comment.