Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike committed Jul 10, 2024
1 parent 83cc97e commit 60414df
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
16 changes: 11 additions & 5 deletions internal/flags/activate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions internal/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"rpc/internal/amt"
"rpc/internal/config"
"rpc/internal/smb"
pkgConfig "rpc/pkg/config"
"rpc/pkg/utils"
"strconv"
"strings"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
6 changes: 3 additions & 3 deletions pkg/config/decrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions prf (1).yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fbqs6okyj0/xcIN8LIYmQlDOpoLp8SISkgetC53Ftc3WUjaax1g0qs9jndKM44fiTs2rHiJdchOtA+IatAwoQKzhyL1mpaapX5e+zYVlJq3roaZtO1ZF59etiVQLlEMHAYnJCj+SV1xxFzyxG+oDorKjj+zROsm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