https://github.com/bwmarrin/go-objectsid
A Go (golang) Utility package for decoding Active Directory objectSID
https://github.com/bwmarrin/go-objectsid
active-directory go golang objectsid sid-format
Last synced: over 1 year ago
JSON representation
A Go (golang) Utility package for decoding Active Directory objectSID
- Host: GitHub
- URL: https://github.com/bwmarrin/go-objectsid
- Owner: bwmarrin
- License: bsd-2-clause
- Created: 2019-11-25T22:42:06.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-11-26T14:45:45.000Z (over 6 years ago)
- Last Synced: 2025-03-18T08:02:08.854Z (over 1 year ago)
- Topics: active-directory, go, golang, objectsid, sid-format
- Language: Go
- Size: 5.86 KB
- Stars: 26
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
go-objectsid
====
[](https://discord.gg/0f1SbxBZjYq9jLBk)
go-objectsid is a [Go](https://golang.org/) package for decoding binary
Active Directory ObjectSID value into a human-readable string format.
**For help with this package or general Go discussion, please join the [Discord
Gophers](https://discord.gg/0f1SbxBZjYq9jLBk) chat server.**
## Status
I just wrote this after finding a few examples in other languages. It seems to
work based on my minimal testing. Please report any bugs you find.
### Binary ObjectSID Format
```
byte[0] - Revision Level
byte[1] - count of Sub-Authorities
byte[2-7] - 48 bit Authority (big-endian)
byte[8+] - n Sub-Authorities, 32 bits each (little-endian)
```
### String ObjectSID Format
`S-{Revision}-{Authority}-{SubAuthority1}-{SubAuthority2}...-{SubAuthorityN}`
## Getting Started
### Installing
This assumes you already have a working Go environment, if not please see
[this page](https://golang.org/doc/install) first.
```sh
go get github.com/bwmarrin/go-objectsid
```
### Usage
Import the package into your project then call the Decode function with a
binary objectSID. It will return a SID object that contains each individual
component of the SID along with a String() method to generate a properly formatted
SID string.
**Example Program:**
```go
package main
import (
"encoding/base64"
"fmt"
"github.com/bwmarrin/go-objectsid"
)
func main() {
// A objectSID in base64
// This is just here for the purpose of an example program
b64sid := `AQUAAAAAAAUVAAAArC22DNydmGz4WUTnUAQAAA==`
// Convert the above into binary form. This is the value you would
// get from a LDAP query on AD.
bsid, _ := base64.StdEncoding.DecodeString(b64sid)
// Decode the binary objectsid into a SID object
sid := objectsid.Decode(bsid)
// Print out just one component of the SID
fmt.Println(sid.Authority)
// Print out the relative identifier
fmt.Println(sid.RID())
// Print the entire ObjectSID
fmt.Println(sid)
}
```
### Credit
This was wrote using the below page as a reference.
http://www.adamretter.org.uk/blog/entries/active-directory-ldap-users-primary-group.xml
### Reference
This page has a lot of useful information on the SID format.
https://docs.microsoft.com/en-us/windows/security/identity-protection/access-control/security-identifiers