1 /*!
2  * \brief Tests for GeneralAuthenticate response APDUs
3  *
4  * \copyright Copyright (c) 2015-2021 Governikus GmbH & Co. KG, Germany
5  */
6 
7 #include <QtCore>
8 #include <QtTest>
9 
10 #include "GeneralAuthenticateResponse.h"
11 
12 
13 using namespace governikus;
14 
15 
16 class test_GeneralAuthenticateResponse
17 	: public QObject
18 {
19 	Q_OBJECT
20 
21 	private Q_SLOTS:
parseGAEncryptedNonceResponse()22 		void parseGAEncryptedNonceResponse()
23 		{
24 			const ResponseApdu apdu(QByteArray::fromHex("7c1280105391ded7867c2d7df7f871ed6913c07d9000"));
25 
26 			const GAEncryptedNonceResponse response(apdu);
27 
28 			QCOMPARE(response.getEncryptedNonce(), QByteArray::fromHex("5391ded7867c2d7df7f871ed6913c07d"));
29 		}
30 
31 
parseGAEncryptedNonceResponse_invalidData()32 		void parseGAEncryptedNonceResponse_invalidData()
33 		{
34 			const ResponseApdu apdu(QByteArray::fromHex("7c1281105391ded7867c2d7df7f871ed6913c07d9000"));
35 
36 			const GAEncryptedNonceResponse response(apdu);
37 
38 			QCOMPARE(response.getEncryptedNonce(), QByteArray());
39 		}
40 
41 
parseGAMapNonceResponse()42 		void parseGAMapNonceResponse()
43 		{
44 			const ResponseApdu apdu(QByteArray::fromHex("7c438241042a8199d469fde8f98e22bf8bb5a72804b5293bb54a8afa4d84e4b63217d163b61d78dc6453408bde19a86254ee3b0f03871964b71f1b57f77037ecdbedbe79b09000"));
45 
46 			const GAMapNonceResponse response(apdu);
47 
48 			QCOMPARE(response.getMappingData(), QByteArray::fromHex("042a8199d469fde8f98e22bf8bb5a72804b5293bb54a8afa4d84e4b63217d163b61d78dc6453	408bde19a86254ee3b0f03871964b71f1b57f77037ecdbedbe79b0"));
49 		}
50 
51 
parseGAMapNonceResponse_invalidData()52 		void parseGAMapNonceResponse_invalidData()
53 		{
54 			const ResponseApdu apdu(QByteArray::fromHex("7c438141042a8199d469fde8f98e22bf8bb5a72804b5293bb54a8afa4d84e4b63217d163b61d78dc6453408bde19a86254ee3b0f03871964b71f1b57f77037ecdbedbe79b09000"));
55 
56 			const GAMapNonceResponse response(apdu);
57 
58 			QCOMPARE(response.getMappingData(), QByteArray());
59 		}
60 
61 
parseGAPerformKeyAgreementResponse()62 		void parseGAPerformKeyAgreementResponse()
63 		{
64 			const ResponseApdu apdu(QByteArray::fromHex("7c43844104a3be2ed0fccb4bf96df00be39a9c3e6b67d3a1118c95c195d0389fa14956c383a322c34f1b63a7bdb41f98b644aa9e15f823a2d726ef6ae8df3c10ac4e7298cc9000"));
65 
66 			const GAPerformKeyAgreementResponse response(apdu);
67 
68 			QCOMPARE(response.getEphemeralPublicKey(), QByteArray::fromHex("04a3be2ed0fccb4bf96df00be39a9c3e6b67d3a1118c95c195d0389fa14956c383a322c34f1b63a7bdb41f98b644aa9e15f823a2d726ef6ae8df3c10ac4e7298cc"));
69 		}
70 
71 
parseGAPerformKeyAgreementResponse_invalid()72 		void parseGAPerformKeyAgreementResponse_invalid()
73 		{
74 			const ResponseApdu apdu(QByteArray::fromHex("7c43814104a3be2ed0fccb4bf96df00be39a9c3e6b67d3a1118c95c195d0389fa14956c383a322c34f1b63a7bdb41f98b644aa9e15f823a2d726ef6ae8df3c10ac4e7298cc9000"));
75 
76 			const GAPerformKeyAgreementResponse response(apdu);
77 
78 			QCOMPARE(response.getEphemeralPublicKey(), QByteArray());
79 		}
80 
81 
parseGAMutualAuthenticationResponse_withoutCARs()82 		void parseGAMutualAuthenticationResponse_withoutCARs()
83 		{
84 			const ResponseApdu apdu(QByteArray::fromHex("7c0a8608afcd013365384ba39000"));
85 
86 			const GAMutualAuthenticationResponse response(apdu);
87 
88 			QCOMPARE(response.getAuthenticationToken(), QByteArray::fromHex("afcd013365384ba3"));
89 			QCOMPARE(response.getCarCurr(), QByteArray());
90 			QCOMPARE(response.getCarPrev(), QByteArray());
91 		}
92 
93 
testGAMutualAuthenticationResponse_oneCAR()94 		void testGAMutualAuthenticationResponse_oneCAR()
95 		{
96 			// this is the response from a new card that did not see any link certificates
97 			const ResponseApdu apdu(QByteArray::fromHex("7c1a860871204ff538eec464870e44454356434165494430303130339000"));
98 
99 			const GAMutualAuthenticationResponse response(apdu);
100 
101 			QCOMPARE(response.getCarCurr(), QByteArray("DECVCAeID00103"));
102 			QCOMPARE(response.getCarPrev(), QByteArray());
103 		}
104 
105 
testGAMutualAuthenticationResponse_twoCARs()106 		void testGAMutualAuthenticationResponse_twoCARs()
107 		{
108 			// this is the response from a card that already saw link certificates
109 			const ResponseApdu apdu(QByteArray::fromHex("7c2a86086fa6266f2ef1f2d9870e4445544553546549443030303034880e44455445535465494430303030329000"));
110 
111 			const GAMutualAuthenticationResponse response(apdu);
112 
113 			QCOMPARE(response.getCarCurr(), QByteArray("DETESTeID00004"));
114 			QCOMPARE(response.getCarPrev(), QByteArray("DETESTeID00002"));
115 		}
116 
117 
testGAMutualAuthenticationResponse_invalid()118 		void testGAMutualAuthenticationResponse_invalid()
119 		{
120 			// this is the response from a new card that did not see any link certificates
121 			const ResponseApdu apdu(QByteArray::fromHex("7c1a810871204ff538eec464870e44454356434165494430303130339000"));
122 
123 			const GAMutualAuthenticationResponse response(apdu);
124 
125 			QCOMPARE(response.getCarCurr(), QByteArray());
126 			QCOMPARE(response.getCarPrev(), QByteArray());
127 		}
128 
129 
testGAChipAuthenticationResponse()130 		void testGAChipAuthenticationResponse()
131 		{
132 			const ResponseApdu apdu(QByteArray::fromHex("7c1481085b5b32c5b15d012c8208aaa14cfba15994d39000"));
133 
134 			const GAChipAuthenticationResponse response(apdu);
135 
136 			QCOMPARE(response.getNonce(), QByteArray::fromHex("5b5b32c5b15d012c"));
137 			QCOMPARE(response.getAuthenticationToken(), QByteArray::fromHex("aaa14cfba15994d3"));
138 		}
139 
140 
testGAChipAuthenticationResponse_invalid()141 		void testGAChipAuthenticationResponse_invalid()
142 		{
143 			const ResponseApdu apdu(QByteArray::fromHex("7c148208aaa14cfba15994d39000"));
144 
145 			const GAChipAuthenticationResponse response(apdu);
146 
147 			QCOMPARE(response.getAuthenticationToken(), QByteArray());
148 			QCOMPARE(response.getNonce(), QByteArray());
149 		}
150 
151 
152 };
153 
154 QTEST_GUILESS_MAIN(test_GeneralAuthenticateResponse)
155 #include "test_GeneralAuthenticateResponse.moc"
156