Skip to content

Commit

Permalink
0005452: Backup keystore before saving it
Browse files Browse the repository at this point in the history
  • Loading branch information
erilong committed Sep 9, 2022
1 parent 2754b56 commit c221b09
Showing 1 changed file with 6 additions and 0 deletions.
Expand Up @@ -47,6 +47,7 @@
import javax.net.ssl.KeyManagerFactory;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.NotImplementedException;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
Expand Down Expand Up @@ -455,6 +456,11 @@ public void saveTrustStore(KeyStore ks) throws Exception {
protected void saveKeyStore(KeyStore ks, String password) throws Exception {
if (keyStoreFileName != null) {
log.info("Saving keystore {}", keyStoreFileName);
try {
FileUtils.copyFile(new File(keyStoreFileName), new File(keyStoreFileName + ".bak"));
} catch (IOException e) {
log.warn("Unable to backup keystore: ", e.getMessage());
}
try (FileOutputStream os = new FileOutputStream(keyStoreFileName)) {
ks.store(os, password.toCharArray());
}
Expand Down

0 comments on commit c221b09

Please sign in to comment.