Skip to content

Commit e0bf69b

Browse files
committed
Add RevertEnterprise functionality
Signed-off-by: Christopher Meis <[email protected]>
1 parent 6a619e8 commit e0bf69b

File tree

5 files changed

+121
-0
lines changed

5 files changed

+121
-0
lines changed

cmd/gosedctl/README.md

+15
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Flags:
5454
```
5555

5656
## Command documentation - Enterprise SSC
57+
initial-setup-enterprise:
5758
```
5859
gosedctl initial-setup-enterprise --device=STRING --sid-password=STRING --band-master-0-pw=STRING --erase-master-pw=STRING
5960
@@ -68,6 +69,20 @@ Flags:
6869
-e, --erase-master-pw=STRING Password for EraseMaster authority for erase operations of ranges.
6970
```
7071

72+
revert-enterprise:
73+
```
74+
gosedctl revert-enterprise --device=STRING --sid-password=STRING --erase-password=STRING
75+
76+
delete after use
77+
78+
Flags:
79+
-h, --help Show context-sensitive help.
80+
81+
-d, --device=STRING Path to SED device (e.g. /dev/nvme0)
82+
-p, --sid-password=STRING Password to SID authority
83+
-e, --erase-password=STRING Password to authenticate as EaseMaster
84+
```
85+
7186
## Roadmap
7287
The intent of this command is to replace all other commands functionality and provide one binary with all capabilities.
7388

cmd/gosedctl/cmd.go

+89
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,20 @@ type initialSetupEnterpriseCmd struct {
4444
EraseMasterPW string `flag:"" required:"" short:"e" help:"Password for EraseMaster authority for erase operations of ranges."`
4545
}
4646

47+
type resetDeviceEnterprise struct {
48+
Device string `flag:"" required:"" short:"d" help:"Path to SED device (e.g. /dev/nvme0)"`
49+
SIDPassword string `flag:"" required:"" short:"p" help:"Password to SID authority"`
50+
ErasePassword string `flag:"" required:"" short:"e" help:"Password to authenticate as EaseMaster"`
51+
}
52+
4753
// cli is the main command line interface struct required by kong command line parser
4854
var cli struct {
4955
InitialSetup initialSetupCmd `cmd:"" help:"Take ownership of a given OPAL SSC device"`
5056
LoadPBA loadPBAImageCmd `cmd:"" help:"Load PBA image to shadow MBR"`
5157
RevertNoerase revertNoeraseCmd `cmd:"" help:""`
5258
RevertTper revertTPerCmd `cmd:"" help:""`
5359
InitialSetupEnterprise initialSetupEnterpriseCmd `cmd:"" help:"Take ownership of a given Enterprise SSC device"`
60+
RevertEnterprise resetDeviceEnterprise `cmd:"" help:"delete after use"`
5461
}
5562

5663
// Run executes when the initial-setup command is invoked
@@ -358,3 +365,85 @@ func (i *initialSetupEnterpriseCmd) Run(ctx *context) error {
358365

359366
return nil
360367
}
368+
369+
func (r *resetDeviceEnterprise) Run(ctx *context) error {
370+
coreObj, err := core.NewCore(r.Device)
371+
if err != nil {
372+
return fmt.Errorf("NewCore(%s) failed: %v", r.Device, err)
373+
}
374+
375+
comID, _, err := core.FindComID(coreObj.DriveIntf, coreObj.DiskInfo.Level0Discovery)
376+
if err != nil {
377+
return fmt.Errorf("FindComID() failed: %v", err)
378+
}
379+
380+
cs, err := core.NewControlSession(coreObj.DriveIntf, coreObj.Level0Discovery, core.WithComID(comID))
381+
if err != nil {
382+
return fmt.Errorf("NewControllSession() failed: %v", err)
383+
}
384+
defer cs.Close()
385+
386+
serial, err := coreObj.SerialNumber()
387+
if err != nil {
388+
return fmt.Errorf("coreObj.SerialNumber() failed: %v", err)
389+
}
390+
391+
salt := fmt.Sprintf("%-20s", serial)
392+
eraseHash := pbkdf2.Key(([]byte(r.ErasePassword)), []byte(salt[:20]), 75000, 32, sha1.New)
393+
394+
lockingSession, err := cs.NewSession(uid.EnterpriseLockingSP)
395+
if err != nil {
396+
return err
397+
}
398+
399+
if err := table.ThisSP_Authenticate(lockingSession, uid.EraseMaster, eraseHash); err != nil {
400+
return fmt.Errorf("authenticating as EraseMaster failed: %v", err)
401+
}
402+
403+
if err := table.EraseBand(lockingSession, uid.InvokingID(uid.Band1Enterprise)); err != nil {
404+
return fmt.Errorf("failed to erase global range: %v", err)
405+
}
406+
407+
if err := lockingSession.Close(); err != nil {
408+
return fmt.Errorf("failed to close lockingSession: %v", err)
409+
}
410+
411+
adminSession, err := cs.NewSession(uid.AdminSP)
412+
if err != nil {
413+
return fmt.Errorf("failed to open session to AdminSP: %v", err)
414+
}
415+
416+
adminHash := pbkdf2.Key(([]byte(r.SIDPassword)), []byte(salt[:20]), 75000, 32, sha1.New)
417+
418+
if err := table.ThisSP_Authenticate(adminSession, uid.AuthoritySID, adminHash); err != nil {
419+
return fmt.Errorf("failed to authenticate to AdminSP: %v", err)
420+
}
421+
422+
msid, err := table.Admin_C_PIN_MSID_GetPIN(adminSession)
423+
if err != nil {
424+
return fmt.Errorf("failed to retrieve MSID: %v", err)
425+
}
426+
427+
if err := table.Admin_C_Pin_SID_SetPIN(adminSession, msid); err != nil {
428+
return fmt.Errorf("failed to set AdminSP credential to MSID: %v", err)
429+
}
430+
431+
if err := adminSession.Close(); err != nil {
432+
return fmt.Errorf("failed to close Session to AdminSP")
433+
}
434+
435+
lockingSession, err = cs.NewSession(uid.EnterpriseLockingSP)
436+
if err != nil {
437+
return err
438+
}
439+
440+
if err := table.ThisSP_Authenticate(lockingSession, uid.LockingAuthorityBandMaster0, adminHash); err != nil {
441+
return fmt.Errorf("authenticating as EraseMaster failed: %v", err)
442+
}
443+
444+
if err := table.SetBandMaster0Pin(lockingSession, msid); err != nil {
445+
return fmt.Errorf("failed to set BandMaster0 Pin to MSID")
446+
}
447+
448+
return nil
449+
}

pkg/core/table/locking.go

+13
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,19 @@ func SetEraseMasterPin(s *core.Session, erasePinHash []byte) error {
602602
return nil
603603
}
604604

605+
func EraseBand(s *core.Session, band uid.InvokingID) error {
606+
if s.ProtocolLevel != core.ProtocolLevelEnterprise {
607+
return fmt.Errorf("invalid Protocol Level for operation")
608+
}
609+
610+
mc := method.NewMethodCall(band, uid.MethodIDEraseEnterprise, s.MethodFlags)
611+
612+
if _, err := s.ExecuteMethod(mc); err != nil {
613+
return err
614+
}
615+
return nil
616+
}
617+
605618
func EnableGlobalRangeEnterprise(s *core.Session) error {
606619
mc := NewSetCall(s, uid.GlobalRangeRowUID)
607620
mc.Token(stream.StartName)

pkg/core/uid/methods.go

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ var (
1515
MethodIDSMSyncTrustedSession = MethodID{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x05}
1616
MethodIDSMCloseSession = MethodID{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x06}
1717

18+
// Erase method for Enterprise SSC
19+
MethodIDEraseEnterprise = MethodID{0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x08, 0x03}
20+
1821
// Opal 2.0 Method
1922
MethodIDAdmin_Activate = MethodID{0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x02, 0x03}
2023

pkg/core/uid/uid.go

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ var (
3333

3434
var (
3535
GlobalRangeRowUID RowUID = [8]byte{0x00, 0x00, 0x08, 0x02, 0x00, 0x00, 0x00, 0x01}
36+
Band1Enterprise RowUID = [8]byte{0x00, 0x00, 0x08, 0x02, 0x00, 0x00, 0x00, 0x02}
3637
)
3738

3839
var (

0 commit comments

Comments
 (0)