diff --git a/autotests/expirycheckertest.cpp b/autotests/expirycheckertest.cpp
index 9493d39bb..233019923 100644
--- a/autotests/expirycheckertest.cpp
+++ b/autotests/expirycheckertest.cpp
@@ -1,299 +1,299 @@
/*
This file is part of libkleopatra's test suite.
SPDX-FileCopyrightText: 2022 Sandro Knauß The OpenPGP key for alice@autocrypt.example (KeyID 0xF231550C4F47E38E) expired less than a day ago. Your OpenPGP encryption key alice@autocrypt.example (KeyID 0xF231550C4F47E38E) expired less than a day "
"ago. Your OpenPGP signing key alice@autocrypt.example (KeyID 0xF231550C4F47E38E) expired less than a day "
"ago. The S/MIME certificate for CN=unittest cert,EMAIL=test@example.com,O=KDAB,C=US (serial "
"number 00D345203A186385C9) expired less than a day ago. Your S/MIME encryption certificate CN=unittest cert,EMAIL=test@example.com,O=KDAB,C=US "
"(serial number 00D345203A186385C9) expired less than a day ago. Your S/MIME signing certificate CN=unittest cert,EMAIL=test@example.com,O=KDAB,C=US "
"(serial number 00D345203A186385C9) expired less than a day ago. The OpenPGP key for alice@autocrypt.example (KeyID 0xF231550C4F47E38E) expires in less than 6 days. Your OpenPGP encryption key alice@autocrypt.example (KeyID 0xF231550C4F47E38E) expires in less than 6 "
"days. Your OpenPGP signing key alice@autocrypt.example (KeyID 0xF231550C4F47E38E) expires in less than 6 "
"days. The S/MIME certificate for CN=unittest cert,EMAIL=test@example.com,O=KDAB,C=US (serial "
- "number 00D345203A186385C9); expires in less than 6 days.
expires in less than 6 days.
") << QStringLiteral( "Your S/MIME encryption certificate
CN=unittest cert,EMAIL=test@example.com,O=KDAB,C=US " - "(serial number 00D345203A186385C9);
expires in less than 6 days.
") + "(serial number 00D345203A186385C9)expires in less than 6 days.
") << QStringLiteral( "Your S/MIME signing certificate
CN=unittest cert,EMAIL=test@example.com,O=KDAB,C=US " - "(serial number 00D345203A186385C9);
expires in less than 6 days.
"); + "(serial number 00D345203A186385C9)expires in less than 6 days.
"); } void nearexpiry() { QFETCH(GpgME::Key, key); QFETCH(QDate, fakedate); QFETCH(QString, msg); QFETCH(QString, msgOwnKey); QFETCH(QString, msgOwnSigningKey); { ExpiryChecker checker(ExpiryCheckerSettings{days{1}, days{10}, days{1}, days{1}}); checker.setTimeProviderForTest(std::make_sharedYour OpenPGP signing key
%1
expired less than a day ago.
"); } else if (isOwnKey) { msg = ki18n("Your OpenPGP encryption key
%1
expired less than a day ago.
"); } else { msg = ki18n("The OpenPGP key for
%1
expired less than a day ago.
"); } return msg.subs(keyInfo).toString(); } KLocalizedString msg; if (isSigningKey) { msg = ki18np( "Your OpenPGP signing key
%2
" "expired one day ago.
", "Your OpenPGP signing key
%2
" "expired %1 days ago.
"); } else if (isOwnKey) { msg = ki18np( "Your OpenPGP encryption key
%2
" "expired one day ago.
", "Your OpenPGP encryption key
%2
" "expired %1 days ago.
"); } else { msg = ki18np( "The OpenPGP key for
%2
" "expired one day ago.
", "The OpenPGP key for
%2
" "expired %1 days ago.
"); } return msg.subs(expiration.duration.count()).subs(keyInfo).toString(); } qCDebug(LIBKLEO_LOG) << "Key" << key << "expires in less than" << expiration.duration.count() + 1 << "days"; KLocalizedString msg; if (isSigningKey) { msg = ki18np( "Your OpenPGP signing key
%2
" "expires in less than a day.
", "Your OpenPGP signing key
%2
" "expires in less than %1 days.
"); } else if (isOwnKey) { msg = ki18np( "Your OpenPGP encryption key
%2
" "expires in less than a day.
", "Your OpenPGP encryption key
%2
" "expires in less than %1 days.
"); } else { msg = ki18np( "The OpenPGP key for
%2
" "expires in less than a day.
", "The OpenPGP key for
%2
" "expires in less than %1 days.
"); } return msg.subs(expiration.duration.count() + 1).subs(keyInfo).toString(); } QString formatSMIMEMessage(const GpgME::Key &key, const GpgME::Key &orig_key, Expiration expiration, ExpiryChecker::KeyFlags flags, bool ca) { const bool isOwnKey = flags & ExpiryChecker::OwnKey; const bool isSigningKey = flags & ExpiryChecker::SigningKey; const auto userCert = orig_key.isNull() ? key : orig_key; const auto userCertInfo = ki18nc("User ID of certificate (serial number serial no. of certificate)", "%1 (serial number %2)") .subs(Kleo::DN(userCert.userID(0).id()).prettyDN()) .subs(QString::fromLatin1(userCert.issuerSerial())); if (expiration.status == Expiration::Expired) { qCDebug(LIBKLEO_LOG) << "Certificate" << key << "expired" << expiration.duration.count() << "days ago"; if (ca) { if (key.isRoot()) { if (expiration.duration.count() == 0) { KLocalizedString msg; if (isSigningKey) { msg = ki18n( "The root certificate
%2
" "for your S/MIME signing certificate
%1
" "expired less than a day ago.
"); } else if (isOwnKey) { msg = ki18n( "The root certificate
%2
" "for your S/MIME encryption certificate
%1
" "expired less than a day ago.
"); } else { msg = ki18n( "The root certificate
%2
" "for S/MIME certificate
%1
" "expired less than a day ago.
"); } return msg.subs(userCertInfo).subs(Kleo::DN(key.userID(0).id()).prettyDN()).toString(); } KLocalizedString msg; if (isSigningKey) { msg = ki18np( "The root certificate
%3
" "for your S/MIME signing certificate
%2
" "expired one day ago.
", "The root certificate
%3
" "for your S/MIME signing certificate
%2
" "expired %1 days ago.
"); } else if (isOwnKey) { msg = ki18np( "The root certificate
%3
" "for your S/MIME encryption certificate
%2
" "expired one day ago.
", "The root certificate
%3
" "for your S/MIME encryption certificate
%2
" "expired %1 days ago.
"); } else { msg = ki18np( "The root certificate
%3
" "for S/MIME certificate
%2
" "expired one day ago.
", "The root certificate
%3
" "for S/MIME certificate
%2
" "expired %1 days ago.
"); } return msg.subs(expiration.duration.count()).subs(userCertInfo).subs(Kleo::DN(key.userID(0).id()).prettyDN()).toString(); } else { if (expiration.duration.count() == 0) { KLocalizedString msg; if (isSigningKey) { msg = ki18n( "The intermediate CA certificate
%2
" "for your S/MIME signing certificate
%1
" "expired less than a day ago.
"); } else if (isOwnKey) { msg = ki18n( "The intermediate CA certificate
%2
" "for your S/MIME encryption certificate
%1
" "expired less than a day ago.
"); } else { msg = ki18n( "The intermediate CA certificate
%2
" "for S/MIME certificate
%1
" "expired less than a day ago.
"); } return msg.subs(userCertInfo).subs(Kleo::DN(key.userID(0).id()).prettyDN()).toString(); } KLocalizedString msg; if (isSigningKey) { msg = ki18np( "The intermediate CA certificate
%3
" "for your S/MIME signing certificate
%2
" "expired less than a day ago.
", "The intermediate CA certificate
%3
" "for your S/MIME signing certificate
%2
" "expired %1 days ago.
"); } else if (isOwnKey) { msg = ki18np( "The intermediate CA certificate
%3
" "for your S/MIME encryption certificate
%2
" "expired less than a day ago.
", "The intermediate CA certificate
%3
" "for your S/MIME encryption certificate
%2
" "expired %1 days ago.
"); } else { msg = ki18np( "The intermediate CA certificate
%3
" "for S/MIME certificate
%2
" "expired less than a day ago.
", "The intermediate CA certificate
%3
" "for S/MIME certificate
%2
" "expired %1 days ago.
"); } return msg.subs(expiration.duration.count()).subs(userCertInfo).subs(Kleo::DN(key.userID(0).id()).prettyDN()).toString(); } } else { if (expiration.duration.count() == 0) { KLocalizedString msg; if (isSigningKey) { msg = ki18n("Your S/MIME signing certificate
%1
expired less than a day ago.
"); } else if (isOwnKey) { msg = ki18n("Your S/MIME encryption certificate
%1
expired less than a day ago.
"); } else { msg = ki18n("The S/MIME certificate for
%1
expired less than a day ago.
"); } return msg.subs(userCertInfo).toString(); } KLocalizedString msg; if (isSigningKey) { msg = ki18np( "Your S/MIME signing certificate
%2
" "expired less than a day ago.
", "Your S/MIME signing certificate
%2
" "expired %1 days ago.
"); } else if (isOwnKey) { msg = ki18np( "Your S/MIME encryption certificate
%2
" "expired less than a day ago.
", "Your S/MIME encryption certificate
%2
" "expired %1 days ago.
"); } else { msg = ki18np( "The S/MIME certificate for
%2
" "expired less than a day ago.
", "The S/MIME certificate for
%2
" "expired %1 days ago.
"); } return msg.subs(expiration.duration.count()).subs(userCertInfo).toString(); } } qCDebug(LIBKLEO_LOG) << "Certificate" << key << "expires in less than" << expiration.duration.count() + 1 << "days"; KLocalizedString msg; if (ca) { if (key.isRoot()) { if (isSigningKey) { msg = ki18np( "The root certificate
%3
" - "for your S/MIME signing certificate
%2;
" + "for your S/MIME signing certificate
%2
" "expires in less than a day.
", "The root certificate
%3
" - "for your S/MIME signing certificate
%2;
" + "for your S/MIME signing certificate
%2
" "expires in less than %1 days.
"); } else if (isOwnKey) { msg = ki18np( "The root certificate
%3
" - "for your S/MIME encryption certificate
%2;
" + "for your S/MIME encryption certificate
%2
" "expires in less than a day.
", "The root certificate
%3
" - "for your S/MIME encryption certificate
%2;
" + "for your S/MIME encryption certificate
%2
" "expires in less than %1 days.
"); } else { msg = ki18np( "The root certificate
%3
" - "for S/MIME certificate
%2;
" + "for S/MIME certificate
%2
" "expires in less than a day.
", "The root certificate
%3
" - "for S/MIME certificate
%2;
" + "for S/MIME certificate
%2
" "expires in less than %1 days.
"); } } else { if (isSigningKey) { msg = ki18np( "The intermediate CA certificate
%3
" - "for your S/MIME signing certificate
%2;
" + "for your S/MIME signing certificate
%2
" "expires in less than a day.
", "The intermediate CA certificate
%3
" - "for your S/MIME signing certificate
%2;
" + "for your S/MIME signing certificate
%2
" "expires in less than %1 days.
"); } else if (isOwnKey) { msg = ki18np( "The intermediate CA certificate
%3
" - "for your S/MIME encryption certificate
%2;
" + "for your S/MIME encryption certificate
%2
" "expires in less than a day.
", "The intermediate CA certificate
%3
" - "for your S/MIME encryption certificate
%2;
" + "for your S/MIME encryption certificate
%2
" "expires in less than %1 days.
"); } else { msg = ki18np( "The intermediate CA certificate
%3
" - "for S/MIME certificate
%2;
" + "for S/MIME certificate
%2
" "expires in less than a day.
", "The intermediate CA certificate
%3
" - "for S/MIME certificate
%2;
" + "for S/MIME certificate
%2
" "expires in less than %1 days.
"); } } return msg.subs(expiration.duration.count() + 1).subs(userCertInfo).subs(Kleo::DN(key.userID(0).id()).prettyDN()).toString(); } if (isSigningKey) { msg = ki18np( - "Your S/MIME signing certificate
%2;
" + "Your S/MIME signing certificate
%2
" "expires in less than a day.
", - "Your S/MIME signing certificate
%2;
" + "Your S/MIME signing certificate
%2
" "expires in less than %1 days.
"); } else if (isOwnKey) { msg = ki18np( - "Your S/MIME encryption certificate
%2;
" + "Your S/MIME encryption certificate
%2
" "expires in less than a day.
", - "Your S/MIME encryption certificate
%2;
" + "Your S/MIME encryption certificate
%2
" "expires in less than %1 days.
"); } else { msg = ki18np( - "The S/MIME certificate for
%2;
" + "The S/MIME certificate for
%2
" "expires in less than a day.
", - "The S/MIME certificate for
%2;
" + "The S/MIME certificate for
%2
" "expires in less than %1 days.
"); } return msg.subs(expiration.duration.count() + 1).subs(userCertInfo).toString(); } Expiration ExpiryCheckerPrivate::calculateExpiration(const GpgME::Subkey &subkey) const { if (subkey.neverExpires()) { return {Expiration::NeverExpires, Kleo::chrono::days::zero()}; } const time_t t = timeProvider ? timeProvider->getTime() : std::time(nullptr); // casting the double-valued difference (returned by std::difftime) of two non-negative time_t to a time_t is no problem; // negative values for expiration time and current time can be safely ignored const time_t secsTillExpiry = static_cast