sieve icon indicating copy to clipboard operation
sieve copied to clipboard

Dovecot/Pigeonhole SASL EXTERNAL for public-key authentication

Open MarcWeustink opened this issue 9 years ago • 10 comments

Hi I'm trying to get the EXTERNAL authentication to work for dovecot/pigeonhole and I followed the settings as mentioned in issue #53. However it appears that dovecot still expects some response (you can fill in anything) See the "dialog" I entered manually:

...
S:OK "TLS negotiation successful."
C:authenticate "EXTERNAL"
S:""
C:"="
S:OK "Logged in."

or even shorter

...
S:OK "TLS negotiation successful."
C:authenticate "EXTERNAL" "="
S:OK "Logged in."

MarcWeustink avatar Oct 12 '17 16:10 MarcWeustink

Sorry but your bug report does not contain the slightest but of useful information.

You should at least provide which addon version you are using and a complete log from the communication with your server.

Refer to https://github.com/thsmi/sieve/blob/master/CONTRIBUTING.md for more details.

Your examples are also rather strange.

External is defined as https://tools.ietf.org/html/rfc4422#page-29

The mechanism is capable of transferring an authorization identity string. If empty, the client is requesting to act as the identity the server has associated with the client's credentials. If non-empty, the client is requesting to act as the identity represented by the string.

The client is expected to send data first in the authentication exchange. Where the client does not provide an initial response data in its request to initiate the authentication exchange, the server is to respond to the request with an empty initial challenge and then the client is to provide its initial response.

The client sends the initial response containing the UTF-8 encoding of the requested authorization identity string. This response is non-empty when the client is requesting to act as the identity represented by the (non-empty) string. This response is empty when the client is requesting to act as the identity the server associated with its authentication credentials.

The addons sends an AUTHENTICATE "EXTERNAL" "" which means it requests the server to use the client's credentials contained in the certificate.

In you example you request the server to be the identity/user "=" which does not make too much sense.

thsmi avatar Oct 12 '17 22:10 thsmi

oops.... its the first thing I ask from my users (blush). I shouldn't write reports when I want to go home. Thunderbird (win10-64) 52.4.0 (32bit) Sieve 0.2.3k Dovecot (Ubuntu 16.04.3 LTS) 2.2.22-1ubuntu2.4

You're right about RFC4422, it doesn't have the "=". However I mixed this up with RFC4959 which addresses imap. Since dovecot handles both imap and sieve I assumed the same syntax, the authorization module is the same

Anyway, the examples I gave are entered by me when I connect manually the the server and have finished the starttls: gnutls-cli --starttls --x509keyfile marc_mail.key --x509certfile marc_mail.crt -p sieve 172.17.1.4

when I send authenticate "EXTERNAL" "=" I'm logged in

when I send authenticate "EXTERNAL" "" the server responds with "" and I have to send and additional "" before I get logged in.

When using the plugin, I get the message in TB : The connection has timed out, the Server is not responding... My assumption here was that the server still waits for the second ""

Usually when I debug communication problems, I use wireshark/tcpdump to see what is going over the line. With an encrypted connection this makes no sense, so I didn't make one. In that case I'm completely dependent on what clients/servers provide to debug communication.

what I see in the server logs when the sieve plugin connects is Oct 13 10:27:00 sidonia dovecot: auth: Debug: auth client connected (pid=14488) Oct 13 10:27:00 sidonia dovecot: auth: Debug: client in: AUTH#0111#011EXTERNAL#011service=sieve#011secured#011valid-client-cert#011session=VJ+4a2lbej/AqGQT#011cert_username=marc#011lip=172.17.1.4#011rip=192.168.100.19#011lport=4190#011rport=16250 Oct 13 10:27:00 sidonia dovecot: auth: Debug: client passdb out: CONT#0111 Oct 13 10:27:20 sidonia dovecot: managesieve-login: Authenticate EXTERNAL failed: Invalid AUTHENTICATE client response.: user=<>, method=EXTERNAL, rip=192.168.100.19, lip=172.17.1.4, TLS, session=<VJ+4a2lbej/AqGQT> Oct 13 10:27:20 sidonia dovecot: auth: Debug: client in: CANCEL#0111

when I connect manually and send only authenticate "EXTERNAL" "" : Oct 13 10:29:05 sidonia dovecot: auth: Debug: auth client connected (pid=14516) Oct 13 10:29:29 sidonia dovecot: auth: Debug: client in: AUTH#0111#011EXTERNAL#011service=sieve#011secured#011valid-client-cert#011session=e6qWdGlbiD/AqGQT#011cert_username=marc#011lip=172.17.1.4#011rip=192.168.100.19#011lport=4190#011rport=16264 Oct 13 10:29:29 sidonia dovecot: auth: Debug: client passdb out: CONT#0111

so this part is he same as when the plugin connects. When I send the second "", the log continues: Oct 13 10:29:41 sidonia dovecot: auth: Debug: client in: CONT#0111#011 (previous base64 data may contain sensitive data) Oct 13 10:29:41 sidonia dovecot: auth: Debug: sql(marc,192.168.100.19,<e6qWdGlbiD/AqGQT>): query: SELECT 'marc' AS user, '' AS password, 'Y' AS nopassword WHERE verify_username('marc') Oct 13 10:29:41 sidonia dovecot: auth: Debug: client passdb out: OK#0111#011user=marc#011#011original_user= Oct 13 10:29:41 sidonia dovecot: managesieve-login: Login: user=<marc>, method=EXTERNAL, rip=192.168.100.19, lip=172.17.1.4, mpid=14520, TLS, session=<e6qWdGlbiD/AqGQT>

This concludes me that the server is waiting for an additional ""

Marc

MarcWeustink avatar Oct 13 '17 08:10 MarcWeustink

Concerning your issue I digged a bit deeper and it starts getting interesting...

...the rfc5804 which is about the manage sieve protocol defines the following:

The authentication protocol exchange consists of a series of server
challenges and client responses that are specific to the selected
authentication mechanism.  A server challenge consists of a string
(quoted or literal) followed by a CRLF.  The contents of the string
is a base-64 encoding [BASE64] of the SASL data.  A client response
consists of a string (quoted or literal) with the base-64 encoding of
the SASL data followed by a CRLF.

So the string needs to be base 64 encoded. To be honest I was not aware of that. So far so good. Then I looked up the RFC for base64 https://tools.ietf.org/html/rfc4648#section-10 because I was unsure how an empty string is encoded in base64.

The RFC states that an empty base64 string is equivalent to an empty string.

  BASE64("") = ""

To make things worse a base64 string which is made of a single "=" is by definition invalid.

If we look closer at your example

authenticate "EXTERNAL" "="

it is getting really strange, because yous server accepts a completely broken request. The string is by definition invalid and technically not decodable. The server has to respond to such a string with a "NO" or "BYE". Which leads to the conclusion you server's implementation is completely screwed up.

Please validate my observation, but it currently seems to me as if you need to file a bug against your server.

Beside that I definitely missed the part about the authorization identity. Which basically allows a proxy authentication. I'll add this to the extension.

Just for curiosity, can you check your sieve server's capabilities? RFC4959 defines a capability named SASL-IR. An it would be interesting if and how it is advertised.

thsmi avatar Oct 13 '17 22:10 thsmi

I agree the server shouldn't have accepted the authenticate "EXTERNAL" "=" since this is a IMAP extention. However reading https://wiki.tools.ietf.org/html/rfc4422#page-29 I think the server response of authenticate "EXTERNAL" "" is correct (when you see the "" as 'Where the client does not provide an initial response data')

about RFC4959, I see no trace of SASL-IR: capability "IMPLEMENTATION" "Dovecot Pigeonhole" "SIEVE" "fileinto reject envelope encoded-character vacation subaddress comparator-i;ascii-numeric relational regex imap4flags copy include variables body enotify environment mailbox date index ihave duplicate mime foreverypart extracttext" "NOTIFY" "mailto" "SASL" "EXTERNAL PLAIN" "VERSION" "1.0" OK "Capability completed."

MarcWeustink avatar Oct 16 '17 09:10 MarcWeustink

I was wondering about the same. But RFC5804 adds a bit clarification what empty means:

  Note that an empty challenge/response is sent as an empty string.  

Which makes RFC4422 more meaningful:

The mechanism is capable of transferring an authorization identity
string.  If empty, the client is requesting to act as the identity
the server has associated with the client's credentials.  If non-
empty, the client is requesting to act as the identity represented by
the string.

The optional initial-response argument to the AUTHENTICATE command is
used to save a round trip when using authentication mechanisms that
are defined to send no data in the initial challenge.  When the
initial-response argument is used with such a mechanism, the initial
empty challenge is not sent to the client and the server uses the
data in the initial-response argument as if it were sent in response
to the empty challenge. 

So "" reads as "provides an empty initial response". And if a response is provided (empty or not) the server is not allowed to not send the initial empty challenge...

Which lead to the conclusion the server behaves badly and the response you have seen should not have happened.

thsmi avatar Oct 16 '17 18:10 thsmi

I finally found the time today to install the latest release 2.2.33.1-1 (I usually try to stick to the distro version). It didn't make a difference. I'll report this the the dovecot team.

MarcWeustink avatar Oct 23 '17 11:10 MarcWeustink

Beside that I definitely missed the part about the authorization identity. Which basically allows a proxy authentication. I'll add this to the extension.

BTW any timeframe on this (days, months, years) ? I just thought it might help me work around the server bug.

MarcWeustink avatar Oct 30 '17 11:10 MarcWeustink

OK, I managed to hack a workaround in the server sources, so the plugin works now.

Thanks

MarcWeustink avatar Nov 01 '17 14:11 MarcWeustink

FYI Fixed in dovecot 2.3

MarcWeustink avatar Dec 28 '17 14:12 MarcWeustink

Thank you for the information

thsmi avatar Dec 29 '17 17:12 thsmi