Browse Source

...

async_key_management
vb 8 years ago
parent
commit
ad8baae8fe
7 changed files with 95 additions and 53 deletions
  1. +36
    -20
      src/cryptotech.c
  2. +3
    -0
      src/cryptotech.h
  3. +33
    -29
      src/pEpEngine.c
  4. +6
    -0
      src/pEp_internal.h
  5. +2
    -0
      src/pgp_gpg_internal.h
  6. +10
    -2
      src/transport.c
  7. +5
    -2
      src/transport.h

+ 36
- 20
src/cryptotech.c View File

@ -1,4 +1,4 @@
#include "cryptotech.h"
#include "pEp_internal.h"
#ifdef NO_GPG
#include "pgp_netpgp.h"
@ -10,29 +10,45 @@
#include <memory.h>
#include <assert.h>
PEP_STATUS init_cryptotech(PEP_cryptotech_t *cryptotech)
PEP_STATUS init_cryptotech(PEP_SESSION session)
{
pEpSession *_session = (pEpSession *) session;
PEP_cryptotech_t *cryptotech = _session->cryptotech;
PEP_STATUS _status;
assert(PEP_crypt__count == 2);
memset(cryptotech, 0, sizeof(PEP_cryptotech_t) * PEP_crypt__count);
cryptotech[0].id = PEP_crypt_none;
cryptotech[0].unconfirmed_comm_type = PEP_ct_no_encryption;
cryptotech[0].confirmed_comm_type = PEP_ct_no_encryption;
cryptotech[1].id = PEP_crypt_OpenPGP;
cryptotech[1].unconfirmed_comm_type = PEP_ct_OpenPGP_unconfirmed;
cryptotech[1].confirmed_comm_type = PEP_ct_OpenPGP;
cryptotech[1].decrypt_and_verify = pgp_decrypt_and_verify;
cryptotech[1].encrypt_and_sign = pgp_encrypt_and_sign;
cryptotech[1].verify_text = pgp_verify_text;
cryptotech[1].delete_keypair = pgp_delete_keypair;
cryptotech[1].export_key = pgp_export_key;
cryptotech[1].find_keys = pgp_find_keys;
cryptotech[1].generate_keypair = pgp_generate_keypair;
cryptotech[1].get_key_rating = pgp_get_key_rating;
cryptotech[1].import_key = pgp_import_key;
cryptotech[1].recv_key = pgp_recv_key;
cryptotech[1].send_key = pgp_send_key;
cryptotech[PEP_crypt_none].id = PEP_crypt_none;
cryptotech[PEP_crypt_none].unconfirmed_comm_type = PEP_ct_no_encryption;
cryptotech[PEP_crypt_none].confirmed_comm_type = PEP_ct_no_encryption;
_status = pgp_init(_session);
assert(_status == PEP_STATUS_OK);
if (_status != PEP_STATUS_OK) {
free(_session);
return _status;
}
cryptotech[PEP_crypt_OpenPGP].id = PEP_crypt_OpenPGP;
cryptotech[PEP_crypt_OpenPGP].unconfirmed_comm_type = PEP_ct_OpenPGP_unconfirmed;
cryptotech[PEP_crypt_OpenPGP].confirmed_comm_type = PEP_ct_OpenPGP;
cryptotech[PEP_crypt_OpenPGP].decrypt_and_verify = pgp_decrypt_and_verify;
cryptotech[PEP_crypt_OpenPGP].encrypt_and_sign = pgp_encrypt_and_sign;
cryptotech[PEP_crypt_OpenPGP].verify_text = pgp_verify_text;
cryptotech[PEP_crypt_OpenPGP].delete_keypair = pgp_delete_keypair;
cryptotech[PEP_crypt_OpenPGP].export_key = pgp_export_key;
cryptotech[PEP_crypt_OpenPGP].find_keys = pgp_find_keys;
cryptotech[PEP_crypt_OpenPGP].generate_keypair = pgp_generate_keypair;
cryptotech[PEP_crypt_OpenPGP].get_key_rating = pgp_get_key_rating;
cryptotech[PEP_crypt_OpenPGP].import_key = pgp_import_key;
cryptotech[PEP_crypt_OpenPGP].recv_key = pgp_recv_key;
cryptotech[PEP_crypt_OpenPGP].send_key = pgp_send_key;
return PEP_STATUS_OK;
}
void release_cryptotech(PEP_SESSION session)
{
pgp_release(session);
}

+ 3
- 0
src/cryptotech.h View File

@ -72,3 +72,6 @@ typedef struct _PEP_cryptotech_t {
} PEP_cryptotech_t;
typedef uint64_t cryptotech_mask;
PEP_STATUS init_cryptotech(PEP_SESSION session);
void release_cryptotech(PEP_SESSION session);

+ 33
- 29
src/pEpEngine.c View File

@ -1,13 +1,9 @@
#include "pEp_internal.h"
#ifndef NO_GPG
#include "pgp_gpg.h"
#else
#include "pgp_netpgp.h"
#endif
#include "cryptotech.h"
#include "transport.h"
DYNAMIC_API PEP_STATUS init(PEP_SESSION *session)
{
PEP_STATUS status_result;
int int_result;
const char *sql_log;
const char *sql_safeword;
@ -32,16 +28,12 @@ DYNAMIC_API PEP_STATUS init(PEP_SESSION *session)
_session->version = PEP_ENGINE_VERSION;
status_result = pgp_init(_session);
assert(status_result == PEP_STATUS_OK);
if (status_result != PEP_STATUS_OK) {
free(_session);
return status_result;
}
init_cryptotech(_session);
init_transport_system(_session->transports);
assert(LOCAL_DB);
if (LOCAL_DB == NULL) {
pgp_release(session);
release_cryptotech(_session);
free(_session);
return PEP_INIT_CANNOT_OPEN_DB;
}
@ -58,7 +50,7 @@ DYNAMIC_API PEP_STATUS init(PEP_SESSION *session)
if (int_result != SQLITE_OK) {
sqlite3_close_v2(_session->db);
pgp_release(session);
release_cryptotech(_session);
free(_session);
return PEP_INIT_CANNOT_OPEN_DB;
}
@ -68,7 +60,7 @@ DYNAMIC_API PEP_STATUS init(PEP_SESSION *session)
assert(SYSTEM_DB);
if (SYSTEM_DB == NULL) {
sqlite3_close_v2(_session->db);
pgp_release(session);
release_cryptotech(_session);
free(_session);
return PEP_INIT_CANNOT_OPEN_SYSTEM_DB;
}
@ -84,7 +76,7 @@ DYNAMIC_API PEP_STATUS init(PEP_SESSION *session)
if (int_result != SQLITE_OK) {
sqlite3_close_v2(_session->system_db);
sqlite3_close_v2(_session->db);
pgp_release(session);
release_cryptotech(_session);
free(_session);
return PEP_INIT_CANNOT_OPEN_SYSTEM_DB;
}
@ -252,7 +244,9 @@ DYNAMIC_API void release(PEP_SESSION session)
sqlite3_close_v2(_session->db);
sqlite3_close_v2(_session->system_db);
}
pgp_release(session);
release_cryptotech(_session);
release_transport_system(_session);
}
free(_session);
}
@ -280,7 +274,6 @@ stringlist_t *stringlist_add(stringlist_t *stringlist, const char *value)
if (stringlist->next != NULL)
return stringlist_add(stringlist->next, value);
if (stringlist->value == NULL) {
stringlist->value = strdup(value);
assert(stringlist->value);
@ -731,7 +724,8 @@ DYNAMIC_API PEP_STATUS decrypt_and_verify(
char **ptext, size_t *psize, stringlist_t **keylist
)
{
return pgp_decrypt_and_verify(session, ctext, csize, ptext, psize, keylist);
pEpSession *_session = (pEpSession *) session;
return _session->cryptotech[PEP_crypt_OpenPGP].decrypt_and_verify(session, ctext, csize, ptext, psize, keylist);
}
DYNAMIC_API PEP_STATUS encrypt_and_sign(
@ -739,7 +733,8 @@ DYNAMIC_API PEP_STATUS encrypt_and_sign(
size_t psize, char **ctext, size_t *csize
)
{
return pgp_encrypt_and_sign(session, keylist, ptext, psize, ctext, csize);
pEpSession *_session = (pEpSession *) session;
return _session->cryptotech[PEP_crypt_OpenPGP].encrypt_and_sign(session, keylist, ptext, psize, ctext, csize);
}
DYNAMIC_API PEP_STATUS verify_text(
@ -747,33 +742,38 @@ DYNAMIC_API PEP_STATUS verify_text(
const char *signature, size_t sig_size, stringlist_t **keylist
)
{
return pgp_verify_text(session, text, size, signature, sig_size, keylist);
pEpSession *_session = (pEpSession *) session;
return _session->cryptotech[PEP_crypt_OpenPGP].verify_text(session, text, size, signature, sig_size, keylist);
}
DYNAMIC_API PEP_STATUS delete_keypair(PEP_SESSION session, const char *fpr)
{
return pgp_delete_keypair(session, fpr);
pEpSession *_session = (pEpSession *) session;
return _session->cryptotech[PEP_crypt_OpenPGP].delete_keypair(session, fpr);
}
DYNAMIC_API PEP_STATUS export_key(
PEP_SESSION session, const char *fpr, char **key_data, size_t *size
)
{
return pgp_export_key(session, fpr, key_data, size);
pEpSession *_session = (pEpSession *) session;
return _session->cryptotech[PEP_crypt_OpenPGP].export_key(session, fpr, key_data, size);
}
DYNAMIC_API PEP_STATUS find_keys(
PEP_SESSION session, const char *pattern, stringlist_t **keylist
)
{
return pgp_find_keys(session, pattern, keylist);
pEpSession *_session = (pEpSession *) session;
return _session->cryptotech[PEP_crypt_OpenPGP].find_keys(session, pattern, keylist);
}
DYNAMIC_API PEP_STATUS generate_keypair(
PEP_SESSION session, pEp_identity *identity
)
{
return pgp_generate_keypair(session, identity);
pEpSession *_session = (pEpSession *) session;
return _session->cryptotech[PEP_crypt_OpenPGP].generate_keypair(session, identity);
}
DYNAMIC_API PEP_STATUS get_key_rating(
@ -782,20 +782,24 @@ DYNAMIC_API PEP_STATUS get_key_rating(
PEP_comm_type *comm_type
)
{
return pgp_get_key_rating(session, fpr, comm_type);
pEpSession *_session = (pEpSession *) session;
return _session->cryptotech[PEP_crypt_OpenPGP].get_key_rating(session, fpr, comm_type);
}
DYNAMIC_API PEP_STATUS import_key(PEP_SESSION session, const char *key_data, size_t size)
{
return pgp_import_key(session, key_data, size);
pEpSession *_session = (pEpSession *) session;
return _session->cryptotech[PEP_crypt_OpenPGP].import_key(session, key_data, size);
}
DYNAMIC_API PEP_STATUS recv_key(PEP_SESSION session, const char *pattern)
{
return pgp_recv_key(session, pattern);
pEpSession *_session = (pEpSession *) session;
return _session->cryptotech[PEP_crypt_OpenPGP].recv_key(session, pattern);
}
DYNAMIC_API PEP_STATUS send_key(PEP_SESSION session, const char *pattern)
{
return pgp_send_key(session, pattern);
pEpSession *_session = (pEpSession *) session;
return _session->cryptotech[PEP_crypt_OpenPGP].send_key(session, pattern);
}

+ 6
- 0
src/pEp_internal.h View File

@ -55,6 +55,9 @@
#include "pgp_gpg_internal.h"
#endif
#include "cryptotech.h"
#include "transport.h"
#define NOT_IMPLEMENTED assert(0)
typedef struct {
@ -66,6 +69,9 @@ typedef struct {
gpgme_ctx_t ctx;
#endif
PEP_cryptotech_t cryptotech[PEP_crypt__count];
PEP_transport_t transports[PEP_trans__count];
sqlite3 *db;
sqlite3 *system_db;


+ 2
- 0
src/pgp_gpg_internal.h View File

@ -1,3 +1,5 @@
#pragma once
#include <gpgme.h>
// init


+ 10
- 2
src/transport.c View File

@ -1,11 +1,14 @@
#include "transport.h"
#include "pEp_internal.h"
#include <stdlib.h>
#include <memory.h>
#include <assert.h>
PEP_STATUS init_transport_system(PEP_transport_t* transports)
PEP_STATUS init_transport_system(PEP_SESSION session)
{
pEpSession *_session = (pEpSession *) session;
PEP_transport_t* transports = _session->transports;
assert(PEP_trans__count == 1);
memset(transports, 0, sizeof(PEP_transport_t) * PEP_trans__count);
@ -13,3 +16,8 @@ PEP_STATUS init_transport_system(PEP_transport_t* transports)
return PEP_STATUS_OK;
}
void release_transport_system(PEP_SESSION session)
{
// nothing yet
}

+ 5
- 2
src/transport.h View File

@ -4,8 +4,8 @@
typedef enum _PEP_transports {
PEP_trans_auto = 0,
// PEP_trans_email = 1,
// PEP_trans_whatsapp = 2,
// PEP_trans_email,
// PEP_trans_whatsapp,
PEP_trans__count
} PEP_transports;
@ -22,3 +22,6 @@ struct _PEP_transport_t {
};
typedef uint64_t transports_mask;
PEP_STATUS init_transport_system(PEP_SESSION session);
void release_transport_system(PEP_SESSION session);

Loading…
Cancel
Save