Browse Source

ENGINE-247: Initial commit - tests need to be cleaned up and are failing for weird reasons.

doc_update_sequoia
Krista Bennett 5 years ago
parent
commit
defbd7c8fe
4 changed files with 49 additions and 12 deletions
  1. +19
    -10
      src/message_api.c
  2. +2
    -1
      src/mime.c
  3. +24
    -0
      src/pEp_internal.h
  4. +4
    -1
      test/pEp_subject_received_test.cc

+ 19
- 10
src/message_api.c View File

@ -103,9 +103,12 @@ void add_opt_field(message *msg, const char *name, const char *value)
static char * combine_short_and_long(const char *shortmsg, const char *longmsg)
{
assert(shortmsg);
assert(strcmp(shortmsg, "pEp") != 0);
if (!shortmsg || strcmp(shortmsg, "pEp") == 0) {
unsigned char pepstr[] = PEP_SUBJ_STRING;
assert(strcmp(shortmsg, "pEp") != 0 && _unsigned_signed_strcmp(pepstr, shortmsg, PEP_SUBJ_BYTELEN) != 0);
if (!shortmsg || strcmp(shortmsg, "pEp") == 0 ||
_unsigned_signed_strcmp(pepstr, shortmsg, PEP_SUBJ_BYTELEN) == 0) {
if (!longmsg) {
return NULL;
}
@ -370,8 +373,10 @@ static PEP_STATUS encrypt_PGP_MIME(
size_t csize;
assert(dst->longmsg == NULL);
dst->enc_format = PEP_enc_PGP_MIME;
unsigned char pepstr[] = PEP_SUBJ_STRING;
if (src->shortmsg && strcmp(src->shortmsg, "pEp") != 0) {
if (src->shortmsg && strcmp(src->shortmsg, "pEp") != 0
&& _unsigned_signed_strcmp(pepstr, src->shortmsg, PEP_SUBJ_BYTELEN) != 0) {
if (session->unencrypted_subject) {
dst->shortmsg = strdup(src->shortmsg);
assert(dst->shortmsg);
@ -390,7 +395,7 @@ static PEP_STATUS encrypt_PGP_MIME(
ptext = src->longmsg;
}
else {
ptext = "pEp";
ptext = (char*)pepstr;
}
message *_src = calloc(1, sizeof(message));
@ -471,7 +476,8 @@ static PEP_STATUS encrypt_PGP_in_pieces(
size_t csize;
char *ptext = NULL;
bool free_ptext = false;
unsigned char pepstr[] = PEP_SUBJ_STRING;
assert(dst->longmsg == NULL);
assert(dst->attachments == NULL);
@ -479,7 +485,8 @@ static PEP_STATUS encrypt_PGP_in_pieces(
bool nosign = (flags & PEP_encrypt_flag_force_unsigned);
if (src->shortmsg && src->shortmsg[0] && strcmp(src->shortmsg, "pEp") != 0) {
if (src->shortmsg && src->shortmsg[0] && strcmp(src->shortmsg, "pEp") != 0 &&
_unsigned_signed_strcmp(pepstr, src->shortmsg, PEP_SUBJ_BYTELEN) != 0) {
if (session->unencrypted_subject) {
dst->shortmsg = strdup(src->shortmsg);
assert(dst->shortmsg);
@ -1284,7 +1291,7 @@ DYNAMIC_API PEP_STATUS encrypt_message(
free_stringlist(keys);
if (msg && msg->shortmsg == NULL) {
msg->shortmsg = strdup("pEp");
msg->shortmsg = _pep_subj_copy();
assert(msg->shortmsg);
if (msg->shortmsg == NULL)
goto enomem;
@ -1395,7 +1402,7 @@ DYNAMIC_API PEP_STATUS encrypt_message_for_self(
goto pep_error;
if (msg && msg->shortmsg == NULL) {
msg->shortmsg = strdup("pEp");
msg->shortmsg = _pep_subj_copy();
assert(msg->shortmsg);
if (msg->shortmsg == NULL)
goto enomem;
@ -1680,6 +1687,7 @@ DYNAMIC_API PEP_STATUS _decrypt_message(
char *ptext = NULL;
size_t psize;
stringlist_t *_keylist = NULL;
unsigned char pepstr[] = PEP_SUBJ_STRING;
assert(session);
assert(src);
@ -1970,7 +1978,8 @@ DYNAMIC_API PEP_STATUS _decrypt_message(
GOTO(pep_error);
}
if (src->shortmsg == NULL || strcmp(src->shortmsg, "pEp") == 0)
if (src->shortmsg == NULL || strcmp(src->shortmsg, "pEp") == 0 ||
_unsigned_signed_strcmp(pepstr, src->shortmsg, PEP_SUBJ_BYTELEN) == 0)
{
char * shortmsg;
char * longmsg;


+ 2
- 1
src/mime.c View File

@ -418,7 +418,8 @@ static PEP_STATUS build_fields(const message *msg, struct mailimf_fields **resul
struct mailimf_fields * fields = NULL;
int r;
clist * fields_list = NULL;
char *subject = msg->shortmsg ? msg->shortmsg : "pEp";
unsigned char pepstr[] = PEP_SUBJ_STRING; // unsigned due to UTF-8 byte fun
char *subject = msg->shortmsg ? msg->shortmsg : (char*)pepstr;
assert(msg);
assert(msg->from);


+ 24
- 0
src/pEp_internal.h View File

@ -31,6 +31,12 @@
#endif
#define CRASHDUMP_MAX_LINES 32767
// pp full string, NUL-terminated
#ifndef PEP_SUBJ_STRING
#define PEP_SUBJ_STRING {0x70,0xE2,0x89,0xA1,0x70,0x00}
#define PEP_SUBJ_BYTELEN 5
#endif
#include "platform.h"
#ifdef WIN32
@ -324,6 +330,24 @@ static inline bool _identity_me(
return identity->user_id && strcmp(identity->user_id, PEP_OWN_USERID) == 0;
}
// size is the length of the bytestr that's coming in. This is really only intended
// for comparing two full strings. If charstr's length is different from bytestr_size,
// we'll return a non-zero value.
static inline int _unsigned_signed_strcmp(const unsigned char* bytestr, const char* charstr, int bytestr_size) {
int charstr_len = strlen(charstr);
if (charstr_len != bytestr_size)
return -1; // we don't actually care except that it's non-zero
return memcmp(bytestr, charstr, bytestr_size);
}
// This is just a horrible example of C type madness. UTF-8 made me do it.
static inline char* _pep_subj_copy() {
unsigned char pepstr[] = PEP_SUBJ_STRING;
void* retval = calloc(1, sizeof(unsigned char)*PEP_SUBJ_BYTELEN + 1);
memcpy(retval, pepstr, PEP_SUBJ_BYTELEN);
return (char*)retval;
}
#ifdef DEBUG_ERRORSTACK
PEP_STATUS session_add_error(PEP_SESSION session, const char* file, unsigned line, PEP_STATUS status);
#define ADD_TO_LOG(status) session_add_error(session, __FILE__, __LINE__, (status))


+ 4
- 1
test/pEp_subject_received_test.cc View File

@ -14,7 +14,7 @@ using namespace std;
int main(int argc, char** argv) {
cout << "\n*** check that pEp subject is handled properly in received mails ***\n\n";
cout << "\n*** check that pp subject is handled properly in received mails ***\n\n";
PEP_SESSION session;
@ -119,6 +119,7 @@ int main(int argc, char** argv) {
cout << "-----------------------------------------------------------------------" << endl;
cout << "Test 3: Encrypted mail, pEp as actual subject, no subject in body text." << endl;
cout << "FIXME: need tp make new encrypted mail for this." << endl;
cout << "-----------------------------------------------------------------------" << endl;
msg_ptr = nullptr;
@ -151,6 +152,7 @@ int main(int argc, char** argv) {
cout << "-----------------------------------------------------------------------" << endl;
cout << "Test 4: Encrypted mail, pEp as actual subject, pEp subject in body text." << endl;
cout << "FIXME: need tp make new encrypted mail for this." << endl;
cout << "-----------------------------------------------------------------------" << endl;
msg_ptr = nullptr;
@ -183,6 +185,7 @@ int main(int argc, char** argv) {
cout << "-------------------------------------------------------------------------" << endl;
cout << "Test 5: Unencrypted variant where pEp in the subject line is the subject." << endl;
cout << "FIXME: need tp make new mail for this." << endl;
cout << "-------------------------------------------------------------------------" << endl;
msg_ptr = nullptr;


Loading…
Cancel
Save