2 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 Ben Kibbey <bjk@luxsci.net>
5 This file is part of pwmd.
7 Pwmd is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 2 of the License, or
10 (at your option) any later version.
12 Pwmd is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Pwmd. If not, see <http://www.gnu.org/licenses/>.
24 #include <gpg-error.h>
26 #include <sys/types.h>
33 struct crypto_s
*crypto
;
52 uint32_t datalen
; /* of the encrypted xml */
53 } __attribute__ ((packed
)) file_header_t
;
58 assuan_context_t client_ctx
;
60 gpg_error_t (*inquire_cb
) (void *data
, const char *line
);
71 size_t inquire_maxlen
;
76 gcry_sexp_t pkey
; /* SAVE --keygrip */
77 gcry_sexp_t sigpkey
; /* SAVE --sign-keygrip */
78 unsigned long s2k_count
; /* SAVE|PASSWD --s2k-count */
80 uint64_t iterations
; /* SAVE --cipher-iterations */
85 assuan_context_t client_ctx
;
86 struct agent_s
*agent
;
88 gcry_sexp_t pkey_sexp
;
89 unsigned char grip
[20];
90 gcry_sexp_t sigpkey_sexp
;
91 unsigned char sign_grip
[20];
92 gcry_sexp_t ciphertext_sexp
;
94 size_t ciphertext_len
;
98 char *filename
; /* the currently opened data file */
101 void cleanup_agent (struct agent_s
*agent
);
102 gpg_error_t
send_to_agent (struct agent_s
*agent
, char **result
, size_t * len
,
103 const char *fmt
, ...);
104 gpg_error_t
agent_init (struct agent_s
**);
105 gpg_error_t
read_data_file (const char *filename
, struct crypto_s
*crypto
);
106 gpg_error_t
read_data_header (const char *filename
, file_header_t
* fh
,
107 struct stat
*st
, int *fd
);
108 gpg_error_t
decrypt_data (assuan_context_t ctx
, struct crypto_s
*crypto
);
109 gpg_error_t
encrypt_data_file (assuan_context_t ctx
, struct crypto_s
*crypto
,
110 gcry_sexp_t pubkey
, gcry_sexp_t sigpkey
,
111 const char *filename
, const void *xml
,
113 void cleanup_crypto_stage1 (struct crypto_s
*cr
);
114 void cleanup_crypto_stage2 (struct crypto_s
*cr
);
115 void cleanup_crypto (struct crypto_s
**c
);
116 gpg_error_t
init_client_crypto (struct crypto_s
**crypto
);
117 gpg_error_t
generate_key (struct crypto_s
*, char *, int, int);
118 gpg_error_t
set_agent_option (struct agent_s
*agent
, const char *name
,
120 gpg_error_t
set_agent_passphrase (struct crypto_s
*crypto
, const char *key
,
122 void set_header_defaults (file_header_t
*);
123 gpg_error_t
set_pinentry_mode (struct agent_s
*agent
, const char *mode
);
124 gpg_error_t
get_pubkey (struct crypto_s
*crypto
, const char *hexgrip
,
125 gcry_sexp_t
* result
);
126 gpg_error_t
get_pubkey_bin (struct crypto_s
*crypto
,
127 const unsigned char *grip
, gcry_sexp_t
* result
);
128 gpg_error_t
set_pinentry_options (struct agent_s
*agent
);
129 gpg_error_t
export_common (struct crypto_s
*crypto
, const char *keygrip
,
130 const char *sign_keygrip
, int no_passphrase
,
131 const void *data
, size_t datalen
,
132 const char *outfile
, const char *keyparams
,
133 const char *keyfile
);
134 char *default_key_params (struct crypto_s
*crypto
);
135 void cleanup_save (struct save_s
*save
);
136 gpg_error_t
agent_loopback_cb (void *user
, const char *keyword
);
137 gpg_error_t
agent_passwd (struct crypto_s
*crypto
);
138 gpg_error_t
kill_scd (struct agent_s
*);
139 gpg_error_t
encrypt_xml (assuan_context_t ctx
, void *key
, size_t keylen
, int
140 algo
, const void *xml
, size_t len
, void **result
,
141 size_t * result_len
, unsigned char **iv
,
142 size_t * iv_len
, uint64_t iterations
);
143 gpg_error_t
decrypt_xml (struct crypto_s
*crypto
, const void *data
,