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

Negotiate improvements #4

Merged
merged 6 commits into from
Jun 2, 2018

Conversation

vanackere
Copy link
Contributor

Hi,

This branch contains various changes / improvements to the negotiate package (FYI those changes were added in order to implement both Web SPNEGO and SASL GSS-SPNEGO support, using the native windows api).

Please merge if you feel those are appropriate, thanks !

@vanackere
Copy link
Contributor Author

Note: I had to change the prototype from sspi.AcquireCredentials in order to pass the principal name since the C++ code I was porting made use of this parameter. Not breaking the current signature would require a new function (sspi.AcquireCredentialsForPrincipal ?), please let me know if you feel this is a better option.

@alexbrainman
Copy link
Owner

I will try to review this weekend.

Alex

Copy link
Owner

@alexbrainman alexbrainman left a comment

Choose a reason for hiding this comment

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

Most of it looks fine to me.

Thank you.

Alex

@@ -245,6 +288,20 @@ func (c *ClientContext) MakeSignature(msg []byte, qop, seqno uint32) ([]byte, er
return makeSignature(c.sctxt, msg, qop, seqno)
}

// EncryptMessage uses the established client context to encrypt a message
Copy link
Owner

Choose a reason for hiding this comment

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

Can you, please, add a test for EncryptMessage and DecryptMessage ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

// credentials cred generated by AcquireCurrentUserCredentials or
// AcquireUserCredentials and SPN to start client Negotiate
// AcquireUserCredentials and SPN to start a client Negotiate
// negotiation sequence. targetName is the service principal name
// (SPN) or the security context of the destination server.
Copy link
Owner

Choose a reason for hiding this comment

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

You do not mention new "flags" parameter in the documentation. Don't you want to say something about it?

Copy link
Owner

Choose a reason for hiding this comment

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

You did not address my comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The flags parameter is documented in AcquireUserCredentialsWithFlags, did you mean something else ?

Copy link
Owner

Choose a reason for hiding this comment

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

My fault, I have no idea why I asked you to document "flag" parameter here. Forget my comment.

sspi.go Outdated
@@ -50,13 +50,21 @@ type Credentials struct {
expiry syscall.Filetime
}

func AcquireCredentials(pkgname string, creduse uint32, authdata *byte) (*Credentials, error) {
func AcquireCredentials(principal string, pkgname string, creduse uint32, authdata *byte) (*Credentials, error) {
Copy link
Owner

Choose a reason for hiding this comment

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

This commit changes the way "principal" parameter of "" is handled. What is happening here is not obvious. This needs to be at least documented in function doco.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

An empty principal parameter is passed as a nil pointer in the underlying winapi call. I will document.

Copy link
Owner

Choose a reason for hiding this comment

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

I still do not see any new documentation that you promised.

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 forgot this part, sorry. I'll fix that.

Copy link
Owner

Choose a reason for hiding this comment

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

Please, do.

@@ -85,13 +85,13 @@ func AcquireUserCredentials(domain, username, password string) (*sspi.Credential
PasswordLength: plen,
Flags: sspi.SEC_WINNT_AUTH_IDENTITY_UNICODE,
}
return acquireCredentials(sspi.SECPKG_CRED_OUTBOUND, &ai)
return acquireCredentials("", sspi.SECPKG_CRED_OUTBOUND, &ai)
}

// AcquireServerCredentials acquires server credentials that will
// be used to authenticate client.
Copy link
Owner

Choose a reason for hiding this comment

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

Maybe add new "principalName" parameter documentation.

Copy link
Owner

Choose a reason for hiding this comment

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

You did not address my comment.

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 sorry, I'm afraid I did not understand what you meant here... Do you suggest to add a new parameter "principalName" to AcquireUserCredentials ?

Copy link
Owner

Choose a reason for hiding this comment

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

You have added "principalName" parameter to AcquireServerCredentials function. You should document new parameter - explain what it does.

if ret != sspi.SEC_E_OK {
return "", ret
}
defer sspi.FreeContextBuffer((*byte)(unsafe.Pointer(ns.ClientName)))
Copy link
Owner

Choose a reason for hiding this comment

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

Why aren't you freeing ServerName too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was simply an oversight, fixed !

@vanackere vanackere force-pushed the negotiate-improvements branch from 48f578e to 816b5ac Compare May 29, 2018 14:30
@vanackere
Copy link
Contributor Author

Hi, I made the requested changes and updated my branch, PTAL

Copy link
Owner

@alexbrainman alexbrainman left a comment

Choose a reason for hiding this comment

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

I still see some of my comments not addressed. Please, let me know, if I am missing something.

Alex

@@ -85,13 +85,13 @@ func AcquireUserCredentials(domain, username, password string) (*sspi.Credential
PasswordLength: plen,
Flags: sspi.SEC_WINNT_AUTH_IDENTITY_UNICODE,
}
return acquireCredentials(sspi.SECPKG_CRED_OUTBOUND, &ai)
return acquireCredentials("", sspi.SECPKG_CRED_OUTBOUND, &ai)
}

// AcquireServerCredentials acquires server credentials that will
// be used to authenticate client.
Copy link
Owner

Choose a reason for hiding this comment

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

You did not address my comment.

sspi.go Outdated
@@ -50,13 +50,21 @@ type Credentials struct {
expiry syscall.Filetime
}

func AcquireCredentials(pkgname string, creduse uint32, authdata *byte) (*Credentials, error) {
func AcquireCredentials(principal string, pkgname string, creduse uint32, authdata *byte) (*Credentials, error) {
Copy link
Owner

Choose a reason for hiding this comment

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

I still do not see any new documentation that you promised.

// credentials cred generated by AcquireCurrentUserCredentials or
// AcquireUserCredentials and SPN to start client Negotiate
// AcquireUserCredentials and SPN to start a client Negotiate
// negotiation sequence. targetName is the service principal name
// (SPN) or the security context of the destination server.
Copy link
Owner

Choose a reason for hiding this comment

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

You did not address my comment.

Copy link
Owner

@alexbrainman alexbrainman left a comment

Choose a reason for hiding this comment

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

I hope that I explained myself better this time.

And, please, rebase your changes, because I just pushed new change into this repo.

Thank you.

Alex

// credentials cred generated by AcquireCurrentUserCredentials or
// AcquireUserCredentials and SPN to start client Negotiate
// AcquireUserCredentials and SPN to start a client Negotiate
// negotiation sequence. targetName is the service principal name
// (SPN) or the security context of the destination server.
Copy link
Owner

Choose a reason for hiding this comment

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

My fault, I have no idea why I asked you to document "flag" parameter here. Forget my comment.

@@ -85,13 +85,13 @@ func AcquireUserCredentials(domain, username, password string) (*sspi.Credential
PasswordLength: plen,
Flags: sspi.SEC_WINNT_AUTH_IDENTITY_UNICODE,
}
return acquireCredentials(sspi.SECPKG_CRED_OUTBOUND, &ai)
return acquireCredentials("", sspi.SECPKG_CRED_OUTBOUND, &ai)
}

// AcquireServerCredentials acquires server credentials that will
// be used to authenticate client.
Copy link
Owner

Choose a reason for hiding this comment

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

You have added "principalName" parameter to AcquireServerCredentials function. You should document new parameter - explain what it does.

sspi.go Outdated
@@ -50,13 +50,21 @@ type Credentials struct {
expiry syscall.Filetime
}

func AcquireCredentials(pkgname string, creduse uint32, authdata *byte) (*Credentials, error) {
func AcquireCredentials(principal string, pkgname string, creduse uint32, authdata *byte) (*Credentials, error) {
Copy link
Owner

Choose a reason for hiding this comment

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

Please, do.

vanackere added 5 commits June 1, 2018 11:37
This allows to pass specific useful flags (like sspi.ISC_REQ_INTEGRITY or ISC_REQ_INTEGRITY)
Setting this parameter to an empty string will pass nil to the underlying windows sspi function.

Only the negotiate public api is changed in this commit (since the C++ code I'm porting was explicitely using this parameter).
This method returns the username corresponding to the authenticated client
Explicitely returning the serverDone boolean allows for slightly cleaner code
@vanackere vanackere force-pushed the negotiate-improvements branch from 816b5ac to 55a2fc7 Compare June 1, 2018 09:38
@vanackere
Copy link
Contributor Author

Branch updated and rebased, please let me know if I still missed anything, thanks !

@alexbrainman
Copy link
Owner

LGTM now. Thank you.

Alex

@alexbrainman alexbrainman merged commit 033374a into alexbrainman:master Jun 2, 2018
@alexbrainman
Copy link
Owner

Merged, so closing this now.

Alex

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

Successfully merging this pull request may close these issues.

2 participants