mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-06-22 14:59:12 -04:00
Bumps [github.com/go-ldap/ldap/v3](https://github.com/go-ldap/ldap) from 3.4.12 to 3.4.13. - [Release notes](https://github.com/go-ldap/ldap/releases) - [Commits](https://github.com/go-ldap/ldap/compare/v3.4.12...v3.4.13) --- updated-dependencies: - dependency-name: github.com/go-ldap/ldap/v3 dependency-version: 3.4.13 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com>
58 lines
1.7 KiB
Go
58 lines
1.7 KiB
Go
// Copyright (c) Microsoft Corporation.
|
|
// Licensed under the MIT License.
|
|
|
|
// Protocol details from https://msdn.microsoft.com/en-us/library/cc236621.aspx,
|
|
// implementation hints from http://davenport.sourceforge.net/ntlm.html .
|
|
// This package only implements authentication, no key exchange or encryption. It
|
|
// only supports Unicode (UTF16LE) encoding of protocol strings, no OEM encoding.
|
|
// This package implements NTLMv2.
|
|
package ntlmssp
|
|
|
|
import (
|
|
"crypto/hmac"
|
|
"crypto/md5"
|
|
"strings"
|
|
|
|
"github.com/Azure/go-ntlmssp/internal/md4"
|
|
)
|
|
|
|
func getNtlmV2Hash(password, username, domain string) []byte {
|
|
return getNtlmV2Hashed(getNtlmHash(password), username, domain)
|
|
}
|
|
|
|
func getNtlmV2Hashed(ntlmHash []byte, username, domain string) []byte {
|
|
return hmacMd5(ntlmHash, toUnicode(strings.ToUpper(username)+domain))
|
|
}
|
|
|
|
func getNtlmHash(password string) []byte {
|
|
hash := md4.New()
|
|
hash.Write(toUnicode(password))
|
|
return hash.Sum(nil)
|
|
}
|
|
|
|
func computeNtlmV2Response(ntlmV2Hash, serverChallenge, clientChallenge,
|
|
timestamp, targetInfo []byte,
|
|
) []byte {
|
|
temp := []byte{1, 1, 0, 0, 0, 0, 0, 0}
|
|
temp = append(temp, timestamp...)
|
|
temp = append(temp, clientChallenge...)
|
|
temp = append(temp, 0, 0, 0, 0)
|
|
temp = append(temp, targetInfo...)
|
|
temp = append(temp, 0, 0, 0, 0)
|
|
|
|
NTProofStr := hmacMd5(ntlmV2Hash, serverChallenge, temp)
|
|
return append(NTProofStr, temp...)
|
|
}
|
|
|
|
func computeLmV2Response(ntlmV2Hash, serverChallenge, clientChallenge []byte) []byte {
|
|
return append(hmacMd5(ntlmV2Hash, serverChallenge, clientChallenge), clientChallenge...)
|
|
}
|
|
|
|
func hmacMd5(key []byte, data ...[]byte) []byte {
|
|
mac := hmac.New(md5.New, key)
|
|
for _, d := range data {
|
|
mac.Write(d)
|
|
}
|
|
return mac.Sum(nil)
|
|
}
|