Remove GLib dependency.
[pwmd.git] / src / agent.h
blob6686efff0ffa7d6df8689c36d86f8b3a9b775606
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 {
32 struct crypto_s *crypto;
33 char *line;
34 size_t len;
35 int preset;
38 typedef struct {
39 size_t len;
40 void *buf;
41 } membuf_t;
43 typedef struct {
44 uint8_t magic[5];
45 uint32_t version;
46 uint64_t iterations;
47 uint64_t flags;
48 uint8_t iv[16];
49 uint32_t datalen; /* of the encrypted xml */
50 } __attribute__((packed)) file_header_t;
52 struct agent_s {
53 assuan_context_t ctx;
54 assuan_context_t client_ctx;
55 membuf_t data;
56 gpg_error_t (*inquire_cb)(void *data, const char *line);
57 void * inquire_data;
58 void * inquire_data2;
59 void * inquire_data3;
60 char *desc;
61 char *display;
62 char *ttyname;
63 char *ttytype;
64 char *lc_messages;
65 char *lc_ctype;
66 int restart;
67 size_t inquire_maxlen;
70 struct save_s {
71 gcry_sexp_t pkey; /* SAVE --keygrip */
72 gcry_sexp_t sigpkey; /* SAVE --sign-keygrip */
73 unsigned long s2k_count; /* SAVE|PASSWD --s2k-count */
74 file_header_t hdr;
75 uint64_t iterations; /* SAVE --cipher-iterations */
78 struct crypto_s {
79 assuan_context_t client_ctx;
80 struct agent_s *agent;
81 struct save_s save;
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;
87 void *ciphertext;
88 size_t ciphertext_len;
89 void *plaintext;
90 size_t plaintext_len;
91 file_header_t hdr;
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,
112 const char *value);
113 gpg_error_t set_agent_passphrase(struct crypto_s *crypto, const char *key,
114 size_t len);
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
135 len);
137 #endif