chore: Fixup test failures introduced by cert import

This commit is contained in:
Magnus Leßmann (@MarkL4YG) 2025-04-20 17:13:07 +02:00
parent 4b863fec42
commit f8e9158a76
Signed by: Mark.TwoFive
GPG key ID: E906A79D91006ECD
3 changed files with 24 additions and 8 deletions

View file

@ -29,7 +29,14 @@ public class Certificate {
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 OffsetDateTime notBefore;

View file

@ -32,4 +32,8 @@ public record X509CertificateInfo(
}
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());
if (info.issuer() != null) {
certificate.setTrustingAuthority(info.issuer().getCommonName());
}
certificate.setRequestedKeyLength(-1);
certificate.setNotBefore(info.notBefore());
certificate.setNotAfter(info.notAfter());
@ -100,6 +102,7 @@ public class CertificateCreationService {
certificate.setSubjectState(subjectInfo.getState());
certificate.setSubjectLocality(subjectInfo.getLocality());
if (info.hasExtensions()) {
final CertificateInfoExtension extension = info.extensions().getFirst();
if (extension != null) {
final CertificateExtension certificateExtension = new CertificateExtension();
@ -107,6 +110,7 @@ public class CertificateCreationService {
certificateExtension.setValue(String.join(",", extension.getAlternativeDnsNames()));
certificate.setCertificateExtension(List.of(certificateExtension));
}
}
return certificate;
}
@ -119,6 +123,7 @@ public class CertificateCreationService {
try {
String fingerprint = openSSLService.getCertificateFingerprint(certificate);
Certificate entity = createEntityFromInfo(openSSLService.getCertificateInfo(certificate));
entity.setRequestedKeyLength(-1);
entity.setFingerprint(fingerprint);
entity.setCert(Files.readAllBytes(certificate));
if (keyFile != null) {