Include all required m4 macros.
[pwmd.git] / src / agent.h
blobf97101aed89a69a3153967a08563ac772158389c
1 /*
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/>.
20 #ifndef AGENT_H
21 #define AGENT_H
23 #include <assuan.h>
24 #include <gpg-error.h>
25 #include <gcrypt.h>
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <stdint.h>
29 #include "cipher.h"
31 struct inquire_data_s
33 struct crypto_s *crypto;
34 char *line;
35 size_t len;
36 int preset;
39 typedef struct
41 size_t len;
42 void *buf;
43 } membuf_t;
45 typedef struct
47 uint8_t magic[5];
48 uint32_t version;
49 uint64_t iterations;
50 uint64_t flags;
51 uint8_t iv[16];
52 uint32_t datalen; /* of the encrypted xml */
53 } __attribute__ ((packed)) file_header_t;
55 struct agent_s
57 assuan_context_t ctx;
58 assuan_context_t client_ctx;
59 membuf_t data;
60 gpg_error_t (*inquire_cb) (void *data, const char *line);
61 void *inquire_data;
62 void *inquire_data2;
63 void *inquire_data3;
64 char *desc;
65 char *display;
66 char *ttyname;
67 char *ttytype;
68 char *lc_messages;
69 char *lc_ctype;
70 int restart;
71 size_t inquire_maxlen;
74 struct save_s
76 gcry_sexp_t pkey; /* SAVE --keygrip */
77 gcry_sexp_t sigpkey; /* SAVE --sign-keygrip */
78 unsigned long s2k_count; /* SAVE|PASSWD --s2k-count */
79 file_header_t hdr;
80 uint64_t iterations; /* SAVE --cipher-iterations */
83 struct crypto_s
85 assuan_context_t client_ctx;
86 struct agent_s *agent;
87 struct save_s save;
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;
93 void *ciphertext;
94 size_t ciphertext_len;
95 void *plaintext;
96 size_t plaintext_len;
97 file_header_t hdr;
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,
112 size_t len);
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,
119 const char *value);
120 gpg_error_t set_agent_passphrase (struct crypto_s *crypto, const char *key,
121 size_t len);
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,
144 size_t len);
146 #endif