Search in sources :

Example 1 with X509ExtensionData

use of de.carne.certmgr.certs.x509.X509ExtensionData in project certmgr by hdecarne.

the class CertOptionsTemplates method storeTemplate.

private static void storeTemplate(Preferences templateNode, Template template) throws IOException {
    templateNode.put(Template.KEY_NAME, template.getName());
    templateNode.put(Template.KEY_ALIAS, template.aliasInput());
    templateNode.put(Template.KEY_DN, template.dnInput());
    KeyPairAlgorithm keyAlg = template.getKeyAlg();
    if (keyAlg != null) {
        templateNode.put(Template.KEY_KEYALG, keyAlg.algorithm());
    }
    Integer keySize = template.getKeySize();
    if (keySize != null) {
        templateNode.putInt(Template.KEY_KEYSIZE, keySize);
    }
    int extensionIndex = 0;
    for (X509ExtensionData extension : template.getExtensions()) {
        Preferences extensionNode = templateNode.node("extension" + extensionIndex);
        extensionNode.put(Template.KEY_EXTENSION_OID, extension.oid());
        extensionNode.putBoolean(Template.KEY_EXTENSION_CRITICAL, extension.getCritical());
        extensionNode.putByteArray(Template.KEY_EXTENSION_DATA, extension.getEncoded());
        extensionIndex++;
    }
}
Also used : X509ExtensionData(de.carne.certmgr.certs.x509.X509ExtensionData) KeyPairAlgorithm(de.carne.certmgr.certs.security.KeyPairAlgorithm) Preferences(java.util.prefs.Preferences) DistributionPoint(de.carne.certmgr.certs.x509.DistributionPoint)

Example 2 with X509ExtensionData

use of de.carne.certmgr.certs.x509.X509ExtensionData in project certmgr by hdecarne.

the class CertOptionsController method onCmdDeleteExtension.

@SuppressWarnings("unused")
@FXML
void onCmdDeleteExtension(ActionEvent evt) {
    ExtensionDataModel extensionDataItem = this.ctlExtensionData.getSelectionModel().getSelectedItem();
    if (extensionDataItem != null) {
        X509ExtensionData extensionData = extensionDataItem.getExtensionData();
        if (extensionData instanceof BasicConstraintsExtensionData) {
            this.basicConstraintsExtension.set(null);
        } else if (extensionData instanceof KeyUsageExtensionData) {
            this.keyUsageExtension.set(null);
        } else if (extensionData instanceof ExtendedKeyUsageExtensionData) {
            this.extendedKeyUsageExtension.set(null);
        } else if (extensionData instanceof SubjectAlternativeNameExtensionData) {
            this.subjectAlternativeExtension.set(null);
        } else if (extensionData instanceof CRLDistributionPointsExtensionData) {
            this.crlDistributionPointsExtension.set(null);
        }
        this.ctlExtensionData.getItems().remove(extensionDataItem);
    }
}
Also used : X509ExtensionData(de.carne.certmgr.certs.x509.X509ExtensionData) ExtendedKeyUsageExtensionData(de.carne.certmgr.certs.x509.ExtendedKeyUsageExtensionData) KeyUsageExtensionData(de.carne.certmgr.certs.x509.KeyUsageExtensionData) ExtendedKeyUsageExtensionData(de.carne.certmgr.certs.x509.ExtendedKeyUsageExtensionData) SubjectAlternativeNameExtensionData(de.carne.certmgr.certs.x509.SubjectAlternativeNameExtensionData) BasicConstraintsExtensionData(de.carne.certmgr.certs.x509.BasicConstraintsExtensionData) CRLDistributionPointsExtensionData(de.carne.certmgr.certs.x509.CRLDistributionPointsExtensionData) FXML(javafx.fxml.FXML)

Example 3 with X509ExtensionData

use of de.carne.certmgr.certs.x509.X509ExtensionData in project certmgr by hdecarne.

the class CertOptionsController method applyPreset.

private void applyPreset(CertOptionsPreset preset) {
    this.ctlAliasInput.setText(preset.aliasInput());
    this.ctlDNInput.setText(preset.dnInput());
    KeyPairAlgorithm keyAlg = preset.getKeyAlg();
    if (keyAlg != null) {
        this.ctlKeyAlgOption.setValue(preset.getKeyAlg());
    }
    Integer keySize = preset.getKeySize();
    if (keySize != null) {
        this.ctlKeySizeOption.setValue(preset.getKeySize());
    }
    this.basicConstraintsExtension.set(null);
    this.keyUsageExtension.set(null);
    this.extendedKeyUsageExtension.set(null);
    this.subjectAlternativeExtension.set(null);
    this.crlDistributionPointsExtension.set(null);
    this.ctlExtensionData.getItems().clear();
    for (X509ExtensionData extensionData : preset.getExtensions()) {
        if (extensionData instanceof BasicConstraintsExtensionData) {
            this.basicConstraintsExtension.set((BasicConstraintsExtensionData) extensionData);
        } else if (extensionData instanceof KeyUsageExtensionData) {
            this.keyUsageExtension.set((KeyUsageExtensionData) extensionData);
        } else if (extensionData instanceof ExtendedKeyUsageExtensionData) {
            this.extendedKeyUsageExtension.set((ExtendedKeyUsageExtensionData) extensionData);
        } else if (extensionData instanceof SubjectAlternativeNameExtensionData) {
            this.subjectAlternativeExtension.set((SubjectAlternativeNameExtensionData) extensionData);
        } else if (extensionData instanceof CRLDistributionPointsExtensionData) {
            this.crlDistributionPointsExtension.set((CRLDistributionPointsExtensionData) extensionData);
        }
        this.ctlExtensionData.getItems().add(new ExtensionDataModel(extensionData));
    }
}
Also used : X509ExtensionData(de.carne.certmgr.certs.x509.X509ExtensionData) KeyPairAlgorithm(de.carne.certmgr.certs.security.KeyPairAlgorithm) ExtendedKeyUsageExtensionData(de.carne.certmgr.certs.x509.ExtendedKeyUsageExtensionData) KeyUsageExtensionData(de.carne.certmgr.certs.x509.KeyUsageExtensionData) ExtendedKeyUsageExtensionData(de.carne.certmgr.certs.x509.ExtendedKeyUsageExtensionData) SubjectAlternativeNameExtensionData(de.carne.certmgr.certs.x509.SubjectAlternativeNameExtensionData) BasicConstraintsExtensionData(de.carne.certmgr.certs.x509.BasicConstraintsExtensionData) CRLDistributionPointsExtensionData(de.carne.certmgr.certs.x509.CRLDistributionPointsExtensionData)

Example 4 with X509ExtensionData

use of de.carne.certmgr.certs.x509.X509ExtensionData in project certmgr by hdecarne.

the class CertOptionsTemplates method wrap.

public static Template wrap(UserCertStoreEntry storeEntry) {
    String dnInput = X500Names.toString(storeEntry.dn());
    String aliasInput = dnInput;
    try {
        LdapName dn = new LdapName(aliasInput);
        for (Rdn rdn : dn.getRdns()) {
            if (DN_ALIAS_KEY.equals(rdn.getType())) {
                aliasInput = String.valueOf(rdn.getValue());
                break;
            }
        }
    } catch (InvalidNameException e) {
        Exceptions.ignore(e);
    }
    CertOptionsPreset preset = new CertOptionsPreset(aliasInput, dnInput);
    try {
        if (storeEntry.hasCRT()) {
            X509Certificate crt = storeEntry.getCRT();
            PublicKey publicKey = crt.getPublicKey();
            preset.setKeyAlg(KeyHelper.getKeyAlg(publicKey));
            preset.setKeySize(KeyHelper.getKeySize(publicKey));
            Set<String> criticalExtensionOIDs = crt.getCriticalExtensionOIDs();
            if (criticalExtensionOIDs != null) {
                for (String criticalExtensionOID : criticalExtensionOIDs) {
                    if (!INVALID_PRESET_EXTENSIONS.contains(criticalExtensionOID)) {
                        X509ExtensionData criticalExtension = X509ExtensionData.decode(criticalExtensionOID, true, crt.getExtensionValue(criticalExtensionOID));
                        preset.addExtension(criticalExtension);
                    }
                }
            }
            Set<String> nonCriticalExtensionOIDs = crt.getNonCriticalExtensionOIDs();
            if (nonCriticalExtensionOIDs != null) {
                for (String nonCriticalExtensionOID : nonCriticalExtensionOIDs) {
                    if (!INVALID_PRESET_EXTENSIONS.contains(nonCriticalExtensionOID)) {
                        X509ExtensionData nonCriticalExtension = X509ExtensionData.decode(nonCriticalExtensionOID, false, crt.getExtensionValue(nonCriticalExtensionOID));
                        preset.addExtension(nonCriticalExtension);
                    }
                }
            }
        }
    } catch (IOException e) {
        Exceptions.warn(e);
    }
    return new Template(preset.aliasInput(), preset);
}
Also used : X509ExtensionData(de.carne.certmgr.certs.x509.X509ExtensionData) InvalidNameException(javax.naming.InvalidNameException) PublicKey(java.security.PublicKey) IOException(java.io.IOException) Rdn(javax.naming.ldap.Rdn) X509Certificate(java.security.cert.X509Certificate) LdapName(javax.naming.ldap.LdapName)

Example 5 with X509ExtensionData

use of de.carne.certmgr.certs.x509.X509ExtensionData in project certmgr by hdecarne.

the class UserCertStoreTest method accessExtensionValues.

private void accessExtensionValues(X509Extension extension) throws IOException {
    Set<String> criticalExtensionOIDs = extension.getCriticalExtensionOIDs();
    if (criticalExtensionOIDs != null) {
        for (String criticalExtensionOID : extension.getCriticalExtensionOIDs()) {
            X509ExtensionData extensionData = X509ExtensionData.decode(criticalExtensionOID, true, extension.getExtensionValue(criticalExtensionOID));
            extensionData.toValueString();
        }
    }
    Set<String> nonCriticalExtensionOIDs = extension.getNonCriticalExtensionOIDs();
    if (nonCriticalExtensionOIDs != null) {
        for (String nonCriticalExtensionOID : nonCriticalExtensionOIDs) {
            X509ExtensionData extensionData = X509ExtensionData.decode(nonCriticalExtensionOID, true, extension.getExtensionValue(nonCriticalExtensionOID));
            extensionData.toValueString();
        }
    }
}
Also used : X509ExtensionData(de.carne.certmgr.certs.x509.X509ExtensionData)

Aggregations

X509ExtensionData (de.carne.certmgr.certs.x509.X509ExtensionData)5 KeyPairAlgorithm (de.carne.certmgr.certs.security.KeyPairAlgorithm)2 BasicConstraintsExtensionData (de.carne.certmgr.certs.x509.BasicConstraintsExtensionData)2 CRLDistributionPointsExtensionData (de.carne.certmgr.certs.x509.CRLDistributionPointsExtensionData)2 ExtendedKeyUsageExtensionData (de.carne.certmgr.certs.x509.ExtendedKeyUsageExtensionData)2 KeyUsageExtensionData (de.carne.certmgr.certs.x509.KeyUsageExtensionData)2 SubjectAlternativeNameExtensionData (de.carne.certmgr.certs.x509.SubjectAlternativeNameExtensionData)2 DistributionPoint (de.carne.certmgr.certs.x509.DistributionPoint)1 IOException (java.io.IOException)1 PublicKey (java.security.PublicKey)1 X509Certificate (java.security.cert.X509Certificate)1 Preferences (java.util.prefs.Preferences)1 FXML (javafx.fxml.FXML)1 InvalidNameException (javax.naming.InvalidNameException)1 LdapName (javax.naming.ldap.LdapName)1 Rdn (javax.naming.ldap.Rdn)1