Browse Source

ENGINE-360: Let's try again, shall we? Lots of fixes related to address-only identities.

doc_update_sequoia
Krista Bennett 4 years ago
parent
commit
cfea00fcef
5 changed files with 72 additions and 182 deletions
  1. +39
    -10
      src/keymanagement.c
  2. +18
    -18
      src/message_api.c
  3. +1
    -1
      test/apple_mail_test.cc
  4. +12
    -151
      test/message_api_test.cc
  5. +2
    -2
      test/new_update_id_and_myself_test.cc

+ 39
- 10
src/keymanagement.c View File

@ -639,19 +639,19 @@ DYNAMIC_API PEP_STATUS update_identity(
snprintf(identity->user_id, strlen(identity->address) + 6,
"TOFU_%s", identity->address);
free(identity->fpr);
identity->fpr = NULL;
identity->comm_type = PEP_ct_unknown;
// * We've already checked and retrieved
// any applicable temporary identities above. If we're
// here, none of them fit.
status = elect_pubkey(session, identity);
// * call set_identity() to store
if (identity->fpr)
status = get_key_rating(session, identity->fpr, &identity->comm_type);
// * call set_identity() to store
status = set_identity(session, identity);
if (status == PEP_STATUS_OK) {
elect_pubkey(session, identity);
}
}
}
else {
@ -688,8 +688,37 @@ DYNAMIC_API PEP_STATUS update_identity(
if (stored_ident)
status = prepare_updated_identity(session, identity,
stored_ident, false);
else // too little info
status = PEP_CANNOT_FIND_IDENTITY;
else {
// too little info. BUT. We see if we can find a key; if so, we create a
// temp identity, look for a key, and store.
// create temporary identity, store it, and Return this
// This means TOFU_ user_id
identity->user_id = calloc(1, strlen(identity->address) + 6);
if (!identity->user_id)
return PEP_OUT_OF_MEMORY;
snprintf(identity->user_id, strlen(identity->address) + 6,
"TOFU_%s", identity->address);
identity->username = strdup(identity->address);
if (!identity->address)
return PEP_OUT_OF_MEMORY;
free(identity->fpr);
identity->fpr = NULL;
identity->comm_type = PEP_ct_unknown;
status = elect_pubkey(session, identity);
if (identity->fpr)
status = get_key_rating(session, identity->fpr, &identity->comm_type);
// * call set_identity() to store
status = set_identity(session, identity);
}
}
// FIXME: This is legacy. I presume it's a notification for the caller...


+ 18
- 18
src/message_api.c View File

@ -1524,7 +1524,7 @@ DYNAMIC_API PEP_STATUS encrypt_message(
_il->ident->comm_type = PEP_ct_key_not_found;
_status = PEP_STATUS_OK;
}
if (!has_pep_user)
if (!has_pep_user && !EMPTYSTR(_il->ident->user_id))
is_pep_user(session, _il->ident, &has_pep_user);
}
else
@ -1556,7 +1556,7 @@ DYNAMIC_API PEP_STATUS encrypt_message(
_il->ident->comm_type = PEP_ct_key_not_found;
_status = PEP_STATUS_OK;
}
if (!has_pep_user)
if (!has_pep_user && !EMPTYSTR(_il->ident->user_id))
is_pep_user(session, _il->ident, &has_pep_user);
}
else
@ -1587,7 +1587,7 @@ DYNAMIC_API PEP_STATUS encrypt_message(
_il->ident->comm_type = PEP_ct_key_not_found;
_status = PEP_STATUS_OK;
}
if (!has_pep_user)
if (!has_pep_user && !EMPTYSTR(_il->ident->user_id))
is_pep_user(session, _il->ident, &has_pep_user);
}
else
@ -3451,21 +3451,21 @@ DYNAMIC_API PEP_STATUS MIME_encrypt_message(
if (status != PEP_STATUS_OK)
GOTO(pep_error);
}
//
// // Own identities can be retrieved here where they would otherwise
// // fail because we lack all other information. This is ok and even
// // desired. FIXME: IS it?
// status = update_identity_recip_list(session, tmp_msg->to);
// if (status != PEP_STATUS_OK)
// GOTO(pep_error);
//
// status = update_identity_recip_list(session, tmp_msg->cc);
// if (status != PEP_STATUS_OK)
// GOTO(pep_error);
//
// status = update_identity_recip_list(session, tmp_msg->bcc);
// if (status != PEP_STATUS_OK)
// GOTO(pep_error);
// Own identities can be retrieved here where they would otherwise
// fail because we lack all other information. This is ok and even
// desired. FIXME: IS it?
status = update_identity_recip_list(session, tmp_msg->to);
if (status != PEP_STATUS_OK)
GOTO(pep_error);
status = update_identity_recip_list(session, tmp_msg->cc);
if (status != PEP_STATUS_OK)
GOTO(pep_error);
status = update_identity_recip_list(session, tmp_msg->bcc);
if (status != PEP_STATUS_OK)
GOTO(pep_error);
// This isn't incoming, though... so we need to reverse the direction
tmp_msg->dir = PEP_dir_outgoing;


+ 1
- 1
test/apple_mail_test.cc View File

@ -37,7 +37,7 @@ int main(int argc, char** argv) {
me->me = true;
PEP_STATUS status = myself(session, me);
pEp_identity * you = new_identity("pep.test.apple@pep-project.org", NULL, "TOFU_pep.test.apple@pep-project.org", "pEp Test Recipient");
pEp_identity * you = new_identity("pep.test.apple@pep-project.org", NULL, "pep.test.apple@pep-project.org", "pEp Apple Test");
you->me = false;
status = update_identity(session, you);


+ 12
- 151
test/message_api_test.cc View File

@ -9,160 +9,10 @@
#include <assert.h>
#include "mime.h"
#include "message_api.h"
#include "test_util.h"
using namespace std;
void test_MIME_decrypt_message()
{
static const std::string private_key =
"-----BEGIN PGP PRIVATE KEY BLOCK-----\n"
"\n"
"lQOmBFpCxkEBCCC8ugYsWOsv966JOl5Ahdw6YiobbU9peFLV8aMBOG+oNIPs3BQj\n"
"u3FUugkVqA5In93oqVgNZ2LU6Y/RWldN+Pc4IMf6qSZnTBj/1ffBjuqAow1hPEYV\n"
"354LNYoQtJXioY0X8FjRgt+NoBPphRbo+XJ0uIQckJey6uvvtukEZkMLM1ur1aID\n"
"9biJZ7yXtJM7KxN5792Vo2gGp/1hlFW6SfM7E0g60L5DT8C/BsYeKtMmxKNZngo6\n"
"ZBxLDAcxMcT5UpRW79B34pTINZAEsvLeT7TLajzqP/OggUrFkkwLr3KJk09aFF+6\n"
"TN6CI2fDdSqdoPVEgNrZE9zFqAgVWOdhLOHRpXgt7wARAQABAAgZATpqsN4xRaIk\n"
"giMdmujkGoMqB/ypoCOW0mqcp3ThESSqWR/Dh8n//k+poHj0Atf7fzie6JNsKruM\n"
"Yo3mdIzyuuxHsONp6xEtNnkDgEB4WTb2btQQFrNaWXNTPzGVqiBoBShcw5xI7SiG\n"
"CKaDlCePbaAHyBHO0uzBdVFo6czqkceXSJ+hNDY7xbURbkgIA5SGJ+8cssmcKKoc\n"
"LDY34S3Pu0gG3+K6gSedYaHAqVVQn8dmEitvDFQ96sTNIpPiMp5Tc+/8UXziF91f\n"
"XRrXYX9o3nkCvz01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1kLeS6lTYeaKORa7JFRc776rkWV//P1Soc\n"
"nW2byeBxNxOmdNXlNsA6Gg8O4rn3rxEgBZlsOYUG1ZcPZZu8kNFkLTYP+mgFIP3I\n"
"izn858IbnNFm0HjRMGiS+zip2r/rgbniIhLQ2l7/BBCL+2x0+Ww5I/el6A7k+y2X\n"
"3xazBVOQfpPl9BgMdsuO0BBlN5RpbTfE8TVpWneeamAuRJh7ArApbAS508Thw7Sj\n"
"8iLKXj5yScAEC2WO9ZsHqJ/RN3VyhCCI0u3Y75wB3qfcroZUlwvQb/WfH8/vHr2O\n"
"E72YoprbNOmRFZ7LZkRX56URRn2JASMEGAEIAAkFAlpCxkECGwwACgkQr2Mun8eZ\n"
"t9RozQggkb/Lb08g4w99CcXq6hV28D5bOHjiEx4XNdkeLVExhfk1zgQ9lf4rjyb2\n"
"ox+e3Dc5S590NoYg/35vd/QWPsg1JiCvAu296lzOLtIiTAI1KGUJdbsLxRIduOU7\n"
"6n/KVxRG4w4kJqpbu+UzBY7KtDbWzapJx8v0sdsTOVxg7kFxvYtra5TRaPfce4EX\n"
"ox2V2HPhtFNSILH8Jqh/R0PV5RRbNFHZA4cKXkBJMw3BcpbpXeLCXiD6P3FNVSKh\n"
"Rkd3JY0XJhwbvGPCRWkobtxkieZe0bCmKu8+gw0Zqm2QNA7J6iMT4rMZWH9k7lpp\n"
"okyt7GheXlwKEtVQSAcH/NalK9Q+ckaQttA=\n"
"=KACn\n"
"-----END PGP PRIVATE KEY BLOCK-----\n"
"\n";
static const std::string mimetext =
"To: denden@peptest.ch\r\n"
"From: Lars Rohwedder <roker@pep-project.org>\r\n"
"Subject: Test for ENGINE-322\r\n"
"Message-ID: <4b2d328c-b284-e359-1c2c-fe136358b8a6@pep-project.org>\r\n"
"Date: Thu, 28 Dec 2017 22:00:47 +0100\r\n"
"User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:52.0)\r\n"
" Gecko/20100101 Thunderbird/52.5.0\r\n"
"MIME-Version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UQKpJRzue2lWsfESLxIVeB+vmbg2zU3PflCmMIsRNh2US7vZj2WdgqSqz\r\n"
"wR2eTG4MgPVy4iiGOVT2JWS5t+KXm3kwUZTy9Twi6P1ebNm/B8KQwlutssdWip2q\r\n"
"hON1aFYa4L601zrHgow592PdBkRPQZGiXNHffCvHgsxBHsj4G4JWZhmIkEK/cIWl\r\n"
"RanlZdQG6UPHkoUomh7hauUUgcYe4FWt4NBKdiba36Y=\r\n"
"=1lFj\r\n"
"-----END PGP MESSAGE-----\r\n"
"\r\n";
PEP_SESSION session;
PEP_STATUS status1 = init(&session);
assert(status1 == PEP_STATUS_OK);
assert(session);
// import secret key
identity_list* pk = NULL;
status1 = import_key( session, private_key.c_str(), private_key.size(), &pk );
assert(status1 == PEP_STATUS_OK);
std::cout << "Imported " << identity_list_length(pk) << " private key(s)." << endl;
char* plaintext = nullptr;
stringlist_t* keys_used = nullptr;
PEP_rating rating;
PEP_decrypt_flags_t dec_flags;
PEP_STATUS status2 = MIME_decrypt_message(session, mimetext.c_str(), mimetext.length(),
&plaintext, &keys_used, &rating, &dec_flags);
std::cout << "MIME_decrypt_message returned " << std::dec << status2 << std::hex << " (0x" << status2 << ")" << std::dec << endl;
// We have no public key, so we cannot, in fact, VERIFY the message. SO cannot be PEP_STATUS_OK.
assert(status2 == PEP_DECRYPTED);
assert(plaintext);
pEp_free(plaintext);
identity_list* il = pk;
while(il)
{
std::cout << "Delete test key \"" << il->ident->fpr << "\"" << endl;
delete_keypair( session, il->ident->fpr );
il = il->next;
}
free_identity_list(pk);
}
int main() {
cout << "\n*** message_api_test ***\n\n";
@ -174,6 +24,17 @@ int main() {
assert(session);
cout << "init() completed.\n";
cout << "Importing Alice's key " << endl;
const string alice_pub_key = slurp("test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
const string alice_priv_key = slurp("test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");
const string bob_pub_key = slurp("test_keys/pub/pep-test-bob-0xC9C2EE39_pub.asc");
PEP_STATUS status0 = import_key(session, alice_pub_key.c_str(), alice_pub_key.size(), NULL);
assert(status0 == PEP_STATUS_OK);
status0 = import_key(session, alice_priv_key.c_str(), alice_priv_key.size(), NULL);
assert(status0 == PEP_STATUS_OK);
status0 = import_key(session, bob_pub_key.c_str(), bob_pub_key.size(), NULL);
assert(status0 == PEP_STATUS_OK);
// message_api test code
cout << "creating message…\n";


+ 2
- 2
test/new_update_id_and_myself_test.cc View File

@ -441,9 +441,9 @@ int main() {
bella = new_identity(bella_address, NULL, NULL, NULL);
status = update_identity(session, bella);
assert(status != PEP_STATUS_OK);
assert(status == PEP_STATUS_OK);
cout << "PASS: update_identity() correctly failed with no matching records (too little info)" << endl << endl;
// cout << "PASS: update_identity() correctly failed with no matching records (too little info)" << endl << endl;
cout << "****************************************************************************************" << endl;
cout << "* III: key election " << endl;


Loading…
Cancel
Save