Search in sources :

Example 16 with CertObjectStore

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();
    }
}
Also used : Path(java.nio.file.Path) ValidationException(de.carne.jfx.util.validation.ValidationException) CertWriter(de.carne.certmgr.certs.spi.CertWriter) CertObjectStore(de.carne.certmgr.certs.CertObjectStore) IOException(java.io.IOException) Nullable(de.carne.check.Nullable) FXML(javafx.fxml.FXML)

Example 17 with CertObjectStore

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));
            }
        }
    }
}
Also used : Path(java.nio.file.Path) OutputStream(java.io.OutputStream) CertObjectStore(de.carne.certmgr.certs.CertObjectStore)

Aggregations

CertObjectStore (de.carne.certmgr.certs.CertObjectStore)17 Nullable (de.carne.check.Nullable)7 IOException (java.io.IOException)6 CertProviderException (de.carne.certmgr.certs.CertProviderException)5 InputStream (java.io.InputStream)4 Path (java.nio.file.Path)4 GeneralSecurityException (java.security.GeneralSecurityException)4 X509Certificate (java.security.cert.X509Certificate)4 PasswordRequiredException (de.carne.certmgr.certs.PasswordRequiredException)3 KeyPair (java.security.KeyPair)3 ArrayList (java.util.ArrayList)3 PKCS12PfxPdu (org.bouncycastle.pkcs.PKCS12PfxPdu)3 UserCertStoreEntry (de.carne.certmgr.certs.UserCertStoreEntry)2 PlatformKeyStore (de.carne.certmgr.certs.security.PlatformKeyStore)2 SignatureAlgorithm (de.carne.certmgr.certs.security.SignatureAlgorithm)2 CertReader (de.carne.certmgr.certs.spi.CertReader)2 CertWriter (de.carne.certmgr.certs.spi.CertWriter)2 PKCS10CertificateRequest (de.carne.certmgr.certs.x509.PKCS10CertificateRequest)2 OutputStream (java.io.OutputStream)2 KeyStore (java.security.KeyStore)2