Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
"cmd": "make update-repos"
}
]
}
},
"makefile.configureOnOpen": false
}
33 changes: 29 additions & 4 deletions tables/macos_profiles/macos_profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package macos_profiles

import (
"context"
"crypto/sha256"
"encoding/json"
"fmt"
"os/exec"

"github.com/groob/plist"
Expand All @@ -22,6 +25,8 @@ type profilePayload struct {
ProfileUUID string
ProfileOrganization string
ProfileType string
PayloadChecksum string
ProfileItems []any
}

func MacOSProfilesColumns() []table.ColumnDefinition {
Expand All @@ -34,6 +39,7 @@ func MacOSProfilesColumns() []table.ColumnDefinition {
table.TextColumn("uuid"),
table.TextColumn("organization"),
table.TextColumn("type"),
table.TextColumn("payload_checksum"),
}
}

Expand All @@ -48,11 +54,14 @@ func MacOSProfilesGenerate(ctx context.Context, queryContext table.QueryContext)
if err != nil {
return nil, errors.Wrap(err, "unmarshalProfilesOutput")
}

return generateResults(profiles), nil
result, err := generateResults(profiles)
if err != nil {
return nil, errors.Wrap(err, "generateResults")
}
return result, nil
}

func generateResults(profiles profilesOutput) []map[string]string {
func generateResults(profiles profilesOutput) ([]map[string]string, error) {
var results []map[string]string
for _, payload := range profiles.ComputerLevel {
result := map[string]string{
Expand All @@ -65,10 +74,26 @@ func generateResults(profiles profilesOutput) []map[string]string {
"organization": payload.ProfileOrganization,
"type": payload.ProfileType,
}
checksum, err := profileItemsChecksum(payload)
if err != nil {
return nil, errors.Wrap(err, "profileItemsChecksum")
}
result["payload_checksum"] = checksum
results = append(results, result)
}

return results
return results, nil

}

func profileItemsChecksum(payload profilePayload) (string, error) {
data, err := json.Marshal(payload.ProfileItems)
if err != nil {
return "", err
}

hash := sha256.Sum256(data)
return fmt.Sprintf("%x", hash), nil

}

Expand Down
41 changes: 34 additions & 7 deletions tables/macos_profiles/macos_profiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ func TestMarshallProfileOutput(t *testing.T) {
ProfileUUID: "597b4018-dbed-5b91-ad38-fd825711cd02",
ProfileOrganization: "Company",
ProfileType: "Configuration",
PayloadChecksum: "",
ProfileItems: []any{
map[string]any{
"PayloadContent": map[string]any{
"EnableFirewall": true,
},
"PayloadDisplayName": "Firewall",
"PayloadIdentifier": "com.apple.security.firewall",
"PayloadOrganization": "Company",
"PayloadType": "com.apple.security.firewall",
"PayloadUUID": "6EE63BCC-3E7C-48B2-AD15-D078EBAF25D0",
"PayloadVersion": uint64(1),
},
},
},
{
ProfileIdentifier: "com.company.profiles.PasswordPolicy",
Expand All @@ -33,12 +47,23 @@ func TestMarshallProfileOutput(t *testing.T) {
ProfileUUID: "45d9e37c-df62-5c6a-9808-18546fcacd22",
ProfileOrganization: "Company",
ProfileType: "Configuration",
PayloadChecksum: "",
ProfileItems: []any{
map[string]any{
"PayloadContent": map[string]any{
"minLength": uint64(100),
},
"PayloadDisplayName": "Passcode",
"PayloadIdentifier": "com.company.profiles.PasswordPolicy",
"PayloadType": "com.apple.mobiledevice.passwordpolicy",
"PayloadUUID": "8CD569F8-58BF-443C-8CE3-75173D3F19D1",
"PayloadVersion": uint64(1),
},
},
},
}
profiles, err := unmarshalProfilesOutput(testProfileStdOut)
if err != nil {
t.Fatal(err)
}
assert.NoError(t, err, "Error unmarshalling profiles output")

assert.Equal(t, profiles, expectedOutput, "Expected output when parsing profiles not recieved")
}
Expand All @@ -55,6 +80,7 @@ func TestMacOSProfilesGenerate(t *testing.T) {
"uuid": "597b4018-dbed-5b91-ad38-fd825711cd02",
"organization": "Company",
"type": "Configuration",
"payload_checksum": "f83dbedab1421631584052840aa182f0550e44a1bdaaea4608529e424c3e37de",
},
{
"identifier": "com.company.profiles.PasswordPolicy",
Expand All @@ -65,12 +91,13 @@ func TestMacOSProfilesGenerate(t *testing.T) {
"uuid": "45d9e37c-df62-5c6a-9808-18546fcacd22",
"organization": "Company",
"type": "Configuration",
"payload_checksum": "f66e9debe2662f568b1c69dc679252d147ee805c41aac330feb7c1926568baab",
},
}
profiles, err := unmarshalProfilesOutput(testProfileStdOut)
if err != nil {
t.Fatal(err)
}
rows := generateResults(profiles)
assert.NoError(t, err, "Error unmarshalling profiles output")
assert.NotNil(t, profiles, "Profiles should not be nil")
rows, err := generateResults(profiles)
assert.NoError(t, err, "Error generating results from profiles")
assert.Equal(t, rows, expectedRows, "Output rows are not equal")
}
Loading