9#include "messageviewer_dkimcheckerdebug.h"
11using namespace MessageViewer;
13DKIMInfo::DKIMInfo() =
default;
15bool DKIMInfo::parseDKIM(
const QString &header)
18 qCWarning(MESSAGEVIEWER_DKIMCHECKER_LOG) <<
"Error: trying to parse empty header";
24 bool foundCanonizations =
false;
25 for (
int i = 0; i < items.
count(); ++i) {
26 const QString elem = items.
at(i).trimmed();
30 qCWarning(MESSAGEVIEWER_DKIMCHECKER_LOG) <<
"Version is not correct " << mVersion;
39 parseCanonicalization(elem.
right(elem.
length() - 2));
40 foundCanonizations =
true;
46 mAgentOrUserIdentifier = elem.
right(elem.
length() - 2);
50 qCWarning(MESSAGEVIEWER_DKIMCHECKER_LOG) <<
"Query is not correct and not supported " << mQuery;
59 const QString str = MessageViewer::DKIMUtil::cleanString(elem.
right(elem.
length() - 2));
66 qCWarning(MESSAGEVIEWER_DKIMCHECKER_LOG) <<
" Unknown element type" << elem <<
" : items : " << items;
69 if (!foundCanonizations) {
70 mHeaderCanonization = Simple;
71 mBodyCanonization = Simple;
77 mQuery = QStringLiteral(
"dns/txt");
79 if (mAgentOrUserIdentifier.
isEmpty()) {
80 mAgentOrUserIdentifier =
QLatin1Char(
'@') + mDomain;
84 if (lst.
count() == 2) {
85 if (mAgentOrUserIdentifier.
isEmpty()) {
86 mAgentOrUserIdentifier =
QLatin1Char(
'@') + mDomain;
94void DKIMInfo::parseAlgorithm(
const QString &str)
98 if (lst.
count() != 2) {
99 qCWarning(MESSAGEVIEWER_DKIMCHECKER_LOG) <<
"algorithm is invalid " << str;
102 mSigningAlgorithm = lst.
at(0);
105 mHashingAlgorithm = HashingAlgorithmType::Sha1;
107 mHashingAlgorithm = HashingAlgorithmType::Sha256;
109 mHashingAlgorithm = HashingAlgorithmType::Unknown;
114QString DKIMInfo::iDomain()
const
119void DKIMInfo::setIDomain(
const QString &iDomain)
124void DKIMInfo::parseCanonicalization(
const QString &str)
129 if (canonicalization.
count() >= 1) {
131 mHeaderCanonization = DKIMInfo::Relaxed;
133 mHeaderCanonization = DKIMInfo::Simple;
135 qCWarning(MESSAGEVIEWER_DKIMCHECKER_LOG) <<
"canonicalization for header unknown " << canonicalization.
at(0);
136 mHeaderCanonization = DKIMInfo::Unknown;
139 if (canonicalization.
count() == 1) {
140 mBodyCanonization = DKIMInfo::Simple;
141 }
else if (canonicalization.
count() == 2) {
143 mBodyCanonization = DKIMInfo::Relaxed;
145 mBodyCanonization = DKIMInfo::Simple;
147 qCWarning(MESSAGEVIEWER_DKIMCHECKER_LOG) <<
"canonicalization for body unknown " << canonicalization.
at(1);
148 mBodyCanonization = DKIMInfo::Unknown;
152 qCWarning(MESSAGEVIEWER_DKIMCHECKER_LOG) <<
" Problem during parsing canonicalization " << str;
153 mHeaderCanonization = DKIMInfo::Unknown;
154 mBodyCanonization = DKIMInfo::Unknown;
162 return mCopiedHeaderField;
165void DKIMInfo::setCopiedHeaderField(
const QStringList &copiedHeaderField)
167 mCopiedHeaderField = copiedHeaderField;
170DKIMInfo::CanonicalizationType DKIMInfo::bodyCanonization()
const
172 return mBodyCanonization;
175void DKIMInfo::setBodyCanonization(CanonicalizationType bodyCanonization)
177 mBodyCanonization = bodyCanonization;
180bool DKIMInfo::operator==(
const DKIMInfo &other)
const
182 return mVersion == other.version() && mHashingAlgorithm == other.hashingAlgorithm() && mSigningAlgorithm == other.signingAlgorithm()
183 && mDomain == other.domain() && mSelector == other.selector() && mBodyHash == other.bodyHash() && mSignatureTimeStamp == other.signatureTimeStamp()
184 && mExpireTime == other.expireTime() && mQuery == other.query() && mSignature == other.signature()
185 && mAgentOrUserIdentifier == other.agentOrUserIdentifier() && mBodyLengthCount == other.bodyLengthCount()
186 && mListSignedHeader == other.listSignedHeader() && mHeaderCanonization == other.headerCanonization() && mBodyCanonization == other.bodyCanonization()
187 && mIDomain == other.iDomain();
190DKIMInfo::CanonicalizationType DKIMInfo::headerCanonization()
const
192 return mHeaderCanonization;
195void DKIMInfo::setHeaderCanonization(CanonicalizationType headerCanonization)
197 mHeaderCanonization = headerCanonization;
200int DKIMInfo::version()
const
205void DKIMInfo::setVersion(
int version)
210DKIMInfo::HashingAlgorithmType DKIMInfo::hashingAlgorithm()
const
212 return mHashingAlgorithm;
215void DKIMInfo::setHashingAlgorithm(DKIMInfo::HashingAlgorithmType hashingAlgorithm)
217 mHashingAlgorithm = hashingAlgorithm;
220QString DKIMInfo::domain()
const
225void DKIMInfo::setDomain(
const QString &domain)
230QString DKIMInfo::selector()
const
235void DKIMInfo::setSelector(
const QString &selector)
237 mSelector = selector;
240QString DKIMInfo::bodyHash()
const
245void DKIMInfo::setBodyHash(
const QString &bodyHash)
247 mBodyHash = bodyHash;
250bool DKIMInfo::isValid()
const
252 if (mBodyCanonization == DKIMInfo::Unknown || mHeaderCanonization == DKIMInfo::Unknown) {
257 && ((mHashingAlgorithm == HashingAlgorithmType::Sha1) || mHashingAlgorithm == HashingAlgorithmType::Sha256);
262 return mListSignedHeader;
265void DKIMInfo::setListSignedHeader(
const QStringList &listSignedHeader)
267 mListSignedHeader = listSignedHeader;
270QString DKIMInfo::signingAlgorithm()
const
272 return mSigningAlgorithm;
275void DKIMInfo::setSigningAlgorithm(
const QString &signingAlgorithm)
277 mSigningAlgorithm = signingAlgorithm;
280qint64 DKIMInfo::signatureTimeStamp()
const
282 return mSignatureTimeStamp;
285void DKIMInfo::setSignatureTimeStamp(qint64 signatureTimeStamp)
287 mSignatureTimeStamp = signatureTimeStamp;
295void DKIMInfo::setQuery(
const QString &query)
300qint64 DKIMInfo::expireTime()
const
305void DKIMInfo::setExpireTime(qint64 expireTime)
307 mExpireTime = expireTime;
310QString DKIMInfo::signature()
const
315void DKIMInfo::setSignature(
const QString &signature)
317 mSignature = signature;
320QString DKIMInfo::agentOrUserIdentifier()
const
322 return mAgentOrUserIdentifier;
325void DKIMInfo::setAgentOrUserIdentifier(
const QString &userAgent)
327 mAgentOrUserIdentifier = userAgent;
330int DKIMInfo::bodyLengthCount()
const
332 return mBodyLengthCount;
335void DKIMInfo::setBodyLengthCount(
int bodyLengthCount)
337 mBodyLengthCount = bodyLengthCount;
342 d <<
"mVersion " << t.version();
343 d <<
"mHashingAlgorithm " << t.hashingAlgorithm();
344 d <<
"mSigningAlgorithm " << t.signingAlgorithm();
345 d <<
"mDomain " << t.domain();
346 d <<
"mSelector " << t.selector();
347 d <<
"mBodyHash " << t.bodyHash();
348 d <<
"mSignatureTimeStamp " << t.signatureTimeStamp();
349 d <<
"mExpireTime " << t.expireTime();
350 d <<
"mQuery " << t.query();
351 d <<
"mSignature " << t.signature();
352 d <<
"mAgentOrUserIdentifier " << t.agentOrUserIdentifier();
353 d <<
"mBodyLengthCount " << t.bodyLengthCount();
354 d <<
"mListSignedHeader " << t.listSignedHeader();
355 d <<
"mHeaderCanonization " << t.headerCanonization();
356 d <<
"mBodyCanonization " << t.bodyCanonization();
357 d <<
"mIdomain " << t.iDomain();
361#include "moc_dkiminfo.cpp"
KSERVICE_EXPORT KService::List query(FilterFunc filterFunc)
KDB_EXPORT KDbVersionInfo version()
QDebug operator<<(QDebug dbg, const PerceptualColor::MultiSpinBoxSection &value)
const_reference at(qsizetype i) const const
qsizetype count() const const
bool isEmpty() const const
qsizetype length() const const
QString & remove(QChar ch, Qt::CaseSensitivity cs)
QString & replace(QChar before, QChar after, Qt::CaseSensitivity cs)
QString right(qsizetype n) const const
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
long toLong(bool *ok, int base) const const
QString trimmed() const const
QStringView right(qsizetype length) const const
QList< QStringView > split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
int toInt(bool *ok, int base) const const