KRBSafe.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. // KRBSafe implements RFC 4120 KRB_SAFE: https://tools.ietf.org/html/rfc4120#section-5.6.1.
  12. type KRBSafe struct {
  13. PVNO int `asn1:"explicit,tag:0"`
  14. MsgType int `asn1:"explicit,tag:1"`
  15. SafeBody KRBSafeBody `asn1:"explicit,tag:2"`
  16. Cksum types.Checksum `asn1:"explicit,tag:3"`
  17. }
  18. // KRBSafeBody implements the KRB_SAFE_BODY of KRB_SAFE.
  19. type KRBSafeBody struct {
  20. UserData []byte `asn1:"explicit,tag:0"`
  21. Timestamp time.Time `asn1:"generalized,optional,explicit,tag:1"`
  22. Usec int `asn1:"optional,explicit,tag:2"`
  23. SequenceNumber int64 `asn1:"optional,explicit,tag:3"`
  24. SAddress types.HostAddress `asn1:"explicit,tag:4"`
  25. RAddress types.HostAddress `asn1:"optional,explicit,tag:5"`
  26. }
  27. // Unmarshal bytes b into the KRBSafe struct.
  28. func (s *KRBSafe) Unmarshal(b []byte) error {
  29. _, err := asn1.UnmarshalWithParams(b, s, fmt.Sprintf("application,explicit,tag:%v", asnAppTag.KRBSafe))
  30. if err != nil {
  31. return processUnmarshalReplyError(b, err)
  32. }
  33. expectedMsgType := msgtype.KRB_SAFE
  34. if s.MsgType != expectedMsgType {
  35. return krberror.NewErrorf(krberror.KRBMsgError, "message ID does not indicate a KRB_SAFE. Expected: %v; Actual: %v", expectedMsgType, s.MsgType)
  36. }
  37. return nil
  38. }