summaryrefslogtreecommitdiff
path: root/src/analysis
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2019-08-29 22:16:59 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2019-08-29 22:16:59 (GMT)
commit14f1b8ff552dfb8aef6c66b3c65e816aa7820bb0 (patch)
tree735e01df60a21d6c9ecb961af36ab61aefec6d2f /src/analysis
parentfa40856e942a7e1bd1cb2729645182c1fa717468 (diff)
Removed code relative to the old share server version.
Diffstat (limited to 'src/analysis')
-rw-r--r--src/analysis/Makefile.am1
-rw-r--r--src/analysis/binary.c79
-rw-r--r--src/analysis/binary.h4
-rw-r--r--src/analysis/db/Makefile.am16
-rw-r--r--src/analysis/db/item.c14
-rw-r--r--src/analysis/db/keymgn.c707
-rw-r--r--src/analysis/db/keymgn.h81
7 files changed, 26 insertions, 876 deletions
diff --git a/src/analysis/Makefile.am b/src/analysis/Makefile.am
index 39b960c..c1fbc9f 100644
--- a/src/analysis/Makefile.am
+++ b/src/analysis/Makefile.am
@@ -21,7 +21,6 @@ libanalysis_la_SOURCES = \
libanalysis_la_LIBADD = \
contents/libanalysiscontents.la \
db/libanalysisdb.la \
- db/libanalysiskeys.la \
disass/libanalysisdisass.la \
human/libanalysishuman.la \
types/libanalysistypes.la
diff --git a/src/analysis/binary.c b/src/analysis/binary.c
index 5ac8e04..ec129b1 100644
--- a/src/analysis/binary.c
+++ b/src/analysis/binary.c
@@ -70,7 +70,7 @@ struct _GLoadedBinary
bool use_remote; /* Enregistrements distants ? */
char *remote_host; /* Nom du serveur distant */
- unsigned short remote_port; /* Port du serveur distant */
+ char *remote_port; /* Port du serveur distant */
GHubClient *local; /* Enregistrements locaux */
GHubClient *remote; /* Enregistrements distants */
@@ -246,7 +246,7 @@ static void g_loaded_binary_init(GLoadedBinary *binary)
binary->use_remote = false;
binary->remote_host = strdup("localhost");
- binary->remote_port = 1337;
+ binary->remote_port = strdup("1337");
binary->storages[DBF_BOOKMARKS] = DBS_ALL_LOCAL;
binary->storages[DBF_COMMENTS] = DBS_ALL_LOCAL;
@@ -446,7 +446,7 @@ static bool g_loaded_binary_load_storage(GLoadedBinary *binary, xmlXPathContext
char *storage_path; /* Partie "Enregistrement" */
char *value; /* Valeur lue à partie du XML */
char *access; /* Chemin d'accès à un élément */
- unsigned short port; /* Port de communication */
+ char *port; /* Port de communication */
DBFeatures i; /* Boucle de parcours */
result = true;
@@ -484,17 +484,21 @@ static bool g_loaded_binary_load_storage(GLoadedBinary *binary, xmlXPathContext
value = get_node_prop_value(context, access, "port");
if (value == NULL) goto glbls_features;
- port = atoi(value);
-
- free(value);
+ port = value;
value = get_node_prop_value(context, access, "host");
- if (value == NULL) goto glbls_features;
+ if (value == NULL)
+ {
+ free(port);
+ goto glbls_features;
+ }
g_loaded_binary_set_remote_server(binary, value, port);
free(value);
+ free(port);
+
glbls_features:
free(access);
@@ -571,7 +575,6 @@ static bool g_loaded_binary_save_storage(const GLoadedBinary *binary, xmlDoc *xd
bool result; /* Bilan à faire remonter */
char *storage_path; /* Partie "Enregistrement" */
char *access; /* Chemin d'accès à un élément */
- char port_str[sizeof(XSTR(USHRT_MAX)) + 1]; /* Version chaînée */
DBFeatures i; /* Boucle de parcours */
result = true;
@@ -598,8 +601,7 @@ static bool g_loaded_binary_save_storage(const GLoadedBinary *binary, xmlDoc *xd
result &= add_string_attribute_to_node(xdoc, context, access, "host", binary->remote_host);
- sprintf(port_str, "%hu", binary->remote_port);
- result &= add_string_attribute_to_node(xdoc, context, access, "port", port_str);
+ result &= add_string_attribute_to_node(xdoc, context, access, "port", binary->remote_port);
free(access);
@@ -747,7 +749,7 @@ void g_loaded_binary_set_remote_storage_usage(GLoadedBinary *binary, bool use)
* *
******************************************************************************/
-void g_loaded_binary_get_remote_server(const GLoadedBinary *binary, const char **host, unsigned short *port)
+void g_loaded_binary_get_remote_server(const GLoadedBinary *binary, const char **host, const char **port)
{
*host = binary->remote_host;
*port = binary->remote_port;
@@ -769,12 +771,13 @@ void g_loaded_binary_get_remote_server(const GLoadedBinary *binary, const char *
* *
******************************************************************************/
-void g_loaded_binary_set_remote_server(GLoadedBinary *binary, const char *host, unsigned short port)
+void g_loaded_binary_set_remote_server(GLoadedBinary *binary, const char *host, const char *port)
{
free(binary->remote_host);
binary->remote_host = strdup(host);
- binary->remote_port = port;
+ free(binary->remote_port);
+ binary->remote_port = strdup(port);
}
@@ -835,25 +838,9 @@ void g_loaded_binary_set_storage(GLoadedBinary *binary, DBFeatures feature, DBSt
static bool g_loaded_binary_connect_internal(GLoadedBinary *binary)
{
bool result; /* Bilan à retourner */
- const char *tmp; /* Stockage temporaire */
- char *author; /* Identification à diffuser */
- char *priv; /* Chemin de la clef privée */
GBinContent *content; /* Contenu bianire manipulé */
const gchar *checksum; /* Identifiant de binaire */
- result = false;
-
- /* Utilisateur représenté */
-
- if (!g_generic_config_get_value(get_main_configuration(), MPK_AUTHOR_NAME, &tmp))
- goto glbcl_exit;
-
- author = strdup(tmp);
-
- /* Chemin vers la clef privée */
-
- priv = get_xdg_config_dir("chrysalide" G_DIR_SEPARATOR_S "id_rsa.priv");
-
/* Détermination de l'identifiant */
content = g_binary_format_get_content(G_BIN_FORMAT(binary->format));
@@ -862,15 +849,10 @@ static bool g_loaded_binary_connect_internal(GLoadedBinary *binary)
/* Tentative de connexion */
- binary->local = g_hub_client_new(/*author, priv,
- g_loaded_binary_get_name(binary, false),
- */checksum,
- binary->collections);
+ binary->local = g_hub_client_new(checksum, binary->collections);
result = g_hub_client_start_internal(binary->local);
- glbcl_exit:
-
return result;
}
@@ -891,27 +873,11 @@ static bool g_loaded_binary_connect_internal(GLoadedBinary *binary)
static bool g_loaded_binary_connect_remote(GLoadedBinary *binary)
{
bool result; /* Bilan à retourner */
- const char *tmp; /* Stockage temporaire */
- char *author; /* Identification à diffuser */
- char *priv; /* Chemin de la clef privée */
GBinContent *content; /* Contenu bianire manipulé */
const gchar *checksum; /* Identifiant de binaire */
- result = false;
-
assert(binary->remote == NULL);
- /* Utilisateur représenté */
-
- if (!g_generic_config_get_value(get_main_configuration(), MPK_AUTHOR_NAME, &tmp))
- goto glbcl_exit;
-
- author = strdup(tmp);
-
- /* Chemin vers la clef privée */
-
- priv = get_xdg_config_dir("chrysalide" G_DIR_SEPARATOR_S "id_rsa.priv");
-
/* Détermination de l'identifiant */
content = g_binary_format_get_content(G_BIN_FORMAT(binary->format));
@@ -920,24 +886,19 @@ static bool g_loaded_binary_connect_remote(GLoadedBinary *binary)
/* Tentative de connexion */
- binary->remote = g_hub_client_new(/*author, priv,
- g_loaded_binary_get_name(binary, false),
- */checksum,
- binary->collections);
+ binary->remote = g_hub_client_new(checksum, binary->collections);
- result = g_hub_client_start_remote(binary->local, binary->remote_host, "1337", true);//binary->remote_port);
+ result = g_hub_client_start_remote(binary->local, binary->remote_host, binary->remote_port, true);
if (!result)
{
- log_variadic_message(LMT_ERROR, _("Failed to connect to remote host '%s:%hu'"),
+ log_variadic_message(LMT_ERROR, _("Failed to connect to remote host '%s:%s'"),
binary->remote_host, binary->remote_port);
g_clear_object(&binary->remote);
}
- glbcl_exit:
-
return result;
}
diff --git a/src/analysis/binary.h b/src/analysis/binary.h
index 2c57283..9b3aa6b 100644
--- a/src/analysis/binary.h
+++ b/src/analysis/binary.h
@@ -97,10 +97,10 @@ bool g_loaded_binary_use_remote_storage(const GLoadedBinary *);
void g_loaded_binary_set_remote_storage_usage(GLoadedBinary *, bool);
/* Identifie le serveur distant associé au binaire courant. */
-void g_loaded_binary_get_remote_server(const GLoadedBinary *, const char **, unsigned short *);
+void g_loaded_binary_get_remote_server(const GLoadedBinary *, const char **, const char **);
/* Définit le serveur distant associé au binaire courant. */
-void g_loaded_binary_set_remote_server(GLoadedBinary *, const char *, unsigned short);
+void g_loaded_binary_set_remote_server(GLoadedBinary *, const char *, const char *);
/* Indique la forme d'enregistrement d'une fonctionnalité. */
DBStorage g_loaded_binary_get_storage(const GLoadedBinary *, DBFeatures);
diff --git a/src/analysis/db/Makefile.am b/src/analysis/db/Makefile.am
index 2f7cddd..b3616bd 100644
--- a/src/analysis/db/Makefile.am
+++ b/src/analysis/db/Makefile.am
@@ -1,5 +1,5 @@
-noinst_LTLIBRARIES = libanalysisdb.la libanalysiskeys.la
+noinst_LTLIBRARIES = libanalysisdb.la
libanalysisdb_la_SOURCES = \
@@ -18,7 +18,7 @@ libanalysisdb_la_LIBADD = \
items/libanalysisdbitems.la \
misc/libanalysisdbmisc.la
-libanalysisdb_la_LDFLAGS =
+libanalysisdb_la_LDFLAGS = $(LIBSSL_LIBS)
devdir = $(includedir)/chrysalide/$(subdir:src/%=%)
@@ -26,17 +26,7 @@ devdir = $(includedir)/chrysalide/$(subdir:src/%=%)
dev_HEADERS = $(libanalysisdb_la_SOURCES:%c=)
-libanalysiskeys_la_SOURCES = \
- keymgn.h keymgn.c
-
-libanalysiskeys_la_LIBADD =
-
-libanalysiskeys_la_CFLAGS = $(LIBSSL_CFLAGS)
-
-libanalysiskeys_la_LDFLAGS = $(LIBSSL_LIBS)
-
-
-AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBARCHIVE_CFLAGS) $(LIBSQLITE_CFLAGS)
+AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBARCHIVE_CFLAGS) $(LIBSQLITE_CFLAGS) $(LIBSSL_CFLAGS)
AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS)
diff --git a/src/analysis/db/item.c b/src/analysis/db/item.c
index 6fa168f..2bbc683 100644
--- a/src/analysis/db/item.c
+++ b/src/analysis/db/item.c
@@ -116,19 +116,7 @@ static void g_db_item_class_init(GDbItemClass *klass)
static void g_db_item_init(GDbItem *item)
{
- const char *author; /* Identification à diffuser */
-#ifndef NDEBUG
- bool status; /* Bilan d'une obtention */
-#endif
-
-#ifndef NDEBUG
- status = g_generic_config_get_value(get_main_configuration(), MPK_AUTHOR_NAME, &author);
- assert(status);
-#else
- g_generic_config_get_value(get_main_configuration(), MPK_AUTHOR_NAME, &author);
-#endif
-
- set_static_rle_string(&item->author, author);
+ set_static_rle_string(&item->author, "");
item->is_volatile = false;
diff --git a/src/analysis/db/keymgn.c b/src/analysis/db/keymgn.c
deleted file mode 100644
index d2abd7c..0000000
--- a/src/analysis/db/keymgn.c
+++ /dev/null
@@ -1,707 +0,0 @@
-
-/* Chrysalide - Outil d'analyse de fichiers binaires
- * keymgn.c - mise en place et gestion des clefs cryptographiques
- *
- * Copyright (C) 2016-2017 Cyrille Bagard
- *
- * This file is part of Chrysalide.
- *
- * Chrysalide is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * Chrysalide is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Chrysalide. If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-#include "keymgn.h"
-
-
-#include <ctype.h>
-#include <stdlib.h>
-#include <string.h>
-
-
-#include "../../common/extstr.h"
-#include "../../common/pathname.h"
-#include "../../common/xdg.h"
-#include "../../core/params.h"
-
-
-
-/* Mémorise en mémoire la définition d'une identité courante. */
-static void store_identity(const x509_entries *, bool);
-
-
-
-/******************************************************************************
-* *
-* Paramètres : client = précise la nature de l'identité à représenter. *
-* entries = éléments d'identité à définir en mémoire. [OUT] *
-* *
-* Description : Charge en mémoire la définition de l'identité courante. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-void load_identity(bool client, x509_entries *entries)
-{
- GGenConfig *config; /* Configuration à manipuler */
- const char *path; /* Accès à la configuration */
- char *saved; /* Valeur sauvegardée */
- char *username; /* Dénomination affichée */
- char *lang; /* Langage de l'utilisateur */
- size_t length; /* Taille de valeur récupérée */
- size_t first; /* Indice de première majuscule*/
- size_t i; /* Boucle de parcours */
-
- memset(entries, 0, sizeof(x509_entries));
-
- /* Chargement à partir des sauvegardes */
-
- config = get_main_configuration();
-
- path = (client ? MPK_IDENTITY_CLIENT_C : MPK_IDENTITY_SERVER_C);
-
- if (g_generic_config_get_value(get_main_configuration(), path, &saved))
- entries->country = (saved != NULL ? strdup(saved) : NULL);
-
- path = (client ? MPK_IDENTITY_CLIENT_ST : MPK_IDENTITY_SERVER_ST);
-
- if (g_generic_config_get_value(get_main_configuration(), path, &saved))
- entries->state = (saved != NULL ? strdup(saved) : NULL);
-
- path = (client ? MPK_IDENTITY_CLIENT_L : MPK_IDENTITY_SERVER_L);
-
- if (g_generic_config_get_value(get_main_configuration(), path, &saved))
- entries->locality = (saved != NULL ? strdup(saved) : NULL);
-
- path = (client ? MPK_IDENTITY_CLIENT_O : MPK_IDENTITY_SERVER_O);
-
- if (g_generic_config_get_value(get_main_configuration(), path, &saved))
- entries->organisation = (saved != NULL ? strdup(saved) : NULL);
-
- path = (client ? MPK_IDENTITY_CLIENT_OU : MPK_IDENTITY_SERVER_OU);
-
- if (g_generic_config_get_value(get_main_configuration(), path, &saved))
- entries->organisational_unit = (saved != NULL ? strdup(saved) : NULL);
-
- path = (client ? MPK_IDENTITY_CLIENT_CN : MPK_IDENTITY_SERVER_CN);
-
- if (g_generic_config_get_value(get_main_configuration(), path, &saved))
- entries->common_name = (saved != NULL ? strdup(saved) : NULL);
-
- /* Si les valeurs n'étaient pas définies... */
-
- if (are_x509_entries_empty(entries))
- {
- /* Identification de l'utilisateur */
-
- username = getenv("USERNAME");
-
- if (username == NULL)
- username = getenv("USER");
-
- if (username == NULL)
- username = getenv("LOGNAME");
-
- if (username != NULL)
- entries->common_name = strdup(username);
- else
- entries->common_name = strdup("???");
-
- /* Identification du pays */
-
- lang = getenv("LANG");
-
- if (lang != NULL)
- {
- length = strlen(lang);
-
- first = length;
-
- for (i = 0; i < length; i++)
- {
- if (isupper(lang[i]))
- {
- if (first == length)
- first = i;
- }
-
- else if (first != length)
- {
- entries->country = strndup(&lang[first], i - first);
- break;
- }
-
- }
-
- }
-
- if (entries->country == NULL)
- entries->country = strdup("??");
-
- }
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : entries = éléments d'identité à conserver en mémoire. *
-* client = précise la nature de l'identité représentée. *
-* *
-* Description : Mémorise en mémoire la définition d'une identité courante. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static void store_identity(const x509_entries *entries, bool client)
-{
- GGenConfig *config; /* Configuration à manipuler */
- const char *path; /* Accès à la configuration */
-
- config = get_main_configuration();
-
- path = (client ? MPK_IDENTITY_CLIENT_C : MPK_IDENTITY_SERVER_C);
-
- g_generic_config_set_value(config, path, entries->country);
-
- path = (client ? MPK_IDENTITY_CLIENT_ST : MPK_IDENTITY_SERVER_ST);
-
- g_generic_config_set_value(config, path, entries->state);
-
- path = (client ? MPK_IDENTITY_CLIENT_L : MPK_IDENTITY_SERVER_L);
-
- g_generic_config_set_value(config, path, entries->locality);
-
- path = (client ? MPK_IDENTITY_CLIENT_O : MPK_IDENTITY_SERVER_O);
-
- g_generic_config_set_value(config, path, entries->organisation);
-
- path = (client ? MPK_IDENTITY_CLIENT_OU : MPK_IDENTITY_SERVER_OU);
-
- g_generic_config_set_value(config, path, entries->organisational_unit);
-
- path = (client ? MPK_IDENTITY_CLIENT_CN : MPK_IDENTITY_SERVER_CN);
-
- g_generic_config_set_value(config, path, entries->common_name);
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : type = type de certificat à gérer. *
-* name = dénomination du serveur visé. *
-* *
-* Description : Fournit le répertoire de travail pour les certifications. *
-* *
-* Retour : Définition d'emplacement à libérer de la mémoire après usage.*
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-char *get_cert_working_directory(const char *type, const char *name)
-{
- char *result; /* Chemin à retourner */
- char *suffix; /* Fin de la destination */
-
- suffix = strdup("chrysalide");
- suffix = stradd(suffix, G_DIR_SEPARATOR_S);
- suffix = stradd(suffix, type);
- suffix = stradd(suffix, G_DIR_SEPARATOR_S);
- suffix = stradd(suffix, name);
- suffix = stradd(suffix, G_DIR_SEPARATOR_S);
-
- result = get_xdg_config_dir(suffix);
-
- free(suffix);
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : entries = éléments d'identité à utiliser pour l'opération. *
-* *
-* Description : Définit les certificats utilisés pour les échanges internes. *
-* *
-* Retour : Bilan de l'opération. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-bool register_standalone_certs(const x509_entries *entries)
-{
- bool result; /* Bilan de l'opération */
- char *working; /* Répertoire par le client */
- char *csr; /* Requête de signature */
- char *cert; /* Certificat signé en sortie */
-
- /* Certificats côtés serveur */
-
- result = register_server_cert("standalone", entries);
-
- if (result)
- {
- /* Demande de signature */
-
- result = make_client_sign_request("standalone", entries);
-
- /* Signature */
-
- if (result)
- {
- working = get_cert_working_directory("clients", "standalone");
-
- csr = build_absolute_filename(working, "client-csr.pem");
- cert = build_absolute_filename(working, "client-cert.pem");
-
- result = sign_client_request("standalone", csr, cert);
-
- free(csr);
- free(cert);
-
- free(working);
-
- }
-
- }
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : name = dénomination du serveur visé. *
-* entries = éléments d'identité à utiliser pour l'opération. *
-* *
-* Description : Définit les certificats utilisés pour par un serveur. *
-* *
-* Retour : Bilan de l'opération. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-bool register_server_cert(const char *name, const x509_entries *entries)
-{
- bool result; /* Bilan de l'opération */
- char *suffix; /* Fin de la destination */
- char *working; /* Répertoire de travail */
- unsigned long valid; /* Durée de validité */
- char *csr; /* Requête de signature */
- char *cacert; /* Certificat d'autorité */
- char *cakey; /* Clef de cette autorité */
- char *cert; /* Certificat signé en sortie */
-
- result = false;
-
- working = get_cert_working_directory("servers", name);
-
- if (working != NULL)
- {
- result = mkpath(working);
- if (!result) goto rsc_quick_exit;
-
- result = g_generic_config_get_value(get_main_configuration(), MPK_IDENTITY_VALIDITY, &valid);
-
- if (!result)
- goto rsc_quick_exit;
-
- result = build_keys_and_ca(working, "ca", valid, entries);
- if (!result) goto rsc_quick_exit;
-
- result = build_keys_and_request(working, "server", entries);
- if (!result) goto rsc_quick_exit;
-
- csr = build_absolute_filename(working, "server-csr.pem");
- cacert = build_absolute_filename(working, "ca-cert.pem");
- cakey = build_absolute_filename(working, "ca-key.pem");
- cert = build_absolute_filename(working, "server-cert.pem");
-
- result = sign_cert(csr, cacert, cakey, cert, valid);
-
- if (result)
- store_identity(entries, false);
-
- free(csr);
- free(cacert);
- free(cakey);
- free(cert);
-
- rsc_quick_exit:
-
- free(working);
-
- }
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : name = dénomination du serveur visé. *
-* entries = éléments d'identité à utiliser pour l'opération. *
-* *
-* Description : Elabore une demande de signature de certificat. *
-* *
-* Retour : Bilan de l'opération. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-bool make_client_sign_request(const char *name, const x509_entries *entries)
-{
- bool result; /* Bilan de l'opération */
- char *working; /* Répertoire par le client */
-
- working = get_cert_working_directory("clients", name);
-
- result = mkpath(working);
-
- if (result)
- result = build_keys_and_request(working, "client", entries);
-
- if (result)
- store_identity(entries, true);
-
- free(working);
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : name = dénomination du serveur visé. *
-* csr = fichier contenant le certificat à signer. *
-* cert = fichier contenant le certificat signé. *
-* *
-* Description : Signe un certificat client pour un accès un serveur donné. *
-* *
-* Retour : Bilan de l'opération. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-bool sign_client_request(const char *name, const char *csr, const char *cert)
-{
- bool result; /* Bilan de l'opération */
- char *working; /* Répertoire par le serveur */
- unsigned long valid; /* Durée de validité */
- char *cacert; /* Certificat d'autorité */
- char *cakey; /* Clef de cette autorité */
-
- working = get_cert_working_directory("servers", name);
-
- result = g_generic_config_get_value(get_main_configuration(), MPK_IDENTITY_VALIDITY, &valid);
-
- if (!result)
- goto scr_exit;
-
- cacert = build_absolute_filename(working, "ca-cert.pem");
- cakey = build_absolute_filename(working, "ca-key.pem");
-
- result = sign_cert(csr, cacert, cakey, cert, valid);
-
- free(cacert);
- free(cakey);
-
- scr_exit:
-
- free(working);
-
- return result;
-
-}
-
-
-
-
-
-
-
-
-
-
-#include <assert.h>
-#include <glib.h>
-#include <malloc.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <openssl/err.h>
-#include <openssl/evp.h>
-#include <openssl/pem.h>
-
-
-#include <i18n.h>
-
-
-#include "../../common/xdg.h"
-
-
-
-/* Met en place de nouvelles clefs RSA. */
-static bool generate_user_rsa_keys(const char *, const char *);
-
-
-
-/******************************************************************************
-* *
-* Paramètres : - *
-* *
-* Description : S'assure que l'utilisateur dispose de clefs RSA. *
-* *
-* Retour : Bilan de l'opération. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-bool ensure_user_has_rsa_keys(void)
-{
- bool result; /* Bilan à retourner */
- char *priv; /* Chemin de la clef privée */
- char *pub; /* Chemin de la clef publique */
- int priv_check; /* Bilan d'une vérification #1 */
- int pub_check; /* Bilan d'une vérification #2 */
-
- result = NULL;
-
- priv = get_xdg_config_dir("chrysalide" G_DIR_SEPARATOR_S "id_rsa.priv");
- pub = get_xdg_config_dir("chrysalide" G_DIR_SEPARATOR_S "id_rsa.pub");
-
- priv_check = access(priv, R_OK);
- pub_check = access(pub, R_OK);
-
- result = (priv_check == 0 && pub_check == 0);
-
- if (!result)
- {
- result = generate_user_rsa_keys(priv, pub);
-
- if (!result)
- fprintf(stderr, _("Unable to create new user RSA key pair.\n"));
-
- }
-
- free(priv);
- free(pub);
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : priv = chemin d'accès pour la clef privée. *
-* pub = chemin d'accès pour la clef publique. *
-* *
-* Description : Met en place de nouvelles clefs RSA. *
-* *
-* Retour : Bilan de l'opération. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static bool generate_user_rsa_keys(const char *priv, const char *pub)
-{
- bool result; /* Bilan à retourner */
- EVP_PKEY_CTX *ctx; /* Contexte de génération */
- int ret; /* Bilan d'un appel */
- EVP_PKEY *pair; /* Paire de clefs RSA générée */
- FILE *stream; /* Flux ouvert en écriture */
-
- result = false;
-
- /**
- * Cf. https://www.openssl.org/docs/manmaster/crypto/EVP_PKEY_keygen.html
- */
-
- ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_RSA, NULL);
- if (ctx == NULL) goto euhrk_exit;
-
- ret = EVP_PKEY_keygen_init(ctx);
- if (ret != 1) goto euhrk_exit;
-
- ret = EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, RSA_USED_SIZE * 8);
- if (ret != 1) goto euhrk_exit;
-
- pair = NULL;
-
- ret = EVP_PKEY_keygen(ctx, &pair);
- if (ret != 1) goto euhrk_exit;
-
- /* Clef privée */
-
- stream = fopen(priv, "wt");
- if (stream == NULL) goto euhrk_bad_write;
-
- ret = PEM_write_PrivateKey(stream, pair, NULL, NULL, 0, NULL, NULL);
- if (ret != 1) goto euhrk_bad_write;
-
- fclose(stream);
-
- /* Clef publique */
-
- stream = fopen(pub, "wt");
- if (stream == NULL) goto euhrk_bad_write;
-
- ret = PEM_write_PUBKEY(stream, pair);
- if (ret != 1) goto euhrk_bad_write;
-
- result = true;
-
- euhrk_bad_write:
-
- fclose(stream);
-
- EVP_PKEY_free(pair);
-
- euhrk_exit:
-
- EVP_PKEY_CTX_free(ctx);
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : filename = chemin d'accès à la clef à charger. *
-* private = nature de la clef visée. *
-* *
-* Description : Charge une clef RSA à partir d'un fichier PEM. *
-* *
-* Retour : Clef RSA ou NULL en cas de soucis. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-RSA *load_rsa_key(const char *filename, bool private)
-{
- RSA *result; /* Clef à retourner */
- FILE *stream; /* Flux ouvert en lecture */
- int bits; /* Taille de la clef en bits */
-
- result = NULL;
-
- stream = fopen(filename, "r");
- if (stream == NULL) goto lrk_exit;
-
- if (private)
- result = PEM_read_RSAPrivateKey(stream, &result, NULL, NULL);
- else
- result = PEM_read_RSA_PUBKEY(stream, &result, NULL, NULL);
-
- fclose(stream);
-
- if (result == NULL)
- fprintf(stderr, _("Unable to read the RSA key from '%s'.\n"), filename);
-
- else
- {
- bits = RSA_size(result);
-
- if (bits != RSA_USED_SIZE)
- {
- fprintf(stderr, _("Wrong RSA key size for %s: expected %d, got %d.\n"), filename, RSA_USED_SIZE, bits);
- RSA_free(result);
- result = NULL;
- }
-
- }
-
- lrk_exit:
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : key = clef RSA à utiliser. *
-* hash = empreinte à signer. *
-* sig = signature calculée. *
-* *
-* Description : Signe une empreinte MD5 à l'aide d'une clef RSA. *
-* *
-* Retour : Bilan de l'opération. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-bool sign_md5_hash(RSA *key, const unsigned char *hash, unsigned char *sig)
-{
- int ret; /* Bilan de l'opération */
- unsigned int siglen; /* Taille de la signature */
-
- siglen = RSA_USED_SIZE;
-
- ret = RSA_sign(NID_md5, hash, 16, sig, &siglen, key);
-
- assert(siglen == RSA_USED_SIZE);
-
- if (ret != 1)
- fprintf(stderr, "Unable to sign hash (error=%lu).\n", ERR_get_error());
-
- return (ret == 1);
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : key = clef RSA à utiliser. *
-* hash = empreinte à signer. *
-* sig = signature calculée. *
-* *
-* Description : Vérifie la signature d'une empreinte MD5 avec une clef RSA. *
-* *
-* Retour : Bilan de l'opération. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-bool verify_md5_hash(RSA *key, const unsigned char *hash, unsigned char *sig)
-{
- int ret; /* Bilan de l'opération */
-
- ret = RSA_verify(NID_md5, hash, 16, sig, RSA_USED_SIZE, key);
-
- return (ret == 1);
-
-}
diff --git a/src/analysis/db/keymgn.h b/src/analysis/db/keymgn.h
deleted file mode 100644
index 24ada61..0000000
--- a/src/analysis/db/keymgn.h
+++ /dev/null
@@ -1,81 +0,0 @@
-
-/* Chrysalide - Outil d'analyse de fichiers binaires
- * keymgn.h - prototypes pour la mise en place et la gestion des clefs cryptographiques
- *
- * Copyright (C) 2016-2017 Cyrille Bagard
- *
- * This file is part of Chrysalide.
- *
- * Chrysalide is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * Chrysalide is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Chrysalide. If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-#ifndef _ANALYSIS_DB_KEYMGN_H
-#define _ANALYSIS_DB_KEYMGN_H
-
-
-#include <stdbool.h>
-
-
-#include "certs.h"
-
-
-#include "auth.h"
-
-
-/* Charge en mémoire la définition de l'identité courante. */
-void load_identity(bool, x509_entries *);
-
-/* Fournit le répertoire de travail pour les certifications. */
-char *get_cert_working_directory(const char *, const char *);
-
-/* Définit les certificats utilisés pour les échanges internes. */
-bool register_standalone_certs(const x509_entries *);
-
-/* Définit les certificats utilisés pour par un serveur. */
-bool register_server_cert(const char *, const x509_entries *);
-
-/* Elabore une demande de signature de certificat. */
-bool make_client_sign_request(const char *, const x509_entries *);
-
-/* Signe un certificat client pour un accès un serveur donné. */
-bool sign_client_request(const char *, const char *, const char *);
-
-
-
-
-
-#include <stdbool.h>
-#include <openssl/rsa.h>
-
-
-/* Taille des clefs RSA */
-#define RSA_USED_SIZE (2048 / 8)
-
-
-/* S'assure que l'utilisateur dispose de clefs RSA. */
-bool ensure_user_has_rsa_keys(void);
-
-/* Charge une clef RSA à partir d'un fichier PEM. */
-RSA *load_rsa_key(const char *, bool);
-
-/* Signe une empreinte MD5 à l'aide d'une clef RSA. */
-bool sign_md5_hash(RSA *, const unsigned char *, unsigned char *);
-
-/* Vérifie la signature d'une empreinte MD5 avec une clef RSA. */
-bool verify_md5_hash(RSA *, const unsigned char *, unsigned char *);
-
-
-
-#endif /* _ANALYSIS_DB_KEYMGN_H */