Browse Source

encrypt in pieces

async_key_management
vb 8 years ago
parent
commit
41a37f7b91
6 changed files with 199 additions and 35 deletions
  1. +2
    -2
      Makefile.conf
  2. +2
    -1
      src/Makefile
  3. +100
    -15
      src/message_api.c
  4. +8
    -1
      src/message_api.h
  5. +61
    -3
      src/transport.c
  6. +26
    -13
      src/transport.h

+ 2
- 2
Makefile.conf View File

@ -1,7 +1,7 @@
BUILD_ON=$(shell uname)
BUILD_FOR=$(BUILD_ON)
#OPTIMIZE=-g -O0
OPTIMIZE=-O3 -DNDEBUG
OPTIMIZE=-g -O0
#OPTIMIZE=-O3 -DNDEBUG
# the next two lines are ignored on Windoze
SYSTEM_DB=/usr/local/share/pEp/system.db
PREFIX=$(HOME)

+ 2
- 1
src/Makefile View File

@ -10,7 +10,8 @@ LIBGPGME=libgpgme-pthread.dylib
CC=gcc -std=c99
CFLAGS=-I$(GPGME_IN)/include -I/opt/local/include $(OPTIMIZE) -pedantic \
-DSYSTEM_DB=\"$(SYSTEM_DB)\" -DLIBGPGME=\"$(LIBGPGME)\" -DSQLITE_THREADSAFE=1
LDFLAGS=-lc -macosx_version_min $(MACOSX_VERSION_MIN) -dylib -arch x86_64
LDFLAGS=-lc -macosx_version_min $(MACOSX_VERSION_MIN) -dylib -arch x86_64 \
-L/opt/local/lib -letpan
else ifeq ($(BUILD_FOR),Windoze)


+ 100
- 15
src/message_api.c View File

@ -9,29 +9,32 @@ PEP_STATUS encrypt_message(
PEP_SESSION session,
const message *src,
stringlist_t * extra,
message **dst
message **dst,
PEP_enc_format format
)
{
PEP_STATUS status = PEP_STATUS_OK;
assert(session);
assert(src);
assert(src->shortmsg || src->longmsg);
assert(dst);
*dst = NULL;
assert(format != PEP_enc_none);
message *msg = new_message(src->dir, src->from, src->to, NULL);
if (msg == NULL)
return PEP_OUT_OF_MEMORY;
src->from->me = true;
msg->from->me = true;
status = myself(session, src->from);
status = myself(session, msg->from);
if (status != PEP_STATUS_OK) {
free_message(msg);
return status;
}
stringlist_t * keys = new_stringlist(src->from->fpr);
stringlist_t * keys = new_stringlist(msg->from->fpr);
if (keys == NULL) {
free_message(msg);
return PEP_OUT_OF_MEMORY;
@ -47,7 +50,7 @@ PEP_STATUS encrypt_message(
}
identity_list * _il;
for (_il = src->to; _il && _il->ident; _il = _il->next) {
for (_il = msg->to; _il && _il->ident; _il = _il->next) {
status = update_identity(session, _il->ident);
if (status != PEP_STATUS_OK) {
free_message(msg);
@ -70,21 +73,103 @@ PEP_STATUS encrypt_message(
_own_keys += stringlist_length(extra);
if (stringlist_length(keys) > _own_keys) {
char *ptext = NULL;
char *ptext;
char *ctext = NULL;
size_t csize = 0;
// TODO: set ptext to MIME text
switch (format) {
case PEP_enc_MIME_multipart:
break;
status = encrypt_and_sign(session, keys, ptext, strlen(ptext), &ctext, &csize);
if (ctext) {
msg->longmsg = ctext;
msg->longmsg_size = csize;
*dst = msg;
case PEP_enc_pieces:
if (src->shortmsg && src->longmsg) {
ptext = calloc(1, strlen(src->shortmsg) + strlen(src->longmsg) + 12);
if (ptext == NULL) {
free_message(msg);
free_stringlist(keys);
return PEP_OUT_OF_MEMORY;
}
strcpy(ptext, "subject: ");
strcat(ptext, src->shortmsg);
strcat(ptext, "\n\n");
strcat(ptext, src->longmsg);
status = encrypt_and_sign(session, keys, ptext, strlen(ptext), &ctext, &csize);
if (ctext) {
msg->longmsg = ctext;
msg->longmsg_size = csize;
msg->shortmsg = strdup("pEp");
}
else {
free_message(msg);
msg = NULL;
}
}
else if (src->shortmsg) {
ptext = src->shortmsg;
status = encrypt_and_sign(session, keys, ptext, strlen(ptext), &ctext, &csize);
if (ctext) {
msg->shortmsg = ctext;
msg->shortmsg_size = csize;
}
else {
free_message(msg);
msg = NULL;
}
}
else if (src->longmsg) {
ptext = src->longmsg;
status = encrypt_and_sign(session, keys, ptext, strlen(ptext), &ctext, &csize);
if (ctext) {
msg->longmsg = ctext;
msg->longmsg_size = csize;
msg->shortmsg = strdup("pEp");
}
else {
free_message(msg);
msg = NULL;
}
}
if (msg && msg->longmsg_formatted) {
ptext = src->longmsg_formatted;
status = encrypt_and_sign(session, keys, ptext, strlen(ptext), &ctext, &csize);
if (ctext) {
msg->longmsg_formatted = ctext;
msg->longmsg_formatted_size = csize;
}
else {
free_message(msg);
msg = NULL;
}
}
if (msg) {
bloblist_t *_s;
bloblist_t *_d = new_bloblist(NULL, 0);
if (_d == NULL) {
free_message(msg);
free_stringlist(keys);
return PEP_OUT_OF_MEMORY;
}
msg->attachments = _d;
for (_s = src->attachments; _s && _s->data_ref; _s = _s->next) {
int psize = _s->size;
ptext = _s->data_ref;
status = encrypt_and_sign(session, keys, ptext, psize, &ctext, &csize);
if (ctext) {
_d = bloblist_add(_d, ctext, csize);
}
else {
free_message(msg);
msg = NULL;
break;
}
}
*dst = msg;
}
break;
default:
assert(0);
}
else
free_message(msg);
free(ptext);
}
else
free_message(msg);


+ 8
- 1
src/message_api.h View File

@ -4,11 +4,18 @@ extern "C" {
#include "transport.h"
typedef enum _PEP_enc_format {
PEP_enc_none = 0,
PEP_enc_MIME_multipart,
PEP_enc_pieces
} PEP_enc_format;
PEP_STATUS encrypt_message(
PEP_SESSION session,
const message *src,
stringlist_t *extra,
message **dst
message **dst,
PEP_enc_format format
);
PEP_STATUS decrypt_message(


+ 61
- 3
src/transport.c View File

@ -74,9 +74,11 @@ void free_identity_list(identity_list *id_list)
identity_list *identity_list_add(identity_list *id_list, const pEp_identity *ident)
{
assert(id_list);
assert(ident);
if (id_list == NULL)
return new_identity_list(ident);
if (id_list->ident == NULL) {
id_list->ident = identity_dup(ident);
assert(id_list->ident);
@ -95,8 +97,61 @@ identity_list *identity_list_add(identity_list *id_list, const pEp_identity *ide
}
}
bloblist_t *new_bloblist(char *blob, size_t size)
{
bloblist_t * bloblist = calloc(1, sizeof(bloblist_t));
if (bloblist == NULL)
return NULL;
bloblist->data_ref = blob;
bloblist->size = size;
return bloblist;
}
bloblist_t *bloblist_dup(const bloblist_t *src)
{
assert(src);
if (src) {
bloblist_t * dst = new_bloblist(src->data_ref, src->size);
if (dst == NULL)
return NULL;
dst->next = bloblist_dup(src->next);
return dst;
}
else
return NULL;
}
void free_bloblist(bloblist_t *bloblist)
{
if (bloblist && bloblist->next)
free_bloblist(bloblist->next);
free(bloblist);
}
bloblist_t *bloblist_add(bloblist_t *bloblist, char *blob, size_t size)
{
assert(blob);
if (bloblist == NULL)
return new_bloblist(blob, size);
if (bloblist->data_ref == NULL) {
bloblist->data_ref = blob;
bloblist->size = size;
return bloblist;
}
if (bloblist->next == NULL) {
bloblist->next = new_bloblist(blob, size);
return bloblist->next;
}
return bloblist_add(bloblist->next, blob, size);
}
message *new_message(
msg_direction dir,
PEP_msg_direction dir,
const pEp_identity *from,
const identity_list *to,
const char *shortmsg
@ -142,6 +197,7 @@ void free_message(message *msg)
free(msg->shortmsg);
free(msg->longmsg);
free(msg->longmsg_formatted);
free_bloblist(msg->attachments);
free(msg->rawmsg);
free_identity_list(msg->to);
free_identity_list(msg->cc);
@ -173,9 +229,11 @@ void free_message_ref_list(message_ref_list *msg_list)
message_ref_list *message_ref_list_add(message_ref_list *msg_list, message *msg)
{
assert(msg_list);
assert(msg);
if (msg_list == NULL)
return new_message_ref_list(msg);
if (msg_list->msg_ref == NULL) {
msg_list->msg_ref = msg;
return msg_list;


+ 26
- 13
src/transport.h View File

@ -29,20 +29,31 @@ identity_list *identity_list_dup(const identity_list *src);
void free_identity_list(identity_list *id_list);
identity_list *identity_list_add(identity_list *id_list, const pEp_identity *ident);
typedef enum _msg_format {
format_plain = 0,
format_html
} msg_format;
typedef enum _msg_direction {
dir_incoming = 0,
dir_outgoing
} msg_direction;
typedef enum _PEP_msg_format {
PEP_format_plain = 0,
PEP_format_html
} PEP_msg_format;
typedef enum _PEP_msg_direction {
PEP_dir_incoming = 0,
PEP_dir_outgoing
} PEP_msg_direction;
typedef struct _bloblist_t {
char *data_ref;
size_t size;
struct _bloblist_t *next;
} bloblist_t;
bloblist_t *new_bloblist(char *blob, size_t size);
bloblist_t *bloblist_dup(const bloblist_t *src);
void free_bloblist(bloblist_t *bloblist);
bloblist_t *bloblist_add(bloblist_t *bloblist, char *blob, size_t size);
struct _message_ref_list;
typedef struct _message {
msg_direction dir;
PEP_msg_direction dir;
char * id;
size_t id_size;
char * shortmsg;
@ -51,7 +62,8 @@ typedef struct _message {
size_t longmsg_size;
char * longmsg_formatted;
size_t longmsg_formatted_size;
msg_format format;
PEP_msg_format format;
bloblist_t * attachments;
char * rawmsg;
size_t rawmsg_size;
timestamp sent;
@ -65,6 +77,7 @@ typedef struct _message {
size_t refering_id_size;
struct _message *refering_msg;
struct _message_ref_list *refered_by;
bool encrypted;
} message;
typedef struct _message_ref_list {
@ -73,7 +86,7 @@ typedef struct _message_ref_list {
} message_ref_list;
message *new_message(
msg_direction dir,
PEP_msg_direction dir,
const pEp_identity *from,
const identity_list *to,
const char *shortmsg
@ -93,7 +106,7 @@ struct _PEP_transport_t {
sendto_t sendto;
readnext_t readnext;
bool long_message_supported;
msg_format native_format;
PEP_msg_format native_format;
};
typedef uint64_t transports_mask;


Loading…
Cancel
Save