Browse Source

merge Release_2.1

IOSAD-186
buff 2 years ago
parent
commit
9b7b4b6d40
7 changed files with 101 additions and 39 deletions
  1. +62
    -22
      src/key_reset.c
  2. +2
    -1
      src/key_reset.h
  3. +2
    -2
      src/pEpEngine.h
  4. +19
    -2
      sync/gen_statemachine.ysl2
  5. +1
    -1
      sync/sync.fsm
  6. +10
    -6
      test/src/KeyResetMessageTest.cc
  7. +5
    -5
      test/src/LotsOfKeysTest.cc

+ 62
- 22
src/key_reset.c View File

@ -611,7 +611,7 @@ PEP_STATUS receive_key_reset(PEP_SESSION session,
// from the user
if (!sender_own_key) {
// Clear all info (ALSO REMOVES OLD KEY RIGHT NOW!!!)
status = key_reset(session, old_fpr, curr_ident);
status = key_reset(session, old_fpr, curr_ident, true);
if (status != PEP_STATUS_OK)
return status;
@ -911,7 +911,7 @@ DYNAMIC_API PEP_STATUS key_reset_identity(
if (!session || !ident || (ident && (EMPTYSTR(ident->user_id) || EMPTYSTR(ident->address))))
return PEP_ILLEGAL_VALUE;
return key_reset(session, fpr, ident);
return key_reset(session, fpr, ident, false);
}
DYNAMIC_API PEP_STATUS key_reset_user(
@ -930,13 +930,13 @@ DYNAMIC_API PEP_STATUS key_reset_user(
if (is_me(session, input_ident) && EMPTYSTR(fpr))
return PEP_ILLEGAL_VALUE;
PEP_STATUS status = key_reset(session, fpr, input_ident);
PEP_STATUS status = key_reset(session, fpr, input_ident, false);
free_identity(input_ident);
return status;
}
DYNAMIC_API PEP_STATUS key_reset_all_own_keys(PEP_SESSION session) {
return key_reset(session, NULL, NULL);
return key_reset(session, NULL, NULL, false);
}
static PEP_STATUS _dup_grouped_only(identity_list* idents, identity_list** filtered) {
@ -1281,10 +1281,46 @@ pEp_free:
return status;
}
static PEP_STATUS _key_reset_partner_by_address(PEP_SESSION session,
pEp_identity* ident) {
if (!ident->address)
return PEP_ILLEGAL_VALUE;
if (is_me(session, ident))
return PEP_ILLEGAL_VALUE;
identity_list* id_list = NULL;
PEP_STATUS status = get_identities_by_address(session, ident->address, &id_list);
if (status != PEP_STATUS_OK && status != PEP_CANNOT_FIND_IDENTITY)
return status;
else
status = PEP_STATUS_OK;
// won't hurt to do it this way; this is correct, anyway. Maybe it's still default
// for the user_id even if the address is not in the DB, so... yeah.
if (!id_list)
return key_reset(session, NULL, ident, true);
identity_list* curr;
for (curr = id_list; curr && curr->ident; curr = curr->next) {
status = key_reset(session, NULL, curr->ident, true);
if (status != PEP_STATUS_OK)
goto pEp_free;
}
pEp_free:
free_identity_list(id_list);
return status;
}
PEP_STATUS key_reset(
PEP_SESSION session,
const char* key_id,
pEp_identity* ident
pEp_identity* ident,
bool no_recurse
)
{
if (!session || (ident && EMPTYSTR(ident->user_id)))
@ -1336,7 +1372,7 @@ PEP_STATUS key_reset(
for (curr_key = keys; curr_key && curr_key->value; curr_key = curr_key->next) {
// FIXME: Is the ident really necessary?
status = key_reset(session, curr_key->value, tmp_ident);
status = key_reset(session, curr_key->value, tmp_ident, false);
if (status != PEP_STATUS_OK && status != PEP_CANNOT_FIND_IDENTITY)
break;
else
@ -1529,22 +1565,26 @@ PEP_STATUS key_reset(
}
} // end is_own_private
else {
// if it's mistrusted, make it not be so.
bool mistrusted_key = false;
is_mistrusted_key(session, fpr_copy, &mistrusted_key);
if (mistrusted_key)
delete_mistrusted_key(session, fpr_copy);
if (tmp_ident->user_id)
status = clear_trust_info(session, tmp_ident->user_id, fpr_copy);
// This is a public key (or a private key that isn't ours, which means
// we want it gone anyway)
//
// Delete this key from the keyring.
// FIXME: when key election disappears, so should this!
status = delete_keypair(session, fpr_copy);
if (!no_recurse && EMPTYSTR(key_id))
_key_reset_partner_by_address(session, tmp_ident);
else {
// if it's mistrusted, make it not be so.
bool mistrusted_key = false;
is_mistrusted_key(session, fpr_copy, &mistrusted_key);
if (mistrusted_key)
delete_mistrusted_key(session, fpr_copy);
if (tmp_ident->user_id)
status = clear_trust_info(session, tmp_ident->user_id, fpr_copy);
// This is a public key (or a private key that isn't ours, which means
// we want it gone anyway)
//
// Delete this key from the keyring.
// FIXME: when key election disappears, so should this!
status = delete_keypair(session, fpr_copy);
}
}
// REGARDLESS OF WHO OWNS THE KEY, WE NOW NEED TO REMOVE IT AS A DEFAULT.


+ 2
- 1
src/key_reset.h View File

@ -128,7 +128,8 @@ DYNAMIC_API PEP_STATUS key_reset_own_grouped_keys(PEP_SESSION session);
PEP_STATUS key_reset(
PEP_SESSION session,
const char* fpr,
pEp_identity* ident
pEp_identity* ident,
bool no_recurse
);
/*


+ 2
- 2
src/pEpEngine.h View File

@ -21,10 +21,10 @@ extern "C" {
// RELEASE version this targets
// (string: major.minor.patch)
#define PEP_ENGINE_VERSION "2.1.9"
#define PEP_ENGINE_VERSION "2.1.11"
#define PEP_ENGINE_VERSION_MAJOR 2
#define PEP_ENGINE_VERSION_MINOR 1
#define PEP_ENGINE_VERSION_PATCH 9
#define PEP_ENGINE_VERSION_PATCH 11
#define PEP_ENGINE_VERSION_RC 0


+ 19
- 2
sync/gen_statemachine.ysl2 View File

@ -415,6 +415,16 @@ tstylesheet {
if (!(session && fsm > None && message_type > None))
return PEP_ILLEGAL_VALUE;
||
if "fsm/message[@security='ignore']" {
|
|> // ignore
|> switch (message_type) {
for "fsm/message[@security='ignore']" {
|>> case «../@name»_PR_«yml:mixedCase(@name)»:
|>>> return PEP_STATUS_OK;
}
|> }
}
if "fsm/message[@ratelimit>0]" {
||
@ -506,7 +516,7 @@ tstylesheet {
break;
// these go anycast; previously used address is sticky (unicast)
`` for "fsm/message[@type='anycast']" |>> case «../@name»_PR_«yml:mixedCase(@name)»:
`` for "fsm/message[@type='anycast' and @security!='ignore']" |>> case «../@name»_PR_«yml:mixedCase(@name)»:
// if we have a comm_partner fixed send it there
if (session->«yml:lcase(@name)»_state.comm_partner.identity) {
pEp_identity *channel = identity_dup(session->«yml:lcase(@name)»_state.comm_partner.identity);
@ -1162,7 +1172,7 @@ tstylesheet {
||
}
for "message[@security!='unencrypted' and @security!='untrusted']" {
for "message[@security!='unencrypted' and @security!='untrusted' and @security!='ignore']" {
if "position()=1" |>> // these messages must come through a trusted channel
||
case «../@name»_PR_«yml:mixedCase(@name)»:
@ -1182,6 +1192,13 @@ tstylesheet {
||
}
for "message[@security='ignore']"
||
case «../@name»_PR_«yml:mixedCase(@name)»:
free_«../../@name»_message(msg);
return PEP_STATUS_OK;
||
||
default:
status = PEP_«yml:ucase(ancestor::protocol/@name)»_ILLEGAL_MESSAGE;


+ 1
- 1
sync/sync.fsm View File

@ -685,7 +685,7 @@ protocol Sync 1 {
// decrypt_message() to mark a previously computed rating. It is only
// valid when signed with an own key.
message ReceiverRating 22, security=unencrypted {
message ReceiverRating 22, security=ignore {
field Rating rating;
}
}


+ 10
- 6
test/src/KeyResetMessageTest.cc View File

@ -1,3 +1,5 @@
#pragma clang diagnostic push
#pragma ide diagnostic ignored "UnreachableCode"
// This file is under GNU General Public License 3.0
// see LICENSE.txt
@ -325,7 +327,7 @@ TEST_F(KeyResetMessageTest, check_reset_key_and_notify) {
);
ASSERT_EQ(int_result , SQLITE_OK);
status = key_reset(session, alice_fpr, from_ident);
status = key_reset(session, alice_fpr, from_ident, true);
ASSERT_EQ(status , PEP_STATUS_OK);
ASSERT_GT(m_queue.size(), 0);
status = myself(session, from_ident);
@ -487,7 +489,7 @@ TEST_F(KeyResetMessageTest, revoke_and_check_receive_message) {
PEP_STATUS status = set_own_key(session, me, "8E8D2381AE066ABE1FEE509821BA977CA4728718");
ASSERT_EQ(status, PEP_STATUS_OK);
status = key_reset(session, "8E8D2381AE066ABE1FEE509821BA977CA4728718", me);
status = key_reset(session, "8E8D2381AE066ABE1FEE509821BA977CA4728718", me, true);
ASSERT_EQ(status, PEP_STATUS_OK);
status = myself(session, me);
ASSERT_NE(me->fpr, nullptr);
@ -524,7 +526,7 @@ TEST_F(KeyResetMessageTest, check_receive_message_to_revoked_key_from_unknown) {
ASSERT_STRCASEEQ(from_ident->fpr, alice_fpr);
ASSERT_TRUE(from_ident->me);
status = key_reset(session, alice_fpr, from_ident);
status = key_reset(session, alice_fpr, from_ident, true);
ASSERT_EQ(status , PEP_STATUS_OK);
m_queue.clear();
@ -589,7 +591,7 @@ TEST_F(KeyResetMessageTest, check_receive_message_to_revoked_key_from_contact) {
// FIXME: longer term we need to fix the test, but the key attached to the message below has expired, so for now, we give her a new key
slurp_and_import_key(session, "test_keys/pub/pep-test-gabrielle-0xE203586C_pub.asc");
status = key_reset(session, alice_fpr, from_ident);
status = key_reset(session, alice_fpr, from_ident, true);
ASSERT_EQ(status , PEP_STATUS_OK);
ASSERT_EQ(m_queue.size() , 0);
m_queue.clear();
@ -636,10 +638,10 @@ TEST_F(KeyResetMessageTest, check_multiple_resets_single_key) {
ASSERT_STRCASEEQ(from_ident->fpr, alice_fpr);
ASSERT_TRUE(from_ident->me);
status = key_reset(session, NULL, NULL);
status = key_reset(session, NULL, NULL, false);
ASSERT_EQ(status , PEP_STATUS_OK);
status = key_reset(session, NULL, NULL);
status = key_reset(session, NULL, NULL, false);
ASSERT_EQ(status , PEP_STATUS_OK);
status = myself(session, from_ident);
@ -3198,3 +3200,5 @@ TEST_F(KeyResetMessageTest, codec_test) {
free_identity(ident2);
free_keyreset_command_list(il);
}
#pragma clang diagnostic pop

+ 5
- 5
test/src/LotsOfKeysTest.cc View File

@ -59,10 +59,10 @@ ggsave("/tmp/pep-benchmark.pdf", width = 4, height = 4)
#define REPITIONS 3
// 10^x, x=0.5.. step 0.5.
const int exp[] = { 3, 10, 31, 100, 316, 1000, 3162, 10000, 31622,
const int _exp[] = { 3, 10, 31, 100, 316, 1000, 3162, 10000, 31622,
100000, 316227, 1000000, 3162277, 10000000,
31622776, 100000000, 316227766, 1000000000 };
#define BENCHMARKS (sizeof(exp) / sizeof(exp[0]))
#define BENCHMARKS (sizeof(_exp) / sizeof(_exp[0]))
struct stats {
FILE *fp;
@ -257,10 +257,10 @@ TEST_F(LotsOfKeysTest, check) {
}
bool do_benchmark = false;
for (int i = 0; i < sizeof(exp) / sizeof(exp[0]); i ++) {
if (key + 1 == exp[i]) {
for (int i = 0; i < sizeof(_exp) / sizeof(_exp[0]); i ++) {
if (key + 1 == _exp[i]) {
do_benchmark = true;
} else if (key + 1 < exp[i]) {
} else if (key + 1 < _exp[i]) {
break;
}
}


Loading…
Cancel
Save