1
0
Fork 0
mirror of https://github.com/deltachat/deltachat-core.git synced 2025-10-06 03:50:08 +02:00

Prepare AES-128 key encryption.

This commit is contained in:
B. Petersen 2017-06-20 01:10:50 +02:00
parent 7b5ad865a1
commit b86c5d8142
3 changed files with 25 additions and 4 deletions

View file

@ -115,7 +115,7 @@ unsigned encode_m_buf(const uint8_t *, size_t, const pgp_pubkey_t *,
uint8_t *);
unsigned pgp_fileread_litdata(const char *, const pgp_litdata_enum,
pgp_output_t *);
unsigned pgp_write_symm_enc_data(const uint8_t *, const int,
unsigned pgp_write_symm_enc_data(const uint8_t *, const int, pgp_symm_alg_t, const uint8_t* key,
pgp_output_t *);
#endif /* CREATE_H_ */

View file

@ -1317,6 +1317,8 @@ pgp_filewrite(const char *filename, const char *buf,
unsigned
pgp_write_symm_enc_data(const uint8_t *data,
const int len,
pgp_symm_alg_t alg, // EDIT BY MR, eg. PGP_SA_AES_128 or PGP_SA_AES_256
const uint8_t* key, // EDIT BY MR - the key was simply missing
pgp_output_t * output)
{
pgp_crypt_t crypt_info;
@ -1324,8 +1326,10 @@ pgp_write_symm_enc_data(const uint8_t *data,
size_t encrypted_sz;
int done = 0;
/* \todo assume AES256 for now */
pgp_crypt_any(&crypt_info, PGP_SA_AES_256);
pgp_crypt_any(&crypt_info, alg);
crypt_info.set_crypt_key(&crypt_info, key);
pgp_encrypt_init(&crypt_info);
encrypted_sz = (size_t)(len + crypt_info.blocksize + 2);

View file

@ -29,6 +29,7 @@
#include <dirent.h>
#include <openssl/rand.h>
#include <libetpan/mmapstring.h>
#include <netpgp-extra.h>
#include "mrmailbox.h"
#include "mrmimeparser.h"
#include "mrosnative.h"
@ -348,6 +349,9 @@ int mrmailbox_render_keys_to_html(mrmailbox_t* mailbox, const char* setup_code,
struct mailmime* payload_mime_anchor = NULL;
MMAPString* payload_string = mmap_string_new("");
#define AES_128_KEY_BYTES 16 // = 128 bit
uint8_t key[AES_128_KEY_BYTES];
if( mailbox==NULL || setup_code==NULL || ret_msg==NULL
|| *ret_msg!=NULL || private_key==NULL || payload_string==NULL ) {
goto cleanup;
@ -395,7 +399,20 @@ int mrmailbox_render_keys_to_html(mrmailbox_t* mailbox, const char* setup_code,
mailmime_write_mem(payload_string, &col, payload_mime_msg);
//char* t2=mr_null_terminate(payload_string->str,payload_string->len);printf("\n~~~~~~~~~~~~~~~~~~~~SETUP-PAYLOAD~~~~~~~~~~~~~~~~~~~~\n%s~~~~~~~~~~~~~~~~~~~~/SETUP-PAYLOAD~~~~~~~~~~~~~~~~~~~~\n",t2);free(t2); // DEBUG OUTPUT
/* encrypt the payload using the setup code */
/* create key from setup-code using OpenPGP's salted+iterated S2K (String-to-key) */
// TODO
/* encrypt the payload using the key */
{
pgp_output_t* encr_output = NULL;
pgp_memory_t* encr_mem = NULL;
pgp_setup_memory_write(&encr_output, &encr_mem, 128);
pgp_write_symm_enc_data((const uint8_t*)payload_string->str, payload_string->len, PGP_SA_AES_128, key, encr_output);
}
//AES_encrypt();
// TODO