TinySAL implements SAL { @Override public CardApplicationConnectResponse cardApplicationConnect(CardApplicationConnect request) { CardApplicationConnectResponse response = WSHelper.makeResponse(CardApplicationConnectResponse.class, WSHelper.makeResultOK()); try { CardApplicationPathType cardAppPath = request.getCardApplicationPath(); Assert.assertIncorrectParameter(cardAppPath, "The parameter CardAppPathRequest is empty."); Set<CardStateEntry> cardStateEntrySet = states.getMatchingEntries(cardAppPath, false); Assert.assertIncorrectParameter(cardStateEntrySet, "The given ConnectionHandle is invalid."); CardStateEntry cardStateEntry = cardStateEntrySet.iterator().next(); byte[] applicationID = cardAppPath.getCardApplication(); if (applicationID == null) { if (cardStateEntry.getImplicitlySelectedApplicationIdentifier() != null) { applicationID = cardStateEntry.getImplicitlySelectedApplicationIdentifier(); } else { applicationID = MF; } } Assert.securityConditionApplication(cardStateEntry, applicationID, ConnectionServiceActionName.CARD_APPLICATION_CONNECT); ConnectionHandleType handle = cardStateEntry.handleCopy(); cardStateEntry = cardStateEntry.derive(handle); Connect connect = new Connect(); connect.setContextHandle(handle.getContextHandle()); connect.setIFDName(handle.getIFDName()); connect.setSlot(handle.getSlotIndex()); ConnectResponse connectResponse = (ConnectResponse) env.getDispatcher().safeDeliver(connect); WSHelper.checkResult(connectResponse); CardCommandAPDU select; if (applicationID.length == 2) { select = new Select.File(applicationID); List<byte[]> responses = new ArrayList<>(); responses.add(TrailerConstants.Success.OK()); responses.add(TrailerConstants.Error.WRONG_P1_P2()); CardResponseAPDU resp = select.transmit(env.getDispatcher(), connectResponse.getSlotHandle(), responses); if (Arrays.equals(resp.getTrailer(), TrailerConstants.Error.WRONG_P1_P2())) { select = new Select.AbsolutePath(applicationID); select.transmit(env.getDispatcher(), connectResponse.getSlotHandle()); } } else { select = new Select.Application(applicationID); select.transmit(env.getDispatcher(), connectResponse.getSlotHandle()); } cardStateEntry.setCurrentCardApplication(applicationID); cardStateEntry.setSlotHandle(connectResponse.getSlotHandle()); cardStateEntry.unsetFCPOfSelectedEF(); states.addEntry(cardStateEntry); response.setConnectionHandle(cardStateEntry.handleCopy()); response.getConnectionHandle().setCardApplication(applicationID); } catch (ECardException e) { response.setResult(e.getResult()); } 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 testCardApplicationConnect() { System.out.println("cardApplicationConnect"); 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()); cardApplicationConnect = new CardApplicationConnect(); CardApplicationPathType wrongCardApplicationPath = cardApplicationPathResponse.getCardAppPathResultSet().getCardApplicationPathResult().get(0); wrongCardApplicationPath.setCardApplication(new byte[] { 0x12, 0x23, 0x34 }); cardApplicationConnect.setCardApplicationPath(wrongCardApplicationPath); result = instance.cardApplicationConnect(cardApplicationConnect); assertEquals(ECardConstants.Major.ERROR, result.getResult().getResultMajor()); assertEquals(ECardConstants.Minor.App.INCORRECT_PARM, result.getResult().getResultMinor()); cardApplicationConnect = new CardApplicationConnect(); cardApplicationConnect.setCardApplicationPath(null); result = instance.cardApplicationConnect(cardApplicationConnect); assertEquals(ECardConstants.Major.ERROR, result.getResult().getResultMajor()); assertEquals(ECardConstants.Minor.App.INCORRECT_PARM, result.getResult().getResultMinor()); }