Messagelib

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

KDE's Doxygen guidelines are available online.