Search in sources :

Example 1 with DifferentialIdentityType

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

the class CIFCreator method createPinDID.

private DIDInfoType createPinDID() throws WSMarshallerException {
    LOG.debug("Creating PinCompare DID object.");
    DIDInfoType di = new DIDInfoType();
    // create differential identity
    DifferentialIdentityType did = new DifferentialIdentityType();
    di.setDifferentialIdentity(did);
    String didName = PIN_NAME;
    did.setDIDName(didName);
    did.setDIDProtocol("urn:oid:1.3.162.15480.3.0.9");
    did.setDIDScope(DIDScopeType.GLOBAL);
    // create pin compare marker
    PinMarkerBuilder markerBuilder = new PinMarkerBuilder();
    KeyRefType kr = new KeyRefType();
    // value is irrelevant
    kr.setKeyRef(new byte[] { 0x01 });
    markerBuilder.setPinRef(kr);
    try {
        PasswordAttributesType pw = new PasswordAttributesType();
        MwToken tok = session.getSlot().getTokenInfo();
        long minPinLen = tok.getUlMinPinLen();
        long maxPinLen = tok.getUlMinPinLen();
        pw.setMinLength(BigInteger.valueOf(minPinLen));
        pw.setMaxLength(BigInteger.valueOf(maxPinLen));
        markerBuilder.setPwAttributes(pw);
    } catch (CryptokiException | NullPointerException ex) {
        LOG.warn("Unable to read min and max PIN length from middleware.");
    }
    // wrap pin compare marker and add to parent
    PinCompareMarkerType marker = markerBuilder.build();
    DIDMarkerType markerWrapper = new DIDMarkerType();
    markerWrapper.setPinCompareMarker(marker);
    did.setDIDMarker(markerWrapper);
    // create acl
    AccessControlListType acl = new AccessControlListType();
    di.setDIDACL(acl);
    List<AccessRuleType> rules = acl.getAccessRule();
    rules.add(createRuleTrue(AuthorizationServiceActionName.ACL_LIST));
    rules.add(createRuleTrue(DifferentialIdentityServiceActionName.DID_LIST));
    rules.add(createRuleTrue(DifferentialIdentityServiceActionName.DID_GET));
    rules.add(createRuleTrue(DifferentialIdentityServiceActionName.DID_AUTHENTICATE));
    return di;
}
Also used : KeyRefType(iso.std.iso_iec._24727.tech.schema.KeyRefType) PasswordAttributesType(iso.std.iso_iec._24727.tech.schema.PasswordAttributesType) AccessControlListType(iso.std.iso_iec._24727.tech.schema.AccessControlListType) PinMarkerBuilder(org.openecard.mdlw.sal.didfactory.PinMarkerBuilder) DIDMarkerType(iso.std.iso_iec._24727.tech.schema.DIDMarkerType) DifferentialIdentityType(iso.std.iso_iec._24727.tech.schema.DifferentialIdentityType) PinCompareMarkerType(iso.std.iso_iec._24727.tech.schema.PinCompareMarkerType) DIDInfoType(iso.std.iso_iec._24727.tech.schema.DIDInfoType) CryptokiException(org.openecard.mdlw.sal.exceptions.CryptokiException) AccessRuleType(iso.std.iso_iec._24727.tech.schema.AccessRuleType)

Example 2 with DifferentialIdentityType

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

the class AndroidMarshaller method parseDifferentialIdentity.

private DifferentialIdentityType parseDifferentialIdentity(XmlPullParser parser) throws XmlPullParserException, IOException {
    DifferentialIdentityType differentialIdentity = new DifferentialIdentityType();
    int eventType;
    do {
        parser.next();
        eventType = parser.getEventType();
        if (eventType == XmlPullParser.START_TAG) {
            if (parser.getName().equals("DIDName")) {
                differentialIdentity.setDIDName(parser.nextText());
            } else if (parser.getName().equals("LocalDIDName")) {
                InternationalStringType internationalString = new InternationalStringType();
                internationalString.setLang(parser.getAttributeValue("http://www.w3.org/XML/1998/namespace", "lang"));
                internationalString.setValue(parser.nextText());
                differentialIdentity.getLocalDIDName().add(internationalString);
            } else if (parser.getName().equals("DIDProtocol")) {
                differentialIdentity.setDIDProtocol(parser.nextText());
            } else if (parser.getName().equals("DIDMarker")) {
                differentialIdentity.setDIDMarker(this.parseDIDMarkerType(parser));
            } else if (parser.getName().equals("DIDScope")) {
                differentialIdentity.setDIDScope(DIDScopeType.fromValue(parser.nextText()));
            } else {
                throw new IOException(parser.getName() + " not yet implemented");
            }
        }
    } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("DifferentialIdentity")));
    return differentialIdentity;
}
Also used : DifferentialIdentityType(iso.std.iso_iec._24727.tech.schema.DifferentialIdentityType) IOException(java.io.IOException) InternationalStringType(oasis.names.tc.dss._1_0.core.schema.InternationalStringType)

Example 3 with DifferentialIdentityType

use of iso.std.iso_iec._24727.tech.schema.DifferentialIdentityType 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 4 with DifferentialIdentityType

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

the class CIFCreator method createCryptoDID.

private DIDInfoType createCryptoDID(List<MwCertificate> mwCerts, SignatureAlgorithms sigalg) throws WSMarshallerException, CryptokiException {
    LOG.debug("Creating Crypto DID object.");
    DIDInfoType di = new DIDInfoType();
    String keyLabel = mwCerts.get(0).getLabel();
    // create differential identity
    DifferentialIdentityType did = new DifferentialIdentityType();
    di.setDifferentialIdentity(did);
    String didName = keyLabel + "_" + mwCerts.get(0).getLabel() + "_" + sigalg.getJcaAlg();
    LOG.debug("DIDName: {}", didName);
    did.setDIDName(didName);
    did.setDIDProtocol("urn:oid:1.3.162.15480.3.0.25");
    did.setDIDScope(DIDScopeType.LOCAL);
    // create crypto marker
    CryptoMarkerBuilder markerBuilder = new CryptoMarkerBuilder();
    // add AlgorithmInfo
    AlgorithmInfoType algInfo = new AlgorithmInfoType();
    algInfo.setAlgorithm(sigalg.getJcaAlg());
    AlgorithmIdentifierType algIdentifier = new AlgorithmIdentifierType();
    algIdentifier.setAlgorithm(sigalg.getAlgId());
    algInfo.setAlgorithmIdentifier(algIdentifier);
    algInfo.getSupportedOperations().add("Compute-signature");
    markerBuilder.setAlgInfo(algInfo);
    markerBuilder.setLegacyKeyname(keyLabel);
    // add certificates
    for (MwCertificate nextCert : mwCerts) {
        try {
            CertificateRefType certRef = new CertificateRefType();
            certRef.setDataSetName(nextCert.getLabel());
            markerBuilder.getCertRefs().add(certRef);
        } catch (CryptokiException ex) {
            LOG.warn("Certificate chain is not complete.");
            break;
        }
    }
    // wrap crypto marker and add to parent
    CryptoMarkerType marker = markerBuilder.build();
    DIDMarkerType markerWrapper = new DIDMarkerType();
    markerWrapper.setCryptoMarker(marker);
    did.setDIDMarker(markerWrapper);
    // create acl
    AccessControlListType acl = new AccessControlListType();
    di.setDIDACL(acl);
    List<AccessRuleType> rules = acl.getAccessRule();
    rules.add(createRuleTrue(AuthorizationServiceActionName.ACL_LIST));
    rules.add(createRuleTrue(DifferentialIdentityServiceActionName.DID_GET));
    // create sign rule with PIN reference
    AccessRuleType signRule = createRuleTrue(CryptographicServiceActionName.SIGN);
    signRule.setSecurityCondition(createDidCond(PIN_NAME));
    rules.add(signRule);
    return di;
}
Also used : CryptoMarkerBuilder(org.openecard.mdlw.sal.didfactory.CryptoMarkerBuilder) AccessControlListType(iso.std.iso_iec._24727.tech.schema.AccessControlListType) CryptoMarkerType(iso.std.iso_iec._24727.tech.schema.CryptoMarkerType) CertificateRefType(iso.std.iso_iec._24727.tech.schema.CertificateRefType) DIDMarkerType(iso.std.iso_iec._24727.tech.schema.DIDMarkerType) DifferentialIdentityType(iso.std.iso_iec._24727.tech.schema.DifferentialIdentityType) DIDInfoType(iso.std.iso_iec._24727.tech.schema.DIDInfoType) AlgorithmInfoType(iso.std.iso_iec._24727.tech.schema.AlgorithmInfoType) CryptokiException(org.openecard.mdlw.sal.exceptions.CryptokiException) AlgorithmIdentifierType(iso.std.iso_iec._24727.tech.schema.AlgorithmIdentifierType) AccessRuleType(iso.std.iso_iec._24727.tech.schema.AccessRuleType)

Aggregations

DifferentialIdentityType (iso.std.iso_iec._24727.tech.schema.DifferentialIdentityType)4 DIDInfoType (iso.std.iso_iec._24727.tech.schema.DIDInfoType)3 AccessControlListType (iso.std.iso_iec._24727.tech.schema.AccessControlListType)2 AccessRuleType (iso.std.iso_iec._24727.tech.schema.AccessRuleType)2 DIDMarkerType (iso.std.iso_iec._24727.tech.schema.DIDMarkerType)2 IOException (java.io.IOException)2 CryptokiException (org.openecard.mdlw.sal.exceptions.CryptokiException)2 AlgorithmIdentifierType (iso.std.iso_iec._24727.tech.schema.AlgorithmIdentifierType)1 AlgorithmInfoType (iso.std.iso_iec._24727.tech.schema.AlgorithmInfoType)1 CardApplicationType (iso.std.iso_iec._24727.tech.schema.CardApplicationType)1 CardInfo (iso.std.iso_iec._24727.tech.schema.CardInfo)1 CertificateRefType (iso.std.iso_iec._24727.tech.schema.CertificateRefType)1 CryptoMarkerType (iso.std.iso_iec._24727.tech.schema.CryptoMarkerType)1 DataSetInfoType (iso.std.iso_iec._24727.tech.schema.DataSetInfoType)1 KeyRefType (iso.std.iso_iec._24727.tech.schema.KeyRefType)1 PasswordAttributesType (iso.std.iso_iec._24727.tech.schema.PasswordAttributesType)1 PinCompareMarkerType (iso.std.iso_iec._24727.tech.schema.PinCompareMarkerType)1 InternationalStringType (oasis.names.tc.dss._1_0.core.schema.InternationalStringType)1 CryptoMarkerType (org.openecard.crypto.common.sal.did.CryptoMarkerType)1 CryptoMarkerBuilder (org.openecard.mdlw.sal.didfactory.CryptoMarkerBuilder)1