Skip to content

Commit

Permalink
server referral
Browse files Browse the repository at this point in the history
  • Loading branch information
jcmturner committed Oct 17, 2017
1 parent c1f7873 commit ab3cf9b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
13 changes: 9 additions & 4 deletions client/TGSExchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

// TGSExchange performs a TGS exchange to retrieve a ticket to the specified SPN.
// The ticket retrieved is added to the client's cache.
func (cl *Client) TGSExchange(spn types.PrincipalName, kdcRealm string, tkt messages.Ticket, sessionKey types.EncryptionKey, renewal bool) (tgsReq messages.TGSReq, tgsRep messages.TGSRep, err error) {
func (cl *Client) TGSExchange(spn types.PrincipalName, kdcRealm string, tkt messages.Ticket, sessionKey types.EncryptionKey, renewal bool, referral int) (tgsReq messages.TGSReq, tgsRep messages.TGSRep, err error) {
//// Check what sessions we have for this SPN.
//// Will get the session to the default realm if one does not exist for requested SPN
//sess, err := cl.GetSessionFromPrincipalName(spn)
Expand Down Expand Up @@ -39,13 +39,18 @@ func (cl *Client) TGSExchange(spn types.PrincipalName, kdcRealm string, tkt mess
return tgsReq, tgsRep, krberror.Errorf(err, krberror.EncodingError, "TGS Exchange Error: failed to process the TGS_REP")
}
if tgsRep.Ticket.SName.NameType == nametype.KRB_NT_SRV_INST {
if referral > 5 {
return tgsReq, tgsRep, krberror.Errorf(err, krberror.KRBMsgError, "maximum number of referrals exceeded")
}
// Server referral https://tools.ietf.org/html/rfc6806.html#section-8
// The TGS Rep contains a TGT for another domain as the service resides in that domain.
if ok, err := tgsRep.IsValid(cl.Config, tgsReq); !ok {
return tgsReq, tgsRep, krberror.Errorf(err, krberror.EncodingError, "TGS Exchange Error: TGS_REP is not valid")
}
// The TGS Rep contains a TGT for another domain as the service resides in that domain.
cl.AddSession(tgsRep.Ticket, tgsRep.DecryptedEncPart)
realm := tgsRep.Ticket.SName.NameString[1]
return cl.TGSExchange(spn, realm, tgsRep.Ticket, tgsRep.DecryptedEncPart.Key, false)
referral += 1
return cl.TGSExchange(spn, realm, tgsRep.Ticket, tgsRep.DecryptedEncPart.Key, false, referral)
}
if ok, err := tgsRep.IsValid(cl.Config, tgsReq); !ok {
return tgsReq, tgsRep, krberror.Errorf(err, krberror.EncodingError, "TGS Exchange Error: TGS_REP is not valid")
Expand Down Expand Up @@ -79,7 +84,7 @@ func (cl *Client) GetServiceTicket(spn string) (messages.Ticket, types.Encryptio
return tkt, skey, err
}
}
_, tgsRep, err := cl.TGSExchange(princ, sess.TGT.Realm, sess.TGT, sess.SessionKey, false)
_, tgsRep, err := cl.TGSExchange(princ, sess.TGT.Realm, sess.TGT, sess.SessionKey, false, 0)
if err != nil {
return tkt, skey, err
}
Expand Down
2 changes: 1 addition & 1 deletion client/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (cl *Client) GetCachedTicket(spn string) (messages.Ticket, types.Encryption
// RenewTicket renews a cache entry ticket
func (cl *Client) RenewTicket(e CacheEntry) (CacheEntry, error) {
spn := e.Ticket.SName
_, tgsRep, err := cl.TGSExchange(spn, e.Ticket.Realm, e.Ticket, e.SessionKey, true)
_, tgsRep, err := cl.TGSExchange(spn, e.Ticket.Realm, e.Ticket, e.SessionKey, true, 0)
if err != nil {
return e, err
}
Expand Down
1 change: 1 addition & 0 deletions client/client_ad_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func TestClient_GetServiceTicket_AD_TRUST_USER_DOMAIN(t *testing.T) {
c, _ := config.NewConfigFromString(testdata.TEST_KRB5CONF)
c.Realms[0].KDC = []string{testdata.TEST_KDC_AD_TRUST_USER_DOMAIN}
c.LibDefaults.DefaultRealm = "USER.GOKRB5"
c.LibDefaults.Canonicalize = true
cl := NewClientWithKeytab("testuser1", "USER.GOKRB5", kt)
c.LibDefaults.DefaultTktEnctypes = []string{"rc4-hmac"}
c.LibDefaults.DefaultTktEnctypeIDs = []int{etypeID.ETypesByName["rc4-hmac"]}
Expand Down
2 changes: 1 addition & 1 deletion client/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (cl *Client) RenewTGT(s *session) error {
NameType: nametype.KRB_NT_SRV_INST,
NameString: []string{"krbtgt", s.Realm},
}
_, tgsRep, err := cl.TGSExchange(spn, s.TGT.Realm, s.TGT, s.SessionKey, true)
_, tgsRep, err := cl.TGSExchange(spn, s.TGT.Realm, s.TGT, s.SessionKey, true, 0)
if err != nil {
return krberror.Errorf(err, krberror.KRBMsgError, "Error renewing TGT")
}
Expand Down

0 comments on commit ab3cf9b

Please sign in to comment.