Search in sources :

Example 11 with DataSetInfoType

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

the class TinySAL method dsiList.

/**
 * The function DSIList supplies the list of the DSI (Data Structure for Interoperability) which exist in the
 * selected data set.
 * See BSI-TR-03112-4, version 1.1.2, section 3.4.5. <br>
 * <br>
 * Prerequisites: <br>
 * - a connection to a card application has been established <br>
 * - a data set has been selected <br>
 *
 * @param request DSIList
 * @return DSIListResponse
 */
@Publish
@Override
public DSIListResponse dsiList(DSIList request) {
    DSIListResponse response = WSHelper.makeResponse(DSIListResponse.class, WSHelper.makeResultOK());
    try {
        ConnectionHandleType connectionHandle = SALUtils.getConnectionHandle(request);
        CardStateEntry cardStateEntry = SALUtils.getCardStateEntry(states, connectionHandle, false);
        CardInfoWrapper cardInfoWrapper = cardStateEntry.getInfo();
        byte[] cardApplicationID = connectionHandle.getCardApplication();
        if (cardStateEntry.getFCPOfSelectedEF() == null) {
            throw new PrerequisitesNotSatisfiedException("No EF selected.");
        }
        DataSetInfoType dataSet = cardInfoWrapper.getDataSetByFid(cardStateEntry.getFCPOfSelectedEF().getFileIdentifiers().get(0));
        Assert.securityConditionDataSet(cardStateEntry, cardApplicationID, dataSet.getDataSetName(), NamedDataServiceActionName.DSI_LIST);
        DSINameListType dsiNameList = new DSINameListType();
        for (DSIType dsi : dataSet.getDSI()) {
            dsiNameList.getDSIName().add(dsi.getDSIName());
        }
        response.setDSINameList(dsiNameList);
    } 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 : DSIListResponse(iso.std.iso_iec._24727.tech.schema.DSIListResponse) ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) ECardException(org.openecard.common.ECardException) CardStateEntry(org.openecard.common.sal.state.CardStateEntry) PrerequisitesNotSatisfiedException(org.openecard.common.sal.exception.PrerequisitesNotSatisfiedException) DSIType(iso.std.iso_iec._24727.tech.schema.DSIType) CardInfoWrapper(org.openecard.common.sal.state.cif.CardInfoWrapper) DataSetInfoType(iso.std.iso_iec._24727.tech.schema.DataSetInfoType) DSINameListType(iso.std.iso_iec._24727.tech.schema.DSINameListType) 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) Publish(org.openecard.common.interfaces.Publish)

Example 12 with DataSetInfoType

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

the class TinySAL method dsiCreate.

/**
 * The DSICreate function creates a DSI (Data Structure for Interoperability) in the currently selected data set.
 * See BSI-TR-03112-4, version 1.1.2, section 3.4.6.
 * <br>
 * <br>
 * Preconditions: <br>
 * - Connection to a card application established via CardApplicationConnect <br>
 * - A data set has been selected with DataSetSelect <br>
 * - The DSI does not exist in the data set. <br>
 *
 * @param request DSICreate
 * @return DSICreateResponse
 */
@Override
public DSICreateResponse dsiCreate(DSICreate request) {
    DSICreateResponse response = WSHelper.makeResponse(DSICreateResponse.class, WSHelper.makeResultOK());
    try {
        ConnectionHandleType connectionHandle = SALUtils.getConnectionHandle(request);
        CardStateEntry cardStateEntry = SALUtils.getCardStateEntry(states, connectionHandle);
        CardInfoWrapper cardInfoWrapper = cardStateEntry.getInfo();
        byte[] cardApplicationID = connectionHandle.getCardApplication();
        byte[] dsiContent = request.getDSIContent();
        Assert.assertIncorrectParameter(dsiContent, "The parameter DSIContent is empty.");
        String dsiName = request.getDSIName();
        Assert.assertIncorrectParameter(dsiName, "The parameter DSIName is empty.");
        DSIType dsi = cardInfoWrapper.getDSIbyName(dsiName);
        if (dsi != null) {
            throw new NameExistsException("There is already an DSI with the name " + dsiName + " in the current EF.");
        }
        byte[] slotHandle = connectionHandle.getSlotHandle();
        if (cardStateEntry.getFCPOfSelectedEF() == null) {
            throw new PrerequisitesNotSatisfiedException("No data set for writing selected.");
        } else {
            DataSetInfoType dataSet = cardInfoWrapper.getDataSetByFid(cardStateEntry.getFCPOfSelectedEF().getFileIdentifiers().get(0));
            Assert.securityConditionDataSet(cardStateEntry, cardApplicationID, dataSet.getDataSetName(), NamedDataServiceActionName.DSI_CREATE);
            DataElements dElements = cardStateEntry.getFCPOfSelectedEF().getDataElements();
            if (dElements.isTransparent()) {
                WriteBinary writeBin = new WriteBinary(WriteBinary.INS_WRITE_BINARY_DATA, (byte) 0x00, (byte) 0x00, dsiContent);
                writeBin.transmit(env.getDispatcher(), slotHandle);
            } else if (dElements.isCyclic()) {
                WriteRecord writeRec = new WriteRecord((byte) 0x00, WriteRecord.WRITE_PREVIOUS, dsiContent);
                writeRec.transmit(env.getDispatcher(), slotHandle);
            } else {
                WriteRecord writeRec = new WriteRecord((byte) 0x00, WriteRecord.WRITE_LAST, dsiContent);
                writeRec.transmit(env.getDispatcher(), slotHandle);
            }
        }
    } 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) DSICreateResponse(iso.std.iso_iec._24727.tech.schema.DSICreateResponse) CardStateEntry(org.openecard.common.sal.state.CardStateEntry) DSIType(iso.std.iso_iec._24727.tech.schema.DSIType) CardInfoWrapper(org.openecard.common.sal.state.cif.CardInfoWrapper) DataElements(org.openecard.common.tlv.iso7816.DataElements) 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) PrerequisitesNotSatisfiedException(org.openecard.common.sal.exception.PrerequisitesNotSatisfiedException) DataSetInfoType(iso.std.iso_iec._24727.tech.schema.DataSetInfoType) WriteBinary(org.openecard.common.apdu.WriteBinary) WriteRecord(org.openecard.common.apdu.WriteRecord) NameExistsException(org.openecard.common.sal.exception.NameExistsException)

Example 13 with DataSetInfoType

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

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

the class AndroidMarshaller method parseDataSetInfo.

private DataSetInfoType parseDataSetInfo(XmlPullParser parser) throws XmlPullParserException, IOException {
    DataSetInfoType dataSetInfo = new DataSetInfoType();
    int eventType;
    do {
        parser.next();
        eventType = parser.getEventType();
        if (eventType == XmlPullParser.START_TAG) {
            if (parser.getName().equals("RequirementLevel")) {
                dataSetInfo.setRequirementLevel(BasicRequirementsType.fromValue(parser.nextText()));
            } else if (parser.getName().equals("DataSetACL")) {
                dataSetInfo.setDataSetACL(this.parseACL(parser, "DataSetACL"));
            } else if (parser.getName().equals("DataSetName")) {
                dataSetInfo.setDataSetName(parser.nextText());
            } else if (parser.getName().equals("DataSetPath")) {
                dataSetInfo.setDataSetPath(this.parseDataSetPath(parser));
            } else if (parser.getName().equals("LocalDataSetName")) {
                InternationalStringType internationalString = new InternationalStringType();
                internationalString.setLang(parser.getAttributeValue("http://www.w3.org/XML/1998/namespace", "lang"));
                internationalString.setValue(parser.nextText());
                dataSetInfo.getLocalDataSetName().add(internationalString);
            } else {
                throw new IOException(parser.getName() + " not yet implemented");
            }
        }
    } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("DataSetInfo")));
    return dataSetInfo;
}
Also used : DataSetInfoType(iso.std.iso_iec._24727.tech.schema.DataSetInfoType) IOException(java.io.IOException) InternationalStringType(oasis.names.tc.dss._1_0.core.schema.InternationalStringType)

Example 15 with DataSetInfoType

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

the class CardInfoWrapper method getDataSetByFid.

/**
 * The method searches a specific data set by the DSI name.
 *
 * @param fileIdentifier The DSIName which shall be found in a data set.
 * @return A DataSetInfoType object containing which contains the DSI which is referenced by the given dsiName. The
 * method returns NULL if no data set was found.
 */
public DataSetInfoType getDataSetByFid(byte[] fileIdentifier) {
    for (CardApplicationWrapper cardAppWrapper : cardApplications.values()) {
        for (DataSetInfoType dSetInfoWrapper : cardAppWrapper.getDataSetInfoList()) {
            byte[] dataSetPath = dSetInfoWrapper.getDataSetPath().getEfIdOrPath();
            int pathLength = dataSetPath.length;
            if (dataSetPath[pathLength - 2] == fileIdentifier[0] && dataSetPath[pathLength - 1] == fileIdentifier[1]) {
                return dSetInfoWrapper;
            }
        }
    }
    return null;
}
Also used : DataSetInfoType(iso.std.iso_iec._24727.tech.schema.DataSetInfoType)

Aggregations

DataSetInfoType (iso.std.iso_iec._24727.tech.schema.DataSetInfoType)15 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)9 ECardException (org.openecard.common.ECardException)9 ThreadTerminateException (org.openecard.common.ThreadTerminateException)9 IncorrectParameterException (org.openecard.common.sal.exception.IncorrectParameterException)9 NamedEntityNotFoundException (org.openecard.common.sal.exception.NamedEntityNotFoundException)9 UnknownProtocolException (org.openecard.common.sal.exception.UnknownProtocolException)9 CardStateEntry (org.openecard.common.sal.state.CardStateEntry)9 CardInfoWrapper (org.openecard.common.sal.state.cif.CardInfoWrapper)9 AddonNotFoundException (org.openecard.addon.AddonNotFoundException)8 InappropriateProtocolForActionException (org.openecard.common.sal.exception.InappropriateProtocolForActionException)8 NameExistsException (org.openecard.common.sal.exception.NameExistsException)8 PrerequisitesNotSatisfiedException (org.openecard.common.sal.exception.PrerequisitesNotSatisfiedException)8 SecurityConditionNotSatisfiedException (org.openecard.common.sal.exception.SecurityConditionNotSatisfiedException)8 UnknownConnectionHandleException (org.openecard.common.sal.exception.UnknownConnectionHandleException)8 TLVException (org.openecard.common.tlv.TLVException)8 DSIType (iso.std.iso_iec._24727.tech.schema.DSIType)5 Publish (org.openecard.common.interfaces.Publish)5 DIDInfoType (iso.std.iso_iec._24727.tech.schema.DIDInfoType)3 PathType (iso.std.iso_iec._24727.tech.schema.PathType)3