Better information extraction from x509 command #20

Merged
MarkL4YG merged 22 commits from wip/38c3 into main 2025-04-21 10:16:27 +00:00
3 changed files with 24 additions and 8 deletions
Showing only changes of commit f8e9158a76 - Show all commits

View file

@ -29,7 +29,14 @@ public class Certificate {
private String trustingAuthority; private String trustingAuthority;
@Min(1) /**
* <ul>
* <li>-1 = no requested key length is known (might happen with imported certificates)</li>
* <li>0 = no key is available for this certificate (might happen with trusted third party certificates)</li>
* <li>> 1 = The key length in bits used for the private key of this certificate</li>
* </ul>
*/
@Min(-1)
private int requestedKeyLength; private int requestedKeyLength;
private OffsetDateTime notBefore; private OffsetDateTime notBefore;

View file

@ -32,4 +32,8 @@ public record X509CertificateInfo(
} }
return Collections.unmodifiableList(extensions); return Collections.unmodifiableList(extensions);
} }
public boolean hasExtensions() {
return extensions != null && !extensions.isEmpty();
}
} }

View file

@ -87,7 +87,9 @@ public class CertificateCreationService {
) )
); );
certificate.setSubjectCommonName(info.subject().getCommonName()); certificate.setSubjectCommonName(info.subject().getCommonName());
certificate.setTrustingAuthority(info.issuer().getCommonName()); if (info.issuer() != null) {
certificate.setTrustingAuthority(info.issuer().getCommonName());
}
certificate.setRequestedKeyLength(-1); certificate.setRequestedKeyLength(-1);
certificate.setNotBefore(info.notBefore()); certificate.setNotBefore(info.notBefore());
certificate.setNotAfter(info.notAfter()); certificate.setNotAfter(info.notAfter());
@ -100,12 +102,14 @@ public class CertificateCreationService {
certificate.setSubjectState(subjectInfo.getState()); certificate.setSubjectState(subjectInfo.getState());
certificate.setSubjectLocality(subjectInfo.getLocality()); certificate.setSubjectLocality(subjectInfo.getLocality());
final CertificateInfoExtension extension = info.extensions().getFirst(); if (info.hasExtensions()) {
if (extension != null) { final CertificateInfoExtension extension = info.extensions().getFirst();
final CertificateExtension certificateExtension = new CertificateExtension(); if (extension != null) {
certificateExtension.setIdentifier("alternativeNames"); final CertificateExtension certificateExtension = new CertificateExtension();
certificateExtension.setValue(String.join(",", extension.getAlternativeDnsNames())); certificateExtension.setIdentifier("alternativeNames");
certificate.setCertificateExtension(List.of(certificateExtension)); certificateExtension.setValue(String.join(",", extension.getAlternativeDnsNames()));
certificate.setCertificateExtension(List.of(certificateExtension));
}
} }
return certificate; return certificate;
} }
@ -119,6 +123,7 @@ public class CertificateCreationService {
try { try {
String fingerprint = openSSLService.getCertificateFingerprint(certificate); String fingerprint = openSSLService.getCertificateFingerprint(certificate);
Certificate entity = createEntityFromInfo(openSSLService.getCertificateInfo(certificate)); Certificate entity = createEntityFromInfo(openSSLService.getCertificateInfo(certificate));
entity.setRequestedKeyLength(-1);
entity.setFingerprint(fingerprint); entity.setFingerprint(fingerprint);
entity.setCert(Files.readAllBytes(certificate)); entity.setCert(Files.readAllBytes(certificate));
if (keyFile != null) { if (keyFile != null) {