Parcourir la source

ticket enc part tests

Jonathan Turner il y a 9 ans
Parent
commit
4a1fba4738
3 fichiers modifiés avec 73 ajouts et 4 suppressions
  1. 2 2
      testdata/test_vectors.go
  2. 6 1
      types/Ticket.go
  3. 65 1
      types/Ticket_test.go

+ 2 - 2
testdata/test_vectors.go

@@ -25,8 +25,8 @@ var TestVectors = map[string]string{
 	"encode_krb5_authenticator(optionalsNULL)":                   "624F304DA003020105A1101B0E415448454E412E4D49542E454455A21A3018A003020101A111300F1B066866747361691B056578747261A405020301E240A511180F31393934303631303036303331375A",
 	"encode_krb5_ticket":                                         "615C305AA003020105A1101B0E415448454E412E4D49542E454455A21A3018A003020101A111300F1B066866747361691B056578747261A3253023A003020100A103020105A21704156B726241534E2E312074657374206D657373616765",
 	"encode_krb5_keyblock":                                       "3011A003020101A10A04083132333435363738",
-	//"encode_krb5_enc_tkt_part":                                   "6382011430820110A007030500FEDCBA98A1133011A003020101A10A04083132333435363738A2101B0E415448454E412E4D49542E454455A31A3018A003020101A111300F1B066866747361691B056578747261A42E302CA003020101A12504234544552C4D49542E2C415448454E412E2C57415348494E47544F4E2E4544552C43532EA511180F31393934303631303036303331375AA611180F31393934303631303036303331375AA711180F31393934303631303036303331375AA811180F31393934303631303036303331375AA920301E300DA003020102A106040412D00023300DA003020102A106040412D00023AA243022300FA003020101A1080406666F6F626172300FA003020101A1080406666F6F626172",
-	//"encode_krb5_enc_tkt_part(optionalsNULL)":                    "6381A53081A2A007030500FEDCBA98A1133011A003020101A10A04083132333435363738A2101B0E415448454E412E4D49542E454455A31A3018A003020101A111300F1B066866747361691B056578747261A42E302CA003020101A12504234544552C4D49542E2C415448454E412E2C57415348494E47544F4E2E4544552C43532EA511180F31393934303631303036303331375AA711180F31393934303631303036303331375A",
+	"encode_krb5_enc_tkt_part":                                   "6382011430820110A007030500FEDCBA98A1133011A003020101A10A04083132333435363738A2101B0E415448454E412E4D49542E454455A31A3018A003020101A111300F1B066866747361691B056578747261A42E302CA003020101A12504234544552C4D49542E2C415448454E412E2C57415348494E47544F4E2E4544552C43532EA511180F31393934303631303036303331375AA611180F31393934303631303036303331375AA711180F31393934303631303036303331375AA811180F31393934303631303036303331375AA920301E300DA003020102A106040412D00023300DA003020102A106040412D00023AA243022300FA003020101A1080406666F6F626172300FA003020101A1080406666F6F626172",
+	"encode_krb5_enc_tkt_part(optionalsNULL)":                    "6381A53081A2A007030500FEDCBA98A1133011A003020101A10A04083132333435363738A2101B0E415448454E412E4D49542E454455A31A3018A003020101A111300F1B066866747361691B056578747261A42E302CA003020101A12504234544552C4D49542E2C415448454E412E2C57415348494E47544F4E2E4544552C43532EA511180F31393934303631303036303331375AA711180F31393934303631303036303331375A",
 	//"encode_krb5_enc_kdc_rep_part":                               "7A82010E3082010AA0133011A003020101A10A04083132333435363738A13630343018A0030201FBA111180F31393934303631303036303331375A3018A0030201FBA111180F31393934303631303036303331375AA20302012AA311180F31393934303631303036303331375AA407030500FEDCBA98A511180F31393934303631303036303331375AA611180F31393934303631303036303331375AA711180F31393934303631303036303331375AA811180F31393934303631303036303331375AA9101B0E415448454E412E4D49542E454455AA1A3018A003020101A111300F1B066866747361691B056578747261AB20301E300DA003020102A106040412D00023300DA003020102A106040412D00023",
 	//"encode_krb5_enc_kdc_rep_part(optionalsNULL)":                "7A81B23081AFA0133011A003020101A10A04083132333435363738A13630343018A0030201FBA111180F31393934303631303036303331375A3018A0030201FBA111180F31393934303631303036303331375AA20302012AA407030500FE5CBA98A511180F31393934303631303036303331375AA711180F31393934303631303036303331375AA9101B0E415448454E412E4D49542E454455AA1A3018A003020101A111300F1B066866747361691B056578747261",
 	"encode_krb5_as_rep":                                         "6B81EA3081E7A003020105A10302010BA22630243010A10302010DA209040770612D646174613010A10302010DA209040770612D64617461A3101B0E415448454E412E4D49542E454455A41A3018A003020101A111300F1B066866747361691B056578747261A55E615C305AA003020105A1101B0E415448454E412E4D49542E454455A21A3018A003020101A111300F1B066866747361691B056578747261A3253023A003020100A103020105A21704156B726241534E2E312074657374206D657373616765A6253023A003020100A103020105A21704156B726241534E2E312074657374206D657373616765",

+ 6 - 1
types/Ticket.go

@@ -27,7 +27,7 @@ type EncTicketPart struct {
 	StartTime         time.Time         `asn1:"explicit,optional,tag:6"`
 	EndTime           time.Time         `asn1:"explicit,tag:7"`
 	RenewTill         time.Time         `asn1:"explicit,optional,tag:8"`
-	CAddr             HostAddress       `asn1:"explicit,optional,tag:9"`
+	CAddr             HostAddresses       `asn1:"explicit,optional,tag:9"`
 	AuthorizationData AuthorizationData `asn1:"explicit,optional,tag:10"`
 }
 
@@ -41,6 +41,11 @@ func (t *Ticket) Unmarshal(b []byte) error {
 	return err
 }
 
+func (t *EncTicketPart) Unmarshal(b []byte) error {
+	_, err := asn1.UnmarshalWithParams(b, t, fmt.Sprintf("application,explicit,tag:%d", asnAppTag.EncTicketPart))
+	return err
+}
+
 func UnmarshalTicket(b []byte) (t Ticket, err error) {
 	_, err = asn1.UnmarshalWithParams(b, &t, fmt.Sprintf("application,explicit,tag:%d", asnAppTag.Ticket))
 	return

+ 65 - 1
types/Ticket_test.go

@@ -5,12 +5,13 @@ import (
 	"github.com/jcmturner/gokrb5/testdata"
 	"github.com/stretchr/testify/assert"
 	"testing"
+	"time"
+	"fmt"
 )
 
 func TestUnmarshalTicket(t *testing.T) {
 	var a Ticket
 	v := "encode_krb5_ticket"
-	//t.Logf("Starting unmarshal tests of %s", v)
 	b, err := hex.DecodeString(testdata.TestVectors[v])
 	if err != nil {
 		t.Fatalf("Test vector read error of %s: %v\n", v, err)
@@ -29,3 +30,66 @@ func TestUnmarshalTicket(t *testing.T) {
 	assert.Equal(t, testdata.TEST_KVNO, a.EncPart.KVNO, "KNVO of Ticket EncPart not as expected")
 	assert.Equal(t, []byte(testdata.TEST_CIPHERTEXT), a.EncPart.Cipher, "Cipher of Ticket EncPart not as expected")
 }
+
+func TestUnmarshalEncTicketPart(t *testing.T) {
+	var a EncTicketPart
+	v := "encode_krb5_enc_tkt_part"
+	b, err := hex.DecodeString(testdata.TestVectors[v])
+	if err != nil {
+		t.Fatalf("Test vector read error of %s: %v\n", v, err)
+	}
+	err = a.Unmarshal(b)
+	if err != nil {
+		t.Fatalf("Unmarshal error of %s: %v\n", v, err)
+	}
+	//Parse the test time value into a time.Time type
+	tt, _ := time.Parse(testdata.TEST_TIME_FORMAT, testdata.TEST_TIME)
+
+	assert.Equal(t, "fedcba98", hex.EncodeToString(a.Flags.Bytes), "Flags not as expected")
+	assert.Equal(t, 1, a.Key.KeyType, "Key type not as expected")
+	assert.Equal(t, []byte("12345678"), a.Key.KeyValue, "Key value not as expected")
+	assert.Equal(t, testdata.TEST_REALM, a.CRealm, "CRealm not as expected")
+	assert.Equal(t, testdata.TEST_PRINCIPALNAME_NAMETYPE, a.CName.NameType, "CName type not as expected")
+	assert.Equal(t, testdata.TEST_PRINCIPALNAME_NAMESTRING, a.CName.NameString, "CName string entries not as expected")
+	assert.Equal(t, 1, a.Transited.TRType, "Transisted type not as expected")
+	assert.Equal(t, []byte("EDU,MIT.,ATHENA.,WASHINGTON.EDU,CS."), a.Transited.Contents, "Transisted content not as expected")
+	assert.Equal(t, tt, a.AuthTime, "Auth time not as expected")
+	assert.Equal(t, tt, a.StartTime, "Start time not as expected")
+	assert.Equal(t, tt, a.EndTime, "End time not as expected")
+	assert.Equal(t, tt, a.RenewTill, "Renew Till time not as expected")
+	assert.Equal(t, 2, len(a.CAddr), "Number of client addresses not as expected")
+	for i, addr := range a.CAddr {
+		assert.Equal(t, 2, addr.AddrType, fmt.Sprintf("Host address type not as expected for address item %d", i+1))
+		assert.Equal(t, "12d00023", hex.EncodeToString(addr.Address), fmt.Sprintf("Host address not as expected for address item %d", i+1))
+	}
+	for i, ele := range a.AuthorizationData{
+		assert.Equal(t, 1, ele.ADType, fmt.Sprintf("Authorization data type of element %d not as expected", i+1))
+		assert.Equal(t, []byte(testdata.TEST_AUTHORIZATION_DATA_VALUE), ele.ADData, fmt.Sprintf("Authorization data of element %d not as expected", i+1))
+	}
+}
+
+func TestUnmarshalEncTicketPart_optionalsNULL(t *testing.T) {
+	var a EncTicketPart
+	v := "encode_krb5_enc_tkt_part(optionalsNULL)"
+	b, err := hex.DecodeString(testdata.TestVectors[v])
+	if err != nil {
+		t.Fatalf("Test vector read error of %s: %v\n", v, err)
+	}
+	err = a.Unmarshal(b)
+	if err != nil {
+		t.Fatalf("Unmarshal error of %s: %v\n", v, err)
+	}
+	//Parse the test time value into a time.Time type
+	tt, _ := time.Parse(testdata.TEST_TIME_FORMAT, testdata.TEST_TIME)
+
+	assert.Equal(t, "fedcba98", hex.EncodeToString(a.Flags.Bytes), "Flags not as expected")
+	assert.Equal(t, 1, a.Key.KeyType, "Key type not as expected")
+	assert.Equal(t, []byte("12345678"), a.Key.KeyValue, "Key value not as expected")
+	assert.Equal(t, testdata.TEST_REALM, a.CRealm, "CRealm not as expected")
+	assert.Equal(t, testdata.TEST_PRINCIPALNAME_NAMETYPE, a.CName.NameType, "CName type not as expected")
+	assert.Equal(t, testdata.TEST_PRINCIPALNAME_NAMESTRING, a.CName.NameString, "CName string entries not as expected")
+	assert.Equal(t, 1, a.Transited.TRType, "Transisted type not as expected")
+	assert.Equal(t, []byte("EDU,MIT.,ATHENA.,WASHINGTON.EDU,CS."), a.Transited.Contents, "Transisted content not as expected")
+	assert.Equal(t, tt, a.AuthTime, "Auth time not as expected")
+	assert.Equal(t, tt, a.EndTime, "End time not as expected")
+}