mirror of
https://github.com/go-gitea/gitea.git
synced 2024-10-30 08:27:32 -04:00
e374bb7e2d
* [Vendor] update go-ldap to v3.0.3 * update go-ldap to v3.2.4 Co-authored-by: techknowlogick <techknowlogick@gitea.io>
65 lines
1.5 KiB
Go
Vendored
65 lines
1.5 KiB
Go
Vendored
package ntlmssp
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/binary"
|
|
"errors"
|
|
"strings"
|
|
)
|
|
|
|
const expMsgBodyLen = 40
|
|
|
|
type negotiateMessageFields struct {
|
|
messageHeader
|
|
NegotiateFlags negotiateFlags
|
|
|
|
Domain varField
|
|
Workstation varField
|
|
|
|
Version
|
|
}
|
|
|
|
var defaultFlags = negotiateFlagNTLMSSPNEGOTIATETARGETINFO |
|
|
negotiateFlagNTLMSSPNEGOTIATE56 |
|
|
negotiateFlagNTLMSSPNEGOTIATE128 |
|
|
negotiateFlagNTLMSSPNEGOTIATEUNICODE |
|
|
negotiateFlagNTLMSSPNEGOTIATEEXTENDEDSESSIONSECURITY
|
|
|
|
//NewNegotiateMessage creates a new NEGOTIATE message with the
|
|
//flags that this package supports.
|
|
func NewNegotiateMessage(domainName, workstationName string) ([]byte, error) {
|
|
payloadOffset := expMsgBodyLen
|
|
flags := defaultFlags
|
|
|
|
if domainName != "" {
|
|
flags |= negotiateFlagNTLMSSPNEGOTIATEOEMDOMAINSUPPLIED
|
|
}
|
|
|
|
if workstationName != "" {
|
|
flags |= negotiateFlagNTLMSSPNEGOTIATEOEMWORKSTATIONSUPPLIED
|
|
}
|
|
|
|
msg := negotiateMessageFields{
|
|
messageHeader: newMessageHeader(1),
|
|
NegotiateFlags: flags,
|
|
Domain: newVarField(&payloadOffset, len(domainName)),
|
|
Workstation: newVarField(&payloadOffset, len(workstationName)),
|
|
Version: DefaultVersion(),
|
|
}
|
|
|
|
b := bytes.Buffer{}
|
|
if err := binary.Write(&b, binary.LittleEndian, &msg); err != nil {
|
|
return nil, err
|
|
}
|
|
if b.Len() != expMsgBodyLen {
|
|
return nil, errors.New("incorrect body length")
|
|
}
|
|
|
|
payload := strings.ToUpper(domainName + workstationName)
|
|
if _, err := b.WriteString(payload); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return b.Bytes(), nil
|
|
}
|