claims.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. package mstypes
  2. import (
  3. "bytes"
  4. "errors"
  5. "gopkg.in/jcmturner/rpc.v1/ndr"
  6. )
  7. // Compression format assigned numbers.
  8. const (
  9. CompressionFormatNone uint16 = 0
  10. CompressionFormatLZNT1 uint16 = 2
  11. CompressionFormatXPress uint16 = 3
  12. CompressionFormatXPressHuff uint16 = 4
  13. )
  14. // ClaimsSourceTypeAD https://msdn.microsoft.com/en-us/library/hh553809.aspx
  15. const ClaimsSourceTypeAD uint16 = 1
  16. // Claim Type assigned numbers
  17. const (
  18. ClaimTypeIDInt64 uint16 = 1
  19. ClaimTypeIDUInt64 uint16 = 2
  20. ClaimTypeIDString uint16 = 3
  21. ClaimsTypeIDBoolean uint16 = 6
  22. )
  23. // ClaimsBlob implements https://msdn.microsoft.com/en-us/library/hh554119.aspx
  24. type ClaimsBlob struct {
  25. Size uint32
  26. EncodedBlob EncodedBlob
  27. }
  28. // EncodedBlob are the bytes of the encoded Claims
  29. type EncodedBlob []byte
  30. // Size returns the size of the bytes of the encoded Claims
  31. func (b EncodedBlob) Size(c interface{}) int {
  32. cb := c.(ClaimsBlob)
  33. return int(cb.Size)
  34. }
  35. // ClaimsSetMetadata implements https://msdn.microsoft.com/en-us/library/hh554073.aspx
  36. type ClaimsSetMetadata struct {
  37. ClaimsSetSize uint32
  38. ClaimsSetBytes []byte `ndr:"pointer,conformant"`
  39. CompressionFormat uint16 // Enum see constants for options
  40. UncompressedClaimsSetSize uint32
  41. ReservedType uint16
  42. ReservedFieldSize uint32
  43. ReservedField []byte `ndr:"pointer,conformant"`
  44. }
  45. // ClaimsSet reads the ClaimsSet type from the NDR encoded ClaimsSetBytes in the ClaimsSetMetadata
  46. func (m *ClaimsSetMetadata) ClaimsSet() (c ClaimsSet, err error) {
  47. if len(m.ClaimsSetBytes) < 1 {
  48. err = errors.New("no bytes available for ClaimsSet")
  49. return
  50. }
  51. // TODO switch statement to decompress ClaimsSetBytes
  52. if m.CompressionFormat != CompressionFormatNone {
  53. err = errors.New("compressed ClaimsSet not currently supported")
  54. return
  55. }
  56. dec := ndr.NewDecoder(bytes.NewReader(m.ClaimsSetBytes))
  57. err = dec.Decode(&c)
  58. return
  59. }
  60. // ClaimsSet implements https://msdn.microsoft.com/en-us/library/hh554122.aspx
  61. type ClaimsSet struct {
  62. ClaimsArrayCount uint32
  63. ClaimsArrays []ClaimsArray `ndr:"pointer,conformant"`
  64. ReservedType uint16
  65. ReservedFieldSize uint32
  66. ReservedField []byte `ndr:"pointer,conformant"`
  67. }
  68. // ClaimsArray implements https://msdn.microsoft.com/en-us/library/hh536458.aspx
  69. type ClaimsArray struct {
  70. ClaimsSourceType uint16
  71. ClaimsCount uint32
  72. ClaimEntries []ClaimEntry `ndr:"pointer,conformant"`
  73. }
  74. // ClaimEntry is a NDR union that implements https://msdn.microsoft.com/en-us/library/hh536374.aspx
  75. type ClaimEntry struct {
  76. ID string `ndr:"pointer,conformant,varying"`
  77. Type uint16 `ndr:"unionTag"`
  78. TypeInt64 ClaimTypeInt64 `ndr:"unionField"`
  79. TypeUInt64 ClaimTypeUInt64 `ndr:"unionField"`
  80. TypeString ClaimTypeString `ndr:"unionField"`
  81. TypeBool ClaimTypeBoolean `ndr:"unionField"`
  82. }
  83. // SwitchFunc is the ClaimEntry union field selection function
  84. func (u ClaimEntry) SwitchFunc(_ interface{}) string {
  85. switch u.Type {
  86. case ClaimTypeIDInt64:
  87. return "TypeInt64"
  88. case ClaimTypeIDUInt64:
  89. return "TypeUInt64"
  90. case ClaimTypeIDString:
  91. return "TypeString"
  92. case ClaimsTypeIDBoolean:
  93. return "TypeBool"
  94. }
  95. return ""
  96. }
  97. // ClaimTypeInt64 is a claim of type int64
  98. type ClaimTypeInt64 struct {
  99. ValueCount uint32
  100. Value []int64 `ndr:"pointer,conformant"`
  101. }
  102. // ClaimTypeUInt64 is a claim of type uint64
  103. type ClaimTypeUInt64 struct {
  104. ValueCount uint32
  105. Value []uint64 `ndr:"pointer,conformant"`
  106. }
  107. // ClaimTypeString is a claim of type string
  108. type ClaimTypeString struct {
  109. ValueCount uint32
  110. Value []LPWSTR `ndr:"pointer,conformant"`
  111. }
  112. // ClaimTypeBoolean is a claim of type bool
  113. type ClaimTypeBoolean struct {
  114. ValueCount uint32
  115. Value []bool `ndr:"pointer,conformant"`
  116. }