Search in sources :

Example 1 with X509Cert

use of org.xipki.security.X509Cert in project xipki by xipki.

the class OcspCertPublisher method certificateAdded.

@Override
public boolean certificateAdded(X509CertificateInfo certInfo) {
    X509Cert caCert = certInfo.getIssuerCert();
    X509CertWithDbId cert = certInfo.getCert();
    try {
        queryExecutor.addCert(caCert, cert, certInfo.getProfile().getName(), certInfo.getRevocationInfo());
        return true;
    } catch (Exception ex) {
        logAndAudit(caCert.getSubject(), cert, ex, "could not save certificate");
        return false;
    }
}
Also used : X509Cert(org.xipki.security.X509Cert) X509CertWithDbId(org.xipki.ca.api.X509CertWithDbId) DataAccessException(org.xipki.datasource.DataAccessException) CertPublisherException(org.xipki.ca.api.publisher.CertPublisherException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 2 with X509Cert

use of org.xipki.security.X509Cert in project xipki by xipki.

the class AbstractP11Slot method refresh.

@Override
public void refresh() throws P11TokenException {
    // CHECKSTYLE:SKIP
    P11SlotRefreshResult res = refresh0();
    mechanisms.clear();
    certificates.clear();
    identities.clear();
    List<Long> ignoreMechs = new ArrayList<>();
    for (Long mech : res.getMechanisms()) {
        if (mechanismFilter.isMechanismPermitted(slotId, mech)) {
            mechanisms.add(mech);
        } else {
            ignoreMechs.add(mech);
        }
    }
    certificates.putAll(res.getCertificates());
    identities.putAll(res.getIdentities());
    updateCaCertsOfIdentities();
    if (LOG.isInfoEnabled()) {
        StringBuilder sb = new StringBuilder();
        sb.append("initialized module ").append(moduleName).append(", slot ").append(slotId);
        sb.append("\nsupported mechanisms:\n");
        List<Long> sortedMechs = new ArrayList<>(mechanisms);
        Collections.sort(sortedMechs);
        for (Long mech : sortedMechs) {
            sb.append("\t").append(Pkcs11Functions.getMechanismDesc(mech)).append("\n");
        }
        sb.append("\nsupported by device but ignored mechanisms:\n");
        if (ignoreMechs.isEmpty()) {
            sb.append("\tNONE\n");
        } else {
            Collections.sort(ignoreMechs);
            for (Long mech : ignoreMechs) {
                sb.append("\t").append(Pkcs11Functions.getMechanismDesc(mech)).append("\n");
            }
        }
        List<P11ObjectIdentifier> ids = getSortedObjectIds(certificates.keySet());
        sb.append(ids.size()).append(" certificates:\n");
        for (P11ObjectIdentifier objectId : ids) {
            X509Cert entity = certificates.get(objectId);
            sb.append("\t").append(objectId);
            sb.append(", subject='").append(entity.getSubject()).append("'\n");
        }
        ids = getSortedObjectIds(identities.keySet());
        sb.append(ids.size()).append(" identities:\n");
        for (P11ObjectIdentifier objectId : ids) {
            P11Identity identity = identities.get(objectId);
            sb.append("\t").append(objectId);
            if (identity.getPublicKey() != null) {
                sb.append(", algo=").append(identity.getPublicKey().getAlgorithm());
                if (identity.getCertificate() != null) {
                    String subject = X509Util.getRfc4519Name(identity.getCertificate().getSubjectX500Principal());
                    sb.append(", subject='").append(subject).append("'");
                }
            } else {
                sb.append(", algo=<symmetric>");
            }
            sb.append("\n");
        }
        LOG.info(sb.toString());
    }
}
Also used : X509Cert(org.xipki.security.X509Cert) ArrayList(java.util.ArrayList)

Example 3 with X509Cert

use of org.xipki.security.X509Cert in project xipki by xipki.

the class AbstractP11Slot method addCert.

@Override
public P11ObjectIdentifier addCert(X509Certificate cert) throws P11TokenException, CertificateException {
    ParamUtil.requireNonNull("cert", cert);
    assertWritable("addCert");
    byte[] encodedCert = cert.getEncoded();
    for (P11ObjectIdentifier objectId : certificates.keySet()) {
        X509Cert tmpCert = certificates.get(objectId);
        if (Arrays.equals(encodedCert, tmpCert.getEncodedCert())) {
            return objectId;
        }
    }
    byte[] id = generateId();
    String cn = X509Util.getCommonName(cert.getSubjectX500Principal());
    String label = generateLabel(cn);
    P11ObjectIdentifier objectId = new P11ObjectIdentifier(id, label);
    addCert(objectId, cert);
    return objectId;
}
Also used : X509Cert(org.xipki.security.X509Cert)

Example 4 with X509Cert

use of org.xipki.security.X509Cert in project xipki by xipki.

the class AbstractP11Slot method exportCert.

@Override
public X509Certificate exportCert(P11ObjectIdentifier objectId) throws P11TokenException {
    ParamUtil.requireNonNull("objectId", objectId);
    try {
        return getIdentity(objectId).getCertificate();
    } catch (P11UnknownEntityException ex) {
    // CHECKSTYLE:SKIP
    }
    X509Cert cert = certificates.get(objectId);
    if (cert == null) {
        throw new P11UnknownEntityException(slotId, objectId);
    }
    return cert.getCert();
}
Also used : P11UnknownEntityException(org.xipki.security.exception.P11UnknownEntityException) X509Cert(org.xipki.security.X509Cert)

Example 5 with X509Cert

use of org.xipki.security.X509Cert in project xipki by xipki.

the class ScepImpl method refreshCa.

private void refreshCa() throws OperationException {
    try {
        X509Ca ca = caManager.getX509Ca(caIdent);
        X509Cert currentCaCert = ca.getCaInfo().getCert();
        if (currentCaCert.equals(caCert)) {
            return;
        }
        caCert = currentCaCert;
        caCertRespBytes = new ScepCaCertRespBytes(currentCaCert.getCert(), responderCert);
    } catch (CaMgmtException | CertificateException | CMSException ex) {
        throw new OperationException(ErrorCode.SYSTEM_FAILURE, ex.getMessage());
    }
}
Also used : ScepCaCertRespBytes(org.xipki.ca.server.api.ScepCaCertRespBytes) CaMgmtException(org.xipki.ca.server.mgmt.api.CaMgmtException) X509Cert(org.xipki.security.X509Cert) X509Ca(org.xipki.ca.server.impl.X509Ca) CertificateException(java.security.cert.CertificateException) OperationException(org.xipki.ca.api.OperationException) CMSException(org.bouncycastle.cms.CMSException)

Aggregations

X509Cert (org.xipki.security.X509Cert)14 X509Certificate (java.security.cert.X509Certificate)5 P11EntityIdentifier (org.xipki.security.pkcs11.P11EntityIdentifier)4 CertificateException (java.security.cert.CertificateException)3 P11TokenException (org.xipki.security.exception.P11TokenException)3 P11ObjectIdentifier (org.xipki.security.pkcs11.P11ObjectIdentifier)3 Session (iaik.pkcs.pkcs11.Session)2 TokenException (iaik.pkcs.pkcs11.TokenException)2 X509PublicKeyCertificate (iaik.pkcs.pkcs11.objects.X509PublicKeyCertificate)2 File (java.io.File)2 PublicKey (java.security.PublicKey)2 OperationException (org.xipki.ca.api.OperationException)2 X509Ca (org.xipki.ca.server.impl.X509Ca)2 Asn1P11EntityIdentifier (org.xipki.p11proxy.msg.Asn1P11EntityIdentifier)2 P11SlotRefreshResult (org.xipki.security.pkcs11.P11SlotRefreshResult)2 DSAPublicKey (iaik.pkcs.pkcs11.objects.DSAPublicKey)1 ECPublicKey (iaik.pkcs.pkcs11.objects.ECPublicKey)1 PublicKey (iaik.pkcs.pkcs11.objects.PublicKey)1 RSAPublicKey (iaik.pkcs.pkcs11.objects.RSAPublicKey)1 SM2PublicKey (iaik.pkcs.pkcs11.objects.SM2PublicKey)1