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

Add support for LDAPTLS_CACERTDIR \ TrustedCertificateDirectory #111877

Merged
merged 6 commits into from
Feb 5, 2025

Conversation

steveharter
Copy link
Member

@steveharter steveharter commented Jan 27, 2025

Fixes #104260

Note that the two new members here throw PlatformNotSupportedException in the appropriate non-Linux cases. However, this was not carried forward to the many other pre-existing members that only run on Linux or non-Linux. Assuming we want to do this, I will create an issue to tract that work but do not plan to address that work in this PR. We could also remove the support for PlatformNotSupportedException for now in this PR.

Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

1 similar comment
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@steveharter steveharter changed the title Add support for setting CertificateDirectory Add support for LDAPTLS_CACERTDIR \ TrustedCertificateDirectory Jan 28, 2025
@steveharter steveharter added the os-linux Linux OS (any supported distro) label Jan 28, 2025
Copy link
Member

@ericstj ericstj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just had a couple questions about testing / input validation.

Comment on lines 385 to 388
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are redundant, the assembly has <UnsupportedOSPlatforms>browser;android;ios;tvos</UnsupportedOSPlatforms> attribute
https://github.com/dotnet/runtime/blob/f552567173b706812d11579f8059a14a748dab81/src/libraries/System.DirectoryServices.Protocols/Directory.Build.props#L6C1-L6C78

Suggested change
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Buyaa! Removed those.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed from source but not from ref

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again - done.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still seeing these, @steveharter. I think we can omit the attributes already defined at the assembly level, and just add the one additional windows one here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, for some reason was looking at subset of commits.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming the previously excluded browser;android;ios;tvos were because the browser and mobile platforms don't support LDAP \ DirectoryServices.

[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("windows")]
public void StartNewTlsSessionContext() { }
public bool TcpKeepAlive { get { throw null; } set { } }
public System.DirectoryServices.Protocols.VerifyServerCertificateCallback VerifyServerCertificate { get { throw null; } set { } }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it changed but, we were talking to make VerifyServerCertificate windows only with this change

Suggested change
public System.DirectoryServices.Protocols.VerifyServerCertificateCallback VerifyServerCertificate { get { throw null; } set { } }
[System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
public System.DirectoryServices.Protocols.VerifyServerCertificateCallback VerifyServerCertificate { get { throw null; } set { } }

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Buyaa! I'll put up another PR for that (per this PR's description I elected not to do any of that, but VerifyServerCertificateCallback has caused a lot of pain so I will do that one-off).

@steveharter steveharter requested a review from ericstj February 3, 2025 21:34

set
{
if (!Directory.Exists(value))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know if a relative path is OK to pass to LDAP? Will it resolve in the same way that Directory.Exists does?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it seems to work locally. All other path-based APIs support relative paths AFAIK and both Directory.Exists() and LDAP client are based upon the current working directory of the current application (and LDAP client is in-process).

{
using (var connection = GetConnection(bind: false))
{
Assert.Throws<DirectoryNotFoundException>(() => connection.SessionOptions.TrustedCertificatesDirectory = "nonexistent");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the directory is deleted after our check then user calls StartNewTlsSessionContext, do we care?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't care. We would throw a vague exception like "unable to connect to server" based on the underlying LDAP error code.

Copy link
Member

@ericstj ericstj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just a couple small questions about testing / edge case.

@steveharter steveharter merged commit 53a3e33 into dotnet:main Feb 5, 2025
84 of 86 checks passed
@steveharter steveharter deleted the FixIssue-104260 branch February 5, 2025 21:29
grendello added a commit to grendello/runtime that referenced this pull request Feb 6, 2025
* main: (23 commits)
  add important remarks to NrbfDecoder (dotnet#111286)
  docs: fix spelling grammar and missing words in clr-code-guide.md (dotnet#112222)
  Consider type declaration order in MethodImpls (dotnet#111998)
  Add a feature flag to not use GVM in Linq Select (dotnet#109978)
  [cDAC] Implement ISOSDacInterface::GetMethodDescPtrFromIp (dotnet#110755)
  Restructure JSImport/JSExport generators to share more code and utilize more Microsoft.Interop.SourceGeneration shared code (dotnet#107769)
  Add more detailed explanations to control-flow RegexOpcode values (dotnet#112170)
  Add repo-specific condition to labeling workflows (dotnet#112169)
  Fix bad assembly when a nested exported type is marked via link.xml (dotnet#107945)
  Make `CalculateAssemblyAction` virtual. (dotnet#112154)
  JIT: Enable reusing profile-aware DFS trees between phases (dotnet#112198)
  Add support for LDAPTLS_CACERTDIR \ TrustedCertificateDirectory (dotnet#111877)
  JIT: Support custom `ClassLayout` instances with GC pointers in them (dotnet#112064)
  Factor positive lookaheads better into find optimizations (dotnet#112107)
  Add ImmutableCollectionsMarshal.AsMemory (dotnet#112177)
  [mono] ILStrip write directly to the output filestream (dotnet#112142)
  Allow the NativeAOT runtime pack to be specified as the ILC runtime package (dotnet#111876)
  JIT: some reworking for conditional escape analysis (dotnet#112194)
  Replace HELPER_METHOD_FRAME with DynamicHelperFrame in patchpoints (dotnet#112025)
  [Android] Decouple runtime initialization and entry point execution for Android sample (dotnet#111742)
  ...
@steveharter
Copy link
Member Author

/backport to release/8.0-staging
/backport to release/9.0-staging

Copy link
Contributor

Started backporting to release/8.0-staging: https://github.com/dotnet/runtime/actions/runs/13311570389

Copy link
Contributor

@steveharter backporting to "release/8.0-staging" failed, the patch most likely resulted in conflicts:

$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: Add support for setting CertificateDirectory
Using index info to reconstruct a base tree...
M	src/libraries/Common/src/Interop/Interop.Ldap.cs
M	src/libraries/Common/tests/System/DirectoryServices/LDAP.Configuration.xml
M	src/libraries/System.DirectoryServices.Protocols/ref/System.DirectoryServices.Protocols.cs
M	src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/ldap/LdapConnection.cs
M	src/libraries/System.DirectoryServices.Protocols/tests/DirectoryServicesProtocolsTests.cs
M	src/libraries/System.DirectoryServices.Protocols/tests/DirectoryServicesTestHelpers.cs
Falling back to patching base and 3-way merge...
Auto-merging src/libraries/System.DirectoryServices.Protocols/tests/DirectoryServicesTestHelpers.cs
Auto-merging src/libraries/System.DirectoryServices.Protocols/tests/DirectoryServicesProtocolsTests.cs
CONFLICT (content): Merge conflict in src/libraries/System.DirectoryServices.Protocols/tests/DirectoryServicesProtocolsTests.cs
Auto-merging src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/ldap/LdapConnection.cs
Auto-merging src/libraries/System.DirectoryServices.Protocols/ref/System.DirectoryServices.Protocols.cs
Auto-merging src/libraries/Common/tests/System/DirectoryServices/LDAP.Configuration.xml
CONFLICT (content): Merge conflict in src/libraries/Common/tests/System/DirectoryServices/LDAP.Configuration.xml
Auto-merging src/libraries/Common/src/Interop/Interop.Ldap.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 Add support for setting CertificateDirectory
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

@steveharter
Copy link
Member Author

/backport to release/9.0-staging

Copy link
Contributor

Started backporting to release/9.0-staging: https://github.com/dotnet/runtime/actions/runs/13311678524

Copy link
Contributor

@steveharter backporting to "release/9.0-staging" failed, the patch most likely resulted in conflicts:

$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: Add support for setting CertificateDirectory
Using index info to reconstruct a base tree...
M	src/libraries/Common/tests/System/DirectoryServices/LDAP.Configuration.xml
M	src/libraries/System.DirectoryServices.Protocols/ref/System.DirectoryServices.Protocols.cs
M	src/libraries/System.DirectoryServices.Protocols/tests/DirectoryServicesProtocolsTests.cs
Falling back to patching base and 3-way merge...
Auto-merging src/libraries/System.DirectoryServices.Protocols/tests/DirectoryServicesProtocolsTests.cs
Auto-merging src/libraries/System.DirectoryServices.Protocols/ref/System.DirectoryServices.Protocols.cs
Auto-merging src/libraries/Common/tests/System/DirectoryServices/LDAP.Configuration.xml
CONFLICT (content): Merge conflict in src/libraries/Common/tests/System/DirectoryServices/LDAP.Configuration.xml
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 Add support for setting CertificateDirectory
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[API Proposal]: LdapSessionOptions.CertificateDirectory Property
3 participants