text stringlengths 0 357 |
|---|
mailmime_write_mem(random_data_mmap, &col, random_data_mime); |
dc_pgp_rand_seed(context, random_data_mmap->str, random_data_mmap->len); |
mmap_string_free(random_data_mmap); |
} |
} |
{ |
dc_key_t* private_key = dc_key_new(); |
clock_t start = clock(); |
dc_log_info(context, 0, "Generating keypair with %i bits, e=%i ...", DC_KEYGEN_BITS, DC_KEYGEN_E); |
/* The public key must contain the following: |
- a signing-capable primary key Kp |
- a user id |
- a self signature |
- an encryption-capable subkey Ke |
- a binding signature over Ke by Kp |
(see https://autocrypt.readthedocs.io/en/latest/level0.html#type-p-openpgp-based-key-data)*/ |
key_created = dc_pgp_create_keypair(context, self_addr, public_key, private_key); |
if (!key_created) { |
dc_log_warning(context, 0, "Cannot create keypair."); |
goto cleanup; |
} |
if (!dc_pgp_is_valid_key(context, public_key) |
|| !dc_pgp_is_valid_key(context, private_key)) { |
dc_log_warning(context, 0, "Generated keys are not valid."); |
goto cleanup; |
} |
if (!dc_key_save_self_keypair(public_key, private_key, self_addr, 1/*set default*/, context->sql)) { |
dc_log_warning(context, 0, "Cannot save keypair."); |
goto cleanup; |
} |
dc_log_info(context, 0, "Keypair generated in %.3f s.", (double)(clock()-start)/CLOCKS_PER_SEC); |
dc_key_unref(private_key); |
} |
} |
success = 1; |
cleanup: |
if (key_creation_here) { s_in_key_creation = 0; } |
return success; |
} |
int dc_ensure_secret_key_exists(dc_context_t* context) |
{ |
/* normally, the key is generated as soon as the first mail is send |
(this is to gain some extra-random-seed by the message content and the timespan between program start and message sending) */ |
int success = 0; |
dc_key_t* public_key = dc_key_new(); |
char* self_addr = NULL; |
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC || public_key==NULL) { |
goto cleanup; |
} |
if ((self_addr=dc_sqlite3_get_config(context->sql, "configured_addr", NULL))==NULL) { |
dc_log_warning(context, 0, "Cannot ensure secret key if context is not configured."); |
goto cleanup; |
} |
if (!load_or_generate_self_public_key(context, public_key, self_addr, NULL/*no random text data for seeding available*/)) { |
goto cleanup; |
} |
success = 1; |
cleanup: |
dc_key_unref(public_key); |
free(self_addr); |
return success; |
} |
/******************************************************************************* |
* Encrypt |
******************************************************************************/ |
void dc_e2ee_encrypt(dc_context_t* context, const clist* recipients_addr, |
int force_unencrypted, |
int e2ee_guaranteed, /*set if e2ee was possible on sending time; we should not degrade to transport*/ |
int min_verified, |
int do_gossip, |
struct mailmime* in_out_message, dc_e2ee_helper_t* helper) |
{ |
int col = 0; |
int do_encrypt = 0; |
dc_aheader_t* autocryptheader = dc_aheader_new(); |
struct mailimf_fields* imffields_unprotected = NULL; /*just a pointer into mailmime structure, must not be freed*/ |
dc_keyring_t* keyring = dc_keyring_new(); |
dc_key_t* sign_key = dc_key_new(); |
MMAPString* plain = mmap_string_new(""); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.