Back to index

opendkim  2.6.4
dkim-types.h
Go to the documentation of this file.
00001 /*
00002 **  Copyright (c) 2005-2008 Sendmail, Inc. and its suppliers.
00003 **    All rights reserved.
00004 **
00005 **  Copyright (c) 2009-2012, The OpenDKIM Project.  All rights reserved.
00006 */
00007 
00008 #ifndef _DKIM_TYPES_H_
00009 #define _DKIM_TYPES_H_
00010 
00011 #ifndef lint
00012 static char dkim_types_h_id[] = "@(#)$Id: dkim-types.h,v 1.23 2010/10/28 02:41:25 cm-msk Exp $";
00013 #endif /* !lint */
00014 
00015 #include "build-config.h"
00016 
00017 /* system includes */
00018 #include <sys/types.h>
00019 #ifdef HAVE_STDBOOL_H
00020 # include <stdbool.h>
00021 #endif /* HAVE_STDBOOL_H */
00022 #ifdef USE_TRE
00023 # ifdef TRE_PRE_080
00024 #  include <tre/regex.h>
00025 # else /* TRE_PRE_080 */
00026 #  include <tre/tre.h>
00027 # endif /* TRE_PRE_080 */
00028 #else /* USE_TRE */
00029 # include <regex.h>
00030 #endif /* USE_TRE */
00031 
00032 #ifdef USE_GNUTLS
00033 # include <gnutls/gnutls.h>
00034 # include <gnutls/crypto.h>
00035 # include <gnutls/abstract.h>
00036 #else /* USE_GNUTLS */
00037 /* OpenSSL includes */
00038 # include <openssl/pem.h>
00039 # include <openssl/rsa.h>
00040 # include <openssl/bio.h>
00041 # include <openssl/err.h>
00042 # include <openssl/sha.h>
00043 #endif /* USE_GNUTLS */
00044 
00045 #ifdef QUERY_CACHE
00046 /* libdb includes */
00047 # include <db.h>
00048 #endif /* QUERY_CACHE */
00049 
00050 /* libopendkim includes */
00051 #include "dkim.h"
00052 #include "dkim-internal.h"
00053 
00054 /* struct dkim_xtag -- signature extension tag */
00055 struct dkim_xtag
00056 {
00057        const char *         xt_tag;
00058        const char *         xt_value;
00059        struct dkim_xtag *   xt_next;
00060 };
00061 
00062 /* struct dkim_queryinfo -- DNS query information */
00063 struct dkim_queryinfo
00064 {
00065        int                  dq_type;
00066        const char           dq_name[DKIM_MAXHOSTNAMELEN + 1];
00067 };
00068 
00069 /* struct dkim_pstate -- policy query state */
00070 struct dkim_pstate
00071 {
00072        unsigned int         ps_pflags;
00073        int                  ps_qstatus;
00074        int                  ps_state;
00075        dkim_policy_t        ps_policy;
00076        DKIM *               ps_dkim;
00077 };
00078 
00079 /* struct dkim_dstring -- a dynamically-sized string */
00080 struct dkim_dstring
00081 {
00082        int                  ds_alloc;
00083        int                  ds_max;
00084        int                  ds_len;
00085        DKIM *               ds_dkim;
00086        unsigned char *             ds_buf;
00087 };
00088 
00089 /* struct dkim_header -- an RFC2822 header of some kind */
00090 struct dkim_header
00091 {
00092        int                  hdr_flags;
00093        size_t               hdr_textlen;
00094        size_t               hdr_namelen;
00095        u_char *             hdr_text;
00096        u_char *             hdr_colon;
00097        struct dkim_header * hdr_next;
00098 };
00099 
00100 /* hdr_flags bits */
00101 #define       DKIM_HDR_SIGNED             0x01
00102 
00103 /* struct dkim_plist -- a parameter/value pair */
00104 struct dkim_plist
00105 {
00106        u_char *             plist_param;
00107        u_char *             plist_value;
00108        struct dkim_plist *  plist_next;
00109 };
00110 
00111 /* struct dkim_set -- a set of parameter/value pairs */
00112 struct dkim_set
00113 {
00114        _Bool                set_bad;
00115        dkim_set_t           set_type;
00116        u_char *             set_data;
00117        const char *         set_name;
00118        void *               set_udata;
00119        struct dkim_plist *  set_plist[NPRINTABLE];
00120        struct dkim_set *    set_next;
00121 };
00122 
00123 /* struct dkim_siginfo -- signature information for use by the caller */
00124 struct dkim_siginfo
00125 {
00126        int                  sig_dnssec_key;
00127        u_int                sig_flags;
00128        u_int                sig_error;
00129        u_int                sig_bh;
00130        u_int                sig_version;
00131        u_int                sig_hashtype;
00132        u_int                sig_keytype;
00133        u_int                sig_keybits;
00134        size_t               sig_siglen;
00135        size_t               sig_keylen;
00136        size_t               sig_b64keylen;
00137        dkim_query_t         sig_query;
00138        dkim_alg_t           sig_signalg;
00139        dkim_canon_t         sig_hdrcanonalg;
00140        dkim_canon_t         sig_bodycanonalg;
00141        uint64_t             sig_timestamp;
00142        u_char *             sig_domain;
00143        u_char *             sig_selector;
00144        u_char *             sig_sig;
00145        u_char *             sig_key;
00146        u_char *             sig_b64key;
00147        void *               sig_context;
00148        void *               sig_signature;
00149        struct dkim_canon *  sig_hdrcanon;
00150        struct dkim_canon *  sig_bodycanon;
00151        struct dkim_set *    sig_taglist;
00152        struct dkim_set *    sig_keytaglist;
00153 };
00154 
00155 #ifdef USE_GNUTLS
00156 /* struct dkim_sha -- stuff needed to do a sha hash */
00157 struct dkim_sha
00158 {
00159        int                  sha_tmpfd;
00160        u_int                sha_outlen;
00161        gnutls_hash_hd_t     sha_hd;
00162        u_char *             sha_out;
00163 };
00164 #else /* USE_GNUTLS */
00165 /* struct dkim_sha1 -- stuff needed to do a sha1 hash */
00166 struct dkim_sha1
00167 {
00168        int                  sha1_tmpfd;
00169        BIO *                sha1_tmpbio;
00170        SHA_CTX                     sha1_ctx;
00171        u_char               sha1_out[SHA_DIGEST_LENGTH];
00172 };
00173 
00174 # ifdef HAVE_SHA256
00175 /* struct dkim_sha256 -- stuff needed to do a sha256 hash */
00176 struct dkim_sha256
00177 {
00178        int                  sha256_tmpfd;
00179        BIO *                sha256_tmpbio;
00180        SHA256_CTX           sha256_ctx;
00181        u_char               sha256_out[SHA256_DIGEST_LENGTH];
00182 };
00183 # endif /* HAVE_SHA256 */
00184 #endif /* USE_GNUTLS */
00185 
00186 /* struct dkim_canon -- a canonicalization status handle */
00187 struct dkim_canon
00188 {
00189        _Bool                canon_done;
00190        _Bool                canon_hdr;
00191        _Bool                canon_blankline;
00192        int                  canon_lastchar;
00193        int                  canon_bodystate;
00194        u_int                canon_hashtype;
00195        u_int                canon_blanks;
00196        size_t               canon_hashbuflen;
00197        size_t               canon_hashbufsize;
00198        ssize_t                     canon_remain;
00199        ssize_t                     canon_wrote;
00200        ssize_t                     canon_length;
00201        dkim_canon_t         canon_canon;
00202        u_char *             canon_hashbuf;
00203        u_char *             canon_hdrlist;
00204        void *               canon_hash;
00205        struct dkim_dstring *       canon_buf;
00206        struct dkim_header * canon_sigheader;
00207        struct dkim_canon *  canon_next;
00208 };
00209 
00210 /* struct dkim_rsa -- stuff needed to do RSA sign/verify */
00211 struct dkim_rsa
00212 {
00213 #ifdef USE_GNUTLS
00214        size_t               rsa_rsaoutlen;
00215        unsigned int         rsa_keysize;
00216        gnutls_x509_privkey_t       rsa_key;
00217        gnutls_privkey_t     rsa_privkey;
00218        gnutls_pubkey_t             rsa_pubkey;
00219        gnutls_datum_t              rsa_sig;
00220        gnutls_datum_t              rsa_digest;
00221        gnutls_datum_t              rsa_rsaout;
00222        gnutls_datum_t              rsa_keydata;
00223 #else /* USE_GNUTLS */
00224        u_char               rsa_pad;
00225        int                  rsa_keysize;
00226        size_t               rsa_rsainlen;
00227        size_t               rsa_rsaoutlen;
00228        EVP_PKEY *           rsa_pkey;
00229        RSA *                rsa_rsa;
00230        BIO *                rsa_keydata;
00231        u_char *             rsa_rsain;
00232        u_char *             rsa_rsaout;
00233 #endif /* USE_GNUTLS */
00234 };
00235 
00236 /* struct dkim_test_dns_data -- simulated DNS replies */
00237 struct dkim_test_dns_data
00238 {
00239        int                  dns_class;
00240        int                  dns_type;
00241        int                  dns_prec;
00242        u_char *             dns_query;
00243        u_char *             dns_reply;
00244        struct dkim_test_dns_data * dns_next;
00245 };
00246 
00247 /* struct dkim_unbound_cb_data -- libunbound callback data */
00248 struct dkim_unbound_cb_data
00249 {
00250        int                  ubd_done;
00251        int                  ubd_rcode;
00252        int                  ubd_id;
00253        int                  ubd_type;
00254        u_int                ubd_result;
00255        DKIM_STAT            ubd_stat;
00256        size_t               ubd_buflen;
00257        u_char *             ubd_buf;
00258        const char *         ubd_jobid;
00259 };
00260 
00261 /* struct dkim -- a complete DKIM transaction context */
00262 struct dkim
00263 {
00264        _Bool                dkim_partial;
00265        _Bool                dkim_bodydone;
00266        _Bool                dkim_subdomain;
00267        _Bool                dkim_skipbody;
00268 #ifdef _FFR_RESIGN
00269        _Bool                dkim_hdrbind;
00270 #endif /* _FFR_RESIGN */
00271        _Bool                dkim_eoh_reentry;
00272        int                  dkim_mode;
00273        int                  dkim_state;
00274        int                  dkim_chunkstate;
00275        int                  dkim_chunksm;
00276        int                  dkim_chunkcrlf;
00277        int                  dkim_timeout;
00278        int                  dkim_presult;
00279        int                  dkim_hdrcnt;
00280        int                  dkim_minsiglen;
00281 #ifdef _FFR_RESIGN
00282        u_int                dkim_refcnt;
00283 #endif /* _FFR_RESIGN */
00284 #ifdef QUERY_CACHE
00285        u_int                dkim_cache_queries;
00286        u_int                dkim_cache_hits;
00287 #endif /* QUERY_CACHE */
00288        u_int                dkim_version;
00289        u_int                dkim_sigcount;
00290        int                  dkim_dnssec_policy;
00291        size_t               dkim_margin;
00292        size_t               dkim_b64siglen;
00293        size_t               dkim_keylen;
00294        size_t               dkim_errlen;
00295        uint64_t             dkim_timestamp;
00296        dkim_query_t         dkim_querymethod;
00297        dkim_canon_t         dkim_hdrcanonalg;
00298        dkim_canon_t         dkim_bodycanonalg;
00299        dkim_alg_t           dkim_signalg;
00300 #ifdef _FFR_ATPS
00301        _Bool                dkim_atps;
00302 #endif /* _FFR_ATPS */
00303        ssize_t                     dkim_bodylen;
00304        ssize_t                     dkim_signlen;
00305        const u_char *              dkim_id;
00306        u_char *             dkim_domain;
00307        u_char *             dkim_user;
00308        u_char *             dkim_selector;
00309        u_char *             dkim_b64key;
00310        u_char *             dkim_b64sig;
00311        u_char *             dkim_key;
00312        u_char *             dkim_reportaddr;
00313        u_char *             dkim_sender;
00314        u_char *             dkim_signer;
00315        u_char *             dkim_error;
00316        u_char *             dkim_hdrlist;
00317        u_char *             dkim_zdecode;
00318        u_char *             dkim_tmpdir;
00319        DKIM_SIGINFO *              dkim_signature;
00320        void *               dkim_keydata;
00321        void *               dkim_closure;
00322        const void *         dkim_user_context;
00323 #ifdef _FFR_RESIGN
00324        DKIM *               dkim_resign;
00325 #endif /* _FFR_RESIGN */
00326        struct dkim_xtag *   dkim_xtags;
00327        struct dkim_siginfo **      dkim_siglist;
00328        struct dkim_set *    dkim_sethead;
00329        struct dkim_set *    dkim_settail;
00330        struct dkim_set *    dkim_sigset;
00331        struct dkim_header * dkim_hhead;
00332        struct dkim_header * dkim_htail;
00333        struct dkim_header * dkim_senderhdr;
00334        struct dkim_canon *  dkim_canonhead;
00335        struct dkim_canon *  dkim_canontail;
00336        struct dkim_dstring *       dkim_hdrbuf;
00337        struct dkim_dstring *       dkim_canonbuf;
00338        struct dkim_test_dns_data * dkim_dnstesth;
00339        struct dkim_test_dns_data * dkim_dnstestt;
00340        DKIM_LIB *           dkim_libhandle;
00341 };
00342 
00343 /* struct dkim_lib -- a DKIM library context */
00344 struct dkim_lib
00345 {
00346        _Bool                dkiml_signre;
00347        _Bool                dkiml_skipre;
00348        u_int                dkiml_flags;
00349        u_int                dkiml_timeout;
00350        u_int                dkiml_version;
00351        u_int                dkiml_callback_int;
00352        u_int                dkiml_flsize;
00353        u_int                dkiml_nalwayshdrs;
00354        uint64_t             dkiml_fixedtime;
00355        uint64_t             dkiml_sigttl;
00356        uint64_t             dkiml_clockdrift;
00357        dkim_query_t         dkiml_querymethod;
00358        u_int *                     dkiml_flist;
00359        void *               (*dkiml_malloc) (void *closure, size_t nbytes);
00360        void                 (*dkiml_free) (void *closure, void *p);
00361        u_char **            dkiml_senderhdrs;
00362        u_char **            dkiml_alwayshdrs;
00363        u_char **            dkiml_oversignhdrs;
00364        u_char **            dkiml_mbs;
00365 #ifdef QUERY_CACHE
00366        DB *                 dkiml_cache;
00367 #endif /* QUERY_CACHE */
00368        regex_t                     dkiml_hdrre;
00369        regex_t                     dkiml_skiphdrre;
00370        DKIM_CBSTAT          (*dkiml_key_lookup) (DKIM *dkim,
00371                                                  DKIM_SIGINFO *sig,
00372                                                  u_char *buf,
00373                                                  size_t buflen);
00374        DKIM_CBSTAT          (*dkiml_policy_lookup) (DKIM *dkim,
00375                                                     u_char *query,
00376                                                     _Bool excheck,
00377                                                     u_char *buf,
00378                                                     size_t buflen,
00379                                                     int *qstat);
00380        void *               (*dkiml_sig_handle) (void *closure);
00381        void                 (*dkiml_sig_handle_free) (void *closure,
00382                                                       void *user);
00383        void                 (*dkiml_sig_tagvalues) (void *user,
00384                                                     dkim_param_t pcode,
00385                                                     const u_char *param,
00386                                                     const u_char *value);
00387        DKIM_CBSTAT          (*dkiml_prescreen) (DKIM *dkim,
00388                                                 DKIM_SIGINFO **sigs,
00389                                                 int nsigs);
00390        DKIM_CBSTAT          (*dkiml_final) (DKIM *dkim,
00391                                             DKIM_SIGINFO **sigs,
00392                                             int nsigs);
00393        void                 (*dkiml_dns_callback) (const void *context);
00394        void                 *dkiml_dns_service;
00395        int                  (*dkiml_dns_start) (void *srv, int type,
00396                                                 unsigned char *query,
00397                                                 unsigned char *buf,
00398                                                 size_t buflen,
00399                                                 void **qh);
00400        int                  (*dkiml_dns_cancel) (void *srv, void *qh);
00401        int                  (*dkiml_dns_waitreply) (void *srv,
00402                                                     void *qh,
00403                                                     struct timeval *to,
00404                                                     size_t *bytes,
00405                                                     int *error,
00406                                                     int *dnssec);
00407        u_char               dkiml_tmpdir[MAXPATHLEN + 1];
00408        u_char               dkiml_queryinfo[MAXPATHLEN + 1];
00409 };
00410 
00411 #endif /* _DKIM_TYPES_H_ */