Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ add_library(${PROJECT_NAME}
src/electronic-ids/pcsc/EstEIDIDEMIA.hpp
src/electronic-ids/pcsc/FinEID.cpp
src/electronic-ids/pcsc/FinEID.hpp
src/electronic-ids/pcsc/LatEIDIDEMIACommon.hpp
src/electronic-ids/pcsc/LatEIDIDEMIAv1.cpp
src/electronic-ids/pcsc/LatEIDIDEMIAv1.hpp
src/electronic-ids/pcsc/LatEIDIDEMIAv2.cpp
src/electronic-ids/pcsc/LatEIDIDEMIAv2.hpp
src/electronic-ids/pcsc/PcscElectronicID.hpp
Expand Down Expand Up @@ -78,7 +75,6 @@ add_executable(${MOCK_TEST_EXE}
tests/mock/select-certificate-script-EST-IDEMIA.hpp
tests/mock/select-certificate-script-FIN-V3.hpp
tests/mock/select-certificate-script-FIN-V4.hpp
tests/mock/select-certificate-script-LAT-V1.hpp
tests/mock/select-certificate-script-LAT-V2.hpp
tests/mock/test-autoselect-card.cpp
tests/mock/test-find-masked-atr.cpp
Expand Down
5 changes: 0 additions & 5 deletions src/electronic-id.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

#include "electronic-ids/pcsc/EstEIDIDEMIA.hpp"
#include "electronic-ids/pcsc/FinEID.hpp"
#include "electronic-ids/pcsc/LatEIDIDEMIAv1.hpp"
#include "electronic-ids/pcsc/LatEIDIDEMIAv2.hpp"

#include "electronic-ids/pkcs11/Pkcs11ElectronicID.hpp"
Expand Down Expand Up @@ -71,10 +70,6 @@ const std::map<byte_vector, ElectronicIDConstructor> SUPPORTED_ATRS {
{{0x3B, 0x7F, 0x96, 0x00, 0x00, 0x80, 0x31, 0xB8, 0x65, 0xB0,
0x85, 0x05, 0x00, 0x11, 0x12, 0x24, 0x60, 0x82, 0x90, 0x00},
constructor<FinEIDv4>},
// LatEID Idemia v1.0
{{0x3b, 0xdd, 0x18, 0x00, 0x81, 0x31, 0xfe, 0x45, 0x90, 0x4c, 0x41,
0x54, 0x56, 0x49, 0x41, 0x2d, 0x65, 0x49, 0x44, 0x90, 0x00, 0x8c},
constructor<LatEIDIDEMIAV1>},
// LatEID Idemia v2.0
{{0x3b, 0xdb, 0x96, 0x00, 0x80, 0xb1, 0xfe, 0x45, 0x1f, 0x83, 0x00,
0x12, 0x42, 0x8f, 0x53, 0x65, 0x49, 0x44, 0x0f, 0x90, 0x00, 0x20},
Expand Down
89 changes: 38 additions & 51 deletions src/electronic-ids/pcsc/EIDIDEMIA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,46 @@ using namespace electronic_id;
namespace
{

const byte_type PIN_PADDING_CHAR = 0xFF;
const byte_type AUTH_PIN_REFERENCE = 0x01;
constexpr byte_type PIN_PADDING_CHAR = 0xFF;
constexpr byte_type AUTH_PIN_REFERENCE = 0x01;
constexpr byte_type SIGN_PIN_REFERENCE = 0x85;

const auto MAIN_AID = CommandApdu::select(0x04,
{0xA0, 0x00, 0x00, 0x00, 0x77, 0x01, 0x08, 0x00, 0x07,
0x00, 0x00, 0xFE, 0x00, 0x00, 0x01, 0x00});
const auto ADF1_AID = CommandApdu::select(
0x04, {0xe8, 0x28, 0xbd, 0x08, 0x0f, 0xf2, 0x50, 0x4f, 0x54, 0x20, 0x41, 0x57, 0x50});
const auto ADF2_AID = CommandApdu::select(0x04,
{0x51, 0x53, 0x43, 0x44, 0x20, 0x41, 0x70, 0x70, 0x6C,
0x69, 0x63, 0x61, 0x74, 0x69, 0x6F, 0x6E});
const auto AUTH_CERT = CommandApdu::select(0x09, {0xAD, 0xF1, 0x34, 0x01});
const auto SIGN_CERT = CommandApdu::select(0x09, {0xAD, 0xF2, 0x34, 0x1F});

} // namespace

void EIDIDEMIA::selectADF1() const
{
transmitApduWithExpectedResponse(*card, ADF1_AID);
}

void EIDIDEMIA::selectADF2() const
{
transmitApduWithExpectedResponse(*card, ADF2_AID);
}

byte_vector EIDIDEMIA::getCertificateImpl(const CertificateType type) const
{
transmitApduWithExpectedResponse(*card, selectApplicationID().MAIN_AID);
return electronic_id::getCertificate(*card,
type.isAuthentication() ? selectCertificate().AUTH_CERT
: selectCertificate().SIGN_CERT);
transmitApduWithExpectedResponse(*card, MAIN_AID);
return electronic_id::getCertificate(*card, type.isAuthentication() ? AUTH_CERT : SIGN_CERT);
}

byte_vector EIDIDEMIA::signWithAuthKeyImpl(byte_vector&& pin, const byte_vector& hash) const
{
// Select authentication application and authentication security environment.
transmitApduWithExpectedResponse(*card, selectApplicationID().MAIN_AID);
transmitApduWithExpectedResponse(*card, selectApplicationID().AUTH_AID);
selectADF1();
selectAuthSecurityEnv();

verifyPin(*card, AUTH_PIN_REFERENCE, std::move(pin), authPinMinMaxLength().first,
pinBlockLength(), PIN_PADDING_CHAR);
authPinMinMaxLength().second, PIN_PADDING_CHAR);

return internalAuthenticate(*card,
authSignatureAlgorithm().isRSAWithPKCS1Padding()
Expand All @@ -62,19 +80,19 @@ byte_vector EIDIDEMIA::signWithAuthKeyImpl(byte_vector&& pin, const byte_vector&

ElectronicID::PinRetriesRemainingAndMax EIDIDEMIA::authPinRetriesLeftImpl() const
{
transmitApduWithExpectedResponse(*card, selectApplicationID().MAIN_AID);
transmitApduWithExpectedResponse(*card, MAIN_AID);
return pinRetriesLeft(AUTH_PIN_REFERENCE);
}

ElectronicID::Signature EIDIDEMIA::signWithSigningKeyImpl(byte_vector&& pin,
const byte_vector& hash,
const HashAlgorithm hashAlgo) const
{
// Select signing application and signing security environment.
transmitApduWithExpectedResponse(*card, selectApplicationID().SIGN_AID);
selectADF2();
pcsc_cpp::byte_type algo = selectSignSecurityEnv();
auto tmp = hash;
if (algo == 0x54) {
bool isECC = algo == 0x54;
if (isECC) {
constexpr size_t ECDSA384_INPUT_LENGTH = 384 / 8;
if (tmp.size() < ECDSA384_INPUT_LENGTH) {
// Zero-pad hashes that are shorter than SHA-384.
Expand All @@ -85,48 +103,17 @@ ElectronicID::Signature EIDIDEMIA::signWithSigningKeyImpl(byte_vector&& pin,
}
}

verifyPin(*card, signingPinReference(), std::move(pin), signingPinMinMaxLength().first,
pinBlockLength(), PIN_PADDING_CHAR);
verifyPin(*card, SIGN_PIN_REFERENCE, std::move(pin), signingPinMinMaxLength().first,
signingPinMinMaxLength().second, PIN_PADDING_CHAR);

return {useInternalAuthenticateAndRSAWithPKCS1PaddingDuringSigning()
? internalAuthenticate(*card, addRSAOID(hashAlgo, hash), name())
: computeSignature(*card, tmp, name()),
{signingSignatureAlgorithm(), hashAlgo}};
return {computeSignature(*card, tmp, name()),
{isECC ? SignatureAlgorithm::ES : SignatureAlgorithm::RS, hashAlgo}};
}

ElectronicID::PinRetriesRemainingAndMax EIDIDEMIA::signingPinRetriesLeftImpl() const
{
transmitApduWithExpectedResponse(*card, selectApplicationID().SIGN_AID);
return pinRetriesLeft(signingPinReference());
}

const SelectApplicationIDCmds& EIDIDEMIA::selectApplicationID() const
{
static const SelectApplicationIDCmds selectAppIDCmds {
// Main AID.
CommandApdu::select(0x04,
{0xA0, 0x00, 0x00, 0x00, 0x77, 0x01, 0x08, 0x00, 0x07, 0x00, 0x00, 0xFE,
0x00, 0x00, 0x01, 0x00}),
// AWP AID.
CommandApdu::select(
0x04, {0xe8, 0x28, 0xbd, 0x08, 0x0f, 0xf2, 0x50, 0x4f, 0x54, 0x20, 0x41, 0x57, 0x50}),
// QSCD AID.
CommandApdu::select(0x04,
{0x51, 0x53, 0x43, 0x44, 0x20, 0x41, 0x70, 0x70, 0x6C, 0x69, 0x63, 0x61,
0x74, 0x69, 0x6F, 0x6E}),
};
return selectAppIDCmds;
}

const SelectCertificateCmds& EIDIDEMIA::selectCertificate() const
{
static const SelectCertificateCmds selectCert1Cmds {
// Authentication certificate.
CommandApdu::select(0x09, {0xAD, 0xF1, 0x34, 0x01}),
// Signing certificate.
CommandApdu::select(0x09, {0xAD, 0xF2, 0x34, 0x1F}),
};
return selectCert1Cmds;
selectADF2();
return pinRetriesLeft(SIGN_PIN_REFERENCE);
}

ElectronicID::PinRetriesRemainingAndMax EIDIDEMIA::pinRetriesLeft(byte_type pinReference) const
Expand Down
29 changes: 4 additions & 25 deletions src/electronic-ids/pcsc/EIDIDEMIA.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,6 @@
namespace electronic_id
{

struct SelectApplicationIDCmds
{
const pcsc_cpp::CommandApdu MAIN_AID;
const pcsc_cpp::CommandApdu AUTH_AID;
const pcsc_cpp::CommandApdu SIGN_AID;
};

struct SelectCertificateCmds
{
const pcsc_cpp::CommandApdu AUTH_CERT;
const pcsc_cpp::CommandApdu SIGN_CERT;
};

class EIDIDEMIA : public PcscElectronicID
{
public:
Expand All @@ -49,26 +36,18 @@ class EIDIDEMIA : public PcscElectronicID
byte_vector getCertificateImpl(const CertificateType type) const override;

PinRetriesRemainingAndMax authPinRetriesLeftImpl() const override;
virtual void selectAuthSecurityEnv() const = 0;
byte_vector signWithAuthKeyImpl(byte_vector&& pin, const byte_vector& hash) const override;

PinRetriesRemainingAndMax signingPinRetriesLeftImpl() const override;
virtual pcsc_cpp::byte_type selectSignSecurityEnv() const = 0;
Signature signWithSigningKeyImpl(byte_vector&& pin, const byte_vector& hash,
const HashAlgorithm hashAlgo) const override;

virtual const SelectApplicationIDCmds& selectApplicationID() const;
virtual const SelectCertificateCmds& selectCertificate() const;
virtual void selectAuthSecurityEnv() const = 0;
virtual pcsc_cpp::byte_type selectSignSecurityEnv() const = 0;

virtual size_t pinBlockLength() const { return authPinMinMaxLength().second; }
virtual byte_type signingPinReference() const { return 0x85; }
virtual SignatureAlgorithm signingSignatureAlgorithm() const = 0;
PinRetriesRemainingAndMax pinRetriesLeft(byte_type pinReference) const;

virtual bool useInternalAuthenticateAndRSAWithPKCS1PaddingDuringSigning() const
{
return false;
}
void selectADF1() const;
void selectADF2() const;
};

} // namespace electronic_id
1 change: 0 additions & 1 deletion src/electronic-ids/pcsc/EstEIDIDEMIA.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class EstEIDIDEMIAV1 : public EIDIDEMIA
PinMinMaxLength authPinMinMaxLength() const override { return {4, 12}; }

const std::set<SignatureAlgorithm>& supportedSigningAlgorithms() const override;
SignatureAlgorithm signingSignatureAlgorithm() const override { return SignatureAlgorithm::ES; }
PinMinMaxLength signingPinMinMaxLength() const override { return {5, 12}; }

std::string name() const override { return "EstEID IDEMIA v1"; }
Expand Down
42 changes: 0 additions & 42 deletions src/electronic-ids/pcsc/LatEIDIDEMIACommon.hpp

This file was deleted.

73 changes: 0 additions & 73 deletions src/electronic-ids/pcsc/LatEIDIDEMIAv1.cpp

This file was deleted.

Loading
Loading