APRep.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package messages
  2. import (
  3. "fmt"
  4. "time"
  5. "github.com/jcmturner/gofork/encoding/asn1"
  6. "gopkg.in/jcmturner/gokrb5.v7/iana/asnAppTag"
  7. "gopkg.in/jcmturner/gokrb5.v7/iana/msgtype"
  8. "gopkg.in/jcmturner/gokrb5.v7/krberror"
  9. "gopkg.in/jcmturner/gokrb5.v7/types"
  10. )
  11. /*
  12. AP-REP ::= [APPLICATION 15] SEQUENCE {
  13. pvno [0] INTEGER (5),
  14. msg-type [1] INTEGER (15),
  15. enc-part [2] EncryptedData -- EncAPRepPart
  16. }
  17. EncAPRepPart ::= [APPLICATION 27] SEQUENCE {
  18. ctime [0] KerberosTime,
  19. cusec [1] Microseconds,
  20. subkey [2] EncryptionKey OPTIONAL,
  21. seq-number [3] UInt32 OPTIONAL
  22. }
  23. */
  24. // APRep implements RFC 4120 KRB_AP_REP: https://tools.ietf.org/html/rfc4120#section-5.5.2.
  25. type APRep struct {
  26. PVNO int `asn1:"explicit,tag:0"`
  27. MsgType int `asn1:"explicit,tag:1"`
  28. EncPart types.EncryptedData `asn1:"explicit,tag:2"`
  29. }
  30. // EncAPRepPart is the encrypted part of KRB_AP_REP.
  31. type EncAPRepPart struct {
  32. CTime time.Time `asn1:"generalized,explicit,tag:0"`
  33. Cusec int `asn1:"explicit,tag:1"`
  34. Subkey types.EncryptionKey `asn1:"optional,explicit,tag:2"`
  35. SequenceNumber int64 `asn1:"optional,explicit,tag:3"`
  36. }
  37. // Unmarshal bytes b into the APRep struct.
  38. func (a *APRep) Unmarshal(b []byte) error {
  39. _, err := asn1.UnmarshalWithParams(b, a, fmt.Sprintf("application,explicit,tag:%v", asnAppTag.APREP))
  40. if err != nil {
  41. return processUnmarshalReplyError(b, err)
  42. }
  43. expectedMsgType := msgtype.KRB_AP_REP
  44. if a.MsgType != expectedMsgType {
  45. return krberror.NewErrorf(krberror.KRBMsgError, "message ID does not indicate a KRB_AP_REP. Expected: %v; Actual: %v", expectedMsgType, a.MsgType)
  46. }
  47. return nil
  48. }
  49. // Unmarshal bytes b into the APRep encrypted part struct.
  50. func (a *EncAPRepPart) Unmarshal(b []byte) error {
  51. _, err := asn1.UnmarshalWithParams(b, a, fmt.Sprintf("application,explicit,tag:%v", asnAppTag.EncAPRepPart))
  52. if err != nil {
  53. return krberror.Errorf(err, krberror.EncodingError, "AP_REP unmarshal error")
  54. }
  55. return nil
  56. }