-
Notifications
You must be signed in to change notification settings - Fork 358
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
[bugfix] Added APOptions []int in client.GSSAPIBindRequest(...) and client.InitSecContext(...), fixes #536 #537
Open
p0dalirius
wants to merge
7
commits into
go-ldap:master
Choose a base branch
from
p0dalirius:fix-ldap-gssapi-kerberos-auth-on-windows-active-directory
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+120
−12
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fe5ed31
Added APOptions []int in client.GSSAPIBindRequest(...) and client.Ini…
p0dalirius 3bbd598
Moving APOptions to GSSAPIBindRequest struct for coherence and to avo…
p0dalirius 78ef5d4
Unified UnmarshalWrapToken() with v3 and base
p0dalirius 1cad944
Update client.go
p0dalirius 1cc1eb3
Removed breaking API changes to InitSecContext, added APOptions in C…
p0dalirius f752bf8
Removed breaking API changes to InitSecContext, added APOptions in C…
p0dalirius a55dbd6
Changing unmarshalWrapToken function to private
p0dalirius File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
package gssapi | ||
|
||
import ( | ||
"bytes" | ||
"encoding/binary" | ||
"encoding/hex" | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/jcmturner/gokrb5/v8/client" | ||
|
@@ -24,6 +28,8 @@ type Client struct { | |
|
||
ekey types.EncryptionKey | ||
Subkey types.EncryptionKey | ||
|
||
APOptions []int | ||
} | ||
|
||
// NewClientWithKeytab creates a new client from a keytab credential. | ||
|
@@ -110,7 +116,7 @@ func (client *Client) InitSecContext(target string, input []byte) ([]byte, bool, | |
} | ||
client.ekey = ekey | ||
|
||
token, err := spnego.NewKRB5TokenAPREQ(client.Client, tkt, ekey, gssapiFlags, []int{}) | ||
token, err := spnego.NewKRB5TokenAPREQ(client.Client, tkt, ekey, gssapiFlags, client.APOptions) | ||
if err != nil { | ||
return nil, false, err | ||
} | ||
|
@@ -160,7 +166,7 @@ func (client *Client) InitSecContext(target string, input []byte) ([]byte, bool, | |
// See RFC 4752 section 3.1. | ||
func (client *Client) NegotiateSaslAuth(input []byte, authzid string) ([]byte, error) { | ||
token := &gssapi.WrapToken{} | ||
err := token.Unmarshal(input, true) | ||
err := unmarshalWrapToken(token, input, true) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
@@ -212,3 +218,48 @@ func (client *Client) NegotiateSaslAuth(input []byte, authzid string) ([]byte, e | |
|
||
return output, nil | ||
} | ||
|
||
func unmarshalWrapToken(wt *gssapi.WrapToken, data []byte, expectFromAcceptor bool) error { | ||
// Check if we can read a whole header | ||
if len(data) < 16 { | ||
return errors.New("bytes shorter than header length") | ||
} | ||
|
||
// Is the Token ID correct? | ||
expectedWrapTokenId := [2]byte{0x05, 0x04} | ||
if !bytes.Equal(expectedWrapTokenId[:], data[0:2]) { | ||
return fmt.Errorf("wrong Token ID. Expected %s, was %s", hex.EncodeToString(expectedWrapTokenId[:]), hex.EncodeToString(data[0:2])) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In cases where returning additional context with the error it may be nice for it to wrap a simpler 'known' error as the related comment says. eg |
||
} | ||
|
||
// Check the acceptor flag | ||
flags := data[2] | ||
isFromAcceptor := flags&0x01 == 1 | ||
if isFromAcceptor && !expectFromAcceptor { | ||
return errors.New("unexpected acceptor flag is set: not expecting a token from the acceptor") | ||
} | ||
if !isFromAcceptor && expectFromAcceptor { | ||
return errors.New("expected acceptor flag is not set: expecting a token from the acceptor, not the initiator") | ||
} | ||
|
||
// Check the filler byte | ||
if data[3] != gssapi.FillerByte { | ||
return fmt.Errorf("unexpected filler byte: expecting 0xFF, was %s ", hex.EncodeToString(data[3:4])) | ||
} | ||
checksumL := binary.BigEndian.Uint16(data[4:6]) | ||
|
||
// Sanity check on the checksum length | ||
if int(checksumL) > len(data)-gssapi.HdrLen { | ||
return fmt.Errorf("inconsistent checksum length: %d bytes to parse, checksum length is %d", len(data), checksumL) | ||
} | ||
|
||
payloadStart := 16 + checksumL | ||
|
||
wt.Flags = flags | ||
wt.EC = checksumL | ||
wt.RRC = binary.BigEndian.Uint16(data[6:8]) | ||
wt.SndSeqNum = binary.BigEndian.Uint64(data[8:16]) | ||
wt.CheckSum = data[16:payloadStart] | ||
wt.Payload = data[payloadStart:] | ||
|
||
return nil | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we anticipate any kind of code handling of these errors it may be kinder to actually create named errors (
var ErrInvalidGSSAPIFooBarHeaderLength = "bytes shorter ..."
), that can be used with theerrors.Is
and related helper functions.