APRep.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package messages
  2. import (
  3. "fmt"
  4. "github.com/jcmturner/asn1"
  5. "github.com/jcmturner/gokrb5/iana/asnAppTag"
  6. "github.com/jcmturner/gokrb5/iana/msgtype"
  7. "github.com/jcmturner/gokrb5/types"
  8. "time"
  9. )
  10. /*
  11. AP-REP ::= [APPLICATION 15] SEQUENCE {
  12. pvno [0] INTEGER (5),
  13. msg-type [1] INTEGER (15),
  14. enc-part [2] EncryptedData -- EncAPRepPart
  15. }
  16. EncAPRepPart ::= [APPLICATION 27] SEQUENCE {
  17. ctime [0] KerberosTime,
  18. cusec [1] Microseconds,
  19. subkey [2] EncryptionKey OPTIONAL,
  20. seq-number [3] UInt32 OPTIONAL
  21. }
  22. */
  23. type APRep struct {
  24. PVNO int `asn1:"explicit,tag:0"`
  25. MsgType int `asn1:"explicit,tag:1"`
  26. EncPart types.EncryptedData `asn1:"explicit,tag:2"`
  27. }
  28. type EncAPRepPart struct {
  29. CTime time.Time `asn1:"generalized,explicit,tag:0"`
  30. Cusec int `asn1:"explicit,tag:1"`
  31. Subkey types.EncryptionKey `asn1:"optional,explicit,tag:2"`
  32. SequenceNumber int `asn1:"optional,explicit,tag:3"`
  33. }
  34. func (a *APRep) Unmarshal(b []byte) error {
  35. _, err := asn1.UnmarshalWithParams(b, a, fmt.Sprintf("application,explicit,tag:%v", asnAppTag.APREP))
  36. if err != nil {
  37. return err
  38. }
  39. expectedMsgType := msgtype.KRB_AP_REP
  40. if a.MsgType != expectedMsgType {
  41. return fmt.Errorf("Message ID does not indicate a KRB_AP_REP. Expected: %v; Actual: %v", expectedMsgType, a.MsgType)
  42. }
  43. return nil
  44. }
  45. func (a *EncAPRepPart) Unmarshal(b []byte) error {
  46. _, err := asn1.UnmarshalWithParams(b, a, fmt.Sprintf("application,explicit,tag:%v", asnAppTag.EncAPRepPart))
  47. if err != nil {
  48. return err
  49. }
  50. return nil
  51. }