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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations