diff --git a/internal/flags/activate.go b/internal/flags/activate.go index 3fe05236..ec5a672a 100644 --- a/internal/flags/activate.go +++ b/internal/flags/activate.go @@ -29,6 +29,7 @@ func (f *Flags) handleActivateCommand() error { f.amtActivateCommand.BoolVar(&f.SkipIPRenew, "skipIPRenew", false, "skip DHCP renewal of the IP address if AMT becomes enabled") // for local activation in ACM mode need a few more items f.amtActivateCommand.StringVar(&f.configContent, "config", "", "specify a config file or smb: file share URL") + f.amtActivateCommand.StringVar(&f.configContent, "configv2", "", "specify a config file or smb: file share URL") f.amtActivateCommand.StringVar(&f.LocalConfig.ACMSettings.AMTPassword, "amtPassword", f.lookupEnvOrString("AMT_PASSWORD", ""), "amt password") f.amtActivateCommand.StringVar(&f.LocalConfig.ACMSettings.ProvisioningCert, "provisioningCert", f.lookupEnvOrString("PROVISIONING_CERT", ""), "provisioning certificate") f.amtActivateCommand.StringVar(&f.LocalConfig.ACMSettings.ProvisioningCertPwd, "provisioningCertPwd", f.lookupEnvOrString("PROVISIONING_CERT_PASSWORD", ""), "provisioning certificate password") @@ -82,12 +83,17 @@ func (f *Flags) handleActivateCommand() error { fmt.Println("must specify -ccm or -acm, but not both") return utils.InvalidParameterCombination } - - err := f.handleLocalConfig() - if err != nil { - return utils.FailedReadingConfiguration + if f.configContentV2 != "" { + err := f.handleLocalConfigV2() + if err != nil { + return utils.FailedReadingConfiguration + } + } else { + err := f.handleLocalConfig() + if err != nil { + return utils.FailedReadingConfiguration + } } - if f.LocalConfig.ACMSettings.AMTPassword == "" && f.Password == "" { if rc := f.ReadNewPasswordTo(&f.Password, "New AMT Password"); rc != nil { return rc diff --git a/internal/flags/flags.go b/internal/flags/flags.go index 82880dab..66571dad 100644 --- a/internal/flags/flags.go +++ b/internal/flags/flags.go @@ -15,6 +15,7 @@ import ( "rpc/internal/amt" "rpc/internal/config" "rpc/internal/smb" + pkgConfig "rpc/pkg/config" "rpc/pkg/utils" "strconv" "strings" @@ -76,8 +77,10 @@ type Flags struct { UseACM bool EchoPass bool configContent string + configContentV2 string UUID string LocalConfig config.Config + LocalConfigV2 pkgConfig.Configuration amtInfoCommand *flag.FlagSet amtActivateCommand *flag.FlagSet amtDeactivateCommand *flag.FlagSet @@ -345,3 +348,13 @@ func (f *Flags) handleLocalConfig() error { } return nil } + +func (f *Flags) handleLocalConfigV2() error { + content, err := pkgConfig.ReadAndDecryptFile(f.configContentV2, []byte("")) + if err != nil { + log.Error("config error: ", err) + return err + } + + f.LocalConfigV2 = content +} diff --git a/pkg/config/decrypt.go b/pkg/config/decrypt.go index 9ffae362..227becd9 100644 --- a/pkg/config/decrypt.go +++ b/pkg/config/decrypt.go @@ -11,7 +11,7 @@ import ( ) // Decrypt ciphertext using AES-GCM with the provided key -func decrypt(cipherText string, key []byte) ([]byte, error) { +func Decrypt(cipherText string, key []byte) ([]byte, error) { data, err := base64.StdEncoding.DecodeString(cipherText) if err != nil { return nil, err @@ -41,13 +41,13 @@ func decrypt(cipherText string, key []byte) ([]byte, error) { } // Read encrypted data from file and decrypt it -func readAndDecryptFile(filePath string, key []byte) (Configuration, error) { +func ReadAndDecryptFile(filePath string, key []byte) (Configuration, error) { encryptedData, err := ioutil.ReadFile(filePath) if err != nil { return Configuration{}, err } - decryptedData, err := decrypt(string(encryptedData), key) + decryptedData, err := Decrypt(string(encryptedData), key) if err != nil { return Configuration{}, err } diff --git a/prf (1).yaml b/prf (1).yaml new file mode 100644 index 00000000..a662d228 --- /dev/null +++ b/prf (1).yaml @@ -0,0 +1 @@ +Fbqs6okyj0/xcIN8LIYmQlDOpoLp8SISkgetC53Ftc3WUjaax1g0qs9jndKM44fiTs2rHiJdchOtA+IatAwoQKzhyL1mpaapX5e+zYVlJq3roaZtO1ZF59etiVQLlEMHAYnJCj+SV1xxFzyxG+oDorKjj+zROsm6RRH/XKlGGY0CmYnS/QOJoR1COA2xNiuq/VqLKNv4Xas1kfEwRPmDNccpOblq81m8HHxJmuSD/cvHxwTTQ4b8mohKHenBrThxeEy5muD0ElyhPuEH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