APRep.go 1.7 KB

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