KDCRep_test.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. package messages
  2. import (
  3. "encoding/hex"
  4. "fmt"
  5. "testing"
  6. "time"
  7. "github.com/stretchr/testify/assert"
  8. "gopkg.in/jcmturner/gokrb5.v7/credentials"
  9. "gopkg.in/jcmturner/gokrb5.v7/iana"
  10. "gopkg.in/jcmturner/gokrb5.v7/iana/etypeID"
  11. "gopkg.in/jcmturner/gokrb5.v7/iana/msgtype"
  12. "gopkg.in/jcmturner/gokrb5.v7/iana/nametype"
  13. "gopkg.in/jcmturner/gokrb5.v7/iana/patype"
  14. "gopkg.in/jcmturner/gokrb5.v7/keytab"
  15. "gopkg.in/jcmturner/gokrb5.v7/test/testdata"
  16. )
  17. const (
  18. testuser1EType18Keytab = "05020000004b0001000b544553542e474f4b5242350009746573747573657231000000015898e0770100120020bbdc430aab7e2d4622a0b6951481453b0962e9db8e2f168942ad175cda6d9de900000001"
  19. testuser1EType18ASREP = "6b8202f3308202efa003020105a10302010ba22e302c302aa103020113a2230421301f301da003020112a1161b14544553542e474f4b524235746573747573657231a30d1b0b544553542e474f4b524235a4163014a003020101a10d300b1b09746573747573657231a582015a6182015630820152a003020105a10d1b0b544553542e474f4b524235a220301ea003020102a11730151b066b72627467741b0b544553542e474f4b524235a382011830820114a003020112a103020101a28201060482010237e486e32cd18ab1ac9f8d42e93f8babd7b3497084cc5599f18ec61961c6d5242d350354d99d67a7604c451116188d16cb719e84377212eac2743440e8c504ef69c755e489cc6b65f935dd032bfc076f9b2c56d816197845b8fe857d738bc59712787631a50e86833d1b0e4732c8712c856417a6a257758e7d01d3182adb3233f0dde65d228c240ed26aa1af69f8d765dc0bc69096fdb037a75af220fea176839528d44b70f7dabfaa2ea506de1296f847176a60c501fd8cef8e0a51399bb6d5f753962d96292e93ffe344c6630db912931d46d88c0279f00719e22d0efcfd4ee33a702d0b660c1f13970a9beec12c0c8af3dda68bd81ac1fe3f126d2a24ebb445c5a682012c30820128a003020112a282011f0482011bb149cc16018072c4c18788d95a33aba540e52c11b54a93e67e788d05de75d8f3d4aa1afafbbfa6fde3eb40e5aa1890644cea2607efd5213a3fd00345b02eeb9ae1b589f36c74c689cd4ec1239dfe61e42ba6afa33f6240e3cfab291e4abb465d273302dbf7dbd148a299a9369044dd03377c1687e7dd36aa66501284a4ca50c0a7b08f4f87aecfa23b0dd0b11490e3ad330906dab715de81fc52f120d09c39990b8b5330d4601cc396b2ed258834329c4cc02c563a12de3ef9bf11e946258bc2ab5257f4caa4d443a7daf0fc25f6f531c2fcba88af8ca55c85300997cd05abbea52811fe2d038ba8f62fc8e3bc71ce04362d356ea2e1df8ac55c784c53cfb07817d48e39fe99fc8788040d98209c79dcf044d97e80de9f47824646"
  20. testRealm = "TEST.GOKRB5"
  21. testUser = "testuser1"
  22. testUserPassword = "passwordvalue"
  23. )
  24. func TestUnmarshalASRep(t *testing.T) {
  25. t.Parallel()
  26. var a ASRep
  27. b, err := hex.DecodeString(testdata.MarshaledKRB5as_rep)
  28. if err != nil {
  29. t.Fatalf("Test vector read error: %v", err)
  30. }
  31. err = a.Unmarshal(b)
  32. if err != nil {
  33. t.Fatalf("Unmarshal error: %v", err)
  34. }
  35. assert.Equal(t, iana.PVNO, a.PVNO, "PVNO not as expected")
  36. assert.Equal(t, msgtype.KRB_AS_REP, a.MsgType, "MsgType not as expected")
  37. assert.Equal(t, 2, len(a.PAData), "Number of PAData items in the sequence not as expected")
  38. for i, pa := range a.PAData {
  39. assert.Equal(t, patype.PA_SAM_RESPONSE, pa.PADataType, fmt.Sprintf("PAData type for entry %d not as expected", i+1))
  40. assert.Equal(t, []byte(testdata.TEST_PADATA_VALUE), pa.PADataValue, fmt.Sprintf("PAData valye for entry %d not as expected", i+1))
  41. }
  42. assert.Equal(t, testdata.TEST_REALM, a.CRealm, "Client Realm not as expected")
  43. assert.Equal(t, nametype.KRB_NT_PRINCIPAL, a.CName.NameType, "CName NameType not as expected")
  44. assert.Equal(t, len(testdata.TEST_PRINCIPALNAME_NAMESTRING), len(a.CName.NameString), "CName does not have the expected number of NameStrings")
  45. assert.Equal(t, testdata.TEST_PRINCIPALNAME_NAMESTRING, a.CName.NameString, "CName entries not as expected")
  46. assert.Equal(t, iana.PVNO, a.Ticket.TktVNO, "TktVNO not as expected")
  47. assert.Equal(t, testdata.TEST_REALM, a.Ticket.Realm, "Ticket Realm not as expected")
  48. assert.Equal(t, nametype.KRB_NT_PRINCIPAL, a.Ticket.SName.NameType, "Ticket service nametype not as expected")
  49. assert.Equal(t, len(testdata.TEST_PRINCIPALNAME_NAMESTRING), len(a.Ticket.SName.NameString), "SName in ticket does not have the expected number of NameStrings")
  50. assert.Equal(t, testdata.TEST_PRINCIPALNAME_NAMESTRING, a.Ticket.SName.NameString, "Ticket SName entries not as expected")
  51. assert.Equal(t, testdata.TEST_ETYPE, a.Ticket.EncPart.EType, "Etype of ticket encrypted part not as expected")
  52. assert.Equal(t, iana.PVNO, a.Ticket.EncPart.KVNO, "Ticket encrypted part KVNO not as expected")
  53. assert.Equal(t, testdata.TEST_CIPHERTEXT, string(a.Ticket.EncPart.Cipher), "Ticket encrypted part cipher not as expected")
  54. assert.Equal(t, testdata.TEST_ETYPE, a.EncPart.EType, "Etype of encrypted part not as expected")
  55. assert.Equal(t, iana.PVNO, a.EncPart.KVNO, "Encrypted part KVNO not as expected")
  56. assert.Equal(t, testdata.TEST_CIPHERTEXT, string(a.EncPart.Cipher), "Ticket encrypted part cipher not as expected")
  57. }
  58. func TestUnmarshalASRep_optionalsNULL(t *testing.T) {
  59. t.Parallel()
  60. var a ASRep
  61. b, err := hex.DecodeString(testdata.MarshaledKRB5as_repOptionalsNULL)
  62. if err != nil {
  63. t.Fatalf("Test vector read error: %v", err)
  64. }
  65. err = a.Unmarshal(b)
  66. if err != nil {
  67. t.Fatalf("Unmarshal error: %v", err)
  68. }
  69. assert.Equal(t, iana.PVNO, a.PVNO, "PVNO not as expected")
  70. assert.Equal(t, msgtype.KRB_AS_REP, a.MsgType, "MsgType not as expected")
  71. assert.Equal(t, 0, len(a.PAData), "Number of PAData items in the sequence not as expected")
  72. assert.Equal(t, testdata.TEST_REALM, a.CRealm, "Client Realm not as expected")
  73. assert.Equal(t, nametype.KRB_NT_PRINCIPAL, a.CName.NameType, "CName NameType not as expected")
  74. assert.Equal(t, len(testdata.TEST_PRINCIPALNAME_NAMESTRING), len(a.CName.NameString), "CName does not have the expected number of NameStrings")
  75. assert.Equal(t, testdata.TEST_PRINCIPALNAME_NAMESTRING, a.CName.NameString, "CName entries not as expected")
  76. assert.Equal(t, iana.PVNO, a.Ticket.TktVNO, "TktVNO not as expected")
  77. assert.Equal(t, testdata.TEST_REALM, a.Ticket.Realm, "Ticket Realm not as expected")
  78. assert.Equal(t, nametype.KRB_NT_PRINCIPAL, a.Ticket.SName.NameType, "Ticket service nametype not as expected")
  79. assert.Equal(t, len(testdata.TEST_PRINCIPALNAME_NAMESTRING), len(a.Ticket.SName.NameString), "SName in ticket does not have the expected number of NameStrings")
  80. assert.Equal(t, testdata.TEST_PRINCIPALNAME_NAMESTRING, a.Ticket.SName.NameString, "Ticket SName entries not as expected")
  81. assert.Equal(t, testdata.TEST_ETYPE, a.Ticket.EncPart.EType, "Etype of ticket encrypted part not as expected")
  82. assert.Equal(t, iana.PVNO, a.Ticket.EncPart.KVNO, "Ticket encrypted part KVNO not as expected")
  83. assert.Equal(t, testdata.TEST_CIPHERTEXT, string(a.Ticket.EncPart.Cipher), "Ticket encrypted part cipher not as expected")
  84. assert.Equal(t, testdata.TEST_ETYPE, a.EncPart.EType, "Etype of encrypted part not as expected")
  85. assert.Equal(t, iana.PVNO, a.EncPart.KVNO, "Encrypted part KVNO not as expected")
  86. assert.Equal(t, testdata.TEST_CIPHERTEXT, string(a.EncPart.Cipher), "Ticket encrypted part cipher not as expected")
  87. }
  88. func TestUnmarshalTGSRep(t *testing.T) {
  89. t.Parallel()
  90. var a TGSRep
  91. b, err := hex.DecodeString(testdata.MarshaledKRB5tgs_rep)
  92. if err != nil {
  93. t.Fatalf("Test vector read error: %v", err)
  94. }
  95. err = a.Unmarshal(b)
  96. if err != nil {
  97. t.Fatalf("Unmarshal error: %v", err)
  98. }
  99. assert.Equal(t, iana.PVNO, a.PVNO, "PVNO not as expected")
  100. assert.Equal(t, msgtype.KRB_TGS_REP, a.MsgType, "MsgType not as expected")
  101. assert.Equal(t, 2, len(a.PAData), "Number of PAData items in the sequence not as expected")
  102. for i, pa := range a.PAData {
  103. assert.Equal(t, patype.PA_SAM_RESPONSE, pa.PADataType, fmt.Sprintf("PAData type for entry %d not as expected", i+1))
  104. assert.Equal(t, []byte(testdata.TEST_PADATA_VALUE), pa.PADataValue, fmt.Sprintf("PAData valye for entry %d not as expected", i+1))
  105. }
  106. assert.Equal(t, testdata.TEST_REALM, a.CRealm, "Client Realm not as expected")
  107. assert.Equal(t, nametype.KRB_NT_PRINCIPAL, a.CName.NameType, "CName NameType not as expected")
  108. assert.Equal(t, len(testdata.TEST_PRINCIPALNAME_NAMESTRING), len(a.CName.NameString), "CName does not have the expected number of NameStrings")
  109. assert.Equal(t, testdata.TEST_PRINCIPALNAME_NAMESTRING, a.CName.NameString, "CName entries not as expected")
  110. assert.Equal(t, iana.PVNO, a.Ticket.TktVNO, "TktVNO not as expected")
  111. assert.Equal(t, testdata.TEST_REALM, a.Ticket.Realm, "Ticket Realm not as expected")
  112. assert.Equal(t, nametype.KRB_NT_PRINCIPAL, a.Ticket.SName.NameType, "Ticket service nametype not as expected")
  113. assert.Equal(t, len(testdata.TEST_PRINCIPALNAME_NAMESTRING), len(a.Ticket.SName.NameString), "SName in ticket does not have the expected number of NameStrings")
  114. assert.Equal(t, testdata.TEST_PRINCIPALNAME_NAMESTRING, a.Ticket.SName.NameString, "Ticket SName entries not as expected")
  115. assert.Equal(t, testdata.TEST_ETYPE, a.Ticket.EncPart.EType, "Etype of ticket encrypted part not as expected")
  116. assert.Equal(t, iana.PVNO, a.Ticket.EncPart.KVNO, "Ticket encrypted part KVNO not as expected")
  117. assert.Equal(t, testdata.TEST_CIPHERTEXT, string(a.Ticket.EncPart.Cipher), "Ticket encrypted part cipher not as expected")
  118. assert.Equal(t, testdata.TEST_ETYPE, a.EncPart.EType, "Etype of encrypted part not as expected")
  119. assert.Equal(t, iana.PVNO, a.EncPart.KVNO, "Encrypted part KVNO not as expected")
  120. assert.Equal(t, testdata.TEST_CIPHERTEXT, string(a.EncPart.Cipher), "Ticket encrypted part cipher not as expected")
  121. }
  122. func TestUnmarshalTGSRep_optionalsNULL(t *testing.T) {
  123. t.Parallel()
  124. var a TGSRep
  125. b, err := hex.DecodeString(testdata.MarshaledKRB5tgs_repOptionalsNULL)
  126. if err != nil {
  127. t.Fatalf("Test vector read error: %v", err)
  128. }
  129. err = a.Unmarshal(b)
  130. if err != nil {
  131. t.Fatalf("Unmarshal error: %v", err)
  132. }
  133. assert.Equal(t, iana.PVNO, a.PVNO, "PVNO not as expected")
  134. assert.Equal(t, msgtype.KRB_TGS_REP, a.MsgType, "MsgType not as expected")
  135. assert.Equal(t, 0, len(a.PAData), "Number of PAData items in the sequence not as expected")
  136. assert.Equal(t, testdata.TEST_REALM, a.CRealm, "Client Realm not as expected")
  137. assert.Equal(t, nametype.KRB_NT_PRINCIPAL, a.CName.NameType, "CName NameType not as expected")
  138. assert.Equal(t, len(testdata.TEST_PRINCIPALNAME_NAMESTRING), len(a.CName.NameString), "CName does not have the expected number of NameStrings")
  139. assert.Equal(t, testdata.TEST_PRINCIPALNAME_NAMESTRING, a.CName.NameString, "CName entries not as expected")
  140. assert.Equal(t, iana.PVNO, a.Ticket.TktVNO, "TktVNO not as expected")
  141. assert.Equal(t, testdata.TEST_REALM, a.Ticket.Realm, "Ticket Realm not as expected")
  142. assert.Equal(t, nametype.KRB_NT_PRINCIPAL, a.Ticket.SName.NameType, "Ticket service nametype not as expected")
  143. assert.Equal(t, len(testdata.TEST_PRINCIPALNAME_NAMESTRING), len(a.Ticket.SName.NameString), "SName in ticket does not have the expected number of NameStrings")
  144. assert.Equal(t, testdata.TEST_PRINCIPALNAME_NAMESTRING, a.Ticket.SName.NameString, "Ticket SName entries not as expected")
  145. assert.Equal(t, testdata.TEST_ETYPE, a.Ticket.EncPart.EType, "Etype of ticket encrypted part not as expected")
  146. assert.Equal(t, iana.PVNO, a.Ticket.EncPart.KVNO, "Ticket encrypted part KVNO not as expected")
  147. assert.Equal(t, testdata.TEST_CIPHERTEXT, string(a.Ticket.EncPart.Cipher), "Ticket encrypted part cipher not as expected")
  148. assert.Equal(t, testdata.TEST_ETYPE, a.EncPart.EType, "Etype of encrypted part not as expected")
  149. assert.Equal(t, iana.PVNO, a.EncPart.KVNO, "Encrypted part KVNO not as expected")
  150. assert.Equal(t, testdata.TEST_CIPHERTEXT, string(a.EncPart.Cipher), "Ticket encrypted part cipher not as expected")
  151. }
  152. func TestUnmarshalEncKDCRepPart(t *testing.T) {
  153. t.Parallel()
  154. var a EncKDCRepPart
  155. b, err := hex.DecodeString(testdata.MarshaledKRB5enc_kdc_rep_part)
  156. if err != nil {
  157. t.Fatalf("Test vector read error: %v", err)
  158. }
  159. err = a.Unmarshal(b)
  160. if err != nil {
  161. t.Fatalf("Unmarshal error: %v", err)
  162. }
  163. //Parse the test time value into a time.Time type
  164. tt, _ := time.Parse(testdata.TEST_TIME_FORMAT, testdata.TEST_TIME)
  165. assert.Equal(t, int32(1), a.Key.KeyType, "Key type not as expected")
  166. assert.Equal(t, []byte("12345678"), a.Key.KeyValue, "Key value not as expected")
  167. assert.Equal(t, 2, len(a.LastReqs), "Number of last request entries not as expected")
  168. for i, r := range a.LastReqs {
  169. assert.Equal(t, int32(-5), r.LRType, fmt.Sprintf("Last request typ not as expected for last request entry %d", i+1))
  170. assert.Equal(t, tt, r.LRValue, fmt.Sprintf("Last request time value not as expected for last request entry %d", i+1))
  171. }
  172. assert.Equal(t, testdata.TEST_NONCE, a.Nonce, "Nonce not as expected")
  173. assert.Equal(t, tt, a.KeyExpiration, "key expiration time not as expected")
  174. assert.Equal(t, "fedcba98", hex.EncodeToString(a.Flags.Bytes), "Flags not as expected")
  175. assert.Equal(t, tt, a.AuthTime, "Auth time not as expected")
  176. assert.Equal(t, tt, a.StartTime, "Start time not as expected")
  177. assert.Equal(t, tt, a.EndTime, "End time not as expected")
  178. assert.Equal(t, tt, a.RenewTill, "Renew Till time not as expected")
  179. assert.Equal(t, testdata.TEST_REALM, a.SRealm, "SRealm not as expected")
  180. assert.Equal(t, nametype.KRB_NT_PRINCIPAL, a.SName.NameType, "SName type not as expected")
  181. assert.Equal(t, testdata.TEST_PRINCIPALNAME_NAMESTRING, a.SName.NameString, "SName string entries not as expected")
  182. assert.Equal(t, 2, len(a.CAddr), "Number of client addresses not as expected")
  183. for i, addr := range a.CAddr {
  184. assert.Equal(t, int32(2), addr.AddrType, fmt.Sprintf("Host address type not as expected for address item %d", i+1))
  185. assert.Equal(t, "12d00023", hex.EncodeToString(addr.Address), fmt.Sprintf("Host address not as expected for address item %d", i+1))
  186. }
  187. }
  188. func TestUnmarshalEncKDCRepPart_optionalsNULL(t *testing.T) {
  189. t.Parallel()
  190. var a EncKDCRepPart
  191. b, err := hex.DecodeString(testdata.MarshaledKRB5enc_kdc_rep_partOptionalsNULL)
  192. if err != nil {
  193. t.Fatalf("Test vector read error: %v", err)
  194. }
  195. err = a.Unmarshal(b)
  196. if err != nil {
  197. t.Fatalf("Unmarshal error: %v", err)
  198. }
  199. //Parse the test time value into a time.Time type
  200. tt, _ := time.Parse(testdata.TEST_TIME_FORMAT, testdata.TEST_TIME)
  201. assert.Equal(t, int32(1), a.Key.KeyType, "Key type not as expected")
  202. assert.Equal(t, []byte("12345678"), a.Key.KeyValue, "Key value not as expected")
  203. assert.Equal(t, 2, len(a.LastReqs), "Number of last request entries not as expected")
  204. for i, r := range a.LastReqs {
  205. assert.Equal(t, int32(-5), r.LRType, fmt.Sprintf("Last request typ not as expected for last request entry %d", i+1))
  206. assert.Equal(t, tt, r.LRValue, fmt.Sprintf("Last request time value not as expected for last request entry %d", i+1))
  207. }
  208. assert.Equal(t, testdata.TEST_NONCE, a.Nonce, "Nonce not as expected")
  209. assert.Equal(t, "fe5cba98", hex.EncodeToString(a.Flags.Bytes), "Flags not as expected")
  210. assert.Equal(t, tt, a.AuthTime, "Auth time not as expected")
  211. assert.Equal(t, tt, a.EndTime, "End time not as expected")
  212. assert.Equal(t, testdata.TEST_REALM, a.SRealm, "SRealm not as expected")
  213. assert.Equal(t, nametype.KRB_NT_PRINCIPAL, a.SName.NameType, "SName type not as expected")
  214. assert.Equal(t, testdata.TEST_PRINCIPALNAME_NAMESTRING, a.SName.NameString, "SName string entries not as expected")
  215. }
  216. func TestUnmarshalASRepDecodeAndDecrypt(t *testing.T) {
  217. t.Parallel()
  218. var asRep ASRep
  219. b, _ := hex.DecodeString(testuser1EType18ASREP)
  220. err := asRep.Unmarshal(b)
  221. if err != nil {
  222. t.Fatalf("AS REP Unmarshal error: %v\n", err)
  223. }
  224. assert.Equal(t, 5, asRep.PVNO, "PVNO not as expected")
  225. assert.Equal(t, 11, asRep.MsgType, "MsgType not as expected")
  226. assert.Equal(t, testRealm, asRep.CRealm, "Client Realm not as expected")
  227. assert.Equal(t, int32(1), asRep.CName.NameType, "CName NameType not as expected")
  228. assert.Equal(t, testUser, asRep.CName.NameString[0], "CName NameType not as expected")
  229. assert.Equal(t, int32(19), asRep.PAData[0].PADataType, "PADataType not as expected")
  230. assert.Equal(t, 5, asRep.Ticket.TktVNO, "TktVNO not as expected")
  231. assert.Equal(t, testRealm, asRep.Ticket.Realm, "Ticket Realm not as expected")
  232. assert.Equal(t, int32(2), asRep.Ticket.SName.NameType, "Ticket service nametype not as expected")
  233. assert.Equal(t, "krbtgt", asRep.Ticket.SName.NameString[0], "Ticket service name string not as expected")
  234. assert.Equal(t, testRealm, asRep.Ticket.SName.NameString[1], "Ticket service name string not as expected")
  235. assert.Equal(t, etypeID.ETypesByName["aes256-cts-hmac-sha1-96"], asRep.Ticket.EncPart.EType, "Etype of ticket encrypted part not as expected")
  236. assert.Equal(t, 1, asRep.Ticket.EncPart.KVNO, "Ticket encrypted part KVNO not as expected")
  237. assert.Equal(t, etypeID.ETypesByName["aes256-cts-hmac-sha1-96"], asRep.EncPart.EType, "Etype of encrypted part not as expected")
  238. assert.Equal(t, 0, asRep.EncPart.KVNO, "Encrypted part KVNO not as expected")
  239. //t.Log("Finished testing unecrypted parts of AS REP")
  240. ktb, _ := hex.DecodeString(testuser1EType18Keytab)
  241. kt := keytab.New()
  242. err = kt.Unmarshal(ktb)
  243. if err != nil {
  244. t.Fatalf("keytab parse error: %v\n", err)
  245. }
  246. cred := credentials.New(testUser, testRealm)
  247. _, err = asRep.DecryptEncPart(cred.WithKeytab(kt))
  248. if err != nil {
  249. t.Fatalf("Decryption of AS_REP EncPart failed: %v", err)
  250. }
  251. assert.Equal(t, int32(18), asRep.DecryptedEncPart.Key.KeyType, "KeyType in decrypted EncPart not as expected")
  252. assert.IsType(t, time.Time{}, asRep.DecryptedEncPart.LastReqs[0].LRValue, "LastReqs did not have a time value")
  253. assert.Equal(t, 2069991465, asRep.DecryptedEncPart.Nonce, "Nonce value not as expected")
  254. assert.IsType(t, time.Time{}, asRep.DecryptedEncPart.KeyExpiration, "Key expiration not a time type")
  255. assert.IsType(t, time.Time{}, asRep.DecryptedEncPart.AuthTime, "AuthTime not a time type")
  256. assert.IsType(t, time.Time{}, asRep.DecryptedEncPart.StartTime, "StartTime not a time type")
  257. assert.IsType(t, time.Time{}, asRep.DecryptedEncPart.EndTime, "StartTime not a time type")
  258. assert.IsType(t, time.Time{}, asRep.DecryptedEncPart.RenewTill, "RenewTill not a time type")
  259. assert.Equal(t, testRealm, asRep.DecryptedEncPart.SRealm, "Service realm not as expected")
  260. assert.Equal(t, int32(2), asRep.DecryptedEncPart.SName.NameType, "Name type for AS_REP not as expected")
  261. assert.Equal(t, []string{"krbtgt", testRealm}, asRep.DecryptedEncPart.SName.NameString, "Service name string not as expected")
  262. }
  263. func TestUnmarshalASRepDecodeAndDecrypt_withPassword(t *testing.T) {
  264. t.Parallel()
  265. var asRep ASRep
  266. b, _ := hex.DecodeString(testuser1EType18ASREP)
  267. err := asRep.Unmarshal(b)
  268. if err != nil {
  269. t.Fatalf("AS REP Unmarshal error: %v\n", err)
  270. }
  271. assert.Equal(t, 5, asRep.PVNO, "PVNO not as expected")
  272. assert.Equal(t, 11, asRep.MsgType, "MsgType not as expected")
  273. assert.Equal(t, testRealm, asRep.CRealm, "Client Realm not as expected")
  274. assert.Equal(t, int32(1), asRep.CName.NameType, "CName NameType not as expected")
  275. assert.Equal(t, testUser, asRep.CName.NameString[0], "CName NameType not as expected")
  276. assert.Equal(t, int32(19), asRep.PAData[0].PADataType, "PADataType not as expected")
  277. assert.Equal(t, 5, asRep.Ticket.TktVNO, "TktVNO not as expected")
  278. assert.Equal(t, testRealm, asRep.Ticket.Realm, "Ticket Realm not as expected")
  279. assert.Equal(t, int32(2), asRep.Ticket.SName.NameType, "Ticket service nametype not as expected")
  280. assert.Equal(t, "krbtgt", asRep.Ticket.SName.NameString[0], "Ticket service name string not as expected")
  281. assert.Equal(t, testRealm, asRep.Ticket.SName.NameString[1], "Ticket service name string not as expected")
  282. assert.Equal(t, etypeID.AES256_CTS_HMAC_SHA1_96, asRep.Ticket.EncPart.EType, "Etype of ticket encrypted part not as expected")
  283. assert.Equal(t, 1, asRep.Ticket.EncPart.KVNO, "Ticket encrypted part KVNO not as expected")
  284. assert.Equal(t, etypeID.AES256_CTS_HMAC_SHA1_96, asRep.EncPart.EType, "Etype of encrypted part not as expected")
  285. assert.Equal(t, 0, asRep.EncPart.KVNO, "Encrypted part KVNO not as expected")
  286. cred := credentials.New(testUser, testRealm)
  287. _, err = asRep.DecryptEncPart(cred.WithPassword(testUserPassword))
  288. if err != nil {
  289. t.Fatalf("Decryption of AS_REP EncPart failed: %v", err)
  290. }
  291. assert.Equal(t, int32(18), asRep.DecryptedEncPart.Key.KeyType, "KeyType in decrypted EncPart not as expected")
  292. assert.IsType(t, time.Time{}, asRep.DecryptedEncPart.LastReqs[0].LRValue, "LastReqs did not have a time value")
  293. assert.Equal(t, 2069991465, asRep.DecryptedEncPart.Nonce, "Nonce value not as expected")
  294. assert.IsType(t, time.Time{}, asRep.DecryptedEncPart.KeyExpiration, "Key expiration not a time type")
  295. assert.IsType(t, time.Time{}, asRep.DecryptedEncPart.AuthTime, "AuthTime not a time type")
  296. assert.IsType(t, time.Time{}, asRep.DecryptedEncPart.StartTime, "StartTime not a time type")
  297. assert.IsType(t, time.Time{}, asRep.DecryptedEncPart.EndTime, "StartTime not a time type")
  298. assert.IsType(t, time.Time{}, asRep.DecryptedEncPart.RenewTill, "RenewTill not a time type")
  299. assert.Equal(t, testRealm, asRep.DecryptedEncPart.SRealm, "Service realm not as expected")
  300. assert.Equal(t, nametype.KRB_NT_SRV_INST, asRep.DecryptedEncPart.SName.NameType, "Name type for AS_REP not as expected")
  301. assert.Equal(t, []string{"krbtgt", testRealm}, asRep.DecryptedEncPart.SName.NameString, "Service name string not as expected")
  302. }