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 DeriveKeyFromSessionKey API for auth #113003

Closed
wants to merge 1 commit into from

Conversation

jborean93
Copy link
Contributor

Added the DeriveKeyFromSessionKey function to NegotiateAuthentication which can be used to retrieve the session key negotiated between the client and server in a negotiated authentication context. This can be used by protocols that do not use the builtin wrapping mechanisms but instead derive their own authentication method from the session key.

Fix #111099

Added the DeriveKeyFromSessionKey function to NegotiateAuthentication
which can be used to retrieve the session key negotiated between the
client and server in a negotiated authentication context. This can be
used by protocols that do not use the builtin wrapping mechanisms but
instead derive their own authentication method from the session key.

Fix dotnet#111099
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.

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Feb 27, 2025
@vcsjones
Copy link
Member

The proposed API in #111099 hasn't been approved yet. Generally, pull requests for un-approved APIs should not be opened, per the API review process.

Debug.Assert(_securityContext is not null);

SecPkgContext_SessionKey sessionKey = default;
int result = Interop.SspiCli.QueryContextAttributesW(ref _securityContext._handle, Interop.SspiCli.ContextAttribute.SECPKG_ATTR_SESSION_KEY, &sessionKey);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some other APIs use SSPIWrapper.QueryBlittableContextAttributes but that doesn't seem to great with this API as:

  • It returns a bool to see if it worked or not which makes it hard to get the original error to the caller on a failure
  • The whole SafeHandle and freeing setup seems quite complicated
    • This is compounded because it seems like I need a custom handle to point to the SessionKey field

So in the end I just manually call the API and FreeContextBuffer the required address. Happy to change it if needed but I wasn't fully sure what the benefits really would be

@@ -56,6 +56,13 @@ static gss_OID_desc gss_mech_ntlm_OID_desc = {.length = STRING_LENGTH(gss_ntlm_o
.elements = gss_ntlm_oid_value};
#endif

#if !HAVE_GSS_C_INQ_SSPI_SESSION_KEY
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not 100% sure what I'm doing here. It seems like MIT krb5, Heimdal, and GSS Framework do define GSS_C_INQ_SSPI_SESSION_KEY and works when I compile it from the src/native/libs dir but when I tried to compile .NET from the root project I still needed to manually define it. In the end it didn't seem an issue to just redefine if needed but happy to change this around if needed.

Comment on lines +754 to +763
NetSecurityNative_MoveBuffer(&sessionKey->elements[0], outBuffer);

for (i = 1; i < sessionKey->count; i++)
{
gss_release_buffer(&minorStatusFree, &sessionKey->elements[i]);
}
free(sessionKey->elements);
free(sessionKey);

return majorStatus;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ideally it would be nice to return the buffer set and have the caller extra the element needed but the use of the shim makes it quite hard to store both the set structure and the elements in there. In the end I found it easier to just set the output buffer to the one that's needed and manually free the remaining buffer set values that gss_release_buffer_set would have done for us anyway.

@jborean93
Copy link
Contributor Author

@vcsjones oh sorry I assumed based on the conversation it was approved but if that's not the case I can close this and wait for approval. Is there any steps I'm missing for the approval process or is it just waiting for someone to get to it?

@vcsjones
Copy link
Member

Approved APIs are labeled api-approved. The next steps for your API is to get it through the API review board. An area owner / champion needs to mark it as api-ready-for-review (seems like that is @wfurt). Assuming the API review board has no objections, then it gets marked api-approved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Net.Security community-contribution Indicates that the PR has been added by a community member new-api-needs-documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[API Proposal]: Expose SessionKey on NegotiateAuthentication
2 participants