Skip to content

Commit 3679ad1

Browse files
committed
Add SHA256 and SHA512 to supported ECC hash algorithms
WE2-861 Signed-off-by: Raul Metsma <raul@metsma.ee>
1 parent 1e6e8cc commit 3679ad1

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/controller/command-handlers/authenticate.cpp

+15-12
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,20 @@ QVariantMap createAuthenticationToken(const QString& signatureAlgorithm,
5151
{"format", QStringLiteral("web-eid:1.0")},
5252
{"appVersion",
5353
QStringLiteral("https://web-eid.eu/web-eid-app/releases/%1")
54-
.arg(qApp->applicationVersion())},
54+
.arg(QApplication::applicationVersion())},
5555
};
5656
}
5757

5858
QByteArray createSignature(const QString& origin, const QString& challengeNonce,
5959
const ElectronicID& eid, const pcsc_cpp::byte_vector& pin)
6060
{
61-
static const auto SIGNATURE_ALGO_TO_HASH =
62-
std::map<JsonWebSignatureAlgorithm, QCryptographicHash::Algorithm> {
61+
static const std::map<JsonWebSignatureAlgorithm, QCryptographicHash::Algorithm>
62+
SIGNATURE_ALGO_TO_HASH {
6363
{JsonWebSignatureAlgorithm::RS256, QCryptographicHash::Sha256},
6464
{JsonWebSignatureAlgorithm::PS256, QCryptographicHash::Sha256},
65+
{JsonWebSignatureAlgorithm::ES256, QCryptographicHash::Sha256},
6566
{JsonWebSignatureAlgorithm::ES384, QCryptographicHash::Sha384},
67+
{JsonWebSignatureAlgorithm::ES512, QCryptographicHash::Sha512},
6668
};
6769

6870
if (!SIGNATURE_ALGO_TO_HASH.count(eid.authSignatureAlgorithm())) {
@@ -80,8 +82,8 @@ QByteArray createSignature(const QString& origin, const QString& challengeNonce,
8082
// The value that is signed is hash(origin)+hash(challenge).
8183
const auto hashToBeSignedQBytearray =
8284
QCryptographicHash::hash(originHash + challengeNonceHash, hashAlgo);
83-
const auto hashToBeSigned =
84-
pcsc_cpp::byte_vector {hashToBeSignedQBytearray.cbegin(), hashToBeSignedQBytearray.cend()};
85+
const pcsc_cpp::byte_vector hashToBeSigned {hashToBeSignedQBytearray.cbegin(),
86+
hashToBeSignedQBytearray.cend()};
8587

8688
const auto signature = eid.signWithAuthKey(pin, hashToBeSigned);
8789

@@ -95,11 +97,12 @@ QByteArray createSignature(const QString& origin, const QString& challengeNonce,
9597
Authenticate::Authenticate(const CommandWithArguments& cmd) : CertificateReader(cmd)
9698
{
9799
const auto arguments = cmd.second;
98-
requireArgumentsAndOptionalLang({"challengeNonce", "origin"}, arguments,
99-
"\"challengeNonce\": \"<challenge nonce>\", "
100-
"\"origin\": \"<origin URL>\"");
100+
requireArgumentsAndOptionalLang(
101+
{"challengeNonce", "origin"}, arguments,
102+
R"("challengeNonce": "<challenge nonce>", "origin": "<origin URL>")");
101103

102-
challengeNonce = validateAndGetArgument<QString>(QStringLiteral("challengeNonce"), arguments);
104+
challengeNonce = validateAndGetArgument<decltype(challengeNonce)>(
105+
QStringLiteral("challengeNonce"), arguments);
103106
// nonce must contain at least 256 bits of entropy and is usually Base64-encoded, so the
104107
// required byte length is 44, the length of 32 Base64-encoded bytes.
105108
if (challengeNonce.length() < 44) {
@@ -135,10 +138,10 @@ QVariantMap Authenticate::onConfirm(WebEidUI* window,
135138

136139
} catch (const VerifyPinFailed& failure) {
137140
switch (failure.status()) {
138-
case electronic_id::VerifyPinFailed::Status::PIN_ENTRY_CANCEL:
139-
case electronic_id::VerifyPinFailed::Status::PIN_ENTRY_TIMEOUT:
141+
case VerifyPinFailed::Status::PIN_ENTRY_CANCEL:
142+
case VerifyPinFailed::Status::PIN_ENTRY_TIMEOUT:
140143
break;
141-
case electronic_id::VerifyPinFailed::Status::PIN_ENTRY_DISABLED:
144+
case VerifyPinFailed::Status::PIN_ENTRY_DISABLED:
142145
emit retry(RetriableError::PIN_VERIFY_DISABLED);
143146
break;
144147
default:

0 commit comments

Comments
 (0)