Messagelib

dkimchecksignaturejob.h
1/*
2 SPDX-FileCopyrightText: 2018-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "messageviewer_export.h"
10#include <KMime/Message>
11#include <MessageViewer/DKIMCheckPolicy>
12#include <MessageViewer/DKIMHeaderParser>
13#include <MessageViewer/DKIMInfo>
14#include <MessageViewer/DKIMKeyRecord>
15#include <QObject>
16
17namespace MessageViewer
18{
19/**
20 * @brief The DKIMCheckSignatureJob class
21 * @author Laurent Montel <montel@kde.org>
22 */
23class MESSAGEVIEWER_EXPORT DKIMCheckSignatureJob : public QObject
24{
25 Q_OBJECT
26public:
27 enum class DKIMStatus : uint8_t {
28 Unknown = 0,
29 Valid = 1,
30 Invalid = 2,
31 EmailNotSigned = 3,
32 NeedToBeSigned = 4,
33 };
34 Q_ENUM(DKIMStatus)
35
36 enum class DKIMError : uint8_t {
37 Any = 0,
38 CorruptedBodyHash = 1,
39 DomainNotExist = 2,
40 MissingFrom = 3,
41 MissingSignature = 4,
42 InvalidQueryMethod = 5,
43 InvalidHeaderCanonicalization = 6,
44 InvalidBodyCanonicalization = 7,
45 InvalidBodyHashAlgorithm = 8,
46 InvalidSignAlgorithm = 9,
47 PublicKeyWasRevoked = 10,
48 SignatureTooLarge = 11,
49 InsupportedHashAlgorithm = 12,
50 PublicKeyTooSmall = 13,
51 ImpossibleToVerifySignature = 14,
52 DomainI = 15,
53 TestKeyMode = 16,
54 ImpossibleToDownloadKey = 17,
55 HashAlgorithmUnsafeSha1 = 18,
56 IDomainError = 19,
57 PublicKeyConversionError = 20,
58 };
59 Q_ENUM(DKIMError)
60 enum class DKIMWarning : uint8_t {
61 Any = 0,
62 SignatureExpired = 1,
63 SignatureCreatedInFuture = 2,
64 SignatureTooSmall = 3,
65 HashAlgorithmUnsafe = 4,
66 PublicRsaKeyTooSmall = 5,
67 };
68 Q_ENUM(DKIMWarning)
69
70 enum class AuthenticationMethod : uint8_t {
71 Unknown = 0,
72 Dkim = 1,
73 Spf = 2,
74 Dmarc = 3,
75 Dkimatps = 4,
76 Auth = 5,
77 };
78 Q_ENUM(AuthenticationMethod)
79
80 struct MESSAGEVIEWER_EXPORT DKIMCheckSignatureAuthenticationResult {
81 QString errorStr;
82 QString infoResult;
83 AuthenticationMethod method = AuthenticationMethod::Unknown;
84 DKIMCheckSignatureJob::DKIMStatus status = DKIMCheckSignatureJob::DKIMStatus::Unknown;
85 QString sdid; // Signing Domain Identifier
86 QString auid; // DKIM MAY optionally provide a single responsible Agent or User Identifier (AUID).
87 [[nodiscard]] bool operator==(const DKIMCheckSignatureAuthenticationResult &other) const;
88 [[nodiscard]] bool isValid() const;
89 };
90
91 struct MESSAGEVIEWER_EXPORT CheckSignatureResult {
92 [[nodiscard]] bool isValid() const;
93
94 [[nodiscard]] bool operator==(const CheckSignatureResult &other) const;
95
96 [[nodiscard]] bool operator!=(const CheckSignatureResult &other) const;
97
98 DKIMCheckSignatureJob::DKIMError error = DKIMCheckSignatureJob::DKIMError::Any;
99 DKIMCheckSignatureJob::DKIMWarning warning = DKIMCheckSignatureJob::DKIMWarning::Any;
100 DKIMCheckSignatureJob::DKIMStatus status = DKIMCheckSignatureJob::DKIMStatus::Unknown;
101 QString sdid; // Signing Domain Identifier
102 QString auid; // DKIM MAY optionally provide a single responsible Agent or User Identifier (AUID).
103 QString fromEmail;
104
105 QList<DKIMCheckSignatureAuthenticationResult> listSignatureAuthenticationResult;
106 };
107
108 explicit DKIMCheckSignatureJob(QObject *parent = nullptr);
109 ~DKIMCheckSignatureJob() override;
110 void start();
111
112 [[nodiscard]] QString dkimValue() const;
113
114 [[nodiscard]] DKIMCheckSignatureJob::DKIMStatus status() const;
115 void setStatus(MessageViewer::DKIMCheckSignatureJob::DKIMStatus status);
116
117 [[nodiscard]] MessageViewer::DKIMCheckSignatureJob::DKIMStatus checkSignature(const MessageViewer::DKIMInfo &info);
118
119 [[nodiscard]] DKIMCheckSignatureJob::DKIMError error() const;
120
121 [[nodiscard]] KMime::Message::Ptr message() const;
122 void setMessage(const KMime::Message::Ptr &message);
123
124 [[nodiscard]] DKIMCheckSignatureJob::DKIMWarning warning() const;
125 void setWarning(MessageViewer::DKIMCheckSignatureJob::DKIMWarning warning);
126
127 [[nodiscard]] QString headerCanonizationResult() const;
128
129 [[nodiscard]] QString bodyCanonizationResult() const;
130
131 [[nodiscard]] DKIMCheckPolicy policy() const;
132 void setPolicy(const DKIMCheckPolicy &policy);
133
134 void setHeaderParser(const DKIMHeaderParser &headerParser);
135
136 void setCheckSignatureAuthenticationResult(const QList<DKIMCheckSignatureJob::DKIMCheckSignatureAuthenticationResult> &lst);
137
138Q_SIGNALS:
139 void result(const MessageViewer::DKIMCheckSignatureJob::CheckSignatureResult &checkResult);
140 void storeKey(const QString &key, const QString &domain, const QString &selector);
141
142private:
143 MESSAGEVIEWER_NO_EXPORT void downloadKey(const DKIMInfo &info);
144 MESSAGEVIEWER_NO_EXPORT void slotDownloadKeyDone(const QList<QByteArray> &lst, const QString &domain, const QString &selector);
145 MESSAGEVIEWER_NO_EXPORT void parseDKIMKeyRecord(const QString &str, const QString &domain, const QString &selector, bool storeKeyValue = true);
146 [[nodiscard]] MESSAGEVIEWER_NO_EXPORT QString headerCanonizationSimple() const;
147 [[nodiscard]] MESSAGEVIEWER_NO_EXPORT QString headerCanonizationRelaxed(bool removeQuoteOnContentType) const;
148 [[nodiscard]] MESSAGEVIEWER_NO_EXPORT QString bodyCanonizationRelaxed() const;
149 [[nodiscard]] MESSAGEVIEWER_NO_EXPORT QString bodyCanonizationSimple() const;
150 [[nodiscard]] MESSAGEVIEWER_NO_EXPORT MessageViewer::DKIMCheckSignatureJob::CheckSignatureResult createCheckResult() const;
151 MESSAGEVIEWER_NO_EXPORT void verifySignature();
152 MESSAGEVIEWER_NO_EXPORT void verifyRSASignature();
153 MESSAGEVIEWER_NO_EXPORT void verifyEd25519Signature();
154 MESSAGEVIEWER_NO_EXPORT void computeHeaderCanonization(bool removeQuoteOnContentType);
155 MESSAGEVIEWER_NO_EXPORT void verificationFailed(DKIMError error);
156
158 DKIMCheckPolicy mPolicy;
159 DKIMHeaderParser mHeaderParser;
160 KMime::Message::Ptr mMessage;
161 QString mFromEmail;
162 DKIMInfo mDkimInfo;
163 DKIMKeyRecord mDkimKeyRecord;
164 QString mDkimValue;
165 QString mHeaderCanonizationResult;
166 QString mBodyCanonizationResult;
167 DKIMCheckSignatureJob::DKIMError mError = DKIMCheckSignatureJob::DKIMError::Any;
168 DKIMCheckSignatureJob::DKIMWarning mWarning = DKIMCheckSignatureJob::DKIMWarning::Any;
169 DKIMCheckSignatureJob::DKIMStatus mStatus = DKIMCheckSignatureJob::DKIMStatus::Unknown;
170};
171}
172MESSAGEVIEWER_EXPORT QDebug operator<<(QDebug d, const MessageViewer::DKIMCheckSignatureJob::CheckSignatureResult &t);
173MESSAGEVIEWER_EXPORT QDebug operator<<(QDebug d, const MessageViewer::DKIMCheckSignatureJob::DKIMCheckSignatureAuthenticationResult &t);
174Q_DECLARE_METATYPE(MessageViewer::DKIMCheckSignatureJob::CheckSignatureResult)
175Q_DECLARE_TYPEINFO(MessageViewer::DKIMCheckSignatureJob::DKIMCheckSignatureAuthenticationResult, Q_RELOCATABLE_TYPE);
The DKIMCheckPolicy class.
The DKIMCheckSignatureJob class.
The DKIMHeaderParser class.
The DKIMInfo class.
Definition dkiminfo.h:20
The DKIMKeyRecord class.
Q_SCRIPTABLE CaptureState status()
Q_SCRIPTABLE Q_NOREPLY void start()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:07:25 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.