• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wmixvideo / nfe / #9519

28 Jul 2026 03:08PM UTC coverage: 51.085%. First build
#9519

push

web-flow
Merge 00094c686 into 0beb7b6c6

68 of 72 new or added lines in 4 files covered. (94.44%)

15201 of 29756 relevant lines covered (51.09%)

0.51 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/java/com/fincatto/documentofiscal/utils/DFSocketFactory.java
1
package com.fincatto.documentofiscal.utils;
2

3
import com.fincatto.documentofiscal.DFConfig;
4
import org.apache.commons.httpclient.params.HttpConnectionParams;
5
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
6

7
import javax.net.ssl.KeyManager;
8
import javax.net.ssl.SSLContext;
9
import javax.net.ssl.SSLSocket;
10
import javax.net.ssl.TrustManager;
11
import javax.net.ssl.TrustManagerFactory;
12
import java.io.IOException;
13
import java.net.InetAddress;
14
import java.net.InetSocketAddress;
15
import java.net.Socket;
16
import java.security.KeyManagementException;
17
import java.security.KeyStoreException;
18
import java.security.NoSuchAlgorithmException;
19
import java.security.UnrecoverableKeyException;
20

21
public class DFSocketFactory implements ProtocolSocketFactory {
22

23
    public static final int TIMEOUT_PADRAO_EM_MILLIS = 60_000;
24
    public static final int SO_TIMEOUT_PADRAO_EM_MILLIS = 30_000;
25

26
    private final DFConfig config;
27
    private final SSLContext sslContext;
28
    
29
    public DFSocketFactory(final DFConfig config) throws UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
×
30
        this.config = config;
×
31
        this.sslContext = this.createSSLContext(config);
×
32
    }
×
33

34
    /**
35
     * Expoe o {@link SSLContext} ja montado a partir do certificado A1 (via {@link DFKeyManager})
36
     * e da cadeia de certificados da SEFAZ, para que outros clientes HTTP (ex.: {@link DFHttpClient})
37
     * possam reaproveita-lo sem duplicar a leitura do KeyStore/TrustStore.
38
     *
39
     * @return o SSLContext usado para o mTLS com a SEFAZ.
40
     */
41
    public SSLContext getSslContext() {
NEW
42
        return this.sslContext;
×
43
    }
44

45
    @Override
46
    public Socket createSocket(final String host, final int port, final InetAddress localAddress, final int localPort, final HttpConnectionParams params) throws IOException {
47
        final Socket socket = this.sslContext.getSocketFactory().createSocket();
×
48
        ((SSLSocket) socket).setEnabledProtocols(this.config.getSSLProtocolos());
×
49
        socket.bind(new InetSocketAddress(localAddress, localPort));
×
50
        
51
        final int connectTimeout = params.getConnectionTimeout();
×
52

53
        socket.connect(new InetSocketAddress(host, port), connectTimeout);
×
54
        return socket;
×
55
    }
56

57
    @Override
58
    public Socket createSocket(final String host, final int port, final InetAddress clientHost, final int clientPort) throws IOException {
59
        return this.sslContext.getSocketFactory().createSocket(host, port, clientHost, clientPort);
×
60
    }
61

62
    @Override
63
    public Socket createSocket(final String host, final int port) throws IOException {
64
        return this.sslContext.getSocketFactory().createSocket(host, port);
×
65
    }
66

67
    private SSLContext createSSLContext(final DFConfig config) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException, UnrecoverableKeyException {
68
        final KeyManager[] keyManagers = this.createKeyManagers(config);
×
69
        final TrustManager[] trustManagers = this.createTrustManagers(config);
×
70
        final SSLContext sslContext = SSLContext.getInstance(config.getSSLProtocolos()[0]);
×
71
        sslContext.init(keyManagers, trustManagers, null);
×
72
        return sslContext;
×
73
    }
74

75
    private KeyManager[] createKeyManagers(final DFConfig config) throws UnrecoverableKeyException, KeyStoreException, NoSuchAlgorithmException{
76
        return new KeyManager[]{new com.fincatto.documentofiscal.utils.DFKeyManager(config)};
×
77
    }
78

79
    private TrustManager[] createTrustManagers(final DFConfig config) throws KeyStoreException, NoSuchAlgorithmException {
80
        final TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
×
81
        trustManagerFactory.init(config.getCadeiaCertificadosKeyStore());
×
82
        return trustManagerFactory.getTrustManagers();
×
83
    }
84

85
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc