Commit aef8cb77 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Continue to fix authenticationstatus

parent 3e25a17f
......@@ -154,6 +154,6 @@ void DKIMCheckSignatureJobTest::shouldTestMail()
QCOMPARE(info.warning, dkimwarning);
QCOMPARE(info.error, dkimerror);
QCOMPARE(info.status, dkimstatus);
QCOMPARE(info.signedBy, dkimdomain);
QCOMPARE(info.sdid, dkimdomain);
QCOMPARE(info.fromEmail, fromEmail);
}
......@@ -51,7 +51,7 @@ void DKIMWidgetInfoTest::shouldClearWidget()
QLabel *mLabel = w.findChild<QLabel *>(QStringLiteral("label"));
MessageViewer::DKIMCheckSignatureJob::CheckSignatureResult result;
result.fromEmail = QStringLiteral("bla");
result.signedBy = QStringLiteral("bli");
result.sdid = QStringLiteral("bli");
result.status = MessageViewer::DKIMCheckSignatureJob::DKIMStatus::NeedToBeSigned;
result.error = MessageViewer::DKIMCheckSignatureJob::DKIMError::CorruptedBodyHash;
result.warning = MessageViewer::DKIMCheckSignatureJob::DKIMWarning::HashAlgorithmUnsafe;
......
......@@ -108,7 +108,6 @@ DKIMAuthenticationStatusInfo::AuthStatusInfo DKIMAuthenticationStatusInfo::parse
authStatusInfo.result = match.captured(3);
valueKey = valueKey.right(valueKey.length() - (index + match.captured(0).length())); // Improve it!
//TODO remove extra text
// 3) extract reasonspec (optional)
const QString reasonspec_p = DKIMAuthenticationStatusInfoUtil::regexMatchO(QLatin1String("reason") + DKIMAuthenticationStatusInfoUtil::cfws_op() + QLatin1Char('=') + DKIMAuthenticationStatusInfoUtil::cfws_op() + DKIMAuthenticationStatusInfoUtil::value_cp());
......@@ -134,7 +133,6 @@ DKIMAuthenticationStatusInfo::AuthStatusInfo DKIMAuthenticationStatusInfo::parse
//qDebug() << "propspec_p " << propspec_p;
const QString regexp = DKIMAuthenticationStatusInfoUtil::regexMatchO(propspec_p);
const QRegularExpression reg(regexp);
if (!reg.isValid()) {
qCWarning(MESSAGEVIEWER_DKIMCHECKER_LOG) << " reg error : " << reg.errorString();
......@@ -145,26 +143,23 @@ DKIMAuthenticationStatusInfo::AuthStatusInfo DKIMAuthenticationStatusInfo::parse
valueKey = valueKey.right(valueKey.length() - (index + match.captured(0).length())); // Improve it!
//qDebug() << " value KEy " << valueKey;
const QString &captured1 = match.captured(1);
//qDebug() << " captured1 " << captured1;
if (captured1 == QLatin1String("header")) {
//qDebug() << " header type found ";
AuthStatusInfo::Property prop;
prop.type = match.captured(2);
prop.value = match.captured(3);
authStatusInfo.header.append(prop);
} else if (captured1 == QLatin1String("smtp")) {
//qDebug() << " smtp type found ";
AuthStatusInfo::Property prop;
prop.type = match.captured(2);
prop.value = match.captured(3);
authStatusInfo.smtp.append(prop);
} else if (captured1 == QLatin1String("body")) {
//qDebug() << " body type found ";
AuthStatusInfo::Property prop;
prop.type = match.captured(2);
prop.value = match.captured(3);
authStatusInfo.body.append(prop);
} else if (captured1 == QLatin1String("policy")) {
//qDebug() << " policy type found ";
AuthStatusInfo::Property prop;
prop.type = match.captured(2);
prop.value = match.captured(3);
......
......@@ -21,6 +21,7 @@
*/
#include "dkimauthenticationstatusinfoconverter.h"
#include "dkimutil.h"
#include "messageviewer_dkimcheckerdebug.h"
using namespace MessageViewer;
......@@ -53,6 +54,24 @@ QVector<DKIMCheckSignatureJob::CheckSignatureResult> DKIMAuthenticationStatusInf
convertedResult.status = DKIMCheckSignatureJob::DKIMStatus::EmailNotSigned;
} else if (infoResult == QLatin1String("pass")) {
convertedResult.status = DKIMCheckSignatureJob::DKIMStatus::Valid;
QString sdid;
QString auid;
for (const DKIMAuthenticationStatusInfo::AuthStatusInfo::Property &prop : info.header) {
if (prop.type == QLatin1String("d")) {
sdid = prop.value;
} else if (prop.type == QLatin1String("i")) {
auid = prop.value;
}
}
if (!auid.isEmpty() || !sdid.isEmpty()) {
if (sdid.isEmpty()) {
sdid = MessageViewer::DKIMUtil::emailDomain(auid);
} else if (auid.isEmpty()) {
auid = QLatin1Char('@') + sdid;
}
convertedResult.sdid = sdid;
convertedResult.auid = auid;
}
} else if (infoResult == QLatin1String("fail") ||
infoResult == QLatin1String("policy") ||
infoResult == QLatin1String("neutral") ||
......@@ -62,7 +81,9 @@ QVector<DKIMCheckSignatureJob::CheckSignatureResult> DKIMAuthenticationStatusInf
convertedResult.status = DKIMCheckSignatureJob::DKIMStatus::Invalid;
} else {
qCWarning(MESSAGEVIEWER_DKIMCHECKER_LOG) << "Invalid result type " << infoResult;
continue;
}
lstResult.append(convertedResult);
}
return lstResult;
......
......@@ -51,7 +51,7 @@ void DKIMCheckAuthenticationStatusJob::start()
str = mHeaderParser.headerType(strAuthenticationHeader);
}
qDebug() << "result info: " << info;
//qDebug() << "result info: " << info;
Q_EMIT result(info);
deleteLater();
}
......
......@@ -70,6 +70,7 @@ void DKIMCheckFullJob::startCheckFullInfo(const Akonadi::Item &item)
void DKIMCheckFullJob::checkAuthenticationResults()
{
qDebug() << " void DKIMCheckFullJob::checkAuthenticationResults()" << mCheckPolicy.useAuthenticationResults();
if (mCheckPolicy.useAuthenticationResults()) {
DKIMCheckAuthenticationStatusJob *job = new DKIMCheckAuthenticationStatusJob(this);
mHeaderParser.setHead(mMessage->head());
......@@ -138,10 +139,12 @@ void DKIMCheckFullJob::storeInKeyManager(const QString &key, const QString &doma
void DKIMCheckFullJob::slotCheckAuthenticationStatusResult(const MessageViewer::DKIMAuthenticationStatusInfo &info)
{
qDebug() << "info " << info;
DKIMAuthenticationStatusInfoConverter converter;
converter.setStatusInfo(info);
const QVector<DKIMCheckSignatureJob::CheckSignatureResult> lst = converter.convert();
for (const DKIMCheckSignatureJob::CheckSignatureResult &result : lst) {
qDebug() << " lst" << result;
//TODO verify it.
}
//TODO implement info !
......
......@@ -74,7 +74,7 @@ void DKIMCheckPolicyJob::compareWithDefaultRules()
if (rule.from() == mEmailAddress || rule.from() == QLatin1Char('*')) {
//Check SDID
for (const QString &ssid : rule.signedDomainIdentifier()) {
if (mCheckResult.signedBy == ssid) {
if (mCheckResult.sdid == ssid) {
switch (rule.ruleType()) {
case DKIMRule::RuleType::Unknown:
// Invalid rule !
......@@ -107,7 +107,7 @@ void DKIMCheckPolicyJob::dmarcPolicyResult(const MessageViewer::DMARCPolicyJob::
mCheckResult.status = DKIMCheckSignatureJob::DKIMStatus::NeedToBeSigned;
//qDebug() << " void DKIMCheckPolicyJob::dmarcPolicyResult(const MessageViewer::DMARCPolicyJob::DMARCResult &value)"<<value.mDomain << "value " << value.mSource;
//TODO verify it.
mCheckResult.signedBy = value.mSource;
mCheckResult.sdid = value.mSource;
}
}
Q_EMIT result(mCheckResult);
......
......@@ -49,7 +49,7 @@ MessageViewer::DKIMCheckSignatureJob::CheckSignatureResult DKIMCheckSignatureJob
result.error = mError;
result.warning = mWarning;
result.status = mStatus;
result.signedBy = mDkimInfo.domain();
result.sdid = mDkimInfo.domain();
result.fromEmail = mFromEmail;
return result;
}
......@@ -657,10 +657,23 @@ bool DKIMCheckSignatureJob::CheckSignatureResult::operator==(const DKIMCheckSign
return error == other.error
&& warning == other.warning
&& status == other.status
&& fromEmail == other.fromEmail;
&& fromEmail == other.fromEmail
&& auid == other.auid
&& sdid == other.sdid;
}
bool DKIMCheckSignatureJob::CheckSignatureResult::operator!=(const DKIMCheckSignatureJob::CheckSignatureResult &other) const
{
return !CheckSignatureResult::operator==(other);
}
QDebug operator <<(QDebug d, const DKIMCheckSignatureJob::CheckSignatureResult &t)
{
d << "error " << t.error;
d << "warning " << t.warning;
d << "status " << t.status;
d << "signedBy " << t.sdid;
d << "fromEmail " << t.fromEmail;
d << "auid " << t.auid;
return d;
}
......@@ -90,7 +90,8 @@ public:
DKIMCheckSignatureJob::DKIMError error = DKIMCheckSignatureJob::DKIMError::Any;
DKIMCheckSignatureJob::DKIMWarning warning = DKIMCheckSignatureJob::DKIMWarning::Any;
DKIMCheckSignatureJob::DKIMStatus status = DKIMCheckSignatureJob::DKIMStatus::Unknown;
QString signedBy;
QString sdid; //Signing Domain Identifier
QString auid; //DKIM MAY optionally provide a single responsible Agent or User Identifier (AUID).
QString fromEmail;
};
......@@ -151,5 +152,6 @@ private:
DKIMCheckSignatureJob::DKIMStatus mStatus = DKIMCheckSignatureJob::DKIMStatus::Unknown;
};
}
MESSAGEVIEWER_EXPORT QDebug operator <<(QDebug d, const MessageViewer::DKIMCheckSignatureJob::CheckSignatureResult &t);
Q_DECLARE_METATYPE(MessageViewer::DKIMCheckSignatureJob::CheckSignatureResult)
#endif // DKIMCHECKSIGNATUREJOB_H
......@@ -57,7 +57,7 @@ void DKIMGenerateRuleJob::verifyAndGenerateRule()
rule.setEnabled(true);
rule.setFrom(mResult.fromEmail);
//rule.setDomain(mResult.signedBy); //TODO verify ?
rule.setSignedDomainIdentifier(QStringList() << mResult.signedBy);
rule.setSignedDomainIdentifier(QStringList() << mResult.sdid);
rule.setRuleType(DKIMRule::RuleType::MustBeSigned);
deleteLater();
}
......
......@@ -101,7 +101,7 @@ void DKIMWidgetInfo::updateInfo()
mLabel->setText(i18n("Unknown"));
break;
case DKIMCheckSignatureJob::DKIMStatus::Valid:
mLabel->setText(i18n("DKIM: valid (signed by %1)", mResult.signedBy));
mLabel->setText(i18n("DKIM: valid (signed by %1)", mResult.sdid));
pal.setColor(backgroundRole(), (mResult.warning != DKIMCheckSignatureJob::DKIMWarning::Any) ? mWarningColor : mOkColor);
mLabel->setPalette(pal);
break;
......@@ -116,7 +116,7 @@ void DKIMWidgetInfo::updateInfo()
mLabel->setPalette(pal);
break;
case DKIMCheckSignatureJob::DKIMStatus::NeedToBeSigned:
mLabel->setText(i18n("DKIM: Should Be Signed by %1", mResult.signedBy));
mLabel->setText(i18n("DKIM: Should Be Signed by %1", mResult.sdid));
pal.setColor(backgroundRole(), mErrorColor);
mLabel->setPalette(pal);
break;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment