summaryrefslogtreecommitdiff
path: root/sqmail-4.3.07/src/include/dkimsign.h
blob: 150a0b8e422d1660f9e1b43f43e571adaf52ecb7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*****************************************************************************
*  Copyright 2005 Alt-N Technologies, Ltd.
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
*  This code incorporates intellectual property owned by Yahoo! and licensed
*  pursuant to the Yahoo! DomainKeys Patent License Agreement.
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*
*  Changes done by ¢feh@fehcom.de obeying the above license
*
*****************************************************************************/
#ifndef DKIMSIGN_H
#define DKIMSIGN_H

#include "dkimbase.h"

class CDKIMSign : public CDKIMBase
{
public:
  CDKIMSign();
  ~CDKIMSign();

  //int Init() = delete;
  int Init(DKIMSignOptions* pOptions);
  int GetSig2(char* szRSAPrivKey,char* szECCPrivKey,char** pszSignature);

  virtual int ProcessHeaders(void) override;
  virtual int ProcessBody(char* szBuffer,int nBufLength,bool bEOF) override;

  enum CKDKIMConstants { OptimalHeaderLineLength = 65 };

  void Hash(const char* szBuffer,int nBufLength,bool bHdr);

protected:

  bool SignThisTag(const string& sTag);
  void GetHeaderParams(const string& sHdr);
  void ProcessHeader(const string& sHdr);
  bool ParseFromAddress(void);

  void InitSig(void);
  void AddTagToSig(const char* const Tag,const string &sValue,char cbrk,bool bFold);
  void AddTagToSig(const char* const Tag,unsigned long nValue);
  void AddInterTagSpace(int nSizeOfNextTag);
  void AddFoldedValueToSig(const string &sValue,char cbrk);

  bool IsRequiredHeader(const string& sTag);
  int ConstructSignature(char* szSignKey,int nSigAlg);

  int AssembleReturnedSig(char* szRSAPrivKey,char* szECCPrivKey);

#if ((OPENSSL_VERSION_NUMBER < 0x10100000L) || (LIBRESSL_VERSION_NUMBER > 0 && LIBRESSL_VERSION_NUMBER < 0x20700000L))
  EVP_MD_CTX m_Hdr_sha1ctx;    /* the RSA SHA1 signature */
  EVP_MD_CTX m_Hdr_sha256ctx;  /* the RSA SHA256 signature */

  EVP_MD_CTX m_Bdy_sha1ctx;    /* the SHA1 digest */
  EVP_MD_CTX m_Bdy_sha256ctx;  /* the SHA256 digest */
#else
  EVP_MD_CTX *m_Hdr_sha1ctx;    /* the RSA SHA1 signature */
  EVP_MD_CTX *m_Hdr_sha256ctx;  /* the RSA SHA256 signature */
  EVP_MD_CTX *m_Hdr_ed25519ctx; /* the PureEd25519 signature */

  EVP_MD_CTX *m_Bdy_sha1ctx;    /* the SHA1 digest */
  EVP_MD_CTX *m_Bdy_sha256ctx;  /* the SHA256 digest for RSA */
  EVP_MD_CTX *m_Edy_sha256ctx;  /* the SHA256 digest for Ed25519 */
#endif

  int m_Canon;  /* canonization method */

  int m_EmptyLineCount;

  string hParam;
  string sFrom;
  string sSender;
  string sSelector;
  string eSelector;   /* Used for Ed25519 signatures */
  string sDomain;
  string sIdentity;   /* for i= tag, if empty tag will not be included in sig */
  string sRequiredHeaders;

  bool m_IncludeBodyLengthTag;
  int m_nBodyLength;
  time_t m_ExpireTime;
  int m_nIncludeTimeStamp;      // 0 = don't include t= tag, 1 = include t= tag
  int m_nIncludeQueryMethod;    // 0 = don't include q= tag, 1 = include q= tag
  int m_nHash;                  // use one of the DKIM_HASH_xx constants here
  int m_nIncludeCopiedHeaders;  // 0 = don't include z= tag, 1 = include z= tag

  DKIMHEADERCALLBACK m_pfnHdrCallback;

  string m_sSig;                // DKIM-Signature ....
  int m_nSigPos;

  string m_sReturnedSig;
  bool m_bReturnedSigAssembled;

  string m_sCopiedHeaders;

  string SigHdrs;
  int m_SigHdrs;
};

#endif // DKIMSIGN_H