1 /* vim:tw=78:ts=8:sw=4:set ft=c: */
3 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 Ben Kibbey <bjk@luxsci.net>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02110-1301 USA
23 #include <sys/types.h>
27 #include <glib/gi18n.h>
29 #define _ASSUAN_ONLY_GPG_ERRORS 1
67 pinentry_status_t status
;
69 gchar key
[ASSUAN_LINELENGTH
];
74 typedef gpg_error_t (*pinentry_finalize_cb
)(assuan_context_t
, guchar
*, gsize
,
79 pth_mutex_t status_mutex
;
80 pth_mutex_t cond_mutex
;
85 pinentry_finalize_cb cb
;
89 pinentry_status_t status
;
104 assuan_error_t (*inquire_cb
)(void *data
, const char *line
);
115 guint8 salt
[8]; // version 2.21 and later
131 file_header_v1_t fh1
;
132 file_header_t fh2_nosalt
;
135 } file_header_internal_t
;
137 struct client_thread_s
{
141 pth_mutex_t mp_mutex
;
146 struct assuan_cmd_s
{
147 assuan_context_t ctx
;
153 /* For use with .flags in the data file header. */
154 #define PWMD_CIPHER_OFFSET (1)
155 #define PWMD_CIPHER(n) (PWMD_CIPHER_OFFSET << n)
156 #define PWMD_CIPHER_AES128 PWMD_CIPHER(0)
157 #define PWMD_CIPHER_AES192 PWMD_CIPHER(1)
158 #define PWMD_CIPHER_AES256 PWMD_CIPHER(2)
159 #define PWMD_CIPHER_SERPENT128 PWMD_CIPHER(3)
160 #define PWMD_CIPHER_SERPENT192 PWMD_CIPHER(4)
161 #define PWMD_CIPHER_SERPENT256 PWMD_CIPHER(5)
162 #define PWMD_CIPHER_CAMELLIA128 PWMD_CIPHER(6)
163 #define PWMD_CIPHER_CAMELLIA192 PWMD_CIPHER(7)
164 #define PWMD_CIPHER_CAMELLIA256 PWMD_CIPHER(8)
165 #define PWMD_CIPHER_3DES PWMD_CIPHER(9)
166 #define PWMD_CIPHER_CAST5 PWMD_CIPHER(10)
167 #define PWMD_CIPHER_BLOWFISH PWMD_CIPHER(11)
168 #define PWMD_CIPHER_TWOFISH PWMD_CIPHER(12)
169 #define PWMD_CIPHER_TWOFISH128 PWMD_CIPHER(13)
171 #define PWMD_FLAG_OFFSET (1<<15)
172 #define PWMD_FLAG(n) (PWMD_FLAG_OFFSET << n)
185 file_header_internal_t
*fh
;
191 /* These are flags that are set by a client option via the SET command. */
192 #define OPT_ITERATIONS 0x1
193 #define OPT_PINENTRY 0x2
194 #define OPT_PINENTRY_TO 0x4
195 #define OPT_CIPHER 0x8
196 #define OPT_LOCK 0x10
197 #define OPT_INQUIRE 0x20
200 assuan_context_t ctx
;
202 struct pinentry_s
*pinentry
;
204 gpointer doc
; /* xmlDocPtr */
215 gboolean is_lock_cmd
;
216 inquire_status_t inquire_status
;
217 struct client_thread_s
*thd
;
218 struct crypto_s
*crypto
;
221 gboolean lock_on_open
;
222 gboolean rc_on_locked
;
229 pth_mutex_t rcfile_mutex
;
230 pth_mutex_t cn_mutex
;
231 GSList
*cn_thread_list
;
233 void log_write(const gchar
*fmt
, ...);
234 gpg_error_t
send_error(assuan_context_t ctx
, gpg_error_t e
);
235 gint
open_file(const gchar
*filename
, struct stat
*st
);
236 gpg_error_t
do_xml_encrypt(struct client_s
*client
, struct crypto_s
*,
237 const gchar
*filename
);
238 gint
get_key_file_integer(const gchar
*section
, const gchar
*what
);
239 gdouble
get_key_file_double(const gchar
*section
, const gchar
*what
);
240 gboolean
get_key_file_boolean(const gchar
*section
, const gchar
*what
);
241 gchar
*get_key_file_string(const gchar
*section
, const gchar
*what
);
242 gchar
*expand_homedir(gchar
*str
);
243 void free_client(struct client_s
*client
);
244 void cleanup_crypto(struct crypto_s
**);
245 struct crypto_s
*init_client_crypto();
246 gpg_error_t
init_client_crypto2(const char *filename
,
247 struct crypto_s
*crypto
);
248 gpg_error_t
do_assuan_command(assuan_context_t ctx
,
249 void *(*cb
)(void *data
), void *data
);
250 void close_file_header(file_header_internal_t
*fh
);
251 void cleanup_ev_cb(void *arg
);
252 void cleanup_mutex_cb(void *arg
);
253 void cleanup_fd_cb(void *arg
);
254 void cleanup_unlink_cb(void *arg
);
255 void cleanup_attr_cb(void *arg
);
256 void cleanup_cancel_cb(void *arg
);
257 guint
pwmd_cipher_str_to_cipher(const gchar
*str
);
258 const gchar
*pwmd_cipher_to_str(guint64 flags
);
259 file_header_internal_t
*read_file_header(const gchar
*filename
, gboolean v1
,