merging sync
authorVolker Birk <vb@pep-project.org>
Sun, 08 Dec 2019 15:13:17 +0100
branchsync
changeset 4238b3235fe2e5b8
parent 4237 3b0910bf9f0e
parent 4236 01980e34ecdf
child 4239 1e9f88b5b9d4
child 4240 5c4a81487c18
merging
     1.1 --- a/Makefile.conf	Sun Dec 08 15:13:05 2019 +0100
     1.2 +++ b/Makefile.conf	Sun Dec 08 15:13:17 2019 +0100
     1.3 @@ -93,7 +93,7 @@
     1.4  endif
     1.5  
     1.6  ifeq ($(BUILD_FOR),Linux)
     1.7 -    CFLAGS=-fPIC -fstrict-aliasing -fdiagnostics-color=always
     1.8 +    CFLAGS=-fPIC -fstrict-aliasing -fdiagnostics-color=auto
     1.9  else ifeq ($(BUILD_FOR),Darwin)
    1.10      CFLAGS=-pthread -fPIC -fstrict-aliasing -fcolor-diagnostics
    1.11  endif
    1.12 @@ -148,7 +148,7 @@
    1.13  # The flag -DNDEBUG will always be removed from CXXFLAGS for compiling tests.
    1.14  # The tests do not work properly, if compiled with -DNDEBUG
    1.15  ifeq ($(BUILD_FOR),Linux)
    1.16 -    CXXFLAGS=-fdiagnostics-color=always -I../src -I../asn.1 $(ETPAN_INC)
    1.17 +    CXXFLAGS=-fdiagnostics-color=auto -I../src -I../asn.1 $(ETPAN_INC)
    1.18      ifdef WARN
    1.19          CXXFLAGS+=
    1.20      else
     2.1 --- a/src/message_api.c	Sun Dec 08 15:13:05 2019 +0100
     2.2 +++ b/src/message_api.c	Sun Dec 08 15:13:17 2019 +0100
     2.3 @@ -1208,6 +1208,7 @@
     2.4          return PEP_rating_unencrypted;
     2.5  
     2.6      case PEP_DECRYPTED:
     2.7 +    case PEP_VERIFY_SIGNER_KEY_REVOKED:
     2.8      case PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH:
     2.9          return PEP_rating_unreliable;
    2.10  
    2.11 @@ -3419,6 +3420,8 @@
    2.12      unsigned int major_ver = 0;
    2.13      unsigned int minor_ver = 0;
    2.14      
    2.15 +    stringpair_list_t* revoke_replace_pairs = NULL;
    2.16 +    
    2.17      // Grab input flags
    2.18      bool reencrypt = ((*flags & PEP_decrypt_flag_untrusted_server) &&
    2.19              (_have_extrakeys(*keylist) || session->unencrypted_subject));
    2.20 @@ -3546,9 +3549,7 @@
    2.21                  status = _mime_decode_message_internal(ptext, psize, &msg, &has_inner);
    2.22                  if (status != PEP_STATUS_OK)
    2.23                      goto pEp_error;
    2.24 -                
    2.25 -                /* Ensure messages whose maintext is in the attachments
    2.26 -                   move main text into message struct longmsg et al */
    2.27 +                                
    2.28                  /* KG: This IS a src modification of old - we're adding to it
    2.29                     w/ memhole subject, but the question is whether or not
    2.30                     this is OK overall... */
    2.31 @@ -3616,7 +3617,8 @@
    2.32          if (status != PEP_STATUS_OK)
    2.33              goto pEp_error;
    2.34  
    2.35 -        if (decrypt_status == PEP_DECRYPTED || decrypt_status == PEP_DECRYPTED_AND_VERIFIED) {
    2.36 +        if (decrypt_status == PEP_DECRYPTED || decrypt_status == PEP_DECRYPTED_AND_VERIFIED || 
    2.37 +            decrypt_status == PEP_VERIFY_SIGNER_KEY_REVOKED) {
    2.38              char* wrap_info = NULL;
    2.39              
    2.40              if (!has_inner) {
    2.41 @@ -3888,67 +3890,69 @@
    2.42      } // End prepare output message for return
    2.43  
    2.44      // 3. Check to see if the sender used any of our revoked keys
    2.45 -    stringpair_list_t* revoke_replace_pairs = NULL;
    2.46 -    status = check_for_own_revoked_key(session, _keylist, &revoke_replace_pairs);
    2.47 -
    2.48 -    //assert(status != PEP_STATUS_OK); // FIXME: FOR DEBUGGING ONLY DO NOT LEAVE IN    
    2.49 -    if (status != PEP_STATUS_OK) {
    2.50 -        // This should really never choke unless the DB is broken.
    2.51 -        status = PEP_UNKNOWN_DB_ERROR;
    2.52 -        goto pEp_error;
    2.53 -    }
    2.54 -    
    2.55 -    if (msg) {
    2.56 -        stringpair_list_t* curr_pair_node;
    2.57 -        stringpair_t* curr_pair;
    2.58 -
    2.59 -        for (curr_pair_node = revoke_replace_pairs; curr_pair_node; curr_pair_node = curr_pair_node->next) {
    2.60 -            curr_pair = curr_pair_node->value;
    2.61 -
    2.62 -            if (!curr_pair)
    2.63 -                continue; // Again, shouldn't occur
    2.64 -
    2.65 -            if (curr_pair->key && curr_pair->value) {
    2.66 -                status = create_standalone_key_reset_message(session,
    2.67 -                    &reset_msg,
    2.68 -                    msg->from,
    2.69 -                    curr_pair->key,
    2.70 -                    curr_pair->value);
    2.71 -
    2.72 -                // If we can't find the identity, this is someone we've never mailed, so we just
    2.73 -                // go on letting them use the wrong key until we mail them ourselves. (Spammers, etc)
    2.74 -                if (status != PEP_CANNOT_FIND_IDENTITY) {
    2.75 -                    if (status != PEP_STATUS_OK)
    2.76 -                        goto pEp_error;
    2.77 -
    2.78 -                    if (!reset_msg) {
    2.79 -                        status = PEP_OUT_OF_MEMORY;
    2.80 -                        goto pEp_error;
    2.81 -                    }
    2.82 -                    // insert into queue
    2.83 -                    if (session->messageToSend)
    2.84 -                        status = session->messageToSend(reset_msg);
    2.85 -                    else
    2.86 -                        status = PEP_SYNC_NO_MESSAGE_SEND_CALLBACK;
    2.87 -
    2.88 -
    2.89 -                    if (status == PEP_STATUS_OK) {
    2.90 -                        // Put into notified DB
    2.91 -                        status = set_reset_contact_notified(session, curr_pair->key, msg->from->user_id);
    2.92 -                        if (status != PEP_STATUS_OK) // It's ok to barf because it's a DB problem??
    2.93 +    if (!is_me(session, msg->from)) {
    2.94 +        status = check_for_own_revoked_key(session, _keylist, &revoke_replace_pairs);
    2.95 +
    2.96 +        //assert(status != PEP_STATUS_OK); // FIXME: FOR DEBUGGING ONLY DO NOT LEAVE IN    
    2.97 +        if (status != PEP_STATUS_OK) {
    2.98 +            // This should really never choke unless the DB is broken.
    2.99 +            status = PEP_UNKNOWN_DB_ERROR;
   2.100 +            goto pEp_error;
   2.101 +        }
   2.102 +        
   2.103 +        if (msg) {
   2.104 +            stringpair_list_t* curr_pair_node;
   2.105 +            stringpair_t* curr_pair;
   2.106 +
   2.107 +            for (curr_pair_node = revoke_replace_pairs; curr_pair_node; curr_pair_node = curr_pair_node->next) {
   2.108 +                curr_pair = curr_pair_node->value;
   2.109 +
   2.110 +                if (!curr_pair)
   2.111 +                    continue; // Again, shouldn't occur
   2.112 +
   2.113 +                if (curr_pair->key && curr_pair->value) {
   2.114 +                    status = create_standalone_key_reset_message(session,
   2.115 +                        &reset_msg,
   2.116 +                        msg->from,
   2.117 +                        curr_pair->key,
   2.118 +                        curr_pair->value);
   2.119 +
   2.120 +                    // If we can't find the identity, this is someone we've never mailed, so we just
   2.121 +                    // go on letting them use the wrong key until we mail them ourselves. (Spammers, etc)
   2.122 +                    if (status != PEP_CANNOT_FIND_IDENTITY) {
   2.123 +                        if (status != PEP_STATUS_OK)
   2.124                              goto pEp_error;
   2.125 -                    }
   2.126 -                    else {
   2.127 -                        // According to Volker, this would only be a fatal error, so...
   2.128 -                        free_message(reset_msg); // ??
   2.129 -                        reset_msg = NULL; // ??
   2.130 -                        goto pEp_error;
   2.131 +
   2.132 +                        if (!reset_msg) {
   2.133 +                            status = PEP_OUT_OF_MEMORY;
   2.134 +                            goto pEp_error;
   2.135 +                        }
   2.136 +                        // insert into queue
   2.137 +                        if (session->messageToSend)
   2.138 +                            status = session->messageToSend(reset_msg);
   2.139 +                        else
   2.140 +                            status = PEP_SYNC_NO_MESSAGE_SEND_CALLBACK;
   2.141 +
   2.142 +
   2.143 +                        if (status == PEP_STATUS_OK) {
   2.144 +                            // Put into notified DB
   2.145 +                            status = set_reset_contact_notified(session, curr_pair->key, msg->from->user_id);
   2.146 +                            if (status != PEP_STATUS_OK) // It's ok to barf because it's a DB problem??
   2.147 +                                goto pEp_error;
   2.148 +                        }
   2.149 +                        else {
   2.150 +                            // According to Volker, this would only be a fatal error, so...
   2.151 +                            free_message(reset_msg); // ??
   2.152 +                            reset_msg = NULL; // ??
   2.153 +                            goto pEp_error;
   2.154 +                        }
   2.155                      }
   2.156                  }
   2.157              }
   2.158          }
   2.159 -    }
   2.160 -
   2.161 +        free_stringpair_list(revoke_replace_pairs);
   2.162 +        revoke_replace_pairs = NULL;
   2.163 +    } // end !is_me(msg->from)    
   2.164  
   2.165      bool reenc_signer_key_is_own_key = false; // only matters for reencrypted messages 
   2.166      
   2.167 @@ -3964,7 +3968,8 @@
   2.168      }    
   2.169  
   2.170      if (reencrypt) {
   2.171 -        if (decrypt_status == PEP_DECRYPTED || decrypt_status == PEP_DECRYPTED_AND_VERIFIED) {
   2.172 +        if (decrypt_status == PEP_DECRYPTED || decrypt_status == PEP_DECRYPTED_AND_VERIFIED
   2.173 +            || decrypt_status == PEP_VERIFY_SIGNER_KEY_REVOKED) {
   2.174              const char* sfpr = NULL;
   2.175              if (has_extra_keys)
   2.176                  sfpr = _keylist->value;
   2.177 @@ -4049,6 +4054,7 @@
   2.178      free_message(msg);
   2.179      free_message(reset_msg);
   2.180      free_stringlist(_keylist);
   2.181 +    free_stringpair_list(revoke_replace_pairs);
   2.182  
   2.183      return status;
   2.184  }
     3.1 --- a/src/pEpEngine.h	Sun Dec 08 15:13:05 2019 +0100
     3.2 +++ b/src/pEpEngine.h	Sun Dec 08 15:13:17 2019 +0100
     3.3 @@ -84,8 +84,10 @@
     3.4      PEP_VERIFY_NO_KEY                               = 0x0407,
     3.5      PEP_VERIFIED_AND_TRUSTED                        = 0x0408,
     3.6      PEP_CANNOT_REENCRYPT                            = 0x0409,
     3.7 +    PEP_VERIFY_SIGNER_KEY_REVOKED                   = 0x040a,
     3.8      PEP_CANNOT_DECRYPT_UNKNOWN                      = 0x04ff,
     3.9  
    3.10 +
    3.11      PEP_TRUSTWORD_NOT_FOUND                         = 0x0501,
    3.12      PEP_TRUSTWORDS_FPR_WRONG_LENGTH                 = 0x0502,
    3.13      PEP_TRUSTWORDS_DUPLICATE_FPR                    = 0x0503,
     4.1 --- a/src/pEp_internal.h	Sun Dec 08 15:13:05 2019 +0100
     4.2 +++ b/src/pEp_internal.h	Sun Dec 08 15:13:17 2019 +0100
     4.3 @@ -143,17 +143,17 @@
     4.4          sqlite3_stmt *begin_transaction;
     4.5          sqlite3_stmt *commit_transaction;
     4.6          sqlite3_stmt *rollback_transaction;
     4.7 -        sqlite3_stmt *tpk_find;
     4.8 +        sqlite3_stmt *cert_find;
     4.9          sqlite3_stmt *tsk_find;
    4.10 -        sqlite3_stmt *tpk_find_by_keyid;
    4.11 +        sqlite3_stmt *cert_find_by_keyid;
    4.12          sqlite3_stmt *tsk_find_by_keyid;
    4.13 -        sqlite3_stmt *tpk_find_by_email;
    4.14 +        sqlite3_stmt *cert_find_by_email;
    4.15          sqlite3_stmt *tsk_find_by_email;
    4.16 -        sqlite3_stmt *tpk_all;
    4.17 +        sqlite3_stmt *cert_all;
    4.18          sqlite3_stmt *tsk_all;
    4.19 -        sqlite3_stmt *tpk_save_insert_primary;
    4.20 -        sqlite3_stmt *tpk_save_insert_subkeys;
    4.21 -        sqlite3_stmt *tpk_save_insert_userids;
    4.22 +        sqlite3_stmt *cert_save_insert_primary;
    4.23 +        sqlite3_stmt *cert_save_insert_subkeys;
    4.24 +        sqlite3_stmt *cert_save_insert_userids;
    4.25          sqlite3_stmt *delete_keypair;
    4.26      } sq_sql;
    4.27  #endif
     5.1 --- a/src/pgp_sequoia.c	Sun Dec 08 15:13:05 2019 +0100
     5.2 +++ b/src/pgp_sequoia.c	Sun Dec 08 15:13:17 2019 +0100
     5.3 @@ -166,24 +166,24 @@
     5.4      }
     5.5  }
     5.6  
     5.7 -static pgp_tpk_cipher_suite_t cipher_suite(PEP_CIPHER_SUITE suite)
     5.8 +static pgp_cert_cipher_suite_t cipher_suite(PEP_CIPHER_SUITE suite)
     5.9  {
    5.10      switch (suite) {
    5.11          // supported cipher suites
    5.12          case PEP_CIPHER_SUITE_RSA2K:
    5.13 -            return PGP_TPK_CIPHER_SUITE_RSA2K;
    5.14 +            return PGP_CERT_CIPHER_SUITE_RSA2K;
    5.15          case PEP_CIPHER_SUITE_RSA3K:
    5.16 -            return PGP_TPK_CIPHER_SUITE_RSA3K;
    5.17 +            return PGP_CERT_CIPHER_SUITE_RSA3K;
    5.18          case PEP_CIPHER_SUITE_CV25519:
    5.19 -            return PGP_TPK_CIPHER_SUITE_CV25519;
    5.20 +            return PGP_CERT_CIPHER_SUITE_CV25519;
    5.21          case PEP_CIPHER_SUITE_P256:
    5.22 -            return PGP_TPK_CIPHER_SUITE_P256;
    5.23 +            return PGP_CERT_CIPHER_SUITE_P256;
    5.24          case PEP_CIPHER_SUITE_P384:
    5.25 -            return PGP_TPK_CIPHER_SUITE_P384;
    5.26 +            return PGP_CERT_CIPHER_SUITE_P384;
    5.27          case PEP_CIPHER_SUITE_P521:
    5.28 -            return PGP_TPK_CIPHER_SUITE_P521;
    5.29 +            return PGP_CERT_CIPHER_SUITE_P521;
    5.30          default:
    5.31 -            return PGP_TPK_CIPHER_SUITE_RSA2K;
    5.32 +            return PGP_CERT_CIPHER_SUITE_RSA2K;
    5.33      }
    5.34  }
    5.35  
    5.36 @@ -385,7 +385,7 @@
    5.37          = sqlite3_prepare_v2(session->key_db,
    5.38                               "SELECT tpk, secret FROM keys"
    5.39                               " WHERE primary_key == ?",
    5.40 -                             -1, &session->sq_sql.tpk_find, NULL);
    5.41 +                             -1, &session->sq_sql.cert_find, NULL);
    5.42      assert(sqlite_result == SQLITE_OK);
    5.43  
    5.44      sqlite_result
    5.45 @@ -401,7 +401,7 @@
    5.46                               " LEFT JOIN keys"
    5.47                               "  ON subkeys.primary_key == keys.primary_key"
    5.48                               " WHERE subkey == ?",
    5.49 -                             -1, &session->sq_sql.tpk_find_by_keyid, NULL);
    5.50 +                             -1, &session->sq_sql.cert_find_by_keyid, NULL);
    5.51      assert(sqlite_result == SQLITE_OK);
    5.52  
    5.53      sqlite_result
    5.54 @@ -410,7 +410,7 @@
    5.55                               " LEFT JOIN keys"
    5.56                               "  ON subkeys.primary_key == keys.primary_key"
    5.57                               " WHERE subkey == ?",
    5.58 -                             -1, &session->sq_sql.tpk_find_by_keyid, NULL);
    5.59 +                             -1, &session->sq_sql.cert_find_by_keyid, NULL);
    5.60      assert(sqlite_result == SQLITE_OK);
    5.61  
    5.62      sqlite_result
    5.63 @@ -428,7 +428,7 @@
    5.64                               " LEFT JOIN keys"
    5.65                               "  ON userids.primary_key == keys.primary_key"
    5.66                               " WHERE userid == ?",
    5.67 -                             -1, &session->sq_sql.tpk_find_by_email, NULL);
    5.68 +                             -1, &session->sq_sql.cert_find_by_email, NULL);
    5.69      assert(sqlite_result == SQLITE_OK);
    5.70  
    5.71      sqlite_result
    5.72 @@ -443,7 +443,7 @@
    5.73      sqlite_result
    5.74          = sqlite3_prepare_v2(session->key_db,
    5.75                               "select tpk, secret from keys",
    5.76 -                             -1, &session->sq_sql.tpk_all, NULL);
    5.77 +                             -1, &session->sq_sql.cert_all, NULL);
    5.78      assert(sqlite_result == SQLITE_OK);
    5.79  
    5.80      sqlite_result
    5.81 @@ -457,7 +457,7 @@
    5.82                               "INSERT OR REPLACE INTO keys"
    5.83                               "   (primary_key, secret, tpk)"
    5.84                               " VALUES (?, ?, ?)",
    5.85 -                             -1, &session->sq_sql.tpk_save_insert_primary, NULL);
    5.86 +                             -1, &session->sq_sql.cert_save_insert_primary, NULL);
    5.87      assert(sqlite_result == SQLITE_OK);
    5.88  
    5.89      sqlite_result
    5.90 @@ -465,7 +465,7 @@
    5.91                               "INSERT OR REPLACE INTO subkeys"
    5.92                               "   (subkey, primary_key)"
    5.93                               " VALUES (?, ?)",
    5.94 -                             -1, &session->sq_sql.tpk_save_insert_subkeys, NULL);
    5.95 +                             -1, &session->sq_sql.cert_save_insert_subkeys, NULL);
    5.96      assert(sqlite_result == SQLITE_OK);
    5.97  
    5.98      sqlite_result
    5.99 @@ -473,7 +473,7 @@
   5.100                               "INSERT OR REPLACE INTO userids"
   5.101                               "   (userid, primary_key)"
   5.102                               " VALUES (?, ?)",
   5.103 -                             -1, &session->sq_sql.tpk_save_insert_userids, NULL);
   5.104 +                             -1, &session->sq_sql.cert_save_insert_userids, NULL);
   5.105      assert(sqlite_result == SQLITE_OK);
   5.106  
   5.107      sqlite_result
   5.108 @@ -521,24 +521,24 @@
   5.109      return fpr_canonicalized;
   5.110  }
   5.111  
   5.112 -// step statement and load the tpk and secret.
   5.113 -static PEP_STATUS key_load(PEP_SESSION, sqlite3_stmt *, pgp_tpk_t *, int *)
   5.114 +// step statement and load the certificate and secret.
   5.115 +static PEP_STATUS key_load(PEP_SESSION, sqlite3_stmt *, pgp_cert_t *, int *)
   5.116      __attribute__((nonnull(1, 2)));
   5.117  static PEP_STATUS key_load(PEP_SESSION session, sqlite3_stmt *stmt,
   5.118 -                           pgp_tpk_t *tpkp, int *secretp)
   5.119 +                           pgp_cert_t *certp, int *secretp)
   5.120  {
   5.121      PEP_STATUS status = PEP_STATUS_OK;
   5.122      int sqlite_result = sqlite3_step(stmt);
   5.123      switch (sqlite_result) {
   5.124      case SQLITE_ROW:
   5.125 -        if (tpkp) {
   5.126 +        if (certp) {
   5.127              int data_len = sqlite3_column_bytes(stmt, 0);
   5.128              const void *data = sqlite3_column_blob(stmt, 0);
   5.129  
   5.130              pgp_error_t err = NULL;
   5.131 -            *tpkp = pgp_tpk_from_bytes(&err, data, data_len);
   5.132 -            if (!*tpkp)
   5.133 -                ERROR_OUT(err, PEP_GET_KEY_FAILED, "parsing TPK");
   5.134 +            *certp = pgp_cert_from_bytes(&err, data, data_len);
   5.135 +            if (!*certp)
   5.136 +                ERROR_OUT(err, PEP_GET_KEY_FAILED, "parsing certificate");
   5.137          }
   5.138  
   5.139          if (secretp)
   5.140 @@ -559,59 +559,59 @@
   5.141      return status;
   5.142  }
   5.143  
   5.144 -// step statement until exhausted and load the tpks.
   5.145 -static PEP_STATUS key_loadn(PEP_SESSION, sqlite3_stmt *, pgp_tpk_t **, int *)
   5.146 +// step statement until exhausted and load the certificates.
   5.147 +static PEP_STATUS key_loadn(PEP_SESSION, sqlite3_stmt *, pgp_cert_t **, int *)
   5.148      __attribute__((nonnull));
   5.149  static PEP_STATUS key_loadn(PEP_SESSION session, sqlite3_stmt *stmt,
   5.150 -                            pgp_tpk_t **tpksp, int *tpks_countp)
   5.151 +                            pgp_cert_t **certsp, int *certs_countp)
   5.152  {
   5.153      PEP_STATUS status = PEP_STATUS_OK;
   5.154 -    int tpks_count = 0;
   5.155 -    int tpks_capacity = 8;
   5.156 -    pgp_tpk_t *tpks = calloc(tpks_capacity, sizeof(pgp_tpk_t));
   5.157 -    if (!tpks)
   5.158 +    int certs_count = 0;
   5.159 +    int certs_capacity = 8;
   5.160 +    pgp_cert_t *certs = calloc(certs_capacity, sizeof(pgp_cert_t));
   5.161 +    if (!certs)
   5.162          ERROR_OUT(NULL, PEP_OUT_OF_MEMORY, "out of memory");
   5.163  
   5.164      for (;;) {
   5.165 -        pgp_tpk_t tpk = NULL;
   5.166 -        status = key_load(session, stmt, &tpk, NULL);
   5.167 +        pgp_cert_t cert = NULL;
   5.168 +        status = key_load(session, stmt, &cert, NULL);
   5.169          if (status == PEP_KEY_NOT_FOUND) {
   5.170              status = PEP_STATUS_OK;
   5.171              break;
   5.172          }
   5.173 -        ERROR_OUT(NULL, status, "loading TPK");
   5.174 -
   5.175 -        if (tpks_count == tpks_capacity) {
   5.176 -            tpks_capacity *= 2;
   5.177 -            tpks = realloc(tpks, sizeof(tpks[0]) * tpks_capacity);
   5.178 -            if (!tpks)
   5.179 -                ERROR_OUT(NULL, PEP_OUT_OF_MEMORY, "tpks");
   5.180 +        ERROR_OUT(NULL, status, "loading certificate");
   5.181 +
   5.182 +        if (certs_count == certs_capacity) {
   5.183 +            certs_capacity *= 2;
   5.184 +            certs = realloc(certs, sizeof(certs[0]) * certs_capacity);
   5.185 +            if (!certs)
   5.186 +                ERROR_OUT(NULL, PEP_OUT_OF_MEMORY, "certs");
   5.187          }
   5.188 -        tpks[tpks_count ++] = tpk;
   5.189 +        certs[certs_count ++] = cert;
   5.190      }
   5.191  
   5.192   out:
   5.193      if (status != PEP_STATUS_OK) {
   5.194 -        for (int i = 0; i < tpks_count; i ++)
   5.195 -            pgp_tpk_free(tpks[i]);
   5.196 -        free(tpks);
   5.197 +        for (int i = 0; i < certs_count; i ++)
   5.198 +            pgp_cert_free(certs[i]);
   5.199 +        free(certs);
   5.200      } else {
   5.201 -        *tpksp = tpks;
   5.202 -        *tpks_countp = tpks_count;
   5.203 +        *certsp = certs;
   5.204 +        *certs_countp = certs_count;
   5.205      }
   5.206  
   5.207 -    T(" -> %s (%d tpks)", pEp_status_to_string(status), *tpks_countp);
   5.208 +    T(" -> %s (%d certs)", pEp_status_to_string(status), *certs_countp);
   5.209      return status;
   5.210  }
   5.211  
   5.212 -// Returns the TPK identified by the provided fingerprint.
   5.213 +// Returns the certificate identified by the provided fingerprint.
   5.214  //
   5.215  // This function only matches on the primary key!
   5.216 -static PEP_STATUS tpk_find(PEP_SESSION, pgp_fingerprint_t, int, pgp_tpk_t *, int *)
   5.217 +static PEP_STATUS cert_find(PEP_SESSION, pgp_fingerprint_t, int, pgp_cert_t *, int *)
   5.218      __attribute__((nonnull(1, 2)));
   5.219 -static PEP_STATUS tpk_find(PEP_SESSION session,
   5.220 +static PEP_STATUS cert_find(PEP_SESSION session,
   5.221                             pgp_fingerprint_t fpr, int private_only,
   5.222 -                           pgp_tpk_t *tpk, int *secret)
   5.223 +                           pgp_cert_t *cert, int *secret)
   5.224  {
   5.225      PEP_STATUS status = PEP_STATUS_OK;
   5.226      char *fpr_str = pgp_fingerprint_to_hex(fpr);
   5.227 @@ -619,10 +619,10 @@
   5.228      T("(%s, %d)", fpr_str, private_only);
   5.229  
   5.230      sqlite3_stmt *stmt
   5.231 -        = private_only ? session->sq_sql.tsk_find : session->sq_sql.tpk_find;
   5.232 +        = private_only ? session->sq_sql.tsk_find : session->sq_sql.cert_find;
   5.233      sqlite3_bind_text(stmt, 1, fpr_str, -1, SQLITE_STATIC);
   5.234  
   5.235 -    status = key_load(session, stmt, tpk, secret);
   5.236 +    status = key_load(session, stmt, cert, secret);
   5.237      ERROR_OUT(NULL, status, "Looking up %s", fpr_str);
   5.238  
   5.239   out:
   5.240 @@ -632,31 +632,31 @@
   5.241      return status;
   5.242  }
   5.243  
   5.244 -// Returns the TPK identified by the provided keyid.
   5.245 +// Returns the certificate identified by the provided keyid.
   5.246  //
   5.247  // This function matches on both primary keys and subkeys!
   5.248  //
   5.249 -// Note: There can be multiple TPKs for a given keyid.  This can
   5.250 -// occur, because an encryption subkey can be bound to multiple TPKs.
   5.251 +// Note: There can be multiple certificates for a given keyid.  This can
   5.252 +// occur, because an encryption subkey can be bound to multiple certificates.
   5.253  // Also, it is possible to collide key ids.  If there are multiple key
   5.254  // ids for a given key, this just returns one of them.
   5.255  //
   5.256 -// If private_only is set, this will only consider TPKs with some
   5.257 +// If private_only is set, this will only consider certificates with some
   5.258  // secret key material.
   5.259 -static PEP_STATUS tpk_find_by_keyid_hex(PEP_SESSION, const char *, int, pgp_tpk_t *, int *)
   5.260 +static PEP_STATUS cert_find_by_keyid_hex(PEP_SESSION, const char *, int, pgp_cert_t *, int *)
   5.261    __attribute__((nonnull(1, 2)));
   5.262 -static PEP_STATUS tpk_find_by_keyid_hex(
   5.263 +static PEP_STATUS cert_find_by_keyid_hex(
   5.264          PEP_SESSION session, const char *keyid_hex, int private_only,
   5.265 -        pgp_tpk_t *tpkp, int *secretp)
   5.266 +        pgp_cert_t *certp, int *secretp)
   5.267  {
   5.268      PEP_STATUS status = PEP_STATUS_OK;
   5.269      T("(%s, %d)", keyid_hex, private_only);
   5.270  
   5.271      sqlite3_stmt *stmt
   5.272 -        = private_only ? session->sq_sql.tsk_find_by_keyid : session->sq_sql.tpk_find_by_keyid;
   5.273 +        = private_only ? session->sq_sql.tsk_find_by_keyid : session->sq_sql.cert_find_by_keyid;
   5.274      sqlite3_bind_text(stmt, 1, keyid_hex, -1, SQLITE_STATIC);
   5.275  
   5.276 -    status = key_load(session, stmt, tpkp, secretp);
   5.277 +    status = key_load(session, stmt, certp, secretp);
   5.278      ERROR_OUT(NULL, status, "Looking up %s", keyid_hex);
   5.279  
   5.280   out:
   5.281 @@ -665,63 +665,63 @@
   5.282      return status;
   5.283  }
   5.284  
   5.285 -// See tpk_find_by_keyid_hex.
   5.286 -PEP_STATUS tpk_find_by_keyid(PEP_SESSION, pgp_keyid_t, int, pgp_tpk_t *, int *)
   5.287 +// See cert_find_by_keyid_hex.
   5.288 +PEP_STATUS cert_find_by_keyid(PEP_SESSION, pgp_keyid_t, int, pgp_cert_t *, int *)
   5.289      __attribute__((nonnull(1, 2)));
   5.290 -PEP_STATUS tpk_find_by_keyid(PEP_SESSION session,
   5.291 +PEP_STATUS cert_find_by_keyid(PEP_SESSION session,
   5.292                               pgp_keyid_t keyid, int private_only,
   5.293 -                             pgp_tpk_t *tpkp, int *secretp)
   5.294 +                             pgp_cert_t *certp, int *secretp)
   5.295  {
   5.296      char *keyid_hex = pgp_keyid_to_hex(keyid);
   5.297      if (! keyid_hex)
   5.298          return PEP_OUT_OF_MEMORY;
   5.299      PEP_STATUS status
   5.300 -        = tpk_find_by_keyid_hex(session, keyid_hex, private_only, tpkp, secretp);
   5.301 +        = cert_find_by_keyid_hex(session, keyid_hex, private_only, certp, secretp);
   5.302      free(keyid_hex);
   5.303      return status;
   5.304  }
   5.305  
   5.306 -// See tpk_find_by_keyid_hex.
   5.307 -static PEP_STATUS tpk_find_by_fpr(PEP_SESSION, pgp_fingerprint_t, int,
   5.308 -                                  pgp_tpk_t *, int *)
   5.309 +// See cert_find_by_keyid_hex.
   5.310 +static PEP_STATUS cert_find_by_fpr(PEP_SESSION, pgp_fingerprint_t, int,
   5.311 +                                  pgp_cert_t *, int *)
   5.312      __attribute__((nonnull(1, 2)));
   5.313 -static PEP_STATUS tpk_find_by_fpr(
   5.314 +static PEP_STATUS cert_find_by_fpr(
   5.315      PEP_SESSION session, pgp_fingerprint_t fpr, int private_only,
   5.316 -    pgp_tpk_t *tpkp, int *secretp)
   5.317 +    pgp_cert_t *certp, int *secretp)
   5.318  {
   5.319      pgp_keyid_t keyid = pgp_fingerprint_to_keyid(fpr);
   5.320      if (! keyid)
   5.321          return PEP_OUT_OF_MEMORY;
   5.322      PEP_STATUS status
   5.323 -        = tpk_find_by_keyid(session, keyid, private_only, tpkp, secretp);
   5.324 +        = cert_find_by_keyid(session, keyid, private_only, certp, secretp);
   5.325      pgp_keyid_free(keyid);
   5.326      return status;
   5.327  }
   5.328  
   5.329 -// See tpk_find_by_keyid_hex.
   5.330 -static PEP_STATUS tpk_find_by_fpr_hex(PEP_SESSION, const char *, int, pgp_tpk_t *, int *secret)
   5.331 +// See cert_find_by_keyid_hex.
   5.332 +static PEP_STATUS cert_find_by_fpr_hex(PEP_SESSION, const char *, int, pgp_cert_t *, int *secret)
   5.333      __attribute__((nonnull(1, 2)));
   5.334 -static PEP_STATUS tpk_find_by_fpr_hex(
   5.335 +static PEP_STATUS cert_find_by_fpr_hex(
   5.336      PEP_SESSION session, const char *fpr, int private_only,
   5.337 -    pgp_tpk_t *tpkp, int *secretp)
   5.338 +    pgp_cert_t *certp, int *secretp)
   5.339  {
   5.340      pgp_fingerprint_t pgp_fpr = pgp_fingerprint_from_hex(fpr);
   5.341      if (! pgp_fpr)
   5.342          return PEP_OUT_OF_MEMORY;
   5.343      PEP_STATUS status
   5.344 -        = tpk_find_by_fpr(session, pgp_fpr, private_only, tpkp, secretp);
   5.345 +        = cert_find_by_fpr(session, pgp_fpr, private_only, certp, secretp);
   5.346      pgp_fingerprint_free(pgp_fpr);
   5.347      return status;
   5.348  }
   5.349  
   5.350 -// Returns all known TPKs.
   5.351 -static PEP_STATUS tpk_all(PEP_SESSION, int, pgp_tpk_t **, int *) __attribute__((nonnull));
   5.352 -static PEP_STATUS tpk_all(PEP_SESSION session, int private_only,
   5.353 -                          pgp_tpk_t **tpksp, int *tpks_countp) {
   5.354 +// Returns all known certificates.
   5.355 +static PEP_STATUS cert_all(PEP_SESSION, int, pgp_cert_t **, int *) __attribute__((nonnull));
   5.356 +static PEP_STATUS cert_all(PEP_SESSION session, int private_only,
   5.357 +                          pgp_cert_t **certsp, int *certs_countp) {
   5.358      PEP_STATUS status = PEP_STATUS_OK;
   5.359 -    sqlite3_stmt *stmt = private_only ? session->sq_sql.tsk_all : session->sq_sql.tpk_all;
   5.360 -    status = key_loadn(session, stmt, tpksp, tpks_countp);
   5.361 -    ERROR_OUT(NULL, status, "loading TPKs");
   5.362 +    sqlite3_stmt *stmt = private_only ? session->sq_sql.tsk_all : session->sq_sql.cert_all;
   5.363 +    status = key_loadn(session, stmt, certsp, certs_countp);
   5.364 +    ERROR_OUT(NULL, status, "loading certificates");
   5.365   out:
   5.366      sqlite3_reset(stmt);
   5.367      return status;
   5.368 @@ -729,21 +729,21 @@
   5.369  
   5.370  // Returns keys that have a user id that matches the specified pattern.
   5.371  //
   5.372 -// The keys returned must be freed using pgp_tpk_free.
   5.373 -static PEP_STATUS tpk_find_by_email(PEP_SESSION, const char *, int, pgp_tpk_t **, int *)
   5.374 +// The keys returned must be freed using pgp_cert_free.
   5.375 +static PEP_STATUS cert_find_by_email(PEP_SESSION, const char *, int, pgp_cert_t **, int *)
   5.376      __attribute__((nonnull));
   5.377 -static PEP_STATUS tpk_find_by_email(PEP_SESSION session,
   5.378 +static PEP_STATUS cert_find_by_email(PEP_SESSION session,
   5.379                                      const char *pattern, int private_only,
   5.380 -                                    pgp_tpk_t **tpksp, int *countp)
   5.381 +                                    pgp_cert_t **certsp, int *countp)
   5.382  {
   5.383      PEP_STATUS status = PEP_STATUS_OK;
   5.384      T("(%s)", pattern);
   5.385  
   5.386      sqlite3_stmt *stmt
   5.387 -        = private_only ? session->sq_sql.tsk_find_by_email : session->sq_sql.tpk_find_by_email;
   5.388 +        = private_only ? session->sq_sql.tsk_find_by_email : session->sq_sql.cert_find_by_email;
   5.389      sqlite3_bind_text(stmt, 1, pattern, -1, SQLITE_STATIC);
   5.390  
   5.391 -    status = key_loadn(session, stmt, tpksp, countp);
   5.392 +    status = key_loadn(session, stmt, certsp, countp);
   5.393      ERROR_OUT(NULL, status, "Searching for '%s'", pattern);
   5.394  
   5.395   out:
   5.396 @@ -753,12 +753,12 @@
   5.397  }
   5.398  
   5.399  
   5.400 -// Saves the specified TPK.
   5.401 +// Saves the specified certificates.
   5.402  //
   5.403 -// This function takes ownership of TPK.
   5.404 -static PEP_STATUS tpk_save(PEP_SESSION, pgp_tpk_t, identity_list **)
   5.405 +// This function takes ownership of CERT.
   5.406 +static PEP_STATUS cert_save(PEP_SESSION, pgp_cert_t, identity_list **)
   5.407      __attribute__((nonnull(1, 2)));
   5.408 -static PEP_STATUS tpk_save(PEP_SESSION session, pgp_tpk_t tpk,
   5.409 +static PEP_STATUS cert_save(PEP_SESSION session, pgp_cert_t cert,
   5.410                             identity_list **private_idents)
   5.411  {
   5.412      PEP_STATUS status = PEP_STATUS_OK;
   5.413 @@ -768,7 +768,7 @@
   5.414      void *tsk_buffer = NULL;
   5.415      size_t tsk_buffer_len = 0;
   5.416      int tried_commit = 0;
   5.417 -    pgp_tpk_key_iter_t key_iter = NULL;
   5.418 +    pgp_cert_key_iter_t key_iter = NULL;
   5.419      pgp_user_id_binding_iter_t user_id_iter = NULL;
   5.420      char *email = NULL;
   5.421      char *name = NULL;
   5.422 @@ -781,24 +781,24 @@
   5.423                    "begin transaction failed: %s",
   5.424                    sqlite3_errmsg(session->key_db));
   5.425  
   5.426 -    pgp_fpr = pgp_tpk_fingerprint(tpk);
   5.427 +    pgp_fpr = pgp_cert_fingerprint(cert);
   5.428      fpr = pgp_fingerprint_to_hex(pgp_fpr);
   5.429      T("(%s, private_idents: %s)", fpr, private_idents ? "yes" : "no");
   5.430  
   5.431 -    // Merge any existing data into TPK.
   5.432 -    pgp_tpk_t current = NULL;
   5.433 -    status = tpk_find(session, pgp_fpr, false, &current, NULL);
   5.434 +    // Merge any existing data into certificate.
   5.435 +    pgp_cert_t current = NULL;
   5.436 +    status = cert_find(session, pgp_fpr, false, &current, NULL);
   5.437      if (status == PEP_KEY_NOT_FOUND)
   5.438          status = PEP_STATUS_OK;
   5.439      else
   5.440          ERROR_OUT(NULL, status, "Looking up %s", fpr);
   5.441      if (current) {
   5.442 -        tpk = pgp_tpk_merge(&err, tpk, current);
   5.443 -        if (! tpk)
   5.444 -            ERROR_OUT(err, PEP_UNKNOWN_ERROR, "Merging TPKs");
   5.445 +        cert = pgp_cert_merge(&err, cert, current);
   5.446 +        if (! cert)
   5.447 +            ERROR_OUT(err, PEP_UNKNOWN_ERROR, "Merging certificates");
   5.448      }
   5.449  
   5.450 -    int is_tsk = pgp_tpk_is_tsk(tpk);
   5.451 +    int is_tsk = pgp_cert_is_tsk(cert);
   5.452  
   5.453      // Serialize it.
   5.454      pgp_writer_t writer = pgp_writer_alloc(&tsk_buffer, &tsk_buffer_len);
   5.455 @@ -806,16 +806,16 @@
   5.456          ERROR_OUT(NULL, PEP_OUT_OF_MEMORY, "out of memory");
   5.457  
   5.458      pgp_status_t pgp_status;
   5.459 -    pgp_tsk_t tsk = pgp_tpk_as_tsk(tpk);
   5.460 +    pgp_tsk_t tsk = pgp_cert_as_tsk(cert);
   5.461      pgp_status = pgp_tsk_serialize(&err, tsk, writer);
   5.462      pgp_tsk_free(tsk);
   5.463      pgp_writer_free(writer);
   5.464      if (pgp_status != 0)
   5.465 -        ERROR_OUT(err, PEP_UNKNOWN_ERROR, "Serializing TPK");
   5.466 +        ERROR_OUT(err, PEP_UNKNOWN_ERROR, "Serializing certificates");
   5.467  
   5.468  
   5.469      // Insert the TSK into the DB.
   5.470 -    stmt = session->sq_sql.tpk_save_insert_primary;
   5.471 +    stmt = session->sq_sql.cert_save_insert_primary;
   5.472      sqlite3_bind_text(stmt, 1, fpr, -1, SQLITE_STATIC);
   5.473      sqlite3_bind_int(stmt, 2, is_tsk);
   5.474      sqlite3_bind_blob(stmt, 3, tsk_buffer, tsk_buffer_len, SQLITE_STATIC);
   5.475 @@ -824,15 +824,15 @@
   5.476      sqlite3_reset(stmt);
   5.477      if (sqlite_result != SQLITE_DONE)
   5.478          ERROR_OUT(NULL, PEP_UNKNOWN_ERROR,
   5.479 -                  "Saving TPK: %s", sqlite3_errmsg(session->key_db));
   5.480 +                  "Saving certificate: %s", sqlite3_errmsg(session->key_db));
   5.481  
   5.482      // Insert the "subkeys" (the primary key and the subkeys).
   5.483 -    stmt = session->sq_sql.tpk_save_insert_subkeys;
   5.484 -    // This inserts all of the keys in the TPK, i.e., revoked and
   5.485 +    stmt = session->sq_sql.cert_save_insert_subkeys;
   5.486 +    // This inserts all of the keys in the certificate, i.e., revoked and
   5.487      // expired keys, which is what we want.
   5.488 -    key_iter = pgp_tpk_key_iter_all(tpk);
   5.489 +    key_iter = pgp_cert_key_iter_all(cert);
   5.490      pgp_key_t key;
   5.491 -    while ((key = pgp_tpk_key_iter_next(key_iter, NULL, NULL))) {
   5.492 +    while ((key = pgp_cert_key_iter_next(key_iter, NULL, NULL))) {
   5.493          pgp_keyid_t keyid = pgp_key_keyid(key);
   5.494          char *keyid_hex = pgp_keyid_to_hex(keyid);
   5.495          sqlite3_bind_text(stmt, 1, keyid_hex, -1, SQLITE_STATIC);
   5.496 @@ -843,17 +843,17 @@
   5.497          free(keyid_hex);
   5.498          pgp_keyid_free(keyid);
   5.499          if (sqlite_result != SQLITE_DONE) {
   5.500 -            pgp_tpk_key_iter_free(key_iter);
   5.501 +            pgp_cert_key_iter_free(key_iter);
   5.502              ERROR_OUT(NULL, PEP_UNKNOWN_ERROR,
   5.503                        "Updating subkeys: %s", sqlite3_errmsg(session->key_db));
   5.504          }
   5.505      }
   5.506 -    pgp_tpk_key_iter_free(key_iter);
   5.507 +    pgp_cert_key_iter_free(key_iter);
   5.508      key_iter = NULL;
   5.509  
   5.510      // Insert the "userids".
   5.511 -    stmt = session->sq_sql.tpk_save_insert_userids;
   5.512 -    user_id_iter = pgp_tpk_user_id_binding_iter(tpk);
   5.513 +    stmt = session->sq_sql.cert_save_insert_userids;
   5.514 +    user_id_iter = pgp_cert_user_id_binding_iter(cert);
   5.515      pgp_user_id_binding_t binding;
   5.516      int first = 1;
   5.517      while ((binding = pgp_user_id_binding_iter_next(user_id_iter))) {
   5.518 @@ -938,11 +938,11 @@
   5.519      free(email);
   5.520      free(name);
   5.521      pgp_user_id_binding_iter_free(user_id_iter);
   5.522 -    pgp_tpk_key_iter_free(key_iter);
   5.523 +    pgp_cert_key_iter_free(key_iter);
   5.524      if (stmt)
   5.525        sqlite3_reset(stmt);
   5.526      free(tsk_buffer);
   5.527 -    pgp_tpk_free(tpk);
   5.528 +    pgp_cert_free(cert);
   5.529      free(fpr);
   5.530      pgp_fingerprint_free(pgp_fpr);
   5.531  
   5.532 @@ -957,6 +957,7 @@
   5.533      int good_checksums;
   5.534      int good_but_expired;
   5.535      int good_but_revoked;
   5.536 +    int not_alive;
   5.537      int missing_keys;
   5.538      int bad_checksums;
   5.539  
   5.540 @@ -971,27 +972,27 @@
   5.541  static pgp_status_t
   5.542  get_public_keys_cb(void *cookie_raw,
   5.543                     pgp_keyid_t *keyids, size_t keyids_len,
   5.544 -                   pgp_tpk_t **tpks, size_t *tpk_len,
   5.545 +                   pgp_cert_t **certs, size_t *certs_len,
   5.546                     void (**our_free)(void *))
   5.547  {
   5.548      struct decrypt_cookie *cookie = cookie_raw;
   5.549      PEP_SESSION session = cookie->session;
   5.550  
   5.551 -    *tpks = calloc(keyids_len, sizeof(*tpks));
   5.552 -    if (!*tpks)
   5.553 +    *certs = calloc(keyids_len, sizeof(*certs));
   5.554 +    if (!*certs)
   5.555          return PGP_STATUS_UNKNOWN_ERROR;
   5.556      *our_free = free;
   5.557  
   5.558      int i, j;
   5.559      j = 0;
   5.560      for (i = 0; i < keyids_len; i ++) {
   5.561 -        pgp_tpk_t tpk = NULL;
   5.562 +        pgp_cert_t cert = NULL;
   5.563          PEP_STATUS status
   5.564 -            = tpk_find_by_keyid(session, keyids[i], false, &tpk, NULL);
   5.565 +            = cert_find_by_keyid(session, keyids[i], false, &cert, NULL);
   5.566          if (status == PEP_STATUS_OK)
   5.567 -            (*tpks)[j ++] = tpk;
   5.568 +            (*certs)[j ++] = cert;
   5.569      }
   5.570 -    *tpk_len = j;
   5.571 +    *certs_len = j;
   5.572      return PGP_STATUS_SUCCESS;
   5.573  }
   5.574  
   5.575 @@ -1006,7 +1007,7 @@
   5.576      pgp_error_t err = NULL;
   5.577      struct decrypt_cookie *cookie = cookie_opaque;
   5.578      PEP_SESSION session = cookie->session;
   5.579 -    pgp_tpk_t *tsks = NULL;
   5.580 +    pgp_cert_t *tsks = NULL;
   5.581      int tsks_count = 0;
   5.582      int wildcards = 0;
   5.583  
   5.584 @@ -1022,7 +1023,7 @@
   5.585          pgp_pkesk_t pkesk = pkesks[i];
   5.586          pgp_keyid_t keyid = pgp_pkesk_recipient(pkesk); /* Reference. */
   5.587          char *keyid_str = pgp_keyid_to_hex(keyid);
   5.588 -        pgp_tpk_key_iter_t key_iter = NULL;
   5.589 +        pgp_cert_key_iter_t key_iter = NULL;
   5.590          pgp_session_key_t sk = NULL;
   5.591  
   5.592          T("Considering PKESK for %s", keyid_str);
   5.593 @@ -1035,12 +1036,12 @@
   5.594  
   5.595          // Collect the recipients.  Note: we must return the primary
   5.596          // key's fingerprint.
   5.597 -        pgp_tpk_t tpk = NULL;
   5.598 +        pgp_cert_t cert = NULL;
   5.599          int is_tsk = 0;
   5.600 -        if (tpk_find_by_keyid(session, keyid, false, &tpk, &is_tsk) != PEP_STATUS_OK)
   5.601 +        if (cert_find_by_keyid(session, keyid, false, &cert, &is_tsk) != PEP_STATUS_OK)
   5.602              goto eol;
   5.603  
   5.604 -        pgp_fingerprint_t fp = pgp_tpk_fingerprint(tpk);
   5.605 +        pgp_fingerprint_t fp = pgp_cert_fingerprint(cert);
   5.606          char *fp_string = pgp_fingerprint_to_hex(fp);
   5.607          stringlist_add_unique(cookie->recipient_keylist, fp_string);
   5.608          free(fp_string);
   5.609 @@ -1050,13 +1051,13 @@
   5.610              goto eol;
   5.611  
   5.612          // See if we have the secret key.
   5.613 -        assert(is_tsk == pgp_tpk_is_tsk(tpk));
   5.614 +        assert(is_tsk == pgp_cert_is_tsk(cert));
   5.615          if (! is_tsk)
   5.616              goto eol;
   5.617  
   5.618 -        key_iter = pgp_tpk_key_iter_all(tpk);
   5.619 +        key_iter = pgp_cert_key_iter_all(cert);
   5.620          pgp_key_t key;
   5.621 -        while ((key = pgp_tpk_key_iter_next(key_iter, NULL, NULL))) {
   5.622 +        while ((key = pgp_cert_key_iter_next(key_iter, NULL, NULL))) {
   5.623              pgp_keyid_t this_keyid = pgp_key_keyid(key);
   5.624              char *this_keyid_hex = pgp_keyid_to_hex(this_keyid);
   5.625              pgp_keyid_free(this_keyid);
   5.626 @@ -1090,14 +1091,14 @@
   5.627  
   5.628          T("Decrypted PKESK for %s", keyid_str);
   5.629  
   5.630 -        *identity_out = pgp_tpk_fingerprint(tpk);
   5.631 +        *identity_out = pgp_cert_fingerprint(cert);
   5.632          cookie->decrypted = 1;
   5.633  
   5.634      eol:
   5.635          pgp_session_key_free (sk);
   5.636          free(keyid_str);
   5.637 -        pgp_tpk_key_iter_free(key_iter);
   5.638 -        pgp_tpk_free(tpk);
   5.639 +        pgp_cert_key_iter_free(key_iter);
   5.640 +        pgp_cert_free(cert);
   5.641      }
   5.642  
   5.643      // Consider wildcard recipients.
   5.644 @@ -1105,27 +1106,27 @@
   5.645          pgp_pkesk_t pkesk = pkesks[i];
   5.646          pgp_keyid_t keyid = pgp_pkesk_recipient(pkesk); /* Reference. */
   5.647          char *keyid_str = pgp_keyid_to_hex(keyid);
   5.648 -        pgp_tpk_key_iter_t key_iter = NULL;
   5.649 +        pgp_cert_key_iter_t key_iter = NULL;
   5.650          pgp_session_key_t sk = NULL;
   5.651  
   5.652          if (strcmp(keyid_str, "0000000000000000") != 0)
   5.653              goto eol2;
   5.654  
   5.655          if (!tsks) {
   5.656 -            if (tpk_all(session, true, &tsks, &tsks_count) != PEP_STATUS_OK) {
   5.657 +            if (cert_all(session, true, &tsks, &tsks_count) != PEP_STATUS_OK) {
   5.658                  DUMP_ERR(NULL, PEP_UNKNOWN_ERROR, "Getting all tsks");
   5.659              }
   5.660          }
   5.661  
   5.662          for (int j = 0; j < tsks_count; j ++) {
   5.663 -            pgp_tpk_t tsk = tsks[j];
   5.664 -
   5.665 -            key_iter = pgp_tpk_key_iter_all(tsk);
   5.666 +            pgp_cert_t tsk = tsks[j];
   5.667 +
   5.668 +            key_iter = pgp_cert_key_iter_all(tsk);
   5.669              pgp_key_t key;
   5.670              pgp_signature_t selfsig;
   5.671 -            while ((key = pgp_tpk_key_iter_next(key_iter, &selfsig, NULL))) {
   5.672 -                if (! (pgp_signature_can_encrypt_at_rest(selfsig)
   5.673 -                       || pgp_signature_can_encrypt_for_transport(selfsig)))
   5.674 +            while ((key = pgp_cert_key_iter_next(key_iter, &selfsig, NULL))) {
   5.675 +                if (! (pgp_signature_for_storage_encryption(selfsig)
   5.676 +                       || pgp_signature_for_transport_encryption(selfsig)))
   5.677                      continue;
   5.678  
   5.679                  fprintf(stderr, "key: %s\n", pgp_key_debug(key));
   5.680 @@ -1145,7 +1146,7 @@
   5.681                  }
   5.682  
   5.683                  // Add it to the recipient list.
   5.684 -                pgp_fingerprint_t fp = pgp_tpk_fingerprint(tsk);
   5.685 +                pgp_fingerprint_t fp = pgp_cert_fingerprint(tsk);
   5.686                  char *fp_string = pgp_fingerprint_to_hex(fp);
   5.687                  T("wildcard recipient appears to be %s", fp_string);
   5.688                  stringlist_add_unique(cookie->recipient_keylist, fp_string);
   5.689 @@ -1160,24 +1161,24 @@
   5.690                      goto eol2;
   5.691                  }
   5.692  
   5.693 -                *identity_out = pgp_tpk_fingerprint(tsk);
   5.694 +                *identity_out = pgp_cert_fingerprint(tsk);
   5.695                  cookie->decrypted = 1;
   5.696  
   5.697                  break;
   5.698              }
   5.699  
   5.700 -            pgp_tpk_key_iter_free(key_iter);
   5.701 +            pgp_cert_key_iter_free(key_iter);
   5.702              key_iter = NULL;
   5.703          }
   5.704      eol2:
   5.705          pgp_session_key_free (sk);
   5.706          free(keyid_str);
   5.707 -        pgp_tpk_key_iter_free(key_iter);
   5.708 +        pgp_cert_key_iter_free(key_iter);
   5.709      }
   5.710  
   5.711      if (tsks) {
   5.712          for (int i = 0; i < tsks_count; i ++)
   5.713 -            pgp_tpk_free(tsks[i]);
   5.714 +            pgp_cert_free(tsks[i]);
   5.715          free(tsks);
   5.716      }
   5.717  
   5.718 @@ -1218,7 +1219,7 @@
   5.719                      pgp_verification_result_good_checksum (result, &sig, NULL,
   5.720                                                             NULL, NULL, NULL);
   5.721  
   5.722 -                    // First try looking up by the TPK using the
   5.723 +                    // First try looking up by the certificate using the
   5.724                      // IssuerFingerprint subpacket.
   5.725                      pgp_fingerprint_t fpr
   5.726                          = pgp_signature_issuer_fingerprint(sig);
   5.727 @@ -1240,48 +1241,48 @@
   5.728                          goto eol;
   5.729                      }
   5.730  
   5.731 -                    pgp_tpk_t tpk;
   5.732 -                    if (tpk_find_by_keyid(session, keyid, false,
   5.733 -                                          &tpk, NULL) != PEP_STATUS_OK)
   5.734 +                    pgp_cert_t cert;
   5.735 +                    if (cert_find_by_keyid(session, keyid, false,
   5.736 +                                          &cert, NULL) != PEP_STATUS_OK)
   5.737                          ; // Soft error.  Ignore.
   5.738  
   5.739                      keyid_str = pgp_keyid_to_string (keyid);
   5.740  
   5.741 -                    if (tpk) {
   5.742 -                        // Ok, we have a TPK.
   5.743 +                    if (cert) {
   5.744 +                        // Ok, we have a certificate.
   5.745  
   5.746                          // We need the primary key's fingerprint (not
   5.747                          // the issuer fingerprint).
   5.748                          pgp_fingerprint_t primary_fpr
   5.749 -                            = pgp_tpk_fingerprint(tpk);
   5.750 +                            = pgp_cert_fingerprint(cert);
   5.751                          char *primary_fpr_str
   5.752                              = pgp_fingerprint_to_hex(primary_fpr);
   5.753  
   5.754                          bool good = true;
   5.755  
   5.756 -                        // Make sure the TPK is not revoked, it's
   5.757 +                        // Make sure the certificate is not revoked, its
   5.758                          // creation time is <= now, and it hasn't
   5.759                          // expired.
   5.760 -                        pgp_revocation_status_t rs = pgp_tpk_revoked(tpk, 0);
   5.761 +                        pgp_revocation_status_t rs = pgp_cert_revoked(cert, 0);
   5.762                          bool revoked = (pgp_revocation_status_variant(rs)
   5.763                                          == PGP_REVOCATION_STATUS_REVOKED);
   5.764                          pgp_revocation_status_free(rs);
   5.765                          if (revoked) {
   5.766 -                            T("TPK %s is revoked.", primary_fpr_str);
   5.767 +                            T("certificate %s is revoked.", primary_fpr_str);
   5.768                              good = false;
   5.769                              cookie->good_but_revoked ++;
   5.770 -                        } else if (! pgp_tpk_alive(tpk, 0)) {
   5.771 -                            T("TPK %s is not alive.", primary_fpr_str);
   5.772 +                        } else if (! pgp_cert_alive(cert, 0)) {
   5.773 +                            T("certificate %s is not alive.", primary_fpr_str);
   5.774                              good = false;
   5.775                              cookie->good_but_expired ++;
   5.776                          }
   5.777  
   5.778                          // Same thing for the signing key.
   5.779                          if (good) {
   5.780 -                            pgp_tpk_key_iter_t iter = pgp_tpk_key_iter_all(tpk);
   5.781 +                            pgp_cert_key_iter_t iter = pgp_cert_key_iter_all(cert);
   5.782                              pgp_key_t key;
   5.783                              pgp_signature_t sig;
   5.784 -                            while ((key = pgp_tpk_key_iter_next(iter, &sig, &rs))
   5.785 +                            while ((key = pgp_cert_key_iter_next(iter, &sig, &rs))
   5.786                                     && good) {
   5.787                                  pgp_keyid_t x = pgp_key_keyid(key);
   5.788                                  if (pgp_keyid_equal(keyid, x)) {
   5.789 @@ -1291,12 +1292,12 @@
   5.790                                      revoked = (pgp_revocation_status_variant(rs)
   5.791                                                 == PGP_REVOCATION_STATUS_REVOKED);
   5.792                                      if (revoked) {
   5.793 -                                        T("TPK %s's signing key %s is revoked.",
   5.794 +                                        T("certificate %s's signing key %s is revoked.",
   5.795                                            primary_fpr_str, keyid_str);
   5.796                                          good = false;
   5.797                                          cookie->good_but_revoked ++;
   5.798                                      } else if (! pgp_signature_key_alive(sig, key, 0)) {
   5.799 -                                        T("TPK %s's signing key %s is expired.",
   5.800 +                                        T("certificate %s's signing key %s is expired.",
   5.801                                            primary_fpr_str, keyid_str);
   5.802                                          good = false;
   5.803                                          cookie->good_but_expired ++;
   5.804 @@ -1307,7 +1308,7 @@
   5.805                                  pgp_signature_free(sig);
   5.806                                  pgp_key_free(key);
   5.807                              }
   5.808 -                            pgp_tpk_key_iter_free(iter);
   5.809 +                            pgp_cert_key_iter_free(iter);
   5.810                          }
   5.811  
   5.812                          if (good) {
   5.813 @@ -1321,11 +1322,11 @@
   5.814  
   5.815                          free(primary_fpr_str);
   5.816                          pgp_fingerprint_free(primary_fpr);
   5.817 -                        pgp_tpk_free(tpk);
   5.818 +                        pgp_cert_free(cert);
   5.819                      } else {
   5.820                          // If we get
   5.821                          // PGP_VERIFICATION_RESULT_CODE_GOOD_CHECKSUM,
   5.822 -                        // then the TPK should be available.  But,
   5.823 +                        // then the CERT should be available.  But,
   5.824                          // another process could have deleted the key
   5.825                          // from the store in the mean time, so be
   5.826                          // tolerant.
   5.827 @@ -1335,6 +1336,16 @@
   5.828                      }
   5.829                      break;
   5.830  
   5.831 +                case PGP_VERIFICATION_RESULT_NOT_ALIVE:
   5.832 +                    pgp_verification_result_not_alive
   5.833 +                        (result, &sig, NULL, NULL, NULL, NULL);
   5.834 +                    keyid = pgp_signature_issuer (sig);
   5.835 +                    keyid_str = pgp_keyid_to_string (keyid);
   5.836 +                    T("Signature from from %s is not alive", keyid_str);
   5.837 +
   5.838 +                    cookie->not_alive ++;
   5.839 +                    break;
   5.840 +
   5.841                  case PGP_VERIFICATION_RESULT_MISSING_KEY:
   5.842                      pgp_verification_result_missing_key (result, &sig);
   5.843                      keyid = pgp_signature_issuer (sig);
   5.844 @@ -1345,7 +1356,8 @@
   5.845                      break;
   5.846  
   5.847                  case PGP_VERIFICATION_RESULT_BAD_CHECKSUM:
   5.848 -                    pgp_verification_result_bad_checksum (result, &sig);
   5.849 +                    pgp_verification_result_bad_checksum
   5.850 +                        (result, &sig, NULL, NULL, NULL, NULL);
   5.851                      keyid = pgp_signature_issuer (sig);
   5.852                      if (keyid) {
   5.853                          keyid_str = pgp_keyid_to_string (keyid);
   5.854 @@ -1412,7 +1424,7 @@
   5.855      char** filename_ptr)
   5.856  {
   5.857      PEP_STATUS status = PEP_STATUS_OK;
   5.858 -    struct decrypt_cookie cookie = { session, 0, NULL, NULL, 0, 0, 0, 0, 0, 0, NULL };
   5.859 +    struct decrypt_cookie cookie = { session, 0, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, NULL };
   5.860      pgp_reader_t reader = NULL;
   5.861      pgp_writer_t writer = NULL;
   5.862      pgp_reader_t decryptor = NULL;
   5.863 @@ -1487,7 +1499,7 @@
   5.864              status = PEP_DECRYPTED_AND_VERIFIED;
   5.865          } else if (cookie.good_but_revoked) {
   5.866              // If there are any signatures from revoked keys, fail.
   5.867 -            status = PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH;
   5.868 +            status = PEP_VERIFY_SIGNER_KEY_REVOKED;
   5.869          } else if (cookie.bad_checksums) {
   5.870              // If there are any bad signatures, fail.
   5.871              status = PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH;
   5.872 @@ -1611,7 +1623,7 @@
   5.873              status = PEP_UNENCRYPTED;
   5.874          } else if (cookie.good_but_revoked) {
   5.875              // If there are any signatures from revoked keys, fail.
   5.876 -            status = PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH;
   5.877 +            status = PEP_VERIFY_SIGNER_KEY_REVOKED;
   5.878          } else if (cookie.bad_checksums) {
   5.879              // If there are any bad signatures, fail.
   5.880              status = PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH;
   5.881 @@ -1653,22 +1665,22 @@
   5.882  
   5.883      PEP_STATUS status = PEP_STATUS_OK;
   5.884      pgp_error_t err = NULL;
   5.885 -    pgp_tpk_t signer_tpk = NULL;
   5.886 -    pgp_tpk_key_iter_t iter = NULL;
   5.887 +    pgp_cert_t signer_cert = NULL;
   5.888 +    pgp_cert_key_iter_t iter = NULL;
   5.889      pgp_key_pair_t signing_keypair = NULL;
   5.890      pgp_signer_t signer = NULL;
   5.891      pgp_writer_stack_t ws = NULL;
   5.892  
   5.893 -    status = tpk_find_by_fpr_hex(session, fpr, true, &signer_tpk, NULL);
   5.894 +    status = cert_find_by_fpr_hex(session, fpr, true, &signer_cert, NULL);
   5.895      ERROR_OUT(NULL, status, "Looking up key '%s'", fpr);
   5.896  
   5.897 -    iter = pgp_tpk_key_iter_valid(signer_tpk);
   5.898 -    pgp_tpk_key_iter_signing_capable (iter);
   5.899 -    pgp_tpk_key_iter_unencrypted_secret (iter, true);
   5.900 +    iter = pgp_cert_key_iter_valid(signer_cert);
   5.901 +    pgp_cert_key_iter_for_signing (iter);
   5.902 +    pgp_cert_key_iter_unencrypted_secret (iter);
   5.903  
   5.904      // If there are multiple signing capable subkeys, we just take
   5.905      // the first one, whichever one that happens to be.
   5.906 -    pgp_key_t key = pgp_tpk_key_iter_next (iter, NULL, NULL);
   5.907 +    pgp_key_t key = pgp_cert_key_iter_next (iter, NULL, NULL);
   5.908      if (! key)
   5.909          ERROR_OUT (err, PEP_UNKNOWN_ERROR,
   5.910                     "%s has no signing capable key", fpr);
   5.911 @@ -1721,8 +1733,8 @@
   5.912      // will become a leak.
   5.913      //
   5.914      //pgp_key_pair_free (signing_keypair);
   5.915 -    pgp_tpk_key_iter_free (iter);
   5.916 -    pgp_tpk_free(signer_tpk);
   5.917 +    pgp_cert_key_iter_free (iter);
   5.918 +    pgp_cert_free(signer_cert);
   5.919  
   5.920      T("(%s)-> %s", fpr, pEp_status_to_string(status));
   5.921      return status;
   5.922 @@ -1735,8 +1747,8 @@
   5.923      PEP_STATUS status = PEP_STATUS_OK;
   5.924      pgp_error_t err = NULL;
   5.925  
   5.926 -    int recipient_tpk_count = 0;
   5.927 -    pgp_tpk_t *recipient_tpks = NULL;
   5.928 +    int recipient_cert_count = 0;
   5.929 +    pgp_cert_t *recipient_certs = NULL;
   5.930  
   5.931      int recipient_count = 0;
   5.932      int recipient_alloc = 0;
   5.933 @@ -1744,9 +1756,9 @@
   5.934      int recipient_keys_count = 0;
   5.935      pgp_key_t *recipient_keys = NULL;
   5.936  
   5.937 -    pgp_tpk_t signer_tpk = NULL;
   5.938 +    pgp_cert_t signer_cert = NULL;
   5.939      pgp_writer_stack_t ws = NULL;
   5.940 -    pgp_tpk_key_iter_t iter = NULL;
   5.941 +    pgp_cert_key_iter_t iter = NULL;
   5.942      pgp_key_pair_t signing_keypair = NULL;
   5.943      pgp_signer_t signer = NULL;
   5.944  
   5.945 @@ -1762,14 +1774,14 @@
   5.946  
   5.947      int keylist_len = stringlist_length(keylist);
   5.948  
   5.949 -    // We don't need to worry about extending recipient_tpks, because
   5.950 -    // there will be at most KEYLIST_LEN tpks, which we allocate up
   5.951 +    // We don't need to worry about extending recipient_certs, because
   5.952 +    // there will be at most KEYLIST_LEN certs, which we allocate up
   5.953      // front.
   5.954 -    recipient_tpks = calloc(keylist_len, sizeof(*recipient_tpks));
   5.955 -    if (recipient_tpks == NULL)
   5.956 +    recipient_certs = calloc(keylist_len, sizeof(*recipient_certs));
   5.957 +    if (recipient_certs == NULL)
   5.958          ERROR_OUT(NULL, PEP_OUT_OF_MEMORY, "out of memory");
   5.959  
   5.960 -    // Because there may be multiple encryption keys per TPK, we may
   5.961 +    // Because there may be multiple encryption keys per certificate, we may
   5.962      // need to extend recipient_keys and recipients.
   5.963      recipient_alloc = keylist_len;
   5.964      recipient_keys = calloc(recipient_alloc, sizeof(*recipient_keys));
   5.965 @@ -1786,24 +1798,24 @@
   5.966      for (_keylist = keylist; _keylist != NULL; _keylist = _keylist->next) {
   5.967          assert(_keylist->value);
   5.968  
   5.969 -        pgp_tpk_t tpk;
   5.970 -        status = tpk_find_by_fpr_hex(session, _keylist->value,
   5.971 -                                     false, &tpk, NULL);
   5.972 +        pgp_cert_t cert;
   5.973 +        status = cert_find_by_fpr_hex(session, _keylist->value,
   5.974 +                                     false, &cert, NULL);
   5.975          // We couldn't find a key for this recipient.
   5.976          ERROR_OUT(NULL, status,
   5.977                    "Looking up key for recipient '%s'", _keylist->value);
   5.978  
   5.979 -        recipient_tpks[recipient_tpk_count ++] = tpk;
   5.980 +        recipient_certs[recipient_cert_count ++] = cert;
   5.981  
   5.982          // Collect all of the keys that have the encryption for
   5.983          // transport capability.
   5.984 -        pgp_tpk_key_iter_t iter = pgp_tpk_key_iter_valid(tpk);
   5.985 +        pgp_cert_key_iter_t iter = pgp_cert_key_iter_valid(cert);
   5.986          if (! iter)
   5.987              ERROR_OUT(NULL, PEP_OUT_OF_MEMORY, "out of memory");
   5.988 -        pgp_tpk_key_iter_encrypting_capable_for_transport(iter);
   5.989 +        pgp_cert_key_iter_for_transport_encryption(iter);
   5.990  
   5.991          pgp_key_t key;
   5.992 -        while ((key = pgp_tpk_key_iter_next (iter, NULL, NULL))) {
   5.993 +        while ((key = pgp_cert_key_iter_next (iter, NULL, NULL))) {
   5.994              assert(recipient_count == recipient_keys_count);
   5.995              if (recipient_count == recipient_alloc) {
   5.996                  assert(recipient_alloc > 0);
   5.997 @@ -1835,12 +1847,12 @@
   5.998  
   5.999              recipients[recipient_count++] = pgp_recipient_new(keyid, key);
  5.1000          }
  5.1001 -        pgp_tpk_key_iter_free(iter);
  5.1002 +        pgp_cert_key_iter_free(iter);
  5.1003      }
  5.1004  
  5.1005      if (sign) {
  5.1006          // The first key in the keylist is the signer.
  5.1007 -        status = tpk_find_by_fpr_hex(session, keylist->value, true, &signer_tpk, NULL);
  5.1008 +        status = cert_find_by_fpr_hex(session, keylist->value, true, &signer_cert, NULL);
  5.1009          ERROR_OUT(NULL, status, "Looking up key for signing '%s'", keylist->value);
  5.1010      }
  5.1011  
  5.1012 @@ -1861,13 +1873,13 @@
  5.1013      recipient_count = 0;
  5.1014  
  5.1015      if (sign) {
  5.1016 -        iter = pgp_tpk_key_iter_valid(signer_tpk);
  5.1017 -        pgp_tpk_key_iter_signing_capable (iter);
  5.1018 -        pgp_tpk_key_iter_unencrypted_secret (iter, true);
  5.1019 +        iter = pgp_cert_key_iter_valid(signer_cert);
  5.1020 +        pgp_cert_key_iter_for_signing (iter);
  5.1021 +        pgp_cert_key_iter_unencrypted_secret (iter);
  5.1022  
  5.1023          // If there are multiple signing capable subkeys, we just take
  5.1024          // the first one, whichever one that happens to be.
  5.1025 -        pgp_key_t key = pgp_tpk_key_iter_next (iter, NULL, NULL);
  5.1026 +        pgp_key_t key = pgp_cert_key_iter_next (iter, NULL, NULL);
  5.1027          if (! key)
  5.1028              ERROR_OUT (err, PEP_UNKNOWN_ERROR,
  5.1029                         "%s has no signing capable key", keylist->value);
  5.1030 @@ -1921,8 +1933,8 @@
  5.1031      // will become a leak.
  5.1032      //
  5.1033      // pgp_key_pair_free (signing_keypair);
  5.1034 -    pgp_tpk_key_iter_free (iter);
  5.1035 -    pgp_tpk_free(signer_tpk);
  5.1036 +    pgp_cert_key_iter_free (iter);
  5.1037 +    pgp_cert_free(signer_cert);
  5.1038  
  5.1039      for (int i = 0; i < recipient_count; i ++)
  5.1040          pgp_recipient_free(recipients[i]);
  5.1041 @@ -1930,9 +1942,9 @@
  5.1042      for (int i = 0; i < recipient_keys_count; i ++)
  5.1043          pgp_key_free(recipient_keys[i]);
  5.1044      free(recipient_keys);
  5.1045 -    for (int i = 0; i < recipient_tpk_count; i ++)
  5.1046 -        pgp_tpk_free(recipient_tpks[i]);
  5.1047 -    free(recipient_tpks);
  5.1048 +    for (int i = 0; i < recipient_cert_count; i ++)
  5.1049 +        pgp_cert_free(recipient_certs[i]);
  5.1050 +    free(recipient_certs);
  5.1051  
  5.1052      T("-> %s", pEp_status_to_string(status));
  5.1053      return status;
  5.1054 @@ -1961,7 +1973,7 @@
  5.1055      pgp_error_t err = NULL;
  5.1056      pgp_packet_t userid_packet = NULL;
  5.1057      char *userid = NULL;
  5.1058 -    pgp_tpk_t tpk = NULL;
  5.1059 +    pgp_cert_t cert = NULL;
  5.1060      pgp_fingerprint_t pgp_fpr = NULL;
  5.1061      char *fpr = NULL;
  5.1062  
  5.1063 @@ -1991,21 +2003,21 @@
  5.1064      T("(%s)", userid);
  5.1065  
  5.1066      // Generate a key.
  5.1067 -    pgp_tpk_builder_t tpkb = pgp_tpk_builder_general_purpose(
  5.1068 +    pgp_cert_builder_t certb = pgp_cert_builder_general_purpose(
  5.1069          cipher_suite(session->cipher_suite), userid);
  5.1070      pgp_signature_t rev;
  5.1071 -    if (pgp_tpk_builder_generate(&err, tpkb, &tpk, &rev))
  5.1072 +    if (pgp_cert_builder_generate(&err, certb, &cert, &rev))
  5.1073          ERROR_OUT(err, PEP_CANNOT_CREATE_KEY, "Generating a key pair");
  5.1074  
  5.1075      // XXX: We should return this.
  5.1076      pgp_signature_free(rev);
  5.1077  
  5.1078      // Get the fingerprint.
  5.1079 -    pgp_fpr = pgp_tpk_fingerprint(tpk);
  5.1080 +    pgp_fpr = pgp_cert_fingerprint(cert);
  5.1081      fpr = pgp_fingerprint_to_hex(pgp_fpr);
  5.1082  
  5.1083 -    status = tpk_save(session, tpk, NULL);
  5.1084 -    tpk = NULL;
  5.1085 +    status = cert_save(session, cert, NULL);
  5.1086 +    cert = NULL;
  5.1087      if (status != 0)
  5.1088          ERROR_OUT(NULL, PEP_CANNOT_CREATE_KEY, "saving TSK");
  5.1089  
  5.1090 @@ -2016,7 +2028,7 @@
  5.1091   out:
  5.1092      pgp_fingerprint_free(pgp_fpr);
  5.1093      free(fpr);
  5.1094 -    pgp_tpk_free(tpk);
  5.1095 +    pgp_cert_free(cert);
  5.1096      free(userid);
  5.1097      pgp_packet_free(userid_packet);
  5.1098  
  5.1099 @@ -2082,7 +2094,7 @@
  5.1100  {
  5.1101      PEP_STATUS status = PEP_NO_KEY_IMPORTED;
  5.1102      pgp_error_t err;
  5.1103 -    pgp_tpk_parser_t parser = NULL;
  5.1104 +    pgp_cert_parser_t parser = NULL;
  5.1105  
  5.1106      if (private_idents)
  5.1107          *private_idents = NULL;
  5.1108 @@ -2110,15 +2122,15 @@
  5.1109          pgp_signature_t sig = pgp_packet_ref_signature (packet);
  5.1110          assert(sig);
  5.1111  
  5.1112 -        pgp_tpk_t tpk = NULL;
  5.1113 +        pgp_cert_t cert = NULL;
  5.1114  
  5.1115          pgp_fingerprint_t issuer_fpr = pgp_signature_issuer_fingerprint(sig);
  5.1116          if (issuer_fpr) {
  5.1117              char *issuer_fpr_hex = pgp_fingerprint_to_hex(issuer_fpr);
  5.1118              T("Importing a signature issued by %s", issuer_fpr_hex);
  5.1119  
  5.1120 -            status = tpk_find_by_fpr_hex(session, issuer_fpr_hex,
  5.1121 -                                         false, &tpk, NULL);
  5.1122 +            status = cert_find_by_fpr_hex(session, issuer_fpr_hex,
  5.1123 +                                         false, &cert, NULL);
  5.1124              if (status && status != PEP_KEY_NOT_FOUND)
  5.1125                  DUMP_ERR(NULL, status, "Looking up %s", issuer_fpr_hex);
  5.1126  
  5.1127 @@ -2126,14 +2138,14 @@
  5.1128              pgp_fingerprint_free(issuer_fpr);
  5.1129          }
  5.1130  
  5.1131 -        if (! tpk) {
  5.1132 +        if (! cert) {
  5.1133              pgp_keyid_t issuer = pgp_signature_issuer(sig);
  5.1134              if (issuer) {
  5.1135                  char *issuer_hex = pgp_keyid_to_hex(issuer);
  5.1136                  T("Importing a signature issued by %s", issuer_hex);
  5.1137  
  5.1138 -                status = tpk_find_by_keyid_hex(session, issuer_hex,
  5.1139 -                                               false, &tpk, NULL);
  5.1140 +                status = cert_find_by_keyid_hex(session, issuer_hex,
  5.1141 +                                               false, &cert, NULL);
  5.1142                  if (status && status != PEP_KEY_NOT_FOUND)
  5.1143                      DUMP_ERR(NULL, status, "Looking up %s", issuer_hex);
  5.1144  
  5.1145 @@ -2146,40 +2158,40 @@
  5.1146          // to free it.
  5.1147          pgp_signature_free(sig);
  5.1148  
  5.1149 -        if (tpk) {
  5.1150 +        if (cert) {
  5.1151              T("Merging packet: %s", pgp_packet_debug(packet));
  5.1152  
  5.1153 -            tpk = pgp_tpk_merge_packets (&err, tpk, &packet, 1);
  5.1154 -            if (! tpk)
  5.1155 +            cert = pgp_cert_merge_packets (&err, cert, &packet, 1);
  5.1156 +            if (! cert)
  5.1157                  ERROR_OUT(err, PEP_UNKNOWN_ERROR, "Merging signature");
  5.1158  
  5.1159 -            status = tpk_save(session, tpk, NULL);
  5.1160 +            status = cert_save(session, cert, NULL);
  5.1161              if (status)
  5.1162 -                ERROR_OUT(NULL, status, "saving merged TPK");
  5.1163 +                ERROR_OUT(NULL, status, "saving merged CERT");
  5.1164              status = PEP_KEY_IMPORTED;
  5.1165          }
  5.1166          break;
  5.1167      }
  5.1168      case PGP_TAG_PUBLIC_KEY:
  5.1169      case PGP_TAG_SECRET_KEY: {
  5.1170 -        parser = pgp_tpk_parser_from_packet_parser(ppr);
  5.1171 -        pgp_tpk_t tpk;
  5.1172 +        parser = pgp_cert_parser_from_packet_parser(ppr);
  5.1173 +        pgp_cert_t cert;
  5.1174          int count = 0;
  5.1175          err = NULL;
  5.1176 -        while ((tpk = pgp_tpk_parser_next(&err, parser))) {
  5.1177 +        while ((cert = pgp_cert_parser_next(&err, parser))) {
  5.1178              count ++;
  5.1179  
  5.1180 -            T("#%d. TPK for %s, %s",
  5.1181 -              count, pgp_tpk_primary_user_id(tpk),
  5.1182 -              pgp_fingerprint_to_hex(pgp_tpk_fingerprint(tpk)));
  5.1183 +            T("#%d. CERT for %s, %s",
  5.1184 +              count, pgp_cert_primary_user_id(cert),
  5.1185 +              pgp_fingerprint_to_hex(pgp_cert_fingerprint(cert)));
  5.1186  
  5.1187              // If private_idents is not NULL and there is any private key
  5.1188              // material, it will be saved.
  5.1189 -            status = tpk_save(session, tpk, private_idents);
  5.1190 +            status = cert_save(session, cert, private_idents);
  5.1191              if (status == PEP_STATUS_OK)
  5.1192                  status = PEP_KEY_IMPORTED;
  5.1193              else
  5.1194 -                ERROR_OUT(NULL, status, "saving TPK");
  5.1195 +                ERROR_OUT(NULL, status, "saving certificate");
  5.1196          }
  5.1197          if (err || count == 0)
  5.1198              ERROR_OUT(err, PEP_UNKNOWN_ERROR, "parsing key data");
  5.1199 @@ -2203,7 +2215,7 @@
  5.1200          status = PEP_UNKNOWN_DB_ERROR;
  5.1201  
  5.1202   out:
  5.1203 -    pgp_tpk_parser_free(parser);
  5.1204 +    pgp_cert_parser_free(parser);
  5.1205  
  5.1206      T("-> %s", pEp_status_to_string(status));
  5.1207      return status;
  5.1208 @@ -2287,7 +2299,7 @@
  5.1209  {
  5.1210      PEP_STATUS status = PEP_STATUS_OK;
  5.1211      pgp_error_t err = NULL;
  5.1212 -    pgp_tpk_t tpk = NULL;
  5.1213 +    pgp_cert_t cert = NULL;
  5.1214      pgp_writer_t armor_writer = NULL;
  5.1215      pgp_writer_t memory_writer = NULL;
  5.1216  
  5.1217 @@ -2303,7 +2315,7 @@
  5.1218  
  5.1219      // If the caller asks for a secret key and we only have a
  5.1220      // public key, then we return an error.
  5.1221 -    status = tpk_find_by_fpr_hex(session, fpr, secret, &tpk, NULL);
  5.1222 +    status = cert_find_by_fpr_hex(session, fpr, secret, &cert, NULL);
  5.1223      ERROR_OUT(NULL, status, "Looking up TSK for %s", fpr);
  5.1224  
  5.1225      memory_writer = pgp_writer_alloc((void **) key_data, size);
  5.1226 @@ -2316,13 +2328,13 @@
  5.1227      }
  5.1228  
  5.1229      if (secret) {
  5.1230 -        pgp_tsk_t tsk = pgp_tpk_as_tsk(tpk);
  5.1231 +        pgp_tsk_t tsk = pgp_cert_as_tsk(cert);
  5.1232          if (pgp_tsk_serialize(&err, tsk, armor_writer))
  5.1233              ERROR_OUT(err, PEP_UNKNOWN_ERROR, "serializing TSK");
  5.1234          pgp_tsk_free(tsk);
  5.1235      } else {
  5.1236 -        if (pgp_tpk_serialize(&err, tpk, armor_writer))
  5.1237 -            ERROR_OUT(err, PEP_UNKNOWN_ERROR, "serializing TPK");
  5.1238 +        if (pgp_cert_serialize(&err, cert, armor_writer))
  5.1239 +            ERROR_OUT(err, PEP_UNKNOWN_ERROR, "serializing certificate");
  5.1240      }
  5.1241  
  5.1242   out:
  5.1243 @@ -2338,8 +2350,8 @@
  5.1244          pgp_writer_free(memory_writer);
  5.1245      }
  5.1246  
  5.1247 -    if (tpk)
  5.1248 -        pgp_tpk_free(tpk);
  5.1249 +    if (cert)
  5.1250 +        pgp_cert_free(cert);
  5.1251  
  5.1252      (*size)--;  // Sequoia is delivering the 0 byte at the end with size, but
  5.1253                  // pEp is expecting it without
  5.1254 @@ -2380,11 +2392,11 @@
  5.1255  static stringpair_list_t *add_key(PEP_SESSION session,
  5.1256                                    stringpair_list_t *keyinfo_list,
  5.1257                                    stringlist_t* keylist,
  5.1258 -                                  pgp_tpk_t tpk, pgp_fingerprint_t fpr) {
  5.1259 +                                  pgp_cert_t cert, pgp_fingerprint_t fpr) {
  5.1260      bool revoked = false;
  5.1261      // Don't add revoked keys to the keyinfo_list.
  5.1262      if (keyinfo_list) {
  5.1263 -        pgp_revocation_status_t rs = pgp_tpk_revoked(tpk, 0);
  5.1264 +        pgp_revocation_status_t rs = pgp_cert_revoked(cert, 0);
  5.1265          pgp_revocation_status_variant_t rsv = pgp_revocation_status_variant(rs);
  5.1266          pgp_revocation_status_free(rs);
  5.1267          if (rsv == PGP_REVOCATION_STATUS_REVOKED)
  5.1268 @@ -2397,12 +2409,12 @@
  5.1269      int dealloc_fpr = 0;
  5.1270      if (!fpr) {
  5.1271          dealloc_fpr = 1;
  5.1272 -        fpr = pgp_tpk_fingerprint(tpk);
  5.1273 +        fpr = pgp_cert_fingerprint(cert);
  5.1274      }
  5.1275      char *fpr_str = pgp_fingerprint_to_hex(fpr);
  5.1276  
  5.1277      if (!revoked && keyinfo_list) {
  5.1278 -        char *user_id = pgp_tpk_primary_user_id(tpk);
  5.1279 +        char *user_id = pgp_cert_primary_user_id(cert);
  5.1280          if (user_id)
  5.1281              keyinfo_list = stringpair_list_add(keyinfo_list,
  5.1282                                                 new_stringpair(fpr_str, user_id));
  5.1283 @@ -2424,7 +2436,7 @@
  5.1284                              stringpair_list_t** keyinfo_list, stringlist_t** keylist)
  5.1285  {
  5.1286      PEP_STATUS status = PEP_STATUS_OK;
  5.1287 -    pgp_tpk_t tpk = NULL;
  5.1288 +    pgp_cert_t cert = NULL;
  5.1289      pgp_fingerprint_t fpr = NULL;
  5.1290  
  5.1291      T("('%s', private: %d)", pattern, private_only);
  5.1292 @@ -2449,15 +2461,15 @@
  5.1293  
  5.1294      if (strchr(pattern, '@')) {
  5.1295          // Looks like a mailbox.
  5.1296 -        pgp_tpk_t *tpks = NULL;
  5.1297 +        pgp_cert_t *certs = NULL;
  5.1298          int count = 0;
  5.1299 -        status = tpk_find_by_email(session, pattern, private_only, &tpks, &count);
  5.1300 +        status = cert_find_by_email(session, pattern, private_only, &certs, &count);
  5.1301          ERROR_OUT(NULL, status, "Looking up '%s'", pattern);
  5.1302          for (int i = 0; i < count; i ++) {
  5.1303 -            add_key(session, _keyinfo_list, _keylist, tpks[i], NULL);
  5.1304 -            pgp_tpk_free(tpks[i]);
  5.1305 +            add_key(session, _keyinfo_list, _keylist, certs[i], NULL);
  5.1306 +            pgp_cert_free(certs[i]);
  5.1307          }
  5.1308 -        free(tpks);
  5.1309 +        free(certs);
  5.1310  
  5.1311          if (count == 0) {
  5.1312              // If match failed, check to see if we've got a dotted
  5.1313 @@ -2481,27 +2493,27 @@
  5.1314          // Fingerprint.  Note: the pep engine never looks keys up by
  5.1315          // keyid, so we don't handle them.
  5.1316          fpr = pgp_fingerprint_from_hex(pattern);
  5.1317 -        status = tpk_find_by_fpr(session, fpr, false, &tpk, NULL);
  5.1318 +        status = cert_find_by_fpr(session, fpr, false, &cert, NULL);
  5.1319          ERROR_OUT(NULL, status, "Looking up key");
  5.1320 -        add_key(session, _keyinfo_list, _keylist, tpk, fpr);
  5.1321 +        add_key(session, _keyinfo_list, _keylist, cert, fpr);
  5.1322      } else if (pattern[0] == 0) {
  5.1323          // Empty string.
  5.1324  
  5.1325 -        pgp_tpk_t *tpks = NULL;
  5.1326 +        pgp_cert_t *certs = NULL;
  5.1327          int count = 0;
  5.1328 -        status = tpk_all(session, private_only, &tpks, &count);
  5.1329 +        status = cert_all(session, private_only, &certs, &count);
  5.1330          ERROR_OUT(NULL, status, "Looking up '%s'", pattern);
  5.1331          for (int i = 0; i < count; i ++) {
  5.1332 -            add_key(session, _keyinfo_list, _keylist, tpks[i], NULL);
  5.1333 -            pgp_tpk_free(tpks[i]);
  5.1334 +            add_key(session, _keyinfo_list, _keylist, certs[i], NULL);
  5.1335 +            pgp_cert_free(certs[i]);
  5.1336          }
  5.1337 -        free(tpks);
  5.1338 +        free(certs);
  5.1339      } else {
  5.1340          T("unsupported pattern '%s'", pattern);
  5.1341      }
  5.1342  
  5.1343   out:
  5.1344 -    pgp_tpk_free(tpk);
  5.1345 +    pgp_cert_free(cert);
  5.1346      pgp_fingerprint_free(fpr);
  5.1347  
  5.1348      if (status == PEP_KEY_NOT_FOUND)
  5.1349 @@ -2575,18 +2587,18 @@
  5.1350  {
  5.1351      PEP_STATUS status = PEP_STATUS_OK;
  5.1352      pgp_error_t err = NULL;
  5.1353 -    pgp_tpk_t tpk = NULL;
  5.1354 -    pgp_tpk_key_iter_t iter = NULL;
  5.1355 +    pgp_cert_t cert = NULL;
  5.1356 +    pgp_cert_key_iter_t iter = NULL;
  5.1357      pgp_key_pair_t keypair = NULL;
  5.1358      pgp_signer_t signer = NULL;
  5.1359      time_t t = mktime((struct tm *) ts);
  5.1360  
  5.1361      T("(%s)", fpr);
  5.1362  
  5.1363 -    status = tpk_find_by_fpr_hex(session, fpr, true, &tpk, NULL);
  5.1364 +    status = cert_find_by_fpr_hex(session, fpr, true, &cert, NULL);
  5.1365      ERROR_OUT(NULL, status, "Looking up '%s'", fpr);
  5.1366  
  5.1367 -    uint32_t creation_time = pgp_key_creation_time(pgp_tpk_primary_key(tpk));
  5.1368 +    uint32_t creation_time = pgp_key_creation_time(pgp_cert_primary_key(cert));
  5.1369      if (creation_time > t)
  5.1370          // The creation time is after the expiration time!
  5.1371          ERROR_OUT(NULL, PEP_UNKNOWN_ERROR,
  5.1372 @@ -2595,13 +2607,13 @@
  5.1373      uint32_t delta = t - creation_time;
  5.1374  
  5.1375  
  5.1376 -    iter = pgp_tpk_key_iter_valid(tpk);
  5.1377 -    pgp_tpk_key_iter_certification_capable (iter);
  5.1378 -    pgp_tpk_key_iter_unencrypted_secret (iter, true);
  5.1379 +    iter = pgp_cert_key_iter_valid(cert);
  5.1380 +    pgp_cert_key_iter_for_certification (iter);
  5.1381 +    pgp_cert_key_iter_unencrypted_secret (iter);
  5.1382  
  5.1383      // If there are multiple certification capable subkeys, we just
  5.1384      // take the first one, whichever one that happens to be.
  5.1385 -    pgp_key_t key = pgp_tpk_key_iter_next (iter, NULL, NULL);
  5.1386 +    pgp_key_t key = pgp_cert_key_iter_next (iter, NULL, NULL);
  5.1387      if (! key)
  5.1388          ERROR_OUT (err, PEP_UNKNOWN_ERROR,
  5.1389                     "%s has no usable certification capable key", fpr);
  5.1390 @@ -2614,12 +2626,12 @@
  5.1391      if (! signer)
  5.1392          ERROR_OUT (err, PEP_UNKNOWN_ERROR, "Creating a signer");
  5.1393  
  5.1394 -    tpk = pgp_tpk_set_expiry(&err, tpk, signer, delta);
  5.1395 -    if (! tpk)
  5.1396 +    cert = pgp_cert_set_expiry(&err, cert, signer, delta);
  5.1397 +    if (! cert)
  5.1398          ERROR_OUT(err, PEP_UNKNOWN_ERROR, "setting expiration");
  5.1399  
  5.1400 -    status = tpk_save(session, tpk, NULL);
  5.1401 -    tpk = NULL;
  5.1402 +    status = cert_save(session, cert, NULL);
  5.1403 +    cert = NULL;
  5.1404      ERROR_OUT(NULL, status, "Saving %s", fpr);
  5.1405  
  5.1406   out:
  5.1407 @@ -2629,8 +2641,8 @@
  5.1408      // will become a leak.
  5.1409      //
  5.1410      pgp_key_pair_free (keypair);
  5.1411 -    pgp_tpk_key_iter_free (iter);
  5.1412 -    pgp_tpk_free(tpk);
  5.1413 +    pgp_cert_key_iter_free (iter);
  5.1414 +    pgp_cert_free(cert);
  5.1415  
  5.1416      T("(%s) -> %s", fpr, pEp_status_to_string(status));
  5.1417      return status;
  5.1418 @@ -2641,23 +2653,23 @@
  5.1419  {
  5.1420      PEP_STATUS status = PEP_STATUS_OK;
  5.1421      pgp_error_t err = NULL;
  5.1422 -    pgp_tpk_t tpk = NULL;
  5.1423 -    pgp_tpk_key_iter_t iter = NULL;
  5.1424 +    pgp_cert_t cert = NULL;
  5.1425 +    pgp_cert_key_iter_t iter = NULL;
  5.1426      pgp_key_pair_t keypair = NULL;
  5.1427      pgp_signer_t signer = NULL;
  5.1428  
  5.1429      T("(%s)", fpr);
  5.1430  
  5.1431 -    status = tpk_find_by_fpr_hex(session, fpr, true, &tpk, NULL);
  5.1432 +    status = cert_find_by_fpr_hex(session, fpr, true, &cert, NULL);
  5.1433      ERROR_OUT(NULL, status, "Looking up %s", fpr);
  5.1434  
  5.1435 -    iter = pgp_tpk_key_iter_valid(tpk);
  5.1436 -    pgp_tpk_key_iter_certification_capable (iter);
  5.1437 -    pgp_tpk_key_iter_unencrypted_secret (iter, true);
  5.1438 +    iter = pgp_cert_key_iter_valid(cert);
  5.1439 +    pgp_cert_key_iter_for_certification (iter);
  5.1440 +    pgp_cert_key_iter_unencrypted_secret (iter);
  5.1441  
  5.1442      // If there are multiple certification capable subkeys, we just
  5.1443      // take the first one, whichever one that happens to be.
  5.1444 -    pgp_key_t key = pgp_tpk_key_iter_next (iter, NULL, NULL);
  5.1445 +    pgp_key_t key = pgp_cert_key_iter_next (iter, NULL, NULL);
  5.1446      if (! key)
  5.1447          ERROR_OUT (err, PEP_UNKNOWN_ERROR,
  5.1448                     "%s has no usable certification capable key", fpr);
  5.1449 @@ -2670,33 +2682,33 @@
  5.1450      if (! signer)
  5.1451          ERROR_OUT (err, PEP_UNKNOWN_ERROR, "Creating a signer");
  5.1452  
  5.1453 -    tpk = pgp_tpk_revoke_in_place(&err, tpk, signer,
  5.1454 +    cert = pgp_cert_revoke_in_place(&err, cert, signer,
  5.1455                                    PGP_REASON_FOR_REVOCATION_UNSPECIFIED,
  5.1456                                    reason);
  5.1457 -    if (! tpk)
  5.1458 +    if (! cert)
  5.1459          ERROR_OUT(err, PEP_UNKNOWN_ERROR, "setting expiration");
  5.1460  
  5.1461 -    assert(pgp_revocation_status_variant(pgp_tpk_revoked(tpk, 0))
  5.1462 +    assert(pgp_revocation_status_variant(pgp_cert_revoked(cert, 0))
  5.1463             == PGP_REVOCATION_STATUS_REVOKED);
  5.1464  
  5.1465 -    status = tpk_save(session, tpk, NULL);
  5.1466 -    tpk = NULL;
  5.1467 +    status = cert_save(session, cert, NULL);
  5.1468 +    cert = NULL;
  5.1469      ERROR_OUT(NULL, status, "Saving %s", fpr);
  5.1470  
  5.1471   out:
  5.1472      pgp_signer_free (signer);
  5.1473      pgp_key_pair_free (keypair);
  5.1474 -    pgp_tpk_key_iter_free (iter);
  5.1475 -    pgp_tpk_free(tpk);
  5.1476 +    pgp_cert_key_iter_free (iter);
  5.1477 +    pgp_cert_free(cert);
  5.1478  
  5.1479      T("(%s) -> %s", fpr, pEp_status_to_string(status));
  5.1480      return status;
  5.1481  }
  5.1482  
  5.1483 -static void _pgp_key_expired(pgp_tpk_t tpk, const time_t when, bool* expired)
  5.1484 +static void _pgp_key_expired(pgp_cert_t cert, const time_t when, bool* expired)
  5.1485  {
  5.1486 -    // Is the TPK live?
  5.1487 -    *expired = !pgp_tpk_alive(tpk, when);
  5.1488 +    // Is the certificate live?
  5.1489 +    *expired = !pgp_cert_alive(cert, when);
  5.1490  
  5.1491  #ifdef TRACING
  5.1492      {
  5.1493 @@ -2711,7 +2723,7 @@
  5.1494              strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", &tm);
  5.1495          }
  5.1496  
  5.1497 -        T("TPK is %slive as of %s", *expired ? "not " : "", buffer);
  5.1498 +        T("certificate is %slive as of %s", *expired ? "not " : "", buffer);
  5.1499      }
  5.1500  #endif
  5.1501      if (*expired)
  5.1502 @@ -2722,27 +2734,27 @@
  5.1503      //    int can_certify = 0, can_encrypt = 0, can_sign = 0;
  5.1504      int can_encrypt = 0, can_sign = 0;
  5.1505  
  5.1506 -    pgp_tpk_key_iter_t key_iter = pgp_tpk_key_iter_valid(tpk);
  5.1507 +    pgp_cert_key_iter_t key_iter = pgp_cert_key_iter_valid(cert);
  5.1508      pgp_key_t key;
  5.1509      pgp_signature_t sig;
  5.1510      pgp_revocation_status_t rev;
  5.1511 -    while ((key = pgp_tpk_key_iter_next(key_iter, &sig, &rev))) {
  5.1512 +    while ((key = pgp_cert_key_iter_next(key_iter, &sig, &rev))) {
  5.1513          if (! sig)
  5.1514              continue;
  5.1515  
  5.1516 -        if (pgp_signature_can_encrypt_for_transport(sig)
  5.1517 -            || pgp_signature_can_encrypt_at_rest(sig))
  5.1518 +        if (pgp_signature_for_transport_encryption(sig)
  5.1519 +            || pgp_signature_for_storage_encryption(sig))
  5.1520              can_encrypt = 1;
  5.1521 -        if (pgp_signature_can_sign(sig))
  5.1522 +        if (pgp_signature_for_signing(sig))
  5.1523              can_sign = 1;
  5.1524 -        // if (pgp_signature_can_certify(sig))
  5.1525 +        // if (pgp_signature_for_certification(sig))
  5.1526          //     can_certify = 1;
  5.1527  
  5.1528  //        if (can_encrypt && can_sign && can_certify)
  5.1529          if (can_encrypt && can_sign)
  5.1530              break;
  5.1531      }
  5.1532 -    pgp_tpk_key_iter_free(key_iter);
  5.1533 +    pgp_cert_key_iter_free(key_iter);
  5.1534  
  5.1535  //    *expired = !(can_encrypt && can_sign && can_certify);
  5.1536      *expired = !(can_encrypt && can_sign);
  5.1537 @@ -2751,18 +2763,18 @@
  5.1538        can_encrypt ? "" : "not",
  5.1539        can_sign ? "" : "not",
  5.1540        *expired ? "" : "not");
  5.1541 -      
  5.1542 +
  5.1543  out:
  5.1544      // Er, this might be problematic in terms of internal vs. external in log. FIXME?
  5.1545      T(" -> expired: %d", *expired);
  5.1546      return;
  5.1547  }
  5.1548 -                            
  5.1549 +
  5.1550  PEP_STATUS pgp_key_expired(PEP_SESSION session, const char *fpr,
  5.1551                             const time_t when, bool *expired)
  5.1552  {
  5.1553      PEP_STATUS status = PEP_STATUS_OK;
  5.1554 -    pgp_tpk_t tpk = NULL;
  5.1555 +    pgp_cert_t cert = NULL;
  5.1556      T("(%s)", fpr);
  5.1557  
  5.1558      assert(session);
  5.1559 @@ -2772,13 +2784,13 @@
  5.1560      *expired = false;
  5.1561  
  5.1562      pgp_fingerprint_t pgp_fpr = pgp_fingerprint_from_hex(fpr);
  5.1563 -    status = tpk_find_by_fpr(session, pgp_fpr, false, &tpk, NULL);
  5.1564 +    status = cert_find_by_fpr(session, pgp_fpr, false, &cert, NULL);
  5.1565      pgp_fingerprint_free(pgp_fpr);
  5.1566      ERROR_OUT(NULL, status, "Looking up %s", fpr);
  5.1567  
  5.1568 -    _pgp_key_expired(tpk, when, expired);
  5.1569 +    _pgp_key_expired(cert, when, expired);
  5.1570   out:
  5.1571 -    pgp_tpk_free(tpk);
  5.1572 +    pgp_cert_free(cert);
  5.1573      T("(%s) -> %s (expired: %d)", fpr, pEp_status_to_string(status), *expired);
  5.1574      return status;
  5.1575  }
  5.1576 @@ -2786,7 +2798,7 @@
  5.1577  PEP_STATUS pgp_key_revoked(PEP_SESSION session, const char *fpr, bool *revoked)
  5.1578  {
  5.1579      PEP_STATUS status = PEP_STATUS_OK;
  5.1580 -    pgp_tpk_t tpk;
  5.1581 +    pgp_cert_t cert;
  5.1582  
  5.1583      T("(%s)", fpr);
  5.1584  
  5.1585 @@ -2797,14 +2809,14 @@
  5.1586      *revoked = false;
  5.1587  
  5.1588      pgp_fingerprint_t pgp_fpr = pgp_fingerprint_from_hex(fpr);
  5.1589 -    status = tpk_find_by_fpr(session, pgp_fpr, false, &tpk, NULL);
  5.1590 +    status = cert_find_by_fpr(session, pgp_fpr, false, &cert, NULL);
  5.1591      pgp_fingerprint_free(pgp_fpr);
  5.1592      ERROR_OUT(NULL, status, "Looking up %s", fpr);
  5.1593  
  5.1594 -    pgp_revocation_status_t rs = pgp_tpk_revoked(tpk, 0);
  5.1595 +    pgp_revocation_status_t rs = pgp_cert_revoked(cert, 0);
  5.1596      *revoked = pgp_revocation_status_variant(rs) == PGP_REVOCATION_STATUS_REVOKED;
  5.1597      pgp_revocation_status_free (rs);
  5.1598 -    pgp_tpk_free(tpk);
  5.1599 +    pgp_cert_free(cert);
  5.1600  
  5.1601   out:
  5.1602      T("(%s) -> %s", fpr, pEp_status_to_string(status));
  5.1603 @@ -2815,7 +2827,7 @@
  5.1604      PEP_SESSION session, const char *fpr, PEP_comm_type *comm_type)
  5.1605  {
  5.1606      PEP_STATUS status = PEP_STATUS_OK;
  5.1607 -    pgp_tpk_t tpk = NULL;
  5.1608 +    pgp_cert_t cert = NULL;
  5.1609  
  5.1610      assert(session);
  5.1611      assert(fpr);
  5.1612 @@ -2824,7 +2836,7 @@
  5.1613      *comm_type = PEP_ct_unknown;
  5.1614  
  5.1615      pgp_fingerprint_t pgp_fpr = pgp_fingerprint_from_hex(fpr);
  5.1616 -    status = tpk_find_by_fpr(session, pgp_fpr, false, &tpk, NULL);
  5.1617 +    status = cert_find_by_fpr(session, pgp_fpr, false, &cert, NULL);
  5.1618      pgp_fingerprint_free(pgp_fpr);
  5.1619      ERROR_OUT(NULL, status, "Looking up key: %s", fpr);
  5.1620  
  5.1621 @@ -2833,19 +2845,19 @@
  5.1622      bool expired = false;
  5.1623      
  5.1624      // MUST guarantee the same behaviour.
  5.1625 -    _pgp_key_expired(tpk, time(NULL), &expired);
  5.1626 +    _pgp_key_expired(cert, time(NULL), &expired);
  5.1627      
  5.1628      if (expired) {
  5.1629          *comm_type = PEP_ct_key_expired;
  5.1630          goto out;        
  5.1631      }
  5.1632      
  5.1633 -    // if (pgp_tpk_expired(tpk)) {
  5.1634 +    // if (pgp_cert_expired(cert)) {
  5.1635      //     *comm_type = PEP_ct_key_expired;
  5.1636      //     goto out;
  5.1637      // }
  5.1638  
  5.1639 -    pgp_revocation_status_t rs = pgp_tpk_revoked(tpk, 0);
  5.1640 +    pgp_revocation_status_t rs = pgp_cert_revoked(cert, 0);
  5.1641      pgp_revocation_status_variant_t rsv = pgp_revocation_status_variant(rs);
  5.1642      pgp_revocation_status_free(rs);
  5.1643      if (rsv == PGP_REVOCATION_STATUS_REVOKED) {
  5.1644 @@ -2854,19 +2866,19 @@
  5.1645      }
  5.1646  
  5.1647      PEP_comm_type best_enc = PEP_ct_no_encryption, best_sign = PEP_ct_no_encryption;
  5.1648 -    pgp_tpk_key_iter_t key_iter = pgp_tpk_key_iter_valid(tpk);
  5.1649 +    pgp_cert_key_iter_t key_iter = pgp_cert_key_iter_valid(cert);
  5.1650      pgp_key_t key;
  5.1651      pgp_signature_t sig;
  5.1652      pgp_revocation_status_t rev;
  5.1653 -    while ((key = pgp_tpk_key_iter_next(key_iter, &sig, &rev))) {
  5.1654 +    while ((key = pgp_cert_key_iter_next(key_iter, &sig, &rev))) {
  5.1655          if (! sig)
  5.1656              continue;
  5.1657  
  5.1658          PEP_comm_type curr = PEP_ct_no_encryption;
  5.1659  
  5.1660 -        int can_enc = pgp_signature_can_encrypt_for_transport(sig)
  5.1661 -            || pgp_signature_can_encrypt_at_rest(sig);
  5.1662 -        int can_sign = pgp_signature_can_sign(sig);
  5.1663 +        int can_enc = pgp_signature_for_transport_encryption(sig)
  5.1664 +            || pgp_signature_for_storage_encryption(sig);
  5.1665 +        int can_sign = pgp_signature_for_signing(sig);
  5.1666  
  5.1667          pgp_public_key_algo_t pk_algo = pgp_key_public_key_algo(key);
  5.1668          if (pk_algo == PGP_PUBLIC_KEY_ALGO_RSA_ENCRYPT_SIGN
  5.1669 @@ -2889,7 +2901,7 @@
  5.1670          if (can_sign)
  5.1671              best_sign = _MAX(best_sign, curr);
  5.1672      }
  5.1673 -    pgp_tpk_key_iter_free(key_iter);
  5.1674 +    pgp_cert_key_iter_free(key_iter);
  5.1675  
  5.1676      if (best_enc == PEP_ct_no_encryption || best_sign == PEP_ct_no_encryption) {
  5.1677          *comm_type = PEP_ct_key_b0rken;
  5.1678 @@ -2899,7 +2911,7 @@
  5.1679      }
  5.1680  
  5.1681   out:
  5.1682 -    pgp_tpk_free(tpk);
  5.1683 +    pgp_cert_free(cert);
  5.1684  
  5.1685      T("(%s) -> %s", fpr, pEp_comm_type_to_string(*comm_type));
  5.1686      return status;
  5.1687 @@ -2909,19 +2921,19 @@
  5.1688  PEP_STATUS pgp_key_created(PEP_SESSION session, const char *fpr, time_t *created)
  5.1689  {
  5.1690      PEP_STATUS status = PEP_STATUS_OK;
  5.1691 -    pgp_tpk_t tpk = NULL;
  5.1692 +    pgp_cert_t cert = NULL;
  5.1693      T("(%s)", fpr);
  5.1694  
  5.1695      *created = 0;
  5.1696  
  5.1697      pgp_fingerprint_t pgp_fpr = pgp_fingerprint_from_hex(fpr);
  5.1698 -    status = tpk_find_by_fpr(session, pgp_fpr, false, &tpk, NULL);
  5.1699 +    status = cert_find_by_fpr(session, pgp_fpr, false, &cert, NULL);
  5.1700      pgp_fingerprint_free(pgp_fpr);
  5.1701      ERROR_OUT(NULL, status, "Looking up %s", fpr);
  5.1702  
  5.1703 -    pgp_key_t k = pgp_tpk_primary_key(tpk);
  5.1704 +    pgp_key_t k = pgp_cert_primary_key(cert);
  5.1705      *created = pgp_key_creation_time(k);
  5.1706 -    pgp_tpk_free(tpk);
  5.1707 +    pgp_cert_free(cert);
  5.1708  
  5.1709   out:
  5.1710      T("(%s) -> %s", fpr, pEp_status_to_string(status));
  5.1711 @@ -2939,7 +2951,7 @@
  5.1712  {
  5.1713      T("(%s)", fpr);
  5.1714      pgp_fingerprint_t pgp_fpr = pgp_fingerprint_from_hex(fpr);
  5.1715 -    PEP_STATUS status = tpk_find_by_fpr(session, pgp_fpr, true, NULL, NULL);
  5.1716 +    PEP_STATUS status = cert_find_by_fpr(session, pgp_fpr, true, NULL, NULL);
  5.1717      pgp_fingerprint_free(pgp_fpr);
  5.1718      if (status == PEP_STATUS_OK) {
  5.1719          *has_private = 1;
     6.1 --- a/test/Makefile	Sun Dec 08 15:13:05 2019 +0100
     6.2 +++ b/test/Makefile	Sun Dec 08 15:13:17 2019 +0100
     6.3 @@ -113,7 +113,7 @@
     6.4  
     6.5  test: all
     6.6  	$(RM) -rf ./pEp_test_home/*
     6.7 -	$(TEST_CMD_PFX) $(TEST_DEBUGGER) python3 $(GTEST_PL) ./$(TARGET)
     6.8 +	$(TEST_CMD_PFX) $(TEST_DEBUGGER) GTEST_COLOR=no python3 $(GTEST_PL) --gtest_color=no ./$(TARGET)
     6.9  clean:
    6.10  	$(RM) $(TARGET) $(TARGET).o $(TARGET).d $(OBJS) $(notdir $(basename $(OBJS))) $(DEPS)
    6.11  	$(RM) -rf ./pEp_test_home/*
     7.1 --- a/test/src/KeyResetMessageTest.cc	Sun Dec 08 15:13:05 2019 +0100
     7.2 +++ b/test/src/KeyResetMessageTest.cc	Sun Dec 08 15:13:17 2019 +0100
     7.3 @@ -1217,6 +1217,36 @@
     7.4      myfile.close();      
     7.5  }
     7.6  
     7.7 +TEST_F(KeyResetMessageTest, check_no_reset_message_to_self) {
     7.8 +    pEp_identity* bob = NULL;
     7.9 +    PEP_STATUS status = set_up_preset(session, BOB,
    7.10 +                                      true, true, true, true, true, &bob);
    7.11 +                                                                
    7.12 +    slurp_and_import_key(session, "test_keys/pub/pep-test-bob-0xC9C2EE39_pub.asc");    
    7.13 +                                          
    7.14 +    message* bob_msg = new_message(PEP_dir_outgoing);
    7.15 +    bob_msg->from = identity_dup(bob);
    7.16 +    bob_msg->to = new_identity_list(identity_dup(bob));
    7.17 +    bob_msg->shortmsg = strdup("Engine bugs suck\n");
    7.18 +    bob_msg->longmsg = strdup("Everything is the engine's fault.\n");
    7.19 +    
    7.20 +    message* enc_msg = NULL;
    7.21 +    
    7.22 +    status = encrypt_message(session, bob_msg, NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
    7.23 +    ASSERT_EQ(status, PEP_STATUS_OK);
    7.24 +
    7.25 +    key_reset_all_own_keys(session);
    7.26 +    
    7.27 +    message* dec_msg = NULL;
    7.28 +    stringlist_t* keylist = NULL;
    7.29 +    PEP_rating rating;
    7.30 +    PEP_decrypt_flags_t flags = 0;
    7.31 +    
    7.32 +    status = decrypt_message(session, enc_msg, &dec_msg, &keylist, &rating, &flags);
    7.33 +    ASSERT_EQ(m_queue.size(), 0);
    7.34 +    ASSERT_EQ(status, PEP_VERIFY_SIGNER_KEY_REVOKED);
    7.35 +}
    7.36 +
    7.37  
    7.38  TEST_F(KeyResetMessageTest, check_reset_mistrust_next_msg_have_not_mailed) {
    7.39      pEp_identity* carol = NULL;
     8.1 --- a/test/src/VerifyTest.cc	Sun Dec 08 15:13:05 2019 +0100
     8.2 +++ b/test/src/VerifyTest.cc	Sun Dec 08 15:13:17 2019 +0100
     8.3 @@ -126,7 +126,7 @@
     8.4                                  &keylist, NULL);
     8.5  
     8.6      // Now it should fail.
     8.7 -    ASSERT_EQ(status , PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH);
     8.8 +    ASSERT_EQ(status , PEP_VERIFY_SIGNER_KEY_REVOKED);
     8.9      ASSERT_NE(keylist, nullptr);
    8.10      // No signer.
    8.11      ASSERT_STREQ(keylist->value, "");
    8.12 @@ -150,7 +150,7 @@
    8.13                           &keylist);
    8.14  
    8.15      // Now it should fail.
    8.16 -    ASSERT_EQ(status , PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH);
    8.17 +    ASSERT_EQ(status , PEP_VERIFY_SIGNER_KEY_REVOKED);
    8.18      ASSERT_NE(keylist, nullptr);
    8.19      // No signer.
    8.20      ASSERT_STREQ(keylist->value, "");
    8.21 @@ -175,7 +175,7 @@
    8.22                                             &keylist, NULL);
    8.23  
    8.24      // It should fail.
    8.25 -    ASSERT_EQ(status , PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH);
    8.26 +    ASSERT_EQ(status , PEP_VERIFY_SIGNER_KEY_REVOKED);
    8.27      ASSERT_NE(keylist, nullptr);
    8.28      // No signer.
    8.29      ASSERT_STREQ(keylist->value, "");
    8.30 @@ -199,7 +199,7 @@
    8.31                           &keylist);
    8.32  
    8.33      // Now it should fail.
    8.34 -    ASSERT_EQ(status , PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH);
    8.35 +    ASSERT_EQ(status , PEP_VERIFY_SIGNER_KEY_REVOKED);
    8.36      ASSERT_NE(keylist, nullptr);
    8.37      // No signer.
    8.38      ASSERT_STREQ(keylist->value, "");