Search in sources :

Example 1 with CardCallTemplateType

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

the class CardCommandTemplateTest method testSymbolFun.

@Test
public void testSymbolFun() throws APDUTemplateException {
    CardCallTemplateType templateType = new CardCallTemplateType();
    templateType.setHeaderTemplate("00a4020c");
    templateType.setDataTemplate("{tlv 0x01 val1}");
    CardCommandTemplate t = new CardCommandTemplate(templateType);
    assertEquals(t.evaluate(CTX).toHexString(), "00A4020C04010200FF");
}
Also used : CardCallTemplateType(iso.std.iso_iec._24727.tech.schema.CardCallTemplateType) Test(org.testng.annotations.Test)

Example 2 with CardCallTemplateType

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

the class SignStep method performLegacySignature.

/**
 * The method performs the SignatureCreation if no standard commands are possible.
 * This method creates a signature with APDUs which are not covered by the methods defined in TR-03112 part 7.
 *
 * @param cryptoMarker A {@link CryptoMarkerType} object containing the information about the creation of a signature
 *   in a legacy way.
 * @param slotHandle A slotHandle identifying the current card.
 * @param templateCTX A Map containing the context data for the evaluation of the template variables. This object
 *   contains per default the message to sign and the {@link TLVFunction}.
 * @return A {@link SignResponse} object containing the signature of the <b>message</b>.
 * @throws APDUTemplateException Thrown if the evaluation of the {@link CardCommandTemplate} failed.
 * @throws APDUException Thrown if one of the commands to execute failed.
 * @throws WSHelper.WSException Thrown if the checkResult method of WSHelper failed.
 */
private SignResponse performLegacySignature(CryptoMarkerType cryptoMarker, ConnectionHandleType connectionHandle, BaseTemplateContext templateCTX) throws APDUTemplateException, APDUException, WSHelper.WSException {
    SignResponse response = WSHelper.makeResponse(SignResponse.class, WSHelper.makeResultOK());
    List<Object> legacyCommands = cryptoMarker.getLegacySignatureGenerationInfo();
    CardCommandAPDU cmdAPDU;
    CardResponseAPDU responseAPDU = null;
    byte[] slotHandle = connectionHandle.getSlotHandle();
    byte[] signedMessage;
    for (Object next : legacyCommands) {
        if (next instanceof CardCallTemplateType) {
            CardCallTemplateType cctt = (CardCallTemplateType) next;
            CardCommandTemplate template = new CardCommandTemplate(cctt);
            cmdAPDU = template.evaluate(templateCTX);
            responseAPDU = cmdAPDU.transmit(dispatcher, slotHandle, Collections.<byte[]>emptyList());
        } else if (next instanceof APICommand) {
            sendAPICommand(connectionHandle, (APICommand) next);
        }
    }
    signedMessage = responseAPDU.getData();
    // check if further response data is available
    while (responseAPDU.getTrailer()[0] == (byte) 0x61) {
        CardCommandAPDU getResponseData = new CardCommandAPDU((byte) 0x00, (byte) 0xC0, (byte) 0x00, (byte) 0x00, responseAPDU.getTrailer()[1]);
        responseAPDU = getResponseData.transmit(dispatcher, slotHandle, Collections.<byte[]>emptyList());
        signedMessage = Arrays.concatenate(signedMessage, responseAPDU.getData());
    }
    if (!Arrays.areEqual(responseAPDU.getTrailer(), new byte[] { (byte) 0x90, (byte) 0x00 })) {
        String minor = SALErrorUtils.getMinor(responseAPDU.getTrailer());
        response.setResult(WSHelper.makeResultError(minor, responseAPDU.getStatusMessage()));
        return response;
    }
    // fix output format
    String outForm = cryptoMarker.getLegacyOutputFormat();
    if (outForm != null) {
        switch(outForm) {
            case "rawRS":
                signedMessage = encodeRawRS(signedMessage);
                break;
            default:
                LOG.warn("Unsupport outputFormat={} specified in LegacySignatureGenerationInfo.", outForm);
        }
    }
    response.setSignature(signedMessage);
    return response;
}
Also used : CardCommandAPDU(org.openecard.common.apdu.common.CardCommandAPDU) CardCallTemplateType(iso.std.iso_iec._24727.tech.schema.CardCallTemplateType) SignResponse(iso.std.iso_iec._24727.tech.schema.SignResponse) CardResponseAPDU(org.openecard.common.apdu.common.CardResponseAPDU) CardCommandTemplate(org.openecard.common.apdu.common.CardCommandTemplate) APICommand(iso.std.iso_iec._24727.tech.schema.LegacySignatureGenerationType.APICommand)

Example 3 with CardCallTemplateType

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

the class CardCommandTemplateTest method testSymbolExp.

@Test
public void testSymbolExp() throws APDUTemplateException {
    CardCallTemplateType templateType = new CardCallTemplateType();
    templateType.setHeaderTemplate("00a4020c");
    templateType.setDataTemplate("{val1}");
    CardCommandTemplate t = new CardCommandTemplate(templateType);
    assertEquals(t.evaluate(CTX).toHexString(), "00A4020C0200FF");
    templateType.setDataTemplate("ab{val1}");
    t = new CardCommandTemplate(templateType);
    assertEquals(t.evaluate(CTX).toHexString(), "00A4020C03AB00FF");
    templateType.setDataTemplate("{val1}ab");
    t = new CardCommandTemplate(templateType);
    assertEquals(t.evaluate(CTX).toHexString(), "00A4020C0300FFAB");
    templateType.setDataTemplate("ba{val1}ab");
    t = new CardCommandTemplate(templateType);
    assertEquals(t.evaluate(CTX).toHexString(), "00A4020C04BA00FFAB");
    templateType.setDataTemplate("ba{val1}ab{val2}cd");
    t = new CardCommandTemplate(templateType);
    assertEquals(t.evaluate(CTX).toHexString(), "00A4020C07BA00FFAB1234CD");
    templateType.setDataTemplate("ba{val1}{val2}cd");
    t = new CardCommandTemplate(templateType);
    assertEquals(t.evaluate(CTX).toHexString(), "00A4020C06BA00FF1234CD");
}
Also used : CardCallTemplateType(iso.std.iso_iec._24727.tech.schema.CardCallTemplateType) Test(org.testng.annotations.Test)

Example 4 with CardCallTemplateType

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

the class CardCommandTemplateTest method testNoExp.

@Test
public void testNoExp() throws APDUTemplateException {
    CardCallTemplateType templateType = new CardCallTemplateType();
    templateType.setHeaderTemplate("00a4020c");
    CardCommandTemplate t = new CardCommandTemplate(templateType);
    assertEquals(t.evaluate(EMPTY_CTX).toHexString(), "00A4020C");
    templateType.setDataTemplate("00ff");
    t = new CardCommandTemplate(templateType);
    assertEquals(t.evaluate(EMPTY_CTX).toHexString(), "00A4020C0200FF");
    templateType.setExpectedLength(BigInteger.valueOf(0xff));
    t = new CardCommandTemplate(templateType);
    assertEquals(t.evaluate(EMPTY_CTX).toHexString(), "00A4020C0200FFFF");
}
Also used : CardCallTemplateType(iso.std.iso_iec._24727.tech.schema.CardCallTemplateType) Test(org.testng.annotations.Test)

Aggregations

CardCallTemplateType (iso.std.iso_iec._24727.tech.schema.CardCallTemplateType)4 Test (org.testng.annotations.Test)3 APICommand (iso.std.iso_iec._24727.tech.schema.LegacySignatureGenerationType.APICommand)1 SignResponse (iso.std.iso_iec._24727.tech.schema.SignResponse)1 CardCommandAPDU (org.openecard.common.apdu.common.CardCommandAPDU)1 CardCommandTemplate (org.openecard.common.apdu.common.CardCommandTemplate)1 CardResponseAPDU (org.openecard.common.apdu.common.CardResponseAPDU)1