2
* Remmina - The GTK+ Remote Desktop Client
3
* Copyright (C) 2009 - Vic Lee
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330,
18
* Boston, MA 02111-1307, USA.
26
#include "remmina_pref.h"
27
#include "remmina_crypt.h"
31
static gboolean remmina_crypt_init(gcry_cipher_hd_t *phd)
37
secret = g_base64_decode(remmina_pref.secret, &secret_len);
41
g_print("secret corrupted\n");
46
err = gcry_cipher_open(phd, GCRY_CIPHER_3DES, GCRY_CIPHER_MODE_CBC, 0);
50
g_print("gcry_cipher_open failure: %s\n", gcry_strerror(err));
55
err = gcry_cipher_setkey((*phd), secret, 24);
59
g_print("gcry_cipher_setkey failure: %s\n", gcry_strerror(err));
61
gcry_cipher_close((*phd));
65
err = gcry_cipher_setiv((*phd), secret + 24, 8);
69
g_print("gcry_cipher_setiv failure: %s\n", gcry_strerror(err));
71
gcry_cipher_close((*phd));
80
gchar* remmina_crypt_encrypt(const gchar *str)
88
if (!str || str[0] == '\0')
91
if (!remmina_crypt_init(&hd))
94
buf_len = strlen(str);
95
/* Pack to 64bit block size, and make sure it's always 0-terminated */
96
buf_len += 8 - buf_len % 8;
97
buf = (guchar*) g_malloc(buf_len);
98
memset(buf, 0, buf_len);
99
memcpy(buf, str, strlen(str));
101
err = gcry_cipher_encrypt(hd, buf, buf_len, NULL, 0);
105
g_print("gcry_cipher_encrypt failure: %s\n", gcry_strerror(err));
107
gcry_cipher_close(hd);
111
result = g_base64_encode(buf, buf_len);
114
gcry_cipher_close(hd);
119
gchar* remmina_crypt_decrypt(const gchar *str)
126
if (!str || str[0] == '\0')
129
if (!remmina_crypt_init(&hd))
132
buf = g_base64_decode(str, &buf_len);
134
err = gcry_cipher_decrypt(hd, buf, buf_len, NULL, 0);
138
g_print("gcry_cipher_decrypt failure: %s\n", gcry_strerror(err));
140
gcry_cipher_close(hd);
144
gcry_cipher_close(hd);
147
buf[buf_len - 1] = '\0';
154
gchar* remmina_crypt_encrypt(const gchar *str)
159
gchar* remmina_crypt_decrypt(const gchar *str)