-
Notifications
You must be signed in to change notification settings - Fork 4
/
krb_windows.go
72 lines (55 loc) · 1.4 KB
/
krb_windows.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//go:build windows
// +build windows
package gopgkrb5
import (
"github.com/alexbrainman/sspi"
"github.com/alexbrainman/sspi/negotiate"
)
// GSS implements the pq.GSS interface and the pgconn.GSS interface.
type GSS struct {
creds *sspi.Credentials
ctx *negotiate.ClientContext
}
// NewGSS creates a new GSS provider.
func NewGSS() (*GSS, error) {
g := &GSS{}
err := g.init()
if err != nil {
return nil, err
}
return g, nil
}
func (g *GSS) init() error {
creds, err := negotiate.AcquireCurrentUserCredentials()
if err != nil {
return err
}
g.creds = creds
return nil
}
// GetInitToken implements the GSS interface.
func (g *GSS) GetInitToken(host string, service string) ([]byte, error) {
host, err := canonicalizeHostname(host)
if err != nil {
return nil, err
}
spn := service + "/" + host
return g.GetInitTokenFromSpn(spn)
}
// GetInitTokenFromSPN implements the GSS interface.
func (g *GSS) GetInitTokenFromSPN(spn string) ([]byte, error) {
ctx, token, err := negotiate.NewClientContext(g.creds, spn)
if err != nil {
return nil, err
}
g.ctx = ctx
return token, nil
}
// GetInitTokenFromSpn implements the GSS interface.
func (g *GSS) GetInitTokenFromSpn(spn string) ([]byte, error) {
return g.GetInitTokenFromSPN(spn)
}
// Continue implements the GSS interface.
func (g *GSS) Continue(inToken []byte) (done bool, outToken []byte, err error) {
return g.ctx.Update(inToken)
}