Showing posts with label Sendmail. Show all posts
Showing posts with label Sendmail. Show all posts

Tuesday, February 11, 2014

Sendmail with DKIM on Fedora 19


http://www.ipsure.com/blog/2010/domainkeys-identified-mail-dkim-with-postfix-smtp-only/
http://www.techsneeze.com/deploy-dkim-milter-multiple-domains-centos-5-sendmail
http://www.cesafaci.ro/tutoriale/sendmail-cu-dkim-pe-centos-fedora-19.html

yum install dkim-milter


cd /etc/mail/dkim-milter/keys
dkim-genkey -r -d your-domain.com
= > 2 files : public key (default.txt) and private key (default.private)

At this point you should have a "default.private" and "default.txt" file in your current working directory (which is /etc/mail/dkim-milter/keys). 
default.txt contains the DNS TXT record you must add to your DNS entries. 

cat default.txt >> /var/named/chroot/var/named/yourdomain.zone
mv default.private /etc/mail/dkim-milter/domeniultau_default.key.pem
chown dkim-milter:dkim-milter /etc/mail/dkim-milter/domeniultau_default.key.pem



/etc/mail/dkim-milter/dkim-filter.conf


Domaindomeniu.ro
KeyFile/etc/mail/dkim-milter/domeniultau_default.key.pem
MTAMSA
Selectordefault
SignatureAlgorithmrsa-sha1
Socketlocal:/var/run/dkim-milter/dkim-milter.sock
SyslogYes
X-HeaderYes












/etc/mail/sendmail.mc
dnl # dkim - yahoo domainkeys implementation
INPUT_MAIL_FILTER(`dkim-filter', `S=local:/var/run/dkim-milter/dkim-milter.sock')

cd /etc/mail
make
service named reload
service dkim-milter start
service sendmail restart
chkconfig dkim-milter on






 The config file (/etc/mail/dkim-milter/dkim-filter.conf) is fully self-documented and easy to understand. 
I made the following changes from the default config:
AutoRestart  Yes
AutoRestartRate 10/1h
Canonicalization simple/simple
Domain  techsneeze.com
ExternalIgnoreList /etc/mail/dkim-milter/trusted-hosts
InternalHosts /etc/mail/dkim-milter/InternalHosts.txt
LogWhy  yes
On-Default accept
On-BadSignature accept
On-DNSError accept
On-InternalError accept
On-NoSignature accept
On-Security accept
SignatureAlgorithm rsa-sha256
Socket  local:/var/run/dkim-milter/dkim-milter.sock
Syslog  yes
SyslogSuccess yes
UserID  dkim-milter:dkim-milter
X-Header  yes



PROBLEM : 
if in the logs appear something like : "no signature data" 
       [ cat /var/log/maillog | grep "no signature data" ] or 
   "external host [192.168.101.54] attempted to send as yourdomain.com
  and this host  [192.168.101.54] is on your internal network ...
SOLUTION: 
#cd /etc/mail/dkim-milter/ 
#touch InternalHosts.txt 
# chmod 444 InternalHosts.txt
 # vi InternalHosts.txt 
         192.168.101.0/24
   
          yourdomain.com     
          smtp.yourdomain.com

~ ~ ~ 

We may enhance DKIM TXT entries like: 
 _domainkey.(yourdomain.com). IN TXT "t=y; o=~; r=postmaster@(yourdomain.com)" 
 where 
 t=y means “this domain is currently testing DKIM, verifier side mustn’t treat the messages differently from unsigned e-mails even if the signature fails to be verified”

 

 o=~ means “some e-mails from this domain are signed, some are not”

  

o=- means “all e-mails from this domain are signed”

 

 r=postmaster@(yourdomain.com) designates responsible e-mail address



When we implemented DomainKeys Identified Mail (DKIM) with Postfix on FreeBSD, we had used dkim-milter plugin. However, it seems that dkim-milter has expired and recently it has been removed from the ports tree. Consequently, we’ll also move to OpenDKIM which is in fact claimed to be bug free compared to dkim-milter. - See more at: http://www.ipsure.com/blog/2012/dkim-milter-is-no-longer-available-how-to-use-opendkim-instead/#sthash.UraBfaka.dpuf





Open



DKIM includes a cryptographic hash in the e-mail header which is calculated with the private key (on the server) and verified with the public key (in the DNS record).
DKIM-Signature: v=1; a=rsa-sha256; d=example.net; s=brisbane;
     c=relaxed/simple; q=dns/txt; l=1234; t=1117574938; x=1118006938;
     h=from:to:subject:date:keywords:keywords;
     bh=MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI=;
     b=dzdVyOfAKCdLXdJOc9G2q8LoXSlEniSbav+yuU4zGeeruD00lszZ
              VoG4ZHRNiYzR


First, install opendkim.
yum install opendkim

/etc/opendkim.conf.
AutoRestart             Yes
UMask                   002
Syslog                  yes
AutoRestartRate         10/1h
Canonicalization        relaxed/simple
ExternalIgnoreList      refile:/etc/opendkim/TrustedHosts
InternalHosts           refile:/etc/opendkim/TrustedHosts
KeyTable                refile:/etc/opendkim/KeyTable
LogWhy                  Yes
Mode                    sv
PidFile                 /var/run/opendkim/opendkim.pid
SignatureAlgorithm      rsa-sha256
SigningTable            refile:/etc/opendkim/SigningTable
Socket                  inet:8891@localhost
SyslogSuccess           Yes
TemporaryDirectory      /var/tmp
UserID                  opendkim:opendkim
As you can see, there are three more files to be added, TrustedHosts (whitelisted IPs that can sign e-mails), KeyTable (multiple domain configuration for public and private keys) and SigningTable (whitelisted users that can sign e-mail).

/etc/opendkim/TrustedHosts:
127.0.0.1
example.com
192.168.0.1/24


/etc/opendkim/SigningTable:
*@example.com default._domainkey.example.com
All users from @example.com can sign. You can specifiy usernames and domains, instead of the wildcard, for additional security.

/etc/opendkim/KeyTable:
default._domainkey.example.com example.com:default:/etc/opendkim/keys/example.com.pvt
Location of the private key and name of the DNS record for each domain. The "default" before _domainkey.example.com and :default: is a selector. This can be changed to something else.

Next, we need to generate the public and private key for each domain.
If some folders don't exist, just create them.
# opendkim-genkey -D /etc/opendkim/keys/example.com -d example.com -s default
Again -s flag is for the selector. If you changed it, you need to enter it here.
The command generates a private key (default) and public key (default.txt). You will probably rename them, to match the configuration.
An important note here is that the files are owned by user opendkim, or you will get permission denied errors in /var/log/mail.err. Default permissions on those files are -rw------.

Move the private key to where you specified it should be in the KeyTable.
Insert the public key in your DNS as a TXT record.

Next up, telling sendmail to talk to opendkim.
Edit /etc/mail/sendmail.mc and add this line at the end. 
INPUT_MAIL_FILTER(`opendkim', `S=inet:8891@localhost')

Rebuild sendmail configuration and restart, start opendkim if it's not running yet
service sendmail restart; service opendkim start

Thursday, November 28, 2013

Sendmail ‘collect: premature EOM: unexpected close’



Sendmail 

‘collect: premature EOM: unexpected close’


If you are getting a ‘collect: premature EOM: unexpected close’ in your mail logs, or if you have people complaining that they cannot send email to your server and you have this error, then there's a solution to the problem.


I had over time installed several Blacklist denials in my sendmail.mc config file, and that perhaps one of these was not responding anymore.
By commenting out each Blacklist deny one at a time, I discovered which one was no longer responding. To comment out a line in the main sendmail.mc file, simply put dnl at the start of the line. 

FEATURE(`dnsbl’,`sbl-xbl.spamhaus.org’,`550 Denied RBL $&{client_addr} by sbl-xbl.spamhaus.org”’)dnl
FEATURE(`dnsbl',`dnsbl.sorbs.net',`"554 Rejected " $&{client_addr} " Found in dnsbl.sorbs.net"',`t')dnl

Friday, October 25, 2013

Fedora 19 systemctl sendmail clamav milter


http://awbsworld.de/archives/125

http://serverfault.com/questions/513005/clamav-warning-no-clamd-server-appears-to-be-available/513006#513006
http://savs.hcc.edu.tw/~chuavv/articles/ClamAV-en.html
http://forums.fedoraforum.org/showthread.php?t=235160

Step 1: Install the necessary rpm packages

sudo yum install clamav-scanner clamav-server clamav-milter clamav-update

Step 2: Configure clamav

Edit /etc/freshclam.conf and remove or comment out the following line and adjust the 
values according to your needs : 


# Comment or remove the line below.
Example
Run freshclam to get an initial virus database.Edit " /etc/clamd.d/scan.conf " and remove or comment out the following line and again adjust the values according to your needs. The values for TCPSocket and TCPAddr need to be enabled.

Step 3: Enabled clamav and regular virus database updates via freshclam

Start the clamav scanner deamon with 
            systemctl start clamd@scan.service. 
Check if the service is running via 
            systemctl status clamd@scan.service. 

To permanently enabled the clamav scanner deamon at startup run 
            systemctl enable clamd@scan.service.

In /etc/mail/clamav-milter.conf:
I also added a line:

AddHeader Add
So it adds 'X-Virus-Status:' and 'X-Virus-Scanned:' headers to the e-mails (so I would know it was working)

And then tell sendmail to call clamav-milter by adding the 2 lines below:
INPUT_MAIL_FILTER(`clamav',`S=local:/var/run/clamav-milter/clamav-milter.socket,F=, T=S:4m;R:4m')
define(`ConfINPUT_MAIL_FILTERS', `clamav')

~ ~ ~ ~ ~ ~ ~ ~ ~ 
IMPORTANT : 

LocalSocket from " /etc/clamd./scan.conf " 

must be the same compared with 
ClamdSocket from " /etc/mail/clamav-milter.conf "

If the sockets are not the same , in /var/log/messages appears the error :

" clamav-milter : WARNING : No clamd server appears to be available "  

IF we leave "LocalSocketGroup virusgroup" and do not set "LocalSocketGroup clamscan" 

in "/etc/clamd./scan.conf" 
in the logs will appear something like this : 
<< 
 TCP: Bound to address 127.0.0.1 on port 3310
 clamd : TCP: Setting connection queue length to 200
 clamd : LOCAL: Unix socket file /var/run/clamd.scan/clamd.sock
 clamd : LOCAL: Setting connection queue length to 200
 clamd : Unknown group virusgroup
 clamd : Socket file removed.
 clamd : ERROR: Unknown group virusgroup
 clamd : Socket file removed.
 systemd : clamd@scan.service: main process exited, code=exited, status=1/FAILURE
 systemd : Unit clamd@scan.service entered failed state.
>> 

~ ~ ~ ~ ~ ~ ~ ~ ~ 


/etc/clamd./scan.conf 

# Comment or remove the line below.
# Example
LogFile /var/log/clamd.scan
PidFile /var/run/clamd.scan/clamd.pid
LocalSocket /var/run/clamd.scan/clamd.sock
LocalSocketGroup clamscan
TCPSocket 3310
TCPAddr 127.0.0.1

~ ~ ~ 


/etc/mail/clamav-milter.conf 

# Comment or remove the line below.
#Example
MilterSocket /var/run/clamav-milter/clamav-milter.socket
MilterSocket inet:7357
#ClamdSocket tcp:localhost:3310
ClamdSocket unix:/var/run/clamd.scan/clamd.sock
AddHeader Add


~ ~ ~ 


# rpm -qa | grep clam

clamav-update-0.98-2.fc19.x86_64
clamav-server-systemd-0.98-2.fc19.noarch
clamav-server-0.98-2.fc19.x86_64
claws-mail-plugins-clamd-3.9.2-7.fc19.x86_64
clamav-milter-0.98-2.fc19.x86_64
clamav-scanner-0.98-2.fc19.noarch
clamav-lib-0.98-2.fc19.x86_64
clamav-filesystem-0.98-2.fc19.noarch
clamtk-4.45-1.fc19.noarch
clamav-0.98-2.fc19.x86_64
clamav-milter-systemd-0.98-2.fc19.noarch
clamav-data-empty-0.98-2.fc19.noarch
clamav-scanner-systemd-0.98-2.fc19.noarch

# uname -a

Linux 3.11.6-200.fc19.x86_64 #1 SMP Fri Oct 18 22:34:18 UTC 2013 x86_64 GNU/Linux
# cat /etc/fedora-release 
Fedora release 19 (Schrödinger’s Cat)


if there's no log file ( /var/log/clamd.scan ) or it has owner and group root 
instead of clamscan , then ~ in the logs will appear something like this : 

Feb  6 21:50:30 abxrds systemd[1]: Starting Generic clamav scanner daemon...
Feb  6 21:50:30 abxrds systemd[1]: Started Generic clamav scanner daemon.
Feb  6 21:50:30 abxrds clamd[20802]: ERROR: Can't initialize the internal logger
Feb  6 21:50:30 abxrds clamd[20802]: ERROR: Can't open /var/log/clamd.scan in append mode (check permissions!).
Feb  6 21:50:30 abxrds systemd[1]: clamd@scan.service: main process exited, code=exited, status=1/FAILURE
Feb  6 21:50:30 abxrds systemd[1]: Unit clamd@scan.service entered failed state.
Feb  6 21:50:30 abxrds systemd[1]: clamd@scan.service holdoff time over, scheduling restart.
Feb  6 21:50:30 abxrds systemd[1]: Stopping Generic clamav scanner daemon...
Feb  6 21:50:30 abxrds systemd[1]: Starting Generic clamav scanner daemon...
Feb  6 21:50:30 abxrds systemd[1]: clamd@scan.service start request repeated too quickly, refusing to start.
Feb  6 21:50:30 abxrds systemd[1]: Failed to start Generic clamav scanner daemon.
Feb  6 21:50:30 abxrds systemd[1]: Unit clamd@scan.service entered failed state.

Tuesday, July 16, 2013

MAIL EXPN VRFY ETRN



sendmail ERROR "did not issue MAIL/EXPN/VRFY/ETRN during connection to MTA"


We had to investigate problems relaying mail from a certain IP. Looking through the MTA logs, we see:



Jul 16 15:40:29 gate sendmail[30309]: r6GCcjKJ030309: spamfilter2.starnet.md [178.168.2.134] did not issue MAIL/EXPN/VRFY/ETRN during connection to MTA
Jul 16 15:57:11 gate sendmail[30913]: r6GCtSW0030913: spamfilter2.starnet.md [178.168.2.134] did not issue MAIL/EXPN/VRFY/ETRN during connection to MTA
Jul 16 16:17:12 gate sendmail[31567]: r6GDFTme031567: spamfilter2.starnet.md [178.168.2.134] did not issue MAIL/EXPN/VRFY/ETRN during connection to MTA
Jul 16 16:18:16 gate sendmail[31617]: r6GDGVie031617: smtpclu-6.eunet.rs [194.247.192.231] did not issue MAIL/EXPN/VRFY/ETRN during connection to MTA
Jul 16 16:22:57 gate sendmail[31786]: r6GDLEbe031786: smtpclu-6.eunet.rs [194.247.192.231] did not issue MAIL/EXPN/VRFY/ETRN during connection to MTA
Jul 16 16:50:59 gate sendmail[32740]: r6GDnIa1032740: smtpclu-6.eunet.rs [194.247.192.231] did not issue MAIL/EXPN/VRFY/ETRN during connection to MTA
Jul 16 17:22:54 gate sendmail[1672] : r6GEL9oM001672: smtpclu-6.eunet.rs [194.247.192.231] did not issue MAIL/EXPN/VRFY/ETRN during connection to MTA


On the other side , the error eMaiL was : 


Reporting-MTA: dns; spamfilter.starnet.md
Arrival-Date: Tue,  9 Jul 2013 22:03:38 +0300 (EEST)

Final-Recipient: rfc822; dircom@mydomain.com
Action: failed
Status: 4.0.0
Diagnostic-Code: X-Spam-&-Virus-Firewall; connect to
    [27.10.97.70]: read timeout



A Cisco PIX between the host and our mail relay is performing SMTP inspection ("SMTP Fixup"). 



The sending MTA apparently does not know how to handle a "500 5.5.1" response from our MTA, and keeps the connection open for one hour (default Timeout.command in sendmail). After one hour, our MTA closes the connection.



As a workaround, enable ESMTP inspection, or disable SMTP inspection. ESMTP inspection allows commands described in RFC 2821. Note that ESMTP inspection and SMTP inspection are mutually exclusive.


http://brandonhutchinson.com/wiki/SMTP_Fixup_problems
http://www.cisco.com/en/US/products/sw/secursw/ps1018/products_configuration_example09186a008064730a.shtml



http://frustratedtech.com/post/41281442135/sendmail-dropping-connections-from-monitoring-servers
http://www.sendmail.com/sm/open_source/docs/configuration_readme/



 Sendmail Dropping Connections From Monitoring Servers?

I’ve been seeing this frequently.  We currently use IPMonitor at work.  I hate it.  But, it is what it is, gotta use what is provided.  So, this monitoring system uses snmp to check all services and then it also tries to connect to smtp.  However, one server is setup to require pop3 login before smtp access can be acquired.  This was giving plenty of false positives for the monitoring system since we were seeing this message a lot.
# tail -f /var/log/maillog
Jan 23 04:02:02 LUX5 sendmail[8278]: r0N922sj008278: [123.456.789.10] did not issue MAIL/EXPN/VRFY/ETRN during connection to MTA
To fix this I needed to add the monitoring server to the access file for sendmail to accept the connection.
# nano /etc/mail/access
# Check the /usr/share/doc/sendmail/README.cf file for a description
# of the format of this file. (search for access_db in that file)
# The /usr/share/doc/sendmail/README.cf is part of the sendmail-doc
# package.
#
# by default we allow relaying from localhost...
connect:localhost.localdomain           RELAY
connect:localhost                       RELAY
connect:127.0.0.1                       RELAY
######ADD YOUR IP BELOW#########
connect:123.456.789.10                  OK
Then just rebuild the database and restart sendmail. You will see see the error message, but at least you will no longer get the false positives.
# makemap hash /etc/mail/access < /etc/mail/access
# service sendmail restart

Thursday, May 19, 2011

FEDORA SENDMAIL SASLAUTHD

I configured a FEDORA 14 server with : SMTPAUTH and STARTTLS
I could send e-mails from a Windows Mobile 6.1 smartphone,
but with Thunderbird there was an error ;

On the Windows Mobile smartphone , the advanced settings were checked :
[ x ] Send/receive when I click send
[ x ] Require SSL for Incoming email
[ x ] Require SSL for Outgoing email
[ x ] Outgoing server requires authentication

In the end I changed MECH=shadow instead of MECH=pam , and
the problem was gone !



/etc/sysconfig/saslauthd
SOCKETDIR=/var/run/saslauthd


# Mechanism to use when checking passwords.  Run "saslauthd -v" to get a list
# of which mechanism your installation was compiled with the ablity to use.
# MECH=pam
MECH=shadow
# Options sent to the saslauthd. If the MECH is other than "pam" uncomment the next line.
# DAEMONOPTS=--user saslauth
# Additional flags to pass to saslauthd on the command line.  See saslauthd(8)
# for the list of accepted flags.
FLAGS=




http://www.howtoforge.com/howto_sendmail_smtp_auth_tls
http://www.screaming-penguin.com/node/4214
http://www.madboa.com/geek/sendmail-auth/
http://blog.mikezhang.com/2005/01/11/using-smtp-auth-and-starttls-with-sendmail




/etc/mail/sendmail.mc 

dnl ### do SMTPAUTH
define(`confAUTH_MECHANISMS', `LOGIN PLAIN DIGEST-MD5 CRAM-MD5')dnl
TRUST_AUTH_MECH(`LOGIN PLAIN DIGEST-MD5 CRAM-MD5')dnl


dnl ### do STARTTLS
define(`confCACERT_PATH', `/etc/mail/certs')dnl
define(`confCACERT', `/etc/mail/certs/cacert.pem')dnl
define(`confSERVER_CERT', `/etc/mail/certs/sendmail.pem')dnl
define(`confSERVER_KEY', `/etc/mail/certs/sendmail.pem')dnl
define(`confCLIENT_CERT', `/etc/mail/certs/sendmail.pem')dnl
define(`confCLIENT_KEY', `/etc/mail/certs/sendmail.pem')dnl
DAEMON_OPTIONS(`Family=inet, Port=465, Name=MTA-SSL, M=s')dnl




the full sendmail.mc 
~ ~ ~ 

divert(-1)dnl
include(`/usr/share/sendmail-cf/m4/cf.m4')dnl
VERSIONID(`setup for linux')dnl
OSTYPE(`linux')dnl
define(`confAUTH_MECHANISMS', `LOGIN PLAIN DIGEST-MD5 CRAM-MD5')dnl
TRUST_AUTH_MECH(`LOGIN PLAIN DIGEST-MD5 CRAM-MD5')dnl
dnl # do STARTTLS
define(`confCACERT_PATH', `/etc/mail/certs')dnl
define(`confCACERT', `/etc/mail/certs/cacert.pem')dnl
define(`confSERVER_CERT', `/etc/mail/certs/sendmail.pem')dnl
define(`confSERVER_KEY', `/etc/mail/certs/sendmail.pem')dnl
define(`confCLIENT_CERT', `/etc/mail/certs/sendmail.pem')dnl
define(`confCLIENT_KEY', `/etc/mail/certs/sendmail.pem')dnl
DAEMON_OPTIONS(`Family=inet, Port=465, Name=MTA-SSL, M=s')dnl
DAEMON_OPTIONS(`Family=inet, Name=MTA-v4, Port=smtp')dnl
FEATURE(`delay_checks')
define(`confDEF_USER_ID', ``8:12'')dnl
define(`confTO_CONNECT', `1m')dnl
define(`confTRY_NULL_MX_LIST', `True')dnl
define(`confDONT_PROBE_INTERFACES', `True')dnl
define(`PROCMAIL_MAILER_PATH', `/usr/bin/procmail')dnl
define(`ALIAS_FILE', `/etc/aliases')dnl
define(`STATUS_FILE', `/var/log/mail/statistics')dnl
define(`UUCP_MAILER_MAX', `2000000')dnl
define(`confUSERDB_SPEC', `/etc/mail/userdb.db')dnl
define(`confPRIVACY_FLAGS', `authwarnings,novrfy,noexpn,restrictqrun')dnl
define(`confAUTH_OPTIONS', `A')dnl
define(`confTO_IDENT', `0')dnl
FEATURE(`no_default_msa', `dnl')dnl
FEATURE(`smrsh', `/usr/sbin/smrsh')dnl
FEATURE(`mailertable', `hash -o /etc/mail/mailertable.db')dnl
FEATURE(`virtusertable', `hash -o /etc/mail/virtusertable.db')dnl
FEATURE(redirect)dnl
FEATURE(always_add_domain)dnl
FEATURE(use_cw_file)dnl
FEATURE(use_ct_file)dnl
FEATURE(`dnsbl',`sbl-xbl.spamhaus.org')dnl
FEATURE(`dnsbl',`list.dsbl.org', `"550 Mail from " $&{client_addr} " BLOCKED/DSBL; see http://www.dsbl.org/listing [dsbl.org]?" $&{client_addr}')dnl
FEATURE(`dnsbl',`bl.spamcop.net', `"550 Mail from " $&{client_addr} " BLOCKED/COP; see http://www.spamcop.net/w3m?action=checkblock&ip= [spamcop.net]" $&{client_addr}')dnl
FEATURE(`dnsbl',`cbl.abuseat.org')dnl
FEATURE(`dnsbl',`dnsbl.sorbs.net',`"554 Rejected " $&{client_addr} " Found in dnsbl.sorbs.net"',`t')dnl
FEATURE(`dnsbl', `bhnc.njabl.org', `"550 Mail from " $&{client_addr} " BLOCKED/BHNC; see http://www.njabl.org/lookup [njabl.org]?" $&{client_addr}')dnl
FEATURE(`dnsbl', `dul.ru', `Use mail relays of your ISP')dnl
FEATURE(`enhdnsbl',`multi.uribl.com', `"Spam blocked see: http://lookup.uribl.com/?"$&{client_addr}', `t')dnl
INPUT_MAIL_FILTER(`greylist',`S=local:/var/run/milter-greylist/milter-greylist.sock')
FEATURE(local_procmail, `', `procmail -t -Y -a $h -d $u')dnl
FEATURE(`access_db', `hash -T -o /etc/mail/access.db')dnl
FEATURE(`blacklist_recipients')dnl
EXPOSED_USER(`root')dnl
LOCAL_DOMAIN(`localhost.localdomain')dnl
MASQUERADE_AS(`grampa.com')dnl
MAILER(smtp)dnl
MAILER(procmail)dnl
dnl MAILER(cyrusv2)dnl
define(`confMAX_MESSAGE_SIZE',`12000000')dnl
INPUT_MAIL_FILTER(`clamav',`S=local:/var/run/clamav-milter/clamav.sock, F=, T=S:4m;R:4m')dnl
define(`confINPUT_MAIL_FILTERS',`clamav')

Saturday, April 16, 2011

Sendmail SMTP AUTH to bypass DNSBL

Q:
<<
I use DNSBL to filter incoming mail. I also offer SMTP AUTH. The problem I'm having is that, while authenticated users are allowed to relay, they're still subject to DNSBL . Any way to prevent that, so that authenticated users can _always_ relay? 
>>


Apr 15 23:45:37 ftp sendmail[27729]: ruleset=check_relay, arg1=[21.23.10.25], arg2=127.0.0.10, relay=[21.23.10.25], reject=554 5.7.1 Rejected 21.23.10.25 Found in dnsbl.sorbs.net


A:

You may use FEATURE(`delay_checks').
skips DNSBL checks for authenticated users.
URL(s):
http://www.sendmail.org/m4/anti_spam.html#delay_check

<<

Delay all checks

By using FEATURE(`delay_checks') the rulesets check_mail and check_relay will not be called when a client connects or issues a MAIL command, respectively. Instead, those rulesets will be called by the check_rcpt ruleset; they will be skipped if a sender has been authenticated using a "trusted" mechanism, i.e., one that is defined via TRUST_AUTH_MECH(). If check_mail returns an error then the RCPT TO command will be rejected with that error. If it returns some other result starting with $# then check_relay will be skipped. If the sender address (or a part of it) is listed in the access map and it has a RHS of OK or RELAY, then check_relay will be skipped.
This has an interesting side effect: if your domain is my.domain and you have


 >>

Apr 16 00:22:08 ftp sendmail[28461]: STARTTLS=server, relay=[21.23.10.25], version=TLSv1/SSLv3, verify=NO, cipher=RC4-MD5, bits=128/128
Apr 16 00:22:11 ftp dovecot: imap-login: Login: user=, method=PLAIN, rip=21.23.10.25, lip=88.88.18.18, mpid=28463, TLS
Apr 16 00:22:17 ftp sendmail[28461]: AUTH=server, relay=[
21.23.10.25], authid=depit, mech=LOGIN, bits=0
Apr 16 00:22:23 ftp sendmail[28461]: p3FLM5Od028461: from=, size=580, class=0, nrcpts=1, msgid=<201104152122.p3FLM5Od028461@tp.angram.com>, proto=ESMTP, daemon=MTA, relay=[
21.23.10.25]
Apr 16 00:22:30 ftp dovecot: imap(depit): Disconnected: Logged out bytes=9/331
Apr 16 00:22:32 ftp dovecot: imap(depit): Disconnected: Logged out bytes=880/2104
Apr 16 00:23:15 ftp sendmail[28466]: p3FLM5Od028461: to=, ctladdr= (500/500), delay=00:00:55, xdelay=00:00:52, mailer=esmtp, pri=120580, relay=ate.ontebanato.com. [21.10.19.17], dsn=2.0.0, stat=Sent (p3FL32t3031751 Message accepted for delivery)



Sendmail-SMTP-AUTH-TLS-Howto

Sendmail SMTP AUTH Quick Start

 

Using SMTP AUTH and STARTTLS with sendmail


1. We need the following software: openssl, cyrus-sasl2, and sendmail.

2. Create Certificates for TLS
mkdir -p /etc/mail/certs
cd /etc/mail/certs
openssl req -new -x509 -keyout cakey.pem -out cacert.pem -days 365

<- Enter your password for smtpd.key.
<- Enter your Country Name (e.g., "DE").
<- Enter your State or Province Name.
<- Enter your City.
<- Enter your Organization Name (e.g., the name of your company).
<- Enter your Organizational Unit Name (e.g. "IT Department").
<- Enter the Fully Qualified Domain Name of the system (e.g. "server1.example.com").
<- Enter your Email Address.

openssl req -nodes -new -x509 -keyout sendmail.pem -out sendmail.pem -days 365
<- Again, enter your password for smtpd.key.
<- Enter your Country Name (e.g., "DE").
<- Enter your State or Province Name.
<- Enter your City.
<- Enter your Organization Name (e.g., the name of your company).
<- Enter your Organizational Unit Name (e.g. "IT Department").
<- Enter the Fully Qualified Domain Name of the system (e.g. "server1.example.com").
<- Enter your Email Address.

openssl x509 -noout -text -in sendmail.pem
chmod 600 ./sendmail.pem

Create the file sendmail.mc with the following contents:

dnl ### do SMTPAUTH
define(`confAUTH_MECHANISMS', `LOGIN PLAIN DIGEST-MD5 CRAM-MD5')dnl
TRUST_AUTH_MECH(`LOGIN PLAIN DIGEST-MD5 CRAM-MD5')dnl

dnl ### do STARTTLS
define(`confCACERT_PATH', `/etc/mail/certs')dnl
define(`confCACERT', `/etc/mail/certs/cacert.pem')dnl
define(`confSERVER_CERT', `/etc/mail/certs/sendmail.pem')dnl
define(`confSERVER_KEY', `/etc/mail/certs/sendmail.pem')dnl
define(`confCLIENT_CERT', `/etc/mail/certs/sendmail.pem')dnl
define(`confCLIENT_KEY', `/etc/mail/certs/sendmail.pem')dnl
DAEMON_OPTIONS(`Family=inet, Port=465, Name=MTA-SSL, M=s')dnl


Then start saslauthd and sendmail:
/etc/init.d/saslauthd start
/etc/init.d/sendmail start


 Test your Configuration
To verify that your sendmail was compiled with the right options type
/usr/sbin/sendmail -d0.1 -bv root
You should see that sendmail was compiled with SASLv2 and STARTTLS:


To see if SMTP-AUTH and TLS work properly now run the following command:
telnet localhost 25
After you have established the connection to your sendmail mail server type
ehlo localhost
If you see the lines
250-STARTTLS
and
250-AUTH
everything is fine.

Type
quit
to return to the system's shell.

 <<
SMTP AUTH allows users to supply a login and password to a server in order to relay mail to other locations. Until recently, relaying was largely controlled by restricting access to trusted IP addresses or networks. This has turned into an administrative nightmare, however, due to the wide adoption of dynamically allocated IP addresses and the demands of roaming users. It makes more sense to control relaying at the user level, regardless of the host or its location on the Internet, but care must be taken to protect passwords from being sent in the clear. >>


chkconfig saslauthd on
service saslauthd restart


You now have SMTP AUTH with encrypted logins!
Verbose mode In order to provide encrypted logins, you must use a version of sendmail that was compiled to use SASL and STARTTLS. 


The confAUTH_OPTIONS macro allows you to instruct sendmail not to offer plain text authentication until after a secure mechanism such as TLS is active (the p option). We are also prohibiting anonymous logins (the y option). The A option is a workaround for broken MTAs:
define(`confAUTH_OPTIONS’, `A p y’)dnl
Now we define which authentication mechanisms we will trust and use:
TRUST_AUTH_MECH(`LOGIN PLAIN’)dnl
define(`confAUTH_MECHANISMS’, `LOGIN PLAIN’)dnl
Next, we tell sendmail where to find the certificates:
define(`confCACERT_PATH’,`/usr/share/ssl/certs’)
define(`confCACERT’,`/usr/share/ssl/certs/ca-bundle.crt’)
define(`confSERVER_CERT’,`/usr/share/ssl/certs/sendmail.pem’)
define(`confSERVER_KEY’,`/usr/share/ssl/certs/sendmail.pem’)
And finally, it may be useful to increase the log level for debugging purposes (delete or comment out this line after everything is working properly):
define(`confLOG_LEVEL’, `14′)dnl