text stringlengths 0 357 |
|---|
(const rpgp_signed_public_key* const*)public_keys, public_keys_len); |
if (dc_pgp_handle_rpgp_error(context)) { |
goto cleanup; |
} |
rpgp_cvec* decrypted_bytes = rpgp_msg_to_bytes(decrypted->message_ptr); |
if (dc_pgp_handle_rpgp_error(context)) { |
goto cleanup; |
} |
*ret_plain_bytes = rpgp_cvec_len(decrypted_bytes); |
*ret_plain = (void*)rpgp_cvec_data(decrypted_bytes); |
// No drop as we only remove the struct |
free(decrypted_bytes); |
/* collect the keys of the valid signatures */ |
if (ret_signature_fingerprints) { |
uint32_t j = 0; |
uint32_t len = (uint32_t)decrypted->valid_ids_len; |
for (; j < len; j++) { |
char* fingerprint_hex = decrypted->valid_ids_ptr[j]; |
if (fingerprint_hex) { |
dc_hash_insert(ret_signature_fingerprints, fingerprint_hex, strlen(fingerprint_hex), (void*)1); |
free(fingerprint_hex); |
} |
} |
} |
} |
success = 1; |
cleanup: |
for (i = 0; i < private_keys_len; i++) { |
rpgp_skey_drop(private_keys[i]); |
} |
for (i = 0; i < public_keys_len; i++) { |
rpgp_pkey_drop(public_keys[i]); |
} |
if (encrypted) { rpgp_msg_drop(encrypted); } |
if (decrypted) { rpgp_message_decrypt_result_drop(decrypted); } |
return success; |
} |
#else // !DC_USE_RPGP |
int dc_pgp_pk_decrypt( dc_context_t* context, |
const void* ctext, |
size_t ctext_bytes, |
const dc_keyring_t* raw_private_keys_for_decryption, |
const dc_keyring_t* raw_public_keys_for_validation, |
int use_armor, |
void** ret_plain, |
size_t* ret_plain_bytes, |
dc_hash_t* ret_signature_fingerprints) |
{ |
pgp_keyring_t* public_keys = calloc(1, sizeof(pgp_keyring_t)); /*should be 0 after parsing*/ |
pgp_keyring_t* private_keys = calloc(1, sizeof(pgp_keyring_t)); |
pgp_keyring_t* dummy_keys = calloc(1, sizeof(pgp_keyring_t)); |
pgp_validation_t* vresult = calloc(1, sizeof(pgp_validation_t)); |
key_id_t* recipients_key_ids = NULL; |
unsigned recipients_cnt = 0; |
pgp_memory_t* keysmem = pgp_memory_new(); |
int i = 0; |
int success = 0; |
if (context==NULL || ctext==NULL || ctext_bytes==0 || ret_plain==NULL || ret_plain_bytes==NULL |
|| raw_private_keys_for_decryption==NULL || raw_private_keys_for_decryption->count<=0 |
|| vresult==NULL || keysmem==NULL || public_keys==NULL || private_keys==NULL) { |
goto cleanup; |
} |
*ret_plain = NULL; |
*ret_plain_bytes = 0; |
/* setup keys (the keys may come from pgp_filter_keys_fileread(), see also pgp_keyring_add(rcpts, key)) */ |
for (i = 0; i < raw_private_keys_for_decryption->count; i++) { |
pgp_memory_clear(keysmem); /* a simple concatenate of private binary keys fails (works for public keys, however, we don't do it there either) */ |
pgp_memory_add(keysmem, raw_private_keys_for_decryption->keys[i]->binary, raw_private_keys_for_decryption->keys[i]->bytes); |
pgp_filter_keys_from_mem(&s_io, dummy_keys/*should stay empty*/, private_keys, NULL, 0, keysmem); |
} |
if (private_keys->keyc<=0) { |
dc_log_warning(context, 0, "Decryption-keyring contains unexpected data (%i/%i)", public_keys->keyc, private_keys->keyc); |
goto cleanup; |
} |
if (raw_public_keys_for_validation) { |
for (i = 0; i < raw_public_keys_for_validation->count; i++) { |
pgp_memory_clear(keysmem); |
pgp_memory_add(keysmem, raw_public_keys_for_validation->keys[i]->binary, raw_public_keys_for_validation->keys[i]->bytes); |
pgp_filter_keys_from_mem(&s_io, public_keys, dummy_keys/*should stay empty*/, NULL, 0, keysmem); |
} |
} |
/* decrypt */ |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.