| 1 |
# |
| 2 |
# read this with 'perldoc authentication.pod' ... |
| 3 |
# |
| 4 |
|
| 5 |
=head1 NAME |
| 6 |
|
| 7 |
Authentication framework for qpsmtpd |
| 8 |
|
| 9 |
=head1 DESCRIPTION |
| 10 |
|
| 11 |
Provides support for SMTP AUTH within qpsmtpd transactions, see |
| 12 |
|
| 13 |
L<http://www.faqs.org/rfcs/rfc2222.html> |
| 14 |
L<http://www.faqs.org/rfcs/rfc2554.html> |
| 15 |
|
| 16 |
for more details. |
| 17 |
|
| 18 |
=head1 USAGE |
| 19 |
|
| 20 |
This code is automatically loaded by Qpsmtpd::SMTP only if a plugin |
| 21 |
providing one of the defined L<Auth Hooks> is loaded. The only |
| 22 |
time this can happen is if the client process employs the EHLO command to |
| 23 |
initiate the SMTP session. If the client uses HELO, the AUTH command is |
| 24 |
not available and this module isn't even loaded. |
| 25 |
|
| 26 |
=head2 Plugin Design |
| 27 |
|
| 28 |
An authentication plugin can bind to one or more auth hooks or bind to all |
| 29 |
of them at once. See L<Multiple Hook Behavior> for more details. |
| 30 |
|
| 31 |
All plugins must provide two functions: |
| 32 |
|
| 33 |
=over 4 |
| 34 |
|
| 35 |
=item * init() |
| 36 |
|
| 37 |
This is the standard function which is called by qpsmtpd for any plugin |
| 38 |
listed in config/plugins. Typically, an auth plugin should register at |
| 39 |
least one hook, like this: |
| 40 |
|
| 41 |
|
| 42 |
sub init { |
| 43 |
my ($self, $qp) = @_; |
| 44 |
|
| 45 |
$self->register_hook("auth", "authfunction"); |
| 46 |
} |
| 47 |
|
| 48 |
where in this case "auth" means this plugin expects to support any of |
| 49 |
the defined authentication methods. |
| 50 |
|
| 51 |
=item * authfunction() |
| 52 |
|
| 53 |
The plugin must provide an authentication function which is part of |
| 54 |
the register_hook call. That function will receive the following |
| 55 |
six parameters when called: |
| 56 |
|
| 57 |
=over 4 |
| 58 |
|
| 59 |
=item $self |
| 60 |
|
| 61 |
A Qpsmtpd::Plugin object, which can be used, for example, to emit log |
| 62 |
entries or to send responses to the remote SMTP client. |
| 63 |
|
| 64 |
=item $transaction |
| 65 |
|
| 66 |
A Qpsmtpd::Transaction object which can be used to examine information |
| 67 |
about the current SMTP session like the remote IP address. |
| 68 |
|
| 69 |
=item $mechanism |
| 70 |
|
| 71 |
The lower-case name of the authentication mechanism requested by the |
| 72 |
client; either "plain", "login", or "cram-md5". |
| 73 |
|
| 74 |
=item $user |
| 75 |
|
| 76 |
Whatever the remote SMTP client sent to identify the user (may be bare |
| 77 |
name or fully qualified e-mail address). |
| 78 |
|
| 79 |
=item $clearPassword |
| 80 |
|
| 81 |
If the particular authentication method supports unencrypted passwords |
| 82 |
(currently PLAIN and LOGIN), which will be the plaintext password sent |
| 83 |
by the remote SMTP client. |
| 84 |
|
| 85 |
=item $hashPassword |
| 86 |
|
| 87 |
An encrypted form of the remote user's password, using the MD-5 algorithm |
| 88 |
(see also the $ticket parameter). |
| 89 |
|
| 90 |
=item $ticket |
| 91 |
|
| 92 |
This is the cryptographic challenge which was sent to the client as part |
| 93 |
of a CRAM-MD5 transaction. Since the MD-5 algorithm is one-way, the same |
| 94 |
$ticket value must be used on the backend to compare with the encrypted |
| 95 |
password sent in $hashPassword. |
| 96 |
|
| 97 |
=back |
| 98 |
|
| 99 |
=back |
| 100 |
|
| 101 |
Plugins should perform whatever checking they want and then return one |
| 102 |
of the following values (taken from Qpsmtpd::Constants): |
| 103 |
|
| 104 |
=over 4 |
| 105 |
|
| 106 |
=item OK |
| 107 |
|
| 108 |
If the authentication has succeeded, the plugin can return this value and |
| 109 |
all subsequently registered hooks will be skipped. |
| 110 |
|
| 111 |
=item DECLINED |
| 112 |
|
| 113 |
If the authentication has failed, but any additional plugins should be run, |
| 114 |
this value will be returned. If none of the registered plugins succeed, the |
| 115 |
overall authentication will fail. Normally an auth plugin should return |
| 116 |
this value for all cases which do not succeed (so that another auth plugin |
| 117 |
can have a chance to authenticate the user). |
| 118 |
|
| 119 |
=item DENY |
| 120 |
|
| 121 |
If the authentication has failed, and the plugin wishes this to short circuit |
| 122 |
any further testing, it should return this value. For example, a plugin could |
| 123 |
register the L<auth-plain> hook and immediately fail any connection which is |
| 124 |
not trusted (e.g. not in the same network). |
| 125 |
|
| 126 |
Another reason to return DENY over DECLINED would be if the user name matched |
| 127 |
an existing account but the password failed to match. This would make a |
| 128 |
dictionary-based attack much harder to accomplish. See the included |
| 129 |
auth_vpopmail_sql plugin for how this might be accomplished. |
| 130 |
|
| 131 |
By returning DENY, no further authentication attempts will be made using the |
| 132 |
current method and data. A remote SMTP client is free to attempt a second |
| 133 |
auth method if the first one fails. |
| 134 |
|
| 135 |
=back |
| 136 |
|
| 137 |
Plugins may also return an optional message with the return code, e.g. |
| 138 |
|
| 139 |
return (DENY, "If you forgot your password, contact your admin"); |
| 140 |
|
| 141 |
and this will be appended to whatever response is sent to the remote SMTP |
| 142 |
client. There is no guarantee that the end user will see this information, |
| 143 |
though, since some prominent MTA's (produced by M$oft) I<helpfully> |
| 144 |
hide this information under the default configuration. This message will |
| 145 |
be logged locally, if appropriate, based on the configured log level. |
| 146 |
|
| 147 |
=head1 Auth Hooks |
| 148 |
|
| 149 |
The currently defined authentication methods are: |
| 150 |
|
| 151 |
=over 4 |
| 152 |
|
| 153 |
=item * auth-plain |
| 154 |
|
| 155 |
Any plugin which registers an auth-plain hook will engage in a plaintext |
| 156 |
prompted negotiation. This is the least secure authentication method since |
| 157 |
both the user name and password are visible in plaintext. Most SMTP clients |
| 158 |
will preferentially choose a more secure method if it is advertised by the |
| 159 |
server. |
| 160 |
|
| 161 |
=item * auth-login |
| 162 |
|
| 163 |
A slightly more secure method where the username and password are Base-64 |
| 164 |
encoded before sending. This is still an insecure method, since it is |
| 165 |
trivial to decode the Base-64 data. Again, it will not normally be chosen |
| 166 |
by SMTP clients unless a more secure method is not available (or if it fails). |
| 167 |
|
| 168 |
=item * auth-cram-md5 |
| 169 |
|
| 170 |
A cryptographically secure authentication method which employs a one-way |
| 171 |
hashing function to transmit the secret information without significant |
| 172 |
risk between the client and server. The server provides a challenge key |
| 173 |
L<$ticket>, which the client uses to encrypt the user's password. |
| 174 |
Then both user name and password are concatenated and Base-64 encoded before |
| 175 |
transmission. |
| 176 |
|
| 177 |
This hook must normally have access to the user's plaintext password, |
| 178 |
since there is no way to extract that information from the transmitted data. |
| 179 |
Since the CRAM-MD5 scheme requires that the server send the challenge |
| 180 |
L<$ticket> before knowing what user is attempting to log in, there is no way |
| 181 |
to use any existing MD5-encrypted password (like is frequently used with MySQL). |
| 182 |
|
| 183 |
=item * auth |
| 184 |
|
| 185 |
A catch-all hook which requires that the plugin support all three preceeding |
| 186 |
authentication methods. Any plugins registering the auth hook will be run |
| 187 |
only after all other plugins registered for the specific authentication |
| 188 |
method which was requested. This allows you to move from more specific |
| 189 |
plugins to more general plugins (e.g. local accounts first vs replicated |
| 190 |
accounts with expensive network access later). |
| 191 |
|
| 192 |
=back |
| 193 |
|
| 194 |
=head2 Multiple Hook Behavior |
| 195 |
|
| 196 |
If more than one hook is registered for a given authentication method, then |
| 197 |
they will be tried in the order that they appear in the config/plugins file |
| 198 |
unless one of the plugins returns DENY, which will immediately cease all |
| 199 |
authentication attempts for this transaction. |
| 200 |
|
| 201 |
In addition, all plugins that are registered for a specific auth hook will |
| 202 |
be tried before any plugins which are registered for the general auth hook. |
| 203 |
|
| 204 |
=head1 VPOPMAIL |
| 205 |
|
| 206 |
There are 4 authentication (smtp-auth) plugins that can be used with |
| 207 |
vpopmail. |
| 208 |
|
| 209 |
=over 4 |
| 210 |
|
| 211 |
=item auth_vpopmaild |
| 212 |
|
| 213 |
If you aren't sure which one to use, then use auth_vpopmaild. It |
| 214 |
supports the PLAIN and LOGIN authentication methods, |
| 215 |
doesn't require the qpsmtpd process to run with special permissions, and |
| 216 |
can authenticate against vpopmail running on another host. It does require |
| 217 |
the vpopmaild server to be running. |
| 218 |
|
| 219 |
=item auth_vpopmail |
| 220 |
|
| 221 |
The next best solution is auth_vpopmail. It requires the p5-vpopmail perl |
| 222 |
module and it compiles against libvpopmail.a. There are two catches. The |
| 223 |
qpsmtpd daemon must run as the vpopmail user, and you must be running v0.09 |
| 224 |
or higher for CRAM-MD5 support. The released version is 0.08 but my |
| 225 |
CRAM-MD5 patch has been added to the developers repo: |
| 226 |
http://github.com/sscanlon/vpopmail |
| 227 |
|
| 228 |
=item auth_vpopmail_sql |
| 229 |
|
| 230 |
If you are using the MySQL backend for vpopmail, then this module can be |
| 231 |
used for smtp-auth. It supports LOGIN, PLAIN, and CRAM-MD5. However, it |
| 232 |
does not work with some vpopmail features such as alias domains, service |
| 233 |
restrictions, nor does it update vpopmail's last_auth information. |
| 234 |
|
| 235 |
=item auth_checkpassword |
| 236 |
|
| 237 |
The auth_checkpassword is a generic authentication module that will work |
| 238 |
with any DJB style checkpassword program, including ~vpopmail/bin/vchkpw. |
| 239 |
It only supports PLAIN and LOGIN auth methods. |
| 240 |
|
| 241 |
=back |
| 242 |
|
| 243 |
=head1 AUTHOR |
| 244 |
|
| 245 |
John Peacock <[email protected]> |
| 246 |
|
| 247 |
Matt Simerson <[email protected]> (added VPOPMAIL) |
| 248 |
|
| 249 |
=head1 COPYRIGHT AND LICENSE |
| 250 |
|
| 251 |
Copyright (c) 2004-2006 John Peacock |
| 252 |
|
| 253 |
Portions based on original code by Ask Bjoern Hansen and Guillaume Filion |
| 254 |
|
| 255 |
This plugin is licensed under the same terms as the qpsmtpd package itself. |
| 256 |
Please see the LICENSE file included with qpsmtpd for details. |
| 257 |
|
| 258 |
=cut |