Skip to content

Commit d233d34

Browse files
committed
Merge pull request #45 from kgraney/proxy_negotiate
Add SPNEGO proxy authentication
2 parents 5058374 + ca4c6c4 commit d233d34

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

spnego/spnego_server.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type ServerNegotiator interface {
2525
// with a client.
2626
type KerberizedServer struct {
2727
*gssapi.Lib
28+
UseProxyAuthentication bool
2829
}
2930

3031
var _ ServerNegotiator = KerberizedServer{}
@@ -56,18 +57,30 @@ func (k KerberizedServer) AcquireCred(serviceName string) (*gssapi.CredId, error
5657

5758
// Negotiate handles the SPNEGO client-server negotiation. Negotiate will likely
5859
// be invoked multiple times; a 200 or 400 response code are terminating
59-
// conditions, whereas a 401 means that the client should respond to the
60+
// conditions, whereas a 401 or 407 means that the client should respond to the
6061
// challenge that we send.
6162
func (k KerberizedServer) Negotiate(cred *gssapi.CredId, inHeader, outHeader http.Header) (string, int, error) {
62-
negotiate, inputToken := CheckSPNEGONegotiate(k.Lib, inHeader, "Authorization")
63+
var challengeHeader, authHeader string
64+
var challengeStatus int
65+
if k.UseProxyAuthentication {
66+
challengeHeader = "Proxy-Authenticate"
67+
challengeStatus = http.StatusProxyAuthRequired
68+
authHeader = "Proxy-Authorization"
69+
} else {
70+
challengeHeader = "WWW-Authenticate"
71+
challengeStatus = http.StatusUnauthorized
72+
authHeader = "Authorization"
73+
}
74+
75+
negotiate, inputToken := CheckSPNEGONegotiate(k.Lib, inHeader, authHeader)
6376
defer inputToken.Release()
6477

6578
// Here, challenge the client to initiate the security context. The first
6679
// request a client has made will often be unauthenticated, so we return a
6780
// 401, which the client handles.
6881
if !negotiate || inputToken.Length() == 0 {
69-
AddSPNEGONegotiate(outHeader, "WWW-Authenticate", inputToken)
70-
return "", http.StatusUnauthorized, errors.New("SPNEGO: unauthorized")
82+
AddSPNEGONegotiate(outHeader, challengeHeader, inputToken)
83+
return "", challengeStatus, errors.New("SPNEGO: unauthorized")
7184
}
7285

7386
// FIXME: GSS_S_CONTINUED_NEEDED handling?

0 commit comments

Comments
 (0)