AuthorizationData.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package types
  2. import (
  3. "github.com/jcmturner/gofork/encoding/asn1"
  4. )
  5. // Reference: https://www.ietf.org/rfc/rfc4120.txt
  6. // Section: 5.2.6
  7. /*
  8. AuthorizationData
  9. -- NOTE: AuthorizationData is always used as an OPTIONAL field and
  10. -- should not be empty.
  11. AuthorizationData ::= SEQUENCE OF SEQUENCE {
  12. ad-type [0] Int32,
  13. ad-data [1] OCTET STRING
  14. }
  15. ad-data
  16. This field contains authorization data to be interpreted according
  17. to the value of the corresponding ad-type field.
  18. ad-type
  19. This field specifies the format for the ad-data subfield. All
  20. negative values are reserved for local use. Non-negative values
  21. are reserved for registered use.
  22. Each sequence of type and data is referred to as an authorization
  23. element. Elements MAY be application specific; however, there is a
  24. common set of recursive elements that should be understood by all
  25. implementations. These elements contain other elements embedded
  26. within them, and the interpretation of the encapsulating element
  27. determines which of the embedded elements must be interpreted, and
  28. which may be ignored.
  29. These common authorization data elements are recursively defined,
  30. meaning that the ad-data for these types will itself contain a
  31. sequence of authorization data whose interpretation is affected by
  32. the encapsulating element. Depending on the meaning of the
  33. encapsulating element, the encapsulated elements may be ignored,
  34. might be interpreted as issued directly by the KDC, or might be
  35. stored in a separate plaintext part of the ticket. The types of the
  36. encapsulating elements are specified as part of the Kerberos
  37. specification because the behavior based on these values should be
  38. understood across implementations, whereas other elements need only
  39. be understood by the applications that they affect.
  40. Authorization data elements are considered critical if present in a
  41. ticket or authenticator. If an unknown authorization data element
  42. type is received by a server either in an AP-REQ or in a ticket
  43. contained in an AP-REQ, then, unless it is encapsulated in a known
  44. authorization data element amending the criticality of the elements
  45. it contains, authentication MUST fail. Authorization data is
  46. intended to restrict the use of a ticket. If the service cannot
  47. determine whether the restriction applies to that service, then a
  48. security weakness may result if the ticket can be used for that
  49. service. Authorization elements that are optional can be enclosed in
  50. an AD-IF-RELEVANT element.
  51. In the definitions that follow, the value of the ad-type for the
  52. element will be specified as the least significant part of the
  53. subsection number, and the value of the ad-data will be as shown in
  54. the ASN.1 structure that follows the subsection heading.
  55. Contents of ad-data ad-type
  56. DER encoding of AD-IF-RELEVANT 1
  57. DER encoding of AD-KDCIssued 4
  58. DER encoding of AD-AND-OR 5
  59. DER encoding of AD-MANDATORY-FOR-KDC 8
  60. */
  61. // AuthorizationData implements RFC 4120 type: https://tools.ietf.org/html/rfc4120#section-5.2.6
  62. type AuthorizationData []AuthorizationDataEntry
  63. // AuthorizationDataEntry implements RFC 4120 type: https://tools.ietf.org/html/rfc4120#section-5.2.6
  64. type AuthorizationDataEntry struct {
  65. ADType int32 `asn1:"explicit,tag:0"`
  66. ADData []byte `asn1:"explicit,tag:1"`
  67. }
  68. // ADIfRelevant implements RFC 4120 type: https://tools.ietf.org/html/rfc4120#section-5.2.6.1
  69. type ADIfRelevant AuthorizationData
  70. // ADKDCIssued implements RFC 4120 type: https://tools.ietf.org/html/rfc4120#section-5.2.6.2
  71. type ADKDCIssued struct {
  72. ADChecksum Checksum `asn1:"explicit,tag:0"`
  73. IRealm string `asn1:"optional,generalstring,explicit,tag:1"`
  74. Isname PrincipalName `asn1:"optional,explicit,tag:2"`
  75. Elements AuthorizationData `asn1:"explicit,tag:3"`
  76. }
  77. // ADAndOr implements RFC 4120 type: https://tools.ietf.org/html/rfc4120#section-5.2.6.3
  78. type ADAndOr struct {
  79. ConditionCount int32 `asn1:"explicit,tag:0"`
  80. Elements AuthorizationData `asn1:"explicit,tag:1"`
  81. }
  82. // ADMandatoryForKDC implements RFC 4120 type: https://tools.ietf.org/html/rfc4120#section-5.2.6.4
  83. type ADMandatoryForKDC AuthorizationData
  84. // Unmarshal bytes into the ADKDCIssued.
  85. func (a *ADKDCIssued) Unmarshal(b []byte) error {
  86. _, err := asn1.Unmarshal(b, a)
  87. return err
  88. }
  89. // Unmarshal bytes into the AuthorizationData.
  90. func (a *AuthorizationData) Unmarshal(b []byte) error {
  91. _, err := asn1.Unmarshal(b, a)
  92. return err
  93. }
  94. // Unmarshal bytes into the AuthorizationDataEntry.
  95. func (a *AuthorizationDataEntry) Unmarshal(b []byte) error {
  96. _, err := asn1.Unmarshal(b, a)
  97. return err
  98. }