diff options
Diffstat (limited to 'gpgmeplug/gpgmeplug.c')
-rw-r--r-- | gpgmeplug/gpgmeplug.c | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/gpgmeplug/gpgmeplug.c b/gpgmeplug/gpgmeplug.c index 12cf2009..0132a67e 100644 --- a/gpgmeplug/gpgmeplug.c +++ b/gpgmeplug/gpgmeplug.c @@ -452,11 +452,31 @@ bool signatureCertificateExpiryNearWarning( void ) int signatureCertificateDaysLeftToExpiry( const char* certificate ) { - /* PENDING(g10) - Please return the number of days that are left until the - certificate specified in the parameter certificate expires. - */ - return 10; /* dummy that triggers a warning in the MUA */ + GpgmeCtx ctx; + GpgmeError err; + GpgmeKey rKey; + time_t daysLeft = 0; + + gpgme_new( &ctx ); + gpgme_set_protocol( ctx, GPGMEPLUG_PROTOCOL ); + + err = gpgme_op_keylist_start( ctx, certificate, 0 ); + if ( GPGME_No_Error == err ) { + err = gpgme_op_keylist_next( ctx, &rKey ); + gpgme_op_keylist_end( ctx ); + if ( GPGME_No_Error == err ) { + time_t expire_time = gpgme_key_get_ulong_attr( + rKey,GPGME_ATTR_EXPIRE, NULL, 0 ); + time_t cur_time = time (NULL); + daysLeft = expire_time - cur_time; + // convert seconds into days + daysLeft /= 43200; + gpgme_key_release( rKey ); + } + } + gpgme_release( ctx ); + + return daysLeft; } |