Hector Santos
unread,Sep 17, 2010, 10:56:26 PM9/17/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to DKIM Support
This is a test
//
***********************************************************************
// (c) Copyright 1998-2010 Santronics Software, Inc. All Rights
Reserved.
//
***********************************************************************
//
// File Name : wcrouter-dkimsigner.wcx
// Subsystem : pcode for wcsmtp router
// Date : 09/17/2010
// Version : 6.3.453.5
// Author : SSI/HLS
// About : DKIM outbound signer
//
// Revision History:
// Build Date Author Comments
// ----- -------- ------
-------------------------------------------
// 453.5 09/17/10 HLS - initial verison
//
***********************************************************************
#include "htmlutil.wch"
#include "Logfile.wch"
#include "smtpfilterhlp.wch"
#include "msgutil.wch"
#include "wcdkimapi.wch"
const RF_LOGFILE = "wcDkim.log"
const crlf = chr(13)+chr(10)
sub rflog(byval s as string)
if s = "" then
writeLogEntry(RF_LOGFILE,"")
else
writeLogEntry(RF_LOGFILE,LogTimeStamp()+" > "+ s)
end if
end sub
function CheckDKimKey(byval dom as string) as boolean
dim priFileName as string
priFileName = "wc:\dkimmgr\"+dom+".rsa.private"
CheckDKimKey = Exists(PriFileName)
end function
function FileHasEnvelope(byval msgfn as string) as boolean
FileHasEnvelope = false
dim fv as integer = open msgfn for input
if (fv > 0) then
dim s as string
do while not eof(fv)
input #fv, s
if s = "" then exit do
if ucase(s) = "DATA:" then
FileHasEnvelope = true
exit do
end if
loop
close(fv)
end if
end function
//------------------------------------------------------------------
// SIGNER
//------------------------------------------------------------------
function DKimSignMail(byval nf as integer, \
byval adomain as string, \
byval aselector as string, \
byval msgfn as string, \
nres as integer) as boolean
DKimSignMail = false
dim ctx as DKIMContext
dim sopts as DKIMSignOptions
sopts.nCanon = DKIM_SIGN_SIMPLE //
canonization
sopts.nIncludeBodyLengthTag = 0 // 0 =
don't include l= tag, 1 = include l= tag
sopts.nIncludeTimeStamp = 1 // 0 =
don't include t= tag, 1 = include t= tag
sopts.nIncludeQueryMethod = 0 // 0 =
don't include q= tag, 1 = include q= tag
sopts.nHash = DKIM_HASH_SHA1 // use one
of the DKIM_HASH_xx constants here
sopts.nIncludeCopiedHeaders = 0 // 0 =
don't include z= tag, 1 = include z= tag
sopts.nIncludeBodyHash = DKIM_BODYHASH_IETF_1 // use one
of the DKIM_BODYHASH_xx constants here
sopts.szIdentity = "" // for i=
tag, if empty tag will not be included in sig
sopts.expireTime = 0 // for x=
tag, if 0 tag will not be included in sig
sopts.nUseRequiredHeadersOnly = 1 // 1 =
used szRequireHeaders
sopts.szRequiredHeaders = "From:To:Date:Message-
Id:Organization:Subject"
sopts.szSelector = aselector
sopts.szDomain = adomain
dim wcPriKeyFile as string = "wc:\dkimmgr\"+sopts.szDomain
+".rsa.private"
dim privkey as string = GetText(wcPriKeyFile)
if privkey = "" then
rflog("- DKIM.NoPrivateKey: domain: "+adomain)
exit function
end if
DKIMSignInit(@ctx, @sopts)
dim inEnvelope as boolean = FileHasEnvelope(msgfn)
dim fv as integer = open msgfn for input
if (fv <= 0) then
rflog("- DKIM.ReadError: "+Hex(GetLastError()))
exit function
end if
while not eof(fv)
dim s as string
input #fv, s
if inEnvelope then
if ucase(s) = "DATA:" then
inEnvelope = False
end if
else
s = s + crlf
DKIMSignProcess( @ctx, s, len(s))
end if
wend
close(fv)
dim szSignature as string*10240
nres = DKIMSignGetSig( @ctx, PrivKey, @szSignature,
sizeof(szSignature) )
DKIMSignFree( @ctx )
if nres = DKIM_SUCCESS then
#if 0
do while (sfSetHeaderLineEx(msgfn,"DKIM-Signature:",
SFHEADER_REMOVE, sfAnyHeader) <> 0)
loop
do while (sfSetHeaderLineEx(msgfn,"Domainkey-Signature:",
SFHEADER_REMOVE, sfAnyHeader) <> 0)
loop
#endif
sfSetHeaderLineEx(msgfn,szSignature, SFHEADER_ADDTOP,
sfMailHeaderOnly)
end if
DKimSignMail = (nres = DKIM_SUCCESS)
End Function
//--------------------------------------------------------------------
// MAIN
//--------------------------------------------------------------------
GlobalResult = TRUE
dim args as string = paramstr(1)
dim ver as string = GetParamStr(args, "ver", "") //
router filter version
dim bld as string = GetParamStr(args, "bld", "") //
router filter build
dim msf as string = GetParamStr(args, "msf", "") //
mail spool file
dim outgoing as boolean = GetParamBool(args, "out", TRUE) //
direction
dim auid as integer = GetParamInt(args, "uid", 0) //
authenticated user id
dim from821 as string = GetParamStr(args, "rpa", "") //
return path
dim To821 as string = GetParamStr(args, "dpa", "") //
dest path
dim sInOut as string = "incoming"
if (outgoing) then sInOut = "outgoing"
from821 = sfStripBrackets(from821)
to821 = sfStripBrackets(to821)
rflog("--------------------------------------------")
dim s as string = ""
s = s + "RES: " + pad(str(GlobalResult),3)
s = s + " | cid: "+pad(str(GetConnectionId()),5)
s = s + " | dir: "+sInOut
s = s + " | aid: "+str(auid)
s = s + " | msf: "+msf
s = s + " | rpa: "+from821
s = s + " | dpa: "+To821
rflog(s)
dim From822 as string
if sfGetHeaderLineEx(msf,"From:",From822, sfMailHeaderOnly) then
dim ea as TEmailAddress
ParseEmailAddress(from822,ea)
rflog("- From821: "+From821)
rflog("- To821 : "+To821)
rflog("- From822: "+From822)
rflog("- From822.domain: "+ea.domain)
if (outgoing and CheckDKIMKey(ea.domain)) then
dim nres as integer
DKimSignMail(1,ea.domain,"tms1",msf,nres)
rflog("- DKIM.nres: "+DKIMFailureReason(nres))
end if
else
rflog("! WARNING NO FROM:")
end if
rflog("")
end