TinySAL implements SAL { @Publish @Override public DSIReadResponse dsiRead(DSIRead request) { DSIReadResponse response = WSHelper.makeResponse(DSIReadResponse.class, WSHelper.makeResultOK()); try { ConnectionHandleType connectionHandle = SALUtils.getConnectionHandle(request); CardStateEntry cardStateEntry = SALUtils.getCardStateEntry(states, connectionHandle); byte[] applicationID = cardStateEntry.getCurrentCardApplication().getApplicationIdentifier(); String dsiName = request.getDSIName(); byte[] slotHandle = connectionHandle.getSlotHandle(); Assert.assertIncorrectParameter(dsiName, "The parameter DSIName is empty."); Assert.securityConditionDataSet(cardStateEntry, applicationID, dsiName, NamedDataServiceActionName.DSI_READ); if (cardStateEntry.getFCPOfSelectedEF() == null) { throw new PrerequisitesNotSatisfiedException("No DataSet to read selected."); } CardInfoWrapper cardInfoWrapper = cardStateEntry.getInfo(); DataSetInfoType dataSetInfo = cardInfoWrapper.getDataSetByDsiName(dsiName); if (dataSetInfo == null) { dataSetInfo = cardInfoWrapper.getDataSetByName(dsiName); if (dataSetInfo != null) { if (!cardStateEntry.getFCPOfSelectedEF().getFileIdentifiers().isEmpty()) { byte[] path = dataSetInfo.getDataSetPath().getEfIdOrPath(); byte[] fid = Arrays.copyOfRange(path, path.length - 2, path.length); if (!Arrays.equals(fid, cardStateEntry.getFCPOfSelectedEF().getFileIdentifiers().get(0))) { String msg = "Wrong DataSet for reading the DSI " + dsiName + " is selected."; throw new PrerequisitesNotSatisfiedException(msg); } } byte[] fileContent = CardUtils.readFile(cardStateEntry.getFCPOfSelectedEF(), env.getDispatcher(), slotHandle); response.setDSIContent(fileContent); } else { String msg = "The given DSIName does not related to any know DSI or DataSet."; throw new IncorrectParameterException(msg); } } else { byte[] dataSetPath = dataSetInfo.getDataSetPath().getEfIdOrPath(); byte[] dataSetFID = new byte[] {dataSetPath[dataSetPath.length - 2], dataSetPath[dataSetPath.length - 1]}; if (Arrays.equals(dataSetFID, cardStateEntry.getFCPOfSelectedEF().getFileIdentifiers().get(0))) { DSIType dsi = cardInfoWrapper.getDSIbyName(dsiName); PathType dsiPath = dsi.getDSIPath(); if (dsiPath.getTagRef() != null) { TagRef tagReference = dsiPath.getTagRef(); byte[] tag = tagReference.getTag(); GetData getDataRequest; if (tag.length == 2) { getDataRequest = new GetData(GetData.INS_DATA, tag[0], tag[1]); CardResponseAPDU cardResponse = getDataRequest.transmit(env.getDispatcher(), slotHandle, Collections.EMPTY_LIST); byte[] responseData = cardResponse.getData(); while (cardResponse.getTrailer()[0] == (byte) 0x61) { GetResponse allData = new GetResponse(); cardResponse = allData.transmit(env.getDispatcher(), slotHandle, Collections.EMPTY_LIST); responseData = ByteUtils.concatenate(responseData, cardResponse.getData()); } response.setDSIContent(responseData); } else if (tag.length == 1) { getDataRequest = new GetData(GetData.INS_DATA, GetData.SIMPLE_TLV, tag[0]); CardResponseAPDU cardResponse = getDataRequest.transmit(env.getDispatcher(), slotHandle, Collections.EMPTY_LIST); byte[] responseData = cardResponse.getData(); if (Arrays.equals(cardResponse.getTrailer(), new byte[] {(byte) 0x6A, (byte) 0x88})) { getDataRequest = new GetData(GetData.INS_DATA, GetData.BER_TLV_ONE_BYTE, tag[0]); cardResponse = getDataRequest.transmit(env.getDispatcher(), slotHandle, Collections.EMPTY_LIST); responseData = cardResponse.getData(); } while (cardResponse.getTrailer()[0] == (byte) 0x61) { GetResponse allData = new GetResponse(); cardResponse = allData.transmit(env.getDispatcher(), slotHandle, Collections.EMPTY_LIST); responseData = ByteUtils.concatenate(responseData, cardResponse.getData()); } response.setDSIContent(responseData); } } else if (dsiPath.getIndex() != null) { byte[] index = dsiPath.getIndex(); byte[] length = dsiPath.getLength(); List<byte[]> allowedResponse = new ArrayList<>(); allowedResponse.add(new byte[]{(byte) 0x90, (byte) 0x00}); allowedResponse.add(new byte[]{(byte) 0x62, (byte) 0x82}); if (cardStateEntry.getFCPOfSelectedEF().getDataElements().isLinear()) { ReadRecord readRecord = new ReadRecord(index[0]); CardResponseAPDU cardResponse = readRecord.transmit(env.getDispatcher(), slotHandle, allowedResponse); response.setDSIContent(cardResponse.getData()); } else { ReadBinary readBinary = new ReadBinary(ByteUtils.toShort(index), ByteUtils.toShort(length)); CardResponseAPDU cardResponse = readBinary.transmit(env.getDispatcher(), slotHandle, allowedResponse); response.setDSIContent(cardResponse.getData()); } } else { String msg = "The currently selected data set does not contain the DSI with the name " + dsiName; throw new PrerequisitesNotSatisfiedException(msg); } } } } catch (ECardException e) { response.setResult(e.getResult()); } catch (Exception e) { LOG.error(e.getMessage(), e); throwThreadKillException(e); response.setResult(WSHelper.makeResult(e)); } return response; } TinySAL(Environment env, CardStateMap states); void setAddonManager(AddonManager manager); @Override InitializeResponse initialize(Initialize request); @Override TerminateResponse terminate(Terminate request); @Override CardApplicationPathResponse cardApplicationPath(CardApplicationPath request); @Override CardApplicationConnectResponse cardApplicationConnect(CardApplicationConnect request); @Override CardApplicationSelectResponse cardApplicationSelect(CardApplicationSelect request); @Override CardApplicationDisconnectResponse cardApplicationDisconnect(CardApplicationDisconnect request); @Publish @Override CardApplicationStartSessionResponse cardApplicationStartSession(CardApplicationStartSession request); @Publish @Override CardApplicationEndSessionResponse cardApplicationEndSession(CardApplicationEndSession request); @Publish @Override CardApplicationListResponse cardApplicationList(CardApplicationList request); @Override CardApplicationCreateResponse cardApplicationCreate(CardApplicationCreate request); @Override CardApplicationDeleteResponse cardApplicationDelete(CardApplicationDelete request); @Publish @Override CardApplicationServiceListResponse cardApplicationServiceList(CardApplicationServiceList request); @Override CardApplicationServiceCreateResponse cardApplicationServiceCreate(CardApplicationServiceCreate request); @Override CardApplicationServiceLoadResponse cardApplicationServiceLoad(CardApplicationServiceLoad request); @Override CardApplicationServiceDeleteResponse cardApplicationServiceDelete(CardApplicationServiceDelete request); @Publish @Override CardApplicationServiceDescribeResponse cardApplicationServiceDescribe(CardApplicationServiceDescribe request); @Override ExecuteActionResponse executeAction(ExecuteAction request); @Publish @Override DataSetListResponse dataSetList(DataSetList request); @Override DataSetCreateResponse dataSetCreate(DataSetCreate request); @Publish @Override DataSetSelectResponse dataSetSelect(DataSetSelect request); @Override DataSetDeleteResponse dataSetDelete(DataSetDelete request); @Publish @Override DSIListResponse dsiList(DSIList request); @Override DSICreateResponse dsiCreate(DSICreate request); @Override DSIDeleteResponse dsiDelete(DSIDelete request); @Publish @Override DSIWriteResponse dsiWrite(DSIWrite request); @Publish @Override DSIReadResponse dsiRead(DSIRead request); @Publish @Override EncipherResponse encipher(Encipher request); @Override DecipherResponse decipher(Decipher request); @Publish @Override GetRandomResponse getRandom(GetRandom request); @Publish @Override HashResponse hash(Hash request); @Override SignResponse sign(Sign request); @Override VerifySignatureResponse verifySignature(VerifySignature request); @Override VerifyCertificateResponse verifyCertificate(VerifyCertificate request); @Publish @Override DIDListResponse didList(DIDList request); @Override DIDCreateResponse didCreate(DIDCreate request); @Publish @Override DIDGetResponse didGet(DIDGet request); @Override DIDUpdateResponse didUpdate(DIDUpdate request); @Override DIDDeleteResponse didDelete(DIDDelete request); @Publish @Override DIDAuthenticateResponse didAuthenticate(DIDAuthenticate request); @Publish @Override ACLListResponse aclList(ACLList request); @Override ACLModifyResponse aclModify(ACLModify request); void setGUI(UserConsent uc);  }
@Test(enabled = TESTS_ENABLED) public void testDsiRead() { System.out.println("dsiRead"); CardApplicationPath cardApplicationPath = new CardApplicationPath(); CardApplicationPathType cardApplicationPathType = new CardApplicationPathType(); cardApplicationPathType.setCardApplication(appIdentifier_ESIGN); cardApplicationPath.setCardAppPathRequest(cardApplicationPathType); CardApplicationPathResponse cardApplicationPathResponse = instance.cardApplicationPath(cardApplicationPath); CardApplicationConnect cardApplicationConnect = new CardApplicationConnect(); cardApplicationConnect.setCardApplicationPath(cardApplicationPathResponse.getCardAppPathResultSet().getCardApplicationPathResult().get(0)); CardApplicationConnectResponse result = instance.cardApplicationConnect(cardApplicationConnect); assertEquals(ECardConstants.Major.OK, result.getResult().getResultMajor()); assertEquals(appIdentifier_ESIGN, result.getConnectionHandle().getCardApplication()); DSIRead dsiRead = new DSIRead(); dsiRead.setConnectionHandle(result.getConnectionHandle()); dsiRead.setDSIName("EF.C.CH.AUT"); DSIReadResponse dsiReadResponse = instance.dsiRead(dsiRead); System.out.println(dsiReadResponse.getResult().getResultMinor()); assertEquals(ECardConstants.Major.OK, dsiReadResponse.getResult().getResultMajor()); System.out.println(dsiReadResponse.getResult().getResultMinor()); assertTrue(dsiReadResponse.getDSIContent().length>0); dsiRead = new DSIRead(); dsiRead.setConnectionHandle(null); dsiRead.setDSIName("EF.C.CH.AUT"); dsiReadResponse = instance.dsiRead(dsiRead); assertEquals(ECardConstants.Major.ERROR, dsiReadResponse.getResult().getResultMajor()); assertEquals(ECardConstants.Minor.App.INCORRECT_PARM, dsiReadResponse.getResult().getResultMinor()); dsiRead = new DSIRead(); dsiRead.setConnectionHandle(result.getConnectionHandle()); dsiRead.setDSIName(null); dsiReadResponse = instance.dsiRead(dsiRead); assertEquals(ECardConstants.Major.ERROR, dsiReadResponse.getResult().getResultMajor()); assertEquals(ECardConstants.Minor.App.INCORRECT_PARM, dsiReadResponse.getResult().getResultMinor()); dsiRead = new DSIRead(); dsiRead.setConnectionHandle(result.getConnectionHandle()); dsiRead.setDSIName("INVALID"); dsiReadResponse = instance.dsiRead(dsiRead); assertEquals(ECardConstants.Major.ERROR, dsiReadResponse.getResult().getResultMajor()); assertEquals(ECardConstants.Minor.SAL.NAMED_ENTITY_NOT_FOUND, dsiReadResponse.getResult().getResultMinor()); dsiRead = new DSIRead(); dsiRead.setConnectionHandle(result.getConnectionHandle()); dsiRead.setDSIName("EF.C.CH.AUTN"); dsiReadResponse = instance.dsiRead(dsiRead); assertEquals(ECardConstants.Major.ERROR, dsiReadResponse.getResult().getResultMajor()); assertEquals(ECardConstants.Minor.SAL.SECURITY_CONDITION_NOT_SATISFIED, dsiReadResponse.getResult().getResultMinor()); dsiRead = new DSIRead(); dsiRead.setConnectionHandle(result.getConnectionHandle()); dsiRead.getConnectionHandle().setIFDName("invalid"); dsiRead.setDSIName(null); dsiReadResponse = instance.dsiRead(dsiRead); assertEquals(ECardConstants.Major.ERROR, dsiReadResponse.getResult().getResultMajor()); assertEquals(ECardConstants.Minor.App.INCORRECT_PARM, dsiReadResponse.getResult().getResultMinor()); }