Search in sources :

Example 1 with PKCS10CertificateRequest

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

the class RemoteCertGenerator method generateCert.

@Override
public CertObjectStore generateCert(GenerateCertRequest request, PasswordCallback password) throws IOException {
    KeyPair key = KeyHelper.generateKey(request.keyPairAlgorithm(), request.keySize());
    SignatureAlgorithm signatureAlgorithm = requiredParameter(request.getSignatureAlgorithm(), "SignatureAlgorithm");
    PKCS10CertificateRequest csr = PKCS10CertificateRequest.generateCSR(request.dn(), key, request.getExtensions(), signatureAlgorithm);
    CertObjectStore certObjects = new CertObjectStore();
    certObjects.addKey(key);
    certObjects.addCSR(csr);
    return certObjects;
}
Also used : KeyPair(java.security.KeyPair) PKCS10CertificateRequest(de.carne.certmgr.certs.x509.PKCS10CertificateRequest) SignatureAlgorithm(de.carne.certmgr.certs.security.SignatureAlgorithm) CertObjectStore(de.carne.certmgr.certs.CertObjectStore)

Example 2 with PKCS10CertificateRequest

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

the class StoreController method updateDetailsView.

private void updateDetailsView(@Nullable TreeItem<StoreEntryModel> selection) {
    TreeItem<AttributeModel> rootItem = null;
    if (selection != null) {
        rootItem = new TreeItem<>();
        rootItem.setExpanded(true);
        UserCertStoreEntry entry = selection.getValue().getEntry();
        updateDetailsViewHelper(rootItem, Attributes.toAttributes(entry), true);
        if (entry.hasCRT()) {
            try {
                X509Certificate crt = entry.getCRT();
                updateDetailsViewHelper(rootItem, X509CertificateHelper.toAttributes(crt), true);
            } catch (IOException e) {
                Exceptions.warn(e);
            }
        }
        if (entry.hasCSR()) {
            try {
                PKCS10CertificateRequest csr = entry.getCSR();
                updateDetailsViewHelper(rootItem, csr.toAttributes(), true);
            } catch (IOException e) {
                Exceptions.ignore(e);
            }
        }
        if (entry.hasCRL()) {
            try {
                X509CRL crl = entry.getCRL();
                updateDetailsViewHelper(rootItem, X509CRLHelper.toAttributes(crl), true);
            } catch (IOException e) {
                Exceptions.ignore(e);
            }
        }
    }
    this.ctlDetailsView.setRoot(rootItem);
}
Also used : X509CRL(java.security.cert.X509CRL) PKCS10CertificateRequest(de.carne.certmgr.certs.x509.PKCS10CertificateRequest) IOException(java.io.IOException) X509Certificate(java.security.cert.X509Certificate) UserCertStoreEntry(de.carne.certmgr.certs.UserCertStoreEntry)

Example 3 with PKCS10CertificateRequest

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

the class DERCertReaderWriter method readBinary.

@Override
@Nullable
public CertObjectStore readBinary(IOResource<InputStream> in, PasswordCallback password) throws IOException {
    LOG.debug("Trying to read DER objects from: ''{0}''...", in);
    CertObjectStore certObjects = null;
    try (ASN1InputStream derStream = new ASN1InputStream(in.io())) {
        ASN1Primitive derObject;
        while ((derObject = derStream.readObject()) != null) {
            X509Certificate crt = tryDecodeCRT(derObject);
            if (crt != null) {
                if (certObjects == null) {
                    certObjects = new CertObjectStore();
                }
                certObjects.addCRT(crt);
                continue;
            }
            KeyPair key = tryDecodeKey(derObject, in.resource(), password);
            if (key != null) {
                if (certObjects == null) {
                    certObjects = new CertObjectStore();
                }
                certObjects.addKey(key);
                continue;
            }
            PKCS10CertificateRequest csr = tryDecodeCSR(derObject);
            if (csr != null) {
                if (certObjects == null) {
                    certObjects = new CertObjectStore();
                }
                certObjects.addCSR(csr);
                continue;
            }
            X509CRL crl = tryDecodeCRL(derObject);
            if (crl != null) {
                if (certObjects == null) {
                    certObjects = new CertObjectStore();
                }
                certObjects.addCRL(crl);
                continue;
            }
            LOG.warning(CertIOI18N.STR_DER_UNKNOWN_OBJECT, derObject.getClass().getName());
        }
    } catch (ClassCastException e) {
        // the file is not a DER stream
        throw new CertProviderException(e);
    }
    return certObjects;
}
Also used : ASN1InputStream(org.bouncycastle.asn1.ASN1InputStream) KeyPair(java.security.KeyPair) X509CRL(java.security.cert.X509CRL) PKCS10CertificateRequest(de.carne.certmgr.certs.x509.PKCS10CertificateRequest) CertObjectStore(de.carne.certmgr.certs.CertObjectStore) ASN1Primitive(org.bouncycastle.asn1.ASN1Primitive) CertProviderException(de.carne.certmgr.certs.CertProviderException) X509Certificate(java.security.cert.X509Certificate) Nullable(de.carne.check.Nullable)

Example 4 with PKCS10CertificateRequest

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

the class UserCertStore method loadPersistentEntries.

private synchronized void loadPersistentEntries(Map<UserCertStoreEntryId, PersistentEntry> entries) throws IOException {
    for (Map.Entry<UserCertStoreEntryId, PersistentEntry> persistentEntryPathsEntry : entries.entrySet()) {
        UserCertStoreEntryId entryId = persistentEntryPathsEntry.getKey();
        PersistentEntry entry = persistentEntryPathsEntry.getValue();
        CertObjectHolder<X509Certificate> crtHolder = entry.crt();
        SecureCertObjectHolder<KeyPair> keyHolder = entry.key();
        CertObjectHolder<PKCS10CertificateRequest> csrHolder = entry.csr();
        CertObjectHolder<X509CRL> crlHolder = entry.crl();
        X500Principal entryDN = null;
        if (crtHolder != null) {
            entryDN = crtHolder.get().getSubjectX500Principal();
        } else if (csrHolder != null) {
            entryDN = csrHolder.get().getSubjectX500Principal();
        } else if (crlHolder != null) {
            entryDN = crlHolder.get().getIssuerX500Principal();
        } else {
            LOG.warning("Ignoring incompliete store entry ''{0}''", entryId);
        }
        if (entryDN != null) {
            Entry storeEntry = new Entry(entryId, entryDN, crtHolder, keyHolder, csrHolder, crlHolder);
            this.storeEntries.put(entryId, storeEntry);
        }
    }
    resetIssuers();
}
Also used : KeyPair(java.security.KeyPair) X509CRL(java.security.cert.X509CRL) PKCS10CertificateRequest(de.carne.certmgr.certs.x509.PKCS10CertificateRequest) X509Certificate(java.security.cert.X509Certificate) X500Principal(javax.security.auth.x500.X500Principal) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

PKCS10CertificateRequest (de.carne.certmgr.certs.x509.PKCS10CertificateRequest)4 KeyPair (java.security.KeyPair)3 X509CRL (java.security.cert.X509CRL)3 X509Certificate (java.security.cert.X509Certificate)3 CertObjectStore (de.carne.certmgr.certs.CertObjectStore)2 CertProviderException (de.carne.certmgr.certs.CertProviderException)1 UserCertStoreEntry (de.carne.certmgr.certs.UserCertStoreEntry)1 SignatureAlgorithm (de.carne.certmgr.certs.security.SignatureAlgorithm)1 Nullable (de.carne.check.Nullable)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 X500Principal (javax.security.auth.x500.X500Principal)1 ASN1InputStream (org.bouncycastle.asn1.ASN1InputStream)1 ASN1Primitive (org.bouncycastle.asn1.ASN1Primitive)1