From f7c725ea5722959145db51847214897bad8e8b01 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Sun, 22 Nov 2026 18:12:06 +0900 Subject: container/seccomp: use sha384 for validation This also replaces hex encoding with base64 for more manageable string representations, and removes targets with build-only support. Signed-off-by: Ophestra --- container/seccomp/presets_test.go | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'container/seccomp/presets_test.go') diff --git a/container/seccomp/presets_test.go b/container/seccomp/presets_test.go index b86d49ba..d24ca97f 100644 --- a/container/seccomp/presets_test.go +++ b/container/seccomp/presets_test.go @@ -2,29 +2,31 @@ package seccomp_test import ( "crypto/sha512" - "encoding/hex" + "encoding/base64" + "fmt" "hakurei.app/container/seccomp" "hakurei.app/container/std" ) type ( + // bpfPreset represents a preset to validate. bpfPreset = struct { seccomp.ExportFlag std.FilterPreset } - bpfLookup map[bpfPreset][sha512.Size]byte + + // bpfLookup are bpf presets and their corresponding filter checksum. + bpfLookup = map[bpfPreset][sha512.Size384]byte ) -func toHash(s string) [sha512.Size]byte { - if len(s) != sha512.Size*2 { - panic("bad sha512 string length") - } - if v, err := hex.DecodeString(s); err != nil { - panic(err.Error()) - } else if len(v) != sha512.Size { - panic("unreachable") +// mustParse parses [base64.StdEncoding] representations of a sha512 checksum. +func mustParse(s string) [sha512.Size384]byte { + if v, err := base64.StdEncoding.DecodeString(s); err != nil { + panic(err) + } else if len(v) != sha512.Size384 { + panic(fmt.Sprintf("bad checksum of %d bytes", len(v))) } else { - return ([sha512.Size]byte)(v) + return ([sha512.Size384]byte)(v) } } -- cgit v1.3.1