Added pgp_key_revoked to pgp_netpgp.*
authorEdouard Tisserant
Wed, 18 May 2016 17:05:40 +0200
changeset 661ec4acbe24505
parent 660 e1905543313b
child 662 3c727b41d0c2
Added pgp_key_revoked to pgp_netpgp.*
src/pgp_netpgp.c
src/pgp_netpgp.h
     1.1 --- a/src/pgp_netpgp.c	Wed May 18 15:53:12 2016 +0200
     1.2 +++ b/src/pgp_netpgp.c	Wed May 18 17:05:40 2016 +0200
     1.3 @@ -168,7 +168,7 @@
     1.4      PEP_STATUS status = PEP_STATUS_OK;
     1.5  
     1.6      assert(session);
     1.7 -    if(!session) return PEP_UNKNOWN_ERROR;
     1.8 +    if(!session) return PEP_ILLEGAL_VALUE;
     1.9  
    1.10      if (in_first) {
    1.11          if((status = init_netpgp()) != PEP_STATUS_OK)
    1.12 @@ -210,32 +210,6 @@
    1.13      return armoured;
    1.14  }
    1.15  
    1.16 -/* write key ID bytes read from hex string 
    1.17 - * tolerates no space, only hexes */
    1.18 -static unsigned str_to_id(uint8_t *keyid, const char *str)
    1.19 -{
    1.20 -    int i, n;
    1.21 -    for (i = 0; i < PGP_KEY_ID_SIZE ; i++) {
    1.22 -        uint8_t b = 0;
    1.23 -        for (n = 0; n < 2; n++) {
    1.24 -            char c = str[i * 2 + n];
    1.25 -            uint8_t q;
    1.26 -            if(c >= '0' &&  c <= '9'){
    1.27 -                q = (c - '0');
    1.28 -            }else if(c >= 'a' &&  c <= 'f'){
    1.29 -                q = (c - 'a' + 0xA);
    1.30 -            }else if(c >= 'A' &&  c <= 'F'){
    1.31 -                q = (c - 'A' + 0xA);
    1.32 -            }else{
    1.33 -                return 0;
    1.34 -            }
    1.35 -            b |= q << (4 * (1 - n));
    1.36 -        }
    1.37 -        keyid[i] = b;
    1.38 -    }
    1.39 -    return 1;
    1.40 -}
    1.41 -
    1.42  /* write key fingerprint hexdump as a string */
    1.43  static unsigned
    1.44  fpr_to_str (char **str, const uint8_t *fpr, size_t length)
    1.45 @@ -391,7 +365,7 @@
    1.46      assert(keylist);
    1.47  
    1.48      if(!session || !ctext || !csize || !ptext || !psize || !keylist) 
    1.49 -        return PEP_UNKNOWN_ERROR;
    1.50 +        return PEP_ILLEGAL_VALUE;
    1.51  
    1.52      if(pthread_mutex_lock(&netpgp_mutex)){
    1.53          return PEP_UNKNOWN_ERROR;
    1.54 @@ -491,7 +465,7 @@
    1.55      assert(keylist);
    1.56  
    1.57      if(!session || !text || !size || !signature || !sig_size || !keylist) 
    1.58 -        return PEP_UNKNOWN_ERROR;
    1.59 +        return PEP_ILLEGAL_VALUE;
    1.60  
    1.61      if(pthread_mutex_lock(&netpgp_mutex)){
    1.62          return PEP_UNKNOWN_ERROR;
    1.63 @@ -584,7 +558,7 @@
    1.64      assert(csize);
    1.65  
    1.66      if(!session || !ptext || !psize || !ctext || !csize || !keylist) 
    1.67 -        return PEP_UNKNOWN_ERROR;
    1.68 +        return PEP_ILLEGAL_VALUE;
    1.69  
    1.70      if(pthread_mutex_lock(&netpgp_mutex)){
    1.71          return PEP_UNKNOWN_ERROR;
    1.72 @@ -732,7 +706,7 @@
    1.73  
    1.74      if(!session || !identity || 
    1.75         !identity->address || identity->fpr || !identity->username)
    1.76 -        return PEP_UNKNOWN_ERROR;
    1.77 +        return PEP_ILLEGAL_VALUE;
    1.78  
    1.79      if(pthread_mutex_lock(&netpgp_mutex)){
    1.80          return PEP_UNKNOWN_ERROR;
    1.81 @@ -839,7 +813,7 @@
    1.82      assert(fprstr);
    1.83  
    1.84      if (!session || !fprstr)
    1.85 -        return PEP_UNKNOWN_ERROR;
    1.86 +        return PEP_ILLEGAL_VALUE;
    1.87  
    1.88      if(pthread_mutex_lock(&netpgp_mutex)){
    1.89          return PEP_UNKNOWN_ERROR;
    1.90 @@ -893,7 +867,7 @@
    1.91      assert(key_data);
    1.92  
    1.93      if(!session || !key_data) 
    1.94 -        return PEP_UNKNOWN_ERROR;
    1.95 +        return PEP_ILLEGAL_VALUE;
    1.96  
    1.97      if(pthread_mutex_lock(&netpgp_mutex)){
    1.98          return PEP_UNKNOWN_ERROR;
    1.99 @@ -941,7 +915,7 @@
   1.100  	pgp_setup_memory_write(&output, &mem, 128);
   1.101  
   1.102      if (mem == NULL || output == NULL) {
   1.103 -        return PEP_OUT_OF_MEMORY;
   1.104 +        return PEP_ILLEGAL_VALUE;
   1.105      }
   1.106  
   1.107      if (!pgp_write_xfer_key(output, key, 1)) {
   1.108 @@ -989,7 +963,7 @@
   1.109      assert(size);
   1.110  
   1.111      if (!session || !fprstr || !key_data || !size)
   1.112 -        return PEP_UNKNOWN_ERROR;
   1.113 +        return PEP_ILLEGAL_VALUE;
   1.114  
   1.115      if(pthread_mutex_lock(&netpgp_mutex)){
   1.116          return PEP_UNKNOWN_ERROR;
   1.117 @@ -1070,7 +1044,7 @@
   1.118      assert(pattern);
   1.119  
   1.120      if (!session || !pattern )
   1.121 -        return PEP_UNKNOWN_ERROR;
   1.122 +        return PEP_ILLEGAL_VALUE;
   1.123  
   1.124      if(pthread_mutex_lock(&session->ctx.curl_mutex)){
   1.125          return PEP_UNKNOWN_ERROR;
   1.126 @@ -1217,9 +1191,12 @@
   1.127      assert(keylist);
   1.128  
   1.129      if (!session || !pattern || !keylist )
   1.130 -        return PEP_UNKNOWN_ERROR;
   1.131 +    {
   1.132 +        return PEP_ILLEGAL_VALUE;
   1.133 +    }
   1.134  
   1.135 -    if(pthread_mutex_lock(&netpgp_mutex)){
   1.136 +    if (pthread_mutex_lock(&netpgp_mutex))
   1.137 +    {
   1.138          return PEP_UNKNOWN_ERROR;
   1.139      }
   1.140  
   1.141 @@ -1314,7 +1291,7 @@
   1.142      assert(pattern);
   1.143  
   1.144      if (!session || !pattern )
   1.145 -        return PEP_UNKNOWN_ERROR;
   1.146 +        return PEP_ILLEGAL_VALUE;
   1.147  
   1.148      encoded_keys = new_stringlist(NULL);
   1.149      assert(encoded_keys);
   1.150 @@ -1399,7 +1376,7 @@
   1.151      assert(comm_type);
   1.152  
   1.153      if (!session || !fprstr || !comm_type )
   1.154 -        return PEP_UNKNOWN_ERROR;
   1.155 +        return PEP_ILLEGAL_VALUE;
   1.156  
   1.157      *comm_type = PEP_ct_unknown;
   1.158  
   1.159 @@ -1472,7 +1449,7 @@
   1.160      assert(fprstr);
   1.161  
   1.162      if (!session || !fprstr )
   1.163 -        return PEP_UNKNOWN_ERROR;
   1.164 +        return PEP_ILLEGAL_VALUE;
   1.165  
   1.166      if(ts)
   1.167      {
   1.168 @@ -1619,7 +1596,7 @@
   1.169  
   1.170  PEP_STATUS pgp_key_expired(
   1.171          PEP_SESSION session,
   1.172 -        const char *keyidstr,
   1.173 +        const char *fprstr,
   1.174          bool *expired
   1.175      )
   1.176  {
   1.177 @@ -1627,12 +1604,16 @@
   1.178      PEP_comm_type comm_type;
   1.179  
   1.180      assert(session);
   1.181 -    assert(keyidstr);
   1.182 +    assert(fprstr);
   1.183      assert(expired);
   1.184  
   1.185 +    if (!session || !fprstr || !expired)
   1.186 +        return PEP_UNKNOWN_ERROR;
   1.187 +
   1.188 +
   1.189      *expired = false;
   1.190  
   1.191 -    status = pgp_get_key_rating(session, keyidstr, &comm_type);
   1.192 +    status = pgp_get_key_rating(session, fprstr, &comm_type);
   1.193  
   1.194      if (status != PEP_STATUS_OK)
   1.195          return status;
   1.196 @@ -1644,3 +1625,29 @@
   1.197      return PEP_STATUS_OK;
   1.198  }
   1.199  
   1.200 +PEP_STATUS pgp_key_revoked(
   1.201 +        PEP_SESSION session,
   1.202 +        const char *fprstr,
   1.203 +        bool *revoked
   1.204 +    )
   1.205 +{
   1.206 +    PEP_STATUS status = PEP_STATUS_OK;
   1.207 +    PEP_comm_type comm_type;
   1.208 +    
   1.209 +    assert(session);
   1.210 +    assert(fprstr);
   1.211 +    assert(revoked);
   1.212 +    
   1.213 +    *revoked = false;
   1.214 +    
   1.215 +    status = pgp_get_key_rating(session, fprstr, &comm_type);
   1.216 +    
   1.217 +    if (status != PEP_STATUS_OK)
   1.218 +        return status;
   1.219 +    
   1.220 +    if (comm_type == PEP_ct_key_revoked){
   1.221 +        *revoked = true;
   1.222 +    }
   1.223 +    
   1.224 +    return PEP_STATUS_OK;
   1.225 +}
     2.1 --- a/src/pgp_netpgp.h	Wed May 18 15:53:12 2016 +0200
     2.2 +++ b/src/pgp_netpgp.h	Wed May 18 17:05:40 2016 +0200
     2.3 @@ -64,3 +64,8 @@
     2.4          bool *expired
     2.5      );
     2.6  
     2.7 +PEP_STATUS pgp_key_revoked(
     2.8 +        PEP_SESSION session,
     2.9 +        const char *fpr,
    2.10 +        bool *revoked
    2.11 +    );