feat: Allow certification results to be usages

This commit is contained in:
Magnus Leßmann (@MarkL4YG) 2024-11-19 23:07:53 +01:00
parent fc34320ffd
commit 1d6bf0facc
2 changed files with 31 additions and 7 deletions

View file

@ -90,7 +90,13 @@ public class OpenSSLCertificateCreator {
try (var certAuthority = certificateProvider.requestCertificateUsage(request.getTrustingAuthority())) {
Path unsignedCert = createSigningRequest(request, keyFile, tmpDir.resolve("child.csr"), certPassword);
Path signedCert = signCertificate(request, certAuthority.certificatePath(), certAuthority.certificateKeyPath(), unsignedCert, certPassword);
Path signedCert = signCertificate(
request,
certAuthority.certificatePath(),
certAuthority.certificateKeyPath(),
unsignedCert,
certPassword
);
String fingerprint = getCertificateFingerprint(signedCert);
passwordProvider.setPasswordFor(fingerprint, certPassword);
return new OpenSSLCertificateResult(tmpDir, signedCert, keyFile, fingerprint);

View file

@ -12,8 +12,7 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
@Getter
public class OpenSSLCertificateResult implements AutoCloseable {
public class OpenSSLCertificateResult implements CertificateUsage {
private final Path tmpDir;
private final Path certificatePath;
@ -21,9 +20,28 @@ public class OpenSSLCertificateResult implements AutoCloseable {
private final String certificateFingerPrint;
@Override
public void close() throws IOException {
log.info("Cleaning up temporary output directory {}", tmpDir);
Files.walkFileTree(tmpDir, Set.of(), Integer.MAX_VALUE, new DeleteRecursiveFileVisitor());
Files.deleteIfExists(tmpDir);
public Path certificatePath() {
return certificatePath;
}
@Override
public Path certificateKeyPath() {
return privateKeyPath;
}
@Override
public String fingerprint() {
return certificateFingerPrint;
}
@Override
public void close() {
try {
log.info("Cleaning up temporary output directory {}", tmpDir);
Files.walkFileTree(tmpDir, Set.of(), Integer.MAX_VALUE, new DeleteRecursiveFileVisitor());
Files.deleteIfExists(tmpDir);
} catch (IOException e) {
log.error("Failed to clean up temporary output directory {}!", tmpDir, e);
}
}
}