Forum Discussion
SMTP STARTTLS iRule
I need help with getting a STARTTLS iRule working for SMTP on our 1600's. We are on version 10.2.1. And to be clear it is working but there are a few tweaks I can't figure out. The main issue is that when I telnet to the VIP I can't do an SMTP conversation. It throws "530 Must issue a STARTTLS command first". If I fire up Outlook Express I am able to use port 25/TLS just fine and the smtp.log with Outlook Express shows a normal conversation. How to get the conversation to work? Here is the code:
when CLIENT_ACCEPTED {
SSL::disable
}
when SERVER_CONNECTED {
TCP::collect
}
when CLIENT_DATA {
set lcpayload [string tolower [TCP::payload]]
if { $lcpayload starts_with "ehlo" } {
TCP::respond "250-STARTTLS\r\n250 OK\r\n"
TCP::payload replace 0 [TCP::payload length] ""
TCP::release
TCP::collect
} elseif { $lcpayload starts_with "starttls" } {
TCP::respond "220 Ready to start TLS\r\n"
TCP::payload replace 0 [TCP::payload length] ""
TCP::release
SSL::enable
} else {
TCP::respond "530 Must issue a STARTTLS command first\r\n"
TCP::payload replace 0 [TCP::payload length] ""
TCP::release
TCP::collect
}
}
when SERVER_DATA {
TCP::release
clientside { TCP::collect }
}
- DamionCirrusWhat about something more along this:
- kraigk_52257Nimbostratus
- Nat_ThirasuttakornEmployeeI think we are getting closer. üôÇ
set response "250-mail.company.com Hello\r\n\" append response "250-PIPELINING\r\n" append response "250-DNS\r\n" append response "250-ENHANCEDSTATUSCODES\r\n" append response "250-AUTH GSSAPI NTLM LOGIN\r\n" append response "250-8BITMIME\r\n" append response "250-BINARYMIME\r\n" append response "250-CHUNKING\r\n" append response "250 STARTTLS\r\n" TCP::respond $response
- DamionCirrusBut the server will respond with the default responses, I think the issue was not specifying the serverside or client side in the opposite respective when clauses. What about the following:
- kraigk_52257NimbostratusDamion,
- Nat_ThirasuttakornEmployeetry this. I did a quick test with thunderbird...
when CLIENT_ACCEPTED { set ehlo 0 SSL::disable } when SERVER_CONNECTED { TCP::collect } when CLIENT_DATA { set lcpayload [string tolower [TCP::payload]] if { $lcpayload starts_with "ehlo" } { set ehlo 1 serverside { TCP::collect } TCP::release TCP::collect } elseif { $lcpayload starts_with "starttls" } { TCP::respond "220 Ready to start TLS\r\n" TCP::payload replace 0 [TCP::payload length] "" TCP::release SSL::enable } else { TCP::release } } when SERVER_DATA { if { $ehlo == 1 and not([string tolower [TCP::payload]] contains "starttls") } { TCP::payload replace 0 0 "250-STARTTLS\r\n" } TCP::release clientside { TCP::collect } }
- kraigk_52257NimbostratusWell I'll be damned. You did it Nat. Both SSL and clear text work. And I can telnet in for a lovely SMTP conversation. You guys are the best. Your code worked as it stands, no changes. This should be put in the codeshare, would no doubt be useful to others.
- Colin_Walker_12Historic F5 AccountAsk and ye shall receive. CodeShare entry created:
- kraigk_52257Nimbostratus
- Colin_Walker_12Historic F5 AccountSure thing, thanks for the awesome feedback to help get this one wrapped up. I love forum threads like this.
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com