Search in sources :

Example 11 with Nullable

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

the class DNEditorController method getRdnInput.

@Nullable
Rdn getRdnInput() {
    String typeInput = Strings.safeTrim(this.ctlTypeInput.getValue());
    String valueInput = Strings.safeTrim(this.ctlValueInput.getText());
    Rdn rdn = null;
    if (Strings.isEmpty(typeInput)) {
        Tooltips.show(this.ctlTypeInput, DNEditorI18N.formatSTR_MESSAGE_NO_TYPE(), Images.WARNING16);
    } else if (Strings.isEmpty(valueInput)) {
        Tooltips.show(this.ctlValueInput, DNEditorI18N.formatSTR_MESSAGE_NO_VALUE(), Images.WARNING16);
    } else {
        try {
            rdn = new Rdn(typeInput, valueInput);
        } catch (InvalidNameException e) {
            Tooltips.show(this.ctlValueInput, DNEditorI18N.formatSTR_MESSAGE_INVALID_RDN(e.getLocalizedMessage()), Images.WARNING16);
        }
    }
    return rdn;
}
Also used : InvalidNameException(javax.naming.InvalidNameException) Rdn(javax.naming.ldap.Rdn) Nullable(de.carne.check.Nullable)

Example 12 with Nullable

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

the class PasswordDialog method queryPasswordHelper.

@Nullable
private char[] queryPasswordHelper(Supplier<PasswordResult> query, boolean requery) {
    PasswordResult passwordResult;
    if (this.cancelAll) {
        passwordResult = PasswordResult.CANCEL;
    } else if (!requery && this.rememberedPassword != null) {
        passwordResult = new PasswordResult(ButtonType.YES, this.rememberedPassword, true);
    } else {
        passwordResult = PlatformHelper.runLater(query);
    }
    ButtonData dialogResultData = passwordResult.dialogResult().getButtonData();
    if (dialogResultData == ButtonData.YES) {
        this.cancelAll = false;
        this.rememberedPassword = (passwordResult.rememberPassword() ? passwordResult.password() : null);
    } else if (dialogResultData == ButtonData.NO) {
        this.cancelAll = false;
        this.rememberedPassword = null;
    } else {
        this.cancelAll = true;
        this.rememberedPassword = null;
    }
    return passwordResult.password();
}
Also used : ButtonData(javafx.scene.control.ButtonBar.ButtonData) Nullable(de.carne.check.Nullable)

Example 13 with Nullable

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

the class CertOptionsTemplates method load.

public static List<Template> load() {
    List<Template> templates = new ArrayList<>();
    try {
        Preferences templateStore;
        if (TEMPLATE_STORE_INITIALIZED.getBoolean(false)) {
            templateStore = TEMPLATE_STORE;
        } else {
            try (InputStream standardTemplatesStream = getStandardTemplatesUrl().openStream()) {
                Properties standardTemplates = new Properties();
                standardTemplates.load(standardTemplatesStream);
                templateStore = FilePreferencesFactory.customRoot(standardTemplates);
            }
        }
        String[] templateNodeNames = templateStore.childrenNames();
        Arrays.sort(templateNodeNames);
        for (String templateNodeName : templateNodeNames) {
            Preferences templateNode = templateStore.node(templateNodeName);
            @Nullable Template template = loadTemplate(templateNode);
            if (template != null) {
                templates.add(template);
            }
        }
    } catch (IOException | BackingStoreException e) {
        Exceptions.warn(e);
    }
    return templates;
}
Also used : InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) BackingStoreException(java.util.prefs.BackingStoreException) IOException(java.io.IOException) Preferences(java.util.prefs.Preferences) Properties(java.util.Properties) Nullable(de.carne.check.Nullable)

Example 14 with Nullable

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

the class CertOptionsTemplates method loadTemplate.

@Nullable
private static Template loadTemplate(Preferences templateNode) {
    @Nullable Template template = null;
    @Nullable String name = templateNode.get(Template.KEY_NAME, null);
    @Nullable String aliasInput = templateNode.get(Template.KEY_ALIAS, null);
    @Nullable String dnInput = templateNode.get(Template.KEY_DN, null);
    if (Strings.notEmpty(name) && Strings.notEmpty(aliasInput) && Strings.notEmpty(dnInput)) {
        assert name != null;
        assert aliasInput != null;
        assert dnInput != null;
        template = new Template(name, new CertOptionsPreset(aliasInput, dnInput));
        @Nullable String keyAlg = templateNode.get(Template.KEY_KEYALG, null);
        if (keyAlg != null) {
            template.setKeyAlg(KeyHelper.getKeyAlg(keyAlg));
        }
        int keySize = templateNode.getInt(Template.KEY_KEYSIZE, 0);
        if (keySize != 0) {
            template.setKeySize(keySize);
        }
        try {
            String[] extensionNodeNames = templateNode.childrenNames();
            for (String extensionNodeName : extensionNodeNames) {
                Preferences extensionNode = templateNode.node(extensionNodeName);
                @Nullable String oid = extensionNode.get(Template.KEY_EXTENSION_OID, null);
                boolean criticial = extensionNode.getBoolean(Template.KEY_EXTENSION_CRITICAL, false);
                @Nullable byte[] data = extensionNode.getByteArray(Template.KEY_EXTENSION_DATA, null);
                if (Strings.notEmpty(oid) && data != null) {
                    assert oid != null;
                    template.addExtension(X509ExtensionData.decode(oid, criticial, data));
                } else {
                    LOG.warning("Ignoring incomplete extension node ''{0}''", extensionNode.absolutePath());
                }
            }
        } catch (BackingStoreException | IOException e) {
            LOG.warning(e, "Ignoring inaccessible extension data for template node ''{0}''", templateNode.absolutePath());
        }
    } else {
        LOG.warning("Ignoring incomplete template node ''{0}''", templateNode.absolutePath());
    }
    return template;
}
Also used : BackingStoreException(java.util.prefs.BackingStoreException) IOException(java.io.IOException) Preferences(java.util.prefs.Preferences) Nullable(de.carne.check.Nullable) DistributionPoint(de.carne.certmgr.certs.x509.DistributionPoint) Nullable(de.carne.check.Nullable)

Example 15 with Nullable

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

the class CRLOptionsController method validateAndGetNextUpdate.

@Nullable
private Date validateAndGetNextUpdate(Date lastUpdate) throws ValidationException {
    LocalDate localNextUpdate = this.ctlNextUpdateInput.getValue();
    Date nextUpdate = (localNextUpdate != null ? Date.from(localNextUpdate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant()) : null);
    if (nextUpdate != null) {
        InputValidator.isTrue(nextUpdate.compareTo(lastUpdate) > 0, (a) -> CRLOptionsI18N.formatSTR_MESSAGE_INVALID_UPDATEDATES(lastUpdate, nextUpdate));
    }
    return nextUpdate;
}
Also used : LocalDate(java.time.LocalDate) Date(java.util.Date) LocalDate(java.time.LocalDate) Nullable(de.carne.check.Nullable)

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