Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions authenticator.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019, 2021, 2024 The Alpaca Authors
// Copyright 2019, 2021, 2024, 2025 The Alpaca Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -23,6 +23,7 @@ import (
"os"
"strings"

"github.com/ThomsonReutersEikon/go-ntlm/ntlm"
"github.com/samuong/go-ntlmssp"
)

Expand All @@ -34,6 +35,10 @@ type authenticator struct {

func (a authenticator) do(req *http.Request, rt http.RoundTripper) (*http.Response, error) {
hostname, _ := os.Hostname() // in case of error, just use the zero value ("") as hostname
// XXX: github.com/ThomsonReutersEikon/go-ntlm doesn't seem to have a
// way to generate a negotiate message (or even a hardcoded one in the
// library?). Use the one from github.com/Azure/go-ntlmssp, and hope
// that it works ¯\_(ツ)_/¯
negotiate, err := ntlmssp.NewNegotiateMessage(a.domain, hostname)
if err != nil {
log.Printf("Error creating NTLM Type 1 (Negotiate) message: %v", err)
Expand All @@ -49,20 +54,34 @@ func (a authenticator) do(req *http.Request, rt http.RoundTripper) (*http.Respon
return resp, nil
}
resp.Body.Close()
challenge, err := base64.StdEncoding.DecodeString(
challengeBytes, err := base64.StdEncoding.DecodeString(
strings.TrimPrefix(resp.Header.Get("Proxy-Authenticate"), "NTLM "))
if err != nil {
log.Printf("Error decoding NTLM Type 2 (Challenge) message: %v", err)
return nil, err
}
authenticate, err := ntlmssp.ProcessChallengeWithHash(
challenge, a.domain, a.username, a.hash)
challenge, err := ntlm.ParseChallengeMessage(challengeBytes)
if err != nil {
log.Printf("Error parsing NTLM Type 2 (Challenge) message: %v", err)
return nil, err
}
session, err := ntlm.CreateClientSession(ntlm.Version2, ntlm.ConnectionlessMode)
if err != nil {
log.Printf("Error creating NTLM client session: %v", err)
return nil, err
}
session.SetUserInfo(a.username, os.Getenv("ALPACA_PASSWORD"), a.domain)
if err := session.ProcessChallengeMessage(challenge); err != nil {
log.Printf("Error processing NTLM Type 2 (Challenge) message: %v", err)
return nil, err
}
authenticate, err := session.GenerateAuthenticateMessage()
if err != nil {
log.Printf("Error processing NTLM Type 2 (Challenge) message: %v", err)
return nil, err
}
req.Header.Set("Proxy-Authorization",
"NTLM "+base64.StdEncoding.EncodeToString(authenticate))
"NTLM "+base64.StdEncoding.EncodeToString(authenticate.Bytes()))
return rt.RoundTrip(req)
}

Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
)

require (
github.com/ThomsonReutersEikon/go-ntlm v0.0.0-00010101000000-000000000000
github.com/alessio/shellescape v1.4.1 // indirect
github.com/danieljoos/wincred v1.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
Expand All @@ -26,3 +27,5 @@ require (
gopkg.in/sourcemap.v1 v1.0.5 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/ThomsonReutersEikon/go-ntlm => github.com/omniboost/ThomsonReutersEikon-go-ntlm v0.0.0-20200629081634-2b904c46aa41
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/keybase/go-keychain v0.0.0-20231219164618-57a3676c3af6 h1:IsMZxCuZqKuao2vNdfD82fjjgPLfyHLpR41Z88viRWs=
github.com/keybase/go-keychain v0.0.0-20231219164618-57a3676c3af6/go.mod h1:3VeWNIJaW+O5xpRQbPp0Ybqu1vJd/pm7s2F473HRrkw=
github.com/omniboost/ThomsonReutersEikon-go-ntlm v0.0.0-20200629081634-2b904c46aa41 h1:g5MhOh7x3/HJ4hjx1U8UuCqbmlTwAdkNe5tPL/17q3g=
github.com/omniboost/ThomsonReutersEikon-go-ntlm v0.0.0-20200629081634-2b904c46aa41/go.mod h1:1GjY7cBv+3oSiN701BVraCLtLPchBiGIB6t7hnMowSA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/robertkrimen/otto v0.4.0 h1:/c0GRrK1XDPcgIasAsnlpBT5DelIeB9U/Z/JCQsgr7E=
Expand Down