-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathPasskeyUtils.h
More file actions
84 lines (70 loc) · 3.07 KB
/
PasskeyUtils.h
File metadata and controls
84 lines (70 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
* Copyright (C) 2026 KeePassXC Team <team@keepassxc.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PASSKEYUTILS_H
#define PASSKEYUTILS_H
#include <QJsonArray>
#include <QJsonObject>
#include <QObject>
#include <QStringList>
#include "BrowserCbor.h"
#include "core/Entry.h"
#define DEFAULT_TIMEOUT 300000
#define DEFAULT_DISCOURAGED_TIMEOUT 120000
#define PASSKEYS_SUCCESS 0
struct ExtensionResult
{
QByteArray extensionData;
QJsonObject extensionObject;
};
class PasskeyUtils : public QObject
{
Q_OBJECT
public:
explicit PasskeyUtils() = default;
~PasskeyUtils() = default;
static PasskeyUtils* instance();
int checkLimits(const QJsonObject& pkOptions) const;
bool checkCredentialCreationOptions(const QJsonObject& credentialCreationOptions) const;
bool checkCredentialAssertionOptions(const QJsonObject& assertionOptions) const;
int getEffectiveDomain(const QString& origin, QString* result) const;
int validateRpId(const QJsonValue& rpIdValue, const QString& effectiveDomain, QString* result) const;
bool validateRelatedOrigins(const QStringList& relatedOrigins, const QString& origin) const;
QString parseAttestation(const QString& attestation) const;
QJsonArray parseCredentialTypes(const QJsonArray& credentialTypes) const;
bool isAuthenticatorSelectionValid(const QJsonObject& authenticatorSelection) const;
bool isUserVerificationValid(const QString& userVerification) const;
bool isResidentKeyRequired(const QJsonObject& authenticatorSelection) const;
bool isUserVerificationRequired(const QJsonObject& authenticatorSelection) const;
bool isOriginAllowedWithLocalhost(bool allowLocalhostWithPasskeys, const QString& origin) const;
ExtensionResult buildExtensionData(QJsonObject& extensionObject) const;
QString buildClientDataJson(const QJsonObject& publicKey, const QString& origin, bool get) const;
QStringList getAllowedCredentialsFromAssertionOptions(const QJsonObject& assertionOptions) const;
QString getCredentialIdFromEntry(const Entry* entry) const;
QString getUsernameFromEntry(const Entry* entry) const;
private:
Q_DISABLE_COPY(PasskeyUtils);
bool isRegistrableDomainSuffix(const QString& hostSuffixString, const QString& originalHost) const;
bool isDomain(const QString& hostName) const;
friend class TestPasskeys;
private:
BrowserCbor m_browserCbor;
};
static inline PasskeyUtils* passkeyUtils()
{
return PasskeyUtils::instance();
}
#endif // PASSKEYUTILS_H