2017-07-03 09:30:10 +02:00
|
|
|
/*!
|
|
|
|
* \brief Unit tests for \ref StatePreVerification
|
|
|
|
*
|
2018-03-28 15:10:51 +02:00
|
|
|
* \copyright Copyright (c) 2014-2018 Governikus GmbH & Co. KG, Germany
|
2017-07-03 09:30:10 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "states/StateProcessCertificatesFromEac2.h"
|
|
|
|
|
|
|
|
#include "asn1/CVCertificateChainBuilder.h"
|
2017-09-15 10:23:30 +02:00
|
|
|
#include "Commands.h"
|
2017-07-03 09:30:10 +02:00
|
|
|
#include "paos/retrieve/DidAuthenticateEac1.h"
|
|
|
|
#include "paos/retrieve/DidAuthenticateEac1Parser.h"
|
|
|
|
#include "paos/retrieve/DidAuthenticateEac2Parser.h"
|
2017-09-15 10:23:30 +02:00
|
|
|
#include "TestAuthContext.h"
|
|
|
|
#include "TestFileHelper.h"
|
2017-07-03 09:30:10 +02:00
|
|
|
|
|
|
|
#include <QtCore>
|
|
|
|
#include <QtTest>
|
|
|
|
|
|
|
|
using namespace governikus;
|
|
|
|
|
|
|
|
|
|
|
|
class test_StateProcessCertificatesFromEac2
|
|
|
|
: public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
QScopedPointer<StateProcessCertificatesFromEac2> mState;
|
|
|
|
QSharedPointer<AuthContext> mAuthContext;
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void fireStateStart(QEvent* pEvent);
|
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void init()
|
|
|
|
{
|
2017-07-03 09:33:28 +02:00
|
|
|
mAuthContext.reset(new TestAuthContext(nullptr, ":/paos/DIDAuthenticateEAC1.xml"));
|
|
|
|
QSharedPointer<DIDAuthenticateEAC2> didAuthEac2(static_cast<DIDAuthenticateEAC2*>(DidAuthenticateEac2Parser().parse(TestFileHelper::readFile(":/paos/DIDAuthenticateEAC2.xml"))));
|
2017-07-03 09:30:10 +02:00
|
|
|
mAuthContext->setDidAuthenticateEac2(didAuthEac2);
|
|
|
|
EstablishPACEChannelOutput paceOutput;
|
2017-12-20 14:54:05 +01:00
|
|
|
paceOutput.parse(QByteArray::fromHex(TestFileHelper::readFile(":/card/EstablishPACEChannelOutput.hex")), PACE_PASSWORD_ID::PACE_PIN);
|
2017-07-03 09:30:10 +02:00
|
|
|
mAuthContext->setPaceOutputData(paceOutput);
|
|
|
|
|
|
|
|
mState.reset(new StateProcessCertificatesFromEac2(mAuthContext));
|
|
|
|
mState->setStateName("StateProcessCertificatesFromEac2");
|
|
|
|
connect(this, &test_StateProcessCertificatesFromEac2::fireStateStart, mState.data(), &AbstractState::onEntry);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void cleanup()
|
|
|
|
{
|
|
|
|
mAuthContext.clear();
|
|
|
|
mState.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void testDoNotProcessIfCvcChainAvailable()
|
|
|
|
{
|
|
|
|
mAuthContext->initCvcChainBuilder();
|
|
|
|
|
2017-12-20 14:54:05 +01:00
|
|
|
QSignalSpy spy(mState.data(), &StateProcessCertificatesFromEac2::fireContinue);
|
2017-07-03 09:30:10 +02:00
|
|
|
Q_EMIT fireStateStart(nullptr);
|
|
|
|
mAuthContext->setStateApproved();
|
|
|
|
|
|
|
|
QCOMPARE(spy.count(), 1);
|
|
|
|
QVERIFY(mState->getContext()->hasChainForCertificationAuthority(*mState->getContext()->getPaceOutputData()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void testDoNotTakeTerminalCvcFromEac2()
|
|
|
|
{
|
|
|
|
// move terminal cvc from eac1 to eac2
|
|
|
|
mAuthContext->mDIDAuthenticateEAC2->mEac2.mCvCertificates.append(mAuthContext->mDIDAuthenticateEAC1->mEac1InputType.mCvCertificates.at(0));
|
|
|
|
mAuthContext->mDIDAuthenticateEAC1->mEac1InputType.mCvCertificates.removeAt(0);
|
|
|
|
mAuthContext->initCvcChainBuilder();
|
|
|
|
|
2017-12-20 14:54:05 +01:00
|
|
|
QSignalSpy spy(mState.data(), &StateProcessCertificatesFromEac2::fireAbort);
|
2017-07-03 09:30:10 +02:00
|
|
|
Q_EMIT fireStateStart(nullptr);
|
|
|
|
mAuthContext->setStateApproved();
|
|
|
|
|
|
|
|
QCOMPARE(spy.count(), 1);
|
|
|
|
QVERIFY(!mState->getContext()->hasChainForCertificationAuthority(*mState->getContext()->getPaceOutputData()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void testCvcFromEac2()
|
|
|
|
{
|
|
|
|
// move terminal dv from eac1 to eac2
|
|
|
|
mAuthContext->mDIDAuthenticateEAC2->mEac2.mCvCertificates.append(mAuthContext->mDIDAuthenticateEAC1->mEac1InputType.mCvCertificates.at(1));
|
|
|
|
mAuthContext->mDIDAuthenticateEAC1->mEac1InputType.mCvCertificates.removeAt(3);
|
|
|
|
mAuthContext->mDIDAuthenticateEAC1->mEac1InputType.mCvCertificates.removeAt(2);
|
|
|
|
mAuthContext->mDIDAuthenticateEAC1->mEac1InputType.mCvCertificates.removeAt(1);
|
|
|
|
mAuthContext->initCvcChainBuilder();
|
|
|
|
|
2017-12-20 14:54:05 +01:00
|
|
|
QSignalSpy spy(mState.data(), &StateProcessCertificatesFromEac2::fireContinue);
|
2017-07-03 09:30:10 +02:00
|
|
|
Q_EMIT fireStateStart(nullptr);
|
|
|
|
mAuthContext->setStateApproved();
|
|
|
|
|
|
|
|
QCOMPARE(spy.count(), 1);
|
|
|
|
QVERIFY(mState->getContext()->hasChainForCertificationAuthority(*mState->getContext()->getPaceOutputData()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
QTEST_GUILESS_MAIN(test_StateProcessCertificatesFromEac2)
|
|
|
|
#include "test_StateProcessCertificatesFromEac2.moc"
|