Skip to content

Commit

Permalink
Merge pull request #4 from bdwyertech/ntlm-cleanup
Browse files Browse the repository at this point in the history
Clean up NTLM Logic
  • Loading branch information
aus authored Feb 20, 2021
2 parents 34ff853 + c133604 commit 45952f3
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions ntlm_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func dialNTLM(p Proxy, addr string, baseDial func() (net.Conn, error)) (net.Conn
Host: addr,
Header: h,
}
if err := connect.Write(conn); err != nil {
if err := connect.WriteProxy(conn); err != nil {
debugf("ntlm> Could not write negotiate message to proxy: %s", err)
return conn, err
}
Expand All @@ -65,6 +65,9 @@ func dialNTLM(p Proxy, addr string, baseDial func() (net.Conn, error)) (net.Conn
debugf("ntlm> Could not read negotiate response from proxy: %s", err)
return conn, err
}
if err := resp.Body.Close(); err != nil {
return conn, err
}

if resp.StatusCode != http.StatusProxyAuthRequired {
debugf("ntlm> Expected %d as return status, got: %d", http.StatusProxyAuthRequired, resp.StatusCode)
Expand Down Expand Up @@ -94,17 +97,15 @@ func dialNTLM(p Proxy, addr string, baseDial func() (net.Conn, error)) (net.Conn
return conn, err
}

resp.Body.Close()
h = p.Headers.Clone()
h.Set("Proxy-Authorization", fmt.Sprintf("NTLM %s", base64.StdEncoding.EncodeToString(authenticate)))
h.Set("Proxy-Connection", "Keep-Alive")
connect = &http.Request{
Method: "CONNECT",
URL: &url.URL{Opaque: addr},
Host: addr,
Header: h,
// Rewind the request body, the handshake needs it
if connect.GetBody != nil {
if connect.Body, err = connect.GetBody(); err != nil {
return conn, err
}
}
if err := connect.Write(conn); err != nil {

connect.Header.Set("Proxy-Authorization", fmt.Sprintf("NTLM %s", base64.StdEncoding.EncodeToString(authenticate)))
if err := connect.WriteProxy(conn); err != nil {
debugf("ntlm> Could not write authenticate message to proxy: %s", err)
return conn, err
}
Expand Down

0 comments on commit 45952f3

Please # to comment.