ENGINE-420: compiled first draft of private key export ENGINE-420
authorKrista Bennett <krista@pep-project.org>
Wed, 11 Apr 2018 16:43:33 +0200
branchENGINE-420
changeset 2592d1cb6fd3ded2
parent 2591 6f54f095b7ec
child 2593 0876c1a73ae1
ENGINE-420: compiled first draft of private key export
src/message_api.c
src/message_api.h
     1.1 --- a/src/message_api.c	Wed Apr 11 15:52:32 2018 +0200
     1.2 +++ b/src/message_api.c	Wed Apr 11 16:43:33 2018 +0200
     1.3 @@ -1812,7 +1812,6 @@
     1.4      return status;
     1.5  }
     1.6  
     1.7 -
     1.8  DYNAMIC_API PEP_STATUS encrypt_message_and_add_priv_key(
     1.9          PEP_SESSION session,
    1.10          message *src,
    1.11 @@ -1866,7 +1865,7 @@
    1.12          
    1.13      // Let's get our own, normal identity
    1.14      pEp_identity* own_identity = NULL;
    1.15 -    status = get_identity(session, src->to->ident->address, own_id, own_identity);    
    1.16 +    status = get_identity(session, src->to->ident->address, own_id, &own_identity);    
    1.17  
    1.18      if (status != PEP_STATUS_OK)
    1.19          goto pep_free;
    1.20 @@ -1890,8 +1889,8 @@
    1.21      char* priv_key_data = NULL;
    1.22      size_t priv_key_size = 0;
    1.23      
    1.24 -    status = export_key(session, own_private_fpr, &priv_key_data, 
    1.25 -                        &priv_key_size, true);
    1.26 +    status = export_secrect_key(session, own_private_fpr, &priv_key_data, 
    1.27 +                                &priv_key_size);
    1.28  
    1.29      if (status != PEP_STATUS_OK)
    1.30          goto pep_free;
    1.31 @@ -1901,13 +1900,67 @@
    1.32          goto pep_free;
    1.33      }
    1.34      
    1.35 -    // Ok, fine... let's encrypt yon blob.
    1.36 +    // Ok, fine... let's encrypt yon blob
    1.37 +    stringlist_t* keys = new_stringlist(to_fpr);
    1.38 +    if (!keys) {
    1.39 +        status = PEP_OUT_OF_MEMORY;
    1.40 +        goto pep_free;
    1.41 +    }
    1.42 +    
    1.43 +    char* encrypted_key_text = NULL;
    1.44 +    size_t encrypted_key_size = 0;
    1.45 +    status = encrypt_and_sign(session, keys, priv_key_data, priv_key_size,
    1.46 +                              &encrypted_key_text, &encrypted_key_size);
    1.47 +    
    1.48 +    if (!encrypted_key_text) {
    1.49 +        status = PEP_UNKNOWN_ERROR;
    1.50 +        goto pep_free;
    1.51 +    }
    1.52 +
    1.53 +    // We will have to delete this before returning, as we allocated it.
    1.54 +    bloblist_t* created_bl = NULL;
    1.55 +    bloblist_t* created_predecessor = NULL;
    1.56 +    if (!src->attachments) {
    1.57 +        src->attachments = new_bloblist(encrypted_key_text, encrypted_key_size,
    1.58 +                                        "application/octet-stream", 
    1.59 +                                        "file://pEpkey.asc.pgp");
    1.60 +        created_bl = src->attachments;
    1.61 +    } 
    1.62 +    else {
    1.63 +        bloblist_t* tmp = src->attachments;
    1.64 +        while (src->attachments->next) {
    1.65 +            tmp = src->attachments->next;
    1.66 +        }
    1.67 +        created_bl = bloblist_add(src->attachments, 
    1.68 +                                  encrypted_key_text, encrypted_key_size,
    1.69 +                                  "application/octet-stream", 
    1.70 +                                   "file://pEpkey.asc.pgp");
    1.71 +                                
    1.72 +        created_predecessor = tmp;                                    
    1.73 +    }
    1.74 +    
    1.75 +    if (!created_bl) {
    1.76 +        status = PEP_OUT_OF_MEMORY;
    1.77 +        goto pep_free;
    1.78 +    }
    1.79 +            
    1.80 +    // Ok, it's in there. Let's do this.        
    1.81 +    status = encrypt_message(session, src, keys, dst, enc_format, 0);
    1.82 +    
    1.83 +    // Delete what we added to src
    1.84 +    free_bloblist(created_bl);
    1.85 +    if (created_predecessor)
    1.86 +        created_predecessor->next = NULL;
    1.87 +    else
    1.88 +        src->attachments = NULL;    
    1.89 +    
    1.90  pep_free:
    1.91      free(own_id);
    1.92      free(default_id);
    1.93      free(priv_key_data);
    1.94      free(own_private_fpr);
    1.95      free_identity(own_identity);
    1.96 +    free_stringlist(keys);
    1.97      return status;
    1.98  }
    1.99  
     2.1 --- a/src/message_api.h	Wed Apr 11 15:52:32 2018 +0200
     2.2 +++ b/src/message_api.h	Wed Apr 11 16:43:33 2018 +0200
     2.3 @@ -75,6 +75,15 @@
     2.4      );
     2.5  
     2.6  
     2.7 +DYNAMIC_API PEP_STATUS encrypt_message_and_add_priv_key(
     2.8 +        PEP_SESSION session,
     2.9 +        message *src,
    2.10 +        message **dst,
    2.11 +        const char* to_fpr,
    2.12 +        PEP_enc_format enc_format
    2.13 +    );
    2.14 +
    2.15 +
    2.16  // encrypt_message_for_self() - encrypt message in memory for user's identity only,
    2.17  //                              ignoring recipients and other identities from
    2.18  //                              the message