merged with default. krista_local_windows
authorkrista
Fri, 02 Sep 2016 13:30:36 +0200
branchkrista_local_windows
changeset 1126129b561095a6
parent 1125 89e75396c69a
parent 1096 396214c5cd9b
merged with default.
asn.1/pEpEngineASN1/pEpEngineASN1.vcxproj
db/create_system_db.sql
pEpEngine.vcxproj
src/cryptotech.c
src/message_api.c
src/message_api.h
src/pEpEngine.c
src/pEpEngine.h
src/pgp_gpg.c
src/pgp_gpg.h
src/pgp_netpgp.c
src/pgp_netpgp.h
src/platform_unix.c
src/platform_unix.h
src/platform_windows.h
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/openpgp_compat.c	Fri Sep 02 13:30:36 2016 +0200
     1.3 @@ -0,0 +1,23 @@
     1.4 +#include "pEp_internal.h"
     1.5 +#include "dynamic_api.h"
     1.6 +#include "openpgp_compat.h"
     1.7 +
     1.8 +DYNAMIC_API PEP_STATUS OpenPGP_list_keyinfo (
     1.9 +        PEP_SESSION session, const char* search_pattern, stringpair_list_t** keyinfo_list
    1.10 +    )
    1.11 +{
    1.12 +    assert(session);
    1.13 +    assert(keyinfo_list);
    1.14 +
    1.15 +    if (!(session && keyinfo_list))
    1.16 +        return PEP_ILLEGAL_VALUE;
    1.17 +
    1.18 +    stringpair_list_t* _keyinfo_list = NULL;
    1.19 +    
    1.20 +    PEP_STATUS retval = pgp_list_keyinfo(session, search_pattern, &_keyinfo_list);
    1.21 +        
    1.22 +    if (retval == PEP_STATUS_OK)
    1.23 +        *keyinfo_list = _keyinfo_list;
    1.24 +    
    1.25 +    return retval;
    1.26 +}
    1.27 \ No newline at end of file
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/openpgp_compat.h	Fri Sep 02 13:30:36 2016 +0200
     2.3 @@ -0,0 +1,44 @@
     2.4 +// openpgp_compat.h
     2.5 +//
     2.6 +// These functions are the exposure of non-generic PGP-specific functionality (largely related to PGP
     2.7 +// keyrings) to adapters that need them without polluting the engine interface.
     2.8 +//
     2.9 +#pragma once
    2.10 +
    2.11 +#ifdef __cplusplus
    2.12 +extern "C" {
    2.13 +#endif
    2.14 +
    2.15 +#include <stddef.h>
    2.16 +#include <stdint.h>
    2.17 +#include <stdbool.h>
    2.18 +    
    2.19 +#include "dynamic_api.h"
    2.20 +#include "stringpair.h"    
    2.21 +
    2.22 +#ifdef USE_GPG
    2.23 +#include "pgp_gpg.h"
    2.24 +#else
    2.25 +#ifdef USE_NETPGP
    2.26 +#include "pgp_netpgp.h"
    2.27 +#endif
    2.28 +#endif    
    2.29 +    
    2.30 +//  OpenPGP_list_keyinfo() - get a key/UID list for pattern matches in keyring (NULL or ""
    2.31 +//                           to return entire keyring), filtering out revoked keys in the results
    2.32 +//
    2.33 +//  parameters:
    2.34 +//      session (in)          session handle
    2.35 +//      search_pattern (in)   search pattern - either an fpr, or something within the UID, or NULL / "" for
    2.36 +//                            all keys
    2.37 +//      keyinfo_list (out)    a key/value pair list for each key / UID combination
    2.38 +//
    2.39 +//  caveat:
    2.40 +//      keyinfo_list must be freed by the caller.
    2.41 +DYNAMIC_API PEP_STATUS OpenPGP_list_keyinfo (
    2.42 +        PEP_SESSION session, const char* search_pattern, stringpair_list_t** keyinfo_list
    2.43 +    );
    2.44 +    
    2.45 +#ifdef __cplusplus
    2.46 +}
    2.47 +#endif
    2.48 \ No newline at end of file
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/encrypt_for_identity_test.cc	Fri Sep 02 13:30:36 2016 +0200
     3.3 @@ -0,0 +1,107 @@
     3.4 +#include <stdlib.h>
     3.5 +#include <string.h>
     3.6 +#include "platform.h"
     3.7 +#include <iostream>
     3.8 +#include <fstream>
     3.9 +#include <assert.h>
    3.10 +#include "mime.h"
    3.11 +#include "message_api.h"
    3.12 +
    3.13 +using namespace std;
    3.14 +
    3.15 +int main() {
    3.16 +    cout << "\n*** encrypt_for_identity_test ***\n\n";
    3.17 +
    3.18 +    PEP_SESSION session;
    3.19 +    
    3.20 +    cout << "calling init()\n";
    3.21 +    PEP_STATUS status1 = init(&session);
    3.22 +    assert(status1 == PEP_STATUS_OK);
    3.23 +    assert(session);
    3.24 +    cout << "init() completed.\n";
    3.25 +
    3.26 +    // message_api test code
    3.27 +
    3.28 +    cout << "creating message…\n";
    3.29 +    pEp_identity* alice = new_identity("pep.test.alice@pep-project.org", NULL, PEP_OWN_USERID, "Alice Test");
    3.30 +    pEp_identity* bob = new_identity("pep.test.bob@pep-project.org", NULL, "42", "Bob Test");
    3.31 +    alice->me = true;
    3.32 +    identity_list* to_list = new_identity_list(bob); // to bob
    3.33 +    message* outgoing_message = new_message(PEP_dir_outgoing);
    3.34 +    assert(outgoing_message);
    3.35 +    outgoing_message->from = alice;
    3.36 +    outgoing_message->to = to_list;
    3.37 +    outgoing_message->shortmsg = strdup("Greetings, humans!");
    3.38 +    outgoing_message->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
    3.39 +    cout << "message created.\n";
    3.40 +
    3.41 +    char* encoded_text = nullptr;
    3.42 +    PEP_STATUS status = mime_encode_message(outgoing_message, false, &encoded_text);
    3.43 +    assert(status == PEP_STATUS_OK);
    3.44 +    assert(encoded_text);
    3.45 +
    3.46 +    cout << "decrypted:\n\n";
    3.47 +    cout << encoded_text << "\n";
    3.48 +
    3.49 +    free(encoded_text);
    3.50 +
    3.51 +    cout << "encrypting message as MIME multipart…\n";
    3.52 +    message* encrypted_msg = nullptr;
    3.53 +    cout << "calling encrypt_message_for_identity()\n";
    3.54 +    status = encrypt_message_for_self(session, alice, outgoing_message, &encrypted_msg, PEP_enc_PGP_MIME);
    3.55 +    cout << "encrypt_message() returns " << std::hex << status << '.' << endl;
    3.56 +    assert(status == PEP_STATUS_OK);
    3.57 +    assert(encrypted_msg);
    3.58 +    cout << "message encrypted.\n";
    3.59 +    
    3.60 +    status = mime_encode_message(encrypted_msg, false, &encoded_text);
    3.61 +    assert(status == PEP_STATUS_OK);
    3.62 +    assert(encoded_text);
    3.63 +
    3.64 +    cout << "encrypted:\n\n";
    3.65 +    cout << encoded_text << "\n";
    3.66 +
    3.67 +    message* decoded_msg = nullptr;
    3.68 +    status = mime_decode_message(encoded_text, strlen(encoded_text), &decoded_msg);
    3.69 +    assert(status == PEP_STATUS_OK);
    3.70 +    const string string3 = encoded_text;
    3.71 +
    3.72 +    unlink("msg_encrypt_for_self.asc");
    3.73 +    ofstream outFile3("msg_encrypt_for_self.asc");
    3.74 +    outFile3.write(string3.c_str(), string3.size());
    3.75 +    outFile3.close();
    3.76 +
    3.77 +    message* decrypted_msg = nullptr;
    3.78 +    stringlist_t* keylist_used = nullptr;
    3.79 +
    3.80 +    PEP_color color;
    3.81 +    PEP_decrypt_flags_t flags;
    3.82 +
    3.83 +    status = decrypt_message(session, encrypted_msg, &decrypted_msg, &keylist_used, &color, &flags);
    3.84 +    assert(status == PEP_STATUS_OK);
    3.85 +    assert(decrypted_msg);
    3.86 +    assert(keylist_used);
    3.87 +    assert(color);
    3.88 +    PEP_comm_type ct = encrypted_msg->from->comm_type;
    3.89 +    assert(ct == PEP_ct_pEp || ct == PEP_ct_pEp_unconfirmed || ct == PEP_ct_OpenPGP || ct == PEP_ct_OpenPGP_unconfirmed );
    3.90 +
    3.91 +    cout << "keys used:\n";
    3.92 +
    3.93 +    for (stringlist_t* kl4 = keylist_used; kl4 && kl4->value; kl4 = kl4->next)
    3.94 +    {
    3.95 +        cout << "\t " << kl4->value << endl;
    3.96 +        assert(strcasecmp("4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", kl4->value) == 0);
    3.97 +        cout << "Encrypted for Alice! Yay! It worked!" << endl;
    3.98 +    }
    3.99 +    cout << "Encrypted ONLY for Alice! Test passed. Move along. These are not the bugs you are looking for." << endl;
   3.100 + 
   3.101 +    cout << "freeing messages…\n";
   3.102 +    free_message(encrypted_msg);
   3.103 +    free_message(decrypted_msg);
   3.104 +    free_message(outgoing_message);
   3.105 +    cout << "done.\n";
   3.106 +
   3.107 +    cout << "calling release()\n";
   3.108 +    release(session);
   3.109 +    return 0;
   3.110 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/pgp_list_keys_test.cc	Fri Sep 02 13:30:36 2016 +0200
     4.3 @@ -0,0 +1,71 @@
     4.4 +#include <iostream>
     4.5 +#include <string>
     4.6 +#include <assert.h>
     4.7 +#include "pEpEngine.h"
     4.8 +#include "stringpair.h"
     4.9 +#include "openpgp_compat.h"
    4.10 +
    4.11 +using namespace std;
    4.12 +
    4.13 +void print_stringpair_list(stringpair_list_t* spl) {
    4.14 +    for ( ; spl != NULL; spl = spl->next) {
    4.15 +        if (spl->value) {
    4.16 +            cout << "Key:" << endl;
    4.17 +            if (spl->value->key)
    4.18 +                cout << "\tFPR: " << spl->value->key << endl;
    4.19 +            if (spl->value->value)
    4.20 +                cout << "\tUID: " << spl->value->value << endl;
    4.21 +        }
    4.22 +    }
    4.23 +}
    4.24 +
    4.25 +int main() {
    4.26 +    cout << "\n*** openpgp_compat test ***\n\n";
    4.27 +
    4.28 +    PEP_SESSION session;
    4.29 +    
    4.30 +    cout << "calling init()\n";
    4.31 +    PEP_STATUS status1 = init(&session);   
    4.32 +    assert(status1 == PEP_STATUS_OK);
    4.33 +    assert(session);
    4.34 +    cout << "init() completed.\n";
    4.35 +
    4.36 +    cout << "Listing all the keys:" << endl;
    4.37 +    stringpair_list_t* all_the_ids = NULL;
    4.38 +    OpenPGP_list_keyinfo(session, "", &all_the_ids);
    4.39 +    print_stringpair_list(all_the_ids);
    4.40 +    free_stringpair_list(all_the_ids);
    4.41 +    
    4.42 +    cout << "**********************" << endl << endl << "Checking on Alice, Bob and John" << endl;
    4.43 +    all_the_ids = NULL;
    4.44 +    OpenPGP_list_keyinfo(session, "pEp Test", &all_the_ids);
    4.45 +    print_stringpair_list(all_the_ids);
    4.46 +    free_stringpair_list(all_the_ids);
    4.47 +
    4.48 +    cout << "**********************" << endl << endl << "Compare to find_keys for Alice, Bob and John" << endl;
    4.49 +    stringlist_t* all_the_keys;
    4.50 +    find_keys(session, "pEp Test", &all_the_keys);
    4.51 +    stringlist_t* i;
    4.52 +    for (i = all_the_keys; i; i = i->next) {
    4.53 +        cout << i->value << endl;
    4.54 +    }
    4.55 +    free_stringlist(all_the_keys);
    4.56 +
    4.57 +    
    4.58 +    cout << "**********************" << endl << endl << "Checking FPR" << endl;
    4.59 +    all_the_ids = NULL;
    4.60 +    OpenPGP_list_keyinfo(session, "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39", &all_the_ids);
    4.61 +    print_stringpair_list(all_the_ids);
    4.62 +    free_stringpair_list(all_the_ids);
    4.63 +
    4.64 +    cout << "**********************" << endl << endl << "Checking on nothing" << endl;
    4.65 +    all_the_ids = NULL;
    4.66 +    OpenPGP_list_keyinfo(session, "ekhwr89234uh4rknfjsklejfnlskjflselkflkserjs", &all_the_ids);
    4.67 +    print_stringpair_list(all_the_ids);
    4.68 +    free_stringpair_list(all_the_ids);
    4.69 +
    4.70 +    cout << "calling release()\n";
    4.71 +    release(session);
    4.72 +    return 0;
    4.73 +}
    4.74 +