Skip to content

Commit

Permalink
secboot: indicate when unlock status is unknown
Browse files Browse the repository at this point in the history
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
  • Loading branch information
bboozzoo committed Nov 6, 2020
1 parent 35a2a99 commit f968bb3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 2 additions & 0 deletions secboot/secboot.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ const (
// UnlockedWithRecoveryKey indicates that the device was unlocked by the
// user providing the recovery key at the prompt.
UnlockedWithRecoveryKey
// UnlockStatusUnknown indicates that the unlock status of the device is not clear.
UnlockStatusUnknown
)

// UnlockResult is the result of trying to unlock a volume.
Expand Down
7 changes: 2 additions & 5 deletions secboot/secboot_tpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,8 @@ func UnlockVolumeUsingSealedKeyIfEncrypted(
// otherwise we have a tpm and we should use the sealed key first, but
// this method will fallback to using the recovery key if enabled
method, err := unlockEncryptedPartitionWithSealedKey(tpm, mapperName, res.Device, sealedEncryptionKeyFile, "", opts.AllowRecoveryKey)
if err != nil {
return err
}
res.UnlockMethod = method
return nil
return err
}()
if err != nil {
return res, err
Expand Down Expand Up @@ -428,7 +425,7 @@ func unlockEncryptedPartitionWithSealedKey(tpm *sb.TPMConnection, name, device,
return UnlockedWithRecoveryKey, nil
}
// no other error is possible when activation succeeded
return NotUnlocked, fmt.Errorf("internal error: volume activated with unexpected error: %v", err)
return UnlockStatusUnknown, fmt.Errorf("internal error: volume activated with unexpected error: %v", err)
}
// ActivateVolumeWithTPMSealedKey should always return an error if activated == false
return NotUnlocked, fmt.Errorf("cannot activate encrypted device %q: %v", device, err)
Expand Down
5 changes: 3 additions & 2 deletions secboot/secboot_tpm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,9 @@ func (s *secbootSuite) TestUnlockVolumeUsingSealedKeyIfEncrypted(c *C) {
activateErr: &sb.ActivateWithTPMSealedKeyError{
RecoveryKeyUsageErr: fmt.Errorf("unexpected"),
},
err: `internal error: volume activated with unexpected error: .* \(unexpected\)`,
disk: mockDiskWithEncDev,
expUnlockMethod: secboot.UnlockStatusUnknown,
err: `internal error: volume activated with unexpected error: .* \(unexpected\)`,
disk: mockDiskWithEncDev,
}, {
// activation works but lock fails, without encrypted device (lock requested)
tpmEnabled: true, lockRequest: true, activated: true,
Expand Down

0 comments on commit f968bb3

Please sign in to comment.