Skip to content

Commit dbc9323

Browse files
committed
Select card
1 parent 0501517 commit dbc9323

5 files changed

Lines changed: 5 additions & 43 deletions

File tree

client/QCNG.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "SslCertificate.h"
2424
#include "TokenData.h"
2525

26+
#include <QtCore/QUuid>
2627
#include <QtCore/QLoggingCategory>
2728
#include <QtNetwork/QSslKey>
2829

@@ -220,7 +221,8 @@ QList<TokenData> QCNG::tokens() const
220221
if(QByteArray tmp = prop(key, NCRYPT_READER_PROPERTY); !tmp.isEmpty())
221222
reader = QString::fromUtf16((const char16_t*)tmp.data());
222223
}
223-
QString guid = prop(h, NCRYPT_SMARTCARD_GUID_PROPERTY).trimmed();
224+
QByteArray guidData = prop(h, NCRYPT_SMARTCARD_GUID_PROPERTY);
225+
QString guid = guidData[0] >= 0x20 && guidData[0] < 0x7F ? guidData.trimmed() : QUuid(*((GUID*)guidData.data())).toString(QUuid::WithBraces);
224226
TokenData &t = result.emplaceBack();
225227
t.setReader(reader);
226228
t.setCard(cert.type() & SslCertificate::EstEidType || cert.type() & SslCertificate::DigiIDType ?
@@ -232,7 +234,8 @@ QList<TokenData> QCNG::tokens() const
232234
qCWarning(CNG) << "key" << t.data(u"provider"_s)
233235
<< "spec" << t.data(u"spec"_s)
234236
<< "alg" << QStringView(keyname->pszAlgid)
235-
<< "flags" << keyname->dwFlags;
237+
<< "flags" << keyname->dwFlags
238+
<< t.card();
236239
if(cert.publicKey().algorithm() != QSsl::Rsa || reader.isEmpty())
237240
continue;
238241

client/QSigner.cpp

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -150,42 +150,6 @@ QSigner::~QSigner()
150150

151151
QList<TokenData> QSigner::cache() const { return d->cache; }
152152

153-
bool QSigner::cardsOrder(const TokenData &s1, const TokenData &s2)
154-
{
155-
static auto cardsOrderScore = [](QChar c) -> quint8 {
156-
switch(c.toLatin1())
157-
{
158-
case 'N': return 6;
159-
case 'A': return 5;
160-
case 'P': return 4;
161-
case 'E': return 3;
162-
case 'F': return 2;
163-
case 'B': return 1;
164-
default: return 0;
165-
}
166-
};
167-
static const QRegularExpression reg(QStringLiteral("(\\w{1,2})(\\d{7})"));
168-
QRegularExpressionMatch r1 = reg.match(s1.card());
169-
QRegularExpressionMatch r2 = reg.match(s2.card());
170-
if(r1.hasMatch() || r2.hasMatch())
171-
return false;
172-
QStringList cap1 = r1.capturedTexts();
173-
QStringList cap2 = r1.capturedTexts();
174-
if(cap1.isEmpty() || cap2.isEmpty())
175-
return false;
176-
// new cards to front
177-
if(cap1[1].size() != cap2[1].size())
178-
return cap1[1].size() > cap2[1].size();
179-
// card type order
180-
if(cap1[1][0] != cap2[1][0])
181-
return cardsOrderScore(cap1[1][0]) > cardsOrderScore(cap2[1][0]);
182-
// card version order
183-
if(cap1[1].size() > 1 && cap2[1].size() > 1 && cap1[1][1] != cap2[1][1])
184-
return cap1[1][1] > cap2[1][1];
185-
// serial number order
186-
return cap1[2].toUInt() > cap2[2].toUInt();
187-
}
188-
189153
X509Cert QSigner::cert() const
190154
{
191155
if( d->sign.cert().isNull() )
@@ -322,7 +286,6 @@ void QSigner::run()
322286

323287
QList<TokenData> acards, scards;
324288
QList<TokenData> cache = d->backend->tokens();
325-
std::sort(cache.begin(), cache.end(), cardsOrder);
326289
if(cache != d->cache)
327290
{
328291
d->cache = std::move(cache);

client/QSigner.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ class QSigner final: public QThread, public digidoc::Signer
5858
void error( const QString &msg );
5959

6060
private:
61-
static bool cardsOrder(const TokenData &s1, const TokenData &s2);
6261
quint8 login(const TokenData &cert) const;
6362
static QCryptographicHash::Algorithm methodToNID(const std::string &method);
6463
void run() final;

client/TokenData.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ bool TokenData::isNull() const {
5858
TokenData& TokenData::operator =( const TokenData &other ) = default;
5959
TokenData& TokenData::operator =(TokenData &&other) Q_DECL_NOEXCEPT = default;
6060

61-
bool TokenData::operator !=( const TokenData &other ) const { return !(operator==(other)); }
62-
6361
bool TokenData::operator ==( const TokenData &other ) const
6462
{
6563
return d == other.d || (

client/TokenData.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ class TokenData
4848

4949
TokenData& operator =( const TokenData &other );
5050
TokenData& operator =(TokenData &&other) Q_DECL_NOEXCEPT;
51-
bool operator !=( const TokenData &other ) const;
5251
bool operator ==( const TokenData &other ) const;
5352

5453
private:

0 commit comments

Comments
 (0)