@@ -50,6 +50,11 @@ type resetDeviceEnterprise struct {
50
50
ErasePassword string `flag:"" required:"" short:"e" help:"Password to authenticate as EaseMaster"`
51
51
}
52
52
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
+
53
58
// cli is the main command line interface struct required by kong command line parser
54
59
var cli struct {
55
60
InitialSetup initialSetupCmd `cmd:"" help:"Take ownership of a given OPAL SSC device"`
@@ -58,6 +63,7 @@ var cli struct {
58
63
RevertTper revertTPerCmd `cmd:"" help:""`
59
64
InitialSetupEnterprise initialSetupEnterpriseCmd `cmd:"" help:"Take ownership of a given Enterprise SSC device"`
60
65
RevertEnterprise resetDeviceEnterprise `cmd:"" help:"delete after use"`
66
+ UnlockEnterprise unlockEnterprise `cmd:"" help:"Unlocks global range with BandMaster0"`
61
67
}
62
68
63
69
// Run executes when the initial-setup command is invoked
@@ -447,3 +453,45 @@ func (r *resetDeviceEnterprise) Run(ctx *context) error {
447
453
448
454
return nil
449
455
}
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
+ }
0 commit comments