Skip to content

Commit

Permalink
secboot: allow unlocking without key file
Browse files Browse the repository at this point in the history
Key datas may be in the tokens of the key slot. ActivateVolumeWithKeyData
will read those. So in the case the key file does not exist,
we should still try without keydata.
  • Loading branch information
valentindavid authored and pedronis committed Feb 7, 2025
1 parent dcf7436 commit 418d28e
Show file tree
Hide file tree
Showing 2 changed files with 208 additions and 154 deletions.
17 changes: 10 additions & 7 deletions secboot/secboot_sb.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"crypto/rand"
"errors"
"fmt"
"os"
"path/filepath"

sb "github.com/snapcore/secboot"
Expand Down Expand Up @@ -127,14 +128,16 @@ func UnlockVolumeUsingSealedKeyIfEncrypted(disk disks.Disk, name string, sealedE

res.PartDevice = partDevice

keyData, _, err := readKeyFile(sealedEncryptionKeyFile)
if err != nil {
return res, err
}

var keys []*sb.KeyData
if keyData != nil {
keys = append(keys, keyData)

if keyData, _, err := readKeyFile(sealedEncryptionKeyFile); err == nil {
if keyData != nil {
keys = append(keys, keyData)
}
} else {
if !os.IsNotExist(err) {
logger.Noticef("WARNING: there was an error loading key %s: %v", sealedEncryptionKeyFile, err)
}
}

if opts.WhichModel != nil {
Expand Down
Loading

0 comments on commit 418d28e

Please sign in to comment.