diff options
author | Paul Fariello <paul@fariello.eu> | 2019-02-19 19:38:40 +0140 |
---|---|---|
committer | Paul Fariello <paul@fariello.eu> | 2019-04-08 11:50:12 +0200 |
commit | 519cf295f31d77bec45644424f7212e9fb2692e8 (patch) | |
tree | 799735d4b5033b392a185493a6733803207972ce /src/omemo | |
parent | bfbc8edcad16e576041d7a81a4d58c70fa17a3fa (diff) | |
download | profani-tty-519cf295f31d77bec45644424f7212e9fb2692e8.tar.gz |
Add signal-protocol locking
Diffstat (limited to 'src/omemo')
-rw-r--r-- | src/omemo/omemo.c | 38 | ||||
-rw-r--r-- | src/omemo/omemo.h | 2 |
2 files changed, 36 insertions, 4 deletions
diff --git a/src/omemo/omemo.c b/src/omemo/omemo.c index 871f3bfc..96e07d1c 100644 --- a/src/omemo/omemo.c +++ b/src/omemo/omemo.c @@ -1,13 +1,24 @@ +#include <pthread.h> #include <signal/signal_protocol.h> #include "config/account.h" #include "ui/ui.h" +#include "omemo/omemo.h" #include "omemo/crypto.h" +static void lock(void *user_data); +static void unlock(void *user_data); + +struct omemo_context_t { + pthread_mutexattr_t attr; + pthread_mutex_t lock; +}; + void omemo_init(ProfAccount *account) { - signal_context *global_context; + signal_context *signal_ctx; + omemo_context *ctx = malloc(sizeof(omemo_context)); signal_crypto_provider crypto_provider = { .random_func = omemo_random_func, .hmac_sha256_init_func = omemo_hmac_sha256_init_func, @@ -27,14 +38,33 @@ omemo_init(ProfAccount *account) cons_show("Error initializing Omemo crypto"); } - if (signal_context_create(&global_context, NULL) != 0) { + pthread_mutexattr_init(&ctx->attr); + pthread_mutexattr_settype(&ctx->attr, PTHREAD_MUTEX_RECURSIVE); + pthread_mutex_init(&ctx->lock, &ctx->attr); + + if (signal_context_create(&signal_ctx, ctx) != 0) { cons_show("Error initializing Omemo context"); return; } - if (signal_context_set_crypto_provider(global_context, &crypto_provider) != 0) { + if (signal_context_set_crypto_provider(signal_ctx, &crypto_provider) != 0) { cons_show("Error initializing Omemo crypto"); return; } - //signal_context_set_locking_functions(global_context, lock_function, unlock_function); + + signal_context_set_locking_functions(signal_ctx, lock, unlock); +} + +static void +lock(void *user_data) +{ + omemo_context *ctx = (omemo_context *)user_data; + pthread_mutex_lock(&ctx->lock); +} + +static void +unlock(void *user_data) +{ + omemo_context *ctx = (omemo_context *)user_data; + pthread_mutex_unlock(&ctx->lock); } diff --git a/src/omemo/omemo.h b/src/omemo/omemo.h index 2ca1c221..d34b90bf 100644 --- a/src/omemo/omemo.h +++ b/src/omemo/omemo.h @@ -1,3 +1,5 @@ #include "config/account.h" +typedef struct omemo_context_t omemo_context; + void omemo_init(ProfAccount *account); |