Search in sources :

Example 1 with UserCertStoreEntry

use of de.carne.certmgr.certs.UserCertStoreEntry in project certmgr by hdecarne.

the class CertExportController method getExportObjectList.

CertObjectStore getExportObjectList(boolean exportCert, boolean exportChain, boolean exportChainRoot, boolean exportKey, boolean exportCSR, boolean exportCRL) throws IOException {
    CertObjectStore exportObjects = new CertObjectStore();
    UserCertStoreEntry exportEntry = this.exportEntryParam.get();
    String exportEntryAlias = exportEntry.id().getAlias();
    if (exportKey) {
        exportObjects.addKey(exportEntryAlias, exportEntry.getKey(PasswordDialog.enterPassword(this)));
    }
    if (exportCert) {
        exportObjects.addCRT(exportEntryAlias, exportEntry.getCRT());
        if (exportChain && !exportEntry.isSelfSigned()) {
            UserCertStoreEntry issuer = exportEntry.issuer();
            while (!issuer.isSelfSigned()) {
                if (issuer.hasCRT()) {
                    exportObjects.addCRT(issuer.id().getAlias(), issuer.getCRT());
                }
                issuer = issuer.issuer();
            }
            if (exportChainRoot && issuer.hasCRT()) {
                exportObjects.addCRT(issuer.id().getAlias(), issuer.getCRT());
            }
        }
    }
    if (exportCSR) {
        exportObjects.addCSR(exportEntryAlias, exportEntry.getCSR());
    }
    if (exportCRL) {
        exportObjects.addCRL(exportEntryAlias, exportEntry.getCRL());
    }
    return exportObjects;
}
Also used : CertObjectStore(de.carne.certmgr.certs.CertObjectStore) UserCertStoreEntry(de.carne.certmgr.certs.UserCertStoreEntry)

Example 2 with UserCertStoreEntry

use of de.carne.certmgr.certs.UserCertStoreEntry in project certmgr by hdecarne.

the class CertImportController method validateImportSelection.

private Set<UserCertStoreEntry> validateImportSelection() throws ValidationException {
    Set<UserCertStoreEntry> importSelection = new HashSet<>();
    forAllImportEntries(this.ctlImportEntryView.getRoot(), (i) -> {
        ImportEntryModel importEntry = i.getValue();
        if (importEntry != null && importEntry.getSelected().booleanValue()) {
            UserCertStoreEntry selectedEntry = importEntry.getEntry();
            if (!selectedEntry.isExternal()) {
                importSelection.add(selectedEntry);
            }
        }
    });
    InputValidator.isTrue(!importSelection.isEmpty(), CertImportI18N::formatSTR_MESSAGE_EMPTY_IMPORT_SELECTION);
    return importSelection;
}
Also used : UserCertStoreEntry(de.carne.certmgr.certs.UserCertStoreEntry) HashSet(java.util.HashSet)

Example 3 with UserCertStoreEntry

use of de.carne.certmgr.certs.UserCertStoreEntry in project certmgr by hdecarne.

the class LocalCertGenerator method generateCert.

@Override
public CertObjectStore generateCert(GenerateCertRequest request, PasswordCallback password) throws IOException {
    KeyPair key = KeyHelper.generateKey(request.keyPairAlgorithm(), request.keySize());
    Issuer issuer = requiredParameter(request.getIssuer(), "Issuer");
    BigInteger serial = BigInteger.ONE;
    X500Principal issuerDN = null;
    KeyPair issuerKey = null;
    X500Principal dn = request.dn();
    if (!this.selfSignedIssuer.equals(issuer)) {
        UserCertStoreEntry issuerEntry = Check.notNull(issuer.storeEntry());
        serial = getNextSerial(issuerEntry);
        issuerDN = issuerEntry.dn();
        issuerKey = issuerEntry.getKey(password);
    } else {
        issuerKey = key;
        issuerDN = dn;
    }
    Date notBefore = requiredParameter(request.getNotBefore(), "NotBefore");
    Date notAfter = requiredParameter(request.getNotAfter(), "NotAfter");
    SignatureAlgorithm signatureAlgorithm = requiredParameter(request.getSignatureAlgorithm(), "SignatureAlgorithm");
    X509Certificate crt = X509CertificateHelper.generateCRT(dn, key, serial, notBefore, notAfter, request.getExtensions(), issuerDN, issuerKey, signatureAlgorithm);
    CertObjectStore certObjects = new CertObjectStore();
    certObjects.addKey(key);
    certObjects.addCRT(crt);
    return certObjects;
}
Also used : KeyPair(java.security.KeyPair) BigInteger(java.math.BigInteger) X500Principal(javax.security.auth.x500.X500Principal) SignatureAlgorithm(de.carne.certmgr.certs.security.SignatureAlgorithm) CertObjectStore(de.carne.certmgr.certs.CertObjectStore) Date(java.util.Date) X509Certificate(java.security.cert.X509Certificate) UserCertStoreEntry(de.carne.certmgr.certs.UserCertStoreEntry)

Example 4 with UserCertStoreEntry

use of de.carne.certmgr.certs.UserCertStoreEntry in project certmgr by hdecarne.

the class LocalCertGenerator method getIssuers.

@Override
public DefaultSet<Issuer> getIssuers(UserCertStore store, @Nullable UserCertStoreEntry defaultHint) {
    DefaultSet<Issuer> issuers = new DefaultSet<>();
    issuers.addDefault(this.selfSignedIssuer);
    if (store != null) {
        for (UserCertStoreEntry storeEntry : store.getEntries()) {
            if (storeEntry.canIssue()) {
                if (storeEntry.equals(defaultHint)) {
                    issuers.addDefault(new LocalIssuer(storeEntry));
                } else {
                    issuers.add(new LocalIssuer(storeEntry));
                }
            }
        }
    }
    return issuers;
}
Also used : DefaultSet(de.carne.jfx.util.DefaultSet) UserCertStoreEntry(de.carne.certmgr.certs.UserCertStoreEntry)

Example 5 with UserCertStoreEntry

use of de.carne.certmgr.certs.UserCertStoreEntry in project certmgr by hdecarne.

the class StoreController method onCmdCopyEntry.

@SuppressWarnings("unused")
@FXML
void onCmdCopyEntry(ActionEvent evt) {
    UserCertStoreEntry entry = getSelectedStoreEntry();
    if (entry != null) {
        List<Path> entryFilePaths = entry.getFilePaths();
        if (!entryFilePaths.isEmpty()) {
            List<File> entryFiles = entryFilePaths.stream().map((p) -> p.toFile()).collect(Collectors.toList());
            Clipboard clipboard = Clipboard.getSystemClipboard();
            ClipboardContent content = new ClipboardContent();
            content.putFiles(entryFiles);
            clipboard.setContent(content);
        }
    }
}
Also used : Path(java.nio.file.Path) X509Certificate(java.security.cert.X509Certificate) Button(javafx.scene.control.Button) Exceptions(de.carne.util.Exceptions) ScheduledFuture(java.util.concurrent.ScheduledFuture) PreferencesDialog(de.carne.certmgr.jfx.preferences.PreferencesDialog) Date(java.util.Date) Alerts(de.carne.jfx.scene.control.Alerts) CheckMenuItem(javafx.scene.control.CheckMenuItem) X509CRL(java.security.cert.X509CRL) PKCS10CertificateRequest(de.carne.certmgr.certs.x509.PKCS10CertificateRequest) UserCertStoreTreeTableViewHelper(de.carne.certmgr.jfx.util.UserCertStoreTreeTableViewHelper) CertOptionsController(de.carne.certmgr.jfx.certoptions.CertOptionsController) AboutInfoController(de.carne.jfx.scene.control.aboutinfo.AboutInfoController) AlertType(javafx.scene.control.Alert.AlertType) ContextMenu(javafx.scene.control.ContextMenu) UserCertStoreEntry(de.carne.certmgr.certs.UserCertStoreEntry) TreeTableCell(javafx.scene.control.TreeTableCell) BigInteger(java.math.BigInteger) CertImportController(de.carne.certmgr.jfx.certimport.CertImportController) Lazy(de.carne.util.Lazy) X509CRLHelper(de.carne.certmgr.certs.x509.X509CRLHelper) Path(java.nio.file.Path) PrintWriter(java.io.PrintWriter) PathPreference(de.carne.certmgr.util.PathPreference) StageController(de.carne.jfx.stage.StageController) MenuItem(javafx.scene.control.MenuItem) AboutInfoDialog(de.carne.jfx.scene.control.aboutinfo.AboutInfoDialog) Collectors(java.util.stream.Collectors) Attributes(de.carne.certmgr.certs.x509.Attributes) PreferencesController(de.carne.certmgr.jfx.preferences.PreferencesController) Images(de.carne.certmgr.jfx.resources.Images) FXML(javafx.fxml.FXML) Windows(de.carne.jfx.stage.Windows) List(java.util.List) Clipboard(javafx.scene.input.Clipboard) Optional(java.util.Optional) ClipboardContent(javafx.scene.input.ClipboardContent) Debug(de.carne.util.Debug) ButtonData(javafx.scene.control.ButtonBar.ButtonData) Nullable(de.carne.check.Nullable) ButtonType(javafx.scene.control.ButtonType) TreeItem(javafx.scene.control.TreeItem) MouseEvent(javafx.scene.input.MouseEvent) NumberFormat(java.text.NumberFormat) TreeTableRow(javafx.scene.control.TreeTableRow) TreeTableView(javafx.scene.control.TreeTableView) ReasonFlag(de.carne.certmgr.certs.x509.ReasonFlag) CRLOptionsController(de.carne.certmgr.jfx.crloptions.CRLOptionsController) UserCertStore(de.carne.certmgr.certs.UserCertStore) Tooltip(javafx.scene.control.Tooltip) PlatformHelper(de.carne.jfx.application.PlatformHelper) DirectoryChooser(javafx.stage.DirectoryChooser) X509CertificateHelper(de.carne.certmgr.certs.x509.X509CertificateHelper) ObjectProperty(javafx.beans.property.ObjectProperty) CertExportController(de.carne.certmgr.jfx.certexport.CertExportController) Label(javafx.scene.control.Label) StringWriter(java.io.StringWriter) IOException(java.io.IOException) File(java.io.File) Preferences(java.util.prefs.Preferences) StorePreferencesController(de.carne.certmgr.jfx.storepreferences.StorePreferencesController) TimeUnit(java.util.concurrent.TimeUnit) TreeTableColumn(javafx.scene.control.TreeTableColumn) ActionEvent(javafx.event.ActionEvent) TreeItemPropertyValueFactory(javafx.scene.control.cell.TreeItemPropertyValueFactory) StorePreferencesDialog(de.carne.certmgr.jfx.storepreferences.StorePreferencesDialog) LogViewController(de.carne.jfx.stage.logview.LogViewController) Stage(javafx.stage.Stage) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) ClipboardContent(javafx.scene.input.ClipboardContent) Clipboard(javafx.scene.input.Clipboard) File(java.io.File) UserCertStoreEntry(de.carne.certmgr.certs.UserCertStoreEntry) FXML(javafx.fxml.FXML)

Aggregations

UserCertStoreEntry (de.carne.certmgr.certs.UserCertStoreEntry)19 IOException (java.io.IOException)10 FXML (javafx.fxml.FXML)6 UserCertStore (de.carne.certmgr.certs.UserCertStore)4 BigInteger (java.math.BigInteger)4 Date (java.util.Date)4 CRLOptionsController (de.carne.certmgr.jfx.crloptions.CRLOptionsController)3 X509CRL (java.security.cert.X509CRL)3 X509Certificate (java.security.cert.X509Certificate)3 CertObjectStore (de.carne.certmgr.certs.CertObjectStore)2 SignatureAlgorithm (de.carne.certmgr.certs.security.SignatureAlgorithm)2 PKCS10CertificateRequest (de.carne.certmgr.certs.x509.PKCS10CertificateRequest)2 ReasonFlag (de.carne.certmgr.certs.x509.ReasonFlag)2 CertExportController (de.carne.certmgr.jfx.certexport.CertExportController)2 Path (java.nio.file.Path)2 ButtonType (javafx.scene.control.ButtonType)2 Test (org.junit.Test)2 PasswordCallback (de.carne.certmgr.certs.PasswordCallback)1 UserCertStoreEntryId (de.carne.certmgr.certs.UserCertStoreEntryId)1 UserCertStorePreferences (de.carne.certmgr.certs.UserCertStorePreferences)1