use of iso.std.iso_iec._24727.tech.schema.Connect in project open-ecard by ecsec.
the class CardRecognitionImpl method connect.
private byte[] connect(byte[] ctx, String ifdName, BigInteger slot) throws RecognitionException {
Connect c = new Connect();
c.setContextHandle(ctx);
c.setIFDName(ifdName);
c.setSlot(slot);
ConnectResponse r = (ConnectResponse) env.getDispatcher().safeDeliver(c);
checkResult(r.getResult());
waitForExclusiveCardAccess(r.getSlotHandle(), ifdName);
return r.getSlotHandle();
}
use of iso.std.iso_iec._24727.tech.schema.Connect in project open-ecard by ecsec.
the class TinySAL method cardApplicationConnect.
/**
* The CardApplicationConnect function establishes an unauthenticated connection between the client
* application and the card application.
* See BSI-TR-03112-4, version 1.1.2, section 3.2.1.
*
* @param request CardApplicationConnect
* @return CardApplicationConnectResponse
*/
@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.");
/*
* [TR-03112-4] If the provided path fragments are valid for more than one card application
* the eCard-API-Framework SHALL return any of the possible choices.
*/
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);
// Connect to the card
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);
// Select the card application
CardCommandAPDU select;
// TODO: proper determination of path, file and app id
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());
// reset the ef FCP
cardStateEntry.unsetFCPOfSelectedEF();
states.addEntry(cardStateEntry);
response.setConnectionHandle(cardStateEntry.handleCopy());
response.getConnectionHandle().setCardApplication(applicationID);
} catch (ECardException e) {
response.setResult(e.getResult());
}
return response;
}
use of iso.std.iso_iec._24727.tech.schema.Connect in project open-ecard by ecsec.
the class TinySALTest method testDsiCreate.
/**
* Test of dsiCreate method, of class TinySAL.
*/
@Test(enabled = TESTS_ENABLED)
public void testDsiCreate() {
System.out.println("dsiCreate");
// get path to esign
CardApplicationPath cardApplicationPath = new CardApplicationPath();
CardApplicationPathType cardApplicationPathType = new CardApplicationPathType();
cardApplicationPathType.setCardApplication(appIdentifier_ESIGN);
cardApplicationPath.setCardAppPathRequest(cardApplicationPathType);
CardApplicationPathResponse cardApplicationPathResponse = instance.cardApplicationPath(cardApplicationPath);
// connect to esign
CardApplicationConnect cardApplicationConnect = new CardApplicationConnect();
cardApplicationConnect.setCardApplicationPath(cardApplicationPathResponse.getCardAppPathResultSet().getCardApplicationPathResult().get(0));
CardApplicationConnectResponse result = instance.cardApplicationConnect(cardApplicationConnect);
assertEquals(ECardConstants.Major.OK, result.getResult().getResultMajor());
// list datasets of esign
DataSetList dataSetList = new DataSetList();
dataSetList.setConnectionHandle(result.getConnectionHandle());
DataSetListResponse dataSetListResponse = instance.dataSetList(dataSetList);
Assert.assertTrue(dataSetListResponse.getDataSetNameList().getDataSetName().size() > 0);
assertEquals(ECardConstants.Major.OK, dataSetListResponse.getResult().getResultMajor());
String dataSetName = dataSetListResponse.getDataSetNameList().getDataSetName().get(0);
byte[] dsiContent = { (byte) 0x74, (byte) 0x65, (byte) 0x73, (byte) 0x74 };
String dsiName = "DsiTest";
PathType dsiPath = new PathType();
byte[] dsiEF = { (byte) 0x03, (byte) 0x00 };
dsiPath.setEfIdOrPath(dsiEF);
DSICreate parameters = new DSICreate();
parameters.setConnectionHandle(result.getConnectionHandle());
parameters.setDSIContent(dsiContent);
parameters.setDSIName(dsiName);
DSICreateResponse resultDSICreate = instance.dsiCreate(parameters);
assertEquals(ECardConstants.Major.OK, resultDSICreate.getResult().getResultMajor());
// list DSIs of DataSetName
DSIList parametersDSI = new DSIList();
parametersDSI.setConnectionHandle(result.getConnectionHandle());
DSIListResponse resultDSIList = instance.dsiList(parametersDSI);
assertEquals(ECardConstants.Major.OK, resultDSIList.getResult().getResultMajor());
// try to find new DSI
Iterator<String> it = resultDSIList.getDSINameList().getDSIName().iterator();
boolean dsiFound = false;
while (it.hasNext()) {
String val = it.next();
if (val.equals(dsiName)) {
dsiFound = true;
}
}
assertTrue(dsiFound);
}
use of iso.std.iso_iec._24727.tech.schema.Connect in project open-ecard by ecsec.
the class TinySALTest method testCardApplicationCreate.
/**
* Test of cardApplicationCreate method, of class TinySAL.
*/
@Test(enabled = TESTS_ENABLED)
public void testCardApplicationCreate() {
System.out.println("cardApplicationCreate");
Set<CardStateEntry> cHandles = states.getMatchingEntries(new ConnectionHandleType());
byte[] appName = { (byte) 0x74, (byte) 0x65, (byte) 0x73, (byte) 0x74 };
CardApplicationCreate parameters = new CardApplicationCreate();
parameters.setConnectionHandle(cHandles.iterator().next().handleCopy());
parameters.setCardApplicationName(appName);
AccessControlListType cardApplicationACL = new AccessControlListType();
parameters.setCardApplicationACL(cardApplicationACL);
CardApplicationCreateResponse result = instance.cardApplicationCreate(parameters);
assertEquals(ECardConstants.Major.OK, result.getResult().getResultMajor());
// get path to esign
CardApplicationPath cardApplicationPath = new CardApplicationPath();
CardApplicationPathType cardApplicationPathType = new CardApplicationPathType();
cardApplicationPathType.setCardApplication(appIdentifier_ESIGN);
cardApplicationPath.setCardAppPathRequest(cardApplicationPathType);
CardApplicationPathResponse cardApplicationPathResponse = instance.cardApplicationPath(cardApplicationPath);
// connect to esign
CardApplicationConnect cardApplicationConnect = new CardApplicationConnect();
cardApplicationConnect.setCardApplicationPath(cardApplicationPathResponse.getCardAppPathResultSet().getCardApplicationPathResult().get(0));
CardApplicationConnectResponse resultConnect = instance.cardApplicationConnect(cardApplicationConnect);
assertEquals(ECardConstants.Major.OK, resultConnect.getResult().getResultMajor());
CardApplicationList cardApplicationList = new CardApplicationList();
cardApplicationList.setConnectionHandle(cHandles.iterator().next().handleCopy());
CardApplicationListResponse cardApplicationListResponse = instance.cardApplicationList(cardApplicationList);
Iterator<byte[]> it = cardApplicationListResponse.getCardApplicationNameList().getCardApplicationName().iterator();
boolean appFound = false;
try {
while (it.hasNext()) {
byte[] val = it.next();
if (Arrays.equals(val, appName)) {
appFound = true;
}
}
assertTrue(appFound);
} catch (Exception e) {
assertTrue(appFound);
System.out.println(e);
}
}
use of iso.std.iso_iec._24727.tech.schema.Connect in project open-ecard by ecsec.
the class TinySALTest method testDidList.
/**
* Test of didList method, of class TinySAL.
*/
@Test(enabled = TESTS_ENABLED)
public void testDidList() {
System.out.println("didList");
// get path to esign
CardApplicationPath cardApplicationPath = new CardApplicationPath();
CardApplicationPathType cardApplicationPathType = new CardApplicationPathType();
cardApplicationPathType.setCardApplication(appIdentifier_ESIGN);
cardApplicationPath.setCardAppPathRequest(cardApplicationPathType);
CardApplicationPathResponse cardApplicationPathResponse = instance.cardApplicationPath(cardApplicationPath);
// connect to esign
CardApplicationConnect cardApplicationConnect = new CardApplicationConnect();
cardApplicationConnect.setCardApplicationPath(cardApplicationPathResponse.getCardAppPathResultSet().getCardApplicationPathResult().get(0));
CardApplicationConnectResponse result = instance.cardApplicationConnect(cardApplicationConnect);
assertEquals(ECardConstants.Major.OK, result.getResult().getResultMajor());
DIDList didList = new DIDList();
didList.setConnectionHandle(result.getConnectionHandle());
DIDQualifierType didQualifier = new DIDQualifierType();
didQualifier.setApplicationIdentifier(appIdentifier_ESIGN);
didQualifier.setObjectIdentifier("urn:oid:1.3.162.15480.3.0.25");
didQualifier.setApplicationFunction("Compute-signature");
didList.setFilter(didQualifier);
DIDListResponse didListResponse = instance.didList(didList);
Assert.assertTrue(didListResponse.getDIDNameList().getDIDName().size() > 0);
assertEquals(ECardConstants.Major.OK, result.getResult().getResultMajor());
// get path to root
cardApplicationPath = new CardApplicationPath();
cardApplicationPathType = new CardApplicationPathType();
cardApplicationPathType.setCardApplication(appIdentifier_ROOT);
cardApplicationPath.setCardAppPathRequest(cardApplicationPathType);
cardApplicationPathResponse = instance.cardApplicationPath(cardApplicationPath);
// connect to root
cardApplicationConnect = new CardApplicationConnect();
cardApplicationConnect.setCardApplicationPath(cardApplicationPathResponse.getCardAppPathResultSet().getCardApplicationPathResult().get(0));
cardApplicationConnect.getCardApplicationPath().setCardApplication(appIdentifier_ROOT);
result = instance.cardApplicationConnect(cardApplicationConnect);
assertEquals(ECardConstants.Major.OK, result.getResult().getResultMajor());
didList = new DIDList();
didList.setConnectionHandle(result.getConnectionHandle());
didQualifier = new DIDQualifierType();
didQualifier.setApplicationIdentifier(appIdentifier_ROOT);
didQualifier.setObjectIdentifier("urn:oid:1.3.162.15480.3.0.25");
didQualifier.setApplicationFunction("Compute-signature");
didList.setFilter(didQualifier);
didListResponse = instance.didList(didList);
// we expect 0 because of the filter
Assert.assertEquals(didListResponse.getDIDNameList().getDIDName().size(), 0);
assertEquals(ECardConstants.Major.OK, didListResponse.getResult().getResultMajor());
// test null connectionhandle
didList = new DIDList();
didList.setConnectionHandle(null);
didListResponse = instance.didList(didList);
assertEquals(ECardConstants.Major.ERROR, didListResponse.getResult().getResultMajor());
assertEquals(ECardConstants.Minor.App.INCORRECT_PARM, didListResponse.getResult().getResultMinor());
// test invalid connectionhandle
didList = new DIDList();
didList.setConnectionHandle(result.getConnectionHandle());
didList.getConnectionHandle().setIFDName("invalid");
didListResponse = instance.didList(didList);
assertEquals(ECardConstants.Major.ERROR, didListResponse.getResult().getResultMajor());
assertEquals(ECardConstants.Minor.App.INCORRECT_PARM, didListResponse.getResult().getResultMinor());
}
Aggregations