Browse Source

...

async_key_management
vb 7 years ago
parent
commit
8a0dfbb113
4 changed files with 305 additions and 32 deletions
  1. +97
    -20
      src/message_api.c
  2. +4
    -3
      src/message_api.h
  3. +161
    -1
      src/transport.c
  4. +43
    -8
      src/transport.h

+ 97
- 20
src/message_api.c View File

@ -12,6 +12,7 @@ static char * combine_short_and_long(const message * src)
{
char * ptext;
char * longmsg;
assert(src);
assert(src->shortmsg && strcmp(src->shortmsg, "pEp") != 0);
@ -32,34 +33,65 @@ static char * combine_short_and_long(const message * src)
return ptext;
}
static message * clone_empty_message(const message * src)
static message * clone_to_empty_message(const message * src)
{
pEp_identity *from = NULL;
identity_list *to = NULL;
message * msg = NULL;
assert(src);
assert(src->from);
assert(src->to);
msg->dir = src->dir;
from = identity_dup(src->from);
assert(from);
if (from == NULL)
goto enomem;
from->me = true;
to = identity_list_dup(src->to);
assert(to);
if (to == NULL)
goto enomem;
msg = new_message(src->dir, from, to, NULL);
assert(msg);
if (msg == NULL)
goto enomem;
if (src->cc) {
msg->cc = identity_list_dup(src->cc);
if (msg->cc == NULL)
goto enomem;
}
if (src->bcc) {
msg->bcc = identity_list_dup(src->bcc);
if (msg->bcc == NULL)
goto enomem;
}
if (src->reply_to) {
msg->reply_to = identity_dup(src->reply_to);
if (msg->reply_to == NULL)
goto enomem;
}
msg->sent = src->sent;
msg->recv = src->recv;
return msg;
enomem:
free_identity(from);
free_identity_list(to);
if (msg) {
free_message(msg);
}
else {
free_identity(from);
free_identity_list(to);
}
return NULL;
}
@ -68,7 +100,7 @@ DYNAMIC_API PEP_STATUS encrypt_message(
const message *src,
stringlist_t * extra,
message **dst,
PEP_enc_format format
PEP_enc_format enc_format
)
{
PEP_STATUS status = PEP_STATUS_OK;
@ -78,15 +110,25 @@ DYNAMIC_API PEP_STATUS encrypt_message(
assert(session);
assert(src);
assert(dst);
assert(enc_format >= PEP_enc_pieces);
*dst = NULL;
assert(format != PEP_enc_none && format != PEP_enc_none_MIME);
// TODO: we don't yet support re-encrypting already encrypted messages
if ((int) src->format >= (int) PEP_enc_pieces) {
NOT_IMPLEMENTED
if (src->enc_format >= PEP_enc_pieces) {
if (src->enc_format == enc_format) {
msg = message_dup(src);
if (msg == NULL)
goto enomem;
*dst = msg;
return PEP_STATUS_OK;
}
else {
// TODO: we don't re-encrypt yet
NOT_IMPLEMENTED
}
}
msg = clone_empty_message(src);
msg = clone_to_empty_message(src);
if (msg == NULL)
goto enomem;
@ -130,7 +172,7 @@ DYNAMIC_API PEP_STATUS encrypt_message(
char *ctext = NULL;
size_t csize = 0;
switch (format) {
switch (enc_format) {
case PEP_enc_MIME_multipart: {
bool free_ptext = false;
@ -146,7 +188,7 @@ DYNAMIC_API PEP_STATUS encrypt_message(
ptext = src->longmsg;
}
if (src->format == PEP_enc_none) {
if (src->enc_format == PEP_enc_none) {
char *_ptext = ptext;
status = mime_encode_text(_ptext, src->longmsg_formatted,
src->attachments, &ptext);
@ -158,7 +200,7 @@ DYNAMIC_API PEP_STATUS encrypt_message(
goto pep_error;
free_ptext = true;
}
else if (src->format == PEP_enc_none_MIME) {
else if (src->enc_format == PEP_enc_none_MIME) {
assert(src->longmsg);
if (src->longmsg == NULL) {
status = PEP_ILLEGAL_VALUE;
@ -186,7 +228,7 @@ DYNAMIC_API PEP_STATUS encrypt_message(
msg->enc_format = PEP_enc_pieces;
// TODO: decoding MIME
if (src->format == PEP_enc_none_MIME) {
if (src->enc_format == PEP_enc_none_MIME) {
NOT_IMPLEMENTED
}
@ -264,6 +306,10 @@ DYNAMIC_API PEP_STATUS encrypt_message(
}
break;
case PEP_enc_PEP:
// TODO: implement
NOT_IMPLEMENTED
default:
assert(0);
status = PEP_ILLEGAL_VALUE;
@ -292,7 +338,8 @@ pep_error:
DYNAMIC_API PEP_STATUS decrypt_message(
PEP_SESSION session,
const message *src,
message **dst
message **dst,
PEP_enc_format enc_format
)
{
PEP_STATUS status = PEP_STATUS_OK;
@ -300,12 +347,42 @@ DYNAMIC_API PEP_STATUS decrypt_message(
assert(session);
assert(src);
assert(src->dir == PEP_dir_incoming);
assert(dst);
assert(enc_format < PEP_enc_pieces);
*dst = NULL;
// msg = new_message(src->dir, from, to, NULL);
NOT_IMPLEMENTED
if (src->enc_format < PEP_enc_pieces) {
if (enc_format == src->enc_format) {
msg = message_dup(src);
if (msg == NULL)
goto enomem;
*dst = msg;
return PEP_STATUS_OK;
}
else {
// TODO: we don't re-encode yet
NOT_IMPLEMENTED
}
}
msg = clone_to_empty_message(src);
if (msg == NULL)
goto enomem;
switch (enc_format) {
case PEP_enc_none:
break;
case PEP_enc_none_MIME:
break;
default:
assert(0);
status = PEP_ILLEGAL_VALUE;
goto pep_error;
}
*dst = msg;
return PEP_STATUS_OK;


+ 4
- 3
src/message_api.h View File

@ -14,7 +14,7 @@ extern "C" {
// src (in) message to encrypt
// extra (in) extra keys for encryption
// dst (out) pointer to encrypted message or NULL on failure
// format (in) encryption format
// format (in) unencrypted format
//
// return value:
// PEP_STATUS_OK on success
@ -29,7 +29,7 @@ DYNAMIC_API PEP_STATUS encrypt_message(
const message *src,
stringlist_t *extra,
message **dst,
PEP_enc_format format
PEP_enc_format enc_format
);
@ -46,7 +46,8 @@ DYNAMIC_API PEP_STATUS encrypt_message(
DYNAMIC_API PEP_STATUS decrypt_message(
PEP_SESSION session,
const message *src,
message **dst
message **dst,
PEP_enc_format enc_format
);
#ifdef __cplusplus


+ 161
- 1
src/transport.c View File

@ -94,8 +94,10 @@ DYNAMIC_API bloblist_t *new_bloblist(char *blob, size_t size, const char *mime_t
const char *file_name)
{
bloblist_t * bloblist = calloc(1, sizeof(bloblist_t));
assert(bloblist);
if (bloblist == NULL)
return NULL;
if (mime_type) {
bloblist->mime_type = strdup(mime_type);
if (bloblist->mime_type == NULL) {
@ -103,6 +105,7 @@ DYNAMIC_API bloblist_t *new_bloblist(char *blob, size_t size, const char *mime_t
return NULL;
}
}
if (file_name) {
bloblist->file_name = strdup(file_name);
if (bloblist->file_name == NULL) {
@ -111,8 +114,10 @@ DYNAMIC_API bloblist_t *new_bloblist(char *blob, size_t size, const char *mime_t
return NULL;
}
}
bloblist->data = blob;
bloblist->size = size;
return bloblist;
}
@ -128,6 +133,29 @@ DYNAMIC_API void free_bloblist(bloblist_t *bloblist)
}
}
DYNAMIC_API bloblist_t *bloblist_dup(const bloblist_t *src)
{
bloblist_t *bloblist = NULL;
assert(src);
bloblist = new_bloblist(src->data, src->size, src->mime_type, src->file_name);
if (bloblist == NULL)
goto enomem;
if (src->next) {
bloblist->next = bloblist_dup(src->next);
if (bloblist->next == NULL)
goto enomem;
}
return bloblist;
enomem:
free_bloblist(bloblist);
return NULL;
}
DYNAMIC_API bloblist_t *bloblist_add(bloblist_t *bloblist, char *blob, size_t size,
const char *mime_type, const char *file_name)
{
@ -206,12 +234,119 @@ DYNAMIC_API void free_message(message *msg)
free_identity(msg->recv_by);
free_identity_list(msg->cc);
free_identity_list(msg->bcc);
free_identity(msg->reply_to);
free(msg->refering_id);
free_message_ref_list(msg->refered_by);
free(msg);
}
}
DYNAMIC_API message * message_dup(const message *src)
{
message * msg = NULL;
pEp_identity * from = NULL;
identity_list * to = NULL;
assert(src);
from = identity_dup(src->from);
if (from == NULL)
goto enomem;
to = identity_list_dup(src->to);
if (to == NULL)
goto enomem;
msg = new_message(src->dir, from, to, src->shortmsg);
if (msg == NULL)
goto enomem;
if (src->id) {
msg->id = strdup(src->id);
assert(msg->id);
if (msg->id == NULL)
goto enomem;
}
if (src->longmsg) {
msg->longmsg = strdup(src->longmsg);
assert(msg->longmsg);
if (msg->longmsg == NULL)
goto enomem;
}
if (src->longmsg_formatted) {
msg->longmsg_formatted = strdup(src->longmsg_formatted);
assert(msg->longmsg_formatted);
if (msg->longmsg_formatted == NULL)
goto enomem;
}
if (src->attachments) {
msg->attachments = bloblist_dup(src->attachments);
if (msg->attachments == NULL)
goto enomem;
}
msg->rawmsg_ref = src->rawmsg_ref;
msg->rawmsg_size = src->rawmsg_size;
msg->sent = src->sent;
msg->recv = src->recv;
if (src->recv_by) {
msg->recv_by = identity_dup(src->recv_by);
if (msg->recv_by == NULL)
goto enomem;
}
if (src->cc) {
msg->cc = identity_list_dup(src->cc);
if (msg->cc == NULL)
goto enomem;
}
if (src->bcc) {
msg->bcc = identity_list_dup(src->bcc);
if (msg->bcc == NULL)
goto enomem;
}
if (src->reply_to) {
msg->reply_to = identity_dup(src->reply_to);
if (msg->reply_to == NULL)
goto enomem;
}
if (src->refering_id) {
msg->refering_id = strdup(src->refering_id);
assert(msg->refering_id);
if (msg->refering_id == NULL)
goto enomem;
}
msg->refering_msg_ref = src->refering_msg_ref;
if (src->refered_by) {
msg->refered_by = message_ref_list_dup(src->refered_by);
if (msg->refered_by == NULL)
goto enomem;
}
msg->enc_format = src->enc_format;
return msg;
enomem:
if (msg) {
free_message(msg);
}
else {
free_identity(from);
free_identity_list(to);
}
return NULL;
}
DYNAMIC_API message_ref_list *new_message_ref_list(message *msg)
{
message_ref_list *msg_list = calloc(1, sizeof(message_ref_list));
@ -232,6 +367,31 @@ DYNAMIC_API void free_message_ref_list(message_ref_list *msg_list)
}
}
DYNAMIC_API message_ref_list *message_ref_list_dup(
const message_ref_list *src
)
{
message_ref_list * msg_list = NULL;
assert(src);
msg_list = new_message_ref_list(src->msg_ref);
if (msg_list == NULL)
goto enomem;
if (src->next) {
msg_list->next = message_ref_list_dup(src->next);
if (msg_list->next == NULL)
goto enomem;
}
return msg_list;
enomem:
free_message_ref_list(msg_list);
return NULL;
}
DYNAMIC_API message_ref_list *message_ref_list_add(message_ref_list *msg_list, message *msg)
{
assert(msg);


+ 43
- 8
src/transport.h View File

@ -81,10 +81,11 @@ DYNAMIC_API void free_identity_list(identity_list *id_list);
DYNAMIC_API identity_list *identity_list_add(identity_list *id_list, pEp_identity *ident);
typedef enum _PEP_msg_format {
PEP_format_plain = 0,
PEP_format_html
} PEP_msg_format;
typedef enum _PEP_text_format {
PEP_text_format_plain = 0,
PEP_text_format_html,
PEP_text_format_other = 0xff
} PEP_text_format;
typedef enum _PEP_msg_direction {
PEP_dir_incoming = 0,
@ -129,6 +130,19 @@ DYNAMIC_API bloblist_t *new_bloblist(char *blob, size_t size, const char *mime_t
DYNAMIC_API void free_bloblist(bloblist_t *bloblist);
// bloblist_dup() - duplicate bloblist
//
// parameters:
// src (in) bloblist to duplicate
//
// return value:
// pointer to a new bloblist_t or NULL if out of memory
//
// caveat:
// this is an expensive operation because all blobs are copied
DYNAMIC_API bloblist_t *bloblist_dup(const bloblist_t *src);
// bloblist_add() - add reference to a blob to bloblist
//
// parameters:
@ -172,7 +186,6 @@ typedef struct _message {
// (plain)
char * longmsg_formatted; // UTF-8 string of long message
// (formatted)
PEP_msg_format format; // format type
bloblist_t * attachments; // blobs with attachements
char * rawmsg_ref; // reference to raw message data
size_t rawmsg_size; // size of raw message data
@ -225,15 +238,25 @@ DYNAMIC_API message *new_message(
// free_message() - free message struct
//
// parameters:
// msg (in) message struct to free
// src (in) message struct to free
//
// caveat:
// raw data as well as referenced other messages aren't freed and remain
// in the ownership of the caller
DYNAMIC_API void free_message(message *msg);
DYNAMIC_API void free_message(message *src);
// message_dup - duplicate message (deep copy)
//
// parameters:
// msg (in) message to duplicate
//
// return value:
// pointer to duplicate of message pointed by msg or NULL
DYNAMIC_API message * message_dup(const message *msg);
// new_message_ref_list() - allocate new message reference list
//
// parameters:
@ -253,6 +276,18 @@ DYNAMIC_API message_ref_list *new_message_ref_list(message *msg);
DYNAMIC_API void free_message_ref_list(message_ref_list *msg_list);
// message_ref_list_dup() - duplicate message reference list
//
// paramters:
// src (in) message_ref_list to duplicate
//
// return value:
// pointer to new message_ref_list or NULL if out of memory
DYNAMIC_API message_ref_list *message_ref_list_dup(
const message_ref_list *src
);
// message_ref_list_add() - add a reference to a message to a message reference
// list
//
@ -280,7 +315,7 @@ struct _PEP_transport_t {
// long messages
bool formatted_message_supported; // flag if this transport supports
// formatted messages
PEP_msg_format native_format; // native format of the transport
PEP_text_format native_text_format; // native format of the transport
};
typedef uint64_t transports_mask;


Loading…
Cancel
Save