Search in sources :

Example 1 with NoCertificateChainException

use of org.openecard.mdlw.sal.exceptions.NoCertificateChainException in project open-ecard by ecsec.

the class CIFCreator method getSignatureCryptoDIDs.

private List<DIDInfoType> getSignatureCryptoDIDs() throws WSMarshallerException, CryptokiException {
    LOG.debug("Reading infos for CryptoDID generation.");
    ArrayList<DIDInfoType> didInfos = new ArrayList<>();
    List<MwPublicKey> pubKeys = session.getPublicKeys();
    for (MwPublicKey pubKey : pubKeys) {
        LOG.debug("Found key object {}.", pubKey);
        if (!Boolean.TRUE.equals(pubKey.getVerify())) {
            LOG.info("Skipping non-signing key {}.", pubKey.getKeyLabel());
            continue;
        }
        // look up certificates
        try {
            List<MwCertificate> mwCerts = createChain(session.getCertificates(), pubKey.getKeyID());
            if (mwCerts.isEmpty()) {
                LOG.info("No certificates available for the key object.");
                continue;
            }
            MwCertificate eeCert = mwCerts.get(0);
            // check certType
            switch(eeCert.getCertificateCategory()) {
                case CK_CERTIFICATE_CATEGORY_TOKEN_USER:
                case CK_CERTIFICATE_CATEGORY_UNSPECIFIED:
                    break;
                default:
                    LOG.info("Skipping key '{}' as certificate has wrong category.", pubKey.getKeyLabel());
            }
            // check certificate usage flags
            if (!canSign(eeCert)) {
                LOG.info("Certificate '{}' can not be used to perform a signature.", eeCert.getLabel());
                continue;
            }
            // determine available algorithms
            List<SignatureAlgorithms> sigalgs = getSigAlgs(pubKey);
            for (SignatureAlgorithms sigalg : sigalgs) {
                DIDInfoType did = createCryptoDID(mwCerts, sigalg);
                didInfos.add(did);
            }
        } catch (NoCertificateChainException ex) {
            LOG.warn("Could not create a certificate chain for requested key.", ex);
        } catch (CryptokiException ex) {
            LOG.warn("Failed to read DID data from middleware, skipping this key entry.", ex);
        }
    }
    return didInfos;
}
Also used : DIDInfoType(iso.std.iso_iec._24727.tech.schema.DIDInfoType) CryptokiException(org.openecard.mdlw.sal.exceptions.CryptokiException) SignatureAlgorithms(org.openecard.crypto.common.SignatureAlgorithms) ArrayList(java.util.ArrayList) NoCertificateChainException(org.openecard.mdlw.sal.exceptions.NoCertificateChainException)

Aggregations

DIDInfoType (iso.std.iso_iec._24727.tech.schema.DIDInfoType)1 ArrayList (java.util.ArrayList)1 SignatureAlgorithms (org.openecard.crypto.common.SignatureAlgorithms)1 CryptokiException (org.openecard.mdlw.sal.exceptions.CryptokiException)1 NoCertificateChainException (org.openecard.mdlw.sal.exceptions.NoCertificateChainException)1