Skip to content
Draft
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
9 changes: 9 additions & 0 deletions grub2/edit_auth_ifc.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package grub2

import (
"fmt"
"regexp"
"strings"
"unicode"

Expand All @@ -18,6 +19,10 @@ const (
editAuthDBusInterface = dbusInterface + ".EditAuthentication"
)

// pbkdf2HashReg 用于校验 grub 编辑认证密码的 PBKDF2 哈希格式:
// grub.pbkdf2.sha<alg>.<iterations>.<salt>.<hash>
var pbkdf2HashReg = regexp.MustCompile(`^grub\.pbkdf2\.sha\d+\.\d+\.[0-9A-Fa-f]+\.[0-9A-Fa-f]+$`)

func (e *EditAuth) GetInterfaceName() string {
return editAuthDBusInterface
}
Expand All @@ -37,6 +42,10 @@ func (e *EditAuth) Enable(sender dbus.Sender, username, password string) *dbus.E
return dbusutil.ToError(fmt.Errorf("username or password invalid"))
}

if !pbkdf2HashReg.MatchString(password) {
return dbusutil.ToError(fmt.Errorf("invalid pbkdf2 hash format"))
}

err = e.setGrubEditShellAuth(username, password)
if err != nil {
return dbusutil.ToError(err)
Expand Down
3 changes: 1 addition & 2 deletions grub2/modify_manger.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ func (m *modifyManager) runUpdateGrubWithUnit() error {
var command []string
path, err := exec.LookPath(updateGrubCmd)
if err != nil {
path = grubMkconfigCmd
command = append(command, updateGrubCmd, "-o", grubScriptFile)
command = append(command, grubMkconfigCmd, "-o", grubScriptFile)
} else {
command = append(command, path)
}
Expand Down
Loading