Sfoglia il codice sorgente

fix types for nonce size

Jonathan Turner 8 anni fa
parent
commit
9ff5fcbad4

+ 72 - 0
client/client_dns_test.go

@@ -0,0 +1,72 @@
+// +build dns
+
+package client
+
+import (
+	"encoding/hex"
+	"github.com/stretchr/testify/assert"
+	"gopkg.in/jcmturner/gokrb5.v3/keytab"
+)
+
+func TestResolveKDC(t *testing.T) {
+	//ns := os.Getenv("DNSUTILS_OVERRIDE_NS")
+	//if ns == "" {
+	//	os.Setenv("DNSUTILS_OVERRIDE_NS", testdata.TEST_NS)
+	//}
+	c, _ := config.NewConfigFromString(testdata.TEST_KRB5CONF)
+	c.LibDefaults.DNSLookupKDC = true
+	var cl Client
+	cl.WithConfig(c)
+	count, res, err := cl.resolveKDC(c.LibDefaults.DefaultRealm, true)
+	if err != nil {
+		t.Errorf("error resolving KDC via DNS TCP: %v", err)
+	}
+	assert.Equal(t, 5, count, "Number of SRV records not as expected: %v", res)
+	assert.Equal(t, count, len(res), "Map size does not match: %v", res)
+	t.Logf("res: %v", res)
+	expected := []string{
+		"kdc.test.gokrb5:88",
+		"kdc1a.test.gokrb5:88",
+		"kdc2a.test.gokrb5:88",
+		"kdc1b.test.gokrb5:88",
+		"kdc2b.test.gokrb5:88",
+	}
+	for _, s := range expected {
+		var found bool
+		for _, v := range res {
+			if s == v {
+				found = true
+				break
+			}
+		}
+		assert.True(t, found, "Record %s not found in results", s)
+	}
+	c.LibDefaults.DNSLookupKDC = false
+	_, res, err = cl.resolveKDC(c.LibDefaults.DefaultRealm, true)
+	if err != nil {
+		t.Errorf("error resolving KDCs from config: %v", err)
+	}
+	assert.Equal(t, "10.80.88.88:88", res[1], "KDC not read from config as expected")
+}
+
+func TestClient_Login_DNSKDCs(t *testing.T) {
+	//ns := os.Getenv("DNSUTILS_OVERRIDE_NS")
+	//if ns == "" {
+	//	os.Setenv("DNSUTILS_OVERRIDE_NS", testdata.TEST_NS)
+	//}
+	c, _ := config.NewConfigFromString(testdata.TEST_KRB5CONF)
+	// Set to lookup KDCs in DNS
+	c.LibDefaults.DNSLookupKDC = true
+	//Blank out the KDCs to ensure they are not being used
+	c.Realms = []config.Realm{}
+
+	b, err := hex.DecodeString(testdata.TESTUSER1_KEYTAB)
+	kt, _ := keytab.Parse(b)
+	cl := NewClientWithKeytab("testuser1", "TEST.GOKRB5", kt)
+	cl.WithConfig(c)
+
+	err = cl.Login()
+	if err != nil {
+		t.Errorf("Error on logging in using DNS lookup of KDCs: %v\n", err)
+	}
+}

+ 0 - 63
client/client_integration_test.go

@@ -420,69 +420,6 @@ func TestNewClientFromCCache(t *testing.T) {
 	}
 }
 
-func TestResolveKDC(t *testing.T) {
-	//ns := os.Getenv("DNSUTILS_OVERRIDE_NS")
-	//if ns == "" {
-	//	os.Setenv("DNSUTILS_OVERRIDE_NS", testdata.TEST_NS)
-	//}
-	c, _ := config.NewConfigFromString(testdata.TEST_KRB5CONF)
-	c.LibDefaults.DNSLookupKDC = true
-	var cl Client
-	cl.WithConfig(c)
-	count, res, err := cl.resolveKDC(c.LibDefaults.DefaultRealm, true)
-	if err != nil {
-		t.Errorf("error resolving KDC via DNS TCP: %v", err)
-	}
-	assert.Equal(t, 5, count, "Number of SRV records not as expected: %v", res)
-	assert.Equal(t, count, len(res), "Map size does not match: %v", res)
-	t.Logf("res: %v", res)
-	expected := []string{
-		"kdc.test.gokrb5:88",
-		"kdc1a.test.gokrb5:88",
-		"kdc2a.test.gokrb5:88",
-		"kdc1b.test.gokrb5:88",
-		"kdc2b.test.gokrb5:88",
-	}
-	for _, s := range expected {
-		var found bool
-		for _, v := range res {
-			if s == v {
-				found = true
-				break
-			}
-		}
-		assert.True(t, found, "Record %s not found in results", s)
-	}
-	c.LibDefaults.DNSLookupKDC = false
-	_, res, err = cl.resolveKDC(c.LibDefaults.DefaultRealm, true)
-	if err != nil {
-		t.Errorf("error resolving KDCs from config: %v", err)
-	}
-	assert.Equal(t, "10.80.88.88:88", res[1], "KDC not read from config as expected")
-}
-
-func TestClient_Login_DNSKDCs(t *testing.T) {
-	//ns := os.Getenv("DNSUTILS_OVERRIDE_NS")
-	//if ns == "" {
-	//	os.Setenv("DNSUTILS_OVERRIDE_NS", testdata.TEST_NS)
-	//}
-	c, _ := config.NewConfigFromString(testdata.TEST_KRB5CONF)
-	// Set to lookup KDCs in DNS
-	c.LibDefaults.DNSLookupKDC = true
-	//Blank out the KDCs to ensure they are not being used
-	c.Realms = []config.Realm{}
-
-	b, err := hex.DecodeString(testdata.TESTUSER1_KEYTAB)
-	kt, _ := keytab.Parse(b)
-	cl := NewClientWithKeytab("testuser1", "TEST.GOKRB5", kt)
-	cl.WithConfig(c)
-
-	err = cl.Login()
-	if err != nil {
-		t.Errorf("Error on logging in using DNS lookup of KDCs: %v\n", err)
-	}
-}
-
 // Login to the TEST.GOKRB5 domain and request service ticket for resource in the RESDOM.GOKRB5 domain.
 // There is a trust between the two domains.
 func TestClient_GetServiceTicket_Trusted_Resource_Domain(t *testing.T) {

+ 2 - 2
messages/KDCRep_test.go

@@ -257,7 +257,7 @@ func TestUnmarshalASRepDecodeAndDecrypt(t *testing.T) {
 	}
 	assert.Equal(t, int32(18), asRep.DecryptedEncPart.Key.KeyType, "KeyType in decrypted EncPart not as expected")
 	assert.IsType(t, time.Time{}, asRep.DecryptedEncPart.LastReqs[0].LRValue, "LastReqs did not have a time value")
-	assert.Equal(t, int64(2069991465), asRep.DecryptedEncPart.Nonce, "Nonce value not as expected")
+	assert.Equal(t, 2069991465, asRep.DecryptedEncPart.Nonce, "Nonce value not as expected")
 	assert.IsType(t, time.Time{}, asRep.DecryptedEncPart.KeyExpiration, "Key expiration not a time type")
 	assert.IsType(t, time.Time{}, asRep.DecryptedEncPart.AuthTime, "AuthTime not a time type")
 	assert.IsType(t, time.Time{}, asRep.DecryptedEncPart.StartTime, "StartTime not a time type")
@@ -297,7 +297,7 @@ func TestUnmarshalASRepDecodeAndDecrypt_withPassword(t *testing.T) {
 	}
 	assert.Equal(t, int32(18), asRep.DecryptedEncPart.Key.KeyType, "KeyType in decrypted EncPart not as expected")
 	assert.IsType(t, time.Time{}, asRep.DecryptedEncPart.LastReqs[0].LRValue, "LastReqs did not have a time value")
-	assert.Equal(t, int64(2069991465), asRep.DecryptedEncPart.Nonce, "Nonce value not as expected")
+	assert.Equal(t, 2069991465, asRep.DecryptedEncPart.Nonce, "Nonce value not as expected")
 	assert.IsType(t, time.Time{}, asRep.DecryptedEncPart.KeyExpiration, "Key expiration not a time type")
 	assert.IsType(t, time.Time{}, asRep.DecryptedEncPart.AuthTime, "AuthTime not a time type")
 	assert.IsType(t, time.Time{}, asRep.DecryptedEncPart.StartTime, "StartTime not a time type")

+ 1 - 1
messages/KRBCred.go

@@ -31,7 +31,7 @@ type KRBCred struct {
 // EncKrbCredPart is the encrypted part of KRB_CRED.
 type EncKrbCredPart struct {
 	TicketInfo []KrbCredInfo     `asn1:"explicit,tag:0"`
-	Nouce      int64             `asn1:"optional,explicit,tag:1"`
+	Nouce      int               `asn1:"optional,explicit,tag:1"`
 	Timestamp  time.Time         `asn1:"generalized,optional,explicit,tag:2"`
 	Usec       int               `asn1:"optional,explicit,tag:3"`
 	SAddress   types.HostAddress `asn1:"optional,explicit,tag:4"`

+ 1 - 1
testdata/test_vectors.go

@@ -10,7 +10,7 @@ const (
 	TEST_PRINCIPALNAME_NAMETYPE   int32 = 1
 	TEST_KVNO                           = 5
 	TEST_ETYPE                    int32 = 0
-	TEST_NONCE                    int64 = 42
+	TEST_NONCE                          = 42
 	TEST_AUTHORIZATION_DATA_TYPE  int32 = 1
 	TEST_AUTHORIZATION_DATA_VALUE       = "foobar"
 	TEST_PADATA_TYPE              int32 = 13