@@ -44,13 +44,20 @@ type initialSetupEnterpriseCmd struct {
44
44
EraseMasterPW string `flag:"" required:"" short:"e" help:"Password for EraseMaster authority for erase operations of ranges."`
45
45
}
46
46
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
+
47
53
// cli is the main command line interface struct required by kong command line parser
48
54
var cli struct {
49
55
InitialSetup initialSetupCmd `cmd:"" help:"Take ownership of a given OPAL SSC device"`
50
56
LoadPBA loadPBAImageCmd `cmd:"" help:"Load PBA image to shadow MBR"`
51
57
RevertNoerase revertNoeraseCmd `cmd:"" help:""`
52
58
RevertTper revertTPerCmd `cmd:"" help:""`
53
59
InitialSetupEnterprise initialSetupEnterpriseCmd `cmd:"" help:"Take ownership of a given Enterprise SSC device"`
60
+ RevertEnterprise resetDeviceEnterprise `cmd:"" help:"delete after use"`
54
61
}
55
62
56
63
// Run executes when the initial-setup command is invoked
@@ -358,3 +365,85 @@ func (i *initialSetupEnterpriseCmd) Run(ctx *context) error {
358
365
359
366
return nil
360
367
}
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
+ }
0 commit comments