text stringlengths 0 357 |
|---|
/* add user id and signature to key */ |
pgp_update_userid(skey, userid, &sigpacket, &sig->sig.info); |
if(pkey) { |
pgp_update_userid(pkey, userid, &sigpacket, &sig->sig.info); |
} |
/* cleanup */ |
pgp_create_sig_delete(sig); |
pgp_output_delete(sigoutput); |
pgp_memory_free(mem_sig); |
} |
static void add_subkey_binding_signature(pgp_subkeysig_t* p, pgp_key_t* primarykey, pgp_key_t* subkey, pgp_key_t* seckey) |
{ |
/*add "0x18: Subkey Binding Signature" packet, PGP_SIG_SUBKEY */ |
pgp_create_sig_t* sig = NULL; |
pgp_output_t* sigoutput = NULL; |
pgp_memory_t* mem_sig = NULL; |
sig = pgp_create_sig_new(); |
pgp_sig_start_key_sig(sig, &primarykey->key.pubkey, &subkey->key.pubkey, NULL, PGP_SIG_SUBKEY); |
pgp_add_creation_time(sig, time(NULL)); |
pgp_add_key_expiration_time(sig, 0); |
pgp_add_key_flags(sig, PGP_KEYFLAG_ENC_STORAGE|PGP_KEYFLAG_ENC_COMM); /* NB: algo/hash/compression preferences are not added to subkeys */ |
pgp_end_hashed_subpkts(sig); |
pgp_add_issuer_keyid(sig, seckey->pubkeyid); /* the issuer keyid is not hashed by definition */ |
pgp_setup_memory_write(&sigoutput, &mem_sig, 128); |
pgp_write_sig(sigoutput, sig, &seckey->key.seckey.pubkey, &seckey->key.seckey); |
p->subkey = primarykey->subkeyc-1; /* index of subkey in array */ |
p->packet.length = mem_sig->length; |
p->packet.raw = mem_sig->buf; mem_sig->buf = NULL; /* move ownership to packet */ |
copy_sig_info(&p->siginfo, &sig->sig.info); /* not sure, if this is okay, however, siginfo should be set up, otherwise we get "bad info-type" errors */ |
pgp_create_sig_delete(sig); |
pgp_output_delete(sigoutput); |
free(mem_sig); /* do not use pgp_memory_free() as this would also free mem_sig->buf which is owned by the packet */ |
} |
int dc_pgp_create_keypair(dc_context_t* context, const char* addr, dc_key_t* ret_public_key, dc_key_t* ret_private_key) |
{ |
int success = 0; |
pgp_key_t seckey; |
pgp_key_t pubkey; |
pgp_key_t subkey; |
uint8_t subkeyid[PGP_KEY_ID_SIZE]; |
uint8_t* user_id = NULL; |
pgp_memory_t* pubmem = pgp_memory_new(); |
pgp_memory_t* secmem = pgp_memory_new(); |
pgp_output_t* pubout = pgp_output_new(); |
pgp_output_t* secout = pgp_output_new(); |
memset(&seckey, 0, sizeof(pgp_key_t)); |
memset(&pubkey, 0, sizeof(pgp_key_t)); |
memset(&subkey, 0, sizeof(pgp_key_t)); |
if (context==NULL || addr==NULL || ret_public_key==NULL || ret_private_key==NULL |
|| pubmem==NULL || secmem==NULL || pubout==NULL || secout==NULL) { |
goto cleanup; |
} |
/* Generate User ID. |
By convention, this is the e-mail-address in angle brackets. |
As the user-id is only decorative in Autocrypt and not needed for Delta Chat, |
so we _could_ just use sth. that looks like an e-mail-address. |
This would protect the user's privacy if someone else uploads the keys to keyservers. |
However, as eg. Enigmail displayes the user-id in "Good signature from <user-id>, |
for now, we decided to leave the address in the user-id */ |
#if 0 |
user_id = (uint8_t*)dc_mprintf("<%08X@%08X.org>", (int)random(), (int)random()); |
#else |
user_id = (uint8_t*)dc_mprintf("<%s>", addr); |
#endif |
/* generate two keypairs */ |
if (!pgp_rsa_generate_keypair(&seckey, DC_KEYGEN_BITS, DC_KEYGEN_E, NULL, NULL, NULL, 0) |
|| !pgp_rsa_generate_keypair(&subkey, DC_KEYGEN_BITS, DC_KEYGEN_E, NULL, NULL, NULL, 0)) { |
goto cleanup; |
} |
/* Create public key, bind public subkey to public key |
------------------------------------------------------------------------ */ |
pubkey.type = PGP_PTAG_CT_PUBLIC_KEY; |
pgp_pubkey_dup(&pubkey.key.pubkey, &seckey.key.pubkey); |
memcpy(pubkey.pubkeyid, seckey.pubkeyid, PGP_KEY_ID_SIZE); |
pgp_fingerprint(&pubkey.pubkeyfpr, &seckey.key.pubkey, 0); |
add_selfsigned_userid(&seckey, &pubkey, (const uint8_t*)user_id, 0/*never expire*/); |
EXPAND_ARRAY((&pubkey), subkey); |
{ |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.