Search in sources :

Example 6 with DIDInfoType

use of iso.std.iso_iec._24727.tech.schema.DIDInfoType in project open-ecard by ecsec.

the class StatusHandler method getSupportedCards.

@Nonnull
private static List<StatusType.SupportedCards> getSupportedCards(List<String> protocols, List<CardInfoType> cifs) {
    List<StatusType.SupportedCards> result = new ArrayList<>();
    for (CardInfoType cif : cifs) {
        StatusType.SupportedCards supportedCard = new StatusType.SupportedCards();
        result.add(supportedCard);
        String name = cif.getCardType().getObjectIdentifier();
        supportedCard.setCardType(name);
        for (CardApplicationType app : cif.getApplicationCapabilities().getCardApplication()) {
            for (DIDInfoType did : app.getDIDInfo()) {
                String proto = did.getDifferentialIdentity().getDIDProtocol();
                // add protocol to list only if it is supported by the application and not yet added
                if (protocols.contains(proto) && !supportedCard.getDIDProtocols().contains(proto)) {
                    supportedCard.getDIDProtocols().add(proto);
                }
            }
        }
    }
    return result;
}
Also used : CardInfoType(iso.std.iso_iec._24727.tech.schema.CardInfoType) CardApplicationType(iso.std.iso_iec._24727.tech.schema.CardApplicationType) DIDInfoType(iso.std.iso_iec._24727.tech.schema.DIDInfoType) StatusType(org.openecard.ws.schema.StatusType) ArrayList(java.util.ArrayList) Nonnull(javax.annotation.Nonnull)

Example 7 with DIDInfoType

use of iso.std.iso_iec._24727.tech.schema.DIDInfoType in project open-ecard by ecsec.

the class CardInfoWrapper method getDIDStructure.

/**
 * @param didName Name of the DID to get the structure for
 * @param cardApplication Identifier of the card application
 * @return DIDStructure for the specified didName and card application or null, if no such did exists.
 */
public DIDStructureType getDIDStructure(String didName, byte[] cardApplication) {
    DIDInfoType didInfo = this.getDIDInfo(didName, cardApplication);
    if (didInfo == null) {
        return null;
    }
    DIDStructureType didStructure = new DIDStructureType();
    didStructure.setDIDName(didInfo.getDifferentialIdentity().getDIDName());
    didStructure.setDIDScope(didInfo.getDifferentialIdentity().getDIDScope());
    if (didStructure.getDIDScope() == null) {
        // no scope is equal to local
        didStructure.setDIDScope(DIDScopeType.LOCAL);
    }
    DIDMarkerType didMarker = didInfo.getDifferentialIdentity().getDIDMarker();
    if (didMarker.getCAMarker() != null) {
        didStructure.setDIDMarker(didMarker.getCAMarker());
    } else if (didMarker.getCryptoMarker() != null) {
        didStructure.setDIDMarker(didMarker.getCryptoMarker());
    } else if (didMarker.getEACMarker() != null) {
        didStructure.setDIDMarker(didMarker.getEACMarker());
    } else if (didMarker.getMutualAuthMarker() != null) {
        didStructure.setDIDMarker(didMarker.getMutualAuthMarker());
    } else if (didMarker.getPACEMarker() != null) {
        didStructure.setDIDMarker(didMarker.getPACEMarker());
    } else if (didMarker.getPinCompareMarker() != null) {
        didStructure.setDIDMarker(didMarker.getPinCompareMarker());
    } else if (didMarker.getRIMarker() != null) {
        didStructure.setDIDMarker(didMarker.getRIMarker());
    } else if (didMarker.getRSAAuthMarker() != null) {
        didStructure.setDIDMarker(didMarker.getRSAAuthMarker());
    } else if (didMarker.getTAMarker() != null) {
        didStructure.setDIDMarker(didMarker.getTAMarker());
    }
    didStructure.setDIDQualifier(didInfo.getDifferentialIdentity().getDIDQualifier());
    return didStructure;
}
Also used : DIDMarkerType(iso.std.iso_iec._24727.tech.schema.DIDMarkerType) DIDInfoType(iso.std.iso_iec._24727.tech.schema.DIDInfoType) DIDStructureType(iso.std.iso_iec._24727.tech.schema.DIDStructureType)

Example 8 with DIDInfoType

use of iso.std.iso_iec._24727.tech.schema.DIDInfoType in project open-ecard by ecsec.

the class TinySAL method didList.

/**
 * The DIDList function returns a list of the existing DIDs in the card application addressed by the
 * ConnectionHandle or the ApplicationIdentifier element within the Filter.
 * See BSI-TR-03112-4, version 1.1.2, section 3.6.1.
 *
 * @param request DIDList
 * @return DIDListResponse
 */
@Publish
@Override
public DIDListResponse didList(DIDList request) {
    DIDListResponse response = WSHelper.makeResponse(DIDListResponse.class, WSHelper.makeResultOK());
    try {
        ConnectionHandleType connectionHandle = SALUtils.getConnectionHandle(request);
        byte[] appId = connectionHandle.getCardApplication();
        CardStateEntry cardStateEntry = SALUtils.getCardStateEntry(states, connectionHandle, false);
        Assert.securityConditionApplication(cardStateEntry, appId, DifferentialIdentityServiceActionName.DID_LIST);
        byte[] applicationIDFilter = null;
        String objectIDFilter = null;
        String applicationFunctionFilter = null;
        DIDQualifierType didQualifier = request.getFilter();
        if (didQualifier != null) {
            applicationIDFilter = didQualifier.getApplicationIdentifier();
            objectIDFilter = didQualifier.getObjectIdentifier();
            applicationFunctionFilter = didQualifier.getApplicationFunction();
        }
        /*
	     * Filter by ApplicationIdentifier.
	     * [TR-03112-4] Allows specifying an application identifier. If this element is present all
	     * DIDs within the specified card application are returned no matter which card application
	     * is currently selected.
	     */
        CardApplicationWrapper cardApplication;
        if (applicationIDFilter != null) {
            cardApplication = cardStateEntry.getInfo().getCardApplication(applicationIDFilter);
            Assert.assertIncorrectParameter(cardApplication, "The given CardApplication cannot be found.");
        } else {
            cardApplication = cardStateEntry.getCurrentCardApplication();
        }
        List<DIDInfoType> didInfos = new ArrayList<>(cardApplication.getDIDInfoList());
        /*
	     * Filter by ObjectIdentifier.
	     * [TR-03112-4] Allows specifying a protocol OID (cf. [TR-03112-7]) such that only DIDs
	     * which support a given protocol are listed.
	     */
        if (objectIDFilter != null) {
            Iterator<DIDInfoType> it = didInfos.iterator();
            while (it.hasNext()) {
                DIDInfoType next = it.next();
                if (!next.getDifferentialIdentity().getDIDProtocol().equals(objectIDFilter)) {
                    it.remove();
                }
            }
        }
        /*
	     * Filter by ApplicationFunction.
	     * [TR-03112-4] Allows filtering for DIDs, which support a specific cryptographic operation.
	     * The bit string is coded as the SupportedOperations-element in [ISO7816-15].
	     */
        if (applicationFunctionFilter != null) {
            Iterator<DIDInfoType> it = didInfos.iterator();
            while (it.hasNext()) {
                DIDInfoType next = it.next();
                if (next.getDifferentialIdentity().getDIDMarker().getCryptoMarker() == null) {
                    it.remove();
                } else {
                    iso.std.iso_iec._24727.tech.schema.CryptoMarkerType rawMarker;
                    rawMarker = next.getDifferentialIdentity().getDIDMarker().getCryptoMarker();
                    CryptoMarkerType cryptoMarker = new CryptoMarkerType(rawMarker);
                    AlgorithmInfoType algInfo = cryptoMarker.getAlgorithmInfo();
                    if (!algInfo.getSupportedOperations().contains(applicationFunctionFilter)) {
                        it.remove();
                    }
                }
            }
        }
        DIDNameListType didNameList = new DIDNameListType();
        for (DIDInfoType didInfo : didInfos) {
            didNameList.getDIDName().add(didInfo.getDifferentialIdentity().getDIDName());
        }
        response.setDIDNameList(didNameList);
    } catch (ECardException e) {
        response.setResult(e.getResult());
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        throwThreadKillException(e);
        response.setResult(WSHelper.makeResult(e));
    }
    return response;
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) CardStateEntry(org.openecard.common.sal.state.CardStateEntry) DIDQualifierType(iso.std.iso_iec._24727.tech.schema.DIDQualifierType) ArrayList(java.util.ArrayList) CryptoMarkerType(org.openecard.crypto.common.sal.did.CryptoMarkerType) DIDListResponse(iso.std.iso_iec._24727.tech.schema.DIDListResponse) PrerequisitesNotSatisfiedException(org.openecard.common.sal.exception.PrerequisitesNotSatisfiedException) NameExistsException(org.openecard.common.sal.exception.NameExistsException) AddonNotFoundException(org.openecard.addon.AddonNotFoundException) ThreadTerminateException(org.openecard.common.ThreadTerminateException) ECardException(org.openecard.common.ECardException) NamedEntityNotFoundException(org.openecard.common.sal.exception.NamedEntityNotFoundException) UnknownProtocolException(org.openecard.common.sal.exception.UnknownProtocolException) IncorrectParameterException(org.openecard.common.sal.exception.IncorrectParameterException) InappropriateProtocolForActionException(org.openecard.common.sal.exception.InappropriateProtocolForActionException) TLVException(org.openecard.common.tlv.TLVException) SecurityConditionNotSatisfiedException(org.openecard.common.sal.exception.SecurityConditionNotSatisfiedException) UnknownConnectionHandleException(org.openecard.common.sal.exception.UnknownConnectionHandleException) ECardException(org.openecard.common.ECardException) DIDNameListType(iso.std.iso_iec._24727.tech.schema.DIDNameListType) DIDInfoType(iso.std.iso_iec._24727.tech.schema.DIDInfoType) AlgorithmInfoType(iso.std.iso_iec._24727.tech.schema.AlgorithmInfoType) CardApplicationWrapper(org.openecard.common.sal.state.cif.CardApplicationWrapper) Publish(org.openecard.common.interfaces.Publish)

Example 9 with DIDInfoType

use of iso.std.iso_iec._24727.tech.schema.DIDInfoType in project open-ecard by ecsec.

the class AndroidMarshallerTest method testConversionOfCardInfo.

@Test
public void testConversionOfCardInfo() throws Exception {
    WSMarshaller m = new AndroidMarshaller();
    Object o = m.unmarshal(m.str2doc(NPA_CIF));
    if (!(o instanceof CardInfo)) {
        throw new Exception("Object should be an instace of CardInfo");
    }
    CardInfo cardInfo = (CardInfo) o;
    assertEquals("http://bsi.bund.de/cif/npa.xml", cardInfo.getCardType().getObjectIdentifier());
    assertEquals(new byte[] { 0x3F, 0x00 }, cardInfo.getApplicationCapabilities().getImplicitlySelectedApplication());
    assertEquals(cardInfo.getApplicationCapabilities().getCardApplication().size(), 3);
    assertEquals(cardInfo.getApplicationCapabilities().getCardApplication().get(0).getApplicationName(), "MF");
    assertEquals(cardInfo.getApplicationCapabilities().getCardApplication().get(0).getRequirementLevel(), BasicRequirementsType.PERSONALIZATION_MANDATORY);
    assertEquals(cardInfo.getApplicationCapabilities().getCardApplication().get(0).getCardApplicationACL().getAccessRule().size(), 40);
    assertEquals(cardInfo.getApplicationCapabilities().getCardApplication().get(0).getCardApplicationACL().getAccessRule().get(0).getCardApplicationServiceName(), "CardApplicationServiceAccess");
    assertEquals(cardInfo.getApplicationCapabilities().getCardApplication().get(0).getCardApplicationACL().getAccessRule().get(0).getAction().getAPIAccessEntryPoint(), APIAccessEntryPointName.INITIALIZE);
    assertTrue(cardInfo.getApplicationCapabilities().getCardApplication().get(0).getCardApplicationACL().getAccessRule().get(0).getSecurityCondition().isAlways());
    // last accessrule
    assertEquals(cardInfo.getApplicationCapabilities().getCardApplication().get(0).getCardApplicationACL().getAccessRule().get(39).getAction().getAuthorizationServiceAction(), AuthorizationServiceActionName.ACL_MODIFY);
    assertFalse(cardInfo.getApplicationCapabilities().getCardApplication().get(0).getCardApplicationACL().getAccessRule().get(39).getSecurityCondition().isNever());
    assertEquals(cardInfo.getApplicationCapabilities().getCardApplication().get(0).getDIDInfo().get(0).getRequirementLevel(), BasicRequirementsType.PERSONALIZATION_MANDATORY);
    assertEquals(cardInfo.getApplicationCapabilities().getCardApplication().get(0).getDIDInfo().get(0).getDIDACL().getAccessRule().get(0).getCardApplicationServiceName(), "DifferentialIdentityService");
    assertEquals(cardInfo.getApplicationCapabilities().getCardApplication().get(1).getDataSetInfo().get(0).getRequirementLevel(), BasicRequirementsType.PERSONALIZATION_MANDATORY);
    assertEquals(cardInfo.getApplicationCapabilities().getCardApplication().get(1).getDataSetInfo().get(0).getDataSetACL().getAccessRule().get(0).getCardApplicationServiceName(), "NamedDataService");
    for (DataSetInfoType dataSetInfo : cardInfo.getApplicationCapabilities().getCardApplication().get(2).getDataSetInfo()) {
        if (dataSetInfo.getDataSetName().equals("EF.C.ZDA.QES")) {
            assertEquals(dataSetInfo.getLocalDataSetName().get(0).getLang(), "DE");
            assertEquals(dataSetInfo.getLocalDataSetName().get(0).getValue(), "Zertifikat des ZDA für die QES");
        }
    }
    // Test eGK
    o = m.unmarshal(m.str2doc(EGK_CIF));
    if (!(o instanceof CardInfo)) {
        throw new Exception("Object should be an instace of CardInfo");
    }
    cardInfo = (CardInfo) o;
    assertEquals("http://ws.gematik.de/egk/1.0.0", cardInfo.getCardType().getObjectIdentifier());
    CardApplicationType cardApplicationESIGN = cardInfo.getApplicationCapabilities().getCardApplication().get(2);
    DIDInfoType didInfo = cardApplicationESIGN.getDIDInfo().get(2);
    DifferentialIdentityType differentialIdentity = didInfo.getDifferentialIdentity();
    assertEquals(differentialIdentity.getDIDName(), "PrK.CH.AUT_signPKCS1_V1_5");
    assertEquals(differentialIdentity.getDIDProtocol(), "urn:oid:1.3.162.15480.3.0.25");
    CryptoMarkerType cryptoMarkerType = new CryptoMarkerType(differentialIdentity.getDIDMarker().getCryptoMarker());
    assertEquals(cryptoMarkerType.getProtocol(), "urn:oid:1.3.162.15480.3.0.25");
    assertEquals(cryptoMarkerType.getAlgorithmInfo().getSupportedOperations().get(0), "Compute-signature");
    // uncomment to get output files to make a diff
    /*WSMarshaller jaxbMarshaller = new JAXBMarshaller();
	CardInfo cardInfoJM = (CardInfo) jaxbMarshaller.unmarshal(jaxbMarshaller.str2doc(egkCif));
	File f = new File("cifJM.xml");
	FileOutputStream fos = new FileOutputStream(f);
	File f2 = new File("cifAM.xml");
	FileOutputStream fos2 = new FileOutputStream(f2);
	marshalLog(cardInfoJM, fos);
	marshalLog(cardInfo, fos2);*/
    // Test ecard AT 0.9.0
    o = m.unmarshal(m.str2doc(ECARD_AT_CIF));
    if (!(o instanceof CardInfo)) {
        throw new Exception("Object should be an instance of CardInfo");
    }
    cardInfo = (CardInfo) o;
}
Also used : DifferentialIdentityType(iso.std.iso_iec._24727.tech.schema.DifferentialIdentityType) CardApplicationType(iso.std.iso_iec._24727.tech.schema.CardApplicationType) DIDInfoType(iso.std.iso_iec._24727.tech.schema.DIDInfoType) DataSetInfoType(iso.std.iso_iec._24727.tech.schema.DataSetInfoType) WSMarshaller(org.openecard.ws.marshal.WSMarshaller) CardInfo(iso.std.iso_iec._24727.tech.schema.CardInfo) CryptoMarkerType(org.openecard.crypto.common.sal.did.CryptoMarkerType) IOException(java.io.IOException) Test(org.testng.annotations.Test)

Example 10 with DIDInfoType

use of iso.std.iso_iec._24727.tech.schema.DIDInfoType 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)12 DIDMarkerType (iso.std.iso_iec._24727.tech.schema.DIDMarkerType)4 CryptokiException (org.openecard.mdlw.sal.exceptions.CryptokiException)4 CardApplicationType (iso.std.iso_iec._24727.tech.schema.CardApplicationType)3 DataSetInfoType (iso.std.iso_iec._24727.tech.schema.DataSetInfoType)3 DifferentialIdentityType (iso.std.iso_iec._24727.tech.schema.DifferentialIdentityType)3 ArrayList (java.util.ArrayList)3 AccessControlListType (iso.std.iso_iec._24727.tech.schema.AccessControlListType)2 AccessRuleType (iso.std.iso_iec._24727.tech.schema.AccessRuleType)2 AlgorithmInfoType (iso.std.iso_iec._24727.tech.schema.AlgorithmInfoType)2 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)2 DIDStructureType (iso.std.iso_iec._24727.tech.schema.DIDStructureType)2 IOException (java.io.IOException)2 AddonNotFoundException (org.openecard.addon.AddonNotFoundException)2 ECardException (org.openecard.common.ECardException)2 ThreadTerminateException (org.openecard.common.ThreadTerminateException)2 Publish (org.openecard.common.interfaces.Publish)2 InappropriateProtocolForActionException (org.openecard.common.sal.exception.InappropriateProtocolForActionException)2 IncorrectParameterException (org.openecard.common.sal.exception.IncorrectParameterException)2 NameExistsException (org.openecard.common.sal.exception.NameExistsException)2