summaryrefslogtreecommitdiffstats
path: root/src/userpref.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/userpref.c')
-rw-r--r--src/userpref.c10
1 files changed, 3 insertions, 7 deletions
diff --git a/src/userpref.c b/src/userpref.c
index db54679..b707957 100644
--- a/src/userpref.c
+++ b/src/userpref.c
@@ -114,10 +114,10 @@ int is_device_known(char *uid)
114 * @return 1 on success and 0 if no public key is given or if it has already 114 * @return 1 on success and 0 if no public key is given or if it has already
115 * been marked as connected previously. 115 * been marked as connected previously.
116 */ 116 */
117int store_device_public_key(char *uid, char *public_key) 117int store_device_public_key(char *uid, gnutls_datum_t public_key)
118{ 118{
119 119
120 if (NULL == public_key || is_device_known(uid)) 120 if (NULL == public_key.data || is_device_known(uid))
121 return 0; 121 return 0;
122 122
123 /* ensure config directory exists */ 123 /* ensure config directory exists */
@@ -127,15 +127,11 @@ int store_device_public_key(char *uid, char *public_key)
127 gchar *device_file = g_strconcat(uid, ".pem", NULL); 127 gchar *device_file = g_strconcat(uid, ".pem", NULL);
128 gchar *pem = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIPHONE_CONF_DIR, device_file, NULL); 128 gchar *pem = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIPHONE_CONF_DIR, device_file, NULL);
129 129
130 /* decode public key for storing */
131 gsize decoded_size;
132 gchar *data = g_base64_decode(public_key, &decoded_size);
133 /* store file */ 130 /* store file */
134 FILE *pFile = fopen(pem, "wb"); 131 FILE *pFile = fopen(pem, "wb");
135 fwrite(data, 1, decoded_size, pFile); 132 fwrite(public_key.data, 1, public_key.size, pFile);
136 fclose(pFile); 133 fclose(pFile);
137 g_free(pem); 134 g_free(pem);
138 g_free(data);
139 g_free(device_file); 135 g_free(device_file);
140 return 1; 136 return 1;
141} 137}