|
|
|
@ -14,6 +14,7 @@
|
|
|
|
|
|
|
|
|
|
#include "pEp_internal.h"
|
|
|
|
|
#include "keymanagement.h"
|
|
|
|
|
#include "KeySync_fsm.h"
|
|
|
|
|
|
|
|
|
|
#include "blacklist.h"
|
|
|
|
|
|
|
|
|
@ -42,6 +43,7 @@ static bool key_matches_address(PEP_SESSION session, const char* address,
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Does not return PASSPHRASE errors
|
|
|
|
|
PEP_STATUS elect_pubkey(
|
|
|
|
|
PEP_SESSION session, pEp_identity * identity, bool check_blacklist
|
|
|
|
|
)
|
|
|
|
@ -109,10 +111,13 @@ PEP_STATUS elect_pubkey(
|
|
|
|
|
// own_must_contain_private is usually true when calling;
|
|
|
|
|
// we only set it to false when we have the idea of
|
|
|
|
|
// possibly having an own pubkey that we need to check on its own
|
|
|
|
|
// N.B. Checked for PASSPHRASE errors - will now return them always
|
|
|
|
|
// False value of "renew_private" prevents their possibility, though.
|
|
|
|
|
static PEP_STATUS validate_fpr(PEP_SESSION session,
|
|
|
|
|
pEp_identity* ident,
|
|
|
|
|
bool check_blacklist,
|
|
|
|
|
bool own_must_contain_private) {
|
|
|
|
|
bool own_must_contain_private,
|
|
|
|
|
bool renew_private) {
|
|
|
|
|
|
|
|
|
|
PEP_STATUS status = PEP_STATUS_OK;
|
|
|
|
|
|
|
|
|
@ -124,6 +129,7 @@ static PEP_STATUS validate_fpr(PEP_SESSION session,
|
|
|
|
|
bool has_private = false;
|
|
|
|
|
status = contains_priv_key(session, fpr, &has_private);
|
|
|
|
|
|
|
|
|
|
// N.B. Will not contain PEP_PASSPHRASE related returns here
|
|
|
|
|
if (ident->me && own_must_contain_private) {
|
|
|
|
|
if (status != PEP_STATUS_OK || !has_private)
|
|
|
|
|
return PEP_KEY_UNSUITABLE;
|
|
|
|
@ -176,6 +182,7 @@ static PEP_STATUS validate_fpr(PEP_SESSION session,
|
|
|
|
|
bool revoked, expired;
|
|
|
|
|
bool blacklisted = false;
|
|
|
|
|
|
|
|
|
|
// Should not need to decrypt key material
|
|
|
|
|
status = key_revoked(session, fpr, &revoked);
|
|
|
|
|
|
|
|
|
|
if (status != PEP_STATUS_OK) {
|
|
|
|
@ -185,11 +192,12 @@ static PEP_STATUS validate_fpr(PEP_SESSION session,
|
|
|
|
|
if (!revoked) {
|
|
|
|
|
time_t exp_time = (ident->me ?
|
|
|
|
|
time(NULL) + (7*24*3600) : time(NULL));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Should not need to decrypt key material
|
|
|
|
|
status = key_expired(session, fpr,
|
|
|
|
|
exp_time,
|
|
|
|
|
&expired);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert(status == PEP_STATUS_OK);
|
|
|
|
|
if (status != PEP_STATUS_OK)
|
|
|
|
|
return status;
|
|
|
|
@ -205,7 +213,9 @@ static PEP_STATUS validate_fpr(PEP_SESSION session,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ident->me && has_private &&
|
|
|
|
|
// Renew key if it's expired, our own, has a private part,
|
|
|
|
|
// isn't too weak, and we didn't say "DON'T DO THIS"
|
|
|
|
|
if (renew_private && ident->me && has_private &&
|
|
|
|
|
(ct >= PEP_ct_strong_but_unconfirmed) &&
|
|
|
|
|
!revoked && expired) {
|
|
|
|
|
// extend key
|
|
|
|
@ -213,6 +223,9 @@ static PEP_STATUS validate_fpr(PEP_SESSION session,
|
|
|
|
|
status = renew_key(session, fpr, ts);
|
|
|
|
|
free_timestamp(ts);
|
|
|
|
|
|
|
|
|
|
if (status == PEP_PASSPHRASE_REQUIRED || status == PEP_WRONG_PASSPHRASE)
|
|
|
|
|
return status;
|
|
|
|
|
|
|
|
|
|
if (status == PEP_STATUS_OK) {
|
|
|
|
|
// if key is valid (second check because pEp key might be extended above)
|
|
|
|
|
// Return fpr
|
|
|
|
@ -341,6 +354,11 @@ PEP_STATUS get_user_default_key(PEP_SESSION session, const char* user_id,
|
|
|
|
|
// Also, we presume that if the stored_identity was sent in
|
|
|
|
|
// without an fpr, there wasn't one in the trust DB for this
|
|
|
|
|
// identity.
|
|
|
|
|
//
|
|
|
|
|
// Will now NOT return passphrase errors, as we tell
|
|
|
|
|
// validate_fpr NOT to renew it. And we specifically suppress them
|
|
|
|
|
// with "PEP_KEY_UNSUITABLE"
|
|
|
|
|
//
|
|
|
|
|
PEP_STATUS get_valid_pubkey(PEP_SESSION session,
|
|
|
|
|
pEp_identity* stored_identity,
|
|
|
|
|
bool* is_identity_default,
|
|
|
|
@ -360,19 +378,28 @@ PEP_STATUS get_valid_pubkey(PEP_SESSION session,
|
|
|
|
|
PEP_STATUS first_reject_status = PEP_KEY_NOT_FOUND;
|
|
|
|
|
|
|
|
|
|
char* stored_fpr = stored_identity->fpr;
|
|
|
|
|
|
|
|
|
|
// Input: stored identity retrieved from database
|
|
|
|
|
// if stored identity contains a default key
|
|
|
|
|
if (!EMPTYSTR(stored_fpr)) {
|
|
|
|
|
status = validate_fpr(session, stored_identity, check_blacklist, true);
|
|
|
|
|
if (status == PEP_STATUS_OK && !EMPTYSTR(stored_identity->fpr)) {
|
|
|
|
|
*is_identity_default = *is_address_default = true;
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
else if (status != PEP_KEY_NOT_FOUND) {
|
|
|
|
|
first_reject_status = status;
|
|
|
|
|
first_reject_comm_type = stored_identity->comm_type;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Won't ask for passphrase, won't return PASSPHRASE status
|
|
|
|
|
// Because of non-renewal
|
|
|
|
|
status = validate_fpr(session, stored_identity, check_blacklist, true, false);
|
|
|
|
|
switch (status) {
|
|
|
|
|
case PEP_STATUS_OK:
|
|
|
|
|
if (!EMPTYSTR(stored_identity->fpr)) {
|
|
|
|
|
*is_identity_default = *is_address_default = true;
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case PEP_KEY_NOT_FOUND:
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
first_reject_status = status;
|
|
|
|
|
first_reject_comm_type = stored_identity->comm_type;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// if no valid default stored identity key found
|
|
|
|
|
free(stored_identity->fpr);
|
|
|
|
|
stored_identity->fpr = NULL;
|
|
|
|
@ -383,24 +410,38 @@ PEP_STATUS get_valid_pubkey(PEP_SESSION session,
|
|
|
|
|
if (!EMPTYSTR(user_fpr)) {
|
|
|
|
|
// There exists a default key for user, so validate
|
|
|
|
|
stored_identity->fpr = user_fpr;
|
|
|
|
|
status = validate_fpr(session, stored_identity, check_blacklist, true);
|
|
|
|
|
if (status == PEP_STATUS_OK && stored_identity->fpr) {
|
|
|
|
|
*is_user_default = true;
|
|
|
|
|
*is_address_default = key_matches_address(session,
|
|
|
|
|
stored_identity->address,
|
|
|
|
|
stored_identity->fpr);
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
else if (status != PEP_KEY_NOT_FOUND && first_reject_status != PEP_KEY_NOT_FOUND) {
|
|
|
|
|
first_reject_status = status;
|
|
|
|
|
first_reject_comm_type = stored_identity->comm_type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Won't ask for passphrase, won't return PASSPHRASE status
|
|
|
|
|
// Because of non-renewal
|
|
|
|
|
status = validate_fpr(session, stored_identity, check_blacklist, true, false);
|
|
|
|
|
|
|
|
|
|
switch (status) {
|
|
|
|
|
case PEP_STATUS_OK:
|
|
|
|
|
if (!EMPTYSTR(stored_identity->fpr)) {
|
|
|
|
|
*is_user_default = true;
|
|
|
|
|
*is_address_default = key_matches_address(session,
|
|
|
|
|
stored_identity->address,
|
|
|
|
|
stored_identity->fpr);
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case PEP_KEY_NOT_FOUND:
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
if (first_reject_status != PEP_KEY_NOT_FOUND) {
|
|
|
|
|
first_reject_status = status;
|
|
|
|
|
first_reject_comm_type = stored_identity->comm_type;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
status = elect_pubkey(session, stored_identity, check_blacklist);
|
|
|
|
|
if (status == PEP_STATUS_OK) {
|
|
|
|
|
if (!EMPTYSTR(stored_identity->fpr))
|
|
|
|
|
validate_fpr(session, stored_identity, false, true); // blacklist already filtered of needed
|
|
|
|
|
if (!EMPTYSTR(stored_identity->fpr)) {
|
|
|
|
|
// Won't ask for passphrase, won't return PASSPHRASE status
|
|
|
|
|
// Because of non-renewal
|
|
|
|
|
status = validate_fpr(session, stored_identity, false, true, false); // blacklist already filtered of needed
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (status != PEP_KEY_NOT_FOUND && first_reject_status != PEP_KEY_NOT_FOUND) {
|
|
|
|
|
first_reject_status = status;
|
|
|
|
@ -428,6 +469,11 @@ PEP_STATUS get_valid_pubkey(PEP_SESSION session,
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// should never happen, but we will MAKE sure
|
|
|
|
|
if (PASS_ERROR(status))
|
|
|
|
|
status = PEP_KEY_UNSUITABLE; // renew it on your own time, baby
|
|
|
|
|
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -466,6 +512,11 @@ static void adjust_pEp_trust_status(PEP_SESSION session, pEp_identity* identity)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// NEVER called on an own identity.
|
|
|
|
|
// But we also make sure get_valid_pubkey
|
|
|
|
|
// and friends NEVER return with a password error.
|
|
|
|
|
// (get_valid_pubkey tells validate_fpr not to try renewal)
|
|
|
|
|
// Will not return PASSPHRASE errors.
|
|
|
|
|
static PEP_STATUS prepare_updated_identity(PEP_SESSION session,
|
|
|
|
|
pEp_identity* return_id,
|
|
|
|
|
pEp_identity* stored_ident,
|
|
|
|
@ -483,29 +534,31 @@ static PEP_STATUS prepare_updated_identity(PEP_SESSION session,
|
|
|
|
|
&is_identity_default,
|
|
|
|
|
&is_user_default,
|
|
|
|
|
&is_address_default,
|
|
|
|
|
false);
|
|
|
|
|
|
|
|
|
|
if (status == PEP_STATUS_OK && stored_ident->fpr && *(stored_ident->fpr) != '\0') {
|
|
|
|
|
// set identity comm_type from trust db (user_id, FPR)
|
|
|
|
|
status = get_trust(session, stored_ident);
|
|
|
|
|
if (status == PEP_CANNOT_FIND_IDENTITY || stored_ident->comm_type == PEP_ct_unknown) {
|
|
|
|
|
// This is OK - there is no trust DB entry, but we
|
|
|
|
|
// found a key. We won't store this, but we'll
|
|
|
|
|
// use it.
|
|
|
|
|
PEP_comm_type ct = PEP_ct_unknown;
|
|
|
|
|
status = get_key_rating(session, stored_ident->fpr, &ct);
|
|
|
|
|
stored_ident->comm_type = ct;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (status != PEP_STATUS_OK) {
|
|
|
|
|
free(stored_ident->fpr);
|
|
|
|
|
stored_ident->fpr = NULL;
|
|
|
|
|
stored_ident->comm_type = PEP_ct_key_not_found;
|
|
|
|
|
}
|
|
|
|
|
else { // no key returned, but status ok?
|
|
|
|
|
if (stored_ident->comm_type == PEP_ct_unknown)
|
|
|
|
|
stored_ident->comm_type = PEP_ct_key_not_found;
|
|
|
|
|
false);
|
|
|
|
|
|
|
|
|
|
switch (status) {
|
|
|
|
|
case PEP_STATUS_OK:
|
|
|
|
|
if (!EMPTYSTR(stored_ident->fpr)) {
|
|
|
|
|
// set identity comm_type from trust db (user_id, FPR)
|
|
|
|
|
status = get_trust(session, stored_ident);
|
|
|
|
|
if (status == PEP_CANNOT_FIND_IDENTITY || stored_ident->comm_type == PEP_ct_unknown) {
|
|
|
|
|
// This is OK - there is no trust DB entry, but we
|
|
|
|
|
// found a key. We won't store this, but we'll
|
|
|
|
|
// use it.
|
|
|
|
|
PEP_comm_type ct = PEP_ct_unknown;
|
|
|
|
|
status = get_key_rating(session, stored_ident->fpr, &ct);
|
|
|
|
|
stored_ident->comm_type = ct;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (stored_ident->comm_type == PEP_ct_unknown)
|
|
|
|
|
stored_ident->comm_type = PEP_ct_key_not_found;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
free(stored_ident->fpr);
|
|
|
|
|
stored_ident->fpr = NULL;
|
|
|
|
|
stored_ident->comm_type = PEP_ct_key_not_found;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
free(return_id->fpr);
|
|
|
|
|
return_id->fpr = NULL;
|
|
|
|
|
if (status == PEP_STATUS_OK && !EMPTYSTR(stored_ident->fpr))
|
|
|
|
@ -585,6 +638,8 @@ static PEP_STATUS prepare_updated_identity(PEP_SESSION session,
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Should not return PASSPHRASE errors because we force
|
|
|
|
|
// calls that can cause key renewal not to.
|
|
|
|
|
DYNAMIC_API PEP_STATUS update_identity(
|
|
|
|
|
PEP_SESSION session, pEp_identity * identity
|
|
|
|
|
)
|
|
|
|
@ -632,7 +687,8 @@ DYNAMIC_API PEP_STATUS update_identity(
|
|
|
|
|
if (_own_addr) {
|
|
|
|
|
free(identity->user_id);
|
|
|
|
|
identity->user_id = strdup(default_own_id);
|
|
|
|
|
return _myself(session, identity, false, false, true);
|
|
|
|
|
// Do not renew, do not generate
|
|
|
|
|
return _myself(session, identity, false, false, false, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -1055,7 +1111,8 @@ PEP_STATUS _has_usable_priv_key(PEP_SESSION session, char* fpr,
|
|
|
|
|
|
|
|
|
|
PEP_STATUS _myself(PEP_SESSION session,
|
|
|
|
|
pEp_identity * identity,
|
|
|
|
|
bool do_keygen,
|
|
|
|
|
bool do_keygen,
|
|
|
|
|
bool do_renew,
|
|
|
|
|
bool ignore_flags,
|
|
|
|
|
bool read_only)
|
|
|
|
|
{
|
|
|
|
@ -1142,7 +1199,10 @@ PEP_STATUS _myself(PEP_SESSION session,
|
|
|
|
|
// Set usernames - priority is input username > stored name > address
|
|
|
|
|
// If there's an input username, we always patch the username with that
|
|
|
|
|
// input.
|
|
|
|
|
if (EMPTYSTR(identity->username) || read_only) {
|
|
|
|
|
// N.B. there was an || read_only here, but why? read_only ONLY means
|
|
|
|
|
// we don't write to the DB! So... removed. But how this managed to work
|
|
|
|
|
// before I don't know.
|
|
|
|
|
if (EMPTYSTR(identity->username)) {
|
|
|
|
|
bool stored_uname = (stored_identity && !EMPTYSTR(stored_identity->username));
|
|
|
|
|
char* uname = (stored_uname ? stored_identity->username : identity->address);
|
|
|
|
|
if (uname) {
|
|
|
|
@ -1167,34 +1227,43 @@ PEP_STATUS _myself(PEP_SESSION session,
|
|
|
|
|
if (stored_identity) {
|
|
|
|
|
if (!EMPTYSTR(stored_identity->fpr)) {
|
|
|
|
|
// Fall back / retrieve
|
|
|
|
|
status = validate_fpr(session, stored_identity, false, true);
|
|
|
|
|
if (status == PEP_OUT_OF_MEMORY)
|
|
|
|
|
goto pEp_free;
|
|
|
|
|
if (status == PEP_STATUS_OK) {
|
|
|
|
|
if (stored_identity->comm_type >= PEP_ct_strong_but_unconfirmed) {
|
|
|
|
|
identity->fpr = strdup(stored_identity->fpr);
|
|
|
|
|
assert(identity->fpr);
|
|
|
|
|
if (!identity->fpr) {
|
|
|
|
|
status = PEP_OUT_OF_MEMORY;
|
|
|
|
|
goto pEp_free;
|
|
|
|
|
}
|
|
|
|
|
valid_key_found = true;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
bool revoked = false;
|
|
|
|
|
status = key_revoked(session, stored_identity->fpr, &revoked);
|
|
|
|
|
if (status)
|
|
|
|
|
goto pEp_free;
|
|
|
|
|
if (revoked) {
|
|
|
|
|
revoked_fpr = strdup(stored_identity->fpr);
|
|
|
|
|
assert(revoked_fpr);
|
|
|
|
|
if (!revoked_fpr) {
|
|
|
|
|
status = validate_fpr(session, stored_identity, false, true, do_renew);
|
|
|
|
|
|
|
|
|
|
switch (status) {
|
|
|
|
|
// Only possible if we called this with do_renew = true
|
|
|
|
|
case PEP_OUT_OF_MEMORY:
|
|
|
|
|
case PEP_PASSPHRASE_REQUIRED:
|
|
|
|
|
case PEP_WRONG_PASSPHRASE:
|
|
|
|
|
goto pEp_free;
|
|
|
|
|
|
|
|
|
|
case PEP_STATUS_OK:
|
|
|
|
|
if (stored_identity->comm_type >= PEP_ct_strong_but_unconfirmed) {
|
|
|
|
|
identity->fpr = strdup(stored_identity->fpr);
|
|
|
|
|
assert(identity->fpr);
|
|
|
|
|
if (!identity->fpr) {
|
|
|
|
|
status = PEP_OUT_OF_MEMORY;
|
|
|
|
|
goto pEp_free;
|
|
|
|
|
}
|
|
|
|
|
valid_key_found = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
bool revoked = false;
|
|
|
|
|
status = key_revoked(session, stored_identity->fpr, &revoked);
|
|
|
|
|
if (status)
|
|
|
|
|
goto pEp_free;
|
|
|
|
|
if (revoked) {
|
|
|
|
|
revoked_fpr = strdup(stored_identity->fpr);
|
|
|
|
|
assert(revoked_fpr);
|
|
|
|
|
if (!revoked_fpr) {
|
|
|
|
|
status = PEP_OUT_OF_MEMORY;
|
|
|
|
|
goto pEp_free;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// reconcile language, flags
|
|
|
|
|
transfer_ident_lang_and_flags(identity, stored_identity);
|
|
|
|
@ -1212,6 +1281,9 @@ PEP_STATUS _myself(PEP_SESSION session,
|
|
|
|
|
status = generate_keypair(session, identity);
|
|
|
|
|
assert(status != PEP_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
|
|
if (status == PEP_PASSPHRASE_FOR_NEW_KEYS_REQUIRED)
|
|
|
|
|
goto pEp_free;
|
|
|
|
|
|
|
|
|
|
if (status != PEP_STATUS_OK) {
|
|
|
|
|
char buf[11];
|
|
|
|
|
snprintf(buf, 11, "%d", status); // uh, this is kludgey. FIXME
|
|
|
|
@ -1263,7 +1335,7 @@ pEp_free:
|
|
|
|
|
|
|
|
|
|
DYNAMIC_API PEP_STATUS myself(PEP_SESSION session, pEp_identity * identity)
|
|
|
|
|
{
|
|
|
|
|
return _myself(session, identity, true, false, false);
|
|
|
|
|
return _myself(session, identity, true, true, false, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DYNAMIC_API PEP_STATUS register_examine_function(
|
|
|
|
@ -1493,6 +1565,12 @@ pEp_free:
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Technically speaking, this should not EVER
|
|
|
|
|
// return PASSPHRASE errors, because
|
|
|
|
|
// this is never for an own identity (enforced), and thus
|
|
|
|
|
// validate_fpr will not call renew_key.
|
|
|
|
|
// If it ever does, the status gets propagated, but
|
|
|
|
|
// it is distinctly not OK.
|
|
|
|
|
DYNAMIC_API PEP_STATUS trust_personal_key(
|
|
|
|
|
PEP_SESSION session,
|
|
|
|
|
pEp_identity *ident
|
|
|
|
@ -1540,7 +1618,7 @@ DYNAMIC_API PEP_STATUS trust_personal_key(
|
|
|
|
|
// Set up a temp trusted identity for the input fpr without a comm type;
|
|
|
|
|
tmp_id = new_identity(ident->address, ident->fpr, ident->user_id, NULL);
|
|
|
|
|
|
|
|
|
|
status = validate_fpr(session, tmp_id, false, true);
|
|
|
|
|
status = validate_fpr(session, tmp_id, false, true, false);
|
|
|
|
|
|
|
|
|
|
if (status == PEP_STATUS_OK) {
|
|
|
|
|
// Validate fpr gets trust DB or, when that fails, key comm type. we checked
|
|
|
|
@ -1600,7 +1678,7 @@ DYNAMIC_API PEP_STATUS trust_personal_key(
|
|
|
|
|
if (!tmp_user_ident)
|
|
|
|
|
status = PEP_OUT_OF_MEMORY;
|
|
|
|
|
else {
|
|
|
|
|
status = validate_fpr(session, tmp_user_ident, false, true);
|
|
|
|
|
status = validate_fpr(session, tmp_user_ident, false, true, false);
|
|
|
|
|
|
|
|
|
|
if (status != PEP_STATUS_OK ||
|
|
|
|
|
tmp_user_ident->comm_type < PEP_ct_strong_but_unconfirmed ||
|
|
|
|
@ -1642,7 +1720,7 @@ DYNAMIC_API PEP_STATUS trust_own_key(
|
|
|
|
|
return PEP_ILLEGAL_VALUE;
|
|
|
|
|
|
|
|
|
|
// don't check blacklist or require a private key
|
|
|
|
|
PEP_STATUS status = validate_fpr(session, ident, false, false);
|
|
|
|
|
PEP_STATUS status = validate_fpr(session, ident, false, false, true);
|
|
|
|
|
|
|
|
|
|
if (status != PEP_STATUS_OK)
|
|
|
|
|
return status;
|
|
|
|
@ -1893,6 +1971,7 @@ DYNAMIC_API PEP_STATUS own_keys_retrieve(PEP_SESSION session, stringlist_t **key
|
|
|
|
|
return _own_keys_retrieve(session, keylist, 0, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Returns PASSPHRASE errors when necessary
|
|
|
|
|
DYNAMIC_API PEP_STATUS set_own_key(
|
|
|
|
|
PEP_SESSION session,
|
|
|
|
|
pEp_identity *me,
|
|
|
|
@ -1914,7 +1993,8 @@ DYNAMIC_API PEP_STATUS set_own_key(
|
|
|
|
|
if (me->fpr == fpr)
|
|
|
|
|
me->fpr = NULL;
|
|
|
|
|
|
|
|
|
|
status = _myself(session, me, false, true, false);
|
|
|
|
|
// renew if needed, but do not generate
|
|
|
|
|
status = _myself(session, me, false, true, true, false);
|
|
|
|
|
// we do not need a valid key but dislike other errors
|
|
|
|
|
if (status != PEP_STATUS_OK && status != PEP_GET_KEY_FAILED && status != PEP_KEY_UNSUITABLE)
|
|
|
|
|
return status;
|
|
|
|
@ -1936,12 +2016,15 @@ DYNAMIC_API PEP_STATUS set_own_key(
|
|
|
|
|
if (!me->fpr)
|
|
|
|
|
return PEP_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
|
|
status = validate_fpr(session, me, false, true);
|
|
|
|
|
status = validate_fpr(session, me, false, true, true);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
|
|
|
|
|
|
|
|
|
me->comm_type = PEP_ct_pEp;
|
|
|
|
|
status = set_identity(session, me);
|
|
|
|
|
if (status == PEP_STATUS_OK)
|
|
|
|
|
signal_Sync_event(session, Sync_PR_keysync, SynchronizeGroupKeys, NULL);
|
|
|
|
|
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -2050,7 +2133,10 @@ static PEP_STATUS _wipe_default_key_if_invalid(PEP_SESSION session,
|
|
|
|
|
if (!ident->fpr)
|
|
|
|
|
return PEP_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
|
|
PEP_STATUS keystatus = validate_fpr(session, ident, true, false);
|
|
|
|
|
PEP_STATUS keystatus = validate_fpr(session, ident, true, false, true);
|
|
|
|
|
if (PASS_ERROR(status))
|
|
|
|
|
return status;
|
|
|
|
|
|
|
|
|
|
switch (keystatus) {
|
|
|
|
|
case PEP_STATUS_OK:
|
|
|
|
|
// Check for non-renewable expiry and
|
|
|
|
@ -2069,13 +2155,14 @@ static PEP_STATUS _wipe_default_key_if_invalid(PEP_SESSION session,
|
|
|
|
|
}
|
|
|
|
|
free(cached_fpr);
|
|
|
|
|
|
|
|
|
|
if (status == PEP_STATUS_OK)
|
|
|
|
|
// This may have been for a user default, not an identity default.
|
|
|
|
|
if (status == PEP_STATUS_OK && !(EMPTYSTR(ident->address)))
|
|
|
|
|
status = myself(session, ident);
|
|
|
|
|
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PEP_STATUS clean_own_key_defaults(PEP_SESSION session) {
|
|
|
|
|
DYNAMIC_API PEP_STATUS clean_own_key_defaults(PEP_SESSION session) {
|
|
|
|
|
identity_list* idents = NULL;
|
|
|
|
|
PEP_STATUS status = own_identities_retrieve(session, &idents);
|
|
|
|
|
if (status != PEP_STATUS_OK)
|
|
|
|
@ -2096,7 +2183,9 @@ PEP_STATUS clean_own_key_defaults(PEP_SESSION session) {
|
|
|
|
|
if (!ident)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
_wipe_default_key_if_invalid(session, ident);
|
|
|
|
|
status = _wipe_default_key_if_invalid(session, ident);
|
|
|
|
|
if (PASS_ERROR(status))
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
free_identity_list(idents);
|
|
|
|
@ -2120,8 +2209,11 @@ PEP_STATUS clean_own_key_defaults(PEP_SESSION session) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
else if (user_default_key) {
|
|
|
|
|
pEp_identity* empty_user = new_identity(NULL, user_default_key, NULL, own_id);
|
|
|
|
|
_wipe_default_key_if_invalid(session, empty_user);
|
|
|
|
|
pEp_identity* empty_user = new_identity(NULL, user_default_key, own_id, NULL);
|
|
|
|
|
status = _wipe_default_key_if_invalid(session, empty_user);
|
|
|
|
|
if (PASS_ERROR(status))
|
|
|
|
|
return status;
|
|
|
|
|
|
|
|
|
|
free(user_default_key);
|
|
|
|
|
}
|
|
|
|
|
free(own_id);
|
|
|
|
|