diff options
Diffstat (limited to 'src/analysis/db/client.c')
-rw-r--r-- | src/analysis/db/client.c | 56 |
1 files changed, 43 insertions, 13 deletions
diff --git a/src/analysis/db/client.c b/src/analysis/db/client.c index 2a5a185..bb900ed 100644 --- a/src/analysis/db/client.c +++ b/src/analysis/db/client.c @@ -35,6 +35,7 @@ #include <i18n.h> +#include "keymgn.h" #include "protocol.h" #include "misc/rlestr.h" #include "../../common/io.h" @@ -47,6 +48,9 @@ struct _GDbClient { GObject parent; /* A laisser en premier */ + char *author; /* Utilisateur représenté */ + char *key_file; /* Accès sa la clef privée */ + const char *name; /* Désignation du binaire */ rle_string hash; /* Empreinte du binaire lié */ @@ -141,6 +145,9 @@ static void g_db_client_init(GDbClient *client) static void g_db_client_finalize(GDbClient *client) { + free(client->author); + free(client->key_file); + unset_rle_string(&client->hash); G_OBJECT_CLASS(g_db_client_parent_class)->finalize(G_OBJECT(client)); @@ -150,24 +157,29 @@ static void g_db_client_finalize(GDbClient *client) /****************************************************************************** * * -* Paramètres : name = désignation humaine du binaire associé. * +* Paramètres : author = utilisateur à représenter via le client. * +* kfile = clef menant à sa clef privée. * +* name = désignation humaine du binaire associé. * * hash = empreinte d'un binaire en cours d'analyse. * * collections = ensemble de collections existantes. * * * * Description : Prépare un client pour une connexion à une BD. * * * -* Retour : Structure mise en plae ou NULL en cas d'échec. * +* Retour : Structure mise en place ou NULL en cas d'échec. * * * * Remarques : - * * * ******************************************************************************/ -GDbClient *g_db_client_new(const char *name, const char *hash, GList *collections) +GDbClient *g_db_client_new(char *author, char *kfile, const char *name, const char *hash, GList *collections) { GDbClient *result; /* Adresse à retourner */ result = g_object_new(G_TYPE_DB_CLIENT, NULL); + result->author = author; + result->key_file = kfile; + result->name = name; set_rle_string(&result->hash, hash); @@ -180,10 +192,9 @@ GDbClient *g_db_client_new(const char *name, const char *hash, GList *collection /****************************************************************************** * * -* Paramètres : client = client pour les accès distants à manipuler. * -* host = hôte à représenter pour le service. * -* port = port de connexion pour les clients. * -* username = utilisateur effectuant les évolutions. * +* Paramètres : client = client pour les accès distants à manipuler. * +* host = hôte à représenter pour le service. * +* port = port de connexion pour les clients. * * * * Description : Démarre la connexion à la base de données. * * * @@ -193,12 +204,16 @@ GDbClient *g_db_client_new(const char *name, const char *hash, GList *collection * * ******************************************************************************/ -bool g_db_client_start(GDbClient *client, const char *host, unsigned short port, const char *username) +bool g_db_client_start(GDbClient *client, const char *host, unsigned short port) { struct hostent *hp; /* Informations sur l'hôte */ struct sockaddr_in addr; /* Adresse de transmission */ int ret; /* Bilan d'un appel */ rle_string user; /* Nom d'utilisateur associé */ + GChecksum *checksum; /* Empreinte MD5 à signer */ + unsigned char md5_digest[16]; /* Empreinte MD5 calculée */ + RSA *key; /* Clef pour la signature */ + unsigned char sig[RSA_USED_SIZE]; /* Signature effectuée */ uint32_t data; /* Mot de données lues */ DBError error; /* Validation de la connexion */ @@ -228,16 +243,13 @@ bool g_db_client_start(GDbClient *client, const char *host, unsigned short port, goto gdcs_no_listening; } - /* Préparation du nom d'utilisateur à diffuser */ - - init_rle_string(&user, username); - /** * On réalise l'envoi initial ; le premier paquet doit contenir : * - la commande 'DBC_HELO'. * - le numéro de version du client. * - l'empreinte du binaire analysé. * - l'identifiant de l'utilisateur effectuant des modifications. + * - la signature de l'empreinte MD5 de l'identifiant. * * Tout ceci est à synchroniser avec la fonction g_db_server_listener(). */ @@ -251,7 +263,25 @@ bool g_db_client_start(GDbClient *client, const char *host, unsigned short port, if (!send_rle_string(&client->hash, client->fd, MSG_MORE)) goto gdcs_error; - if (!send_rle_string(&user, client->fd, 0)) + init_rle_string(&user, client->author); + + if (!send_rle_string(&user, client->fd, MSG_MORE)) + goto gdcs_error; + + checksum = g_checksum_new(G_CHECKSUM_MD5); + g_checksum_update(checksum, (guchar *)get_rle_string(&user), get_rle_length(&user)); + g_checksum_get_digest(checksum, (guint8 *)md5_digest, (gsize []) { sizeof(md5_digest) }); + g_checksum_free(checksum); + + key = load_rsa_key(client->key_file, true); + if (key == NULL) goto gdcs_error; + + if (!sign_md5_hash(key, md5_digest, sig)) + goto gdcs_error; + + RSA_free(key); + + if (!safe_send(client->fd, sig, RSA_USED_SIZE, 0)) goto gdcs_error; /** |