Search in sources :

Example 1 with Encipher

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

the class TinySALTest method testEncipher.

/**
 * Test of encipher method, of class TinySAL.
 */
@Test(enabled = TESTS_ENABLED)
public void testEncipher() {
    System.out.println("encipher");
    Encipher parameters = new Encipher();
    EncipherResponse result = instance.encipher(parameters);
    assertEquals(ECardConstants.Major.ERROR, result.getResult().getResultMajor());
}
Also used : EncipherResponse(iso.std.iso_iec._24727.tech.schema.EncipherResponse) Encipher(iso.std.iso_iec._24727.tech.schema.Encipher) Test(org.testng.annotations.Test)

Example 2 with Encipher

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

the class PINCompareProtocolTest method testUnsupportedFunctions.

/*
     * [TR-03112-7] The following functions are not supported with this protocol
     * and, when called up, relay an error message to this effect
     * /resultminor/sal#inappropriateProtocolForAction:
     * CardApplicationStartSession, Encipher, Decipher, GetRandom, Hash, Sign,
     * VerifySignature, VerifyCertificate
     */
/**
 * This Test ensures that all functions unsupported by this protocol relay the correct error message when
 * called.
 */
@Test(enabled = TESTS_ENABLED)
public void testUnsupportedFunctions() {
    CardApplicationPath cardApplicationPath = new CardApplicationPath();
    CardApplicationPathType cardApplicationPathType = new CardApplicationPathType();
    cardApplicationPathType.setCardApplication(this.appIdentifier_ROOT);
    cardApplicationPath.setCardAppPathRequest(cardApplicationPathType);
    CardApplicationPathResponse cardApplicationPathResponse = instance.cardApplicationPath(cardApplicationPath);
    CardApplicationConnect cardApplicationConnect = new CardApplicationConnect();
    cardApplicationPathType = cardApplicationPathResponse.getCardAppPathResultSet().getCardApplicationPathResult().get(0);
    cardApplicationConnect.setCardApplicationPath(cardApplicationPathType);
    CardApplicationConnectResponse result1 = instance.cardApplicationConnect(cardApplicationConnect);
    Encipher encipher = new Encipher();
    encipher.setDIDName("PIN.home");
    encipher.setPlainText(new byte[] { 0x0, 0x0, 0x0 });
    encipher.setConnectionHandle(result1.getConnectionHandle());
    EncipherResponse encipherResponse = instance.encipher(encipher);
    assertEquals(encipherResponse.getResult().getResultMajor(), ECardConstants.Major.ERROR);
    assertEquals(encipherResponse.getResult().getResultMinor(), ECardConstants.Minor.SAL.INAPPROPRIATE_PROTOCOL_FOR_ACTION);
// TODO remaining unsupported functions
}
Also used : CardApplicationPathType(iso.std.iso_iec._24727.tech.schema.CardApplicationPathType) CardApplicationPath(iso.std.iso_iec._24727.tech.schema.CardApplicationPath) CardApplicationPathResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationPathResponse) CardApplicationConnect(iso.std.iso_iec._24727.tech.schema.CardApplicationConnect) EncipherResponse(iso.std.iso_iec._24727.tech.schema.EncipherResponse) CardApplicationConnectResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse) Encipher(iso.std.iso_iec._24727.tech.schema.Encipher) Test(org.testng.annotations.Test)

Example 3 with Encipher

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

the class GenericCryptographyProtocolTest method testEncipher.

@Test(enabled = TESTS_ENABLED)
public void testEncipher() {
    // TODO write test as soon as implemented
    EncipherResponse resp = instance.encipher(new Encipher());
    assertEquals(resp.getResult().getResultMajor(), ECardConstants.Major.ERROR);
}
Also used : EncipherResponse(iso.std.iso_iec._24727.tech.schema.EncipherResponse) Encipher(iso.std.iso_iec._24727.tech.schema.Encipher) Test(org.testng.annotations.Test)

Example 4 with Encipher

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

the class TinySAL method encipher.

/**
 * The Encipher function encrypts a transmitted plain text. The detailed behaviour of this function depends on
 * the protocol of the DID.
 * See BSI-TR-03112-4, version 1.1.2, section 3.5.1.
 *
 * @param request Encipher
 * @return EncipherResponse
 */
@Publish
@Override
public EncipherResponse encipher(Encipher request) {
    EncipherResponse response = WSHelper.makeResponse(EncipherResponse.class, WSHelper.makeResultOK());
    try {
        ConnectionHandleType connectionHandle = SALUtils.getConnectionHandle(request);
        CardStateEntry cardStateEntry = SALUtils.getCardStateEntry(states, connectionHandle, false);
        byte[] applicationID = cardStateEntry.getCurrentCardApplication().getApplicationIdentifier();
        String didName = SALUtils.getDIDName(request);
        byte[] plainText = request.getPlainText();
        Assert.assertIncorrectParameter(plainText, "The parameter PlainText is empty.");
        DIDScopeType didScope = request.getDIDScope();
        if (didScope == null) {
            didScope = DIDScopeType.LOCAL;
        }
        if (didScope.equals(DIDScopeType.LOCAL)) {
            byte[] necessaryCardApp = cardStateEntry.getInfo().getApplicationIdByDidName(didName, didScope);
            if (!Arrays.equals(necessaryCardApp, applicationID)) {
                throw new SecurityConditionNotSatisfiedException("Wrong application selected.");
            }
        }
        DIDStructureType didStructure = cardStateEntry.getDIDStructure(didName, didScope);
        Assert.assertNamedEntityNotFound(didStructure, "The given DIDName cannot be found.");
        String protocolURI = didStructure.getDIDMarker().getProtocol();
        SALProtocol protocol = getProtocol(connectionHandle, request.getDIDScope(), protocolURI);
        if (protocol.hasNextStep(FunctionType.Encipher)) {
            response = protocol.encipher(request);
            removeFinishedProtocol(connectionHandle, protocolURI, protocol);
        } else {
            throw new InappropriateProtocolForActionException("Encipher", protocol.toString());
        }
    } catch (ECardException e) {
        response.setResult(e.getResult());
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        throwThreadKillException(e);
        response.setResult(WSHelper.makeResult(e));
    }
    return response;
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) InappropriateProtocolForActionException(org.openecard.common.sal.exception.InappropriateProtocolForActionException) ECardException(org.openecard.common.ECardException) CardStateEntry(org.openecard.common.sal.state.CardStateEntry) EncipherResponse(iso.std.iso_iec._24727.tech.schema.EncipherResponse) SecurityConditionNotSatisfiedException(org.openecard.common.sal.exception.SecurityConditionNotSatisfiedException) SALProtocol(org.openecard.addon.sal.SALProtocol) DIDScopeType(iso.std.iso_iec._24727.tech.schema.DIDScopeType) DIDStructureType(iso.std.iso_iec._24727.tech.schema.DIDStructureType) PrerequisitesNotSatisfiedException(org.openecard.common.sal.exception.PrerequisitesNotSatisfiedException) NameExistsException(org.openecard.common.sal.exception.NameExistsException) AddonNotFoundException(org.openecard.addon.AddonNotFoundException) ThreadTerminateException(org.openecard.common.ThreadTerminateException) ECardException(org.openecard.common.ECardException) NamedEntityNotFoundException(org.openecard.common.sal.exception.NamedEntityNotFoundException) UnknownProtocolException(org.openecard.common.sal.exception.UnknownProtocolException) IncorrectParameterException(org.openecard.common.sal.exception.IncorrectParameterException) InappropriateProtocolForActionException(org.openecard.common.sal.exception.InappropriateProtocolForActionException) TLVException(org.openecard.common.tlv.TLVException) SecurityConditionNotSatisfiedException(org.openecard.common.sal.exception.SecurityConditionNotSatisfiedException) UnknownConnectionHandleException(org.openecard.common.sal.exception.UnknownConnectionHandleException) Publish(org.openecard.common.interfaces.Publish)

Aggregations

EncipherResponse (iso.std.iso_iec._24727.tech.schema.EncipherResponse)4 Encipher (iso.std.iso_iec._24727.tech.schema.Encipher)3 Test (org.testng.annotations.Test)3 CardApplicationConnect (iso.std.iso_iec._24727.tech.schema.CardApplicationConnect)1 CardApplicationConnectResponse (iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse)1 CardApplicationPath (iso.std.iso_iec._24727.tech.schema.CardApplicationPath)1 CardApplicationPathResponse (iso.std.iso_iec._24727.tech.schema.CardApplicationPathResponse)1 CardApplicationPathType (iso.std.iso_iec._24727.tech.schema.CardApplicationPathType)1 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)1 DIDScopeType (iso.std.iso_iec._24727.tech.schema.DIDScopeType)1 DIDStructureType (iso.std.iso_iec._24727.tech.schema.DIDStructureType)1 AddonNotFoundException (org.openecard.addon.AddonNotFoundException)1 SALProtocol (org.openecard.addon.sal.SALProtocol)1 ECardException (org.openecard.common.ECardException)1 ThreadTerminateException (org.openecard.common.ThreadTerminateException)1 Publish (org.openecard.common.interfaces.Publish)1 InappropriateProtocolForActionException (org.openecard.common.sal.exception.InappropriateProtocolForActionException)1 IncorrectParameterException (org.openecard.common.sal.exception.IncorrectParameterException)1 NameExistsException (org.openecard.common.sal.exception.NameExistsException)1 NamedEntityNotFoundException (org.openecard.common.sal.exception.NamedEntityNotFoundException)1