Skip to content

Commit

Permalink
fix: Use expiry from negotiated context (#121)
Browse files Browse the repository at this point in the history
Fixes #6
  • Loading branch information
bodgit committed Oct 13, 2023
1 parent 7c134dd commit 0d4e7fc
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
10 changes: 4 additions & 6 deletions gss/apcera.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,10 @@ func (c *Client) NegotiateContext(host string) (keyname string, expiry time.Time
var (
input *gssapi.Buffer
ctx *gssapi.CtxId
tkey *dns.TKEY
)

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

ctx = nctx
ctx, expiry = nctx, time.Now().UTC().Add(duration)

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

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

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

expiry = time.Unix(int64(tkey.Expiration), 0)

c.m.Lock()
defer c.m.Unlock()

Expand Down
4 changes: 1 addition & 3 deletions gss/gokrb5.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,12 @@ func (c *Client) negotiateContext(host string, options []wrapper.Option[wrapper.
}
}

expiry := time.Unix(int64(tkey.Expiration), 0)

c.m.Lock()
defer c.m.Unlock()

c.ctx[keyname] = ctx

return keyname, expiry, nil
return keyname, ctx.Expiry(), nil
}

// NegotiateContext exchanges RFC 2930 TKEY records with the indicated DNS
Expand Down
4 changes: 1 addition & 3 deletions gss/sspi.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,12 @@ func (c *Client) negotiateContext(host string, creds *sspi.Credentials) (string,
}
}

expiry := time.Unix(int64(tkey.Expiration), 0)

c.m.Lock()
defer c.m.Unlock()

c.ctx[keyname] = ctx

return keyname, expiry, nil
return keyname, ctx.Expiry(), nil
}

// NegotiateContext exchanges RFC 2930 TKEY records with the indicated DNS
Expand Down

0 comments on commit 0d4e7fc

Please sign in to comment.