Search in sources :

Example 11 with UnsupportedAlgorithmException

use of org.openecard.crypto.common.UnsupportedAlgorithmException in project open-ecard by ecsec.

the class SmartCardSignerCredential method getDidAlgorithm.

public SignatureAlgorithms getDidAlgorithm() {
    try {
        AlgorithmInfoType algInfo = did.getGenericCryptoMarker().getAlgorithmInfo();
        SignatureAlgorithms alg = SignatureAlgorithms.fromAlgId(algInfo.getAlgorithmIdentifier().getAlgorithm());
        return alg;
    } catch (UnsupportedAlgorithmException | WSHelper.WSException ex) {
        throw new RuntimeException("Error evaluating algorithm", ex);
    }
}
Also used : AlgorithmInfoType(iso.std.iso_iec._24727.tech.schema.AlgorithmInfoType) SignatureAlgorithms(org.openecard.crypto.common.SignatureAlgorithms) UnsupportedAlgorithmException(org.openecard.crypto.common.UnsupportedAlgorithmException)

Example 12 with UnsupportedAlgorithmException

use of org.openecard.crypto.common.UnsupportedAlgorithmException in project open-ecard by ecsec.

the class HashStep method perform.

@Override
public HashResponse perform(Hash request, Map<String, Object> internalData) {
    HashResponse response = WSHelper.makeResponse(HashResponse.class, WSHelper.makeResultOK());
    try {
        ConnectionHandleType connectionHandle = SALUtils.getConnectionHandle(request);
        String didName = SALUtils.getDIDName(request);
        CardStateEntry cardStateEntry = SALUtils.getCardStateEntry(internalData, connectionHandle);
        DIDStructureType didStructure = SALUtils.getDIDStructure(request, didName, cardStateEntry, connectionHandle);
        CryptoMarkerType cryptoMarker = new CryptoMarkerType(didStructure.getDIDMarker());
        HashGenerationInfoType hashInfo = cryptoMarker.getHashGenerationInfo();
        if (hashInfo != null) {
            if (hashInfo == HashGenerationInfoType.NOT_ON_CARD) {
                String algId = cryptoMarker.getAlgorithmInfo().getAlgorithmIdentifier().getAlgorithm();
                SignatureAlgorithms alg = SignatureAlgorithms.fromAlgId(algId);
                HashAlgorithms hashAlg = alg.getHashAlg();
                if (hashAlg == null) {
                    String msg = String.format("Algorithm %s does not specify a Hash algorithm.", algId);
                    LOG.error(msg);
                    String minor = ECardConstants.Minor.App.INCORRECT_PARM;
                    response.setResult(WSHelper.makeResultError(minor, msg));
                } else {
                    // calculate hash
                    MessageDigest md = MessageDigest.getInstance(hashAlg.getJcaAlg());
                    md.update(request.getMessage());
                    byte[] digest = md.digest();
                    response.setHash(digest);
                }
            } else {
                // TODO: implement hashing on card
                String msg = String.format("Unsupported Hash generation type (%s) requested.", hashInfo);
                LOG.error(msg);
                String minor = ECardConstants.Minor.SAL.INAPPROPRIATE_PROTOCOL_FOR_ACTION;
                response.setResult(WSHelper.makeResultError(minor, msg));
            }
        } else {
            // no hash alg specified, this is an error
            String msg = String.format("No Hash generation type specified in CIF.");
            LOG.error(msg);
            String minor = ECardConstants.Minor.SAL.INAPPROPRIATE_PROTOCOL_FOR_ACTION;
            response.setResult(WSHelper.makeResultError(minor, msg));
        }
    } catch (ECardException e) {
        response.setResult(e.getResult());
    } catch (UnsupportedAlgorithmException | NoSuchAlgorithmException ex) {
    } catch (Exception e) {
        LOG.warn(e.getMessage(), e);
        response.setResult(WSHelper.makeResult(e));
    }
    return response;
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) HashAlgorithms(org.openecard.crypto.common.HashAlgorithms) CardStateEntry(org.openecard.common.sal.state.CardStateEntry) CryptoMarkerType(org.openecard.crypto.common.sal.did.CryptoMarkerType) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) HashGenerationInfoType(iso.std.iso_iec._24727.tech.schema.HashGenerationInfoType) UnsupportedAlgorithmException(org.openecard.crypto.common.UnsupportedAlgorithmException) ECardException(org.openecard.common.ECardException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ECardException(org.openecard.common.ECardException) HashResponse(iso.std.iso_iec._24727.tech.schema.HashResponse) SignatureAlgorithms(org.openecard.crypto.common.SignatureAlgorithms) UnsupportedAlgorithmException(org.openecard.crypto.common.UnsupportedAlgorithmException) DIDStructureType(iso.std.iso_iec._24727.tech.schema.DIDStructureType) MessageDigest(java.security.MessageDigest)

Aggregations

UnsupportedAlgorithmException (org.openecard.crypto.common.UnsupportedAlgorithmException)12 SignatureAlgorithms (org.openecard.crypto.common.SignatureAlgorithms)8 WSHelper (org.openecard.common.WSHelper)6 AlgorithmInfoType (iso.std.iso_iec._24727.tech.schema.AlgorithmInfoType)5 DidInfo (org.openecard.crypto.common.sal.did.DidInfo)5 ArrayList (java.util.ArrayList)4 SecurityConditionUnsatisfiable (org.openecard.common.SecurityConditionUnsatisfiable)4 DidInfos (org.openecard.crypto.common.sal.did.DidInfos)4 ThreadTerminateException (org.openecard.common.ThreadTerminateException)3 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)2 IOException (java.io.IOException)2 X509Certificate (java.security.cert.X509Certificate)2 ParameterInvalid (org.openecard.addons.cg.ex.ParameterInvalid)2 SlotHandleInvalid (org.openecard.addons.cg.ex.SlotHandleInvalid)2 InvocationTargetExceptionUnchecked (org.openecard.common.interfaces.InvocationTargetExceptionUnchecked)2 CryptoMarkerType (org.openecard.crypto.common.sal.did.CryptoMarkerType)2 NoSuchDid (org.openecard.crypto.common.sal.did.NoSuchDid)2 AlgorithmIdentifierType (iso.std.iso_iec._24727.tech.schema.AlgorithmIdentifierType)1 DIDStructureType (iso.std.iso_iec._24727.tech.schema.DIDStructureType)1 HashGenerationInfoType (iso.std.iso_iec._24727.tech.schema.HashGenerationInfoType)1