From a6a7d6ce079cabdaf2fa502b2e2cf15e5428ac6f Mon Sep 17 00:00:00 2001 From: Jannis Hoffmann Date: Wed, 3 Jul 2024 15:52:39 +0200 Subject: format files --- src/dkimsign.cpp | 607 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 322 insertions(+), 285 deletions(-) (limited to 'src/dkimsign.cpp') diff --git a/src/dkimsign.cpp b/src/dkimsign.cpp index 03b03e2..8be3fc6 100644 --- a/src/dkimsign.cpp +++ b/src/dkimsign.cpp @@ -21,15 +21,17 @@ *****************************************************************************/ #define _strnicmp strncasecmp -#define _stricmp strcasecmp +#define _stricmp strcasecmp #define LOWORD(l) ((unsigned)(l) & 0xffff) #define HIWORD(l) ((unsigned)(l) >> 16) +#include "dkimsign.h" + #include + #include #include "dkim.h" -#include "dkimsign.h" /***************************************************************************** * @@ -119,63 +121,67 @@ CDKIMSign::CDKIMSign() m_EmptyLineCount = 0; m_pfnHdrCallback = NULL; -#if ((OPENSSL_VERSION_NUMBER < 0x10100000L) || (LIBRESSL_VERSION_NUMBER > 0 && LIBRESSL_VERSION_NUMBER < 0x20700000L)) - EVP_SignInit(&m_Hdr_sha1ctx,EVP_sha1()); - EVP_SignInit(&m_Hdr_sha256ctx,EVP_sha256()); - EVP_DigestInit(&m_Bdy_sha1ctx,EVP_sha1()); - EVP_DigestInit(&m_Bdy_sha256ctx,EVP_sha256()); +#if ( \ + (OPENSSL_VERSION_NUMBER < 0x10100000L) \ + || (LIBRESSL_VERSION_NUMBER > 0 && LIBRESSL_VERSION_NUMBER < 0x20700000L)) + EVP_SignInit(&m_Hdr_sha1ctx, EVP_sha1()); + EVP_SignInit(&m_Hdr_sha256ctx, EVP_sha256()); + EVP_DigestInit(&m_Bdy_sha1ctx, EVP_sha1()); + EVP_DigestInit(&m_Bdy_sha256ctx, EVP_sha256()); #else m_Hdr_sha1ctx = EVP_MD_CTX_create(); - EVP_SignInit_ex(m_Hdr_sha1ctx,EVP_sha1(),NULL); + EVP_SignInit_ex(m_Hdr_sha1ctx, EVP_sha1(), NULL); m_Hdr_sha256ctx = EVP_MD_CTX_create(); - EVP_SignInit_ex(m_Hdr_sha256ctx,EVP_sha256(),NULL); + EVP_SignInit_ex(m_Hdr_sha256ctx, EVP_sha256(), NULL); m_Bdy_sha1ctx = EVP_MD_CTX_create(); - EVP_DigestInit_ex(m_Bdy_sha1ctx,EVP_sha1(),NULL); + EVP_DigestInit_ex(m_Bdy_sha1ctx, EVP_sha1(), NULL); m_Bdy_sha256ctx = EVP_MD_CTX_create(); - EVP_DigestInit_ex(m_Bdy_sha256ctx,EVP_sha256(),NULL); + EVP_DigestInit_ex(m_Bdy_sha256ctx, EVP_sha256(), NULL); m_Hdr_ed25519ctx = EVP_MD_CTX_create(); m_Edy_sha256ctx = EVP_MD_CTX_create(); - EVP_DigestInit_ex(m_Edy_sha256ctx,EVP_sha256(),NULL); + EVP_DigestInit_ex(m_Edy_sha256ctx, EVP_sha256(), NULL); #endif } CDKIMSign::~CDKIMSign() { -#if ((OPENSSL_VERSION_NUMBER < 0x10100000L) || (LIBRESSL_VERSION_NUMBER > 0 && LIBRESSL_VERSION_NUMBER < 0x20700000L)) - EVP_MD_CTX_cleanup(&m_Hdr_sha1ctx); - EVP_MD_CTX_cleanup(&m_Hdr_sha256ctx); - EVP_MD_CTX_cleanup(&m_Bdy_sha1ctx); - EVP_MD_CTX_cleanup(&m_Bdy_sha256ctx); +#if ( \ + (OPENSSL_VERSION_NUMBER < 0x10100000L) \ + || (LIBRESSL_VERSION_NUMBER > 0 && LIBRESSL_VERSION_NUMBER < 0x20700000L)) + EVP_MD_CTX_cleanup(&m_Hdr_sha1ctx); + EVP_MD_CTX_cleanup(&m_Hdr_sha256ctx); + EVP_MD_CTX_cleanup(&m_Bdy_sha1ctx); + EVP_MD_CTX_cleanup(&m_Bdy_sha256ctx); #else - EVP_MD_CTX_free(m_Hdr_sha1ctx); - EVP_MD_CTX_free(m_Hdr_sha256ctx); - EVP_MD_CTX_free(m_Hdr_ed25519ctx); - EVP_MD_CTX_free(m_Bdy_sha1ctx); - EVP_MD_CTX_free(m_Bdy_sha256ctx); - EVP_MD_CTX_free(m_Edy_sha256ctx); + EVP_MD_CTX_free(m_Hdr_sha1ctx); + EVP_MD_CTX_free(m_Hdr_sha256ctx); + EVP_MD_CTX_free(m_Hdr_ed25519ctx); + EVP_MD_CTX_free(m_Bdy_sha1ctx); + EVP_MD_CTX_free(m_Bdy_sha256ctx); + EVP_MD_CTX_free(m_Edy_sha256ctx); #endif } //////////////////////////////////////////////////////////////////////////////// -// +// // Init - save the options // //////////////////////////////////////////////////////////////////////////////// -int CDKIMSign::Init(DKIMSignOptions* pOptions) +int CDKIMSign::Init(DKIMSignOptions *pOptions) { int nRet = CDKIMBase::Init(); m_Canon = pOptions->nCanon; // as of draft 01, these are the only allowed signing types: - if ((m_Canon != DKIM_SIGN_SIMPLE_RELAXED) && - (m_Canon != DKIM_SIGN_RELAXED) && - (m_Canon != DKIM_SIGN_RELAXED_SIMPLE)) { + if ((m_Canon != DKIM_SIGN_SIMPLE_RELAXED) && (m_Canon != DKIM_SIGN_RELAXED) + && (m_Canon != DKIM_SIGN_RELAXED_SIMPLE)) + { m_Canon = DKIM_SIGN_SIMPLE; } @@ -203,8 +209,7 @@ int CDKIMSign::Init(DKIMSignOptions* pOptions) //sRequiredHeaders.assign(pOptions->szRequiredHeaders); //make sure there is a colon after the last header in the list - if ((sRequiredHeaders.size() > 0) && - sRequiredHeaders.at(sRequiredHeaders.size() - 1) != ':') { + if ((sRequiredHeaders.size() > 0) && sRequiredHeaders.at(sRequiredHeaders.size() - 1) != ':') { sRequiredHeaders.append(":"); } @@ -222,11 +227,11 @@ int CDKIMSign::Init(DKIMSignOptions* pOptions) } //////////////////////////////////////////////////////////////////////////////// -// +// // Hash - update the hash // //////////////////////////////////////////////////////////////////////////////// -void CDKIMSign::Hash(const char *szBuffer,int nBufLength,bool bHdr) +void CDKIMSign::Hash(const char *szBuffer, int nBufLength, bool bHdr) { /** START DEBUG CODE ** @@ -247,53 +252,56 @@ void CDKIMSign::Hash(const char *szBuffer,int nBufLength,bool bHdr) ** END DEBUG CODE **/ - if (bHdr) { /* Generate signature: b=... */ - if ((m_nHash == DKIM_HASH_SHA1) || - (m_nHash == DKIM_HASH_SHA1_AND_SHA256)) -#if ((OPENSSL_VERSION_NUMBER < 0x10100000L) || (LIBRESSL_VERSION_NUMBER > 0 && LIBRESSL_VERSION_NUMBER < 0x20700000L)) - EVP_SignUpdate(&m_Hdr_sha1ctx,szBuffer,nBufLength); -#else - EVP_SignUpdate(m_Hdr_sha1ctx,szBuffer,nBufLength); + if (bHdr) { /* Generate signature: b=... */ + if ((m_nHash == DKIM_HASH_SHA1) || (m_nHash == DKIM_HASH_SHA1_AND_SHA256)) +#if ( \ + (OPENSSL_VERSION_NUMBER < 0x10100000L) \ + || (LIBRESSL_VERSION_NUMBER > 0 && LIBRESSL_VERSION_NUMBER < 0x20700000L)) + EVP_SignUpdate(&m_Hdr_sha1ctx, szBuffer, nBufLength); +#else + EVP_SignUpdate(m_Hdr_sha1ctx, szBuffer, nBufLength); #endif - if ((m_nHash == DKIM_HASH_SHA256) || - (m_nHash == DKIM_HASH_SHA1_AND_SHA256) || - (m_nHash == DKIM_HASH_RSA256_AND_ED25519)) -#if ((OPENSSL_VERSION_NUMBER < 0x10100000L) || (LIBRESSL_VERSION_NUMBER > 0 && LIBRESSL_VERSION_NUMBER < 0x20700000L)) - EVP_SignUpdate(&m_Hdr_sha256ctx,szBuffer,nBufLength); -#else - EVP_SignUpdate(m_Hdr_sha256ctx,szBuffer,nBufLength); + if ((m_nHash == DKIM_HASH_SHA256) || (m_nHash == DKIM_HASH_SHA1_AND_SHA256) + || (m_nHash == DKIM_HASH_RSA256_AND_ED25519)) +#if ( \ + (OPENSSL_VERSION_NUMBER < 0x10100000L) \ + || (LIBRESSL_VERSION_NUMBER > 0 && LIBRESSL_VERSION_NUMBER < 0x20700000L)) + EVP_SignUpdate(&m_Hdr_sha256ctx, szBuffer, nBufLength); +#else + EVP_SignUpdate(m_Hdr_sha256ctx, szBuffer, nBufLength); #endif #if ((OPENSSL_VERSION_NUMBER > 0x10101000L)) - if ((m_nHash == DKIM_HASH_ED25519) || - (m_nHash == DKIM_HASH_RSA256_AND_ED25519)) { - SigHdrs.append(szBuffer,nBufLength); + if ((m_nHash == DKIM_HASH_ED25519) || (m_nHash == DKIM_HASH_RSA256_AND_ED25519)) { + SigHdrs.append(szBuffer, nBufLength); m_SigHdrs += nBufLength; } #endif - } else { /* lets go for body hash values: bh=... (either SHA1 or SHA256) */ - if ((m_nHash == DKIM_HASH_SHA1) || - (m_nHash == DKIM_HASH_SHA1_AND_SHA256)) -#if ((OPENSSL_VERSION_NUMBER < 0x10100000L) || (LIBRESSL_VERSION_NUMBER > 0 && LIBRESSL_VERSION_NUMBER < 0x20700000L)) - EVP_DigestUpdate(&m_Bdy_sha1ctx,szBuffer,nBufLength); -#else - EVP_DigestUpdate(m_Bdy_sha1ctx,szBuffer,nBufLength); + } else { /* lets go for body hash values: bh=... (either SHA1 or SHA256) */ + if ((m_nHash == DKIM_HASH_SHA1) || (m_nHash == DKIM_HASH_SHA1_AND_SHA256)) +#if ( \ + (OPENSSL_VERSION_NUMBER < 0x10100000L) \ + || (LIBRESSL_VERSION_NUMBER > 0 && LIBRESSL_VERSION_NUMBER < 0x20700000L)) + EVP_DigestUpdate(&m_Bdy_sha1ctx, szBuffer, nBufLength); +#else + EVP_DigestUpdate(m_Bdy_sha1ctx, szBuffer, nBufLength); #endif if (m_nHash != DKIM_HASH_SHA1) -#if ((OPENSSL_VERSION_NUMBER < 0x10100000L) || (LIBRESSL_VERSION_NUMBER > 0 && LIBRESSL_VERSION_NUMBER < 0x20700000L)) - EVP_DigestUpdate(&m_Bdy_sha256ctx,szBuffer,nBufLength); +#if ( \ + (OPENSSL_VERSION_NUMBER < 0x10100000L) \ + || (LIBRESSL_VERSION_NUMBER > 0 && LIBRESSL_VERSION_NUMBER < 0x20700000L)) + EVP_DigestUpdate(&m_Bdy_sha256ctx, szBuffer, nBufLength); #else - EVP_DigestUpdate(m_Bdy_sha256ctx,szBuffer,nBufLength); + EVP_DigestUpdate(m_Bdy_sha256ctx, szBuffer, nBufLength); #endif #if ((OPENSSL_VERSION_NUMBER > 0x10101000L)) - if ((m_nHash == DKIM_HASH_ED25519) || - (m_nHash == DKIM_HASH_RSA256_AND_ED25519)) - EVP_DigestUpdate(m_Edy_sha256ctx,szBuffer,nBufLength); + if ((m_nHash == DKIM_HASH_ED25519) || (m_nHash == DKIM_HASH_RSA256_AND_ED25519)) + EVP_DigestUpdate(m_Edy_sha256ctx, szBuffer, nBufLength); #endif } } //////////////////////////////////////////////////////////////////////////////// -// +// // SignThisTag - return boolean whether or not to sign this tag // //////////////////////////////////////////////////////////////////////////////// @@ -301,25 +309,25 @@ bool CDKIMSign::SignThisTag(const string& sTag) { bool bRet = true; - if (_strnicmp(sTag.c_str(),"X-",2) == 0 || - _stricmp(sTag.c_str(),"Authentication-Results:") == 0 || - _stricmp(sTag.c_str(),"Return-Path:") == 0) { + if (_strnicmp(sTag.c_str(), "X-", 2) == 0 || _stricmp(sTag.c_str(), "Authentication-Results:") == 0 + || _stricmp(sTag.c_str(), "Return-Path:") == 0) + { bRet = false; } return bRet; } -bool ConvertHeaderToQuotedPrintable(const char* source, char* dest) +bool ConvertHeaderToQuotedPrintable(const char *source, char *dest) { bool bConvert = false; // do quoted printable - static unsigned char hexchars[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; + static unsigned char hexchars[16] = { + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; - unsigned char *d = (unsigned char*)dest; - for (const unsigned char *s = (const unsigned char *)source; *s != '\0'; s++) - { + unsigned char *d = (unsigned char *)dest; + for (const unsigned char *s = (const unsigned char *)source; *s != '\0'; s++) { if (*s >= 33 && *s <= 126 && *s != '=' && *s != ':' && *s != ';' && *s != '|') { *d++ = *s; } else { @@ -335,15 +343,19 @@ bool ConvertHeaderToQuotedPrintable(const char* source, char* dest) } //////////////////////////////////////////////////////////////////////////////// -// +// // GetHeaderParams - Extract any needed header parameters // //////////////////////////////////////////////////////////////////////////////// -void CDKIMSign::GetHeaderParams(const string &sHdr) +void CDKIMSign::GetHeaderParams(const string& sHdr) { - if (_strnicmp(sHdr.c_str(),"X",1) == 0) return; - if (_strnicmp(sHdr.c_str(),"From:",5) == 0) { sFrom.assign(sHdr.c_str() + 5); } - if (_strnicmp(sHdr.c_str(),"Sender:",7) == 0) { sSender.assign(sHdr.c_str() + 7); } + if (_strnicmp(sHdr.c_str(), "X", 1) == 0) return; + if (_strnicmp(sHdr.c_str(), "From:", 5) == 0) { + sFrom.assign(sHdr.c_str() + 5); + } + if (_strnicmp(sHdr.c_str(), "Sender:", 7) == 0) { + sSender.assign(sHdr.c_str() + 7); + } if (m_nIncludeCopiedHeaders) { string::size_type pos = sHdr.find(':'); @@ -352,13 +364,16 @@ void CDKIMSign::GetHeaderParams(const string &sHdr) string sTag, sValue; char *workBuffer = new char[sHdr.size() * 3 + 1]; - sTag.assign(sHdr.substr(0,pos)); - sValue.assign(sHdr.substr(pos + 1,string::npos)); + sTag.assign(sHdr.substr(0, pos)); + sValue.assign(sHdr.substr(pos + 1, string::npos)); - ConvertHeaderToQuotedPrintable(sTag.c_str(),workBuffer); - if (!m_sCopiedHeaders.empty()) { m_sCopiedHeaders.append("|"); } - m_sCopiedHeaders.append(workBuffer); m_sCopiedHeaders.append(":"); - ConvertHeaderToQuotedPrintable(sValue.c_str(),workBuffer); + ConvertHeaderToQuotedPrintable(sTag.c_str(), workBuffer); + if (!m_sCopiedHeaders.empty()) { + m_sCopiedHeaders.append("|"); + } + m_sCopiedHeaders.append(workBuffer); + m_sCopiedHeaders.append(":"); + ConvertHeaderToQuotedPrintable(sValue.c_str(), workBuffer); m_sCopiedHeaders.append(workBuffer); delete[] workBuffer; @@ -367,14 +382,14 @@ void CDKIMSign::GetHeaderParams(const string &sHdr) } //////////////////////////////////////////////////////////////////////////////// -// +// // ProcessHeaders - sign headers and save needed parameters (this is a lie) // //////////////////////////////////////////////////////////////////////////////// int CDKIMSign::ProcessHeaders(void) { - map::reverse_iterator> IterMap; - map::reverse_iterator>::iterator IterMapIter; + map::reverse_iterator> IterMap; + map::reverse_iterator>::iterator IterMapIter; list::reverse_iterator riter; list::iterator iter; string sTag; @@ -391,20 +406,20 @@ int CDKIMSign::ProcessHeaders(void) int nSignThisTag = 1; // hack off anything past the colon - sTag.erase(pos + 1,string::npos); + sTag.erase(pos + 1, string::npos); // is this the From: header? - if (_stricmp(sTag.c_str(),"From:") == 0) { + if (_stricmp(sTag.c_str(), "From:") == 0) { bFromHeaderFound = true; nSignThisTag = 1; IsRequiredHeader(sTag); // remove from required header list } // is this in the list of headers that must be signed? - else if (IsRequiredHeader(sTag)) { + else if (IsRequiredHeader(sTag)) + { nSignThisTag = 1; - } - else { - if(m_pfnHdrCallback) { + } else { + if (m_pfnHdrCallback) { nSignThisTag = m_pfnHdrCallback(iter->c_str()); } else { nSignThisTag = SignThisTag(sTag) ? 1 : 0; @@ -424,7 +439,7 @@ int CDKIMSign::ProcessHeaders(void) // walk the list in reverse looking for the last instance of this header while (riter != HeaderList.rend()) { - if (_strnicmp(riter->c_str(),sTag.c_str(),sTag.size()) == 0) { + if (_strnicmp(riter->c_str(), sTag.c_str(), sTag.size()) == 0) { ProcessHeader(*riter); // save the reverse iterator position for this tag @@ -433,106 +448,102 @@ int CDKIMSign::ProcessHeaders(void) break; } riter++; - } + } } } } - if(!bFromHeaderFound) { + if (!bFromHeaderFound) { string sFrom("From:"); hParam.append(sFrom); - IsRequiredHeader(sFrom); // remove from required header list -// Hash("\r\n",2); + IsRequiredHeader(sFrom); // remove from required header list + // Hash("\r\n",2); } hParam.append(sRequiredHeaders); -// string::size_type end = sRequiredHeaders.find(':'); -// while (end != string::npos) -// { -// Hash("\r\n",2); -// end = sRequiredHeaders.find(':', end+1); -// } + // string::size_type end = sRequiredHeaders.find(':'); + // while (end != string::npos) + // { + // Hash("\r\n",2); + // end = sRequiredHeaders.find(':', end+1); + // } // remove the last colon from h= - if (hParam.at(hParam.size() - 1) == ':') - hParam.erase(hParam.size() - 1,string::npos); + if (hParam.at(hParam.size() - 1) == ':') hParam.erase(hParam.size() - 1, string::npos); return DKIM_SUCCESS; } -void CDKIMSign::ProcessHeader(const string &sHdr) +void CDKIMSign::ProcessHeader(const string& sHdr) { switch (HIWORD(m_Canon)) { case DKIM_CANON_SIMPLE: - Hash(sHdr.c_str(),sHdr.size(),true); - Hash("\r\n",2,true); + Hash(sHdr.c_str(), sHdr.size(), true); + Hash("\r\n", 2, true); break; - case DKIM_CANON_NOWSP: { + case DKIM_CANON_NOWSP: { string sTemp = sHdr; RemoveSWSP(sTemp); // convert characters before ':' to lower case - for (char *s = (char*)sTemp.c_str(); *s != '\0' && *s != ':'; s++) { - if (*s >= 'A' && *s <= 'Z') - *s += 'a' - 'A'; + for (char *s = (char *)sTemp.c_str(); *s != '\0' && *s != ':'; s++) { + if (*s >= 'A' && *s <= 'Z') *s += 'a' - 'A'; } - Hash(sTemp.c_str(),sTemp.size(),true); - Hash("\r\n",2,true); - } - break; + Hash(sTemp.c_str(), sTemp.size(), true); + Hash("\r\n", 2, true); + } break; - case DKIM_CANON_RELAXED: { + case DKIM_CANON_RELAXED: { string sTemp = RelaxHeader(sHdr); - Hash(sTemp.c_str(),sTemp.length(),true); - Hash("\r\n",2,true); - } - break; + Hash(sTemp.c_str(), sTemp.length(), true); + Hash("\r\n", 2, true); + } break; } } -int CDKIMSign::ProcessBody(char *szBuffer,int nBufLength,bool bEOF) +int CDKIMSign::ProcessBody(char *szBuffer, int nBufLength, bool bEOF) { - switch(LOWORD(m_Canon)) { + switch (LOWORD(m_Canon)) { case DKIM_CANON_SIMPLE: if (nBufLength > 0) { while (m_EmptyLineCount > 0) { - Hash("\r\n",2,false); + Hash("\r\n", 2, false); m_nBodyLength += 2; m_EmptyLineCount--; } - Hash(szBuffer,nBufLength,false); - Hash("\r\n",2,false); + Hash(szBuffer, nBufLength, false); + Hash("\r\n", 2, false); m_nBodyLength += nBufLength + 2; } else { m_EmptyLineCount++; if (bEOF) { - Hash("\r\n",2,false); + Hash("\r\n", 2, false); m_nBodyLength += 2; } } break; case DKIM_CANON_NOWSP: - RemoveSWSP(szBuffer,nBufLength); + RemoveSWSP(szBuffer, nBufLength); if (nBufLength > 0) { - Hash(szBuffer,nBufLength,false); + Hash(szBuffer, nBufLength, false); m_nBodyLength += nBufLength; } break; case DKIM_CANON_RELAXED: - CompressSWSP(szBuffer,nBufLength); + CompressSWSP(szBuffer, nBufLength); if (nBufLength > 0) { while (m_EmptyLineCount > 0) { - Hash("\r\n",2,false); + Hash("\r\n", 2, false); m_nBodyLength += 2; m_EmptyLineCount--; } - Hash(szBuffer,nBufLength,false); + Hash(szBuffer, nBufLength, false); m_nBodyLength += nBufLength; if (!bEOF) { - Hash("\r\n",2,false); + Hash("\r\n", 2, false); m_nBodyLength += 2; } } else @@ -560,21 +571,18 @@ bool CDKIMSign::ParseFromAddress(void) // remove '<' and anything before it pos = sAddress.find('<'); - if(pos != string::npos) - sAddress.erase(0,pos); + if (pos != string::npos) sAddress.erase(0, pos); // remove '>' and anything after it pos = sAddress.find('>'); - if (pos != string::npos) - sAddress.erase(pos,string::npos); + if (pos != string::npos) sAddress.erase(pos, string::npos); // look for '@' symbol pos = sAddress.find('@'); - if (pos == string::npos) - return false; + if (pos == string::npos) return false; if (sDomain.empty()) { - sDomain.assign (sAddress.c_str() + pos + 1); + sDomain.assign(sAddress.c_str() + pos + 1); RemoveSWSP(sDomain); } @@ -582,7 +590,7 @@ bool CDKIMSign::ParseFromAddress(void) } //////////////////////////////////////////////////////////////////////////////// -// +// // InitSig - initialize signature folding algorithm // //////////////////////////////////////////////////////////////////////////////// @@ -594,12 +602,12 @@ void CDKIMSign::InitSig(void) } //////////////////////////////////////////////////////////////////////////////// -// +// // AddTagToSig - add tag and value to signature folding if necessary // if bFold, fold at cbrk char // //////////////////////////////////////////////////////////////////////////////// -void CDKIMSign::AddTagToSig(const char* const Tag,const string &sValue,char cbrk,bool bFold) +void CDKIMSign::AddTagToSig(const char *const Tag, const string& sValue, char cbrk, bool bFold) { int nTagLen = strlen(Tag); @@ -613,35 +621,35 @@ void CDKIMSign::AddTagToSig(const char* const Tag,const string &sValue,char cbrk m_sSig.append(sValue); m_nSigPos += sValue.size(); } else { - AddFoldedValueToSig(sValue,cbrk); + AddFoldedValueToSig(sValue, cbrk); } m_sSig.append(";"); m_nSigPos++; } //////////////////////////////////////////////////////////////////////////////// -// +// // AddTagToSig - add tag and numeric value to signature folding if necessary // //////////////////////////////////////////////////////////////////////////////// -void CDKIMSign::AddTagToSig(const char* const Tag,unsigned long nValue) +void CDKIMSign::AddTagToSig(const char *const Tag, unsigned long nValue) { char szValue[64]; - sprintf(szValue,"%lu",nValue); - AddTagToSig(Tag,szValue,0,false); + sprintf(szValue, "%lu", nValue); + AddTagToSig(Tag, szValue, 0, false); } //////////////////////////////////////////////////////////////////////////////// -// +// // AddInterTagSpace - add space or fold here // //////////////////////////////////////////////////////////////////////////////// void CDKIMSign::AddInterTagSpace(int nSizeOfNextTag) { if (m_nSigPos + nSizeOfNextTag + 1 > OptimalHeaderLineLength) { -// m_sSig.append("\r\n\t"); - m_sSig.append("\r\n "); /* s/qmail style */ - m_nSigPos = 1; + // m_sSig.append("\r\n\t"); + m_sSig.append("\r\n "); /* s/qmail style */ + m_nSigPos = 1; } else { m_sSig.append(" "); m_nSigPos++; @@ -649,12 +657,12 @@ void CDKIMSign::AddInterTagSpace(int nSizeOfNextTag) } //////////////////////////////////////////////////////////////////////////////// -// +// // AddTagToSig - add value to signature folding if necessary // if cbrk == 0 fold anywhere, otherwise fold only at cbrk // //////////////////////////////////////////////////////////////////////////////// -void CDKIMSign::AddFoldedValueToSig(const string &sValue,char cbrk) +void CDKIMSign::AddFoldedValueToSig(const string& sValue, char cbrk) { string::size_type pos = 0; @@ -662,15 +670,14 @@ void CDKIMSign::AddFoldedValueToSig(const string &sValue,char cbrk) // fold anywhere while (pos < sValue.size()) { string::size_type len = OptimalHeaderLineLength - m_nSigPos; - if (len > sValue.size() - pos) - len = sValue.size() - pos; - m_sSig.append(sValue.substr(pos,len)); + if (len > sValue.size() - pos) len = sValue.size() - pos; + m_sSig.append(sValue.substr(pos, len)); m_nSigPos += len; pos += len; if (pos < sValue.size()) { -// m_sSig.append("\r\n\t"); - m_sSig.append("\r\n "); /* s/qmail style */ + // m_sSig.append("\r\n\t"); + m_sSig.append("\r\n "); /* s/qmail style */ m_nSigPos = 1; } } @@ -683,11 +690,11 @@ void CDKIMSign::AddFoldedValueToSig(const string &sValue,char cbrk) if (sValue.size() - pos < len) { brkpos = sValue.size(); } else { - brkpos = sValue.rfind(cbrk,pos + len); + brkpos = sValue.rfind(cbrk, pos + len); } if (brkpos == string::npos || brkpos < pos) { - brkpos = sValue.find(cbrk,pos); + brkpos = sValue.find(cbrk, pos); if (brkpos == string::npos) { brkpos = sValue.size(); } @@ -695,14 +702,14 @@ void CDKIMSign::AddFoldedValueToSig(const string &sValue,char cbrk) len = brkpos - pos + 1; - m_sSig.append(sValue.substr(pos,len)); + m_sSig.append(sValue.substr(pos, len)); m_nSigPos += len; pos += len; if (pos < sValue.size()) { -// m_sSig.append("\r\n\t"); - m_sSig.append("\r\n "); /* s/qmail style */ + // m_sSig.append("\r\n\t"); + m_sSig.append("\r\n "); /* s/qmail style */ m_nSigPos = 1; } } @@ -710,11 +717,11 @@ void CDKIMSign::AddFoldedValueToSig(const string &sValue,char cbrk) } //////////////////////////////////////////////////////////////////////////////// -// +// // GetSig - compute hash and return signature header in szSignature // //////////////////////////////////////////////////////////////////////////////// -int CDKIMSign::GetSig2(char* szRSAKey,char* szECCKey,char** pszSignature) +int CDKIMSign::GetSig2(char *szRSAKey, char *szECCKey, char **pszSignature) { if (szRSAKey == NULL && szECCKey == NULL) { return DKIM_BAD_PRIVATE_KEY; @@ -724,19 +731,18 @@ int CDKIMSign::GetSig2(char* szRSAKey,char* szECCKey,char** pszSignature) return DKIM_BUFFER_TOO_SMALL; } - int nRet = AssembleReturnedSig(szRSAKey,szECCKey); + int nRet = AssembleReturnedSig(szRSAKey, szECCKey); - if (nRet != DKIM_SUCCESS) - return nRet; + if (nRet != DKIM_SUCCESS) return nRet; - *pszSignature = (char*)m_sReturnedSig.c_str(); + *pszSignature = (char *)m_sReturnedSig.c_str(); return DKIM_SUCCESS; } //////////////////////////////////////////////////////////////////////////////// -// +// // IsRequiredHeader - Check if header in required list. If so, delete // header from list. // @@ -748,118 +754,132 @@ bool CDKIMSign::IsRequiredHeader(const string& sTag) while (end != string::npos) { // check for a zero-length header - if(start == end) { - sRequiredHeaders.erase(start,1); + if (start == end) { + sRequiredHeaders.erase(start, 1); } else { - if (_stricmp(sTag.c_str(),sRequiredHeaders.substr(start,end - start + 1).c_str()) == 0) { - sRequiredHeaders.erase(start,end - start + 1); + if (_stricmp(sTag.c_str(), sRequiredHeaders.substr(start, end - start + 1).c_str()) == 0) { + sRequiredHeaders.erase(start, end - start + 1); return true; } else { start = end + 1; } } - end = sRequiredHeaders.find(':',start); + end = sRequiredHeaders.find(':', start); } return false; } //////////////////////////////////////////////////////////////////////////////// -// +// // ConstructSignature // // Here, we don't construct the 'signature' but rather the DKIM header // multiply and indidually crafted for each distinct nSigAlg method -// +// // nSigAlg: DKIM_HASH_SHA1, DKIM_HASH_SHA256, DKIM_HASH_ED25519 // //////////////////////////////////////////////////////////////////////////////// -int CDKIMSign::ConstructSignature(char* szPrivKey,int nSigAlg) +int CDKIMSign::ConstructSignature(char *szPrivKey, int nSigAlg) { string sSignedSig; - unsigned char* sig; + unsigned char *sig; EVP_PKEY *pkey = 0; BIO *bio, *b64; unsigned int siglen; int size; int len; - char* buf; + char *buf; int nSignRet; /* construct the DKIM-Signature: header and add to hash */ InitSig(); - AddTagToSig("v","1",0,false); + AddTagToSig("v", "1", 0, false); switch (nSigAlg) { - case DKIM_HASH_SHA1: - AddTagToSig("a","rsa-sha1",0,false); break; - case DKIM_HASH_SHA256: - AddTagToSig("a","rsa-sha256",0,false); break; - case DKIM_HASH_ED25519: - AddTagToSig("a","ed25519-sha256",0,false); break; + case DKIM_HASH_SHA1: AddTagToSig("a", "rsa-sha1", 0, false); break; + case DKIM_HASH_SHA256: AddTagToSig("a", "rsa-sha256", 0, false); break; + case DKIM_HASH_ED25519: AddTagToSig("a", "ed25519-sha256", 0, false); break; } switch (m_Canon) { - case DKIM_SIGN_SIMPLE: - AddTagToSig("c","simple/simple",0,false); break; - case DKIM_SIGN_SIMPLE_RELAXED: - AddTagToSig("c","simple/relaxed",0,false); break; - case DKIM_SIGN_RELAXED: - AddTagToSig("c","relaxed/relaxed",0,false); break; - case DKIM_SIGN_RELAXED_SIMPLE: - AddTagToSig("c","relaxed/simple",0,false); break; + case DKIM_SIGN_SIMPLE: AddTagToSig("c", "simple/simple", 0, false); break; + case DKIM_SIGN_SIMPLE_RELAXED: AddTagToSig("c", "simple/relaxed", 0, false); break; + case DKIM_SIGN_RELAXED: AddTagToSig("c", "relaxed/relaxed", 0, false); break; + case DKIM_SIGN_RELAXED_SIMPLE: AddTagToSig("c", "relaxed/simple", 0, false); break; } - AddTagToSig("d",sDomain,0,false); + AddTagToSig("d", sDomain, 0, false); if (nSigAlg == DKIM_HASH_ED25519) - AddTagToSig("s",eSelector,0,false); + AddTagToSig("s", eSelector, 0, false); else - AddTagToSig("s",sSelector,0,false); - if (m_IncludeBodyLengthTag) { AddTagToSig("l",m_nBodyLength); } - if (m_nIncludeTimeStamp != 0) { time_t t; time(&t); AddTagToSig("t",t); } - if (m_ExpireTime != 0) { AddTagToSig("x",m_ExpireTime); } - if (!sIdentity.empty()) { AddTagToSig("i",sIdentity,0,false); } - if (m_nIncludeQueryMethod) { AddTagToSig("q","dns/txt",0,false); } + AddTagToSig("s", sSelector, 0, false); + if (m_IncludeBodyLengthTag) { + AddTagToSig("l", m_nBodyLength); + } + if (m_nIncludeTimeStamp != 0) { + time_t t; + time(&t); + AddTagToSig("t", t); + } + if (m_ExpireTime != 0) { + AddTagToSig("x", m_ExpireTime); + } + if (!sIdentity.empty()) { + AddTagToSig("i", sIdentity, 0, false); + } + if (m_nIncludeQueryMethod) { + AddTagToSig("q", "dns/txt", 0, false); + } - AddTagToSig("h",hParam,':',true); // copied headers follow the ':' - if (m_nIncludeCopiedHeaders) { AddTagToSig("z",m_sCopiedHeaders,0,true); } + AddTagToSig("h", hParam, ':', true); // copied headers follow the ':' + if (m_nIncludeCopiedHeaders) { + AddTagToSig("z", m_sCopiedHeaders, 0, true); + } /* Set up context for (body) hash */ - + unsigned char Hash[4096]; unsigned int nHashLen = 0; switch (nSigAlg) { - case DKIM_HASH_SHA1: -#if ((OPENSSL_VERSION_NUMBER < 0x10100000L) || (LIBRESSL_VERSION_NUMBER > 0 && LIBRESSL_VERSION_NUMBER < 0x20700000L)) - EVP_DigestFinal(&m_Bdy_sha1ctx,Hash,&nHashLen); break; + case DKIM_HASH_SHA1: +#if ( \ + (OPENSSL_VERSION_NUMBER < 0x10100000L) \ + || (LIBRESSL_VERSION_NUMBER > 0 && LIBRESSL_VERSION_NUMBER < 0x20700000L)) + EVP_DigestFinal(&m_Bdy_sha1ctx, Hash, &nHashLen); + break; #else - EVP_DigestFinal_ex(m_Bdy_sha1ctx,Hash,&nHashLen); break; + EVP_DigestFinal_ex(m_Bdy_sha1ctx, Hash, &nHashLen); + break; #endif - case DKIM_HASH_SHA256: -#if ((OPENSSL_VERSION_NUMBER < 0x10100000L) || (LIBRESSL_VERSION_NUMBER > 0 && LIBRESSL_VERSION_NUMBER < 0x20700000L)) - EVP_DigestFinal(&m_Bdy_sha256ctx,Hash,&nHashLen); break; + case DKIM_HASH_SHA256: +#if ( \ + (OPENSSL_VERSION_NUMBER < 0x10100000L) \ + || (LIBRESSL_VERSION_NUMBER > 0 && LIBRESSL_VERSION_NUMBER < 0x20700000L)) + EVP_DigestFinal(&m_Bdy_sha256ctx, Hash, &nHashLen); + break; #else - EVP_DigestFinal_ex(m_Bdy_sha256ctx,Hash,&nHashLen); break; + EVP_DigestFinal_ex(m_Bdy_sha256ctx, Hash, &nHashLen); + break; #endif -#if (OPENSSL_VERSION_NUMBER > 0x10101000L) - case DKIM_HASH_ED25519: - EVP_DigestFinal_ex(m_Edy_sha256ctx,Hash,&nHashLen); break; +#if (OPENSSL_VERSION_NUMBER > 0x10101000L) + case DKIM_HASH_ED25519: EVP_DigestFinal_ex(m_Edy_sha256ctx, Hash, &nHashLen); break; #endif } bio = BIO_new(BIO_s_mem()); - if (!bio) return DKIM_OUT_OF_MEMORY; - + if (!bio) return DKIM_OUT_OF_MEMORY; + b64 = BIO_new(BIO_f_base64()); if (!b64) { BIO_free(bio); return DKIM_OUT_OF_MEMORY; } - BIO_set_flags(b64,BIO_FLAGS_BASE64_NO_NL); - BIO_push(b64,bio); - if (BIO_write(b64,Hash,nHashLen) < (int)nHashLen) { + BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL); + BIO_push(b64, bio); + if (BIO_write(b64, Hash, nHashLen) < (int)nHashLen) { BIO_free_all(b64); return DKIM_OUT_OF_MEMORY; } @@ -873,17 +893,17 @@ int CDKIMSign::ConstructSignature(char* szPrivKey,int nSigAlg) return DKIM_OUT_OF_MEMORY; } - size = BIO_read(bio,buf,len); + size = BIO_read(bio, buf, len); BIO_free_all(b64); // this should never happen if (size >= len) { - delete[] buf; - return DKIM_OUT_OF_MEMORY; + delete[] buf; + return DKIM_OUT_OF_MEMORY; } buf[size] = '\0'; - AddTagToSig("bh",buf,0,true); + AddTagToSig("bh", buf, 0, true); delete[] buf; AddInterTagSpace(3); @@ -908,35 +928,46 @@ int CDKIMSign::ConstructSignature(char* szPrivKey,int nSigAlg) /* Update streaming signatures */ switch (nSigAlg) { - case DKIM_HASH_SHA1: -#if ((OPENSSL_VERSION_NUMBER < 0x10100000L) || (LIBRESSL_VERSION_NUMBER > 0 && LIBRESSL_VERSION_NUMBER < 0x20700000L)) - EVP_SignUpdate(&m_Hdr_sha1ctx,sTemp.c_str(),sTemp.size()); break; + case DKIM_HASH_SHA1: +#if ( \ + (OPENSSL_VERSION_NUMBER < 0x10100000L) \ + || (LIBRESSL_VERSION_NUMBER > 0 && LIBRESSL_VERSION_NUMBER < 0x20700000L)) + EVP_SignUpdate(&m_Hdr_sha1ctx, sTemp.c_str(), sTemp.size()); + break; #else - EVP_SignUpdate(m_Hdr_sha1ctx,sTemp.c_str(),sTemp.size()); break; + EVP_SignUpdate(m_Hdr_sha1ctx, sTemp.c_str(), sTemp.size()); + break; #endif - case DKIM_HASH_SHA256: -#if ((OPENSSL_VERSION_NUMBER < 0x10100000L) || (LIBRESSL_VERSION_NUMBER > 0 && LIBRESSL_VERSION_NUMBER < 0x20700000L)) - EVP_SignUpdate(&m_Hdr_sha256ctx,sTemp.c_str(),sTemp.size()); break; + case DKIM_HASH_SHA256: +#if ( \ + (OPENSSL_VERSION_NUMBER < 0x10100000L) \ + || (LIBRESSL_VERSION_NUMBER > 0 && LIBRESSL_VERSION_NUMBER < 0x20700000L)) + EVP_SignUpdate(&m_Hdr_sha256ctx, sTemp.c_str(), sTemp.size()); + break; #else - EVP_SignUpdate(m_Hdr_sha256ctx,sTemp.c_str(),sTemp.size()); break; + EVP_SignUpdate(m_Hdr_sha256ctx, sTemp.c_str(), sTemp.size()); + break; #endif #if ((OPENSSL_VERSION_NUMBER > 0x10101000L)) - case DKIM_HASH_ED25519: - SigHdrs.append(sTemp.c_str(),sTemp.size()); - m_SigHdrs += sTemp.size(); break; + case DKIM_HASH_ED25519: + SigHdrs.append(sTemp.c_str(), sTemp.size()); + m_SigHdrs += sTemp.size(); + break; #endif } bio = BIO_new_mem_buf(szPrivKey, -1); if (bio == NULL) return DKIM_OUT_OF_MEMORY; - pkey = PEM_read_bio_PrivateKey(bio,NULL,NULL,NULL); // FIXME - done + pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL); // FIXME - done BIO_free(bio); - if (!pkey) { return DKIM_BAD_PRIVATE_KEY; } + if (!pkey) { + return DKIM_BAD_PRIVATE_KEY; + } siglen = EVP_PKEY_size(pkey); - sig = (unsigned char*) OPENSSL_malloc(siglen); + sig = (unsigned char *)OPENSSL_malloc(siglen); if (sig == NULL) { EVP_PKEY_free(pkey); return DKIM_OUT_OF_MEMORY; @@ -945,41 +976,50 @@ int CDKIMSign::ConstructSignature(char* szPrivKey,int nSigAlg) /* Finish streaming signature and potentially go for Ed25519 signatures */ size_t sig_len; - unsigned char* SignMsg; + unsigned char *SignMsg; switch (nSigAlg) { - case DKIM_HASH_SHA1: -#if ((OPENSSL_VERSION_NUMBER < 0x10100000L) || (LIBRESSL_VERSION_NUMBER > 0 && LIBRESSL_VERSION_NUMBER < 0x20700000L)) - nSignRet = EVP_SignFinal(&m_Hdr_sha1ctx,sig,&siglen,pkey); break; + case DKIM_HASH_SHA1: +#if ( \ + (OPENSSL_VERSION_NUMBER < 0x10100000L) \ + || (LIBRESSL_VERSION_NUMBER > 0 && LIBRESSL_VERSION_NUMBER < 0x20700000L)) + nSignRet = EVP_SignFinal(&m_Hdr_sha1ctx, sig, &siglen, pkey); + break; #else - nSignRet = EVP_SignFinal(m_Hdr_sha1ctx,sig,&siglen,pkey); break; + nSignRet = EVP_SignFinal(m_Hdr_sha1ctx, sig, &siglen, pkey); + break; #endif - case DKIM_HASH_SHA256: -#if ((OPENSSL_VERSION_NUMBER < 0x10100000L) || (LIBRESSL_VERSION_NUMBER > 0 && LIBRESSL_VERSION_NUMBER < 0x20700000L)) - nSignRet = EVP_SignFinal(&m_Hdr_sha256ctx,sig,&siglen,pkey); break; + case DKIM_HASH_SHA256: +#if ( \ + (OPENSSL_VERSION_NUMBER < 0x10100000L) \ + || (LIBRESSL_VERSION_NUMBER > 0 && LIBRESSL_VERSION_NUMBER < 0x20700000L)) + nSignRet = EVP_SignFinal(&m_Hdr_sha256ctx, sig, &siglen, pkey); + break; #else - nSignRet = EVP_SignFinal(m_Hdr_sha256ctx,sig,&siglen,pkey); break; + nSignRet = EVP_SignFinal(m_Hdr_sha256ctx, sig, &siglen, pkey); + break; #endif -#if (OPENSSL_VERSION_NUMBER > 0x10101000L) - case DKIM_HASH_ED25519: - EVP_DigestSignInit(m_Hdr_ed25519ctx,NULL,NULL,NULL,pkey); - SignMsg = (unsigned char*) SigHdrs.c_str(); - EVP_DigestSign(m_Hdr_ed25519ctx,NULL,&sig_len,SignMsg,m_SigHdrs); - sig = (unsigned char*) OPENSSL_malloc(sig_len); - nSignRet = EVP_DigestSign(m_Hdr_ed25519ctx,sig,&sig_len,SignMsg,m_SigHdrs); - siglen = (unsigned int) sig_len; break; +#if (OPENSSL_VERSION_NUMBER > 0x10101000L) + case DKIM_HASH_ED25519: + EVP_DigestSignInit(m_Hdr_ed25519ctx, NULL, NULL, NULL, pkey); + SignMsg = (unsigned char *)SigHdrs.c_str(); + EVP_DigestSign(m_Hdr_ed25519ctx, NULL, &sig_len, SignMsg, m_SigHdrs); + sig = (unsigned char *)OPENSSL_malloc(sig_len); + nSignRet = EVP_DigestSign(m_Hdr_ed25519ctx, sig, &sig_len, SignMsg, m_SigHdrs); + siglen = (unsigned int)sig_len; + break; #endif } EVP_PKEY_free(pkey); if (!nSignRet) { OPENSSL_free(sig); - return DKIM_BAD_PRIVATE_KEY; // key too small + return DKIM_BAD_PRIVATE_KEY; // key too small } bio = BIO_new(BIO_s_mem()); if (!bio) { - return DKIM_OUT_OF_MEMORY; + return DKIM_OUT_OF_MEMORY; } b64 = BIO_new(BIO_f_base64()); @@ -988,10 +1028,10 @@ int CDKIMSign::ConstructSignature(char* szPrivKey,int nSigAlg) return DKIM_OUT_OF_MEMORY; } - BIO_set_flags(b64,BIO_FLAGS_BASE64_NO_NL); - BIO_push(b64,bio); + BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL); + BIO_push(b64, bio); - if (BIO_write(b64,sig,siglen) < (int) siglen) { + if (BIO_write(b64, sig, siglen) < (int)siglen) { OPENSSL_free(sig); BIO_free_all(b64); return DKIM_OUT_OF_MEMORY; @@ -1007,35 +1047,34 @@ int CDKIMSign::ConstructSignature(char* szPrivKey,int nSigAlg) return DKIM_OUT_OF_MEMORY; } - size = BIO_read(bio,buf,len); + size = BIO_read(bio, buf, len); BIO_free_all(b64); // this should never happen if (size >= len) { delete[] buf; - return DKIM_OUT_OF_MEMORY; + return DKIM_OUT_OF_MEMORY; } buf[size] = '\0'; - AddFoldedValueToSig(buf,0); + AddFoldedValueToSig(buf, 0); delete[] buf; return DKIM_SUCCESS; } //////////////////////////////////////////////////////////////////////////////// -// +// // AssembleReturnSig // -// calls ConstructSignature +// calls ConstructSignature // for all different hashes and signature key files // //////////////////////////////////////////////////////////////////////////////// -int CDKIMSign::AssembleReturnedSig(char* szRSAKey,char* szECCKey) +int CDKIMSign::AssembleReturnedSig(char *szRSAKey, char *szECCKey) { int nRet; - if (m_bReturnedSigAssembled) - return DKIM_SUCCESS; + if (m_bReturnedSigAssembled) return DKIM_SUCCESS; ProcessFinal(); @@ -1045,30 +1084,28 @@ int CDKIMSign::AssembleReturnedSig(char* szRSAKey,char* szECCKey) string ed25519Sig, sha256Sig, sha1Sig; - if ((m_nHash == DKIM_HASH_ED25519) || - (m_nHash == DKIM_HASH_RSA256_AND_ED25519)) { - nRet = ConstructSignature(szECCKey,DKIM_HASH_ED25519); + if ((m_nHash == DKIM_HASH_ED25519) || (m_nHash == DKIM_HASH_RSA256_AND_ED25519)) { + nRet = ConstructSignature(szECCKey, DKIM_HASH_ED25519); if (nRet == DKIM_SUCCESS) { ed25519Sig.assign(m_sSig); } else { return nRet; - } + } } - if ((m_nHash == DKIM_HASH_SHA256) || - (m_nHash == DKIM_HASH_SHA1_AND_SHA256) || - (m_nHash == DKIM_HASH_RSA256_AND_ED25519)) { - nRet = ConstructSignature(szRSAKey,DKIM_HASH_SHA256); + if ((m_nHash == DKIM_HASH_SHA256) || (m_nHash == DKIM_HASH_SHA1_AND_SHA256) + || (m_nHash == DKIM_HASH_RSA256_AND_ED25519)) + { + nRet = ConstructSignature(szRSAKey, DKIM_HASH_SHA256); if (nRet == DKIM_SUCCESS) { sha256Sig.assign(m_sSig); } else { return nRet; - } + } } - if ((m_nHash == DKIM_HASH_SHA1) || - (m_nHash == DKIM_HASH_SHA1_AND_SHA256)) { - nRet = ConstructSignature(szRSAKey,DKIM_HASH_SHA1); + if ((m_nHash == DKIM_HASH_SHA1) || (m_nHash == DKIM_HASH_SHA1_AND_SHA256)) { + nRet = ConstructSignature(szRSAKey, DKIM_HASH_SHA1); if (nRet == DKIM_SUCCESS) { sha1Sig.assign(m_sSig); } else { @@ -1076,11 +1113,11 @@ int CDKIMSign::AssembleReturnedSig(char* szRSAKey,char* szECCKey) } } -// fclose(fpdebug); -// fpdebug = NULL; + // fclose(fpdebug); + // fpdebug = NULL; if (!ed25519Sig.empty()) { -/* if (!m_sReturnedSig.empty()) { + /* if (!m_sReturnedSig.empty()) { m_sReturnedSig.append("\r\n"); } */ -- cgit v1.2.3