APRep.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. // RFC 4120 KRB_AP_REP: https://tools.ietf.org/html/rfc4120#section-5.5.2.
  24. type APRep struct {
  25. PVNO int `asn1:"explicit,tag:0"`
  26. MsgType int `asn1:"explicit,tag:1"`
  27. EncPart types.EncryptedData `asn1:"explicit,tag:2"`
  28. }
  29. // Encrypted part of KRB_AP_REP.
  30. type EncAPRepPart struct {
  31. CTime time.Time `asn1:"generalized,explicit,tag:0"`
  32. Cusec int `asn1:"explicit,tag:1"`
  33. Subkey types.EncryptionKey `asn1:"optional,explicit,tag:2"`
  34. SequenceNumber int `asn1:"optional,explicit,tag:3"`
  35. }
  36. // Unmarshal bytes b into the APRep struct.
  37. func (a *APRep) Unmarshal(b []byte) error {
  38. _, err := asn1.UnmarshalWithParams(b, a, fmt.Sprintf("application,explicit,tag:%v", asnAppTag.APREP))
  39. if err != nil {
  40. return processReplyError(b, err)
  41. }
  42. expectedMsgType := msgtype.KRB_AP_REP
  43. if a.MsgType != expectedMsgType {
  44. return fmt.Errorf("Message ID does not indicate a KRB_AP_REP. Expected: %v; Actual: %v", expectedMsgType, a.MsgType)
  45. }
  46. return nil
  47. }
  48. // Unmarshal bytes b into the APRep encryoted part struct.
  49. func (a *EncAPRepPart) Unmarshal(b []byte) error {
  50. _, err := asn1.UnmarshalWithParams(b, a, fmt.Sprintf("application,explicit,tag:%v", asnAppTag.EncAPRepPart))
  51. if err != nil {
  52. return err
  53. }
  54. return nil
  55. }