chiark / gitweb /
dirmngr: Make sure Tor mode is also set for DNS on SIGHUP.
[gnupg2.git] / dirmngr / dirmngr.h
1 /* dirmngr.h - Common definitions for the dirmngr
2  * Copyright (C) 2002 Klarälvdalens Datakonsult AB
3  * Copyright (C) 2004, 2015 g10 Code GmbH
4  * Copyright (C) 2014 Werner Koch
5  *
6  * This file is part of GnuPG.
7  *
8  * GnuPG is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * GnuPG is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, see <https://www.gnu.org/licenses/>.
20  */
21
22 #ifndef DIRMNGR_H
23 #define DIRMNGR_H
24
25 #include "./dirmngr-err.h"
26 #define map_assuan_err(a) \
27         map_assuan_err_with_source (GPG_ERR_SOURCE_DEFAULT, (a))
28 #include <errno.h>
29 #include <gcrypt.h>
30 #include <ksba.h>
31
32 #include "../common/util.h"
33 #include "../common/membuf.h"
34 #include "../common/sysutils.h" /* (gnupg_fd_t) */
35 #include "../common/asshelp.h"  /* (assuan_context_t) */
36 #include "../common/i18n.h"
37 #include "http.h"     /* (parsed_uri_t) */
38
39 /* This objects keeps information about a particular LDAP server and
40    is used as item of a single linked list of servers. */
41 struct ldap_server_s
42 {
43   struct ldap_server_s* next;
44
45   char *host;
46   int   port;
47   char *user;
48   char *pass;
49   char *base;
50 };
51 typedef struct ldap_server_s *ldap_server_t;
52
53
54 /* This objects is used to build a list of URI consisting of the
55    original and the parsed URI.  */
56 struct uri_item_s
57 {
58   struct uri_item_s *next;
59   parsed_uri_t parsed_uri;  /* The broken down URI.  */
60   char uri[1];              /* The original URI.  */
61 };
62 typedef struct uri_item_s *uri_item_t;
63
64
65 /* A list of fingerprints.  */
66 struct fingerprint_list_s;
67 typedef struct fingerprint_list_s *fingerprint_list_t;
68 struct fingerprint_list_s
69 {
70   fingerprint_list_t next;
71   char hexfpr[20+20+1];
72 };
73
74
75 /* A large struct named "opt" to keep global flags.  */
76 struct
77 {
78   unsigned int debug; /* debug flags (DBG_foo_VALUE) */
79   int verbose;        /* verbosity level */
80   int quiet;          /* be as quiet as possible */
81   int dry_run;        /* don't change any persistent data */
82   int batch;          /* batch mode */
83   const char *homedir_cache; /* Dir for cache files (/var/cache/dirmngr).  */
84
85   char *config_filename;     /* Name of a config file, which will be
86                                 reread on a HUP if it is not NULL. */
87
88   char *ldap_wrapper_program; /* Override value for the LDAP wrapper
89                                  program.  */
90   char *http_wrapper_program; /* Override value for the HTTP wrapper
91                                  program.  */
92
93   int running_detached; /* We are running in detached mode.  */
94   int use_tor;          /* Tor mode has been enabled.  */
95   int allow_version_check; /* --allow-version-check is active.  */
96
97   int force;          /* Force loading outdated CRLs. */
98
99   int disable_http;       /* Do not use HTTP at all.  */
100   int disable_ldap;       /* Do not use LDAP at all.  */
101   int honor_http_proxy;   /* Honor the http_proxy env variable. */
102   const char *http_proxy; /* The default HTTP proxy.  */
103   const char *ldap_proxy; /* Use given LDAP proxy.  */
104   int only_ldap_proxy;    /* Only use the LDAP proxy; no fallback.  */
105   int ignore_http_dp;     /* Ignore HTTP CRL distribution points.  */
106   int ignore_ldap_dp;     /* Ignore LDAP CRL distribution points.  */
107   int ignore_ocsp_service_url; /* Ignore OCSP service URLs as given in
108                                   the certificate.  */
109
110   /* A list of certificate extension OIDs which are ignored so that
111      one can claim that a critical extension has been handled.  One
112      OID per string.  */
113   strlist_t ignored_cert_extensions;
114
115   int allow_ocsp;     /* Allow using OCSP. */
116
117   int max_replies;
118   unsigned int ldaptimeout;
119
120   ldap_server_t ldapservers;
121   int add_new_ldapservers;
122
123   const char *ocsp_responder;     /* Standard OCSP responder's URL. */
124   fingerprint_list_t ocsp_signer; /* The list of fingerprints with allowed
125                                      standard OCSP signer certificates.  */
126
127   unsigned int ocsp_max_clock_skew; /* Allowed seconds of clocks skew. */
128   unsigned int ocsp_max_period;     /* Seconds a response is at maximum
129                                        considered valid after thisUpdate. */
130   unsigned int ocsp_current_period; /* Seconds a response is considered
131                                        current after nextUpdate. */
132
133   strlist_t keyserver;              /* List of default keyservers.  */
134 } opt;
135
136
137 #define DBG_X509_VALUE    1     /* debug x.509 parsing */
138 #define DBG_CRYPTO_VALUE  4     /* debug low level crypto */
139 #define DBG_DNS_VALUE     16    /* debug DNS calls.  */
140 #define DBG_MEMORY_VALUE  32    /* debug memory allocation stuff */
141 #define DBG_CACHE_VALUE   64    /* debug the caching */
142 #define DBG_MEMSTAT_VALUE 128   /* show memory statistics */
143 #define DBG_HASHING_VALUE 512   /* debug hashing operations */
144 #define DBG_IPC_VALUE     1024  /* debug assuan communication */
145 #define DBG_NETWORK_VALUE 2048  /* debug network I/O.  */
146 #define DBG_LOOKUP_VALUE  8192  /* debug lookup details */
147
148 #define DBG_X509    (opt.debug & DBG_X509_VALUE)
149 #define DBG_CRYPTO  (opt.debug & DBG_CRYPTO_VALUE)
150 #define DBG_DNS     (opt.debug & DBG_DNS_VALUE)
151 #define DBG_MEMORY  (opt.debug & DBG_MEMORY_VALUE)
152 #define DBG_CACHE   (opt.debug & DBG_CACHE_VALUE)
153 #define DBG_HASHING (opt.debug & DBG_HASHING_VALUE)
154 #define DBG_IPC     (opt.debug & DBG_IPC_VALUE)
155 #define DBG_NETWORK (opt.debug & DBG_NETWORK_VALUE)
156 #define DBG_LOOKUP  (opt.debug & DBG_LOOKUP_VALUE)
157
158 /* A simple list of certificate references. */
159 struct cert_ref_s
160 {
161   struct cert_ref_s *next;
162   unsigned char fpr[20];
163 };
164 typedef struct cert_ref_s *cert_ref_t;
165
166 /* Forward references; access only through server.c.  */
167 struct server_local_s;
168
169 /* Connection control structure.  */
170 struct server_control_s
171 {
172   int refcount;      /* Count additional references to this object.  */
173   int no_server;     /* We are not running under server control. */
174   int status_fd;     /* Only for non-server mode. */
175   struct server_local_s *server_local;
176   int force_crl_refresh; /* Always load a fresh CRL. */
177
178   int check_revocations_nest_level; /* Internal to check_revovations.  */
179   cert_ref_t ocsp_certs; /* Certificates from the current OCSP
180                             response. */
181
182   int audit_events;  /* Send audit events to client.  */
183   char *http_proxy;  /* The used http_proxy or NULL.  */
184 };
185
186
187 /*-- dirmngr.c --*/
188 void dirmngr_exit( int );  /* Wrapper for exit() */
189 void dirmngr_init_default_ctrl (ctrl_t ctrl);
190 void dirmngr_deinit_default_ctrl (ctrl_t ctrl);
191 void dirmngr_sighup_action (void);
192 const char* dirmngr_get_current_socket_name (void);
193
194
195 /*-- server.c --*/
196 ldap_server_t get_ldapservers_from_ctrl (ctrl_t ctrl);
197 ksba_cert_t get_cert_local (ctrl_t ctrl, const char *issuer);
198 ksba_cert_t get_issuing_cert_local (ctrl_t ctrl, const char *issuer);
199 ksba_cert_t get_cert_local_ski (ctrl_t ctrl,
200                                 const char *name, ksba_sexp_t keyid);
201 gpg_error_t get_istrusted_from_client (ctrl_t ctrl, const char *hexfpr);
202 int dirmngr_assuan_log_monitor (assuan_context_t ctx, unsigned int cat,
203                                 const char *msg);
204 void start_command_handler (gnupg_fd_t fd);
205 gpg_error_t dirmngr_status (ctrl_t ctrl, const char *keyword, ...);
206 gpg_error_t dirmngr_status_help (ctrl_t ctrl, const char *text);
207 gpg_error_t dirmngr_tick (ctrl_t ctrl);
208
209
210 /*-- loadswdb.c --*/
211 gpg_error_t dirmngr_load_swdb (ctrl_t ctrl, int force);
212
213
214 #endif /*DIRMNGR_H*/