From 89b7b67a13ebb7965cc7f13ad0595e2194a2d34c Mon Sep 17 00:00:00 2001 From: Jannis Hoffmann Date: Wed, 3 Jul 2024 15:48:04 +0200 Subject: add sqmail-4.2.29a --- src/include/dkimsign.h | 113 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 src/include/dkimsign.h (limited to 'src/include/dkimsign.h') diff --git a/src/include/dkimsign.h b/src/include/dkimsign.h new file mode 100644 index 0000000..150a0b8 --- /dev/null +++ b/src/include/dkimsign.h @@ -0,0 +1,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 -- cgit v1.2.3