text stringlengths 0 357 |
|---|
{ |
pgp_memory_t* outmem = pgp_decrypt_and_validate_buf(&s_io, vresult, ctext, ctext_bytes, private_keys, public_keys, |
use_armor, &recipients_key_ids, &recipients_cnt); |
if (outmem==NULL) { |
dc_log_warning(context, 0, "Decryption failed."); |
goto cleanup; |
} |
*ret_plain = outmem->buf; |
*ret_plain_bytes = outmem->length; |
free(outmem); /* do not use pgp_memory_free() as we took ownership of the buffer */ |
// collect the keys of the valid signatures |
if (ret_signature_fingerprints) |
{ |
for (i = 0; i < vresult->validc; i++) |
{ |
unsigned from = 0; |
pgp_key_t* key0 = pgp_getkeybyid(&s_io, public_keys, vresult->valid_sigs[i].signer_id, &from, NULL, NULL, 0, 0); |
if (key0) { |
pgp_pubkey_t* pubkey0 = &key0->key.pubkey; |
if (!pgp_fingerprint(&key0->pubkeyfpr, pubkey0, 0)) { |
goto cleanup; |
} |
char* fingerprint_hex = dc_binary_to_uc_hex(key0->pubkeyfpr.fingerprint, key0->pubkeyfpr.length); |
if (fingerprint_hex) { |
dc_hash_insert(ret_signature_fingerprints, fingerprint_hex, strlen(fingerprint_hex), (void*)1); |
} |
free(fingerprint_hex); |
} |
} |
} |
} |
success = 1; |
cleanup: |
if (keysmem) { pgp_memory_free(keysmem); } |
if (public_keys) { pgp_keyring_purge(public_keys); free(public_keys); } /*pgp_keyring_free() frees the content, not the pointer itself*/ |
if (private_keys) { pgp_keyring_purge(private_keys); free(private_keys); } |
if (dummy_keys) { pgp_keyring_purge(dummy_keys); free(dummy_keys); } |
if (vresult) { pgp_validate_result_free(vresult); } |
free(recipients_key_ids); |
return success; |
} |
#endif // !DC_USE_RPGP |
/******************************************************************************* |
* Symmetric encrypt/decrypt, needed for the autocrypt setup messages |
******************************************************************************/ |
#ifdef DC_USE_RPGP |
int dc_pgp_symm_encrypt(dc_context_t* context, |
const char* passphrase, |
const void* plain, size_t plain_bytes, |
char** ret_ctext_armored) |
{ |
int success = 0; |
rpgp_message* decrypted = NULL; |
if (context==NULL || passphrase==NULL || plain==NULL || plain_bytes==0 |
|| ret_ctext_armored==NULL ) { |
goto cleanup; |
} |
decrypted = rpgp_encrypt_bytes_with_password(plain, plain_bytes, passphrase); |
if (dc_pgp_handle_rpgp_error(context)) { |
goto cleanup; |
} |
*ret_ctext_armored = rpgp_msg_to_armored_str(decrypted); |
if (dc_pgp_handle_rpgp_error(context)) { |
goto cleanup; |
} |
success = 1; |
cleanup: |
if (decrypted) { rpgp_msg_drop(decrypted); } |
return success; |
} |
#else // !DC_USE_RPGP |
int dc_pgp_symm_encrypt(dc_context_t* context, |
const char* passphrase, |
const void* plain, size_t plain_bytes, |
char** ret_ctext_armored) |
{ |
int success = 0; |
uint8_t salt[PGP_SALT_SIZE]; |
pgp_crypt_t crypt_info; |
uint8_t* key = NULL; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.