@@ -10,6 +10,36 @@ import (
1010 bmclibErrs "github.com/bmc-toolbox/bmclib/v2/errors"
1111)
1212
13+ // ResetSecureBootKeysType identifies the type of Secure Boot key reset to perform.
14+ type ResetSecureBootKeysType string
15+
16+ // ResetSecureBootKeysType constants enumerate the supported reset types for the whole Secure Boot subsystem.
17+ const (
18+ ResetSecureBootKeysTypeResetAllKeysToDefault ResetSecureBootKeysType = "ResetAllKeysToDefault"
19+ ResetSecureBootKeysTypeDeleteAllKeys ResetSecureBootKeysType = "DeleteAllKeys"
20+ ResetSecureBootKeysTypeDeletePK ResetSecureBootKeysType = "DeletePK"
21+ )
22+
23+ // ResetSecureBootDatabaseKeysType identifies the type of per-database Secure Boot key reset to perform.
24+ type ResetSecureBootDatabaseKeysType string
25+
26+ // ResetSecureBootDatabaseKeysType constants enumerate the supported reset types for a single Secure Boot database.
27+ const (
28+ ResetSecureBootDatabaseKeysTypeResetAllKeysToDefault ResetSecureBootDatabaseKeysType = "ResetAllKeysToDefault"
29+ ResetSecureBootDatabaseKeysTypeDeleteAllKeys ResetSecureBootDatabaseKeysType = "DeleteAllKeys"
30+ )
31+
32+ // SecureBootDatabase identifies a UEFI Secure Boot key database.
33+ type SecureBootDatabase string
34+
35+ // SecureBootDatabase constants enumerate the supported Secure Boot key databases.
36+ const (
37+ SecureBootDatabaseDB SecureBootDatabase = "db"
38+ SecureBootDatabaseKEK SecureBootDatabase = "KEK"
39+ SecureBootDatabasePK SecureBootDatabase = "PK"
40+ SecureBootDatabaseDBX SecureBootDatabase = "dbx"
41+ )
42+
1343// SecureBootStateGetter provides retrieval of whether UEFI Secure Boot is enabled.
1444type SecureBootStateGetter interface {
1545 GetSecureBoot (ctx context.Context ) (enabled bool , err error )
@@ -32,7 +62,7 @@ type secureBootSetterProvider struct {
3262
3363// SecureBootKeysResetter provides resetting the UEFI Secure Boot key databases.
3464type SecureBootKeysResetter interface {
35- ResetSecureBootKeys (ctx context.Context , resetType string ) (err error )
65+ ResetSecureBootKeys (ctx context.Context , resetType ResetSecureBootKeysType ) (err error )
3666}
3767
3868type secureBootKeysResetterProvider struct {
@@ -44,7 +74,7 @@ type secureBootKeysResetterProvider struct {
4474// database (e.g. "db", "KEK"), leaving every other database - including PK -
4575// untouched.
4676type SecureBootDatabaseKeysResetter interface {
47- ResetSecureBootDatabaseKeys (ctx context.Context , database , resetType string ) (err error )
77+ ResetSecureBootDatabaseKeys (ctx context.Context , database SecureBootDatabase , resetType ResetSecureBootDatabaseKeysType ) (err error )
4878}
4979
5080type secureBootDatabaseKeysResetterProvider struct {
@@ -56,7 +86,7 @@ type secureBootDatabaseKeysResetterProvider struct {
5686// UEFI Secure Boot key database (e.g. "db", "KEK") without disturbing any
5787// certificate already present.
5888type SecureBootCertificateImporter interface {
59- ImportSecureBootCertificate (ctx context.Context , database , certificatePEM string ) (err error )
89+ ImportSecureBootCertificate (ctx context.Context , database SecureBootDatabase , certificatePEM string ) (err error )
6090}
6191
6292type secureBootCertificateImporterProvider struct {
@@ -116,7 +146,7 @@ Loop:
116146 return metadata , multierror .Append (err , errors .New ("failure to set secure boot state" ))
117147}
118148
119- func resetSecureBootKeys (ctx context.Context , generic []secureBootKeysResetterProvider , resetType string ) (metadata Metadata , err error ) {
149+ func resetSecureBootKeys (ctx context.Context , generic []secureBootKeysResetterProvider , resetType ResetSecureBootKeysType ) (metadata Metadata , err error ) {
120150 metadata = newMetadata ()
121151Loop:
122152 for _ , elem := range generic {
@@ -142,7 +172,7 @@ Loop:
142172 return metadata , multierror .Append (err , errors .New ("failure to reset secure boot keys" ))
143173}
144174
145- func resetSecureBootDatabaseKeys (ctx context.Context , generic []secureBootDatabaseKeysResetterProvider , database , resetType string ) (metadata Metadata , err error ) {
175+ func resetSecureBootDatabaseKeys (ctx context.Context , generic []secureBootDatabaseKeysResetterProvider , database SecureBootDatabase , resetType ResetSecureBootDatabaseKeysType ) (metadata Metadata , err error ) {
146176 metadata = newMetadata ()
147177Loop:
148178 for _ , elem := range generic {
@@ -168,7 +198,7 @@ Loop:
168198 return metadata , multierror .Append (err , errors .New ("failure to reset secure boot database keys" ))
169199}
170200
171- func importSecureBootCertificate (ctx context.Context , generic []secureBootCertificateImporterProvider , database , certificatePEM string ) (metadata Metadata , err error ) {
201+ func importSecureBootCertificate (ctx context.Context , generic []secureBootCertificateImporterProvider , database SecureBootDatabase , certificatePEM string ) (metadata Metadata , err error ) {
172202 metadata = newMetadata ()
173203Loop:
174204 for _ , elem := range generic {
@@ -258,7 +288,7 @@ func SetSecureBootFromInterfaces(ctx context.Context, generic []interface{}, ena
258288
259289// ResetSecureBootKeysFromInterfaces resets the UEFI Secure Boot key databases using
260290// the first successful SecureBootKeysResetter implementation found in generic.
261- func ResetSecureBootKeysFromInterfaces (ctx context.Context , generic []interface {}, resetType string ) (metadata Metadata , err error ) {
291+ func ResetSecureBootKeysFromInterfaces (ctx context.Context , generic []interface {}, resetType ResetSecureBootKeysType ) (metadata Metadata , err error ) {
262292 implementations := make ([]secureBootKeysResetterProvider , 0 )
263293 for _ , elem := range generic {
264294 if elem == nil {
@@ -290,7 +320,7 @@ func ResetSecureBootKeysFromInterfaces(ctx context.Context, generic []interface{
290320// ResetSecureBootDatabaseKeysFromInterfaces resets a single UEFI Secure Boot key
291321// database using the first successful SecureBootDatabaseKeysResetter
292322// implementation found in generic.
293- func ResetSecureBootDatabaseKeysFromInterfaces (ctx context.Context , generic []interface {}, database , resetType string ) (metadata Metadata , err error ) {
323+ func ResetSecureBootDatabaseKeysFromInterfaces (ctx context.Context , generic []interface {}, database SecureBootDatabase , resetType ResetSecureBootDatabaseKeysType ) (metadata Metadata , err error ) {
294324 implementations := make ([]secureBootDatabaseKeysResetterProvider , 0 )
295325 for _ , elem := range generic {
296326 if elem == nil {
@@ -322,7 +352,7 @@ func ResetSecureBootDatabaseKeysFromInterfaces(ctx context.Context, generic []in
322352// ImportSecureBootCertificateFromInterfaces enrolls a certificate into a single
323353// UEFI Secure Boot key database using the first successful
324354// SecureBootCertificateImporter implementation found in generic.
325- func ImportSecureBootCertificateFromInterfaces (ctx context.Context , generic []interface {}, database , certificatePEM string ) (metadata Metadata , err error ) {
355+ func ImportSecureBootCertificateFromInterfaces (ctx context.Context , generic []interface {}, database SecureBootDatabase , certificatePEM string ) (metadata Metadata , err error ) {
326356 implementations := make ([]secureBootCertificateImporterProvider , 0 )
327357 for _ , elem := range generic {
328358 if elem == nil {
0 commit comments