feat(aa-log): Add support for encoded paths and profile names.

This commit is contained in:
Alexandre Pujol 2022-05-02 13:21:53 +01:00
parent 35a281d045
commit e5c4ca400c
Failed to generate hash of commit

View file

@ -40,7 +40,10 @@ type AppArmorLog map[string]string
// AppArmorLogs describes all apparmor log entries // AppArmorLogs describes all apparmor log entries
type AppArmorLogs []AppArmorLog type AppArmorLogs []AppArmorLog
var quoted bool var (
quoted bool
isHexa = regexp.MustCompile("^[0-9A-Fa-f]+$")
)
func splitQuoted(r rune) bool { func splitQuoted(r rune) bool {
if r == '"' { if r == '"' {
@ -56,6 +59,14 @@ func toQuote(str string) string {
return str return str
} }
func decodeHex(str string) string {
if isHexa.MatchString(str) {
bs, _ := hex.DecodeString(str)
return string(bs)
}
return str
}
func removeDuplicateLog(logs []string) []string { func removeDuplicateLog(logs []string) []string {
list := []string{} list := []string{}
keys := map[string]interface{}{"": true} keys := map[string]interface{}{"": true}
@ -113,6 +124,10 @@ func NewApparmorLogs(file *os.File, profile string) AppArmorLogs {
aa[kv[0]] = strings.Trim(kv[1], `"`) aa[kv[0]] = strings.Trim(kv[1], `"`)
} }
} }
aa["profile"] = decodeHex(aa["profile"])
if name, ok := aa["name"]; ok {
aa["name"] = decodeHex(name)
}
aaLogs = append(aaLogs, aa) aaLogs = append(aaLogs, aa)
} }