text stringlengths 0 357 |
|---|
if (dc_pgp_handle_rpgp_error(context)) { |
goto cleanup; |
} |
/* Get the public key */ |
pkey = rpgp_skey_public_key(skey); |
if (dc_pgp_handle_rpgp_error(context)) { |
goto cleanup; |
} |
/* Serialize public key into bytes */ |
pkey_bytes = rpgp_pkey_to_bytes(pkey); |
if (dc_pgp_handle_rpgp_error(context)) { |
goto cleanup; |
} |
/* copy into the return secret key */ |
dc_key_set_from_binary(ret_private_key, rpgp_cvec_data(skey_bytes), rpgp_cvec_len(skey_bytes), DC_KEY_PRIVATE); |
if (dc_pgp_handle_rpgp_error(context)) { |
goto cleanup; |
} |
/* copy into the return public key */ |
dc_key_set_from_binary(ret_public_key, rpgp_cvec_data(pkey_bytes), rpgp_cvec_len(pkey_bytes), DC_KEY_PUBLIC); |
if (dc_pgp_handle_rpgp_error(context)) { |
goto cleanup; |
} |
success = 1; |
/* cleanup */ |
cleanup: |
if (skey) { rpgp_skey_drop(skey); } |
if (skey_bytes) { rpgp_cvec_drop(skey_bytes); } |
if (pkey) { rpgp_pkey_drop(pkey); } |
if (pkey_bytes) { rpgp_cvec_drop(pkey_bytes); } |
if (user_id) { free(user_id); } |
return success; |
} |
#else // !DC_USE_RPGP |
static unsigned add_key_prefs(pgp_create_sig_t *sig) |
{ |
/* similar to pgp_add_key_prefs(), Mimic of GPG default settings, limited to supported algos */ |
return |
/* Symmetric algo prefs */ |
pgp_write_ss_header(sig->output, 6, PGP_PTAG_SS_PREFERRED_SKA) && |
pgp_write_scalar(sig->output, PGP_SA_AES_256, 1) && |
pgp_write_scalar(sig->output, PGP_SA_AES_128, 1) && |
pgp_write_scalar(sig->output, PGP_SA_CAST5, 1) && |
pgp_write_scalar(sig->output, PGP_SA_TRIPLEDES, 1) && |
pgp_write_scalar(sig->output, PGP_SA_IDEA, 1) && |
/* Hash algo prefs, the first algo is the preferred algo */ |
pgp_write_ss_header(sig->output, 6, PGP_PTAG_SS_PREFERRED_HASH) && |
pgp_write_scalar(sig->output, PGP_HASH_SHA256, 1) && |
pgp_write_scalar(sig->output, PGP_HASH_SHA384, 1) && |
pgp_write_scalar(sig->output, PGP_HASH_SHA512, 1) && |
pgp_write_scalar(sig->output, PGP_HASH_SHA224, 1) && |
pgp_write_scalar(sig->output, PGP_HASH_SHA1, 1) && /* Edit for Autocrypt/Delta Chat: due to the weak SHA1, it should not be preferred */ |
/* Compression algo prefs */ |
pgp_write_ss_header(sig->output, 2/*1+number of following items*/, PGP_PTAG_SS_PREF_COMPRESS) && |
pgp_write_scalar(sig->output, PGP_C_ZLIB, 1) /*&& -- not sure if Delta Chat will support bzip2 on all platforms, however, this is not that important as typical files are compressed themselves and text is not that big |
pgp_write_scalar(sig->output, PGP_C_BZIP2, 1) -- if you re-enable this, do not forget to modifiy the header count*/; |
} |
static void add_selfsigned_userid(pgp_key_t *skey, pgp_key_t *pkey, const uint8_t *userid, time_t key_expiry) |
{ |
/* similar to pgp_add_selfsigned_userid() which, however, uses different key flags */ |
pgp_create_sig_t* sig = NULL; |
pgp_subpacket_t sigpacket; |
pgp_memory_t* mem_sig = NULL; |
pgp_output_t* sigoutput = NULL; |
/* create sig for this pkt */ |
sig = pgp_create_sig_new(); |
pgp_sig_start_key_sig(sig, &skey->key.seckey.pubkey, NULL, userid, PGP_CERT_POSITIVE); |
pgp_add_creation_time(sig, time(NULL)); |
pgp_add_key_expiration_time(sig, key_expiry); |
pgp_add_primary_userid(sig, 1); |
pgp_add_key_flags(sig, PGP_KEYFLAG_SIGN_DATA|PGP_KEYFLAG_CERT_KEYS); |
add_key_prefs(sig); |
pgp_add_key_features(sig); /* will add 0x01 - modification detection */ |
pgp_end_hashed_subpkts(sig); |
pgp_add_issuer_keyid(sig, skey->pubkeyid); /* the issuer keyid is not hashed by definition */ |
pgp_setup_memory_write(&sigoutput, &mem_sig, 128); |
pgp_write_sig(sigoutput, sig, &skey->key.seckey.pubkey, &skey->key.seckey); |
/* add this packet to key */ |
sigpacket.length = pgp_mem_len(mem_sig); |
sigpacket.raw = pgp_mem_data(mem_sig); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.