From 0e8a77deea7b91de50c0d5ef29eb6c088d4abd37 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Fri, 8 Jan 2010 14:19:58 +0100 Subject: Add userpref helper to allow removal of the stored device public key --- src/userpref.c | 24 ++++++++++++++++++++++++ src/userpref.h | 1 + 2 files changed, 25 insertions(+) diff --git a/src/userpref.c b/src/userpref.c index 10c14a0..09ec495 100644 --- a/src/userpref.c +++ b/src/userpref.c @@ -212,6 +212,30 @@ userpref_error_t userpref_set_device_public_key(const char *uuid, gnutls_datum_t return USERPREF_E_SUCCESS; } +/** Remove the public key stored for the device with uuid from this host. + * + * @param uuid The uuid of the device + * + * @return USERPREF_E_SUCCESS on success. + */ +userpref_error_t userpref_remove_device_public_key(const char *uuid) +{ + if (!userpref_has_device_public_key(uuid)) + return USERPREF_E_SUCCESS; + + /* build file path */ + gchar *device_file = g_strconcat(uuid, ".pem", NULL); + gchar *pem = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIPHONE_CONF_DIR, device_file, NULL); + + /* remove file */ + g_remove(pem); + + g_free(pem); + g_free(device_file); + + return USERPREF_E_SUCCESS; +} + /** Private function which reads the given file into a gnutls structure. * * @param file The filename of the file to read diff --git a/src/userpref.h b/src/userpref.h index 3540468..48b8969 100644 --- a/src/userpref.h +++ b/src/userpref.h @@ -38,6 +38,7 @@ G_GNUC_INTERNAL userpref_error_t userpref_get_keys_and_certs(gnutls_x509_privkey G_GNUC_INTERNAL userpref_error_t userpref_set_keys_and_certs(gnutls_datum_t * root_key, gnutls_datum_t * root_cert, gnutls_datum_t * host_key, gnutls_datum_t * host_cert); G_GNUC_INTERNAL userpref_error_t userpref_get_certs_as_pem(gnutls_datum_t *pem_root_cert, gnutls_datum_t *pem_host_cert); G_GNUC_INTERNAL userpref_error_t userpref_set_device_public_key(const char *uuid, gnutls_datum_t public_key); +G_GNUC_INTERNAL userpref_error_t userpref_remove_device_public_key(const char *uuid); G_GNUC_INTERNAL int userpref_has_device_public_key(const char *uuid); G_GNUC_INTERNAL void userpref_get_host_id(char **host_id); -- cgit v1.1-32-gdbae