Skip to content

Commit 92570fd

Browse files
authored
Search also from Thales LDAP (#1345)
IB-8403 Signed-off-by: Raul Metsma <[email protected]>
1 parent 61f50b3 commit 92570fd

File tree

6 files changed

+46
-49
lines changed

6 files changed

+46
-49
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ set_env( TSL_URL "https://ec.europa.eu/tools/lotl/eu-lotl.xml" CACHE STRING "TSL
1717
set_env( TSL_INCLUDE "EE" CACHE STRING "TSL list include in binary" )
1818
set_env(CDOC2_GET_URL "https://cdoc2.id.ee:8444" CACHE STRING "CDoc 2.0 Key Server get URL")
1919
set_env(CDOC2_POST_URL "https://cdoc2.id.ee:8443" CACHE STRING "CDoc 2.0 Key Server post URL")
20-
set_env( MOBILEID_URL "https://dd-mid.ria.ee/mid-api" CACHE STRING "URL for Mobile-ID" )
21-
set_env( SMARTID_URL "https://dd-sid.ria.ee/v1" CACHE STRING "URL for Smart-ID" )
20+
set_env(MOBILEID_URL "https://eid-dd.ria.ee/mid" CACHE STRING "URL for Mobile-ID")
21+
set_env(SMARTID_URL "https://eid-dd.ria.ee/sid/v2" CACHE STRING "URL for Smart-ID")
2222
set(VERSION ${PROJECT_VERSION}.${BUILD_NUMBER})
2323
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
2424
set(CMAKE_INCLUDE_CURRENT_DIR ON)

client/LdapSearch.cpp

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ using namespace std::chrono;
5050
template<typename T>
5151
static constexpr auto TO_QSTR(const T *str)
5252
{
53-
if constexpr (std::is_same<T,char>::value)
53+
if constexpr (std::is_same_v<T,char>)
5454
return QLatin1String(str);
5555
else
5656
return QStringView(str);
@@ -60,15 +60,15 @@ class LdapSearch::Private
6060
{
6161
public:
6262
LDAP *ldap {};
63-
QByteArray host;
63+
QUrl url;
6464
QTimer *timer {};
6565
};
6666

67-
LdapSearch::LdapSearch(QByteArray host, QObject *parent)
67+
LdapSearch::LdapSearch(const QString &url, QObject *parent)
6868
: QObject( parent )
6969
, d(new Private)
7070
{
71-
d->host = std::move(host);
71+
d->url = QUrl(url);
7272
d->timer = new QTimer(this);
7373
d->timer->setSingleShot(true);
7474
connect(d->timer, &QTimer::timeout, this, [this]{
@@ -94,18 +94,18 @@ bool LdapSearch::init()
9494
}
9595

9696
#ifdef Q_OS_WIN
97-
QUrl url(d->host);
98-
int ssl = url.scheme() == QStringLiteral("ldaps") ? 1 : 0;
99-
QString host = url.host();
100-
ULONG port = ULONG(url.port(ssl ? LDAP_SSL_PORT : LDAP_PORT));
97+
int ssl = d->url.scheme() == QLatin1String("ldaps") ? 1 : 0;
98+
QString host = d->url.host();
99+
ULONG port = ULONG(d->url.port(ssl ? LDAP_SSL_PORT : LDAP_PORT));
101100
if(d->ldap = ldap_sslinit(TO_STR(host), port, ssl); !d->ldap)
102101
{
103102
setLastError(tr("Failed to init ldap"), int(LdapGetLastError()));
104103
return false;
105104
}
106105
ULONG err = 0;
107106
#else
108-
int err = ldap_initialize(&d->ldap, d->host.constData());
107+
QByteArray host = d->url.toString(QUrl::RemovePath|QUrl::RemoveQuery|QUrl::RemoveFragment).toUtf8();
108+
int err = ldap_initialize(&d->ldap, host.constData());
109109
if(err)
110110
{
111111
setLastError(tr("Failed to init ldap"), err);
@@ -148,11 +148,6 @@ bool LdapSearch::init()
148148
return !err;
149149
}
150150

151-
bool LdapSearch::isSSL() const
152-
{
153-
return QUrl(d->host).scheme() == QStringLiteral("ldaps");
154-
}
155-
156151
void LdapSearch::search(const QString &search, const QVariantMap &userData)
157152
{
158153
if(!init())
@@ -166,7 +161,8 @@ void LdapSearch::search(const QString &search, const QVariantMap &userData)
166161
std::array<STR_T, 2> attrs { STR("userCertificate;binary"), nullptr };
167162

168163
ULONG msg_id = 0;
169-
int err = ldap_search_ext(d->ldap, STR("c=EE"), LDAP_SCOPE_SUBTREE,
164+
QString path = d->url.path();
165+
int err = ldap_search_ext(d->ldap, TO_STR(path.isEmpty() ? "c=EE" : path.remove(0, 1)), LDAP_SCOPE_SUBTREE,
170166
TO_STR(search), attrs.data(), 0, nullptr, nullptr, LDAP_NO_LIMIT, LDAP_NO_LIMIT, &msg_id);
171167
if(err)
172168
return setLastError( tr("Failed to init ldap search"), err );
@@ -175,8 +171,7 @@ void LdapSearch::search(const QString &search, const QVariantMap &userData)
175171
connect(timer, &QTimer::timeout, this, [this, msg_id, timer, userData] {
176172
LDAPMessage *result = nullptr;
177173
LDAP_TIMEVAL t { 5, 0 };
178-
int err = ldap_result(d->ldap, msg_id, LDAP_MSG_ALL, &t, &result);
179-
switch(err)
174+
switch(int err = ldap_result(d->ldap, msg_id, LDAP_MSG_ALL, &t, &result))
180175
{
181176
case LDAP_SUCCESS: //Timeout
182177
return;

client/LdapSearch.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ class LdapSearch final: public QObject
2727
Q_OBJECT
2828

2929
public:
30-
LdapSearch(QByteArray host, QObject *parent = nullptr);
30+
LdapSearch(const QString &url, QObject *parent = nullptr);
3131
~LdapSearch() final;
3232

33-
bool isSSL() const;
3433
void search(const QString &search, const QVariantMap &userData);
3534

3635
Q_SIGNALS:

client/dialogs/AddRecipients.cpp

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
#include "Application.h"
2525
#include "CheckConnection.h"
26-
#include "common_enums.h"
2726
#include "FileDialog.h"
2827
#include "IKValidator.h"
2928
#include "LdapSearch.h"
@@ -32,20 +31,28 @@
3231
#include "TokenData.h"
3332
#include "dialogs/WarningDialog.h"
3433
#include "effects/Overlay.h"
34+
#include "widgets/AddressItem.h"
35+
#include "widgets/ItemList.h"
3536

3637
#include <QtCore/QDateTime>
3738
#include <QtCore/QJsonArray>
38-
#include <QtCore/QJsonObject>
3939
#include <QtNetwork/QSslConfiguration>
4040
#include <QtNetwork/QSslError>
4141
#include <QtWidgets/QMessageBox>
4242

4343
AddRecipients::AddRecipients(ItemList* itemList, QWidget *parent)
4444
: QDialog(parent)
4545
, ui(new Ui::AddRecipients)
46-
, ldap_person(new LdapSearch(defaultUrl(QLatin1String("LDAP-PERSON-URL"), QStringLiteral("ldaps://esteid.ldap.sk.ee")).toUtf8(), this))
47-
, ldap_corp(new LdapSearch(defaultUrl(QLatin1String("LDAP-CORP-URL"), QStringLiteral("ldaps://k3.ldap.sk.ee")).toUtf8(), this))
46+
, ldap_corp(new LdapSearch(Application::confValue(QLatin1String("LDAP-CORP-URL")).toString(QStringLiteral("ldaps://k3.ldap.sk.ee")), this))
4847
{
48+
for(const auto list = Application::confValue(QLatin1String("LDAP-PERSON-URLS")).toArray(); auto url: list) {
49+
ldap_person.append(new LdapSearch(url.toString(), this));
50+
}
51+
if(ldap_person.isEmpty()) {
52+
ldap_person.append(new LdapSearch(QStringLiteral("ldaps://esteid.ldap.sk.ee"), this));
53+
ldap_person.append(new LdapSearch(QStringLiteral("ldaps://ldap.eidpki.ee/dc=eidpki,dc=ee"), this));
54+
}
55+
4956
ui->setupUi(this);
5057
#if defined (Q_OS_WIN)
5158
ui->actionLayout->setDirection(QBoxLayout::RightToLeft);
@@ -62,9 +69,11 @@ AddRecipients::AddRecipients(ItemList* itemList, QWidget *parent)
6269
ui->leftPane->clear();
6370
search(term);
6471
});
65-
connect(ldap_person, &LdapSearch::searchResult, this, &AddRecipients::showResult);
72+
for(auto ldap: ldap_person) {
73+
connect(ldap, &LdapSearch::searchResult, this, &AddRecipients::showResult);
74+
connect(ldap, &LdapSearch::error, this, &AddRecipients::showError);
75+
}
6676
connect(ldap_corp, &LdapSearch::searchResult, this, &AddRecipients::showResult);
67-
connect(ldap_person, &LdapSearch::error, this, &AddRecipients::showError);
6877
connect(ldap_corp, &LdapSearch::error, this, &AddRecipients::showError);
6978
connect(this, &AddRecipients::finished, this, &AddRecipients::close);
7079

@@ -139,7 +148,7 @@ void AddRecipients::addRecipientFromHistory()
139148

140149
ui->leftPane->clear();
141150
for(const HistoryCertData &certData: selectedCertData) {
142-
QString term = (certData.type == QStringLiteral("1") || certData.type == QStringLiteral("3")) ? certData.CN : certData.CN.split(',').value(2);
151+
QString term = (certData.type == QLatin1String("1") || certData.type == QLatin1String("3")) ? certData.CN : certData.CN.split(',').value(2);
143152
search(term, true, certData.type);
144153
}
145154
});
@@ -153,13 +162,11 @@ void AddRecipients::addRecipient(const QSslCertificate& cert, bool select)
153162
{
154163
leftItem = new AddressItem(cert, AddressItem::Add, ui->leftPane);
155164
ui->leftPane->addWidget(leftItem);
156-
bool contains = rightList.contains(cert);
157-
leftItem->setDisabled(contains);
165+
leftItem->setDisabled(rightList.contains(cert));
158166
connect(leftItem, &AddressItem::add, this, [this](Item *item) { addRecipientToRightPane(item); });
159167
if(auto *add = ui->leftPane->findChild<QWidget*>(QStringLiteral("add")))
160168
add->setVisible(true);
161169
}
162-
163170
if(select)
164171
addRecipientToRightPane(leftItem);
165172
}
@@ -202,7 +209,6 @@ void AddRecipients::addRecipientToRightPane(Item *item, bool update)
202209
return;
203210
}
204211
}
205-
updated = update;
206212

207213
rightList.append(key);
208214

@@ -212,7 +218,6 @@ void AddRecipients::addRecipientToRightPane(Item *item, bool update)
212218
if(auto *leftItem = itemListValue(ui->leftPane, rightItem->getKey().cert))
213219
leftItem->setDisabled(false);
214220
rightList.removeAll(rightItem->getKey());
215-
updated = true;
216221
ui->confirm->setDisabled(rightList.isEmpty());
217222
});
218223
ui->rightPane->addWidget(rightItem);
@@ -222,14 +227,9 @@ void AddRecipients::addRecipientToRightPane(Item *item, bool update)
222227
leftItem->setDisabled(true);
223228
}
224229

225-
QString AddRecipients::defaultUrl(QLatin1String key, const QString &defaultValue)
226-
{
227-
return Application::confValue(key).toString(defaultValue);
228-
}
229-
230230
bool AddRecipients::isUpdated() const
231231
{
232-
return updated;
232+
return ui->confirm->isEnabled();
233233
}
234234

235235
AddressItem* AddRecipients::itemListValue(ItemList *list, const CKey &cert)
@@ -273,6 +273,7 @@ void AddRecipients::search(const QString &term, bool select, const QString &type
273273
.replace(QStringLiteral("("), QStringLiteral("\\("))
274274
.replace(QStringLiteral(")"), QStringLiteral("\\)"));
275275
#endif
276+
multiSearch = 0;
276277
bool isDigit = false;
277278
void(cleanTerm.toULongLong(&isDigit));
278279
if(!isDigit || (cleanTerm.size() != 11 && cleanTerm.size() != 8))
@@ -282,7 +283,10 @@ void AddRecipients::search(const QString &term, bool select, const QString &type
282283
else if(IKValidator::isValid(cleanTerm))
283284
{
284285
userData[QStringLiteral("personSearch")] = true;
285-
ldap_person->search(QStringLiteral("(serialNumber=%1%2)" ).arg(ldap_person->isSSL() ? QStringLiteral("PNOEE-") : QString(), cleanTerm), userData);
286+
for(auto *ldap: ldap_person) {
287+
ldap->search(QStringLiteral("(serialNumber=PNOEE-%1)").arg(cleanTerm), userData);
288+
++multiSearch;
289+
}
286290
}
287291
else
288292
{
@@ -314,7 +318,7 @@ void AddRecipients::showResult(const QList<QSslCertificate> &result, int resultC
314318
}
315319
if(resultCount >= 50)
316320
showError(tr("The name you were looking for gave too many results, please refine your search."));
317-
else if(ui->leftPane->items.isEmpty())
321+
else if(--multiSearch <= 0 && ui->leftPane->items.isEmpty())
318322
{
319323
showError(tr("Person or company does not own a valid certificate.<br />"
320324
"It is necessary to have a valid certificate for encryption.<br />"

client/dialogs/AddRecipients.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@
2020
#pragma once
2121

2222
#include "CertificateHistory.h"
23-
#include "widgets/AddressItem.h"
24-
#include "widgets/ItemList.h"
2523

2624
#include <QDialog>
27-
#include <QHash>
2825

2926
namespace Ui {
3027
class AddRecipients;
3128
}
3229

30+
class AddressItem;
31+
class Item;
32+
class ItemList;
3333
class LdapSearch;
3434
class QSslCertificate;
3535

@@ -50,17 +50,17 @@ class AddRecipients final : public QDialog
5050
void addRecipient(const QSslCertificate& cert, bool select = true);
5151
void addRecipientToRightPane(Item *item, bool update = true);
5252

53-
AddressItem* itemListValue(ItemList *list, const CKey &cert);
5453
void search(const QString &term, bool select = false, const QString &type = {});
5554
void showError(const QString &msg, const QString &details = {});
5655
void showResult(const QList<QSslCertificate> &result, int resultCount, const QVariantMap &userData);
5756

58-
static QString defaultUrl(QLatin1String key, const QString &defaultValue);
57+
static AddressItem* itemListValue(ItemList *list, const CKey &cert);
5958

6059
Ui::AddRecipients *ui;
6160
QList<CKey> rightList;
62-
LdapSearch *ldap_person, *ldap_corp;
63-
bool updated = false;
61+
QList<LdapSearch*> ldap_person;
62+
LdapSearch *ldap_corp;
63+
int multiSearch = 0;
6464

6565
HistoryList historyCertData;
6666
};

client/widgets/ItemList.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ void ItemList::init(ItemType item, const char *header)
171171
{
172172
itemType = item;
173173
ui->listHeader->setText(tr(header));
174-
ui->listHeader->setAccessibleName(tr(header));
175174
listText = header;
176175
ui->listHeader->setFont( Styles::font(Styles::Regular, 20));
177176

0 commit comments

Comments
 (0)