1 /* gpgsm.h - Global definitions for GpgSM
2 * Copyright (C) 2001 Free Software Foundation, Inc.
4 * This file is part of GnuPG.
6 * GnuPG 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 * GnuPG 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 02111-1307, USA
25 #include "../common/util.h"
26 #include "../common/errors.h"
28 #define MAX_DIGEST_LEN 24
30 /* A large struct name "opt" to keep global flags */
32 unsigned int debug
; /* debug flags (DBG_foo_VALUE) */
33 int verbose
; /* verbosity level */
34 int quiet
; /* be as quiet as possible */
35 int batch
; /* run in batch mode, i.e w/o any user interaction */
36 int answer_yes
; /* assume yes on most questions */
37 int answer_no
; /* assume no on most questions */
38 int dry_run
; /* don't change any persistent data */
40 const char *homedir
; /* configuration directory name */
41 const char *agent_program
;
46 const char *lc_messages
;
48 const char *dirmngr_program
;
49 char *outfile
; /* name of output file */
51 int with_key_data
;/* include raw key in the column delimted output */
53 int fingerprint
; /* list fingerprints in all key listings */
55 int armor
; /* force base64 armoring (see also ctrl.with_base64) */
56 int no_armor
; /* don't try to figure out whether data is base64 armored*/
58 const char *def_cipher_algoid
; /* cipher algorithm to use if
59 nothing else is specified */
61 int def_digest_algo
; /* Ditto for hash algorithm */
62 int def_compress_algo
; /* Ditto for compress algorithm */
64 char *def_recipient
; /* userID of the default recipient */
65 int def_recipient_self
; /* The default recipient is the default key */
67 char *local_user
; /* NULL or argument to -u */
69 int always_trust
; /* Trust the given keys even if there is no
70 valid certification path */
71 int skip_verify
; /* do not check signatures on data */
73 int lock_once
; /* Keep lock once they are set */
75 int ignore_time_conflict
; /* Ignore certain time conflicts */
77 int no_crl_check
; /* Don't do a CRL check */
79 char *policy_file
; /* full pathname of policy file */
80 int no_policy_check
; /* ignore certificate policies */
85 #define DBG_X509_VALUE 1 /* debug x.509 data reading/writing */
86 #define DBG_MPI_VALUE 2 /* debug mpi details */
87 #define DBG_CRYPTO_VALUE 4 /* debug low level crypto */
88 #define DBG_MEMORY_VALUE 32 /* debug memory allocation stuff */
89 #define DBG_CACHE_VALUE 64 /* debug the caching */
90 #define DBG_MEMSTAT_VALUE 128 /* show memory statistics */
91 #define DBG_HASHING_VALUE 512 /* debug hashing operations */
92 #define DBG_AGENT_VALUE 1024 /* debug communication with the agent */
94 #define DBG_X509 (opt.debug & DBG_X509_VALUE)
95 #define DBG_CRYPTO (opt.debug & DBG_CRYPTO_VALUE)
96 #define DBG_MEMORY (opt.debug & DBG_MEMORY_VALUE)
97 #define DBG_CACHE (opt.debug & DBG_CACHE_VALUE)
98 #define DBG_HASHING (opt.debug & DBG_HASHING_VALUE)
99 #define DBG_AGENT (opt.debug & DBG_AGENT_VALUE)
101 struct server_local_s
;
103 /* Note that the default values for this are set by
104 gpgsm_init_default_ctrl() */
105 struct server_control_s
{
106 int no_server
; /* we are not running under server control */
107 int status_fd
; /* only for non-server mode */
108 struct server_local_s
*server_local
;
109 int with_colons
; /* use column delimited output format */
111 int autodetect_encoding
; /* try to detect the input encoding */
112 int is_pem
; /* Is in PEM format */
113 int is_base64
; /* is in plain base-64 format */
115 int create_base64
; /* Create base64 encoded output */
116 int create_pem
; /* create PEM output */
117 const char *pem_name
; /* PEM name to use */
119 int include_certs
; /* -1 to send all certificates in the chain
120 along with a signature or the number of
121 certificates up the chain (0 = none, 1 = only
125 typedef struct server_control_s
*CTRL
;
127 /* data structure used in base64.c */
128 typedef struct base64_context_s
*Base64Context
;
132 struct certlist_s
*next
;
135 typedef struct certlist_s
*CERTLIST
;
138 void gpgsm_exit (int rc
);
139 void gpgsm_init_default_ctrl (struct server_control_s
*ctrl
);
142 void gpgsm_server (void);
143 void gpgsm_status (CTRL ctrl
, int no
, const char *text
);
144 void gpgsm_status2 (CTRL ctrl
, int no
, ...);
146 /*-- fingerprint --*/
147 char *gpgsm_get_fingerprint (KsbaCert cert
, int algo
, char *array
, int *r_len
);
148 char *gpgsm_get_fingerprint_string (KsbaCert cert
, int algo
);
149 char *gpgsm_get_fingerprint_hexstring (KsbaCert cert
, int algo
);
150 char *gpgsm_get_keygrip (KsbaCert cert
, char *array
);
151 char *gpgsm_get_keygrip_hexstring (KsbaCert cert
);
152 char *gpgsm_get_certid (KsbaCert cert
);
156 int gpgsm_create_reader (Base64Context
*ctx
,
157 CTRL ctrl
, FILE *fp
, KsbaReader
*r_reader
);
158 void gpgsm_destroy_reader (Base64Context ctx
);
159 int gpgsm_create_writer (Base64Context
*ctx
,
160 CTRL ctrl
, FILE *fp
, KsbaWriter
*r_writer
);
161 int gpgsm_finish_writer (Base64Context ctx
);
162 void gpgsm_destroy_writer (Base64Context ctx
);
166 void gpgsm_dump_cert (const char *text
, KsbaCert cert
);
167 void gpgsm_dump_serial (KsbaConstSexp p
);
168 void gpgsm_dump_time (time_t t
);
169 void gpgsm_dump_string (const char *string
);
171 /*-- certcheck.c --*/
172 int gpgsm_check_cert_sig (KsbaCert issuer_cert
, KsbaCert cert
);
173 int gpgsm_check_cms_signature (KsbaCert cert
, KsbaConstSexp sigval
,
174 GCRY_MD_HD md
, int hash_algo
);
175 /* fixme: move create functions to another file */
176 int gpgsm_create_cms_signature (KsbaCert cert
, GCRY_MD_HD md
, int mdalgo
,
181 int gpgsm_walk_cert_chain (KsbaCert start
, KsbaCert
*r_next
);
182 int gpgsm_is_root_cert (KsbaCert cert
);
183 int gpgsm_validate_path (KsbaCert cert
);
184 int gpgsm_basic_cert_check (KsbaCert cert
);
187 int gpgsm_cert_use_sign_p (KsbaCert cert
);
188 int gpgsm_cert_use_encrypt_p (KsbaCert cert
);
189 int gpgsm_cert_use_verify_p (KsbaCert cert
);
190 int gpgsm_cert_use_decrypt_p (KsbaCert cert
);
191 int gpgsm_add_to_certlist (const char *name
, CERTLIST
*listaddr
);
192 void gpgsm_release_certlist (CERTLIST list
);
193 int gpgsm_find_cert (const char *name
, KsbaCert
*r_cert
);
196 void gpgsm_list_keys (CTRL ctrl
, STRLIST names
, FILE *fp
, unsigned int mode
);
199 int gpgsm_import (CTRL ctrl
, int in_fd
);
202 void gpgsm_export (CTRL ctrl
, STRLIST names
, FILE *fp
);
205 int gpgsm_verify (CTRL ctrl
, int in_fd
, int data_fd
, FILE *out_fp
);
208 int gpgsm_get_default_cert (KsbaCert
*r_cert
);
209 int gpgsm_sign (CTRL ctrl
, int data_fd
, int detached
, FILE *out_fp
);
212 int gpgsm_encrypt (CTRL ctrl
, CERTLIST recplist
, int in_fd
, FILE *out_fp
);
215 int gpgsm_decrypt (CTRL ctrl
, int in_fd
, FILE *out_fp
);
217 /*-- certreqgen.c --*/
218 int gpgsm_genkey (CTRL ctrl
, int in_fd
, FILE *out_fp
);
220 /*-- call-agent.c --*/
221 int gpgsm_agent_pksign (const char *keygrip
,
222 unsigned char *digest
,
225 char **r_buf
, size_t *r_buflen
);
226 int gpgsm_agent_pkdecrypt (const char *keygrip
,
227 KsbaConstSexp ciphertext
,
228 char **r_buf
, size_t *r_buflen
);
229 int gpgsm_agent_genkey (KsbaConstSexp keyparms
, KsbaSexp
*r_pubkey
);
230 int gpgsm_agent_istrusted (KsbaCert cert
);
231 int gpgsm_agent_havekey (const char *hexkeygrip
);
232 int gpgsm_agent_marktrusted (KsbaCert cert
);
233 int gpgsm_agent_learn (void);
235 /*-- call-dirmngr.c --*/
236 int gpgsm_dirmngr_isvalid (KsbaCert cert
);