Messagelib

dkimchecksignaturejob.h
1 /*
2  SPDX-FileCopyrightText: 2018-2023 Laurent Montel <[email protected]>
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 
17 namespace MessageViewer
18 {
19 /**
20  * @brief The DKIMCheckSignatureJob class
21  * @author Laurent Montel <[email protected]>
22  */
23 class MESSAGEVIEWER_EXPORT DKIMCheckSignatureJob : public QObject
24 {
25  Q_OBJECT
26 public:
27  enum class DKIMStatus : int {
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 : int {
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 : int {
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 : int {
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  Q_REQUIRED_RESULT bool operator==(const DKIMCheckSignatureAuthenticationResult &other) const;
88  Q_REQUIRED_RESULT bool isValid() const;
89  };
90 
91  struct MESSAGEVIEWER_EXPORT CheckSignatureResult {
92  Q_REQUIRED_RESULT bool isValid() const;
93 
94  Q_REQUIRED_RESULT bool operator==(const CheckSignatureResult &other) const;
95 
96  Q_REQUIRED_RESULT 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  QVector<DKIMCheckSignatureAuthenticationResult> listSignatureAuthenticationResult;
106  };
107 
108  explicit DKIMCheckSignatureJob(QObject *parent = nullptr);
109  ~DKIMCheckSignatureJob() override;
110  void start();
111 
112  Q_REQUIRED_RESULT QString dkimValue() const;
113 
114  Q_REQUIRED_RESULT DKIMCheckSignatureJob::DKIMStatus status() const;
115  void setStatus(MessageViewer::DKIMCheckSignatureJob::DKIMStatus status);
116 
117  Q_REQUIRED_RESULT MessageViewer::DKIMCheckSignatureJob::DKIMStatus checkSignature(const MessageViewer::DKIMInfo &info);
118 
119  Q_REQUIRED_RESULT DKIMCheckSignatureJob::DKIMError error() const;
120 
121  Q_REQUIRED_RESULT KMime::Message::Ptr message() const;
122  void setMessage(const KMime::Message::Ptr &message);
123 
124  Q_REQUIRED_RESULT DKIMCheckSignatureJob::DKIMWarning warning() const;
125  void setWarning(MessageViewer::DKIMCheckSignatureJob::DKIMWarning warning);
126 
127  Q_REQUIRED_RESULT QString headerCanonizationResult() const;
128 
129  Q_REQUIRED_RESULT QString bodyCanonizationResult() const;
130 
131  Q_REQUIRED_RESULT DKIMCheckPolicy policy() const;
132  void setPolicy(const DKIMCheckPolicy &policy);
133 
134  void setHeaderParser(const DKIMHeaderParser &headerParser);
135 
136  void setCheckSignatureAuthenticationResult(const QVector<DKIMCheckSignatureJob::DKIMCheckSignatureAuthenticationResult> &lst);
137 
138 Q_SIGNALS:
139  void result(const MessageViewer::DKIMCheckSignatureJob::CheckSignatureResult &checkResult);
140  void storeKey(const QString &key, const QString &domain, const QString &selector);
141 
142 private:
143  void downloadKey(const DKIMInfo &info);
144  void slotDownloadKeyDone(const QList<QByteArray> &lst, const QString &domain, const QString &selector);
145  void parseDKIMKeyRecord(const QString &str, const QString &domain, const QString &selector, bool storeKeyValue = true);
146  Q_REQUIRED_RESULT QString headerCanonizationSimple() const;
147  Q_REQUIRED_RESULT QString headerCanonizationRelaxed(bool removeQuoteOnContentType) const;
148  Q_REQUIRED_RESULT QString bodyCanonizationRelaxed() const;
149  Q_REQUIRED_RESULT QString bodyCanonizationSimple() const;
150  Q_REQUIRED_RESULT MessageViewer::DKIMCheckSignatureJob::CheckSignatureResult createCheckResult() const;
151  void verifySignature();
152  void verifyRSASignature();
153  void verifyEd25519Signature();
154  void computeHeaderCanonization(bool removeQuoteOnContentType);
156  DKIMCheckPolicy mPolicy;
157  DKIMHeaderParser mHeaderParser;
158  KMime::Message::Ptr mMessage;
159  QString mFromEmail;
160  DKIMInfo mDkimInfo;
161  DKIMKeyRecord mDkimKeyRecord;
162  QString mDkimValue;
163  QString mHeaderCanonizationResult;
164  QString mBodyCanonizationResult;
165  DKIMCheckSignatureJob::DKIMError mError = DKIMCheckSignatureJob::DKIMError::Any;
166  DKIMCheckSignatureJob::DKIMWarning mWarning = DKIMCheckSignatureJob::DKIMWarning::Any;
167  DKIMCheckSignatureJob::DKIMStatus mStatus = DKIMCheckSignatureJob::DKIMStatus::Unknown;
168 };
169 }
170 MESSAGEVIEWER_EXPORT QDebug operator<<(QDebug d, const MessageViewer::DKIMCheckSignatureJob::CheckSignatureResult &t);
171 MESSAGEVIEWER_EXPORT QDebug operator<<(QDebug d, const MessageViewer::DKIMCheckSignatureJob::DKIMCheckSignatureAuthenticationResult &t);
172 Q_DECLARE_METATYPE(MessageViewer::DKIMCheckSignatureJob::CheckSignatureResult)
173 Q_DECLARE_TYPEINFO(MessageViewer::DKIMCheckSignatureJob::DKIMCheckSignatureAuthenticationResult, Q_MOVABLE_TYPE);
The DKIMKeyRecord class.
Definition: dkimkeyrecord.h:19
The DKIMCheckPolicy class.
The DKIMCheckSignatureJob class.
Q_SCRIPTABLE Q_NOREPLY void start()
QDataStream & operator<<(QDataStream &out, const KDateTime &dateTime)
Q_SCRIPTABLE CaptureState status()
The DKIMHeaderParser class.
The DKIMInfo class.
Definition: dkiminfo.h:19
QString message
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Wed Mar 22 2023 04:07:14 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.