forked from aksdb/CalAnonSync
46 lines
1.6 KiB
Go
46 lines
1.6 KiB
Go
package httpntlm
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"encoding/binary"
|
|
)
|
|
|
|
const (
|
|
negotiateUnicode = 0x0001 // Text strings are in unicode
|
|
negotiateOEM = 0x0002 // Text strings are in OEM
|
|
requestTarget = 0x0004 // Server return its auth realm
|
|
negotiateSign = 0x0010 // Request signature capability
|
|
negotiateSeal = 0x0020 // Request confidentiality
|
|
negotiateLMKey = 0x0080 // Generate session key
|
|
negotiateNTLM = 0x0200 // NTLM authentication
|
|
negotiateLocalCall = 0x4000 // client/server on same machine
|
|
negotiateAlwaysSign = 0x8000 // Sign for all security levels
|
|
negotiateIdentify = 0x80000
|
|
)
|
|
|
|
var (
|
|
put32 = binary.LittleEndian.PutUint32
|
|
put16 = binary.LittleEndian.PutUint16
|
|
encBase64 = base64.StdEncoding.EncodeToString
|
|
decBase64 = base64.StdEncoding.DecodeString
|
|
)
|
|
|
|
// generates NTLM Negotiate type-1 message
|
|
// for details see http://www.innovation.ch/personal/ronald/ntlm.html
|
|
func negotiate() []byte {
|
|
ret := make([]byte, 32)
|
|
flags := negotiateAlwaysSign | negotiateNTLM | requestTarget | negotiateOEM | negotiateUnicode | negotiateIdentify
|
|
|
|
copy(ret, []byte("NTLMSSP\x00")) // protocol
|
|
put32(ret[8:], 1) // type
|
|
put32(ret[12:], uint32(flags)) // flags
|
|
put16(ret[16:], 0) // NT domain name length
|
|
put16(ret[18:], 0) // NT domain name max length
|
|
put32(ret[20:], 0x20) // NT domain name offset
|
|
put16(ret[24:], 0) // local workstation name length
|
|
put16(ret[26:], 0) // local workstation name max length
|
|
put32(ret[28:], 0x20) // local workstation name offset
|
|
|
|
return ret
|
|
}
|