diff options
Diffstat (limited to 'src/dkimsign.cpp')
-rw-r--r-- | src/dkimsign.cpp | 62 |
1 files changed, 22 insertions, 40 deletions
diff --git a/src/dkimsign.cpp b/src/dkimsign.cpp index fbdc001..988fd94 100644 --- a/src/dkimsign.cpp +++ b/src/dkimsign.cpp @@ -28,11 +28,17 @@ #include "dkim.h" +#define OLD_SSL \ + ((OPENSSL_VERSION_NUMBER < 0x10100000L) \ + || (LIBRESSL_VERSION_NUMBER > 0 && LIBRESSL_VERSION_NUMBER < 0x20700000L)) + #define _strnicmp strncasecmp #define _stricmp strcasecmp #define LOWORD(l) ((unsigned)(l) & 0xffff) #define HIWORD(l) ((unsigned)(l) >> 16) +using std::string; + /***************************************************************************** * * Generating Ed25519 signed message: @@ -121,9 +127,7 @@ CDKIMSign::CDKIMSign() m_EmptyLineCount = 0; m_pfnHdrCallback = NULL; -#if ( \ - (OPENSSL_VERSION_NUMBER < 0x10100000L) \ - || (LIBRESSL_VERSION_NUMBER > 0 && LIBRESSL_VERSION_NUMBER < 0x20700000L)) +#if OLD_SSL EVP_SignInit(&m_Hdr_sha1ctx, EVP_sha1()); EVP_SignInit(&m_Hdr_sha256ctx, EVP_sha256()); EVP_DigestInit(&m_Bdy_sha1ctx, EVP_sha1()); @@ -150,9 +154,7 @@ CDKIMSign::CDKIMSign() CDKIMSign::~CDKIMSign() { -#if ( \ - (OPENSSL_VERSION_NUMBER < 0x10100000L) \ - || (LIBRESSL_VERSION_NUMBER > 0 && LIBRESSL_VERSION_NUMBER < 0x20700000L)) +#if OLD_SSL EVP_MD_CTX_cleanup(&m_Hdr_sha1ctx); EVP_MD_CTX_cleanup(&m_Hdr_sha256ctx); EVP_MD_CTX_cleanup(&m_Bdy_sha1ctx); @@ -254,18 +256,14 @@ void CDKIMSign::Hash(const char *szBuffer, int nBufLength, bool bHdr) 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)) +#if OLD_SSL 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)) +#if OLD_SSL EVP_SignUpdate(&m_Hdr_sha256ctx, szBuffer, nBufLength); #else EVP_SignUpdate(m_Hdr_sha256ctx, szBuffer, nBufLength); @@ -278,17 +276,13 @@ void CDKIMSign::Hash(const char *szBuffer, int nBufLength, bool bHdr) #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)) +#if OLD_SSL 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)) +#if OLD_SSL EVP_DigestUpdate(&m_Bdy_sha256ctx, szBuffer, nBufLength); #else EVP_DigestUpdate(m_Bdy_sha256ctx, szBuffer, nBufLength); @@ -382,10 +376,10 @@ void CDKIMSign::GetHeaderParams(const string& sHdr) //////////////////////////////////////////////////////////////////////////////// int CDKIMSign::ProcessHeaders(void) { - map<string, list<string>::reverse_iterator> IterMap; - map<string, list<string>::reverse_iterator>::iterator IterMapIter; - list<string>::reverse_iterator riter; - list<string>::iterator iter; + std::map<string, std::list<string>::reverse_iterator> IterMap; + std::map<string, std::list<string>::reverse_iterator>::iterator IterMapIter; + std::list<string>::reverse_iterator riter; + std::list<string>::iterator iter; string sTag; bool bFromHeaderFound = false; @@ -824,9 +818,7 @@ int CDKIMSign::ConstructSignature(char *szPrivKey, int nSigAlg) switch (nSigAlg) { case DKIM_HASH_SHA1: -#if ( \ - (OPENSSL_VERSION_NUMBER < 0x10100000L) \ - || (LIBRESSL_VERSION_NUMBER > 0 && LIBRESSL_VERSION_NUMBER < 0x20700000L)) +#if OLD_SSL EVP_DigestFinal(&m_Bdy_sha1ctx, Hash, &nHashLen); break; #else @@ -834,9 +826,7 @@ int CDKIMSign::ConstructSignature(char *szPrivKey, int nSigAlg) break; #endif case DKIM_HASH_SHA256: -#if ( \ - (OPENSSL_VERSION_NUMBER < 0x10100000L) \ - || (LIBRESSL_VERSION_NUMBER > 0 && LIBRESSL_VERSION_NUMBER < 0x20700000L)) +#if OLD_SSL EVP_DigestFinal(&m_Bdy_sha256ctx, Hash, &nHashLen); break; #else @@ -908,9 +898,7 @@ int CDKIMSign::ConstructSignature(char *szPrivKey, int nSigAlg) switch (nSigAlg) { case DKIM_HASH_SHA1: -#if ( \ - (OPENSSL_VERSION_NUMBER < 0x10100000L) \ - || (LIBRESSL_VERSION_NUMBER > 0 && LIBRESSL_VERSION_NUMBER < 0x20700000L)) +#if OLD_SSL EVP_SignUpdate(&m_Hdr_sha1ctx, sTemp.c_str(), sTemp.size()); break; #else @@ -918,9 +906,7 @@ int CDKIMSign::ConstructSignature(char *szPrivKey, int nSigAlg) break; #endif case DKIM_HASH_SHA256: -#if ( \ - (OPENSSL_VERSION_NUMBER < 0x10100000L) \ - || (LIBRESSL_VERSION_NUMBER > 0 && LIBRESSL_VERSION_NUMBER < 0x20700000L)) +#if OLD_SSL EVP_SignUpdate(&m_Hdr_sha256ctx, sTemp.c_str(), sTemp.size()); break; #else @@ -957,9 +943,7 @@ int CDKIMSign::ConstructSignature(char *szPrivKey, int nSigAlg) switch (nSigAlg) { case DKIM_HASH_SHA1: -#if ( \ - (OPENSSL_VERSION_NUMBER < 0x10100000L) \ - || (LIBRESSL_VERSION_NUMBER > 0 && LIBRESSL_VERSION_NUMBER < 0x20700000L)) +#if OLD_SSL nSignRet = EVP_SignFinal(&m_Hdr_sha1ctx, sig, &siglen, pkey); break; #else @@ -967,9 +951,7 @@ int CDKIMSign::ConstructSignature(char *szPrivKey, int nSigAlg) break; #endif case DKIM_HASH_SHA256: -#if ( \ - (OPENSSL_VERSION_NUMBER < 0x10100000L) \ - || (LIBRESSL_VERSION_NUMBER > 0 && LIBRESSL_VERSION_NUMBER < 0x20700000L)) +#if OLD_SSL nSignRet = EVP_SignFinal(&m_Hdr_sha256ctx, sig, &siglen, pkey); break; #else |