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>
31 struct inquire_data_s
{
32 struct crypto_s
*crypto
;
49 uint32_t datalen
; /* of the encrypted xml */
50 } __attribute__((packed
)) file_header_t
;
54 assuan_context_t client_ctx
;
56 gpg_error_t (*inquire_cb
)(void *data
, const char *line
);
67 size_t inquire_maxlen
;
71 gcry_sexp_t pkey
; /* SAVE --keygrip */
72 gcry_sexp_t sigpkey
; /* SAVE --sign-keygrip */
73 unsigned long s2k_count
; /* SAVE|PASSWD --s2k-count */
75 uint64_t iterations
; /* SAVE --cipher-iterations */
79 assuan_context_t client_ctx
;
80 struct agent_s
*agent
;
82 gcry_sexp_t pkey_sexp
;
83 unsigned char grip
[20];
84 gcry_sexp_t sigpkey_sexp
;
85 unsigned char sign_grip
[20];
86 gcry_sexp_t ciphertext_sexp
;
88 size_t ciphertext_len
;
92 char *filename
; /* the currently opened data file */
95 void cleanup_agent(struct agent_s
*agent
);
96 gpg_error_t
send_to_agent(struct agent_s
*agent
, char **result
, size_t *len
,
97 const char *fmt
, ...);
98 gpg_error_t
agent_init(struct agent_s
**);
99 gpg_error_t
read_data_file(const char *filename
, struct crypto_s
*crypto
);
100 gpg_error_t
read_data_header(const char *filename
, file_header_t
*fh
,
101 struct stat
*st
, int *fd
);
102 gpg_error_t
decrypt_data(assuan_context_t ctx
, struct crypto_s
*crypto
);
103 gpg_error_t
encrypt_data_file(assuan_context_t ctx
, struct crypto_s
*crypto
,
104 gcry_sexp_t pubkey
, gcry_sexp_t sigpkey
, const char *filename
, const
105 void *xml
, size_t len
);
106 void cleanup_crypto_stage1(struct crypto_s
*cr
);
107 void cleanup_crypto_stage2(struct crypto_s
*cr
);
108 void cleanup_crypto(struct crypto_s
**c
);
109 gpg_error_t
init_client_crypto(struct crypto_s
**crypto
);
110 gpg_error_t
generate_key(struct crypto_s
*, char *, int, int);
111 gpg_error_t
set_agent_option(struct agent_s
*agent
, const char *name
,
113 gpg_error_t
set_agent_passphrase(struct crypto_s
*crypto
, const char *key
,
115 void set_header_defaults(file_header_t
*);
116 gpg_error_t
set_pinentry_mode(struct agent_s
*agent
, const char *mode
);
117 gpg_error_t
get_pubkey(struct crypto_s
*crypto
, const char *hexgrip
,
118 gcry_sexp_t
*result
);
119 gpg_error_t
get_pubkey_bin(struct crypto_s
*crypto
, const unsigned char *grip
,
120 gcry_sexp_t
*result
);
121 gpg_error_t
set_pinentry_options(struct agent_s
*agent
);
122 gpg_error_t
export_common(struct crypto_s
*crypto
, const char *keygrip
,
123 const char *sign_keygrip
, int no_passphrase
,
124 const void *data
, size_t datalen
, const char *outfile
,
125 const char *keyparams
, const char *keyfile
);
126 char *default_key_params(struct crypto_s
*crypto
);
127 void cleanup_save(struct save_s
*save
);
128 gpg_error_t
agent_loopback_cb(void *user
, const char *keyword
);
129 gpg_error_t
agent_passwd(struct crypto_s
*crypto
);
130 gpg_error_t
kill_scd(struct agent_s
*);
131 gpg_error_t
encrypt_xml(assuan_context_t ctx
, void *key
, size_t keylen
, int
132 algo
, const void *xml
, size_t len
, void **result
, size_t
133 *result_len
, unsigned char **iv
, size_t *iv_len
, uint64_t iterations
);
134 gpg_error_t
decrypt_xml(struct crypto_s
*crypto
, const void *data
, size_t