Documentation
¶
Overview ¶
Package ntlmcbt provides NTLM authentication with Channel Binding Token (CBT) support for Extended Protection for Authentication (EPA).
This package wraps go-ntlmssp and injects MsvAvChannelBindings into the NTLM AUTHENTICATE_MESSAGE, enabling authentication to EPA-protected servers.
Channel binding tokens are computed per RFC 5929 using the tls-server-end-point method, which hashes the server's TLS certificate.
Usage ¶
After establishing a TLS connection, extract the server certificate and create a channel binding:
cert := tlsConn.ConnectionState().PeerCertificates[0] cb := ntlmcbt.ComputeTLSServerEndpoint(cert)
Then use the Negotiator to perform NTLM authentication:
nego := &ntlmcbt.Negotiator{ChannelBindings: cb}
negotiateMsg, _ := nego.Negotiate("DOMAIN", "WORKSTATION")
// ... send negotiateMsg, receive challengeMsg ...
authMsg, _ := nego.ChallengeResponse(challengeMsg, "user", "password")
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GSSChannelBindings ¶
type GSSChannelBindings struct {
// InitiatorAddrType is the address type of the initiator (typically 0/unspecified).
InitiatorAddrType uint32
// InitiatorAddress is the initiator's address (typically empty for TLS bindings).
InitiatorAddress []byte
// AcceptorAddrType is the address type of the acceptor (typically 0/unspecified).
AcceptorAddrType uint32
// AcceptorAddress is the acceptor's address (typically empty for TLS bindings).
AcceptorAddress []byte
// ApplicationData contains the channel binding data (e.g., "tls-server-end-point:<hash>").
ApplicationData []byte
}
GSSChannelBindings represents the RFC 2744 gss_channel_bindings_struct. For TLS server endpoint channel bindings, only ApplicationData is populated.
func ComputeTLSServerEndpoint ¶
func ComputeTLSServerEndpoint(cert *x509.Certificate) *GSSChannelBindings
ComputeTLSServerEndpoint creates channel bindings from a TLS server certificate using the tls-server-end-point method defined in RFC 5929.
The hash algorithm is determined by the certificate's signature algorithm:
- MD5 or SHA-1 signatures → use SHA-256 (per RFC 5929 Section 4.1)
- SHA-384 signatures → use SHA-384
- SHA-512 signatures → use SHA-512
- All others → use SHA-256
func (*GSSChannelBindings) MD5Hash ¶
func (cb *GSSChannelBindings) MD5Hash() []byte
MD5Hash returns the MD5 hash of the packed channel bindings. This is the value used in NTLM's MsvAvChannelBindings AV_PAIR. Note: MD5 is mandated by the MS-NLMP specification for channel bindings.
func (*GSSChannelBindings) Pack ¶
func (cb *GSSChannelBindings) Pack() []byte
Pack serializes the channel bindings to wire format (little-endian). This format is compatible with Windows SEC_CHANNEL_BINDINGS structure.
type Negotiator ¶
type Negotiator struct {
// ChannelBindings contains the computed channel binding token.
// If nil, standard NTLM authentication is performed without CBT.
ChannelBindings *GSSChannelBindings
// DomainNeeded indicates whether the domain should be included in the response.
// This is passed to go-ntlmssp's ProcessChallenge function.
DomainNeeded bool
}
Negotiator implements NTLM authentication with optional channel binding support. It wraps go-ntlmssp and injects MsvAvChannelBindings when channel bindings are provided.
func NewNegotiator ¶
func NewNegotiator(cb *GSSChannelBindings) *Negotiator
NewNegotiator creates a new Negotiator with the provided channel bindings. It defaults to DomainNeeded=true, which matches standard Windows behavior.
func (*Negotiator) ChallengeResponse ¶
func (n *Negotiator) ChallengeResponse(challenge []byte, username, password string) ([]byte, error)
ChallengeResponse processes the server's CHALLENGE_MESSAGE (Type 2) and generates the AUTHENTICATE_MESSAGE (Type 3).
If channel bindings are configured, the MsvAvChannelBindings AV_PAIR is injected into the response before computing the final message.
func (*Negotiator) ChallengeResponseWithHash ¶
func (n *Negotiator) ChallengeResponseWithHash(challenge []byte, username, hash string) ([]byte, error)
ChallengeResponseWithHash is like ChallengeResponse but uses a password hash instead of the plaintext password.