@@ -30,28 +30,46 @@ using namespace electronic_id;
3030namespace
3131{
3232
33- const byte_type PIN_PADDING_CHAR = 0xFF ;
34- const byte_type AUTH_PIN_REFERENCE = 0x01 ;
33+ constexpr byte_type PIN_PADDING_CHAR = 0xFF ;
34+ constexpr byte_type AUTH_PIN_REFERENCE = 0x01 ;
35+ constexpr byte_type SIGN_PIN_REFERENCE = 0x85 ;
36+
37+ const auto MAIN_AID = CommandApdu::select(0x04 ,
38+ {0xA0 , 0x00 , 0x00 , 0x00 , 0x77 , 0x01 , 0x08 , 0x00 , 0x07 ,
39+ 0x00 , 0x00 , 0xFE , 0x00 , 0x00 , 0x01 , 0x00 });
40+ const auto ADF1_AID = CommandApdu::select(
41+ 0x04 , {0xe8 , 0x28 , 0xbd , 0x08 , 0x0f , 0xf2 , 0x50 , 0x4f , 0x54 , 0x20 , 0x41 , 0x57 , 0x50 });
42+ const auto ADF2_AID = CommandApdu::select(0x04 ,
43+ {0x51 , 0x53 , 0x43 , 0x44 , 0x20 , 0x41 , 0x70 , 0x70 , 0x6C ,
44+ 0x69 , 0x63 , 0x61 , 0x74 , 0x69 , 0x6F , 0x6E });
45+ const auto AUTH_CERT = CommandApdu::select(0x09 , {0xAD , 0xF1 , 0x34 , 0x01 });
46+ const auto SIGN_CERT = CommandApdu::select(0x09 , {0xAD , 0xF2 , 0x34 , 0x1F });
3547
3648} // namespace
3749
50+ void EIDIDEMIA::selectADF1 () const
51+ {
52+ transmitApduWithExpectedResponse (*card, ADF1_AID);
53+ }
54+
55+ void EIDIDEMIA::selectADF2 () const
56+ {
57+ transmitApduWithExpectedResponse (*card, ADF2_AID);
58+ }
59+
3860byte_vector EIDIDEMIA::getCertificateImpl (const CertificateType type) const
3961{
40- transmitApduWithExpectedResponse (*card, selectApplicationID ().MAIN_AID );
41- return electronic_id::getCertificate (*card,
42- type.isAuthentication () ? selectCertificate ().AUTH_CERT
43- : selectCertificate ().SIGN_CERT );
62+ transmitApduWithExpectedResponse (*card, MAIN_AID);
63+ return electronic_id::getCertificate (*card, type.isAuthentication () ? AUTH_CERT : SIGN_CERT);
4464}
4565
4666byte_vector EIDIDEMIA::signWithAuthKeyImpl (byte_vector&& pin, const byte_vector& hash) const
4767{
48- // Select authentication application and authentication security environment.
49- transmitApduWithExpectedResponse (*card, selectApplicationID ().MAIN_AID );
50- transmitApduWithExpectedResponse (*card, selectApplicationID ().AUTH_AID );
68+ selectADF1 ();
5169 selectAuthSecurityEnv ();
5270
5371 verifyPin (*card, AUTH_PIN_REFERENCE, std::move (pin), authPinMinMaxLength ().first ,
54- pinBlockLength () , PIN_PADDING_CHAR);
72+ authPinMinMaxLength (). second , PIN_PADDING_CHAR);
5573
5674 return internalAuthenticate (*card,
5775 authSignatureAlgorithm ().isRSAWithPKCS1Padding ()
@@ -62,19 +80,19 @@ byte_vector EIDIDEMIA::signWithAuthKeyImpl(byte_vector&& pin, const byte_vector&
6280
6381ElectronicID::PinRetriesRemainingAndMax EIDIDEMIA::authPinRetriesLeftImpl () const
6482{
65- transmitApduWithExpectedResponse (*card, selectApplicationID (). MAIN_AID );
83+ transmitApduWithExpectedResponse (*card, MAIN_AID);
6684 return pinRetriesLeft (AUTH_PIN_REFERENCE);
6785}
6886
6987ElectronicID::Signature EIDIDEMIA::signWithSigningKeyImpl (byte_vector&& pin,
7088 const byte_vector& hash,
7189 const HashAlgorithm hashAlgo) const
7290{
73- // Select signing application and signing security environment.
74- transmitApduWithExpectedResponse (*card, selectApplicationID ().SIGN_AID );
91+ selectADF2 ();
7592 pcsc_cpp::byte_type algo = selectSignSecurityEnv ();
7693 auto tmp = hash;
77- if (algo == 0x54 ) {
94+ bool isECC = algo == 0x54 ;
95+ if (isECC) {
7896 constexpr size_t ECDSA384_INPUT_LENGTH = 384 / 8 ;
7997 if (tmp.size () < ECDSA384_INPUT_LENGTH) {
8098 // Zero-pad hashes that are shorter than SHA-384.
@@ -85,48 +103,17 @@ ElectronicID::Signature EIDIDEMIA::signWithSigningKeyImpl(byte_vector&& pin,
85103 }
86104 }
87105
88- verifyPin (*card, signingPinReference () , std::move (pin), signingPinMinMaxLength ().first ,
89- pinBlockLength () , PIN_PADDING_CHAR);
106+ verifyPin (*card, SIGN_PIN_REFERENCE , std::move (pin), signingPinMinMaxLength ().first ,
107+ signingPinMinMaxLength (). second , PIN_PADDING_CHAR);
90108
91- return {useInternalAuthenticateAndRSAWithPKCS1PaddingDuringSigning ()
92- ? internalAuthenticate (*card, addRSAOID (hashAlgo, hash), name ())
93- : computeSignature (*card, tmp, name ()),
94- {signingSignatureAlgorithm (), hashAlgo}};
109+ return {computeSignature (*card, tmp, name ()),
110+ {isECC ? SignatureAlgorithm::ES : SignatureAlgorithm::RS, hashAlgo}};
95111}
96112
97113ElectronicID::PinRetriesRemainingAndMax EIDIDEMIA::signingPinRetriesLeftImpl () const
98114{
99- transmitApduWithExpectedResponse (*card, selectApplicationID ().SIGN_AID );
100- return pinRetriesLeft (signingPinReference ());
101- }
102-
103- const SelectApplicationIDCmds& EIDIDEMIA::selectApplicationID () const
104- {
105- static const SelectApplicationIDCmds selectAppIDCmds {
106- // Main AID.
107- CommandApdu::select (0x04 ,
108- {0xA0 , 0x00 , 0x00 , 0x00 , 0x77 , 0x01 , 0x08 , 0x00 , 0x07 , 0x00 , 0x00 , 0xFE ,
109- 0x00 , 0x00 , 0x01 , 0x00 }),
110- // AWP AID.
111- CommandApdu::select (
112- 0x04 , {0xe8 , 0x28 , 0xbd , 0x08 , 0x0f , 0xf2 , 0x50 , 0x4f , 0x54 , 0x20 , 0x41 , 0x57 , 0x50 }),
113- // QSCD AID.
114- CommandApdu::select (0x04 ,
115- {0x51 , 0x53 , 0x43 , 0x44 , 0x20 , 0x41 , 0x70 , 0x70 , 0x6C , 0x69 , 0x63 , 0x61 ,
116- 0x74 , 0x69 , 0x6F , 0x6E }),
117- };
118- return selectAppIDCmds;
119- }
120-
121- const SelectCertificateCmds& EIDIDEMIA::selectCertificate () const
122- {
123- static const SelectCertificateCmds selectCert1Cmds {
124- // Authentication certificate.
125- CommandApdu::select (0x09 , {0xAD , 0xF1 , 0x34 , 0x01 }),
126- // Signing certificate.
127- CommandApdu::select (0x09 , {0xAD , 0xF2 , 0x34 , 0x1F }),
128- };
129- return selectCert1Cmds;
115+ selectADF2 ();
116+ return pinRetriesLeft (SIGN_PIN_REFERENCE);
130117}
131118
132119ElectronicID::PinRetriesRemainingAndMax EIDIDEMIA::pinRetriesLeft (byte_type pinReference) const
0 commit comments