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

FIWARE / contract-management / #91

22 Apr 2026 06:29AM UTC coverage: 1.776% (+0.1%) from 1.681%
#91

push

web-flow
Merge pull request #23 from FIWARE/fix/proxy

fix(proxy): do not require proxyHost and proxyPort when proxy is disabled

20 of 136 new or added lines in 11 files covered. (14.71%)

1 existing line in 1 file now uncovered.

621 of 34976 relevant lines covered (1.78%)

0.02 hits per line

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

0.0
/src/main/java/org/fiware/iam/cert/CertReader.java
1
package org.fiware.iam.cert;
2

3
import org.bouncycastle.openssl.PEMKeyPair;
4
import org.bouncycastle.openssl.PEMParser;
5
import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter;
6
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
7

8
import java.io.IOException;
9
import java.io.InputStream;
10
import java.io.InputStreamReader;
11
import java.nio.charset.StandardCharsets;
12
import java.nio.file.Files;
13
import java.nio.file.Path;
14
import java.nio.file.Paths;
15
import java.security.PrivateKey;
16
import java.security.cert.CertificateException;
17
import java.security.cert.CertificateFactory;
18
import java.security.cert.X509Certificate;
19
import jakarta.inject.Singleton;
20
import java.util.List;
21

22
@Singleton
NEW
23
public class CertReader {
×
24

25
    public PrivateKey loadPrivateKey(String filename) {
NEW
26
        try (InputStream is = openInputStream(filename)) {
×
NEW
27
            if (is == null) {
×
NEW
28
                throw new IllegalArgumentException("Private key not found: " + filename);
×
29
            }
NEW
30
            PEMParser parser = new PEMParser(new InputStreamReader(is, StandardCharsets.UTF_8));
×
NEW
31
            Object obj = parser.readObject();
×
NEW
32
            JcaPEMKeyConverter converter = new JcaPEMKeyConverter();
×
NEW
33
            if (obj instanceof PEMKeyPair pemKeyPair) {
×
NEW
34
                return converter.getPrivateKey(pemKeyPair.getPrivateKeyInfo());
×
NEW
35
            } else if (obj instanceof PrivateKeyInfo privateKeyInfo) {
×
NEW
36
                return converter.getPrivateKey(privateKeyInfo);
×
37
            }
NEW
38
            throw new IllegalArgumentException("Unsupported key format in: " + filename);
×
NEW
39
        } catch (IOException e) {
×
NEW
40
            throw new IllegalArgumentException("Was not able to load the private key from " + filename, e);
×
41
        }
42
    }
43

44
    public List<X509Certificate> loadCertificates(String resource) {
NEW
45
        try (InputStream is = openInputStream(resource)) {
×
NEW
46
            if (is == null) {
×
NEW
47
                throw new IllegalArgumentException("Certificate file not found: " + resource);
×
48
            }
NEW
49
            CertificateFactory cf = CertificateFactory.getInstance("X.509");
×
NEW
50
            return cf.generateCertificates(is).stream()
×
NEW
51
                    .map(X509Certificate.class::cast)
×
NEW
52
                    .toList();
×
NEW
53
        } catch (IOException | CertificateException e) {
×
NEW
54
            throw new IllegalArgumentException(String.format("Was not able to load the certificates from %s", resource), e);
×
55
        }
56
    }
57

58
    private InputStream openInputStream(String filepath) throws IOException {
NEW
59
        Path path = Paths.get(filepath);
×
NEW
60
        if (!Files.isRegularFile(path)) {
×
NEW
61
            return null;
×
62
        }
NEW
63
        return Files.newInputStream(path);
×
64
    }
65

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

© 2026 Coveralls, Inc