key_created() added to determine creation date of a key keysync
authorVolker Birk <vb@pep.foundation>
Mon, 01 Aug 2016 12:03:00 +0200
branchkeysync
changeset 958cef602982909
parent 955 060272dfaaeb
child 959 c1c463ecf30c
key_created() added to determine creation date of a key
src/cryptotech.c
src/cryptotech.h
src/pEpEngine.c
src/pEpEngine.h
src/pgp_gpg.c
src/pgp_gpg.h
     1.1 --- a/src/cryptotech.c	Mon Aug 01 09:14:47 2016 +0200
     1.2 +++ b/src/cryptotech.c	Mon Aug 01 12:03:00 2016 +0200
     1.3 @@ -46,6 +46,7 @@
     1.4          cryptotech[PEP_crypt_OpenPGP].revoke_key = pgp_revoke_key;
     1.5          cryptotech[PEP_crypt_OpenPGP].key_expired = pgp_key_expired;
     1.6          cryptotech[PEP_crypt_OpenPGP].key_revoked = pgp_key_revoked;
     1.7 +        cryptotech[PEP_crypt_OpenPGP].key_created = pgp_key_created;
     1.8  #ifdef PGP_BINARY_PATH
     1.9          cryptotech[PEP_crypt_OpenPGP].binary_path = PGP_BINARY_PATH;
    1.10  #endif
     2.1 --- a/src/cryptotech.h	Mon Aug 01 09:14:47 2016 +0200
     2.2 +++ b/src/cryptotech.h	Mon Aug 01 12:03:00 2016 +0200
     2.3 @@ -64,7 +64,10 @@
     2.4          const time_t when, bool *expired);
     2.5  
     2.6  typedef PEP_STATUS (*key_revoked_t)(PEP_SESSION session, const char *fpr,
     2.7 -                                    bool *revoked);
     2.8 +        bool *revoked);
     2.9 +
    2.10 +typedef PEP_STATUS (*key_created_t)(PEP_SESSION session, const char *fpr,
    2.11 +        time_t *created);
    2.12  
    2.13  typedef PEP_STATUS (*binary_path_t)(const char **path);
    2.14  
    2.15 @@ -88,6 +91,7 @@
    2.16      revoke_key_t revoke_key;
    2.17      key_expired_t key_expired;
    2.18      key_revoked_t key_revoked;
    2.19 +    key_created_t key_created;
    2.20      binary_path_t binary_path;
    2.21  } PEP_cryptotech_t;
    2.22  
     3.1 --- a/src/pEpEngine.c	Mon Aug 01 09:14:47 2016 +0200
     3.2 +++ b/src/pEpEngine.c	Mon Aug 01 12:03:00 2016 +0200
     3.3 @@ -1800,6 +1800,20 @@
     3.4      return status;
     3.5  }
     3.6  
     3.7 +PEP_STATUS key_created(
     3.8 +        PEP_SESSION session,
     3.9 +        const char *fpr,
    3.10 +        time_t *created
    3.11 +    )
    3.12 +{
    3.13 +    assert(session && fpr && created);
    3.14 +    if (!(session && fpr && created))
    3.15 +        return PEP_ILLEGAL_VALUE;
    3.16 +
    3.17 +    return session->cryptotech[PEP_crypt_OpenPGP].key_created(session, fpr,
    3.18 +            created);
    3.19 +}
    3.20 +
    3.21  DYNAMIC_API PEP_STATUS reset_peptest_hack(PEP_SESSION session)
    3.22  {
    3.23      assert(session);
     4.1 --- a/src/pEpEngine.h	Mon Aug 01 09:14:47 2016 +0200
     4.2 +++ b/src/pEpEngine.h	Mon Aug 01 12:03:00 2016 +0200
     4.3 @@ -878,6 +878,7 @@
     4.4         const uint64_t revocation_date
     4.5      );
     4.6  
     4.7 +
     4.8  // get_revoked() - find revoked key that may have been replaced by given key, if any
     4.9  //
    4.10  //  parameters:
    4.11 @@ -894,6 +895,20 @@
    4.12      );
    4.13  
    4.14  
    4.15 +// key_created() - get creation date of a key
    4.16 +//
    4.17 +//  parameters:
    4.18 +//      session (in)            session handle
    4.19 +//      fpr (in)                fingerprint of key
    4.20 +//      created (out)           date of creation
    4.21 +
    4.22 +PEP_STATUS key_created(
    4.23 +        PEP_SESSION session,
    4.24 +        const char *fpr,
    4.25 +        time_t *created
    4.26 +    );
    4.27 +
    4.28 +
    4.29  DYNAMIC_API PEP_STATUS reset_peptest_hack(PEP_SESSION session);
    4.30  
    4.31  #ifdef __cplusplus
     5.1 --- a/src/pgp_gpg.c	Mon Aug 01 09:14:47 2016 +0200
     5.2 +++ b/src/pgp_gpg.c	Mon Aug 01 12:03:00 2016 +0200
     5.3 @@ -1965,6 +1965,36 @@
     5.4      return status;
     5.5  }
     5.6  
     5.7 +PEP_STATUS pgp_key_created(
     5.8 +        PEP_SESSION session,
     5.9 +        const char *fpr,
    5.10 +        time_t *created
    5.11 +    )
    5.12 +{
    5.13 +    PEP_STATUS status = PEP_STATUS_OK;
    5.14 +    gpgme_key_t key;
    5.15 +
    5.16 +    assert(session);
    5.17 +    assert(fpr);
    5.18 +    assert(created);
    5.19 +
    5.20 +    status = find_single_key(session, fpr, &key);
    5.21 +    if (status != PEP_STATUS_OK)
    5.22 +        return status;
    5.23 +
    5.24 +    if (key && key->subkeys)
    5.25 +    {
    5.26 +        *created = (time_t) key->subkeys->timestamp;
    5.27 +    }
    5.28 +    else
    5.29 +    {
    5.30 +        status = PEP_KEY_NOT_FOUND;
    5.31 +    }
    5.32 +
    5.33 +    gpg.gpgme_key_unref(key);
    5.34 +    return status;
    5.35 +}
    5.36 +
    5.37  PEP_STATUS pgp_binary(const char **path)
    5.38  {
    5.39      assert(path);
     6.1 --- a/src/pgp_gpg.h	Mon Aug 01 09:14:47 2016 +0200
     6.2 +++ b/src/pgp_gpg.h	Mon Aug 01 12:03:00 2016 +0200
     6.3 @@ -74,6 +74,12 @@
     6.4          bool *revoked
     6.5      );
     6.6  
     6.7 +PEP_STATUS pgp_key_created(
     6.8 +        PEP_SESSION session,
     6.9 +        const char *fpr,
    6.10 +        time_t *created
    6.11 +    );
    6.12 +
    6.13  PEP_STATUS pgp_binary(const char **path);
    6.14  #define PGP_BINARY_PATH pgp_binary
    6.15