Skip to content

Commit 0d4e7fc

Browse files
authored
fix: Use expiry from negotiated context (#121)
Fixes #6
1 parent 7c134dd commit 0d4e7fc

3 files changed

Lines changed: 6 additions & 12 deletions

File tree

gss/apcera.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,10 @@ func (c *Client) NegotiateContext(host string) (keyname string, expiry time.Time
160160
var (
161161
input *gssapi.Buffer
162162
ctx *gssapi.CtxId
163-
tkey *dns.TKEY
164163
)
165164

166165
for ok := true; ok; ok = c.lib.LastStatus.Major.ContinueNeeded() {
167-
nctx, _, output, _, _, err := c.lib.InitSecContext(
166+
nctx, _, output, _, duration, err := c.lib.InitSecContext(
168167
c.lib.GSS_C_NO_CREDENTIAL,
169168
ctx, // nil initially
170169
service,
@@ -174,7 +173,7 @@ func (c *Client) NegotiateContext(host string) (keyname string, expiry time.Time
174173
c.lib.GSS_C_NO_CHANNEL_BINDINGS,
175174
input)
176175

177-
ctx = nctx
176+
ctx, expiry = nctx, time.Now().UTC().Add(duration)
178177

179178
defer func() {
180179
err = multierror.Append(err, output.Release()).ErrorOrNil()
@@ -190,7 +189,8 @@ func (c *Client) NegotiateContext(host string) (keyname string, expiry time.Time
190189
}
191190

192191
//nolint:lll
193-
if tkey, _, err = util.ExchangeTKEY(c.client, host, keyname, tsig.GSS, util.TkeyModeGSS, 3600, output.Bytes(), nil, "", ""); err != nil {
192+
tkey, _, err := util.ExchangeTKEY(c.client, host, keyname, tsig.GSS, util.TkeyModeGSS, 3600, output.Bytes(), nil, "", "")
193+
if err != nil {
194194
return "", time.Time{}, multierror.Append(err, ctx.DeleteSecContext())
195195
}
196196

@@ -212,8 +212,6 @@ func (c *Client) NegotiateContext(host string) (keyname string, expiry time.Time
212212
}()
213213
}
214214

215-
expiry = time.Unix(int64(tkey.Expiration), 0)
216-
217215
c.m.Lock()
218216
defer c.m.Unlock()
219217

gss/gokrb5.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,12 @@ func (c *Client) negotiateContext(host string, options []wrapper.Option[wrapper.
127127
}
128128
}
129129

130-
expiry := time.Unix(int64(tkey.Expiration), 0)
131-
132130
c.m.Lock()
133131
defer c.m.Unlock()
134132

135133
c.ctx[keyname] = ctx
136134

137-
return keyname, expiry, nil
135+
return keyname, ctx.Expiry(), nil
138136
}
139137

140138
// NegotiateContext exchanges RFC 2930 TKEY records with the indicated DNS

gss/sspi.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,12 @@ func (c *Client) negotiateContext(host string, creds *sspi.Credentials) (string,
116116
}
117117
}
118118

119-
expiry := time.Unix(int64(tkey.Expiration), 0)
120-
121119
c.m.Lock()
122120
defer c.m.Unlock()
123121

124122
c.ctx[keyname] = ctx
125123

126-
return keyname, expiry, nil
124+
return keyname, ctx.Expiry(), nil
127125
}
128126

129127
// NegotiateContext exchanges RFC 2930 TKEY records with the indicated DNS

0 commit comments

Comments
 (0)