Skip to content

Commit 881df71

Browse files
committed
Add unlock-enterprise command
Signed-off-by: Christopher Meis <[email protected]>
1 parent e0bf69b commit 881df71

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

cmd/gosedctl/README.md

+13
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,19 @@ Flags:
8383
-e, --erase-password=STRING Password to authenticate as EaseMaster
8484
```
8585

86+
unlock-enterprise:
87+
```
88+
gosedctl unlock-enterprise --device=STRING --band-master-pw=STRING
89+
90+
Unlocks global range with BandMaster0
91+
92+
Flags:
93+
-h, --help Show context-sensitive help.
94+
95+
-d, --device=STRING Path to SED device (e.g. /dev/nvme0)
96+
-b, --band-master-pw=STRING Password for BandMaster0 authority for configuration, lock and unlock operations.
97+
```
98+
8699
## Roadmap
87100
The intent of this command is to replace all other commands functionality and provide one binary with all capabilities.
88101

cmd/gosedctl/cmd.go

+48
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ type resetDeviceEnterprise struct {
5050
ErasePassword string `flag:"" required:"" short:"e" help:"Password to authenticate as EaseMaster"`
5151
}
5252

53+
type unlockEnterprise struct {
54+
Device string `flag:"" required:"" short:"d" help:"Path to SED device (e.g. /dev/nvme0)"`
55+
BandMasterPW string `flag:"" required:"" short:"b" help:"Password for BandMaster0 authority for configuration, lock and unlock operations."`
56+
}
57+
5358
// cli is the main command line interface struct required by kong command line parser
5459
var cli struct {
5560
InitialSetup initialSetupCmd `cmd:"" help:"Take ownership of a given OPAL SSC device"`
@@ -58,6 +63,7 @@ var cli struct {
5863
RevertTper revertTPerCmd `cmd:"" help:""`
5964
InitialSetupEnterprise initialSetupEnterpriseCmd `cmd:"" help:"Take ownership of a given Enterprise SSC device"`
6065
RevertEnterprise resetDeviceEnterprise `cmd:"" help:"delete after use"`
66+
UnlockEnterprise unlockEnterprise `cmd:"" help:"Unlocks global range with BandMaster0"`
6167
}
6268

6369
// Run executes when the initial-setup command is invoked
@@ -447,3 +453,45 @@ func (r *resetDeviceEnterprise) Run(ctx *context) error {
447453

448454
return nil
449455
}
456+
457+
func (u *unlockEnterprise) Run(ctx *context) error {
458+
coreObj, err := core.NewCore(u.Device)
459+
if err != nil {
460+
return fmt.Errorf("NewCore(%s) failed: %v", u.Device, err)
461+
}
462+
463+
comID, _, err := core.FindComID(coreObj.DriveIntf, coreObj.DiskInfo.Level0Discovery)
464+
if err != nil {
465+
return fmt.Errorf("FindComID() failed: %v", err)
466+
}
467+
468+
cs, err := core.NewControlSession(coreObj.DriveIntf, coreObj.Level0Discovery, core.WithComID(comID))
469+
if err != nil {
470+
return fmt.Errorf("NewControllSession() failed: %v", err)
471+
}
472+
defer cs.Close()
473+
474+
serial, err := coreObj.SerialNumber()
475+
if err != nil {
476+
return fmt.Errorf("coreObj.SerialNumber() failed: %v", err)
477+
}
478+
479+
salt := fmt.Sprintf("%-20s", serial)
480+
pwhash := pbkdf2.Key(([]byte(u.BandMasterPW)), []byte(salt[:20]), 75000, 32, sha1.New)
481+
482+
lockingSession, err := cs.NewSession(uid.EnterpriseLockingSP)
483+
if err != nil {
484+
return fmt.Errorf("NewSession() to LockingSP failed: %v", err)
485+
}
486+
487+
defer lockingSession.Close()
488+
489+
if err := table.ThisSP_Authenticate(lockingSession, uid.LockingAuthorityBandMaster0, pwhash); err != nil {
490+
return fmt.Errorf("authenticating as BandMaster0 failed: %v", err)
491+
}
492+
493+
if err := table.UnlockGlobalRangeEnterprise(lockingSession, uid.GlobalRangeRowUID); err != nil {
494+
return fmt.Errorf("failed to unlock global range: %v", err)
495+
}
496+
return nil
497+
}

pkg/core/table/locking.go

+19
Original file line numberDiff line numberDiff line change
@@ -641,3 +641,22 @@ func EnableGlobalRangeEnterprise(s *core.Session) error {
641641
}
642642
return nil
643643
}
644+
645+
func UnlockGlobalRangeEnterprise(s *core.Session, band uid.RowUID) error {
646+
mc := NewSetCall(s, band)
647+
mc.Token(stream.StartName)
648+
mc.Bytes([]byte("ReadLocked"))
649+
mc.Token(stream.OpalFalse)
650+
mc.Token(stream.EndName)
651+
mc.Token(stream.StartName)
652+
mc.Bytes([]byte("WriteLocked"))
653+
mc.Token(stream.OpalFalse)
654+
mc.Token(stream.EndName)
655+
mc.EndList()
656+
mc.EndList()
657+
658+
if _, err := s.ExecuteMethod(mc); err != nil {
659+
return err
660+
}
661+
return nil
662+
}

0 commit comments

Comments
 (0)