Browse Source

Fix for empty usernames and URI addresses - we now allow passing NULL into generate_keypair. Underlying crypto wrappers will have to deal with the need for a username by their implementations individually (sequoia will deal with this if it's NULL, but not if we feel it an explicit URI)

add_key_notification
parent
commit
785ea9a8d1
4 changed files with 59 additions and 20 deletions
  1. +10
    -0
      src/keymanagement.c
  2. +24
    -19
      src/pEpEngine.c
  3. +1
    -1
      src/pgp_sequoia.c
  4. +24
    -0
      test/src/URIAddressTest.cc

+ 10
- 0
src/keymanagement.c View File

@ -1076,6 +1076,8 @@ PEP_STATUS _myself(PEP_SESSION session,
char* default_own_id = NULL;
status = get_default_own_userid(session, &default_own_id);
bool no_uname_on_entry = EMPTYSTR(identity->username);
// Deal with non-default user_ids.
// FIXME: if non-default and read-only, reject totally?
@ -1200,7 +1202,15 @@ PEP_STATUS _myself(PEP_SESSION session,
free(identity->fpr);
identity->fpr = NULL;
char* namecache = NULL;
if (no_uname_on_entry) {
namecache = identity->username;
identity->username = NULL;
}
status = generate_keypair(session, identity);
if (namecache) {
identity->username = namecache;
}
assert(status != PEP_OUT_OF_MEMORY);
if (status != PEP_STATUS_OK) {


+ 24
- 19
src/pEpEngine.c View File

@ -4739,32 +4739,37 @@ PEP_STATUS _generate_keypair(PEP_SESSION session,
assert(identity);
assert(identity->address);
assert(identity->fpr == NULL || identity->fpr[0] == 0);
assert(identity->username);
// assert(identity->username);
// N.B. We now allow empty usernames, so the underlying layer for
// non-sequoia crypto implementations will have to deal with this.
if (!(session && identity && identity->address &&
(identity->fpr == NULL || identity->fpr[0] == 0) &&
identity->username))
(identity->fpr == NULL || identity->fpr[0] == 0)))
return PEP_ILLEGAL_VALUE;
char* saved_username = NULL;
char* at = NULL;
size_t uname_len = strlen(identity->username);
if (uname_len > 0)
at = strstr(identity->username, "@");
if (at) {
saved_username = identity->username;
identity->username = calloc(uname_len + 3, 1);
if (!identity->username) {
identity->username = saved_username;
return PEP_OUT_OF_MEMORY;
// KB: In light of the above, remove? FIXME.
if (identity->username) {
char* at = NULL;
size_t uname_len = strlen(identity->username);
if (uname_len > 0)
at = strstr(identity->username, "@");
if (at) {
saved_username = identity->username;
identity->username = calloc(uname_len + 3, 1);
if (!identity->username) {
identity->username = saved_username;
return PEP_OUT_OF_MEMORY;
}
identity->username[0] = '"';
strlcpy((identity->username) + 1, saved_username, uname_len + 1);
identity->username[uname_len + 1] = '"';
}
identity->username[0] = '"';
strlcpy((identity->username) + 1, saved_username, uname_len + 1);
identity->username[uname_len + 1] = '"';
}
PEP_STATUS status =
session->cryptotech[PEP_crypt_OpenPGP].generate_keypair(session,
identity);


+ 1
- 1
src/pgp_sequoia.c View File

@ -1981,7 +1981,7 @@ PEP_STATUS pgp_generate_keypair(PEP_SESSION session, pEp_identity *identity)
assert(identity);
assert(identity->address);
assert(identity->fpr == NULL || identity->fpr[0] == 0);
assert(identity->username);
// assert(identity->username);
userid_packet = pgp_user_id_from_unchecked_address(&err,
identity->username, NULL,


+ 24
- 0
test/src/URIAddressTest.cc View File

@ -109,6 +109,30 @@ TEST_F(URIAddressTest, check_uri_address_genkey) {
free_identity(me);
}
TEST_F(URIAddressTest, check_uri_address_genkey_empty_uname) {
const char* uri_addr = "payto://BIC/SYSTEMB";
const char* uname = "Jonas's Broken Identity";
pEp_identity* me = new_identity(uri_addr, NULL, "SystemA", NULL);
PEP_STATUS status = myself(session, me);
ASSERT_EQ(status , PEP_STATUS_OK);
ASSERT_TRUE(me->fpr && me->fpr[0] != '\0');
char* keydata = NULL;
size_t keysize = 0;
status = export_key(session, me->fpr,
&keydata, &keysize);
ASSERT_GT(keydata && keysize, 0);
// no guarantee of NUL-termination atm.
// output_stream << keydata << endl;
free(keydata);
free_identity(me);
}
// FIXME: URL, URN
TEST_F(URIAddressTest, check_uri_address_encrypt) {
const char* uri_addr = "shark://grrrr/39874293847092837443987492834";


Loading…
Cancel
Save