Skip to content
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

SmtpClient NTLM and Kerberos testing #19436

Open
CIPop opened this issue Nov 21, 2016 · 10 comments
Open

SmtpClient NTLM and Kerberos testing #19436

CIPop opened this issue Nov 21, 2016 · 10 comments
Labels
area-System.Net test-enhancement Improvements of test source code
Milestone

Comments

@CIPop
Copy link
Member

CIPop commented Nov 21, 2016

Per offline SCRUM discussion: add e2e NTLM/Kerberos testing for SmtpClient authentication.
Example:
https://github.com/dotnet/corefx/blob/master/src/System.Net.Security/tests/FunctionalTests/NegotiateStreamKerberosTest.cs

/cc: @karelz @Priya91

@CIPop
Copy link
Member Author

CIPop commented Mar 22, 2017

Testing this would require Nego infrastructure (Active Directory, a SMTP server that understands NTLM/Kerberos, etc).

@karelz
Copy link
Member

karelz commented Oct 2, 2019

Triage: This will likely fall out of @davidsh's enterprise scenarios testing effort which is under way.

@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the Future milestone Jan 31, 2020
@filipnavara
Copy link
Member

filipnavara commented Jun 22, 2022

In the prototype branch for issue #70909 I added a test that runs against the fake Negotiate / NTLM server inside the loopback server. Obviously that's not going to cover Kerberos but it seems like an easiest path to get some coverage for the authentication code paths.

@filipnavara
Copy link
Member

@jborean93 created a proof-of-concept for testing against custom local KDC much like we already do on Linux/macOS - https://github.com/jborean93/LocalKdc. Unlike the Unix-based system it needs admin access to run but that's still way better than needing separate infrastructure or restarting the machine.

Do we have some outerloop test infrastructure that is run with admin rights? I am looking for some prior art.

Even if we can make this working only for local testing it would be a huge improvement.

/cc @wfurt

@filipnavara
Copy link
Member

Turns out, with fixed realm and 4 DNS records I can make this work as non-admin too: https://github.com/filipnavara/LocalKdc/pull/new/filipnavara-dev

I setup the following DNS records to point to localhost:

dc01                     	3600	IN A    	127.0.0.1
_kerberos._tcp           	3600	IN SRV  	1 1 88 dc01.filipnavara.dev.
_kerberos._tcp.dc._msdcs 	3600	IN SRV  	1 1 88 dc01.filipnavara.dev.
_ldap._tcp.dc._msdcs     	3600	IN SRV  	1 1 389 dc01.filipnavara.dev.

@jborean93
Copy link
Contributor

@SteveSyfuhs I know this is a long shot but is there any way at all to replicate how a domain joined computer account gets its ticket for authentication? I’m hoping there is so we can test out the acceptor/inbound context through SSPI with something like the local KDC setup. I know there is an auth package to list/purge tickets as exposed through klist.exe but that seems to be about it.

@jborean93
Copy link
Contributor

jborean93 commented Jul 31, 2024

Looks like it is possible with an undocumented credential type SEC_WINNT_AUTH_DATA_TYPE_KEYTAB. I've created a test that follows the workflow of https://github.com/SteveSyfuhs/DelegatedAuthentication/blob/1b099b53bf1b966b364ceab0245f658ae8e641bb/src/Shared/KeytabCredential.cs. The acceptor can use the keytab bytes as the packed credential data and is able to process the output token from the initiator.

Definitely not documented but it could be worthwhile for testing purposes.

Also credit to James Forshaw for pointing out that example from Steve’s delegation repo.

@SteveSyfuhs
Copy link

..._KEYTAB is a supported mechanism but it's actually not how Windows does machine accounts. Machine accounts are functionally just normal user accounts that call LsaLogonUser. We have a supported mechanism to configure that using ksetup.exe /setcomputerpassword: https://github.com/MicrosoftDocs/windowsserverdocs/blob/main/WindowsServerDocs/administration/windows-commands/ksetup.md

@jborean93
Copy link
Contributor

jborean93 commented Jul 31, 2024

..._KEYTAB is a supported mechanism but it's actually not how Windows does machine accounts

Is is possible to have this documented officially, would love to use it officially in some of my libraries that call SSPI.

We have a supported mechanism to configure that using ksetup.exe /setcomputerpassword:

Thanks for the info. Does that mean theoretically I could just provide in the SEC_WINNT_AUTH_IDENTITY_W with the service's SPN and password to use as an inbound credential for AcceptSecurityContext? In this case I'm looking into ways to test out the acceptor scenario without necessarily be running as SYSTEM/machine account. The keytab method works but is a bit more complex than just providing the password which I'm generating manually in the test KDC.

Edit: Just tested that and it does not work, the AcceptSecurityContext call fails with SEC_E_NO_CREDENTIALS. Must be some step missing in the SSPI calls that Windows does for a computer account on logon to work with this scenario. I'll continue to use the keytab setup for my testing.

@SteveSyfuhs
Copy link

You will also have to disable PAC validation since your KDC doesn't have a netlogon endpoint. You will have to run as SYSTEM still though.

Ultimately your approach works fine and it might be less hassle in the long run since you don't have to deal with key normalization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Net test-enhancement Improvements of test source code
Projects
None yet
Development

No branches or pull requests

6 participants