2017-07-03 09:30:10 +02:00
|
|
|
/*!
|
|
|
|
* \brief Tests for card EstablishPACEChannelOutput
|
|
|
|
*
|
2018-03-28 15:10:51 +02:00
|
|
|
* \copyright Copyright (c) 2015-2018 Governikus GmbH & Co. KG, Germany
|
2017-07-03 09:30:10 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <QtCore/QtCore>
|
|
|
|
#include <QtTest/QtTest>
|
|
|
|
|
2019-01-03 15:06:22 +01:00
|
|
|
#include "EstablishPaceChannelOutput.h"
|
2017-07-03 09:30:10 +02:00
|
|
|
#include "TestFileHelper.h"
|
|
|
|
|
|
|
|
|
|
|
|
using namespace governikus;
|
|
|
|
|
|
|
|
|
2019-01-03 15:06:22 +01:00
|
|
|
class test_EstablishPaceChannelOutput
|
2017-07-03 09:30:10 +02:00
|
|
|
: public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private Q_SLOTS:
|
2019-01-03 15:06:22 +01:00
|
|
|
void parseEstablishPaceChannelOutput()
|
2017-07-03 09:30:10 +02:00
|
|
|
{
|
2019-01-03 15:06:22 +01:00
|
|
|
QByteArray bytes = QByteArray::fromHex(TestFileHelper::readFile(":/card/EstablishPaceChannelOutput.hex"));
|
2017-07-03 09:30:10 +02:00
|
|
|
|
2019-01-03 15:06:22 +01:00
|
|
|
EstablishPaceChannelOutput channelOutput;
|
|
|
|
channelOutput.parse(bytes, PacePasswordId::PACE_PIN);
|
2017-07-03 09:30:10 +02:00
|
|
|
QCOMPARE(channelOutput.getCARcurr(), QByteArray("DETESTeID00004"));
|
|
|
|
QVERIFY(channelOutput.getCARprev().isEmpty());
|
|
|
|
QVERIFY(channelOutput.getEfCardAccess().toHex().startsWith(QByteArray("3181c1300d0608040")));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-03 15:06:22 +01:00
|
|
|
void parseEstablishPaceChannelOutput_wrongPIN()
|
2017-07-03 09:30:10 +02:00
|
|
|
{
|
2019-01-03 15:06:22 +01:00
|
|
|
QByteArray bytes = QByteArray::fromHex(TestFileHelper::readFile(":/card/EstablishPaceChannelOutput_wrongPIN.hex"));
|
2017-07-03 09:30:10 +02:00
|
|
|
|
2019-01-03 15:06:22 +01:00
|
|
|
EstablishPaceChannelOutput channelOutput;
|
|
|
|
channelOutput.parse(bytes, PacePasswordId::PACE_PIN);
|
2017-07-03 09:30:10 +02:00
|
|
|
QVERIFY(channelOutput.getCARcurr().isEmpty());
|
|
|
|
QVERIFY(channelOutput.getCARprev().isEmpty());
|
|
|
|
QVERIFY(channelOutput.getEfCardAccess().isEmpty());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-03 15:06:22 +01:00
|
|
|
void parseEstablishPaceChannelOutput_fromCcid()
|
2017-07-03 09:30:10 +02:00
|
|
|
{
|
2019-01-03 15:06:22 +01:00
|
|
|
QByteArray bytes = QByteArray::fromHex(TestFileHelper::readFile(":/card/EstablishPaceChannelOutput_fromCcid.hex"));
|
2017-07-03 09:30:10 +02:00
|
|
|
|
2019-01-03 15:06:22 +01:00
|
|
|
EstablishPaceChannelOutput channelOutput;
|
|
|
|
channelOutput.parseFromCcid(bytes, PacePasswordId::PACE_PIN);
|
2017-07-03 09:33:28 +02:00
|
|
|
QCOMPARE(CardReturnCode::OK, channelOutput.getPaceReturnCode());
|
2017-07-03 09:30:10 +02:00
|
|
|
QCOMPARE(channelOutput.getCARcurr(), QByteArray("DECVCAeID00103"));
|
|
|
|
QCOMPARE(channelOutput.getCARprev(), QByteArray("DECVCAeID00102"));
|
|
|
|
QVERIFY(!channelOutput.getEfCardAccess().isEmpty());
|
|
|
|
QVERIFY(!channelOutput.getIDicc().isEmpty());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-03 15:06:22 +01:00
|
|
|
void parseEstablishPaceChannelOutput_fromCcid2()
|
2017-07-03 09:30:10 +02:00
|
|
|
{
|
2019-01-03 15:06:22 +01:00
|
|
|
QByteArray bytes = QByteArray::fromHex(TestFileHelper::readFile(":/card/EstablishPaceChannelOutput_fromCcid2.hex"));
|
2017-07-03 09:30:10 +02:00
|
|
|
|
2019-01-03 15:06:22 +01:00
|
|
|
EstablishPaceChannelOutput channelOutput;
|
|
|
|
channelOutput.parseFromCcid(bytes, PacePasswordId::PACE_PIN);
|
2017-07-03 09:33:28 +02:00
|
|
|
QCOMPARE(CardReturnCode::OK, channelOutput.getPaceReturnCode());
|
2017-07-03 09:30:10 +02:00
|
|
|
QVERIFY(channelOutput.getCARcurr().isEmpty());
|
|
|
|
QVERIFY(channelOutput.getCARprev().isEmpty());
|
|
|
|
QVERIFY(!channelOutput.getEfCardAccess().isEmpty());
|
|
|
|
QVERIFY(!channelOutput.getIDicc().isEmpty());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-03 15:06:22 +01:00
|
|
|
void parseEstablishPaceChannelOutput_fromCcid_parseCrap()
|
2017-07-03 09:30:10 +02:00
|
|
|
{
|
|
|
|
QByteArray hexBytes = QByteArray("30 0C"
|
|
|
|
" 04 04 F0200001"
|
|
|
|
" 04 02 9000"
|
|
|
|
" 31 00"
|
|
|
|
// " A4 22 04 20 24e41d62b8c848226b86fcc6c7657577dca47ad2bf21573617bae84807f85c6b"
|
|
|
|
// " A5 10 040e4445435643416549443030313033"
|
|
|
|
// " A6 10 040e4445435643416549443030313032"
|
|
|
|
" 9000" // ReturnCode
|
|
|
|
);
|
|
|
|
|
2019-01-03 15:06:22 +01:00
|
|
|
EstablishPaceChannelOutput channelOutput;
|
|
|
|
channelOutput.parseFromCcid(QByteArray::fromHex(hexBytes), PacePasswordId::PACE_PIN);
|
2017-07-03 09:33:28 +02:00
|
|
|
QCOMPARE(CardReturnCode::UNKNOWN, channelOutput.getPaceReturnCode());
|
2017-12-20 14:54:05 +01:00
|
|
|
QCOMPARE(channelOutput.getMseStatusSetAt(), QByteArray());
|
2017-07-03 09:30:10 +02:00
|
|
|
QCOMPARE(channelOutput.getCARcurr(), QByteArray());
|
|
|
|
QCOMPARE(channelOutput.getCARprev(), QByteArray());
|
|
|
|
QCOMPARE(channelOutput.getEfCardAccess(), QByteArray());
|
|
|
|
QCOMPARE(channelOutput.getIDicc(), QByteArray());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-03 15:06:22 +01:00
|
|
|
void parseEstablishPaceChannelOutput_fromCcid_onlyMandatoryElements()
|
2017-07-03 09:30:10 +02:00
|
|
|
{
|
|
|
|
QByteArray hexBytes = QByteArray("30 12"
|
|
|
|
" A1 06 04 04 F0200001"
|
|
|
|
" A2 04 04 02 9000"
|
|
|
|
" A3 02 31 00"
|
|
|
|
// " A4 22 04 20 24e41d62b8c848226b86fcc6c7657577dca47ad2bf21573617bae84807f85c6b"
|
|
|
|
// " A5 10 040e4445435643416549443030313033"
|
|
|
|
// " A6 10 040e4445435643416549443030313032"
|
|
|
|
" 9000" // ReturnCode
|
|
|
|
);
|
|
|
|
|
2019-01-03 15:06:22 +01:00
|
|
|
EstablishPaceChannelOutput channelOutput;
|
|
|
|
channelOutput.parseFromCcid(QByteArray::fromHex(hexBytes), PacePasswordId::PACE_PIN);
|
2017-07-03 09:33:28 +02:00
|
|
|
QCOMPARE(CardReturnCode::CANCELLATION_BY_USER, channelOutput.getPaceReturnCode());
|
2017-12-20 14:54:05 +01:00
|
|
|
QCOMPARE(channelOutput.getMseStatusSetAt(), QByteArray::fromHex("9000"));
|
2017-07-03 09:30:10 +02:00
|
|
|
QCOMPARE(channelOutput.getCARcurr(), QByteArray());
|
|
|
|
QCOMPARE(channelOutput.getCARprev(), QByteArray());
|
|
|
|
QCOMPARE(channelOutput.getEfCardAccess(), QByteArray::fromHex("3100"));
|
|
|
|
QCOMPARE(channelOutput.getIDicc(), QByteArray());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-03 15:06:22 +01:00
|
|
|
void parseEstablishPaceChannelOutput_fromCcid_allElements()
|
2017-07-03 09:30:10 +02:00
|
|
|
{
|
|
|
|
QByteArray hexBytes = QByteArray("30 5A"
|
|
|
|
" A1 06 04 04 F0200001"
|
|
|
|
" A2 04 04 02 9000"
|
|
|
|
" A3 02 31 00"
|
|
|
|
" A4 22 04 20 24e41d62b8c848226b86fcc6c7657577dca47ad2bf21573617bae84807f85c6b"
|
|
|
|
" A5 10 04 0e 4445435643416549443030313033"
|
|
|
|
" A6 10 04 0e 4445435643416549443030313032"
|
|
|
|
" 9000" // ReturnCode
|
|
|
|
);
|
|
|
|
|
2019-01-03 15:06:22 +01:00
|
|
|
EstablishPaceChannelOutput channelOutput;
|
|
|
|
channelOutput.parseFromCcid(QByteArray::fromHex(hexBytes), PacePasswordId::PACE_PIN);
|
2017-07-03 09:33:28 +02:00
|
|
|
QCOMPARE(CardReturnCode::CANCELLATION_BY_USER, channelOutput.getPaceReturnCode());
|
2017-12-20 14:54:05 +01:00
|
|
|
QCOMPARE(channelOutput.getMseStatusSetAt(), QByteArray::fromHex("9000"));
|
2017-07-03 09:30:10 +02:00
|
|
|
QCOMPARE(channelOutput.getCARcurr(), QByteArray("DECVCAeID00103"));
|
|
|
|
QCOMPARE(channelOutput.getCARprev(), QByteArray("DECVCAeID00102"));
|
|
|
|
QCOMPARE(channelOutput.getEfCardAccess(), QByteArray::fromHex("3100"));
|
|
|
|
QCOMPARE(channelOutput.getIDicc(), QByteArray::fromHex("24e41d62b8c848226b86fcc6c7657577dca47ad2bf21573617bae84807f85c6b"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Workaround for erroneous firmware implementation of reader cyberJack wave:
|
|
|
|
* When entering a wrong PIN, the reader returns an invalid ASN.1 structure, where the element
|
|
|
|
*
|
|
|
|
* ESTABLISHPACECHANNELOUTPUT.efCardAccess
|
|
|
|
*
|
|
|
|
* is treated as IMPLICIT TAGGED. That's wrong.
|
|
|
|
*/
|
2019-01-03 15:06:22 +01:00
|
|
|
void parseEstablishPaceChannelOutput_fromCcid_cyberJackWave_workaround()
|
2017-07-03 09:30:10 +02:00
|
|
|
{
|
|
|
|
QByteArray hexBytes = QByteArray("30 10"
|
|
|
|
" a1 06 04 04 f00663c2"
|
|
|
|
" a2 04 04 02 0000"
|
|
|
|
" a3 00"
|
|
|
|
"9000" // ReturnCode
|
|
|
|
);
|
2019-01-03 15:06:22 +01:00
|
|
|
EstablishPaceChannelOutput channelOutput;
|
|
|
|
channelOutput.parseFromCcid(QByteArray::fromHex(hexBytes), PacePasswordId::PACE_PIN);
|
2017-07-03 09:33:28 +02:00
|
|
|
QCOMPARE(CardReturnCode::INVALID_PIN, channelOutput.getPaceReturnCode());
|
2017-07-03 09:30:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-20 14:54:05 +01:00
|
|
|
void toCcid()
|
|
|
|
{
|
|
|
|
QByteArray hexBytes = QByteArray("30 5A"
|
|
|
|
" A1 06 04 04 F0200001"
|
|
|
|
" A2 04 04 02 9000"
|
|
|
|
" A3 02 31 00"
|
|
|
|
" A4 22 04 20 24e41d62b8c848226b86fcc6c7657577dca47ad2bf21573617bae84807f85c6b"
|
|
|
|
" A5 10 04 0e 4445435643416549443030313033"
|
|
|
|
" A6 10 04 0e 4445435643416549443030313032"
|
|
|
|
" 9000" // ReturnCode
|
|
|
|
);
|
|
|
|
|
2019-01-03 15:06:22 +01:00
|
|
|
EstablishPaceChannelOutput channelOutput;
|
|
|
|
channelOutput.parseFromCcid(QByteArray::fromHex(hexBytes), PacePasswordId::PACE_PIN);
|
2017-12-20 14:54:05 +01:00
|
|
|
|
2019-01-03 15:06:22 +01:00
|
|
|
EstablishPaceChannelOutput channelOutput2;
|
|
|
|
channelOutput2.parseFromCcid(channelOutput.toCcid(), PacePasswordId::PACE_PIN);
|
2017-12-20 14:54:05 +01:00
|
|
|
|
|
|
|
QCOMPARE(channelOutput2.getPaceReturnCode(), CardReturnCode::CANCELLATION_BY_USER);
|
|
|
|
QCOMPARE(channelOutput2.getPaceReturnCode(), channelOutput.getPaceReturnCode());
|
|
|
|
|
|
|
|
QCOMPARE(channelOutput2.getMseStatusSetAt(), QByteArray::fromHex("9000"));
|
|
|
|
QCOMPARE(channelOutput2.getMseStatusSetAt(), channelOutput.getMseStatusSetAt());
|
|
|
|
|
|
|
|
QCOMPARE(channelOutput2.getCARcurr(), QByteArray("DECVCAeID00103"));
|
|
|
|
QCOMPARE(channelOutput2.getCARcurr(), channelOutput.getCARcurr());
|
|
|
|
|
|
|
|
QCOMPARE(channelOutput2.getCARprev(), QByteArray("DECVCAeID00102"));
|
|
|
|
QCOMPARE(channelOutput2.getCARprev(), channelOutput.getCARprev());
|
|
|
|
|
|
|
|
QCOMPARE(channelOutput2.getEfCardAccess(), QByteArray::fromHex("3100"));
|
|
|
|
QCOMPARE(channelOutput2.getEfCardAccess(), channelOutput.getEfCardAccess());
|
|
|
|
|
|
|
|
QCOMPARE(channelOutput2.getIDicc(), QByteArray::fromHex("24e41d62b8c848226b86fcc6c7657577dca47ad2bf21573617bae84807f85c6b"));
|
|
|
|
QCOMPARE(channelOutput2.getIDicc(), channelOutput.getIDicc());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void toCcid_ReturnCode_ErrorCode_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<CardReturnCode>("cardReturnCode");
|
2019-01-03 15:06:22 +01:00
|
|
|
QTest::addColumn<PacePasswordId>("pacePasswordId");
|
2017-12-20 14:54:05 +01:00
|
|
|
|
2019-01-03 15:06:22 +01:00
|
|
|
QTest::newRow("INVALID_CAN") << CardReturnCode::INVALID_CAN << PacePasswordId::PACE_CAN;
|
|
|
|
QTest::newRow("INVALID_PIN") << CardReturnCode::INVALID_PIN << PacePasswordId::PACE_PIN;
|
|
|
|
QTest::newRow("INVALID_PUK") << CardReturnCode::INVALID_PUK << PacePasswordId::PACE_PUK;
|
2017-12-20 14:54:05 +01:00
|
|
|
|
2019-01-03 15:06:22 +01:00
|
|
|
QTest::newRow("OK") << CardReturnCode::OK << PacePasswordId::PACE_PIN;
|
|
|
|
QTest::newRow("CANCELLATION_BY_USER") << CardReturnCode::CANCELLATION_BY_USER << PacePasswordId::PACE_PIN;
|
|
|
|
QTest::newRow("INPUT_TIME_OUT") << CardReturnCode::INPUT_TIME_OUT << PacePasswordId::PACE_PIN;
|
|
|
|
QTest::newRow("COMMAND_FAILED") << CardReturnCode::COMMAND_FAILED << PacePasswordId::PACE_PIN;
|
|
|
|
QTest::newRow("CARD_NOT_FOUND") << CardReturnCode::CARD_NOT_FOUND << PacePasswordId::PACE_PIN;
|
2017-12-20 14:54:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void toCcid_ReturnCode_ErrorCode()
|
|
|
|
{
|
|
|
|
QFETCH(CardReturnCode, cardReturnCode);
|
2019-01-03 15:06:22 +01:00
|
|
|
QFETCH(PacePasswordId, pacePasswordId);
|
2017-12-20 14:54:05 +01:00
|
|
|
|
2019-01-03 15:06:22 +01:00
|
|
|
EstablishPaceChannelOutput channelOutput;
|
2017-12-20 14:54:05 +01:00
|
|
|
channelOutput.setPaceReturnCode(cardReturnCode);
|
|
|
|
|
2019-01-03 15:06:22 +01:00
|
|
|
EstablishPaceChannelOutput channelOutput2;
|
2017-12-20 14:54:05 +01:00
|
|
|
channelOutput2.parseFromCcid(channelOutput.toCcid(), pacePasswordId);
|
|
|
|
|
|
|
|
QCOMPARE(channelOutput2.getPaceReturnCode(), cardReturnCode);
|
|
|
|
QCOMPARE(channelOutput2.getPaceReturnCode(), channelOutput.getPaceReturnCode());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-03 09:30:10 +02:00
|
|
|
};
|
|
|
|
|
2019-01-03 15:06:22 +01:00
|
|
|
QTEST_GUILESS_MAIN(test_EstablishPaceChannelOutput)
|
|
|
|
#include "test_EstablishPaceChannelOutput.moc"
|