~ubuntu-branches/ubuntu/raring/remmina/raring

« back to all changes in this revision

Viewing changes to remmina/src/remmina_crypt.c

  • Committer: Package Import Robot
  • Author(s): Luca Falavigna
  • Date: 2012-02-11 17:28:48 UTC
  • mfrom: (1.2.8)
  • Revision ID: package-import@ubuntu.com-20120211172848-rh3ffi7075qyobuq
Tags: 1.0.0-1
* New upstream release.
  - Compatible with FreeRDP 1.0 (Closes: #658363).
  - Ported to GTK3, this also fixes an incompatibility with
    GTK2 and recent Avahi with GTK3 support, which lead to
    crashes when scanning network services (Closes: #626499).
* debian/patches/libvncserver.patch:
  - Do not use convenience copy of libvncserver.
* debian/patches/g_thread_init.patch:
  - Do not use deprecated g_thread_init function.
* debian/patches/REMMINA_COMMAND_NONE.patch:
  - Removed, obsoleted by GApplication port.
* debian/clean:
  - Remove spurious files created at build-time.
* debian/compat:
  - Bump compatibility level to 9.
* debian/control:
  - Refresh build-dependencies to match new structure.
  - Drop remmina-dev package, no longer used.
  - Build packages once provided by remmina-plugins.
  - Provide remmina-common package.
  - Provide remmina-plugin-gnome package.
* debian/copyright:
  - Refresh copyright information.
* debian/docs:
  - Documentation is no longer accurate, do not ship it anymore.
* debian/remmina-dev.install:
  - Drop remmina-dev package, no longer used.
* debian/remmina-plugin-telepathy.install:
  - Adjust location for Remmina.client.
  - Disable D-BUS support for now.
* debian/rules:
  - Compile with -DWITH_APPINDICATOR=OFF.
  - Do not treat plugins as shared libraries.
* debian/watch:
  - Adjust watch file to match new download location.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Remmina - The GTK+ Remote Desktop Client
 
3
 * Copyright (C) 2009 - Vic Lee 
 
4
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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.
 
19
 */
 
20
 
 
21
#include "config.h"
 
22
#include <glib.h>
 
23
#ifdef HAVE_LIBGCRYPT
 
24
#include <gcrypt.h>
 
25
#endif
 
26
#include "remmina_pref.h"
 
27
#include "remmina_crypt.h"
 
28
 
 
29
#ifdef HAVE_LIBGCRYPT
 
30
 
 
31
static gboolean remmina_crypt_init(gcry_cipher_hd_t *phd)
 
32
{
 
33
        guchar* secret;
 
34
        gcry_error_t err;
 
35
        gsize secret_len;
 
36
 
 
37
        secret = g_base64_decode(remmina_pref.secret, &secret_len);
 
38
 
 
39
        if (secret_len < 32)
 
40
        {
 
41
                g_print("secret corrupted\n");
 
42
                g_free(secret);
 
43
                return FALSE;
 
44
        }
 
45
 
 
46
        err = gcry_cipher_open(phd, GCRY_CIPHER_3DES, GCRY_CIPHER_MODE_CBC, 0);
 
47
 
 
48
        if (err)
 
49
        {
 
50
                g_print("gcry_cipher_open failure: %s\n", gcry_strerror(err));
 
51
                g_free(secret);
 
52
                return FALSE;
 
53
        }
 
54
 
 
55
        err = gcry_cipher_setkey((*phd), secret, 24);
 
56
 
 
57
        if (err)
 
58
        {
 
59
                g_print("gcry_cipher_setkey failure: %s\n", gcry_strerror(err));
 
60
                g_free(secret);
 
61
                gcry_cipher_close((*phd));
 
62
                return FALSE;
 
63
        }
 
64
 
 
65
        err = gcry_cipher_setiv((*phd), secret + 24, 8);
 
66
 
 
67
        if (err)
 
68
        {
 
69
                g_print("gcry_cipher_setiv failure: %s\n", gcry_strerror(err));
 
70
                g_free(secret);
 
71
                gcry_cipher_close((*phd));
 
72
                return FALSE;
 
73
        }
 
74
 
 
75
        g_free(secret);
 
76
 
 
77
        return TRUE;
 
78
}
 
79
 
 
80
gchar* remmina_crypt_encrypt(const gchar *str)
 
81
{
 
82
        guchar* buf;
 
83
        gint buf_len;
 
84
        gchar* result;
 
85
        gcry_error_t err;
 
86
        gcry_cipher_hd_t hd;
 
87
 
 
88
        if (!str || str[0] == '\0')
 
89
                return NULL;
 
90
 
 
91
        if (!remmina_crypt_init(&hd))
 
92
                return NULL;
 
93
 
 
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));
 
100
 
 
101
        err = gcry_cipher_encrypt(hd, buf, buf_len, NULL, 0);
 
102
 
 
103
        if (err)
 
104
        {
 
105
                g_print("gcry_cipher_encrypt failure: %s\n", gcry_strerror(err));
 
106
                g_free(buf);
 
107
                gcry_cipher_close(hd);
 
108
                return NULL;
 
109
        }
 
110
 
 
111
        result = g_base64_encode(buf, buf_len);
 
112
 
 
113
        g_free(buf);
 
114
        gcry_cipher_close(hd);
 
115
 
 
116
        return result;
 
117
}
 
118
 
 
119
gchar* remmina_crypt_decrypt(const gchar *str)
 
120
{
 
121
        guchar* buf;
 
122
        gsize buf_len;
 
123
        gcry_error_t err;
 
124
        gcry_cipher_hd_t hd;
 
125
 
 
126
        if (!str || str[0] == '\0')
 
127
                return NULL;
 
128
 
 
129
        if (!remmina_crypt_init(&hd))
 
130
                return NULL;
 
131
 
 
132
        buf = g_base64_decode(str, &buf_len);
 
133
 
 
134
        err = gcry_cipher_decrypt(hd, buf, buf_len, NULL, 0);
 
135
 
 
136
        if (err)
 
137
        {
 
138
                g_print("gcry_cipher_decrypt failure: %s\n", gcry_strerror(err));
 
139
                g_free(buf);
 
140
                gcry_cipher_close(hd);
 
141
                return NULL;
 
142
        }
 
143
 
 
144
        gcry_cipher_close(hd);
 
145
 
 
146
        /* Just in case */
 
147
        buf[buf_len - 1] = '\0';
 
148
 
 
149
        return (gchar*) buf;
 
150
}
 
151
 
 
152
#else
 
153
 
 
154
gchar* remmina_crypt_encrypt(const gchar *str)
 
155
{
 
156
        return NULL;
 
157
}
 
158
 
 
159
gchar* remmina_crypt_decrypt(const gchar *str)
 
160
{
 
161
        return NULL;
 
162
}
 
163
 
 
164
#endif
 
165