Jonathan Turner 7 éve
szülő
commit
c314191dba

+ 0 - 313
mstypes/claims.go

@@ -1,313 +0,0 @@
-package mstypes
-
-import (
-	"bytes"
-	"encoding/binary"
-	"errors"
-	"fmt"
-
-	"gopkg.in/jcmturner/rpc.v0/ndr"
-)
-
-// Compression format assigned numbers.
-const (
-	CompressionFormatNone       uint16 = 0
-	CompressionFormatLZNT1      uint16 = 2
-	CompressionFormatXPress     uint16 = 3
-	CompressionFormatXPressHuff uint16 = 4
-)
-
-// ClaimsSourceTypeAD https://msdn.microsoft.com/en-us/library/hh553809.aspx
-const ClaimsSourceTypeAD uint16 = 1
-
-// Claim Type assigned numbers
-const (
-	ClaimTypeIDInt64    uint16 = 1
-	ClaimTypeIDUInt64   uint16 = 2
-	ClaimTypeIDString   uint16 = 3
-	ClaimsTypeIDBoolean uint16 = 6
-)
-
-// ClaimsBlob implements https://msdn.microsoft.com/en-us/library/hh554119.aspx
-type ClaimsBlob struct {
-	Size        uint32
-	EncodedBlob []byte
-}
-
-// ReadClaimsBlob reads a ClaimsBlob from the byte slice.
-func ReadClaimsBlob(b *[]byte, p *int, e *binary.ByteOrder) (c ClaimsBlob) {
-	c.Size = ndr.ReadUint32(b, p, e)
-	c.EncodedBlob = ndr.ReadBytes(b, p, int(c.Size), e)
-	return
-}
-
-// ClaimsSetMetadata implements https://msdn.microsoft.com/en-us/library/hh554073.aspx
-type ClaimsSetMetadata struct {
-	claimsSetSize             uint32
-	ClaimsSet                 ClaimsSet
-	CompressionFormat         uint16 // Enum see constants for options
-	uncompressedClaimsSetSize uint32
-	ReservedType              uint16
-	reservedFieldSize         uint32
-	ReservedField             []byte
-}
-
-// ClaimsSet implements https://msdn.microsoft.com/en-us/library/hh554122.aspx
-type ClaimsSet struct {
-	ClaimsArrayCount  uint32
-	ClaimsArrays      []ClaimsArray
-	ReservedType      uint16
-	reservedFieldSize uint32
-	ReservedField     []byte
-}
-
-// ClaimsArray implements https://msdn.microsoft.com/en-us/library/hh536458.aspx
-type ClaimsArray struct {
-	ClaimsSourceType uint16
-	ClaimsCount      uint32
-	ClaimsEntries    []ClaimEntry
-}
-
-// ClaimEntry implements https://msdn.microsoft.com/en-us/library/hh536374.aspx
-type ClaimEntry struct {
-	ID         string //utf16string
-	Type       uint16 // enums are 16 bit https://msdn.microsoft.com/en-us/library/windows/desktop/aa366818(v=vs.85).aspx
-	TypeInt64  ClaimTypeInt64
-	TypeUInt64 ClaimTypeUInt64
-	TypeString ClaimTypeString
-	TypeBool   ClaimTypeBoolean
-}
-
-// ClaimTypeInt64 is a claim of type int64
-type ClaimTypeInt64 struct {
-	ValueCount uint32
-	Value      []int64
-}
-
-// ClaimTypeUInt64 is a claim of type uint64
-type ClaimTypeUInt64 struct {
-	ValueCount uint32
-	Value      []uint64
-}
-
-// ClaimTypeString is a claim of type string
-type ClaimTypeString struct {
-	ValueCount uint32
-	Value      []string
-}
-
-// ClaimTypeBoolean is a claim of type bool
-type ClaimTypeBoolean struct {
-	ValueCount uint32
-	Value      []bool
-}
-
-// ReadClaimsSetMetadata reads a ClaimsSetMetadata from the bytes slice.
-func ReadClaimsSetMetadata(b *[]byte, p *int, e *binary.ByteOrder) (c ClaimsSetMetadata, err error) {
-	c.claimsSetSize = ndr.ReadUint32(b, p, e)
-	*p += 4 //Move over pointer to ClaimSet array
-	c.CompressionFormat = ndr.ReadUint16(b, p, e)
-	// TODO Currently compression is not supported so if it is compressed we just have to return.
-	if c.CompressionFormat != CompressionFormatNone {
-		*p = len(*b)
-		return
-	}
-	c.uncompressedClaimsSetSize = ndr.ReadUint32(b, p, e)
-	c.ReservedType = ndr.ReadUint16(b, p, e)
-	c.reservedFieldSize = ndr.ReadUint32(b, p, e)
-	*p += 4 //Move over pointer to ReservedField array
-	var ah ndr.ConformantArrayHeader
-	if c.claimsSetSize > 0 {
-		// ClaimsSet is a conformant array https://msdn.microsoft.com/en-us/library/windows/desktop/aa373603(v=vs.85).aspx
-		ah, err = ndr.ReadUniDimensionalConformantArrayHeader(b, p, e)
-		if err != nil {
-			return
-		}
-		if ah.MaxCount != int(c.claimsSetSize) {
-			err = errors.New("error with size of CLAIMS_SET array")
-			return
-		}
-		csb := ndr.ReadBytes(b, p, int(c.claimsSetSize), e)
-		//TODO put decompression here
-		c.ClaimsSet, err = ReadClaimsSet(csb)
-		if err != nil {
-			return
-		}
-	}
-	if c.reservedFieldSize > 0 {
-		ah, err = ndr.ReadUniDimensionalConformantArrayHeader(b, p, e)
-		if err != nil {
-			return
-		}
-		if ah.MaxCount != int(c.reservedFieldSize) {
-			err = errors.New("error with size of CLAIMS_SET_METADATA's reserved field array")
-			return
-		}
-		c.ReservedField = ndr.ReadBytes(b, p, int(c.reservedFieldSize), e)
-	}
-	return
-}
-
-// ReadClaimsSet reads a ClaimsSet from the bytes slice.
-func ReadClaimsSet(b []byte) (c ClaimsSet, err error) {
-	ch, _, p, err := ndr.ReadHeaders(&b)
-	if err != nil {
-		err = fmt.Errorf("error parsing NDR byte stream headers of CLAIMS_SET: %v", err)
-		return
-	}
-	e := &ch.Endianness
-	//The next 4 bytes are an RPC unique pointer referent. We just skip these
-	p += 4
-
-	c.ClaimsArrayCount = ndr.ReadUint32(&b, &p, e)
-	p += 4 //Move over pointer to claims array
-	c.ReservedType = ndr.ReadUint16(&b, &p, e)
-	c.reservedFieldSize = ndr.ReadUint32(&b, &p, e)
-	p += 4 //Move over pointer to ReservedField array
-
-	var ah ndr.ConformantArrayHeader
-	if c.ClaimsArrayCount > 0 {
-		ah, err = ndr.ReadUniDimensionalConformantArrayHeader(&b, &p, e)
-		if err != nil {
-			return
-		}
-		if ah.MaxCount != int(c.ClaimsArrayCount) {
-			err = errors.New("error with size of CLAIMS_SET's claims array")
-			return
-		}
-		c.ClaimsArrays = make([]ClaimsArray, c.ClaimsArrayCount, c.ClaimsArrayCount)
-		for i := range c.ClaimsArrays {
-			c.ClaimsArrays[i], err = ReadClaimsArray(&b, &p, e)
-			if err != nil {
-				return
-			}
-		}
-	}
-	if c.reservedFieldSize > 0 {
-		ah, err = ndr.ReadUniDimensionalConformantArrayHeader(&b, &p, e)
-		if err != nil {
-			return
-		}
-		if ah.MaxCount != int(c.reservedFieldSize) {
-			err = errors.New("error with size of CLAIMS_SET's reserved field array")
-			return
-		}
-		c.ReservedField = ndr.ReadBytes(&b, &p, int(c.reservedFieldSize), e)
-	}
-	return c, nil
-}
-
-// ReadClaimsArray reads a ClaimsArray from the bytes slice.
-func ReadClaimsArray(b *[]byte, p *int, e *binary.ByteOrder) (c ClaimsArray, err error) {
-	c.ClaimsSourceType = ndr.ReadUint16(b, p, e)
-	c.ClaimsCount = ndr.ReadUint32(b, p, e)
-	*p += 4 //Move over pointer to claims array
-	ah, err := ndr.ReadUniDimensionalConformantArrayHeader(b, p, e)
-	if err != nil {
-		return
-	}
-	if ah.MaxCount != int(c.ClaimsCount) {
-		err = errors.New("error with size of CLAIMS_ARRAY's claims entries")
-		return
-	}
-	c.ClaimsEntries = make([]ClaimEntry, c.ClaimsCount, c.ClaimsCount)
-	for i := range c.ClaimsEntries {
-		var vc uint32
-		c.ClaimsEntries[i].Type, vc, err = ReadClaimEntriesUnionHeaders(b, p, e)
-		if err != nil {
-			return
-		}
-		switch c.ClaimsEntries[i].Type {
-		case ClaimTypeIDInt64:
-			c.ClaimsEntries[i].TypeInt64.ValueCount = vc
-		case ClaimTypeIDUInt64:
-			c.ClaimsEntries[i].TypeUInt64.ValueCount = vc
-		case ClaimTypeIDString:
-			c.ClaimsEntries[i].TypeString.ValueCount = vc
-		case ClaimsTypeIDBoolean:
-			c.ClaimsEntries[i].TypeBool.ValueCount = vc
-		}
-	}
-	for i := range c.ClaimsEntries {
-		err = FillClaimEntry(b, p, e, &c.ClaimsEntries[i])
-		if err != nil {
-			return
-		}
-	}
-	return
-}
-
-// ReadClaimEntriesUnionHeaders reads the union headers from the byte stream.
-func ReadClaimEntriesUnionHeaders(b *[]byte, p *int, e *binary.ByteOrder) (uint16, uint32, error) {
-	*p += 4
-	// This is an NDR union: http://pubs.opengroup.org/onlinepubs/9629399/chap14.htm#tagfcjh_39
-	// The discriminant [tag] is marshalled into the transmitted data stream twice:
-	// once as the field or parameter in the procedure argument list and
-	// once as the first part of the union representation [value]
-	t1 := ndr.ReadUint16(b, p, e)
-	t2 := ndr.ReadUint16(b, p, e)
-	if t1 != t2 {
-		return 0, 0, ndr.Malformed{EText: "malformed NDR encoding of CLAIM_ENTRY union"}
-	}
-	vc := ndr.ReadUint32(b, p, e)
-	*p += 4 //Move over pointer to array of values
-	return t1, vc, nil
-}
-
-// FillClaimEntry reads a ClaimEntry from the bytes slice.
-func FillClaimEntry(b *[]byte, p *int, e *binary.ByteOrder, c *ClaimEntry) (err error) {
-	c.ID, err = ndr.ReadConformantVaryingString(b, p, e)
-	if err != nil {
-		return
-	}
-	ah, err := ndr.ReadUniDimensionalConformantArrayHeader(b, p, e)
-	if err != nil {
-		return
-	}
-	switch c.Type {
-	case ClaimTypeIDInt64:
-		if ah.MaxCount != int(c.TypeInt64.ValueCount) {
-			return errors.New("error with size of CLAIM_ENTRY's value")
-		}
-		c.TypeInt64.Value = make([]int64, c.TypeInt64.ValueCount, c.TypeInt64.ValueCount)
-		for i := range c.TypeInt64.Value {
-			buf := bytes.NewReader((*b)[*p : *p+8])
-			err = binary.Read(buf, *e, &c.TypeInt64.Value[i])
-			if err != nil {
-				return
-			}
-			*p += 8 // progress position for a uint64
-		}
-	case ClaimTypeIDUInt64:
-		if ah.MaxCount != int(c.TypeUInt64.ValueCount) {
-			return errors.New("error with size of CLAIM_ENTRY's value")
-		}
-		c.TypeUInt64.Value = make([]uint64, c.TypeUInt64.ValueCount, c.TypeUInt64.ValueCount)
-		for i := range c.TypeUInt64.Value {
-			c.TypeUInt64.Value[i] = ndr.ReadUint64(b, p, e)
-		}
-	case ClaimTypeIDString:
-		if ah.MaxCount != int(c.TypeString.ValueCount) {
-			return errors.New("error with size of CLAIM_ENTRY's value")
-		}
-		c.TypeString.Value = make([]string, c.TypeString.ValueCount, c.TypeString.ValueCount)
-		*p += 4 * (int(c.TypeString.ValueCount)) // Move over pointers
-		for i := range c.TypeString.Value {
-			c.TypeString.Value[i], err = ndr.ReadConformantVaryingString(b, p, e)
-			if err != nil {
-				return
-			}
-		}
-	case ClaimsTypeIDBoolean:
-		if ah.MaxCount != int(c.TypeBool.ValueCount) {
-			return errors.New("error with size of CLAIM_ENTRY's value")
-		}
-		c.TypeBool.Value = make([]bool, c.TypeBool.ValueCount, c.TypeBool.ValueCount)
-		for i := range c.TypeBool.Value {
-			if ndr.ReadUint64(b, p, e) != 0 {
-				c.TypeBool.Value[i] = true
-			}
-		}
-	}
-	return
-}

+ 0 - 65
mstypes/filetime.go

@@ -1,65 +0,0 @@
-// Package mstypes implements representations of Microsoft types for PAC processing.
-package mstypes
-
-import (
-	"encoding/binary"
-	"time"
-
-	"gopkg.in/jcmturner/rpc.v0/ndr"
-)
-
-/*
-FILETIME is a windows data structure.
-Ref: https://msdn.microsoft.com/en-us/library/windows/desktop/ms724284%28v=vs.85%29.aspx
-It contains two parts that are 32bit integers:
-	dwLowDateTime
-	dwHighDateTime
-We need to combine these two into one 64bit integer.
-This gives the number of 100 nano second period from January 1, 1601, Coordinated Universal Time (UTC)
-*/
-
-const unixEpochDiff = 116444736000000000
-
-// FileTime implements the Microsoft FILETIME type https://msdn.microsoft.com/en-us/library/cc230324.aspx
-type FileTime struct {
-	LowDateTime  uint32
-	HighDateTime uint32
-}
-
-// Time return a golang Time type from the FileTime
-func (ft FileTime) Time() time.Time {
-	ns := (ft.MSEpoch() - unixEpochDiff) * 100
-	return time.Unix(0, int64(ns)).UTC()
-}
-
-// MSEpoch returns the FileTime as a Microsoft epoch, the number of 100 nano second periods elapsed from January 1, 1601 UTC.
-func (ft FileTime) MSEpoch() int64 {
-	return (int64(ft.HighDateTime) << 32) + int64(ft.LowDateTime)
-}
-
-// Unix returns the FileTime as a Unix time, the number of seconds elapsed since January 1, 1970 UTC.
-func (ft FileTime) Unix() int64 {
-	return (ft.MSEpoch() - unixEpochDiff) / 10000000
-}
-
-// GetFileTime returns a FileTime type from the provided Golang Time type.
-func GetFileTime(t time.Time) FileTime {
-	ns := t.UnixNano()
-	fp := (ns / 100) + unixEpochDiff
-	hd := fp >> 32
-	ld := fp - (hd << 32)
-	return FileTime{
-		LowDateTime:  uint32(ld),
-		HighDateTime: uint32(hd),
-	}
-}
-
-// ReadFileTime reads a FileTime from the bytes slice.
-func ReadFileTime(b *[]byte, p *int, e *binary.ByteOrder) FileTime {
-	l := ndr.ReadUint32(b, p, e)
-	h := ndr.ReadUint32(b, p, e)
-	return FileTime{
-		LowDateTime:  l,
-		HighDateTime: h,
-	}
-}

+ 0 - 17
mstypes/filetime_test.go

@@ -1,17 +0,0 @@
-package mstypes
-
-import (
-	"github.com/stretchr/testify/assert"
-	"testing"
-	"time"
-)
-
-func TestFileTime(t *testing.T) {
-	t.Parallel()
-	//2007-02-22 17:00:01.6382155
-	tt := time.Date(2007, 2, 22, 17, 0, 1, 638215500, time.UTC)
-	ft := GetFileTime(tt)
-	assert.Equal(t, tt.Unix(), ft.Unix(), "Unix epoch time not as expected")
-	assert.Equal(t, int64(128166372016382155), ft.MSEpoch(), "MSEpoch not as expected")
-	assert.Equal(t, tt, ft.Time(), "Golang time object returned from FileTime not as expected")
-}

+ 0 - 53
mstypes/group_membership.go

@@ -1,53 +0,0 @@
-package mstypes
-
-import (
-	"encoding/binary"
-
-	"gopkg.in/jcmturner/rpc.v0/ndr"
-)
-
-// GroupMembership implements https://msdn.microsoft.com/en-us/library/cc237945.aspx
-// RelativeID : A 32-bit unsigned integer that contains the RID of a particular group.
-// The possible values for the Attributes flags are identical to those specified in KERB_SID_AND_ATTRIBUTES
-type GroupMembership struct {
-	RelativeID uint32
-	Attributes uint32
-}
-
-// ReadGroupMembership reads a GroupMembership from the bytes slice.
-func ReadGroupMembership(b *[]byte, p *int, e *binary.ByteOrder) GroupMembership {
-	r := ndr.ReadUint32(b, p, e)
-	a := ndr.ReadUint32(b, p, e)
-	return GroupMembership{
-		RelativeID: r,
-		Attributes: a,
-	}
-}
-
-// DomainGroupMembership implements https://msdn.microsoft.com/en-us/library/hh536344.aspx
-// DomainId: A SID structure that contains the SID for the domain.This member is used in conjunction with the GroupIds members to create group SIDs for the device.
-// GroupCount: A 32-bit unsigned integer that contains the number of groups within the domain to which the account belongs.
-// GroupIds: A pointer to a list of GROUP_MEMBERSHIP structures that contain the groups to which the account belongs in the domain. The number of groups in this list MUST be equal to GroupCount.
-type DomainGroupMembership struct {
-	DomainID   RPCSID
-	GroupCount uint32
-	GroupIDs   []GroupMembership // Size is value of GroupCount
-}
-
-// ReadDomainGroupMembership reads a DomainGroupMembership from the bytes slice.
-func ReadDomainGroupMembership(b *[]byte, p *int, e *binary.ByteOrder) (DomainGroupMembership, error) {
-	d, err := ReadRPCSID(b, p, e)
-	if err != nil {
-		return DomainGroupMembership{}, err
-	}
-	c := ndr.ReadUint32(b, p, e)
-	g := make([]GroupMembership, c, c)
-	for i := range g {
-		g[i] = ReadGroupMembership(b, p, e)
-	}
-	return DomainGroupMembership{
-		DomainID:   d,
-		GroupCount: c,
-		GroupIDs:   g,
-	}, nil
-}

+ 0 - 42
mstypes/kerb_sid_and_attributes.go

@@ -1,42 +0,0 @@
-package mstypes
-
-import (
-	"encoding/binary"
-
-	"gopkg.in/jcmturner/rpc.v0/ndr"
-)
-
-// Attributes of a security group membership and can be combined by using the bitwise OR operation.
-// They are used by an access check mechanism to specify whether the membership is to be used in an access check decision.
-const (
-	SEGroupMandatory        = 31
-	SEGroupEnabledByDefault = 30
-	SEGroupEnabled          = 29
-	SEGroupOwner            = 28
-	SEGroupResource         = 2
-	//All other bits MUST be set to zero and MUST be  ignored on receipt.
-)
-
-// KerbSidAndAttributes implements https://msdn.microsoft.com/en-us/library/cc237947.aspx
-type KerbSidAndAttributes struct {
-	SID        RPCSID // A pointer to an RPC_SID structure.
-	Attributes uint32
-}
-
-// ReadKerbSidAndAttributes reads a KerbSidAndAttribute from the bytes slice.
-func ReadKerbSidAndAttributes(b *[]byte, p *int, e *binary.ByteOrder) (KerbSidAndAttributes, error) {
-	s, err := ReadRPCSID(b, p, e)
-	if err != nil {
-		return KerbSidAndAttributes{}, err
-	}
-	a := ndr.ReadUint32(b, p, e)
-	return KerbSidAndAttributes{
-		SID:        s,
-		Attributes: a,
-	}, nil
-}
-
-// SetFlag sets a flag in a uint32 attribute value.
-func SetFlag(a *uint32, i uint) {
-	*a = *a | (1 << (31 - i))
-}

+ 0 - 36
mstypes/rpc_unicode_string.go

@@ -1,36 +0,0 @@
-package mstypes
-
-import (
-	"encoding/binary"
-
-	"gopkg.in/jcmturner/rpc.v0/ndr"
-)
-
-// RPCUnicodeString implements https://msdn.microsoft.com/en-us/library/cc230365.aspx
-type RPCUnicodeString struct {
-	Length        uint16 // The length, in bytes, of the string pointed to by the Buffer member, not including the terminating null character if any. The length MUST be a multiple of 2. The length SHOULD equal the entire size of the Buffer, in which case there is no terminating null character. Any method that accesses this structure MUST use the Length specified instead of relying on the presence or absence of a null character.
-	MaximumLength uint16 // The maximum size, in bytes, of the string pointed to by Buffer. The size MUST be a multiple of 2. If not, the size MUST be decremented by 1 prior to use. This value MUST not be less than Length.
-	BufferPrt     uint32 // A pointer to a string buffer. If MaximumLength is greater than zero, the buffer MUST contain a non-null value.
-	Value         string
-}
-
-// ReadRPCUnicodeString reads a RPCUnicodeString from the bytes slice.
-func ReadRPCUnicodeString(b *[]byte, p *int, e *binary.ByteOrder) (RPCUnicodeString, error) {
-	l := ndr.ReadUint16(b, p, e)
-	ml := ndr.ReadUint16(b, p, e)
-	if ml < l || l%2 != 0 || ml%2 != 0 {
-		return RPCUnicodeString{}, ndr.Malformed{EText: "Invalid data for RPC_UNICODE_STRING"}
-	}
-	ptr := ndr.ReadUint32(b, p, e)
-	return RPCUnicodeString{
-		Length:        l,
-		MaximumLength: ml,
-		BufferPrt:     ptr,
-	}, nil
-}
-
-// UnmarshalString populates a golang string into the RPCUnicodeString struct.
-func (s *RPCUnicodeString) UnmarshalString(b *[]byte, p *int, e *binary.ByteOrder) (err error) {
-	s.Value, err = ndr.ReadConformantVaryingString(b, p, e)
-	return
-}

+ 0 - 70
mstypes/sid.go

@@ -1,70 +0,0 @@
-package mstypes
-
-import (
-	"encoding/binary"
-	"encoding/hex"
-	"fmt"
-
-	"gopkg.in/jcmturner/rpc.v0/ndr"
-)
-
-// RPCSID implements https://msdn.microsoft.com/en-us/library/cc230364.aspx
-type RPCSID struct {
-	Revision            uint8                     // An 8-bit unsigned integer that specifies the revision level of the SID. This value MUST be set to 0x01.
-	SubAuthorityCount   uint8                     // An 8-bit unsigned integer that specifies the number of elements in the SubAuthority array. The maximum number of elements allowed is 15.
-	IdentifierAuthority RPCSIDIdentifierAuthority // An RPC_SID_IDENTIFIER_AUTHORITY structure that indicates the authority under which the SID was created. It describes the entity that created the SID. The Identifier Authority value {0,0,0,0,0,5} denotes SIDs created by the NT SID authority.
-	SubAuthority        []uint32                  // A variable length array of unsigned 32-bit integers that uniquely identifies a principal relative to the IdentifierAuthority. Its length is determined by SubAuthorityCount.
-}
-
-// RPCSIDIdentifierAuthority implements https://msdn.microsoft.com/en-us/library/cc230372.aspx
-type RPCSIDIdentifierAuthority struct {
-	Value []byte // 6 bytes
-}
-
-// ReadRPCSID reads a RPC_SID from the bytes slice.
-func ReadRPCSID(b *[]byte, p *int, e *binary.ByteOrder) (RPCSID, error) {
-	size := int(ndr.ReadUint32(b, p, e)) // This is part of the NDR encoding rather than the data type.
-	r := ndr.ReadUint8(b, p)
-	if r != uint8(1) {
-		return RPCSID{}, ndr.Malformed{EText: fmt.Sprintf("SID revision value read as %d when it must be 1", r)}
-	}
-	c := ndr.ReadUint8(b, p)
-	a := ReadRPCSIDIdentifierAuthority(b, p, e)
-	s := make([]uint32, c, c)
-	if size != len(s) {
-		return RPCSID{}, ndr.Malformed{EText: fmt.Sprintf("Number of elements (%d) within SID in the byte stream does not equal the SubAuthorityCount (%d)", size, c)}
-	}
-	for i := 0; i < len(s); i++ {
-		s[i] = ndr.ReadUint32(b, p, e)
-	}
-	return RPCSID{
-		Revision:            r,
-		SubAuthorityCount:   c,
-		IdentifierAuthority: a,
-		SubAuthority:        s,
-	}, nil
-}
-
-// ReadRPCSIDIdentifierAuthority reads a RPC_SIDIdentifierAuthority from the bytes slice.
-func ReadRPCSIDIdentifierAuthority(b *[]byte, p *int, e *binary.ByteOrder) RPCSIDIdentifierAuthority {
-	return RPCSIDIdentifierAuthority{
-		Value: ndr.ReadBytes(b, p, 6, e),
-	}
-}
-
-// ToString returns the string representation of the RPC_SID.
-func (s *RPCSID) ToString() string {
-	var str string
-	b := append(make([]byte, 2, 2), s.IdentifierAuthority.Value...)
-	// For a strange reason this is read big endian: https://msdn.microsoft.com/en-us/library/dd302645.aspx
-	i := binary.BigEndian.Uint64(b)
-	if i >= 4294967296 {
-		str = fmt.Sprintf("S-1-0x%s", hex.EncodeToString(s.IdentifierAuthority.Value))
-	} else {
-		str = fmt.Sprintf("S-1-%d", i)
-	}
-	for _, sub := range s.SubAuthority {
-		str = fmt.Sprintf("%s-%d", str, sub)
-	}
-	return str
-}

+ 0 - 30
mstypes/user_session_key.go

@@ -1,30 +0,0 @@
-package mstypes
-
-import (
-	"encoding/binary"
-
-	"gopkg.in/jcmturner/rpc.v0/ndr"
-)
-
-// CypherBlock implements https://msdn.microsoft.com/en-us/library/cc237040.aspx
-type CypherBlock struct {
-	Data []byte // size = 8
-}
-
-// UserSessionKey implements https://msdn.microsoft.com/en-us/library/cc237080.aspx
-type UserSessionKey struct {
-	Data []CypherBlock // size = 2
-}
-
-// ReadUserSessionKey reads a UserSessionKey from the bytes slice.
-func ReadUserSessionKey(b *[]byte, p *int, e *binary.ByteOrder) UserSessionKey {
-	cb1 := CypherBlock{
-		Data: ndr.ReadBytes(b, p, 8, e),
-	}
-	cb2 := CypherBlock{
-		Data: ndr.ReadBytes(b, p, 8, e),
-	}
-	return UserSessionKey{
-		Data: []CypherBlock{cb1, cb2},
-	}
-}

+ 0 - 13
ndr/error.go

@@ -1,13 +0,0 @@
-package ndr
-
-import "fmt"
-
-// Malformed implements the error interface for malformed NDR encoding errors.
-type Malformed struct {
-	EText string
-}
-
-// Error implements the error interface on the Malformed struct.
-func (e Malformed) Error() string {
-	return fmt.Sprintf("Malformed NDR steam: %s", e.EText)
-}

+ 0 - 246
ndr/ndr.go

@@ -1,246 +0,0 @@
-// Package ndr is DEPRECATED and will be removed from next major revision of gokrb5. Please use gopkg.in/jcmturner/rpc.vX instead. This package is a partial implementation of NDR encoding: http://pubs.opengroup.org/onlinepubs/9629399/chap14.htm
-package ndr
-
-import (
-	"bytes"
-	"encoding/binary"
-	"fmt"
-	"math"
-)
-
-/*
-Serialization Version 1
-https://msdn.microsoft.com/en-us/library/cc243563.aspx
-
-Common Header - https://msdn.microsoft.com/en-us/library/cc243890.aspx
-8 bytes in total:
-- First byte - Version: Must equal 1
-- Second byte -  1st 4 bits: Endianess (0=Big; 1=Little); 2nd 4 bits: Character Encoding (0=ASCII; 1=EBCDIC)
-- 3rd - Floating point representation
-- 4th - Common Header Length: Must equal 8
-- 5th - 8th - Filler: MUST be set to 0xcccccccc on marshaling, and SHOULD be ignored during unmarshaling.
-
-Private Header - https://msdn.microsoft.com/en-us/library/cc243919.aspx
-8 bytes in total:
-- First 4 bytes - Indicates the length of a serialized top-level type in the octet stream. It MUST include the padding length and exclude the header itself.
-- Second 4 bytes - Filler: MUST be set to 0 (zero) during marshaling, and SHOULD be ignored during unmarshaling.
-*/
-
-const (
-	protocolVersion    = 1
-	commonHeaderBytes  = 8
-	privateHeaderBytes = 8
-	bigEndian          = 0
-	littleEndian       = 1
-	ascii              = 0
-	ebcdic             = 1
-	ieee               = 0
-	vax                = 1
-	cray               = 2
-	ibm                = 3
-)
-
-// CommonHeader implements the NDR common header: https://msdn.microsoft.com/en-us/library/cc243889.aspx
-type CommonHeader struct {
-	Version           uint8
-	Endianness        binary.ByteOrder
-	CharacterEncoding uint8
-	//FloatRepresentation uint8
-	HeaderLength uint16
-	Filler       []byte
-}
-
-// PrivateHeader implements the NDR private header: https://msdn.microsoft.com/en-us/library/cc243919.aspx
-type PrivateHeader struct {
-	ObjectBufferLength uint32
-	Filler             []byte
-}
-
-// ReadHeaders processes the bytes to return the NDR Common and Private headers.
-func ReadHeaders(b *[]byte) (CommonHeader, PrivateHeader, int, error) {
-	ch, p, err := GetCommonHeader(b)
-	if err != nil {
-		return CommonHeader{}, PrivateHeader{}, 0, err
-	}
-	ph, err := GetPrivateHeader(b, &p, &ch.Endianness)
-	if err != nil {
-		return CommonHeader{}, PrivateHeader{}, 0, err
-	}
-	return ch, ph, p, err
-}
-
-// GetCommonHeader processes the bytes to return the NDR Common header.
-func GetCommonHeader(b *[]byte) (CommonHeader, int, error) {
-	//The first 8 bytes comprise the Common RPC Header for type marshalling.
-	if len(*b) < commonHeaderBytes {
-		return CommonHeader{}, 0, Malformed{EText: "Not enough bytes."}
-	}
-	if (*b)[0] != protocolVersion {
-		return CommonHeader{}, 0, Malformed{EText: fmt.Sprintf("Stream does not indicate a RPC Type serialization of version %v", protocolVersion)}
-	}
-	endian := int((*b)[1] >> 4 & 0xF)
-	if endian != 0 && endian != 1 {
-		return CommonHeader{}, 1, Malformed{EText: "Common header does not indicate a valid endianness"}
-	}
-	charEncoding := uint8((*b)[1] & 0xF)
-	if charEncoding != 0 && charEncoding != 1 {
-		return CommonHeader{}, 1, Malformed{EText: "Common header does not indicate a valid charater encoding"}
-	}
-	var bo binary.ByteOrder
-	switch endian {
-	case littleEndian:
-		bo = binary.LittleEndian
-	case bigEndian:
-		bo = binary.BigEndian
-	}
-	l := bo.Uint16((*b)[2:4])
-	if l != commonHeaderBytes {
-		return CommonHeader{}, 4, Malformed{EText: fmt.Sprintf("Common header does not indicate a valid length: %v instead of %v", uint8((*b)[3]), commonHeaderBytes)}
-	}
-
-	return CommonHeader{
-		Version:           uint8((*b)[0]),
-		Endianness:        bo,
-		CharacterEncoding: charEncoding,
-		//FloatRepresentation: uint8(b[2]),
-		HeaderLength: l,
-		Filler:       (*b)[4:8],
-	}, 8, nil
-}
-
-// GetPrivateHeader processes the bytes to return the NDR Private header.
-func GetPrivateHeader(b *[]byte, p *int, bo *binary.ByteOrder) (PrivateHeader, error) {
-	//The next 8 bytes comprise the RPC type marshalling private header for constructed types.
-	if len(*b) < (privateHeaderBytes) {
-		return PrivateHeader{}, Malformed{EText: "Not enough bytes."}
-	}
-	var l uint32
-	buf := bytes.NewBuffer((*b)[*p : *p+4])
-	binary.Read(buf, *bo, &l)
-	if l%8 != 0 {
-		return PrivateHeader{}, Malformed{EText: "Object buffer length not a multiple of 8"}
-	}
-	*p += 8
-	return PrivateHeader{
-		ObjectBufferLength: l,
-		Filler:             (*b)[4:8],
-	}, nil
-}
-
-// ReadUint8 reads bytes representing a thirty two bit integer.
-func ReadUint8(b *[]byte, p *int) (i uint8) {
-	if len((*b)[*p:]) < 1 {
-		return
-	}
-	ensureAlignment(p, 1)
-	i = uint8((*b)[*p])
-	*p++
-	return
-}
-
-// ReadUint16 reads bytes representing a thirty two bit integer.
-func ReadUint16(b *[]byte, p *int, e *binary.ByteOrder) (i uint16) {
-	if len((*b)[*p:]) < 2 {
-		return
-	}
-	ensureAlignment(p, 2)
-	i = (*e).Uint16((*b)[*p : *p+2])
-	*p += 2
-	return
-}
-
-// ReadUint32 reads bytes representing a thirty two bit integer.
-func ReadUint32(b *[]byte, p *int, e *binary.ByteOrder) (i uint32) {
-	if len((*b)[*p:]) < 4 {
-		return
-	}
-	ensureAlignment(p, 4)
-	i = (*e).Uint32((*b)[*p : *p+4])
-	*p += 4
-	return
-}
-
-// ReadUint64 reads bytes representing a thirty two bit integer.
-func ReadUint64(b *[]byte, p *int, e *binary.ByteOrder) (i uint64) {
-	if len((*b)[*p:]) < 8 {
-		return
-	}
-	ensureAlignment(p, 8)
-	i = (*e).Uint64((*b)[*p : *p+8])
-	*p += 8
-	return
-}
-
-// ReadBytes reads the number of bytes specified.
-func ReadBytes(b *[]byte, p *int, s int, e *binary.ByteOrder) (r []byte) {
-	if len((*b)[*p:]) < s {
-		return
-	}
-	buf := bytes.NewBuffer((*b)[*p : *p+s])
-	r = make([]byte, s)
-	binary.Read(buf, *e, &r)
-	*p += s
-	return r
-}
-
-// ReadBool reads bytes representing a boolean.
-func ReadBool(b *[]byte, p *int) bool {
-	if len((*b)[*p:]) < 1 {
-		return false
-	}
-	if ReadUint8(b, p) != 0 {
-		return true
-	}
-	return false
-}
-
-// ReadIEEEfloat32 reads bytes representing a IEEE formatted 32 bit float.
-func ReadIEEEfloat32(b *[]byte, p *int, e *binary.ByteOrder) float32 {
-	ensureAlignment(p, 4)
-	return math.Float32frombits(ReadUint32(b, p, e))
-}
-
-// ReadIEEEfloat64 reads bytes representing a IEEE formatted 64 bit float.
-func ReadIEEEfloat64(b *[]byte, p *int, e *binary.ByteOrder) float64 {
-	ensureAlignment(p, 8)
-	return math.Float64frombits(ReadUint64(b, p, e))
-}
-
-// ReadConformantVaryingString reads a Conformant and Varying String from the bytes slice.
-// A conformant and varying string is a string in which the maximum number of elements is not known beforehand and therefore is included in the representation of the string.
-// NDR represents a conformant and varying string as an ordered sequence of representations of the string elements, preceded by three unsigned long integers.
-// The first integer gives the maximum number of elements in the string, including the terminator.
-// The second integer gives the offset from the first index of the string to the first index of the actual subset being passed.
-// The third integer gives the actual number of elements being passed, including the terminator.
-func ReadConformantVaryingString(b *[]byte, p *int, e *binary.ByteOrder) (string, error) {
-	m := ReadUint32(b, p, e) // Max element count
-	o := ReadUint32(b, p, e) // Offset
-	a := ReadUint32(b, p, e) // Actual count
-	if a > (m-o) || o > m {
-		return "", Malformed{EText: fmt.Sprintf("Not enough bytes. Max: %d, Offset: %d, Actual: %d", m, o, a)}
-	}
-	//Unicode string so each element is 2 bytes
-	//move position based on the offset
-	if o > 0 {
-		*p += int(o * 2)
-	}
-	s := make([]rune, a, a)
-	for i := 0; i < len(s); i++ {
-		s[i] = rune(ReadUint16(b, p, e))
-	}
-	ensureAlignment(p, 4)
-	return string(s), nil
-}
-
-// ReadUniDimensionalConformantArrayHeader reads a UniDimensionalConformantArrayHeader from the bytes slice.
-func ReadUniDimensionalConformantArrayHeader(b *[]byte, p *int, e *binary.ByteOrder) int {
-	return int(ReadUint32(b, p, e))
-}
-
-func ensureAlignment(p *int, byteSize int) {
-	if byteSize > 0 {
-		if s := *p % byteSize; s != 0 {
-			*p += byteSize - s
-		}
-	}
-}

+ 3 - 3
pac/client_claims_test.go

@@ -34,7 +34,7 @@ func TestPAC_ClientClaimsInfoStr_Unmarshal(t *testing.T) {
 	assert.Equal(t, uint16(3), k.ClaimsSet.ClaimsArrays[0].ClaimEntries[0].Type, "claims entry type not as expected")
 	assert.Equal(t, uint32(1), k.ClaimsSet.ClaimsArrays[0].ClaimEntries[0].TypeString.ValueCount, "claims value count not as expected")
 	assert.Equal(t, ClaimsEntryIDStr, k.ClaimsSet.ClaimsArrays[0].ClaimEntries[0].ID, "claims entry ID not as expected")
-	assert.Equal(t, []mstypes.LPWSTR{{ClaimsEntryValueStr}}, k.ClaimsSet.ClaimsArrays[0].ClaimEntries[0].TypeString.Value, "claims value not as expected")
+	assert.Equal(t, []mstypes.LPWSTR{{Value: ClaimsEntryValueStr}}, k.ClaimsSet.ClaimsArrays[0].ClaimEntries[0].TypeString.Value, "claims value not as expected")
 	assert.Equal(t, mstypes.CompressionFormatNone, k.ClaimsSetMetadata.CompressionFormat, "compression format not as expected")
 }
 
@@ -97,7 +97,7 @@ func TestPAC_ClientClaimsMultiValueStr_Unmarshal(t *testing.T) {
 	assert.Equal(t, mstypes.ClaimTypeIDString, k.ClaimsSet.ClaimsArrays[0].ClaimEntries[0].Type, "claims entry type not as expected")
 	assert.Equal(t, uint32(4), k.ClaimsSet.ClaimsArrays[0].ClaimEntries[0].TypeString.ValueCount, "claims value count not as expected")
 	assert.Equal(t, "ad://ext/otherIpPhone:88d5de9f6b4af985", k.ClaimsSet.ClaimsArrays[0].ClaimEntries[0].ID, "claims entry ID not as expected")
-	assert.Equal(t, []mstypes.LPWSTR{{"str1"}, {"str2"}, {"str3"}, {"str4"}}, k.ClaimsSet.ClaimsArrays[0].ClaimEntries[0].TypeString.Value, "claims value not as expected")
+	assert.Equal(t, []mstypes.LPWSTR{{Value: "str1"}, {Value: "str2"}, {Value: "str3"}, {Value: "str4"}}, k.ClaimsSet.ClaimsArrays[0].ClaimEntries[0].TypeString.Value, "claims value not as expected")
 	assert.Equal(t, mstypes.CompressionFormatNone, k.ClaimsSetMetadata.CompressionFormat, "compression format not as expected")
 }
 
@@ -123,7 +123,7 @@ func TestPAC_ClientClaimsInfoMultiEntry_Unmarshal(t *testing.T) {
 	assert.Equal(t, uint16(3), k.ClaimsSet.ClaimsArrays[0].ClaimEntries[1].Type, "claims entry type not as expected")
 	assert.Equal(t, uint32(1), k.ClaimsSet.ClaimsArrays[0].ClaimEntries[1].TypeString.ValueCount, "claims value count not as expected")
 	assert.Equal(t, ClaimsEntryIDStr, k.ClaimsSet.ClaimsArrays[0].ClaimEntries[1].ID, "claims entry ID not as expected")
-	assert.Equal(t, []mstypes.LPWSTR{{ClaimsEntryValueStr}}, k.ClaimsSet.ClaimsArrays[0].ClaimEntries[1].TypeString.Value, "claims value not as expected")
+	assert.Equal(t, []mstypes.LPWSTR{{Value: ClaimsEntryValueStr}}, k.ClaimsSet.ClaimsArrays[0].ClaimEntries[1].TypeString.Value, "claims value not as expected")
 	assert.Equal(t, mstypes.CompressionFormatNone, k.ClaimsSetMetadata.CompressionFormat, "compression format not as expected")
 }