Imported Upstream version 2.2.1
[platform/upstream/gpg2.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 allow_version_check; /* --allow-version-check is active.  */
95
96   int force;          /* Force loading outdated CRLs. */
97
98
99   unsigned int connect_timeout;       /* Timeout for connect.  */
100   unsigned int connect_quick_timeout; /* Shorter timeout for connect.  */
101
102   int disable_http;       /* Do not use HTTP at all.  */
103   int disable_ldap;       /* Do not use LDAP at all.  */
104   int disable_ipv4;       /* Do not use legacy IP addresses.  */
105   int disable_ipv6;       /* Do not use standard IP addresses.  */
106   int honor_http_proxy;   /* Honor the http_proxy env variable. */
107   const char *http_proxy; /* The default HTTP proxy.  */
108   const char *ldap_proxy; /* Use given LDAP proxy.  */
109   int only_ldap_proxy;    /* Only use the LDAP proxy; no fallback.  */
110   int ignore_http_dp;     /* Ignore HTTP CRL distribution points.  */
111   int ignore_ldap_dp;     /* Ignore LDAP CRL distribution points.  */
112   int ignore_ocsp_service_url; /* Ignore OCSP service URLs as given in
113                                   the certificate.  */
114
115   /* A list of certificate extension OIDs which are ignored so that
116      one can claim that a critical extension has been handled.  One
117      OID per string.  */
118   strlist_t ignored_cert_extensions;
119
120   int allow_ocsp;     /* Allow using OCSP. */
121
122   int max_replies;
123   unsigned int ldaptimeout;
124
125   ldap_server_t ldapservers;
126   int add_new_ldapservers;
127
128   const char *ocsp_responder;     /* Standard OCSP responder's URL. */
129   fingerprint_list_t ocsp_signer; /* The list of fingerprints with allowed
130                                      standard OCSP signer certificates.  */
131
132   unsigned int ocsp_max_clock_skew; /* Allowed seconds of clocks skew. */
133   unsigned int ocsp_max_period;     /* Seconds a response is at maximum
134                                        considered valid after thisUpdate. */
135   unsigned int ocsp_current_period; /* Seconds a response is considered
136                                        current after nextUpdate. */
137
138   strlist_t keyserver;              /* List of default keyservers.  */
139 } opt;
140
141
142 #define DBG_X509_VALUE    1     /* debug x.509 parsing */
143 #define DBG_CRYPTO_VALUE  4     /* debug low level crypto */
144 #define DBG_DNS_VALUE     16    /* debug DNS calls.  */
145 #define DBG_MEMORY_VALUE  32    /* debug memory allocation stuff */
146 #define DBG_CACHE_VALUE   64    /* debug the caching */
147 #define DBG_MEMSTAT_VALUE 128   /* show memory statistics */
148 #define DBG_HASHING_VALUE 512   /* debug hashing operations */
149 #define DBG_IPC_VALUE     1024  /* debug assuan communication */
150 #define DBG_NETWORK_VALUE 2048  /* debug network I/O.  */
151 #define DBG_LOOKUP_VALUE  8192  /* debug lookup details */
152 #define DBG_EXTPROG_VALUE 16384 /* debug external program calls */
153
154 #define DBG_X509    (opt.debug & DBG_X509_VALUE)
155 #define DBG_CRYPTO  (opt.debug & DBG_CRYPTO_VALUE)
156 #define DBG_DNS     (opt.debug & DBG_DNS_VALUE)
157 #define DBG_MEMORY  (opt.debug & DBG_MEMORY_VALUE)
158 #define DBG_CACHE   (opt.debug & DBG_CACHE_VALUE)
159 #define DBG_HASHING (opt.debug & DBG_HASHING_VALUE)
160 #define DBG_IPC     (opt.debug & DBG_IPC_VALUE)
161 #define DBG_NETWORK (opt.debug & DBG_NETWORK_VALUE)
162 #define DBG_LOOKUP  (opt.debug & DBG_LOOKUP_VALUE)
163 #define DBG_EXTPROG (opt.debug & DBG_EXTPROG_VALUE)
164
165 /* A simple list of certificate references.  FIXME: Better use
166    certlist_t also for references (Store NULL at .cert) */
167 struct cert_ref_s
168 {
169   struct cert_ref_s *next;
170   unsigned char fpr[20];
171 };
172 typedef struct cert_ref_s *cert_ref_t;
173
174
175 /* Forward references; access only through server.c.  */
176 struct server_local_s;
177
178 #if SIZEOF_UNSIGNED_LONG == 8
179 # define SERVER_CONTROL_MAGIC 0x6469726d6e677220
180 #else
181 # define SERVER_CONTROL_MAGIC 0x6469726d
182 #endif
183
184 /* Connection control structure.  */
185 struct server_control_s
186 {
187   unsigned long magic;/* Always has SERVER_CONTROL_MAGIC.  */
188   int refcount;       /* Count additional references to this object.  */
189   int no_server;      /* We are not running under server control. */
190   int status_fd;      /* Only for non-server mode. */
191   struct server_local_s *server_local;
192   int force_crl_refresh; /* Always load a fresh CRL. */
193
194   int check_revocations_nest_level; /* Internal to check_revovations.  */
195   cert_ref_t ocsp_certs; /* Certificates from the current OCSP
196                             response. */
197
198   int audit_events;  /* Send audit events to client.  */
199   char *http_proxy;  /* The used http_proxy or NULL.  */
200
201   unsigned int timeout; /* Timeout for connect calls in ms.  */
202
203   unsigned int http_no_crl:1;  /* Do not check CRLs for https.  */
204 };
205
206
207 /*-- dirmngr.c --*/
208 void dirmngr_exit( int );  /* Wrapper for exit() */
209 void dirmngr_init_default_ctrl (ctrl_t ctrl);
210 void dirmngr_deinit_default_ctrl (ctrl_t ctrl);
211 void dirmngr_sighup_action (void);
212 const char* dirmngr_get_current_socket_name (void);
213 int dirmngr_use_tor (void);
214
215 /*-- Various housekeeping functions.  --*/
216 void ks_hkp_housekeeping (time_t curtime);
217 void ks_hkp_reload (void);
218
219
220 /*-- server.c --*/
221 ldap_server_t get_ldapservers_from_ctrl (ctrl_t ctrl);
222 ksba_cert_t get_cert_local (ctrl_t ctrl, const char *issuer);
223 ksba_cert_t get_issuing_cert_local (ctrl_t ctrl, const char *issuer);
224 ksba_cert_t get_cert_local_ski (ctrl_t ctrl,
225                                 const char *name, ksba_sexp_t keyid);
226 gpg_error_t get_istrusted_from_client (ctrl_t ctrl, const char *hexfpr);
227 int dirmngr_assuan_log_monitor (assuan_context_t ctx, unsigned int cat,
228                                 const char *msg);
229 void start_command_handler (gnupg_fd_t fd);
230 gpg_error_t dirmngr_status (ctrl_t ctrl, const char *keyword, ...);
231 gpg_error_t dirmngr_status_help (ctrl_t ctrl, const char *text);
232 gpg_error_t dirmngr_status_printf (ctrl_t ctrl, const char *keyword,
233                                    const char *format,
234                                    ...) GPGRT_ATTR_PRINTF(3,4);
235 gpg_error_t dirmngr_tick (ctrl_t ctrl);
236
237 /*-- http-ntbtls.c --*/
238 /* Note that we don't use a callback for gnutls.  */
239
240 gpg_error_t gnupg_http_tls_verify_cb (void *opaque,
241                                       http_t http,
242                                       http_session_t session,
243                                       unsigned int flags,
244                                       void *tls_context);
245
246
247 /*-- loadswdb.c --*/
248 gpg_error_t dirmngr_load_swdb (ctrl_t ctrl, int force);
249
250
251 #endif /*DIRMNGR_H*/