s/qmail 4.3.17
Next generation secure email transport
Loading...
Searching...
No Matches
dkim.h
Go to the documentation of this file.
1/*****************************************************************************
2* Copyright 2005 Alt-N Technologies, Ltd.
3*
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8* http://www.apache.org/licenses/LICENSE-2.0
9*
10* This code incorporates intellectual property owned by Yahoo! and licensed
11* pursuant to the Yahoo! DomainKeys Patent License Agreement.
12*
13* Unless required by applicable law or agreed to in writing, software
14* distributed under the License is distributed on an "AS IS" BASIS,
15* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16* See the License for the specific language governing permissions and
17* limitations under the License.
18*
19* Changes done by ¢feh@fehcom.de obeying the above license
20*
21*****************************************************************************/
22#ifndef DKIM_H_INCLUDE
23#define DKIM_H_INCLUDE
24
25#define MAKELONG(a,b) ((long)(((unsigned)(a) & 0xffff) | (((unsigned)(b) & 0xffff) << 16)))
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31// DKIM hash algorithms
32#define DKIM_HASH_SHA1 1
33#define DKIM_HASH_SHA256 2
34#define DKIM_HASH_SHA1_AND_SHA256 3
35#define DKIM_HASH_ED25519 4
36#define DKIM_HASH_RSA256_AND_ED25519 5
37
38// DKIM canonicalization methods
39#define DKIM_CANON_SIMPLE 1
40#define DKIM_CANON_NOWSP 2
41#define DKIM_CANON_RELAXED 3
42
43#define DKIM_SIGN_SIMPLE MAKELONG(DKIM_CANON_SIMPLE,DKIM_CANON_SIMPLE)
44#define DKIM_SIGN_SIMPLE_RELAXED MAKELONG(DKIM_CANON_RELAXED,DKIM_CANON_SIMPLE)
45#define DKIM_SIGN_RELAXED MAKELONG(DKIM_CANON_RELAXED,DKIM_CANON_RELAXED)
46#define DKIM_SIGN_RELAXED_SIMPLE MAKELONG(DKIM_CANON_SIMPLE,DKIM_CANON_RELAXED)
47
48// DKIM Error codes
49#define DKIM_SUCCESS 0 // operation successful
50#define DKIM_FAIL -1 // verify error: message is suspicious
51#define DKIM_BAD_SYNTAX -2 // signature error: DKIM-Signature could not parse or has bad tags/values
52#define DKIM_SIGNATURE_BAD -3 // signature error: RSA/ED25519 verify failed
53#define DKIM_SIGNATURE_BAD_BUT_TESTING -4 // signature error: RSA/ED25519 verify failed but testing
54#define DKIM_SIGNATURE_EXPIRED -5 // signature error: x= is old
55#define DKIM_SELECTOR_INVALID -6 // signature error: selector doesn't parse or contains invalid values
56#define DKIM_SELECTOR_GRANULARITY_MISMATCH -7 // signature error: selector g= doesn't match i=
57#define DKIM_SELECTOR_KEY_REVOKED -8 // signature error: selector p= empty
58#define DKIM_SELECTOR_DOMAIN_NAME_TOO_LONG -9 // signature error: selector domain name too long to request
59#define DKIM_SELECTOR_DNS_TEMP_FAILURE -10 // signature error: temporary dns failure requesting selector
60#define DKIM_SELECTOR_DNS_PERM_FAILURE -11 // signature error: permanent dns failure requesting selector
61#define DKIM_SELECTOR_PUBLIC_KEY_INVALID -12 // signature error: selector p= value invalid or wrong format
62#define DKIM_NO_SIGNATURES -13 // process error, no sigs
63#define DKIM_NO_VALID_SIGNATURES -14 // process error, no valid sigs
64#define DKIM_BODY_HASH_MISMATCH -15 // sigature verify error: message body does not hash to bh value
65#define DKIM_SELECTOR_ALGORITHM_MISMATCH -16 // signature error: selector h= doesn't match signature a=
66#define DKIM_STAT_INCOMPAT -17 // signature error: incompatible v=
67#define DKIM_UNSIGNED_FROM -18 // signature error: not all message's From headers in signature
68#define DKIM_OUT_OF_MEMORY -20 // memory allocation failed
69#define DKIM_INVALID_CONTEXT -21 // DKIMContext structure invalid for this operation
70#define DKIM_NO_SENDER -22 // signing error: Could not find From: or Sender: header in message
71#define DKIM_BAD_PRIVATE_KEY -23 // signing error: Could not parse private key
72#define DKIM_BUFFER_TOO_SMALL -24 // signing error: Buffer passed in is not large enough
73#define DKIM_MAX_ERROR -25 // set this to 1 greater than the highest error code (but negative)
74
75// DKIM_SUCCESS // verify result: all signatures verified
76 // signature result: signature verified
77#define DKIM_FINISHED_BODY 1 // process result: no more message body is needed
78#define DKIM_PARTIAL_SUCCESS 2 // verify result: at least one but not all signatures verified
79#define DKIM_NEUTRAL 3 // verify result: no signatures verified but message is not suspicous
80#define DKIM_SUCCESS_BUT_EXTRA 4 // signature result: signature verified but it did not include all of the body
81
82
83
84// This function is called once for each header in the message
85// return 1 to include this header in the signature and 0 to exclude.
86typedef int (*DKIMHEADERCALLBACK)(const char* szHeader);
87
88// This function is called to retrieve a TXT record from DNS
89typedef int (*DKIMDNSCALLBACK)(const char* szFQDN,char* szBuffer,int nBufLen);
90
91typedef struct DKIMContext_t
92{
93 unsigned int reserved1;
94 unsigned int reserved2;
95 void* reserved3;
97
98typedef struct DKIMSignOptions_t
99{
100 int nCanon; // canonization
101 int nIncludeBodyLengthTag; // 0 = don't include l= tag, 1 = include l= tag
102 int nIncludeTimeStamp; // 0 = don't include t= tag, 1 = include t= tag
103 int nIncludeQueryMethod; // 0 = don't include q= tag, 1 = include q= tag
104 char szSelector[64]; // selector - required
105 char szSelectorE[64]; // 2nd selector - optional
106 char szDomain[256]; // domain - optional - if empty, domain is computed from sender
107 char szIdentity[256]; // for i= tag, if empty tag will not be included in sig
108 unsigned long expireTime; // for x= tag, if 0 tag will not be included in sig
110 char szRequiredHeaders[256]; // colon-separated list of headers that must be signed
111 int nHash; // use one of the DKIM_HASH_xx constants here
112 // even if not present in the message
113 int nIncludeCopiedHeaders; // 0 = don't include z= tag, 1 = include z= tag
115
117{
118 DKIMDNSCALLBACK pfnSelectorCallback; // selector record callback
119 DKIMDNSCALLBACK pfnPracticesCallback; // ADSP record callback
120 int nHonorBodyLengthTag; // 0 = ignore l= tag, 1 = use l= tag to limit the amount of body verified
121 int nCheckPractices; // 0 = use default (unknown) practices, 1 = request and use author domain signing practices
122 int nSubjectRequired; // 0 = subject is required to be signed, 1 = not required
123 int nSaveCanonicalizedData; // 0 = canonicalized data is not saved, 1 = canonicalized data is saved
124 int nAllowUnsignedFromHeaders; // 0 = From headers not included in the signature are not allowed, 1 = allowed
126
128{
135
136int DKIMSignInit(DKIMContext* pSignContext,DKIMSignOptions* pOptions);
137int DKIMSignProcess(DKIMContext* pSignContext,char* szBuffer,int nBufLength);
138int DKIMSignGetSig2(DKIMContext* pSignContext,char* szRSAPrivKey,char *szECCPrivKey,char** pszSignature);
139void DKIMSignFree(DKIMContext* pSignContext);
140
141int DKIMVerifyInit(DKIMContext* pVerifyContext,DKIMVerifyOptions* pOptions);
142int DKIMVerifyProcess(DKIMContext* pVerifyContext,const char* szBuffer,int nBufLength);
143int DKIMVerifyResults(DKIMContext* pVerifyContext);
144int DKIMVerifyGetDetails(DKIMContext* pVerifyContext,int* nSigCount,DKIMVerifyDetails** pDetails,char* szPractices);
145void DKIMVerifyFree(DKIMContext* pVerifyContext);
146
147// const char *DKIMVersion();
148
149const char *DKIMGetErrorString(int ErrorCode);
150
151int _DKIM_ReportResult(char const *,char const *,char const *);
152const char *DKIM_ErrorResult(const int);
153
154#ifdef __cplusplus
155}
156#endif
157#endif
int DKIMSignInit(DKIMContext *pSignContext, DKIMSignOptions *pOptions)
Definition: dkim.cpp:53
int _DKIM_ReportResult(char const *, char const *, char const *)
Definition: dkimverify.cpp:102
struct DKIMVerifyDetails_t DKIMVerifyDetails
int(* DKIMHEADERCALLBACK)(const char *szHeader)
Definition: dkim.h:86
int DKIMVerifyInit(DKIMContext *pVerifyContext, DKIMVerifyOptions *pOptions)
Definition: dkim.cpp:95
int DKIMSignGetSig2(DKIMContext *pSignContext, char *szRSAPrivKey, char *szECCPrivKey, char **pszSignature)
Definition: dkim.cpp:77
struct DKIMContext_t DKIMContext
const char * DKIM_ErrorResult(const int)
Definition: dkimverify.cpp:124
struct DKIMVerifyOptions_t DKIMVerifyOptions
void DKIMSignFree(DKIMContext *pSignContext)
Definition: dkim.cpp:85
int DKIMSignProcess(DKIMContext *pSignContext, char *szBuffer, int nBufLength)
Definition: dkim.cpp:69
void DKIMVerifyFree(DKIMContext *pVerifyContext)
Definition: dkim.cpp:151
int DKIMVerifyProcess(DKIMContext *pVerifyContext, const char *szBuffer, int nBufLength)
Definition: dkim.cpp:115
int DKIMVerifyResults(DKIMContext *pVerifyContext)
Definition: dkim.cpp:126
const char * DKIMGetErrorString(int ErrorCode)
Definition: dkim.cpp:192
int DKIMVerifyGetDetails(DKIMContext *pVerifyContext, int *nSigCount, DKIMVerifyDetails **pDetails, char *szPractices)
Definition: dkim.cpp:136
struct DKIMSignOptions_t DKIMSignOptions
int(* DKIMDNSCALLBACK)(const char *szFQDN, char *szBuffer, int nBufLen)
Definition: dkim.h:89
int
Definition: qmail-mrtg.c:27
unsigned int reserved2
Definition: dkim.h:94
void * reserved3
Definition: dkim.h:95
unsigned int reserved1
Definition: dkim.h:93
int nIncludeBodyLengthTag
Definition: dkim.h:101
char szRequiredHeaders[256]
Definition: dkim.h:110
DKIMHEADERCALLBACK pfnHeaderCallback
Definition: dkim.h:109
int nIncludeCopiedHeaders
Definition: dkim.h:113
unsigned long expireTime
Definition: dkim.h:108
char szDomain[256]
Definition: dkim.h:106
char szIdentity[256]
Definition: dkim.h:107
int nIncludeTimeStamp
Definition: dkim.h:102
char szSelector[64]
Definition: dkim.h:104
int nIncludeQueryMethod
Definition: dkim.h:103
char szSelectorE[64]
Definition: dkim.h:105
char * szCanonicalizedData
Definition: dkim.h:132
char * szIdentityDomain
Definition: dkim.h:131
char * szSignatureDomain
Definition: dkim.h:130
char * szSignature
Definition: dkim.h:129
int nHonorBodyLengthTag
Definition: dkim.h:120
DKIMDNSCALLBACK pfnSelectorCallback
Definition: dkim.h:118
int nAllowUnsignedFromHeaders
Definition: dkim.h:124
int nSaveCanonicalizedData
Definition: dkim.h:123
DKIMDNSCALLBACK pfnPracticesCallback
Definition: dkim.h:119
int nSubjectRequired
Definition: dkim.h:122
int nCheckPractices
Definition: dkim.h:121