-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
System.DirectoryServices.Protocols.LdapConnection with SessionOptions.StartTransportLayerSecurity() sends credentials in clear text on Linux #54274
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
[Triage] Let's try to fix this in this release |
I think this has changed a little bit on First, The second is more complex. OpenLDAP's Here are a couple of options:
I have a local commit that implements the first one, but it needs to be cleaned up, and I don't know how to write an automated test for it. (I've tested manually, and viewed the output in Wireshark to confirm that it works.) We can't just pass if it binds successfully with that option set, since the credentials would still fall through to the server. Maybe there's a way to restrict an LDAP server only to use StartTLS and not plain text, or to attempt to bind to a random TCP socket and detect whether the StartTLS operation was sent to it? |
@emnlz Can you elaborate on this? I confirmed that the StartTLS issue present in .NET 5. A reproduction program is below. I think what's happening is that if using System;
using System.Net;
using System.Text;
using System.IO;
using System.DirectoryServices.Protocols;
var identifier = new LdapDirectoryIdentifier("ldap.local", 1389);
var cred = new NetworkCredential("cn=admin,dc=example,dc=org", "password");
using var conn = new LdapConnection(identifier, cred);
conn.SessionOptions.ProtocolVersion = 3;
var controls = new DirectoryControlCollection
{
new DirectoryControl("7.8.9", Encoding.ASCII.GetBytes("this should show up in initial request"), false, true),
};
conn.SessionOptions.StartTransportLayerSecurity(controls);
conn.Bind(); Program throws an exception on
Server logs:
Packet capture is attached. On frame 20, the credentials are sent in cleartext after doing a TLS handshake. If I change the Tested with Docker container
I think the other issue that I experienced above is due to the way binding changed in .NET 6, so I'll open a separate issue for that. |
@iinuwa If I add an explicit AuthType before Bind, whatever value I use, it produces the same packets sequence resulting in a basic authentication (i.e. cleartext password). The following code results in a STARTTLS + SASL authentication on Windows, and no TLS + basic authentication on Linux:
|
Does the same AuthType issue occur without using StartTLS? If so, I think creating a separate issue would be helpful to track the two. Does setting the protocol version to 3 change anything (OpenLDAP defaults to version 2)? And have you checked out this comment? I haven't looked into the details; it looks like they're using a keytab rather than an explicit username and password like you are. I don't know if that makes a difference. Re: StartTLS, do you think that the theory about certificate trust affecting StartTLS is valid? |
Yes the AuthType issue seems to be unrelated to the StartTLS issue. If I remove the StartTLS, any AuthType results in a successful basic authentication on Linux. |
Description
The following code snippet opens an LdapConnection, requires TLS encryption and then binds with credentials of an existing account.
The code works on both Windows and Linux, however, using a network packet sniffer shows that, when run under linux, StartTLS is ignored and credentials are sent over the network in clear text.
Moreover, the AuthType property seems to be ignored on Linux. Any value results in Basic authentication.
Code
The observed behavior is that encryption and authentication requirements are silently ignored on Linux.
The expected behavior is that unavailable security requirements always throw an exception and never silently fall back into a less secure scheme.
Configuration
.Net 5.0
Windows 10 and Debian 10.9 (docker mcr.microsoft.com/dotnet/runtime:5.0)
The text was updated successfully, but these errors were encountered: