merged in default ENGINE-118
authorKrista Grothoff <krista@pep-project.org>
Tue, 18 Oct 2016 17:36:15 +0200
branchENGINE-118
changeset 13119d70c1d3f6b6
parent 1306 7f45f780a3db
parent 1308 df40e76a86fc
child 1322 517692958c78
merged in default
     1.1 --- a/build-mac/pEpEngine.xcodeproj/project.pbxproj	Tue Oct 18 17:00:21 2016 +0200
     1.2 +++ b/build-mac/pEpEngine.xcodeproj/project.pbxproj	Tue Oct 18 17:36:15 2016 +0200
     1.3 @@ -12,6 +12,7 @@
     1.4  		4354FF691D6EE1A70033069C /* NULL.c in Sources */ = {isa = PBXBuildFile; fileRef = 4354FF681D6EE1A70033069C /* NULL.c */; };
     1.5  		43BA0F461D7964750059172F /* asn1_helper.c in Sources */ = {isa = PBXBuildFile; fileRef = 43BA0F451D7964750059172F /* asn1_helper.c */; };
     1.6  		43E9BC6A1DB51A1E00AD2352 /* GroupUpdate.c in Sources */ = {isa = PBXBuildFile; fileRef = 43E9BC691DB51A1E00AD2352 /* GroupUpdate.c */; };
     1.7 +		43E9BC7F1DB6720E00AD2352 /* UpdateRequest.c in Sources */ = {isa = PBXBuildFile; fileRef = 43E9BC7E1DB6720E00AD2352 /* UpdateRequest.c */; };
     1.8  		6400FB861B8CA1C6005221E3 /* libnetpgp.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 645922521B8BD32B00A5AF93 /* libnetpgp.a */; };
     1.9  		6400FB8B1B8CA1CF005221E3 /* libetpan-ios.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 64289E371B8B630200FC617B /* libetpan-ios.a */; };
    1.10  		644297C51BE11CE0002BC73B /* system.db in Resources */ = {isa = PBXBuildFile; fileRef = 64951A1B1BE0FCD800B10E71 /* system.db */; };
    1.11 @@ -193,6 +194,7 @@
    1.12  		4354FF681D6EE1A70033069C /* NULL.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = NULL.c; path = ../asn.1/NULL.c; sourceTree = "<group>"; };
    1.13  		43BA0F451D7964750059172F /* asn1_helper.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = asn1_helper.c; path = ../src/asn1_helper.c; sourceTree = "<group>"; };
    1.14  		43E9BC691DB51A1E00AD2352 /* GroupUpdate.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = GroupUpdate.c; path = ../asn.1/GroupUpdate.c; sourceTree = "<group>"; };
    1.15 +		43E9BC7E1DB6720E00AD2352 /* UpdateRequest.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = UpdateRequest.c; path = ../asn.1/UpdateRequest.c; sourceTree = "<group>"; };
    1.16  		644297BF1BE11C65002BC73B /* pEpTrustWords.bundle */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = pEpTrustWords.bundle; sourceTree = BUILT_PRODUCTS_DIR; };
    1.17  		644297C11BE11C65002BC73B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
    1.18  		646788871CEB3D120001F54C /* map_asn1.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = map_asn1.c; path = ../src/map_asn1.c; sourceTree = "<group>"; };
    1.19 @@ -362,6 +364,7 @@
    1.20  		6406CE811CE382F400C14D77 /* asn.1 */ = {
    1.21  			isa = PBXGroup;
    1.22  			children = (
    1.23 +				43E9BC7E1DB6720E00AD2352 /* UpdateRequest.c */,
    1.24  				43E9BC691DB51A1E00AD2352 /* GroupUpdate.c */,
    1.25  				4354FF681D6EE1A70033069C /* NULL.c */,
    1.26  				646C40951D510CD700C63EFF /* asn_application.h */,
    1.27 @@ -808,6 +811,7 @@
    1.28  				4354FF651D6EDF300033069C /* sync_impl.c in Sources */,
    1.29  				64A8267E1B455D0800EECAF0 /* message_api.c in Sources */,
    1.30  				64A826851B455D0800EECAF0 /* sqlite3.c in Sources */,
    1.31 +				43E9BC7F1DB6720E00AD2352 /* UpdateRequest.c in Sources */,
    1.32  				646C41361D510CD800C63EFF /* Version.c in Sources */,
    1.33  				646C41081D510CD800C63EFF /* constr_TYPE.c in Sources */,
    1.34  				646C40FE1D510CD800C63EFF /* BOOLEAN.c in Sources */,
     2.1 --- a/src/message_api.c	Tue Oct 18 17:00:21 2016 +0200
     2.2 +++ b/src/message_api.c	Tue Oct 18 17:36:15 2016 +0200
     2.3 @@ -1907,3 +1907,85 @@
     2.4      assert(false);
     2.5  }
     2.6  
     2.7 +DYNAMIC_API PEP_STATUS get_trustwords(
     2.8 +    PEP_SESSION session, pEp_identity* id1, pEp_identity* id2,
     2.9 +    const char* lang, char **words, size_t *wsize, bool full
    2.10 +)
    2.11 +{
    2.12 +    assert(session);
    2.13 +    assert(id1);
    2.14 +    assert(id2);
    2.15 +    assert(id1->fpr);
    2.16 +    assert(id2->fpr);
    2.17 +    assert(words);
    2.18 +    assert(wsize);
    2.19 +    
    2.20 +    if (!(session && id1 && id2 && words && wsize) ||
    2.21 +        !(id1->fpr) || (!id2->fpr))
    2.22 +        return PEP_ILLEGAL_VALUE;
    2.23 +    
    2.24 +    const char *source1 = id1->fpr;
    2.25 +    const char *source2 = id2->fpr;
    2.26 +    
    2.27 +    *words = NULL;
    2.28 +    *wsize = 0;
    2.29 +
    2.30 +    const size_t SHORT_NUM_TWORDS = 5;
    2.31 +    
    2.32 +    // N.B. THIS will have to be changed once we start checking trustword entropy.
    2.33 +    // For now, full is ALL, and otherwise it's 5-per-id.
    2.34 +    size_t max_words_per_id = (full ? 0 : SHORT_NUM_TWORDS);
    2.35 +    
    2.36 +    char* first_set = NULL;
    2.37 +    char* second_set = NULL;
    2.38 +    size_t first_wsize = 0;
    2.39 +    size_t second_wsize = 0;
    2.40 +    PEP_STATUS status = PEP_UNKNOWN_ERROR;
    2.41 +    
    2.42 +    char* _retstr = NULL;
    2.43 +    
    2.44 +    if (source1 > source2) {
    2.45 +        status = trustwords(session, source2, lang, &first_set, &first_wsize, max_words_per_id);
    2.46 +        if (status != PEP_STATUS_OK)
    2.47 +            goto error_release;
    2.48 +        status = trustwords(session, source1, lang, &second_set, &second_wsize, max_words_per_id); 
    2.49 +        if (status != PEP_STATUS_OK)
    2.50 +            goto error_release;
    2.51 +    }
    2.52 +    else {
    2.53 +        status = trustwords(session, source1, lang, &first_set, &first_wsize, max_words_per_id);
    2.54 +        if (status != PEP_STATUS_OK)
    2.55 +            goto error_release;
    2.56 +        status = trustwords(session, source2, lang, &second_set, &second_wsize, max_words_per_id); 
    2.57 +        if (status != PEP_STATUS_OK)
    2.58 +            goto error_release;
    2.59 +    }
    2.60 +    size_t _wsize = first_wsize + second_wsize;
    2.61 +    
    2.62 +    _retstr = calloc(1, _wsize + 1);
    2.63 +    
    2.64 +    size_t len = strlcpy(_retstr, first_set, _wsize);
    2.65 +    if (len >= _wsize) {
    2.66 +        status = PEP_UNKNOWN_ERROR;
    2.67 +        goto error_release;
    2.68 +    }
    2.69 +    strlcat(_retstr, second_set, _wsize);
    2.70 +    if (len >= _wsize){
    2.71 +        status = PEP_UNKNOWN_ERROR;
    2.72 +        goto error_release;
    2.73 +    }
    2.74 +    
    2.75 +    *words = _retstr;
    2.76 +    *wsize = _wsize;
    2.77 +    status = PEP_STATUS_OK;
    2.78 +    
    2.79 +    goto the_end;
    2.80 +    
    2.81 +    error_release:
    2.82 +    free(_retstr);
    2.83 +    
    2.84 +    the_end:
    2.85 +    free(first_set);
    2.86 +    free(second_set);
    2.87 +    return status;
    2.88 +}
    2.89 \ No newline at end of file
     3.1 --- a/src/message_api.h	Tue Oct 18 17:00:21 2016 +0200
     3.2 +++ b/src/message_api.h	Tue Oct 18 17:36:15 2016 +0200
     3.3 @@ -234,6 +234,36 @@
     3.4  //                          **path is owned by the library, do not change it!
     3.5  DYNAMIC_API PEP_STATUS get_binary_path(PEP_cryptotech tech, const char **path);
     3.6  
     3.7 +// get_trustwords() - get full trustwords string for a *pair* of identities
     3.8 +//
     3.9 +//    parameters:
    3.10 +//        session (in)        session handle
    3.11 +//        id1 (in)            identity of first party in communication - fpr can't be NULL  
    3.12 +//        id2 (in)            identity of second party in communication - fpr can't be NULL
    3.13 +//        lang (in)           C string with ISO 639-1 language code
    3.14 +//        words (out)         pointer to C string with all trustwords UTF-8 encoded,
    3.15 +//                            separated by a blank each
    3.16 +//                            NULL if language is not supported or trustword
    3.17 +//                            wordlist is damaged or unavailable
    3.18 +//        wsize (out)         length of full trustwords string
    3.19 +//        full (in)           if true, generate ALL trustwords for these identities.
    3.20 +//                            else, generate a fixed-size subset. (TODO: fixed-minimum-entropy
    3.21 +//                            subset in next version)
    3.22 +//
    3.23 +//    return value:
    3.24 +//        PEP_STATUS_OK            trustwords retrieved
    3.25 +//        PEP_OUT_OF_MEMORY        out of memory
    3.26 +//        PEP_TRUSTWORD_NOT_FOUND  at least one trustword not found
    3.27 +//
    3.28 +//    caveat:
    3.29 +//        the word pointer goes to the ownership of the caller
    3.30 +//        the caller is responsible to free() it (on Windoze use pEp_free())
    3.31 +//
    3.32 +
    3.33 +DYNAMIC_API PEP_STATUS get_trustwords(
    3.34 +    PEP_SESSION session, pEp_identity* id1, pEp_identity* id2,
    3.35 +    const char* lang, char **words, size_t *wsize, bool full
    3.36 +);
    3.37  
    3.38  #ifdef __cplusplus
    3.39  }
     4.1 --- a/src/pEpEngine.c	Tue Oct 18 17:00:21 2016 +0200
     4.2 +++ b/src/pEpEngine.c	Tue Oct 18 17:36:15 2016 +0200
     4.3 @@ -877,85 +877,6 @@
     4.4      return PEP_STATUS_OK;
     4.5  }
     4.6  
     4.7 -DYNAMIC_API PEP_STATUS get_trustwords(
     4.8 -    PEP_SESSION session, pEp_identity* id1, pEp_identity* id2,
     4.9 -    const char* lang, char **words, size_t *wsize, int max_words_per_id
    4.10 -)
    4.11 -{
    4.12 -    assert(session);
    4.13 -    assert(id1);
    4.14 -    assert(id2);
    4.15 -    assert(id1->fpr);
    4.16 -    assert(id2->fpr);
    4.17 -    assert(words);
    4.18 -    assert(wsize);
    4.19 -    assert(max_words_per_id >= 0);
    4.20 -    
    4.21 -    if (!(session && id1 && id2 && words && wsize && max_words_per_id >= 0) ||
    4.22 -        !(id1->fpr) || (!id2->fpr))
    4.23 -        return PEP_ILLEGAL_VALUE;
    4.24 -    
    4.25 -    const char *source1 = id1->fpr;
    4.26 -    const char *source2 = id2->fpr;
    4.27 -    
    4.28 -    *words = NULL;
    4.29 -    *wsize = 0;
    4.30 -
    4.31 -    char* first_set = NULL;
    4.32 -    char* second_set = NULL;
    4.33 -    size_t first_wsize = 0;
    4.34 -    size_t second_wsize = 0;
    4.35 -    PEP_STATUS status = PEP_UNKNOWN_ERROR;
    4.36 -
    4.37 -    char* _retstr = NULL;
    4.38 -    
    4.39 -    if (source1 > source2) {
    4.40 -        status = trustwords(session, source2, lang, &first_set, &first_wsize, max_words_per_id);
    4.41 -        if (status != PEP_STATUS_OK)
    4.42 -            goto error_release;
    4.43 -        status = trustwords(session, source1, lang, &second_set, &second_wsize, max_words_per_id); 
    4.44 -        if (status != PEP_STATUS_OK)
    4.45 -            goto error_release;
    4.46 -    }
    4.47 -    else {
    4.48 -        status = trustwords(session, source1, lang, &first_set, &first_wsize, max_words_per_id);
    4.49 -        if (status != PEP_STATUS_OK)
    4.50 -            goto error_release;
    4.51 -        status = trustwords(session, source2, lang, &second_set, &second_wsize, max_words_per_id); 
    4.52 -        if (status != PEP_STATUS_OK)
    4.53 -            goto error_release;
    4.54 -    }
    4.55 -    size_t _wsize = first_wsize + second_wsize;
    4.56 -    
    4.57 -    _retstr = calloc(1, _wsize + 1);
    4.58 -
    4.59 -    size_t len = strlcpy(_retstr, first_set, _wsize);
    4.60 -    if (len >= _wsize) {
    4.61 -        status = PEP_UNKNOWN_ERROR;
    4.62 -        goto error_release;
    4.63 -    }
    4.64 -    strlcat(_retstr, second_set, _wsize);
    4.65 -    if (len >= _wsize){
    4.66 -        status = PEP_UNKNOWN_ERROR;
    4.67 -        goto error_release;
    4.68 -    }
    4.69 -    
    4.70 -    *words = _retstr;
    4.71 -    *wsize = _wsize;
    4.72 -    status = PEP_STATUS_OK;
    4.73 -    
    4.74 -    goto the_end;
    4.75 -    
    4.76 -error_release:
    4.77 -    free(_retstr);
    4.78 -    
    4.79 -the_end:
    4.80 -    free(first_set);
    4.81 -    free(second_set);
    4.82 -    return status;
    4.83 -}
    4.84 -
    4.85 -
    4.86  pEp_identity *new_identity(
    4.87          const char *address, const char *fpr, const char *user_id,
    4.88          const char *username
     5.1 --- a/src/pEpEngine.h	Tue Oct 18 17:00:21 2016 +0200
     5.2 +++ b/src/pEpEngine.h	Tue Oct 18 17:36:15 2016 +0200
     5.3 @@ -530,44 +530,6 @@
     5.4          PEP_SESSION session, const pEp_identity *identity
     5.5      );
     5.6  
     5.7 -// get_trustwords() - get full trustwords string for a *pair* of identities
     5.8 -//
     5.9 -//    parameters:
    5.10 -//        session (in)        session handle
    5.11 -//        id1 (in)            identity of first party in communication - fpr can't be NULL  
    5.12 -//        id2 (in)            identity of second party in communication - fpr can't be NULL
    5.13 -//        lang (in)           C string with ISO 639-1 language code
    5.14 -//        words (out)         pointer to C string with all trustwords UTF-8 encoded,
    5.15 -//                            separated by a blank each
    5.16 -//                            NULL if language is not supported or trustword
    5.17 -//                            wordlist is damaged or unavailable
    5.18 -//        wsize (out)         length of full trustwords string
    5.19 -//        max_words_per_id (in) generate at most max_words_per_id *per input identity* (output
    5.20 -//                              string can have 2 times this value)
    5.21 -//                              if max_words_per_id == 0 there is no such limit
    5.22 -//
    5.23 -//    return value:
    5.24 -//        PEP_STATUS_OK            trustwords retrieved
    5.25 -//        PEP_OUT_OF_MEMORY        out of memory
    5.26 -//        PEP_TRUSTWORD_NOT_FOUND  at least one trustword not found
    5.27 -//
    5.28 -//    caveat:
    5.29 -//        the word pointer goes to the ownership of the caller
    5.30 -//        the caller is responsible to free() it (on Windoze use pEp_free())
    5.31 -//
    5.32 -//  Warning from trustwords(), as this function uses trustwords() as an underlying function:
    5.33 -//  DON'T USE THIS FUNCTION FROM HIGH LEVEL LANGUAGES!
    5.34 -//
    5.35 -//  Better implement a simple one in the adapter yourself using trustword(), and
    5.36 -//  return a list of trustwords.
    5.37 -//  This function is provided for being used by C and C++ programs only.
    5.38 -
    5.39 -DYNAMIC_API PEP_STATUS get_trustwords(
    5.40 -    PEP_SESSION session, pEp_identity* id1, pEp_identity* id2,
    5.41 -    const char* lang, char **words, size_t *wsize, int max_words_per_id
    5.42 -);
    5.43 -
    5.44 -
    5.45  // set_device_group() - update own person's device group
    5.46  //
    5.47  //    parameters:
    5.48 @@ -1044,6 +1006,7 @@
    5.49  //
    5.50  DYNAMIC_API const char* get_engine_version();
    5.51  
    5.52 +
    5.53  DYNAMIC_API PEP_STATUS reset_peptest_hack(PEP_SESSION session);
    5.54  
    5.55  #ifdef __cplusplus
     6.1 --- a/src/pgp_gpg.c	Tue Oct 18 17:00:21 2016 +0200
     6.2 +++ b/src/pgp_gpg.c	Tue Oct 18 17:36:15 2016 +0200
     6.3 @@ -1083,6 +1083,11 @@
     6.4              gpgme_import_result =
     6.5                  gpg.gpgme_op_import_result(session->ctx);
     6.6              assert(gpgme_import_result);
     6.7 +            if (!gpgme_import_result) {
     6.8 +                gpg.gpgme_data_release(dh);
     6.9 +                return PEP_UNKNOWN_ERROR;
    6.10 +            }
    6.11 +
    6.12              gpgme_import_status_t import;
    6.13              for (import = gpgme_import_result->imports; 
    6.14                   import; 
     7.1 --- a/test/Makefile	Tue Oct 18 17:00:21 2016 +0200
     7.2 +++ b/test/Makefile	Tue Oct 18 17:36:15 2016 +0200
     7.3 @@ -4,7 +4,10 @@
     7.4  CXX?=g++ -std=gnu++11 -pthread
     7.5  LD?=$(CXX)
     7.6  LDFLAGS?=-L$(HOME)/lib
     7.7 -LDLIBS?=-letpan -lpEpEngine -lstdc++ -L../asn.1 -lasn1 -luuid
     7.8 +LDLIBS?=-letpan -lpEpEngine -lstdc++ -L../asn.1 -lasn1
     7.9 +ifeq ($(BUILD_FOR),Linux)
    7.10 +LDLIBS=$(LDLIBS) -luuid
    7.11 +endif
    7.12  CXXFLAGS?=-std=c++11 -g -O0 -I../src -I../asn.1
    7.13  # CXXFLAGS=-O3 -DNDEBUG
    7.14  
     8.1 --- a/test/trustwords_test.cc	Tue Oct 18 17:00:21 2016 +0200
     8.2 +++ b/test/trustwords_test.cc	Tue Oct 18 17:36:15 2016 +0200
     8.3 @@ -2,6 +2,7 @@
     8.4  #include <string>
     8.5  #include <assert.h>
     8.6  #include "pEpEngine.h"
     8.7 +#include "message_api.h"
     8.8  
     8.9  using namespace std;
    8.10  
    8.11 @@ -48,7 +49,7 @@
    8.12      cout << words2 << "\n";
    8.13  
    8.14      cout << "\nfinding German trustwords for " << identity1->address << " and " << identity2->address << "...\n";
    8.15 -    get_trustwords(session, identity1, identity2, "de", &full_wordlist, &wsize_full, 5);
    8.16 +    get_trustwords(session, identity1, identity2, "de", &full_wordlist, &wsize_full, false);
    8.17      assert(full_wordlist);
    8.18      cout << full_wordlist << "\n";
    8.19