summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2025-02-10 00:39:50 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2025-02-10 00:39:50 (GMT)
commitd01509d9afe32c0d98d2efba5e75a9df53ac5de9 (patch)
treef4d742bec88c34ee9d04c42d16dc7ac84bc642b7 /src
parent71d0b80eca2fd2aed5883e2a6a57cb8c03aa27ff (diff)
Switch the secure storage to the GObject system.
Diffstat (limited to 'src')
-rw-r--r--src/core/Makefile.am3
-rw-r--r--src/core/core.c5
-rw-r--r--src/core/global.c46
-rw-r--r--src/core/global.h7
-rw-r--r--src/glibext/Makefile.am2
-rw-r--r--src/glibext/secstorage-int.h56
-rw-r--r--src/glibext/secstorage.c (renamed from src/core/secstorage.c)263
-rw-r--r--src/glibext/secstorage.h (renamed from src/core/secstorage.h)31
8 files changed, 283 insertions, 130 deletions
diff --git a/src/core/Makefile.am b/src/core/Makefile.am
index 906c383..17fd2bf 100644
--- a/src/core/Makefile.am
+++ b/src/core/Makefile.am
@@ -20,8 +20,7 @@ libcore4_la_SOURCES = \
logs.h logs.c \
nox.h nox.c \
nproc.h nproc.c \
- paths.h paths.c \
- secstorage.h secstorage.c
+ paths.h paths.c
libcore4_la_CFLAGS = $(TOOLKIT_CFLAGS) $(LIBSSL_CFLAGS)
diff --git a/src/core/core.c b/src/core/core.c
index eaf7763..8fe12f5 100644
--- a/src/core/core.c
+++ b/src/core/core.c
@@ -25,7 +25,6 @@
#include "global.h"
-#include "secstorage.h"
@@ -54,7 +53,7 @@ bool load_core_components(AvailableCoreComponent flags)
if ((flags & ACC_GLOBAL_VARS) != 0 && (__loaded & ACC_GLOBAL_VARS) == 0)
{
- init_secret_storage();
+ set_secret_storage(g_secret_storage_new(NULL));
set_work_queue(g_work_queue_new());
@@ -85,7 +84,7 @@ void unload_core_components(AvailableCoreComponent flags)
{
set_work_queue(NULL);
- exit_secret_storage();
+ set_secret_storage(NULL);
__loaded &= ~ACC_GLOBAL_VARS;
diff --git a/src/core/global.c b/src/core/global.c
index d38656b..0275e09 100644
--- a/src/core/global.c
+++ b/src/core/global.c
@@ -36,6 +36,9 @@ static size_t _bytes_sent = 0;
/* Gestionnaire de tâches parallèles */
static GWorkQueue *_queue = NULL;
+/* Gardien des secrets avec support des stockages */
+static GSecretStorage *_storage = NULL;
+
/******************************************************************************
@@ -131,6 +134,49 @@ GWorkQueue *get_work_queue(void)
}
+/******************************************************************************
+* *
+* Paramètres : queue = nouveau stockage sécurisé à mémoriser ou NULL. *
+* *
+* Description : Définit le stockage sécurisé principal. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void set_secret_storage(/* __steal */GSecretStorage *storage)
+{
+ if (_storage != NULL)
+ unref_object(_storage);
+
+ _storage = storage;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Fournit le stockage sécurisé principal. *
+* *
+* Retour : Gestionnaire de traitements parallèles courant. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GSecretStorage *get_secret_storage(void)
+{
+ ref_object(_storage);
+
+ return _storage;
+
+}
+
+
diff --git a/src/core/global.h b/src/core/global.h
index b861ad8..f5d8a62 100644
--- a/src/core/global.h
+++ b/src/core/global.h
@@ -25,6 +25,7 @@
#define _CORE_GLOBAL_H
+#include "../glibext/secstorage.h"
#include "../glibext/workqueue.h"
@@ -41,6 +42,12 @@ void set_work_queue(/* __steal */GWorkQueue *);
/* Fournit le gestionnaire de traitements parallèles courant. */
GWorkQueue *get_work_queue(void);
+/* Définit le stockage sécurisé principal. */
+void set_secret_storage(/* __steal */GSecretStorage *);
+
+/* Fournit le stockage sécurisé principal. */
+GSecretStorage *get_secret_storage(void);
+
diff --git a/src/glibext/Makefile.am b/src/glibext/Makefile.am
index 2e9e86d..81d13d2 100644
--- a/src/glibext/Makefile.am
+++ b/src/glibext/Makefile.am
@@ -47,6 +47,8 @@ libglibext_la_SOURCES = \
objhole.h objhole.c \
portion-int.h \
portion.h portion.c \
+ secstorage-int.h \
+ secstorage.h secstorage.c \
singleton-int.h \
singleton.h singleton.c \
strbuilder-int.h \
diff --git a/src/glibext/secstorage-int.h b/src/glibext/secstorage-int.h
new file mode 100644
index 0000000..310fbbc
--- /dev/null
+++ b/src/glibext/secstorage-int.h
@@ -0,0 +1,56 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * secstorage-int.h - définitions internes pour la conservation sécurisée d'éléments de configuration
+ *
+ * Copyright (C) 2025 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 _GLIBEXT_SECSTORAGE_INT_H
+#define _GLIBEXT_SECSTORAGE_INT_H
+
+
+#include "secstorage.h"
+
+
+
+/* Gardien des secrets avec support des stockages (instance) */
+struct _GSecretStorage
+{
+ GObject parent; /* A laisser en premier */
+
+ GSettings *settings; /* Configuration sollicitée */
+
+ void *master_key; /* Clef déverrouillée */
+
+};
+
+/* Gardien des secrets avec support des stockages (classe) */
+struct _GSecretStorageClass
+{
+ GObjectClass parent; /* A laisser en premier */
+
+};
+
+
+/* Met en place un gardien des secrets avec support de stockage. */
+bool g_secret_storage_create(GSecretStorage *, GSettings *);
+
+
+
+#endif /* _GLIBEXT_SECSTORAGE_INT_H */
diff --git a/src/core/secstorage.c b/src/glibext/secstorage.c
index 7f57b1c..84fc10c 100644
--- a/src/core/secstorage.c
+++ b/src/glibext/secstorage.c
@@ -30,8 +30,8 @@
#include <openssl/rand.h>
+#include "secstorage-int.h"
#include "../core/logs.h"
-#include "../glibext/helpers.h"
@@ -71,20 +71,54 @@
#define SECRET_STORAGE_IV_SIZE SECRET_STORAGE_BLOCK_SIZE
-/* Conservation des clefs de déchiffrement maîtres par configuration. */
-static GHashTable *__unlocked_keys = NULL;
+/* Initialise la classe des stockages de secrets. */
+static void g_secret_storage_class_init(GSecretStorageClass *);
-/* Fournit l'espace de configuration réel à manipuler. */
-static GSettings *get_secret_storage_settings(GSettings *);
+/* Initialise une instance de stockage de secrets. */
+static void g_secret_storage_init(GSecretStorage *);
+/* Supprime toutes les références externes. */
+static void g_secret_storage_dispose(GObject *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_secret_storage_finalize(GObject *);
+
+
+
+/* Indique le type défini pour un gardien des secrets avec support des stockages. */
+G_DEFINE_TYPE(GSecretStorage, g_secret_storage, G_TYPE_OBJECT);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des stockages de secrets. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_secret_storage_class_init(GSecretStorageClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = g_secret_storage_dispose;
+ object->finalize = g_secret_storage_finalize;
+
+}
/******************************************************************************
* *
-* Paramètres : - *
+* Paramètres : storage = instance à initialiser. *
* *
-* Description : Initialise le stockage des clefs de déchiffrement en place. *
+* Description : Initialise une instance de stockage de secrets. *
* *
* Retour : - *
* *
@@ -92,18 +126,20 @@ static GSettings *get_secret_storage_settings(GSettings *);
* *
******************************************************************************/
-void init_secret_storage(void)
+static void g_secret_storage_init(GSecretStorage *storage)
{
- __unlocked_keys = g_hash_table_new_full(g_direct_hash, g_direct_equal, g_object_unref, free);
+ storage->settings = NULL;
+
+ storage->master_key = NULL;
}
/******************************************************************************
* *
-* Paramètres : - *
+* Paramètres : object = instance d'objet GLib à traiter. *
* *
-* Description : Supprime le stockage des clefs de déchiffrement en place. *
+* Description : Supprime toutes les références externes. *
* *
* Retour : - *
* *
@@ -111,42 +147,97 @@ void init_secret_storage(void)
* *
******************************************************************************/
-void exit_secret_storage(void)
+static void g_secret_storage_dispose(GObject *object)
{
- assert(__unlocked_keys != NULL);
+ GSecretStorage *storage; /* Gestion de stockage sécurisé*/
+
+ storage = G_SECRET_STORAGE(object);
- g_hash_table_remove_all(__unlocked_keys);
- g_hash_table_unref(__unlocked_keys);
+ g_clear_object(&storage->settings);
- __unlocked_keys = NULL;
+ G_OBJECT_CLASS(g_secret_storage_parent_class)->dispose(object);
}
/******************************************************************************
* *
-* Paramètres : settings = éventuel espace de configuration à manipuler. *
+* Paramètres : object = instance d'objet GLib à traiter. *
* *
-* Description : Fournit l'espace de configuration réel à manipuler. *
+* Description : Procède à la libération totale de la mémoire. *
* *
-* Retour : Instance de travail à employer avant libération. *
+* Retour : - *
* *
* Remarques : - *
* *
******************************************************************************/
-static GSettings *get_secret_storage_settings(GSettings *settings)
+static void g_secret_storage_finalize(GObject *object)
{
- GSettings *result; /* Instance à retourner */
+ GSecretStorage *storage; /* Gestion de stockage sécurisé*/
+
+ storage = G_SECRET_STORAGE(object);
+
+ if (storage->master_key != NULL)
+ free(storage->master_key);
+
+ G_OBJECT_CLASS(g_secret_storage_parent_class)->finalize(object);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : settings = éventuel espace de configuration à utiliser. *
+* *
+* Description : Créé un nouveau gardien des secrets avec support de stockage.*
+* *
+* Retour : Gestionnaire de stockage sécurisé mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GSecretStorage *g_secret_storage_new(GSettings *settings)
+{
+ GSecretStorage *result; /* Instance à retourner */
+
+ result = g_object_new(G_TYPE_SECRET_STORAGE, NULL);
+ if (!g_secret_storage_create(result, settings))
+ g_clear_object(&result);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : storage = stockage sécurisé à initialiser. *
+* settings = éventuel espace de configuration à utiliser. *
+* *
+* Description : Met en place un gardien des secrets avec support de stockage.*
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_secret_storage_create(GSecretStorage *storage, GSettings *settings)
+{
+ bool result; /* Bilan à retourner */
+
+ result = true;
if (settings != NULL)
{
ref_object(settings);
- result = settings;
+ storage->settings = settings;
}
else
- result = NULL; // TODO
+ result = false; // TODO
return result;
@@ -155,7 +246,7 @@ static GSettings *get_secret_storage_settings(GSettings *settings)
/******************************************************************************
* *
-* Paramètres : settings = éventuel espace de configuration à manipuler. *
+* Paramètres : storage = espace de stockage sécurisé à consulter. *
* *
* Description : Détermine si une clef de chiffrement protégée est en place. *
* *
@@ -165,7 +256,7 @@ static GSettings *get_secret_storage_settings(GSettings *settings)
* *
******************************************************************************/
-bool has_secret_storage_key(GSettings *settings)
+bool g_secret_storage_has_key(const GSecretStorage *storage)
{
bool result; /* Bilan à retourner */
GVariant *value; /* Valeur de configuration */
@@ -173,10 +264,7 @@ bool has_secret_storage_key(GSettings *settings)
result = false;
- settings = get_secret_storage_settings(settings);
- assert(settings != NULL);
-
- value = g_settings_get_value(settings, "master");
+ value = g_settings_get_value(storage->settings, "master");
g_variant_get_fixed_array(value, &length, 1);
@@ -184,8 +272,6 @@ bool has_secret_storage_key(GSettings *settings)
g_variant_unref(value);
- unref_object(settings);
-
return result;;
}
@@ -193,7 +279,7 @@ bool has_secret_storage_key(GSettings *settings)
/******************************************************************************
* *
-* Paramètres : settings = éventuel espace de configuration à manipuler. *
+* Paramètres : storage = espace de stockage sécurisé à consulter. *
* password = mot de passe principal à appliquer. *
* *
* Description : Définit un mot de passe pour protéger une clef maître. *
@@ -204,7 +290,7 @@ bool has_secret_storage_key(GSettings *settings)
* *
******************************************************************************/
-bool set_secret_storage_password(GSettings *settings, const char *passwd)
+bool g_secret_storage_set_password(const GSecretStorage *storage, const char *passwd)
{
bool result; /* Bilan à retourner */
unsigned char salt[SECRET_STORAGE_SALT_SIZE]; /* Sel pour la dérivation*/
@@ -220,10 +306,7 @@ bool set_secret_storage_password(GSettings *settings, const char *passwd)
result = false;
- settings = get_secret_storage_settings(settings);
- assert(settings != NULL);
-
- if (has_secret_storage_key(settings))
+ if (g_secret_storage_has_key(storage))
goto exit;
/* Création d'un sel pour la dérivation du mot de passe */
@@ -250,7 +333,7 @@ bool set_secret_storage_password(GSettings *settings, const char *passwd)
* Il n'y a donc pas lieu d'appeler g_variant_unref().
*/
- g_settings_set_value(settings, "salt", value);
+ g_settings_set_value(storage->settings, "salt", value);
/* Dérivation du mot de passe */
@@ -329,7 +412,7 @@ bool set_secret_storage_password(GSettings *settings, const char *passwd)
value = g_variant_new_fixed_array(G_VARIANT_TYPE_BYTE,
encrypted, iter - encrypted, sizeof(unsigned char));
- g_settings_set_value(settings, "master", value);
+ g_settings_set_value(storage->settings, "master", value);
result = true;
@@ -339,8 +422,6 @@ bool set_secret_storage_password(GSettings *settings, const char *passwd)
exit:
- unref_object(settings);
-
return result;
}
@@ -348,7 +429,7 @@ bool set_secret_storage_password(GSettings *settings, const char *passwd)
/******************************************************************************
* *
-* Paramètres : settings = éventuel espace de configuration à manipuler. *
+* Paramètres : storage = espace de stockage sécurisé à consulter. *
* *
* Description : Détermine si la clef de chiffrement maître est vérouillée. *
* *
@@ -358,16 +439,11 @@ bool set_secret_storage_password(GSettings *settings, const char *passwd)
* *
******************************************************************************/
-bool is_secret_storage_locked(GSettings *settings)
+bool g_secret_storage_is_locked(const GSecretStorage *storage)
{
bool result; /* Bilan à retourner */
- settings = get_secret_storage_settings(settings);
- assert(settings != NULL);
-
- result = (g_hash_table_lookup(__unlocked_keys, settings) == NULL);
-
- unref_object(settings);
+ result = (storage->master_key == NULL);
return result;
@@ -376,7 +452,7 @@ bool is_secret_storage_locked(GSettings *settings)
/******************************************************************************
* *
-* Paramètres : settings = éventuel espace de configuration à manipuler. *
+* Paramètres : storage = espace de stockage sécurisé à manipuler. *
* password = mot de passe principal à utiliser. *
* *
* Description : Déverrouille la clef de chiffrement maître. *
@@ -387,7 +463,7 @@ bool is_secret_storage_locked(GSettings *settings)
* *
******************************************************************************/
-bool unlock_secret_storage(GSettings *settings, const char *passwd)
+bool g_secret_storage_unlock(GSecretStorage *storage, const char *passwd)
{
bool result; /* Bilan à retourner */
GVariant *salt_value; /* Valeur du sel configuré */
@@ -403,17 +479,10 @@ bool unlock_secret_storage(GSettings *settings, const char *passwd)
unsigned char key[SECRET_STORAGE_KEY_SIZE]; /* Clef maître */
unsigned char *iter; /* Tête d'écriture */
int outlen; /* Taille des données utiles */
- void *unlocked; /* Zone de conservation */
-#ifndef NDEBUG
- gboolean new; /* Validation de la création */
-#endif
result = false;
- settings = get_secret_storage_settings(settings);
- assert(settings != NULL);
-
- if (!is_secret_storage_locked(settings))
+ if (!g_secret_storage_is_locked(storage))
{
result = true;
goto quick_exit;
@@ -421,7 +490,7 @@ bool unlock_secret_storage(GSettings *settings, const char *passwd)
/* Récupération du sel mis en place */
- salt_value = g_settings_get_value(settings, "salt");
+ salt_value = g_settings_get_value(storage->settings, "salt");
salt = g_variant_get_fixed_array(salt_value, &salt_length, sizeof(bin_t));
@@ -443,7 +512,7 @@ bool unlock_secret_storage(GSettings *settings, const char *passwd)
/* Récupération des paramètres chiffrés */
- enc_value = g_settings_get_value(settings, "master");
+ enc_value = g_settings_get_value(storage->settings, "master");
encrypted = g_variant_get_fixed_array(enc_value, &enc_length, sizeof(bin_t));
@@ -495,17 +564,8 @@ bool unlock_secret_storage(GSettings *settings, const char *passwd)
/* Stockage de la clef maître en mémoire */
- ref_object(settings);
-
- unlocked = malloc(SECRET_STORAGE_KEY_SIZE);
- memcpy(unlocked, key, SECRET_STORAGE_KEY_SIZE);
-
-#ifndef NDEBUG
- new = g_hash_table_replace(__unlocked_keys, settings, unlocked);
- assert(new);
-#else
- g_hash_table_replace(__unlocked_keys, settings, unlocked);
-#endif
+ storage->master_key = malloc(SECRET_STORAGE_KEY_SIZE);
+ memcpy(storage->master_key, key, SECRET_STORAGE_KEY_SIZE);
result = true;
@@ -525,8 +585,6 @@ bool unlock_secret_storage(GSettings *settings, const char *passwd)
quick_exit:
- unref_object(settings);
-
return result;
}
@@ -534,7 +592,7 @@ bool unlock_secret_storage(GSettings *settings, const char *passwd)
/******************************************************************************
* *
-* Paramètres : settings = éventuel espace de configuration à manipuler. *
+* Paramètres : storage = espace de stockage sécurisé à manipuler. *
* *
* Description : Verrouille la clef de chiffrement maître. *
* *
@@ -544,23 +602,22 @@ bool unlock_secret_storage(GSettings *settings, const char *passwd)
* *
******************************************************************************/
-void lock_secret_storage(GSettings *settings)
+void g_secret_storage_lock(GSecretStorage *storage)
{
- settings = get_secret_storage_settings(settings);
- assert(settings != NULL);
-
- g_hash_table_remove(__unlocked_keys, settings);
-
- unref_object(settings);
+ if (storage->master_key != NULL)
+ {
+ free(storage->master_key);
+ storage->master_key = NULL;
+ }
}
/******************************************************************************
* *
-* Paramètres : settings = éventuel espace de configuration à manipuler. *
-* in = séquence d'octets à traiter. *
-* out = séquence d'octets résultantes. [OUT] *
+* Paramètres : storage = espace de stockage sécurisé à consulter. *
+* in = séquence d'octets à traiter. *
+* out = séquence d'octets résultantes. [OUT] *
* *
* Description : Chiffre des données avec la clef de chiffrement maître. *
* *
@@ -570,10 +627,9 @@ void lock_secret_storage(GSettings *settings)
* *
******************************************************************************/
-bool encrypt_secret_storage_data(GSettings *settings, const sized_binary_t *in, sized_binary_t *out)
+bool g_secret_storage_encrypt_data(const GSecretStorage *storage, const sized_binary_t *in, sized_binary_t *out)
{
bool result; /* Bilan à retourner */
- gpointer key; /* Clef de chiffrement */
unsigned char iv[SECRET_STORAGE_IV_SIZE]; /* IV associé */
int ret; /* Bilan à d'un appel */
EVP_CIPHER_CTX *ctx; /* Contexte pour le chiffrement*/
@@ -583,16 +639,11 @@ bool encrypt_secret_storage_data(GSettings *settings, const sized_binary_t *in,
result = false;
- settings = get_secret_storage_settings(settings);
- assert(settings != NULL);
-
- if (is_secret_storage_locked(settings))
+ if (g_secret_storage_is_locked(storage))
goto quick_exit;
/* Récupération de la clef maître et d'un IV de chiffrement */
- key = g_hash_table_lookup(__unlocked_keys, settings);
-
ret = RAND_bytes(iv, sizeof(iv));
if (ret != 1)
{
@@ -616,7 +667,7 @@ bool encrypt_secret_storage_data(GSettings *settings, const sized_binary_t *in,
goto exit;
}
- ret = EVP_EncryptInit_ex2(ctx, EVP_aes_256_cbc(), key, iv, NULL);
+ ret = EVP_EncryptInit_ex2(ctx, EVP_aes_256_cbc(), storage->master_key, iv, NULL);
if (ret != 1)
{
LOG_ERROR_OPENSSL;
@@ -661,8 +712,6 @@ bool encrypt_secret_storage_data(GSettings *settings, const sized_binary_t *in,
exit:
quick_exit:
- unref_object(settings);
-
return result;
}
@@ -670,9 +719,9 @@ bool encrypt_secret_storage_data(GSettings *settings, const sized_binary_t *in,
/******************************************************************************
* *
-* Paramètres : settings = éventuel espace de configuration à manipuler. *
-* in = séquence d'octets à traiter. *
-* out = séquence d'octets résultantes. [OUT] *
+* Paramètres : storage = espace de stockage sécurisé à consulter. *
+* in = séquence d'octets à traiter. *
+* out = séquence d'octets résultantes. [OUT] *
* *
* Description : Déchiffre des données avec la clef de chiffrement maître. *
* *
@@ -682,10 +731,9 @@ bool encrypt_secret_storage_data(GSettings *settings, const sized_binary_t *in,
* *
******************************************************************************/
-bool decrypt_secret_storage_data(GSettings *settings, const sized_binary_t *in, sized_binary_t *out)
+bool g_secret_storage_decrypt_data(const GSecretStorage *storage, const sized_binary_t *in, sized_binary_t *out)
{
bool result; /* Bilan à retourner */
- gpointer key; /* Clef de chiffrement */
unsigned char iv[SECRET_STORAGE_IV_SIZE]; /* IV associé */
int ret; /* Bilan à d'un appel */
EVP_CIPHER_CTX *ctx; /* Contexte pour le chiffrement*/
@@ -695,15 +743,10 @@ bool decrypt_secret_storage_data(GSettings *settings, const sized_binary_t *in,
result = false;
- settings = get_secret_storage_settings(settings);
- assert(settings != NULL);
-
- if (is_secret_storage_locked(settings))
+ if (g_secret_storage_is_locked(storage))
goto quick_exit;
- /* Récupération de la clef maître et d'un IV de chiffrement */
-
- key = g_hash_table_lookup(__unlocked_keys, settings);
+ /* Récupération d'un IV de déchiffrement */
if (in->size < SECRET_STORAGE_IV_SIZE)
goto exit;
@@ -726,7 +769,7 @@ bool decrypt_secret_storage_data(GSettings *settings, const sized_binary_t *in,
goto exit;
}
- ret = EVP_DecryptInit_ex2(ctx, EVP_aes_256_cbc(), key, iv, NULL);
+ ret = EVP_DecryptInit_ex2(ctx, EVP_aes_256_cbc(), storage->master_key, iv, NULL);
if (ret != 1)
{
LOG_ERROR_OPENSSL;
@@ -772,8 +815,6 @@ bool decrypt_secret_storage_data(GSettings *settings, const sized_binary_t *in,
exit:
quick_exit:
- unref_object(settings);
-
return result;
}
diff --git a/src/core/secstorage.h b/src/glibext/secstorage.h
index 7c27e07..a75b1a3 100644
--- a/src/core/secstorage.h
+++ b/src/glibext/secstorage.h
@@ -21,45 +21,48 @@
*/
-#ifndef _CORE_SECSTORAGE_H
-#define _CORE_SECSTORAGE_H
+#ifndef _GLIBEXT_SECSTORAGE_H
+#define _GLIBEXT_SECSTORAGE_H
#include <stdbool.h>
#include <gio/gio.h>
+#include "helpers.h"
#include "../common/szbin.h"
-/* Initialise le stockage des clefs de déchiffrement en place. */
-void init_secret_storage(void);
+#define G_TYPE_SECRET_STORAGE (g_secret_storage_get_type())
-/* Supprime le stockage des clefs de déchiffrement en place. */
-void exit_secret_storage(void);
+DECLARE_GTYPE(GSecretStorage, g_secret_storage, G, SECRET_STORAGE);
+
+
+/* Créé un nouveau gardien des secrets avec support de stockage. */
+GSecretStorage *g_secret_storage_new(GSettings *);
/* Détermine si une clef de chiffrement protégée est en place. */
-bool has_secret_storage_key(GSettings *);
+bool g_secret_storage_has_key(const GSecretStorage *);
/* Définit un mot de passe pour protéger une clef maître. */
-bool set_secret_storage_password(GSettings *, const char *);
+bool g_secret_storage_set_password(const GSecretStorage *, const char *);
/* Détermine si la clef de chiffrement maître est vérouillée. */
-bool is_secret_storage_locked(GSettings *);
+bool g_secret_storage_is_locked(const GSecretStorage *);
/* Déverrouille la clef de chiffrement maître. */
-bool unlock_secret_storage(GSettings *, const char *);
+bool g_secret_storage_unlock(GSecretStorage *, const char *);
/* Verrouille la clef de chiffrement maître. */
-void lock_secret_storage(GSettings *);
+void g_secret_storage_lock(GSecretStorage *);
/* Chiffre des données avec la clef de chiffrement maître. */
-bool encrypt_secret_storage_data(GSettings *, const sized_binary_t *, sized_binary_t *);
+bool g_secret_storage_encrypt_data(const GSecretStorage *, const sized_binary_t *, sized_binary_t *);
/* Déchiffre des données avec la clef de chiffrement maître. */
-bool decrypt_secret_storage_data(GSettings *, const sized_binary_t *, sized_binary_t *);
+bool g_secret_storage_decrypt_data(const GSecretStorage *, const sized_binary_t *, sized_binary_t *);
-#endif /* _CORE_SECSTORAGE_H */
+#endif /* _GLIBEXT_SECSTORAGE_H */