Search in sources :

Example 6 with Nullable

use of de.carne.check.Nullable in project certmgr by hdecarne.

the class UserCertStore method matchPKCS10CertificateRequest.

@Nullable
private Entry matchPKCS10CertificateRequest(PKCS10CertificateRequest csr) throws IOException {
    X500Principal csrDN = csr.getSubjectX500Principal();
    PublicKey csrPublicKey = csr.getPublicKey();
    Entry matchingEntry = null;
    for (Entry entry : this.storeEntries.values()) {
        if (csrDN.equals(entry.dn()) && entry.hasPublicKey() && Arrays.equals(csrPublicKey.getEncoded(), entry.getPublicKey().getEncoded())) {
            matchingEntry = entry;
            break;
        }
        if (entry.hasCRL() && X509CRLHelper.isCRLSignedBy(entry.getCRL(), csrPublicKey)) {
            matchingEntry = entry;
            break;
        }
    }
    return matchingEntry;
}
Also used : PublicKey(java.security.PublicKey) X500Principal(javax.security.auth.x500.X500Principal) Nullable(de.carne.check.Nullable)

Example 7 with Nullable

use of de.carne.check.Nullable in project certmgr by hdecarne.

the class KeyPairAlgorithm method getDefaultSet.

/**
 * Get the available key pair algorithms.
 *
 * @param defaultHint The default to return (may be {@code null}). If this algorithm is contained in the default
 *        set, it is also set as the default.
 * @param expertMode Whether only standard algorithms are considered ({@code false}) or all algorithms available on
 *        the current platform ({@code true}).
 * @return The available key pair algorithms
 */
public static DefaultSet<KeyPairAlgorithm> getDefaultSet(@Nullable String defaultHint, boolean expertMode) {
    DefaultSet<KeyPairAlgorithm> keyPairAlgorithms = new DefaultSet<>();
    DefaultSet<String> defaultNames = SecurityDefaults.getKeyAlgorithmNames();
    @Nullable String defaultName = (defaultHint != null && defaultNames.contains(defaultHint) ? defaultHint : defaultNames.getDefault());
    for (Provider provider : SecurityDefaults.getProviders(expertMode)) {
        for (Provider.Service service : provider.getServices()) {
            if (!SERVICE_TYPE_KEY_PAIR_GENERATOR.equals(service.getType())) {
                continue;
            }
            String algorithm = service.getAlgorithm();
            if (!expertMode && !defaultNames.contains(algorithm)) {
                continue;
            }
            KeyPairAlgorithm keyPairAlgorithm = (expertMode ? new ExpertKeyPairAlgorithm(service) : new StandardKeyPairAlgorithm(service));
            if (algorithm.equals(defaultName)) {
                keyPairAlgorithms.addDefault(keyPairAlgorithm);
            } else {
                keyPairAlgorithms.add(keyPairAlgorithm);
            }
        }
    }
    return keyPairAlgorithms;
}
Also used : DefaultSet(de.carne.jfx.util.DefaultSet) Service(java.security.Provider.Service) Nullable(de.carne.check.Nullable) Provider(java.security.Provider)

Example 8 with Nullable

use of de.carne.check.Nullable in project certmgr by hdecarne.

the class CertMgrApplication method evalCmdLine.

@Nullable
private File evalCmdLine() {
    CmdLineProcessor cmdLine = new CmdLineProcessor("certmgr", getParameters().getRaw());
    List<String> defaultArgs = new ArrayList<>();
    cmdLine.onSwitch((s) -> applyLogConfig(Logs.CONFIG_VERBOSE)).arg("--verbose");
    cmdLine.onSwitch((s) -> applyLogConfig(Logs.CONFIG_DEBUG)).arg("--debug");
    cmdLine.onUnnamedOption((s) -> defaultArgs.add(s));
    try {
        cmdLine.process();
        LOG.info("Running command line ''{0}''", cmdLine);
    } catch (CmdLineException e) {
        LOG.warning(e, "Invalid command line ''{0}''; ", cmdLine);
    }
    File defaultStoreHome = null;
    for (String defaultArg : defaultArgs) {
        if (defaultStoreHome == null) {
            defaultStoreHome = new File(defaultArg);
        } else {
            LOG.warning("Ignoring extra store home argument ''{0}''", defaultStoreHome);
        }
    }
    return defaultStoreHome;
}
Also used : Nullable(de.carne.check.Nullable) CmdLineException(de.carne.util.cmdline.CmdLineException) StageController(de.carne.jfx.stage.StageController) Check(de.carne.check.Check) IOException(java.io.IOException) CmdLineProcessor(de.carne.util.cmdline.CmdLineProcessor) Logs(de.carne.boot.logging.Logs) ShutdownHooks(de.carne.util.ShutdownHooks) File(java.io.File) ArrayList(java.util.ArrayList) Images(de.carne.certmgr.jfx.resources.Images) Application(javafx.application.Application) StoreController(de.carne.certmgr.jfx.store.StoreController) List(java.util.List) Stage(javafx.stage.Stage) LogViewImages(de.carne.jfx.stage.logview.LogViewImages) Log(de.carne.boot.logging.Log) LogLevel(de.carne.boot.logging.LogLevel) ArrayList(java.util.ArrayList) CmdLineProcessor(de.carne.util.cmdline.CmdLineProcessor) File(java.io.File) CmdLineException(de.carne.util.cmdline.CmdLineException) Nullable(de.carne.check.Nullable)

Example 9 with Nullable

use of de.carne.check.Nullable in project certmgr by hdecarne.

the class PreferencesController method call.

@Override
@Nullable
public UserPreferences call(@Nullable ButtonType param) {
    UserPreferences dialogResult = null;
    if (param != null && ButtonType.APPLY.getButtonData() == param.getButtonData()) {
        this.preferencesParam.get().expertMode.put(this.ctlExpertModeOption.isSelected());
        try {
            this.preferencesParam.get().sync();
            dialogResult = this.preferencesParam.get();
        } catch (BackingStoreException e) {
            Alerts.unexpected(e).showAndWait();
        }
    }
    return dialogResult;
}
Also used : UserPreferences(de.carne.certmgr.jfx.store.UserPreferences) BackingStoreException(java.util.prefs.BackingStoreException) Nullable(de.carne.check.Nullable)

Example 10 with Nullable

use of de.carne.check.Nullable in project certmgr by hdecarne.

the class StoreController method setupStage.

@Override
protected void setupStage(Stage stage) {
    stage.getIcons().addAll(Images.STORE32, Images.STORE16);
    stage.setTitle(StoreI18N.formatSTR_STAGE_TITLE());
    this.cmdStorePreferences.disableProperty().bind(this.storeProperty.isNull());
    this.cmdCopyEntry.disableProperty().bind(this.ctlStoreEntryView.getSelectionModel().selectedItemProperty().isNull());
    this.cmdDeleteEntry.disableProperty().bind(this.ctlStoreEntryView.getSelectionModel().selectedItemProperty().isNull());
    this.cmdNewCert.disableProperty().bind(this.storeProperty.isNull());
    this.cmdRevokeCert.disableProperty().bind(this.ctlStoreEntryView.getSelectionModel().selectedItemProperty().isNull());
    this.cmdManageCRL.disableProperty().bind(this.ctlStoreEntryView.getSelectionModel().selectedItemProperty().isNull());
    this.cmdExportCert.disableProperty().bind(this.ctlStoreEntryView.getSelectionModel().selectedItemProperty().isNull());
    this.cmdImportCerts.disableProperty().bind(this.storeProperty.isNull());
    this.cmdStorePreferencesButton.disableProperty().bind(this.storeProperty.isNull());
    this.cmdCopyEntryButton.disableProperty().bind(this.cmdCopyEntry.disableProperty());
    this.cmdDeleteEntryButton.disableProperty().bind(this.cmdDeleteEntry.disableProperty());
    this.cmdNewCertButton.disableProperty().bind(this.cmdNewCert.disableProperty());
    this.cmdRevokeCertButton.disableProperty().bind(this.cmdRevokeCert.disableProperty());
    this.cmdManageCRLButton.disableProperty().bind(this.cmdManageCRL.disableProperty());
    this.cmdExportCertButton.disableProperty().bind(this.cmdExportCert.disableProperty());
    this.cmdImportCertsButton.disableProperty().bind(this.cmdImportCerts.disableProperty());
    ContextMenu storeEntryViewMenu = this.ctlStoreEntryView.getContextMenu();
    this.ctlStoreEntryView.setContextMenu(null);
    this.ctlStoreEntryView.setRowFactory(param -> {
        ContextMenu menu = storeEntryViewMenu;
        return new TreeTableRow<StoreEntryModel>() {

            @Override
            protected void updateItem(@Nullable StoreEntryModel item, boolean empty) {
                super.updateItem(item, empty);
                if (!empty) {
                    setContextMenu(menu);
                } else {
                    setContextMenu(null);
                }
            }
        };
    });
    Tooltip storeEntryViewTooltip = this.ctlStoreEntryView.getTooltip();
    this.ctlStoreEntryTooltipExternalCrt.managedProperty().bind(this.ctlStoreEntryTooltipExternalCrt.visibleProperty());
    this.ctlStoreEntryTooltipPublicCrt.managedProperty().bind(this.ctlStoreEntryTooltipPublicCrt.visibleProperty());
    this.ctlStoreEntryTooltipPrivateCrt.managedProperty().bind(this.ctlStoreEntryTooltipPrivateCrt.visibleProperty());
    this.ctlStoreEntryTooltipCsr.managedProperty().bind(this.ctlStoreEntryTooltipCsr.visibleProperty());
    this.ctlStoreEntryTooltipCrl.managedProperty().bind(this.ctlStoreEntryTooltipCrl.visibleProperty());
    this.ctlStoreEntryTooltipKey.managedProperty().bind(this.ctlStoreEntryTooltipKey.visibleProperty());
    this.ctlStoreEntryTooltipRevokedCrt.managedProperty().bind(this.ctlStoreEntryTooltipRevokedCrt.visibleProperty());
    this.ctlStoreEntryTooltipInvalidCrt.managedProperty().bind(this.ctlStoreEntryTooltipInvalidCrt.visibleProperty());
    this.ctlStoreEntryView.setTooltip(null);
    this.ctlStoreEntryViewId.setCellFactory(param -> {
        return new TreeTableCell<StoreEntryModel, String>() {

            Tooltip tooltip = storeEntryViewTooltip;

            @Override
            protected void updateItem(@Nullable String item, boolean empty) {
                if (!empty) {
                    setTooltip(this.tooltip);
                    setOnMouseEntered(StoreController.this::onStoreViewItemMouseEntered);
                    setText(item);
                } else {
                    setTooltip(null);
                    setOnMouseEntered(null);
                    setText(null);
                }
            }
        };
    });
    this.ctlStoreEntryViewId.setCellValueFactory(new TreeItemPropertyValueFactory<>("id"));
    this.ctlStoreEntryViewName.setCellValueFactory(new TreeItemPropertyValueFactory<>("name"));
    this.ctlStoreEntryViewSerial.setCellValueFactory(new TreeItemPropertyValueFactory<>("serial"));
    this.ctlStoreEntryViewExpires.setCellValueFactory(new TreeItemPropertyValueFactory<>("expires"));
    ContextMenu detailsViewMenu = this.ctlDetailsView.getContextMenu();
    this.ctlDetailsView.setContextMenu(null);
    this.ctlDetailsView.setRowFactory(param -> {
        ContextMenu menu = detailsViewMenu;
        return new TreeTableRow<AttributeModel>() {

            @Override
            protected void updateItem(@Nullable AttributeModel item, boolean empty) {
                super.updateItem(item, empty);
                if (!empty) {
                    setContextMenu(menu);
                } else {
                    setContextMenu(null);
                }
            }
        };
    });
    this.ctlDetailsViewName.setCellValueFactory(new TreeItemPropertyValueFactory<>("name"));
    this.ctlDetailsViewValue.setCellValueFactory(new TreeItemPropertyValueFactory<>("value"));
    this.ctlStoreEntryView.getSelectionModel().selectedItemProperty().addListener((p, o, n) -> onStoreViewSelectionChanged(n));
    Windows.onHiding(stage, (ScheduledFuture<?> f) -> f.cancel(true), getExecutorService().scheduleAtFixedRate(PlatformHelper.runLaterRunnable(() -> onUpdateHeapStatus()), 0, 500, TimeUnit.MILLISECONDS));
}
Also used : TreeTableCell(javafx.scene.control.TreeTableCell) Tooltip(javafx.scene.control.Tooltip) ContextMenu(javafx.scene.control.ContextMenu) TreeTableRow(javafx.scene.control.TreeTableRow) Nullable(de.carne.check.Nullable) ScheduledFuture(java.util.concurrent.ScheduledFuture)

Aggregations

Nullable (de.carne.check.Nullable)24 IOException (java.io.IOException)9 CertObjectStore (de.carne.certmgr.certs.CertObjectStore)7 PrivateKey (java.security.PrivateKey)4 CertProviderException (de.carne.certmgr.certs.CertProviderException)3 InputStream (java.io.InputStream)3 Path (java.nio.file.Path)3 PublicKey (java.security.PublicKey)3 BackingStoreException (java.util.prefs.BackingStoreException)3 X500Principal (javax.security.auth.x500.X500Principal)3 PasswordRequiredException (de.carne.certmgr.certs.PasswordRequiredException)2 CertReader (de.carne.certmgr.certs.spi.CertReader)2 DefaultSet (de.carne.jfx.util.DefaultSet)2 GeneralSecurityException (java.security.GeneralSecurityException)2 Key (java.security.Key)2 KeyPair (java.security.KeyPair)2 Provider (java.security.Provider)2 Service (java.security.Provider.Service)2 X509Certificate (java.security.cert.X509Certificate)2 ArrayDeque (java.util.ArrayDeque)2