From 30c569259de53afedcc2458fbc3f33aa1ba182d0 Mon Sep 17 00:00:00 2001 From: moloch-- <875022+moloch--@users.noreply.github.com> Date: Sat, 4 Jun 2022 11:51:28 -0700 Subject: [PATCH] Outline auth support for private armories --- client/assets/armories.go | 30 +++++++++++++++++++++++++++--- client/command/armory/install.go | 1 + client/console/console.go | 3 +-- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/client/assets/armories.go b/client/assets/armories.go index cfb11ba113..625b9b9e18 100644 --- a/client/assets/armories.go +++ b/client/assets/armories.go @@ -21,7 +21,9 @@ package assets import ( "encoding/json" "io/ioutil" + "log" "os" + "os/exec" "path/filepath" ) @@ -30,8 +32,10 @@ const ( ) var ( + // DefaultArmoryPublicKey - The default public key for the armory DefaultArmoryPublicKey string - DefaultArmoryRepoURL string + // DefaultArmoryRepoURL - The default repo url for the armory + DefaultArmoryRepoURL string defaultArmoryConfig = &ArmoryConfig{ PublicKey: DefaultArmoryPublicKey, @@ -39,9 +43,12 @@ var ( } ) +// ArmoryConfig - The armory config file type ArmoryConfig struct { - PublicKey string `json:"public_key"` - RepoURL string `json:"repo_url"` + PublicKey string `json:"public_key"` + RepoURL string `json:"repo_url"` + Authorization string `json:"authorization"` + AuthorizationCmd string `json:"authorization_cmd"` } // GetArmoriesConfig - The parsed armory config file @@ -59,5 +66,22 @@ func GetArmoriesConfig() []*ArmoryConfig { if err != nil { return []*ArmoryConfig{defaultArmoryConfig} } + for _, armoryConfig := range armoryConfigs { + if armoryConfig.AuthorizationCmd != "" { + armoryConfig.Authorization = executeAuthorizationCmd(armoryConfig) + } + } return append(armoryConfigs, defaultArmoryConfig) } + +func executeAuthorizationCmd(armoryConfig *ArmoryConfig) string { + if armoryConfig.AuthorizationCmd == "" { + return "" + } + out, err := exec.Command(armoryConfig.AuthorizationCmd).CombinedOutput() + if err != nil { + log.Printf("Failed to execute authorization_cmd '%s': %v", armoryConfig.AuthorizationCmd, err) + return "" + } + return string(out) +} diff --git a/client/command/armory/install.go b/client/command/armory/install.go index 4194524aa1..9a71dcd0f6 100644 --- a/client/command/armory/install.go +++ b/client/command/armory/install.go @@ -35,6 +35,7 @@ import ( ) var ( + // ErrPackageNotFound - The package was not found ErrPackageNotFound = errors.New("package not found") ) diff --git a/client/console/console.go b/client/console/console.go index ed65ff9c9c..0deff64d17 100644 --- a/client/console/console.go +++ b/client/console/console.go @@ -26,7 +26,6 @@ import ( "io/ioutil" "log" insecureRand "math/rand" - "path" "path/filepath" "strconv" "strings" @@ -109,7 +108,7 @@ func Start(rpc rpcpb.SliverRPCClient, bindCmds BindCmds, extraCmds BindCmds, isS App: grumble.New(&grumble.Config{ Name: "Sliver", Description: "Sliver Client", - HistoryFile: path.Join(assets.GetRootAppDir(), "history"), + HistoryFile: filepath.Join(assets.GetRootAppDir(), "history"), PromptColor: color.New(), HelpHeadlineColor: color.New(), HelpHeadlineUnderline: true,