diff --git a/keyresolver.cpp b/keyresolver.cpp index 744e32a05..4027ea702 100644 --- a/keyresolver.cpp +++ b/keyresolver.cpp @@ -552,13 +552,105 @@ Kpgp::Result Kleo::KeyResolver::checkKeyNearExpiry( const GpgME::Key & key, cons const GpgME::Subkey subkey = key.subkey(0); if ( d->alreadyWarnedFingerprints.count( subkey.fingerprint() ) ) return Kpgp::Ok; // already warned about this one (and so about it's issuers) - d->alreadyWarnedFingerprints.insert( subkey.fingerprint() ); if ( subkey.neverExpires() ) return Kpgp::Ok; static const double secsPerDay = 24 * 60 * 60; - const int daysTillExpiry = - 1 + int( ::difftime( subkey.expirationTime(), time(0) ) / secsPerDay ); + const double secsTillExpiry = ::difftime( subkey.expirationTime(), time(0) ); + if ( secsTillExpiry <= 0 ) { + const int daysSinceExpiry = 1 + int( -secsTillExpiry / secsPerDay ); + kDebug(5006) << "Key 0x" << key.shortKeyID() << " expired less than " + << daysSinceExpiry << " days ago"; + const QString msg = + key.protocol() == GpgME::OpenPGP + ? ( mine ? sign + ? ki18np("

Your OpenPGP signing key

%2 (KeyID 0x%3)

" + "

expired less than a day ago.

", + "

Your OpenPGP signing key

%2 (KeyID 0x%3)

" + "

expired %1 days ago.

") + : ki18np("

Your OpenPGP encryption key

%2 (KeyID 0x%3)

" + "

expired less than a day ago.

", + "

Your OpenPGP encryption key

%2 (KeyID 0x%3)

" + "

expired %1 days ago.

") + : ki18np("

The OpenPGP key for

%2 (KeyID 0x%3)

" + "

expired less than a day ago.

", + "

The OpenPGP key for

%2 (KeyID 0x%3)

" + "

expired %1 days ago.

") ) + .subs( daysSinceExpiry ) + .subs( QString::fromUtf8( key.userID(0).id() ) ) + .subs( key.shortKeyID() ) + .toString() + : ( ca + ? ( key.isRoot() + ? ( mine ? sign + ? ki18np("

The root certificate

%4

" + "

for your S/MIME signing certificate

%2 (serial number %3)

" + "

expired less than a day ago.

", + "

The root certificate

%4

" + "

for your S/MIME signing certificate

%2 (serial number %3)

" + "

expired %1 days ago.

") + : ki18np("

The root certificate

%4

" + "

for your S/MIME encryption certificate

%2 (serial number %3)

" + "

expired less than a day ago.

", + "

The root certificate

%4

" + "

for your S/MIME encryption certificate

%2 (serial number %3)

" + "

expired %1 days ago.

") + : ki18np("

The root certificate

%4

" + "

for S/MIME certificate

%2 (serial number %3)

" + "

expired less than a day ago.

", + "

The root certificate

%4

" + "

for S/MIME certificate

%2 (serial number %3)

" + "

expired %1 days ago.

") ) + : ( mine ? sign + ? ki18np("

The intermediate CA certificate

%4

" + "

for your S/MIME signing certificate

%2 (serial number %3)

" + "

expired less than a day ago.

", + "

The intermediate CA certificate

%4

" + "

for your S/MIME signing certificate

%2 (serial number %3)

" + "

expired %1 days ago.

") + : ki18np("

The intermediate CA certificate

%4

" + "

for your S/MIME encryption certificate

%2 (serial number %3)

" + "

expired less than a day ago.

", + "

The intermediate CA certificate

%4

" + "

for your S/MIME encryption certificate

%2 (serial number %3)

" + "

expired %1 days ago.

") + : ki18np("

The intermediate CA certificate

%4

" + "

for S/MIME certificate

%2 (serial number %3)

" + "

expired less than a day ago.

", + "

The intermediate CA certificate

%4

" + "

for S/MIME certificate

%2 (serial number %3)

" + "

expired %1 days ago.

") ) ) + .subs( daysSinceExpiry ) + .subs( Kleo::DN( orig.userID(0).id() ).prettyDN() ) + .subs( orig.issuerSerial() ) + .subs( Kleo::DN( key.userID(0).id() ).prettyDN() ) + .toString() + : ( mine ? sign + ? ki18np("

Your S/MIME signing certificate

%2 (serial number %3)

" + "

expired less than a day ago.

", + "

Your S/MIME signing certificate

%2 (serial number %3)

" + "

expired %1 days ago.

") + : ki18np("

Your S/MIME encryption certificate

%2 (serial number %3)

" + "

expired less than a day ago.

", + "

Your S/MIME encryption certificate

%2 (serial number %3)

" + "

expired %1 days ago.

") + : ki18np("

The S/MIME certificate for

%2 (serial number %3)

" + "

expired less than a day ago.

", + "

The S/MIME certificate for

%2 (serial number %3)

" + "

expired %1 days ago.

" ) ) + .subs( daysSinceExpiry ) + .subs( Kleo::DN( key.userID(0).id() ).prettyDN() ) + .subs( key.issuerSerial() ) + .toString() ); + d->alreadyWarnedFingerprints.insert( subkey.fingerprint() ); + if ( KMessageBox::warningContinueCancel( 0, msg, + key.protocol() == GpgME::OpenPGP + ? i18n("OpenPGP Key Expired" ) + : i18n("S/MIME Certificate Expired" ), + KStandardGuiItem::cont(), KStandardGuiItem::cancel(), dontAskAgainName ) == KMessageBox::Cancel ) + return Kpgp::Canceled; + } else { + const int daysTillExpiry = 1 + int( secsTillExpiry / secsPerDay ); kDebug(5006) <<"Key 0x" << key.shortKeyID() <<"expires in less than" << daysTillExpiry << "days"; const int threshold = @@ -655,6 +747,7 @@ Kpgp::Result Kleo::KeyResolver::checkKeyNearExpiry( const GpgME::Key & key, cons .subs( Kleo::DN( key.userID(0).id() ).prettyDN() ) .subs( key.issuerSerial() ) .toString() ); + d->alreadyWarnedFingerprints.insert( subkey.fingerprint() ); if ( KMessageBox::warningContinueCancel( 0, msg, key.protocol() == GpgME::OpenPGP ? i18n("OpenPGP Key Expires Soon" ) @@ -664,6 +757,7 @@ Kpgp::Result Kleo::KeyResolver::checkKeyNearExpiry( const GpgME::Key & key, cons == KMessageBox::Cancel ) return Kpgp::Canceled; } + } if ( key.isRoot() ) return Kpgp::Ok; else if ( const char * chain_id = key.chainID() ) {