FEAT: Preparation work for on-disk encryption and certificate stores #13

Merged
MarkL4YG merged 9 commits from feat/certEncryption into main 2024-11-22 08:48:02 +00:00
2 changed files with 31 additions and 7 deletions
Showing only changes of commit 22a2c0529e - Show all commits

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);
}
}
}