Restore Secureboot check

Something is missing from our implementation, which makes it break

Signed-off-by: Itxaka <itxaka@kairos.io>
This commit is contained in:
Itxaka
2025-02-21 13:26:28 +01:00
parent 7445605bb4
commit d455c7f6ec
4 changed files with 20 additions and 202 deletions

View File

@@ -1,9 +1,7 @@
package utils
import (
"bytes"
"crypto/sha256"
"encoding/binary"
"errors"
"fmt"
"io"
@@ -350,31 +348,3 @@ func Copy(src, dst string) error {
}
return nil
}
// GetSecureboot checks if secureboot is enabled in the system by checking the expected efivar.
func GetSecureboot() bool {
// /sys/firmware/efi/efivars/ is the path to the efivars
// Secureboot is the VAR name
// 8be4df61-93ca-11d2-aa0d-00e098032b8c is the Global EFI Variable GUID, set by the UEFI spec
// See page 82 of https://uefi.org/sites/default/files/resources/UEFI_Spec_2_9_2021_03_18.pdf
SecureBootEfiVar := "/sys/firmware/efi/efivars/SecureBoot-8be4df61-93ca-11d2-aa0d-00e098032b8c"
f, err := os.Open(SecureBootEfiVar)
if err != nil {
return false
}
defer f.Close()
// We just read it in Binary
var buf []byte
if err := binary.Read(f, binary.LittleEndian, &buf); err != nil {
return false
}
data := bytes.NewBuffer(buf)
// We just read the first byte
b, _ := data.ReadByte()
// If it's 1, it's enabled
if b == 1 {
return true
}
// Otherwise is disabled
return false
}