creation and verification of beacon messages now works fdik_sync
authorKrista Bennett <krista@pep-project.org>
Fri, 24 Mar 2017 15:40:17 +0100
branchfdik_sync
changeset 169062610d1dcbca
parent 1689 0579d2132265
child 1691 a1f336a3c422
creation and verification of beacon messages now works
src/pgp_gpg.c
test/sign_verify_blob_test.cc
test/test_data/random_blob.pEp
     1.1 --- a/src/pgp_gpg.c	Fri Mar 24 12:22:23 2017 +0100
     1.2 +++ b/src/pgp_gpg.c	Fri Mar 24 15:40:17 2017 +0100
     1.3 @@ -255,6 +255,12 @@
     1.4              "gpgme_op_encrypt");
     1.5          assert(gpg.gpgme_op_encrypt);
     1.6  
     1.7 +        gpg.gpgme_op_sign
     1.8 +            = (gpgme_op_verify_t) (intptr_t) dlsym(gpgme,
     1.9 +            "gpgme_op_sign");
    1.10 +        assert(gpg.gpgme_op_sign);
    1.11 +
    1.12 +
    1.13          gpg.gpgme_op_verify_result
    1.14              = (gpgme_op_verify_result_t) (intptr_t) dlsym(gpgme,
    1.15              "gpgme_op_verify_result");
    1.16 @@ -1065,8 +1071,7 @@
    1.17      gpgme_data_t plain, detached_sig;
    1.18      gpgme_key_t *rcpt;
    1.19      gpgme_sig_mode_t sig_mode = GPGME_SIG_MODE_DETACH;
    1.20 -    const stringlist_t *_keylist;
    1.21 -    int i, j;
    1.22 +    int j;
    1.23  
    1.24      assert(session);
    1.25      assert(keylist);
    1.26 @@ -1114,7 +1119,7 @@
    1.27      if (!keylist->value)
    1.28          return PEP_KEY_NOT_FOUND;
    1.29          
    1.30 -    gpgme_error = gpg.gpgme_get_key(session->ctx, _keylist->value,
    1.31 +    gpgme_error = gpg.gpgme_get_key(session->ctx, keylist->value,
    1.32          &rcpt[0], 0);
    1.33          
    1.34      gpgme_error = _GPGERR(gpgme_error);
    1.35 @@ -1152,8 +1157,6 @@
    1.36              gpg.gpgme_data_release(detached_sig);
    1.37              return PEP_GET_KEY_FAILED;
    1.38      }
    1.39 -
    1.40 -    sig_mode = GPGME_SIG_MODE_NORMAL;
    1.41      
    1.42      gpgme_error = gpg.gpgme_op_sign(session->ctx, plain, detached_sig, sig_mode);
    1.43      
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/sign_verify_blob_test.cc	Fri Mar 24 15:40:17 2017 +0100
     2.3 @@ -0,0 +1,80 @@
     2.4 +// This file is under GNU General Public License 3.0
     2.5 +// see LICENSE.txt
     2.6 +
     2.7 +#include <stdlib.h>
     2.8 +#include <string.h>
     2.9 +#include "platform.h"
    2.10 +#include <iostream>
    2.11 +#include <fstream>
    2.12 +#include <assert.h>
    2.13 +#include "mime.h"
    2.14 +#include "message_api.h"
    2.15 +
    2.16 +using namespace std;
    2.17 +
    2.18 +int main() {
    2.19 +    cout << "\n*** sign_verify_blob_test ***\n\n";
    2.20 +
    2.21 +    PEP_SESSION session;
    2.22 +    
    2.23 +    cout << "calling init()\n";
    2.24 +    PEP_STATUS status1 = init(&session);
    2.25 +    assert(status1 == PEP_STATUS_OK);
    2.26 +    assert(session);
    2.27 +    cout << "init() completed.\n";
    2.28 +
    2.29 +    // message_api test code
    2.30 +
    2.31 +    cout << "creating message…\n";
    2.32 +    pEp_identity * me2 = new_identity("pep.test.alice@pep-project.org", NULL, PEP_OWN_USERID, "Alice Test");
    2.33 +    me2->me = true;
    2.34 +    identity_list *to2 = new_identity_list(new_identity("pep.test.bob@pep-project.org", NULL, "42", "Bob Test"));
    2.35 +    message *msg2 = new_message(PEP_dir_outgoing);
    2.36 +    assert(msg2);
    2.37 +    msg2->from = me2;
    2.38 +    msg2->to = to2;
    2.39 +    msg2->shortmsg = strdup("Sample Beacon Message");
    2.40 +    msg2->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
    2.41 +    cout << "message created.\n";
    2.42 + 
    2.43 +    const size_t BUFFERSIZE = 1024;
    2.44 +    char buffer[BUFFERSIZE];
    2.45 +    
    2.46 +    std::ifstream fin("test_data/random_blob.pEp", ios::in | ios::binary );
    2.47 +    fin.read(buffer, BUFFERSIZE);  
    2.48 +
    2.49 +    size_t blob_size = fin.gcount(); 
    2.50 +    assert(blob_size == 999); 
    2.51 +
    2.52 +    PEP_STATUS status1_5 = prepare_beacon_message(session, buffer, blob_size, msg2); 
    2.53 +    assert(status1_5 == PEP_STATUS_OK);
    2.54 +
    2.55 +    cout << "*** beacon blob signed and attached to message:" << endl;
    2.56 +      
    2.57 +    char *text2 = nullptr;
    2.58 +    PEP_STATUS status2 = mime_encode_message(msg2, false, &text2);
    2.59 +    assert(status2 == PEP_STATUS_OK);
    2.60 +    assert(text2);
    2.61 +
    2.62 +    cout << "encoded:\n\n";
    2.63 +    cout << text2 << "\n";
    2.64 +
    2.65 +    message *msg3 = nullptr;
    2.66 +    PEP_STATUS status3 = mime_decode_message(text2, strlen(text2), &msg3);
    2.67 +    assert(status3 == PEP_STATUS_OK);
    2.68 +
    2.69 +    char* signing_fpr = NULL;
    2.70 +    PEP_STATUS status4 = verify_beacon_message(session, msg3, &signing_fpr);
    2.71 +    assert(status4 == PEP_VERIFIED || status4 == PEP_VERIFIED_AND_TRUSTED);
    2.72 +
    2.73 +    cout << "*** beacon blob in encoded message extracted and verified!!!!:" << endl;
    2.74 +    assert(strcmp("4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", signing_fpr) == 0);
    2.75 +
    2.76 +    cout << "*** Beacon signed by " << signing_fpr << ", as expected. SUCCESS!!!!" << endl;    
    2.77 +
    2.78 +    cout << "calling release()\n";
    2.79 +    release(session);
    2.80 +
    2.81 +    cout << "\n*** PASSED: sign_verify_blob_test ***\n\n";
    2.82 +    return 0;
    2.83 +}
     3.1 Binary file test/test_data/random_blob.pEp has changed