Back to index

opendkim  2.6.4
dkim-tables.c
Go to the documentation of this file.
00001 /*
00002 **  Copyright (c) 2005-2009 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 lint
00009 static char dkim_tables_c_id[] = "@(#)$Id: dkim-tables.c,v 1.7 2010/09/02 05:10:57 cm-msk Exp $";
00010 #endif /* !lint */
00011 
00012 /* system includes */
00013 #include <sys/types.h>
00014 #include <string.h>
00015 #include <assert.h>
00016 
00017 /* libopendkim includes */
00018 #include "dkim-tables.h"
00019 #include "dkim-internal.h"
00020 
00021 /* lookup tables */
00022 static struct nametable prv_keyparams[] = /* key parameters */
00023 {
00024        { "a",        DKIM_KEY_ALGORITHM },
00025        { "n",        DKIM_KEY_NOTES },
00026        { "p",        DKIM_KEY_DATA },
00027        { "s",        DKIM_KEY_SERVICE },
00028        { "t",        DKIM_KEY_FLAGS },
00029        { "v",        DKIM_KEY_VERSION },
00030        { NULL,              -1 }
00031 };
00032 struct nametable *keyparams = prv_keyparams;
00033 
00034 static struct nametable prv_keyflags[] =  /* policy flags */
00035 {
00036        { "y",        DKIM_SIGFLAG_TESTKEY },
00037        { "s",        DKIM_SIGFLAG_NOSUBDOMAIN },
00038        { NULL,              -1 }
00039 };
00040 struct nametable *keyflags = prv_keyflags;
00041 
00042 static struct nametable prv_policyparams[] =     /* policy parameters */
00043 {
00044        { "atps",     DKIM_PPARAM_ATPS },
00045        { "dkim",     DKIM_PPARAM_POLICY },
00046        { "r",        DKIM_PPARAM_REPORTADDR },
00047        { NULL,              -1 }
00048 };
00049 struct nametable *policyparams = prv_policyparams;
00050 
00051 static struct nametable prv_policies[] =  /* policies */
00052 {
00053        { "unknown",  DKIM_POLICY_UNKNOWN },
00054        { "all",      DKIM_POLICY_ALL },
00055        { "discardable", DKIM_POLICY_DISCARDABLE },
00056        { NULL,              -1 }
00057 };
00058 struct nametable *policies = prv_policies;
00059 
00060 static struct nametable prv_policyresults[] =    /* policy results */
00061 {
00062        { "none",                          DKIM_PRESULT_NONE },
00063        { "author domain policy found",           DKIM_PRESULT_FOUND },
00064        { "domain does not exist",         DKIM_PRESULT_NXDOMAIN },
00065        { NULL,                                   -1 }
00066 };
00067 struct nametable *policyresults = prv_policyresults;
00068 
00069 static struct nametable prv_sigparams[] = /* signature parameters */
00070 {
00071        { "a",        DKIM_PARAM_SIGNALG },
00072        { "b",        DKIM_PARAM_SIGNATURE },
00073        { "bh",              DKIM_PARAM_BODYHASH },
00074        { "c",        DKIM_PARAM_CANONALG },
00075        { "d",        DKIM_PARAM_DOMAIN },
00076        { "h",        DKIM_PARAM_HDRLIST },
00077        { "i",        DKIM_PARAM_IDENTITY },
00078        { "l",        DKIM_PARAM_BODYLENGTH },
00079        { "q",        DKIM_PARAM_QUERYMETHOD },
00080        { "s",        DKIM_PARAM_SELECTOR },
00081        { "t",        DKIM_PARAM_TIMESTAMP },
00082        { "v",        DKIM_PARAM_VERSION },
00083        { "x",        DKIM_PARAM_EXPIRATION },
00084        { "z",        DKIM_PARAM_COPIEDHDRS },
00085        { NULL,              -1 }
00086 };
00087 struct nametable *sigparams = prv_sigparams;
00088 
00089 static struct nametable prv_algorithms[] =       /* signing algorithms */
00090 {
00091        { "rsa-sha1", DKIM_SIGN_RSASHA1 },
00092        { "rsa-sha256",      DKIM_SIGN_RSASHA256 },
00093        { NULL,              -1 },
00094 };
00095 struct nametable *algorithms = prv_algorithms;
00096 
00097 static struct nametable prv_canonicalizations[] = /* canonicalizations */
00098 {
00099        { "simple",   DKIM_CANON_SIMPLE },
00100        { "relaxed",  DKIM_CANON_RELAXED },
00101        { NULL,              -1 },
00102 };
00103 struct nametable *canonicalizations = prv_canonicalizations;
00104 
00105 static struct nametable prv_hashes[] =           /* hashes */
00106 {
00107        { "sha1",     DKIM_HASHTYPE_SHA1 },
00108        { "sha256",   DKIM_HASHTYPE_SHA256 },
00109        { NULL,              -1 },
00110 };
00111 struct nametable *hashes = prv_hashes;
00112 
00113 static struct nametable prv_keytypes[] =  /* key types */
00114 {
00115        { "rsa",      DKIM_KEYTYPE_RSA },
00116        { NULL,              -1 },
00117 };
00118 struct nametable *keytypes = prv_keytypes;
00119 
00120 static struct nametable prv_querytypes[] =       /* query types */
00121 {
00122        { "dns",      DKIM_QUERY_DNS },
00123        { NULL,              -1 },
00124 };
00125 struct nametable *querytypes = prv_querytypes;
00126 
00127 static struct nametable prv_results[] =          /* result codes */
00128 {
00129        { "Success",                DKIM_STAT_OK },
00130        { "Bad signature",          DKIM_STAT_BADSIG },
00131        { "No signature",           DKIM_STAT_NOSIG },
00132        { "No key",                 DKIM_STAT_NOKEY },
00133        { "Unable to verify",              DKIM_STAT_CANTVRFY },
00134        { "Syntax error",           DKIM_STAT_SYNTAX },
00135        { "Resource unavailable",   DKIM_STAT_NORESOURCE },
00136        { "Internal error",         DKIM_STAT_INTERNAL },
00137        { "Revoked key",            DKIM_STAT_REVOKED },
00138        { "Invalid parameter",             DKIM_STAT_INVALID },
00139        { "Not implemented",        DKIM_STAT_NOTIMPLEMENT },
00140        { "Key retrieval failed",   DKIM_STAT_KEYFAIL },
00141        { "Reject requested",              DKIM_STAT_CBREJECT },
00142        { "Invalid result",         DKIM_STAT_CBINVALID },
00143        { "Try again later",        DKIM_STAT_CBTRYAGAIN },
00144        { "Multiple DNS replies",   DKIM_STAT_MULTIDNSREPLY },
00145        { NULL,                            -1 },
00146 };
00147 struct nametable *results = prv_results;
00148 
00149 static struct nametable prv_settypes[] =  /* set types */
00150 {
00151        { "key",      DKIM_SETTYPE_KEY },
00152        { "policy",   DKIM_SETTYPE_POLICY },
00153        { "signature",       DKIM_SETTYPE_SIGNATURE },
00154        { "signature reporting", DKIM_SETTYPE_SIGREPORT },
00155        { NULL,              -1 },
00156 };
00157 struct nametable *settypes = prv_settypes;
00158 
00159 static struct nametable prv_sigerrors[] = /* signature parsing errors */
00160 {
00161        { "no signature error",            DKIM_SIGERROR_OK },
00162        { "unsupported signature version", DKIM_SIGERROR_VERSION },
00163        { "invalid domain coverage",              DKIM_SIGERROR_DOMAIN },
00164        { "signature expired",                    DKIM_SIGERROR_EXPIRED },
00165        { "signature timestamp in the future",    DKIM_SIGERROR_FUTURE },
00166        { "signature timestamp order error",      DKIM_SIGERROR_TIMESTAMPS },
00167        { "invalid header canonicalization",      DKIM_SIGERROR_INVALID_HC },
00168        { "invalid body canonicalization", DKIM_SIGERROR_INVALID_BC },
00169        { "signature algorithm missing",   DKIM_SIGERROR_MISSING_A },
00170        { "signature algorithm invalid",   DKIM_SIGERROR_INVALID_A },
00171        { "header list missing",           DKIM_SIGERROR_MISSING_H },
00172        { "body length value invalid",            DKIM_SIGERROR_INVALID_L },
00173        { "query method invalid",          DKIM_SIGERROR_INVALID_Q },
00174        { "query option invalid",          DKIM_SIGERROR_INVALID_QO },
00175        { "domain tag missing",                   DKIM_SIGERROR_MISSING_D },
00176        { "domain tag empty",                     DKIM_SIGERROR_EMPTY_D },
00177        { "selector tag missing",          DKIM_SIGERROR_MISSING_S },
00178        { "selector tag empty",                   DKIM_SIGERROR_EMPTY_S },
00179        { "signature data missing",        DKIM_SIGERROR_MISSING_B },
00180        { "signature data empty",          DKIM_SIGERROR_EMPTY_B },
00181        { "signature data corrupt",        DKIM_SIGERROR_CORRUPT_B },
00182        { "key not found in DNS",          DKIM_SIGERROR_NOKEY },
00183        { "key DNS reply corrupt",         DKIM_SIGERROR_DNSSYNTAX },
00184        { "key DNS query failed",          DKIM_SIGERROR_KEYFAIL },
00185        { "body hash missing",                    DKIM_SIGERROR_MISSING_BH },
00186        { "body hash empty",               DKIM_SIGERROR_EMPTY_BH },
00187        { "body hash corrupt",                    DKIM_SIGERROR_CORRUPT_BH },
00188        { "signature verification failed", DKIM_SIGERROR_BADSIG },
00189        { "unauthorized subdomain",        DKIM_SIGERROR_SUBDOMAIN },
00190        { "multiple keys found",           DKIM_SIGERROR_MULTIREPLY },
00191        { "header list tag empty",         DKIM_SIGERROR_EMPTY_H },
00192        { "header list missing required entries", DKIM_SIGERROR_INVALID_H },
00193        { "length tag value exceeds body size", DKIM_SIGERROR_TOOLARGE_L },
00194        { "unprotected header field",             DKIM_SIGERROR_MBSFAILED },
00195        { "unknown key version",           DKIM_SIGERROR_KEYVERSION },
00196        { "unknown key hash",                     DKIM_SIGERROR_KEYUNKNOWNHASH },
00197        { "signature-key hash mismatch",   DKIM_SIGERROR_KEYHASHMISMATCH },
00198        { "not an e-mail key",                    DKIM_SIGERROR_NOTEMAILKEY },
00199        { "key type missing",                     DKIM_SIGERROR_KEYTYPEMISSING },
00200        { "unknown key type",                     DKIM_SIGERROR_KEYTYPEUNKNOWN },
00201        { "key revoked",                   DKIM_SIGERROR_KEYREVOKED },
00202        { "unable to apply public key",           DKIM_SIGERROR_KEYDECODE },
00203        { "version missing",               DKIM_SIGERROR_MISSING_V },
00204        { "version empty",                 DKIM_SIGERROR_EMPTY_V },
00205        { NULL,                                   -1 },
00206 };
00207 struct nametable *sigerrors = prv_sigerrors;
00208 
00209 /* ===================================================================== */
00210 
00211 /*
00212 **  DKIM_CODE_TO_NAME -- translate a mnemonic code to its name
00213 **
00214 **  Parameters:
00215 **     tbl -- name table
00216 **     code -- code to translate
00217 **
00218 **  Return value:
00219 **     Pointer to the name matching the provided code, or NULL if not found.
00220 */
00221 
00222 const char *
00223 dkim_code_to_name(struct nametable *tbl, const int code)
00224 {
00225        int c;
00226 
00227        assert(tbl != NULL);
00228 
00229        for (c = 0; ; c++)
00230        {
00231               if (tbl[c].tbl_code == -1 && tbl[c].tbl_name == NULL)
00232                      return NULL;
00233 
00234               if (tbl[c].tbl_code == code)
00235                      return tbl[c].tbl_name;
00236        }
00237 }
00238 
00239 /*
00240 **  DKIM_NAME_TO_CODE -- translate a name to a mnemonic code
00241 **
00242 **  Parameters:
00243 **     tbl -- name table
00244 **     name -- name to translate
00245 **
00246 **  Return value:
00247 **     A mnemonic code matching the provided name, or -1 if not found.
00248 */
00249 
00250 const int
00251 dkim_name_to_code(struct nametable *tbl, const char *name)
00252 {
00253        int c;
00254 
00255        assert(tbl != NULL);
00256 
00257        for (c = 0; ; c++)
00258        {
00259               if (tbl[c].tbl_code == -1 && tbl[c].tbl_name == NULL)
00260                      return -1;
00261 
00262               if (strcasecmp(tbl[c].tbl_name, name) == 0)
00263                      return tbl[c].tbl_code;
00264        }
00265 }