use of de.carne.certmgr.certs.CertObjectStore in project certmgr by hdecarne.
the class CertExportController method onCmdExport.
@SuppressWarnings("unused")
@FXML
void onCmdExport(ActionEvent evt) {
try {
CertWriter exportFormat = validateAndGetFormat();
boolean encrypt = this.ctlEncryptOption.isSelected();
boolean exportCert = this.ctlExportCertOption.isSelected();
boolean exportChain = this.ctlExportChainOption.isSelected();
boolean exportChainRoot = this.ctlExportChainRootOption.isSelected();
boolean exportKey = this.ctlExportKeyOption.isSelected();
boolean exportCSR = this.ctlExportCSROption.isSelected();
boolean exportCRL = this.ctlExportCRLOption.isSelected();
if (this.ctlFileDestinationOption.isSelected()) {
Path exportFile = validateFileDestinationInput();
getExecutorService().submit(new ExportTask<Path>(exportCert, exportChain, exportChainRoot, exportKey, exportCSR, exportCRL, exportFormat, exportFile, encrypt) {
@Override
protected void export(CertWriter format, @Nullable Path param, CertObjectStore exportObjects, boolean encryptExport) throws IOException {
exportToFile(format, Check.notNull(param), exportObjects, encryptExport);
}
});
} else if (this.ctlDirectoryDestinationOption.isSelected()) {
Path exportDirectory = validateDirectoryDestinationInput();
getExecutorService().submit(new ExportTask<Path>(exportCert, exportChain, exportChainRoot, exportKey, exportCSR, exportCRL, exportFormat, exportDirectory, encrypt) {
@Override
protected void export(CertWriter format, @Nullable Path param, CertObjectStore exportObjects, boolean encryptExport) throws IOException {
exportToDirectory(format, Check.notNull(param), exportObjects, encryptExport);
}
});
} else if (this.ctlClipboardDestinationOption.isSelected()) {
getExecutorService().submit(new ExportTask<Void>(exportCert, exportChain, exportChainRoot, exportKey, exportCSR, exportCRL, exportFormat, null, encrypt) {
@Override
protected void export(CertWriter format, @Nullable Void param, CertObjectStore exportObjects, boolean encryptExport) throws IOException {
exportToClipboard(format, exportObjects, encryptExport);
}
});
}
} catch (ValidationException e) {
ValidationAlerts.error(e).showAndWait();
}
}
use of de.carne.certmgr.certs.CertObjectStore in project certmgr by hdecarne.
the class CertExportController method exportToDirectory.
void exportToDirectory(CertWriter format, Path directory, CertObjectStore exportObjects, boolean encryptExport) throws IOException {
for (CertObjectStore.Entry exportObject : exportObjects) {
String filePattern = exportObject.alias() + "-%d" + format.fileExtension(exportObject.getClass());
Path file = createUniqueFile(directory, filePattern);
try (IOResource<OutputStream> out = IOResource.newOutputStream(file.toString(), file, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
if (encryptExport) {
format.writeEncryptedBinary(out, CertObjectStore.wrap(exportObject), PasswordDialog.enterNewPassword(this));
} else {
format.writeBinary(out, CertObjectStore.wrap(exportObject));
}
}
}
}
Aggregations