Skip to content

Commit

Permalink
revise manifest schema
Browse files Browse the repository at this point in the history
  • Loading branch information
C-Sto committed Sep 30, 2023
1 parent 84aed07 commit 7815b67
Show file tree
Hide file tree
Showing 9 changed files with 415 additions and 433 deletions.
34 changes: 19 additions & 15 deletions client/command/armory/armory.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ type pkgCacheEntry struct {
Pkg ArmoryPackage
Sig minisign.Signature
Alias *alias.AliasManifest
Extension extensions.MultiManifest
Extension *extensions.ExtensionManifest
LastErr error
}

Expand Down Expand Up @@ -141,7 +141,7 @@ func ArmoryCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []stri
if cacheEntry.Pkg.IsAlias {
aliases = append(aliases, cacheEntry.Alias)
} else {
exts = append(exts, cacheEntry.Extension...)
exts = append(exts, cacheEntry.Extension) //todo: check this isn't a bug
}
}
return true
Expand Down Expand Up @@ -183,7 +183,7 @@ func packagesInCache() ([]*alias.AliasManifest, []*extensions.ExtensionManifest)
if cacheEntry.Pkg.IsAlias {
aliases = append(aliases, cacheEntry.Alias)
} else {
exts = append(exts, cacheEntry.Extension...)
exts = append(exts, cacheEntry.Extension) //todo: check this isn't a bug
}
}
return true
Expand Down Expand Up @@ -217,9 +217,11 @@ func AliasExtensionOrBundleCompleter() carapace.Action {
aliasesComps := carapace.ActionValuesDescribed(results...).Tag("aliases").Invoke(ctx)
results = make([]string, 0)

for _, extensionPkg := range exts {
results = append(results, extensionPkg.CommandName)
results = append(results, extensionPkg.Help)
for _, extension := range exts {
for _, extensionPkg := range extension.ExtCommand {
results = append(results, extensionPkg.CommandName)
results = append(results, extensionPkg.Help)
}
}
extentionComps := carapace.ActionValuesDescribed(results...).Tag("extensions").Invoke(ctx)
results = make([]string, 0)
Expand Down Expand Up @@ -291,14 +293,16 @@ func PrintArmoryPackages(aliases []*alias.AliasManifest, exts []*extensions.Exte
URL: aliasPkg.RepoURL,
})
}
for _, extension := range exts {
entries = append(entries, pkgInfo{
CommandName: extension.CommandName,
Version: extension.Version,
Type: "Extension",
Help: extension.Help,
URL: extension.RepoURL,
})
for _, extm := range exts {
for _, extension := range extm.ExtCommand {
entries = append(entries, pkgInfo{
CommandName: extension.CommandName,
Version: extension.Manifest.Version,
Type: "Extension",
Help: extension.Help,
URL: extension.Manifest.RepoURL,
})
}
}

sliverMenu := con.App.Menu("implant")
Expand Down Expand Up @@ -533,7 +537,7 @@ func fetchPackageSignature(wg *sync.WaitGroup, armoryConfig *assets.ArmoryConfig
if armoryPkg.IsAlias {
pkgCacheEntry.Alias, err = alias.ParseAliasManifest(manifestData)
} else {
pkgCacheEntry.Extension, err = extensions.ParseMultiManifest(manifestData)
pkgCacheEntry.Extension, err = extensions.ParseExtensionManifest(manifestData)
}
if err != nil {
pkgCacheEntry.LastErr = fmt.Errorf("failed to parse trusted manifest in pkg signature: %s", err)
Expand Down
59 changes: 24 additions & 35 deletions client/command/armory/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,13 @@ func installPackageByName(name string, clientConfig ArmoryHTTPConfig, con *conso
}
}
}
for _, ext := range extensions {
if ext.CommandName == name || name == "all" {
installExtension(ext, clientConfig, con)
if name != "all" {
return nil
for _, extm := range extensions {
for _, ext := range extm.ExtCommand {
if ext.CommandName == name || name == "all" {
installExtension(ext.Manifest, clientConfig, con)
if name != "all" {
return nil
}
}
}
}
Expand Down Expand Up @@ -186,25 +188,27 @@ func installAliasPackageByName(name string, clientConfig ArmoryHTTPConfig, con *
return nil
}

func installExtension(ext *extensions.ExtensionManifest, clientConfig ArmoryHTTPConfig, con *console.SliverConsoleClient) {
func installExtension(extm *extensions.ExtensionManifest, clientConfig ArmoryHTTPConfig, con *console.SliverConsoleClient) {
deps := make(map[string]struct{})
resolveExtensionPackageDependencies(ext.CommandName, deps, clientConfig, con)
sliverMenu := con.App.Menu(constants.ImplantMenu)
for dep := range deps {
if extensions.CmdExists(dep, sliverMenu.Command) {
continue // Dependency is already installed
for _, ext := range extm.ExtCommand {
resolveExtensionPackageDependencies(ext.CommandName, deps, clientConfig, con)
sliverMenu := con.App.Menu(constants.ImplantMenu)
for dep := range deps {
if extensions.CmdExists(dep, sliverMenu.Command) {
continue // Dependency is already installed
}
err := installExtensionPackageByName(dep, clientConfig, con)
if err != nil {
con.PrintErrorf("Failed to install extension dependency '%s': %s", dep, err)
return
}
}
err := installExtensionPackageByName(dep, clientConfig, con)
err := installExtensionPackageByName(ext.CommandName, clientConfig, con)
if err != nil {
con.PrintErrorf("Failed to install extension dependency '%s': %s", dep, err)
con.PrintErrorf("Failed to install extension '%s': %s", ext.CommandName, err)
return
}
}
err := installExtensionPackageByName(ext.CommandName, clientConfig, con)
if err != nil {
con.PrintErrorf("Failed to install extension '%s': %s", ext.CommandName, err)
return
}
}

const maxDepDepth = 10 // Arbitrary recursive limit for dependencies
Expand All @@ -222,7 +226,7 @@ func resolveExtensionPackageDependencies(name string, deps map[string]struct{},
if entry == nil {
return
}
for _, multiExt := range entry.Extension {
for _, multiExt := range entry.Extension.ExtCommand {
if multiExt.DependsOn == "" {
continue // Avoid adding empty dependency
}
Expand Down Expand Up @@ -298,22 +302,7 @@ func installExtensionPackageByName(name string, clientConfig ArmoryHTTPConfig, c

con.Printf(console.Clearln + "\r") // Clear download message

installPath := extensions.InstallFromFilePath(tmpFile.Name(), true, con)
if installPath == nil {
return errors.New("failed to install extension")
}
manyfest, err := extensions.LoadExtensionManifest(filepath.Join(*installPath, extensions.ManifestFileName))
if err != nil {
return err
}
extensions.InstallFromDir(tmpFile.Name(), con, true)

sliverMenu := con.App.Menu(constants.ImplantMenu)
//
// if extensions.CmdExists(extCmd.Name, sliverMenu.Command) {
// con.App.Commands().Remove(extCmd.Name)
// }
for _, extCmd := range manyfest {
extensions.ExtensionRegisterCommand(extCmd, sliverMenu.Command, con)
}
return nil
}
8 changes: 5 additions & 3 deletions client/command/armory/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ func ArmorySearchCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args
}
}
matchedExts := []*extensions.ExtensionManifest{}
for _, ext := range exts {
if nameExpr.MatchString(ext.CommandName) {
matchedExts = append(matchedExts, ext)
for _, extm := range exts {
for _, ext := range extm.ExtCommand {
if nameExpr.MatchString(ext.CommandName) {
matchedExts = append(matchedExts, extm)
}
}
}
if len(matchedAliases) == 0 && len(matchedExts) == 0 {
Expand Down
15 changes: 7 additions & 8 deletions client/command/armory/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,18 @@ func checkForExtensionUpdates(clientConfig ArmoryHTTPConfig, con *console.Sliver
if err != nil {
continue
}
manyfest, err := extensions.ParseMultiManifest(data)
localManifest, err := extensions.ParseExtensionManifest(data)
if err != nil {
continue
}
for _, localManifest := range manyfest {
for _, latestExt := range cachedExtensions {
// Right now we don't try to enforce any kind of versioning, it is assumed if the version from
// the armory differs at all from the local version, the extension is out of date.
if latestExt.CommandName == localManifest.CommandName && latestExt.Version != localManifest.Version {
results = append(results, localManifest.CommandName)
}
for _, latestExt := range cachedExtensions {
// Right now we don't try to enforce any kind of versioning, it is assumed if the version from
// the armory differs at all from the local version, the extension is out of date.
if latestExt.Name == localManifest.Name && latestExt.Version != localManifest.Version {
results = append(results, localManifest.Name)
}
}
}

return results
}
22 changes: 12 additions & 10 deletions client/command/extensions/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,27 @@ func PrintExtensions(con *console.SliverConsoleClient) {

installedManifests := getInstalledManifests()
for _, extension := range loadedExtensions {
//for _, extension := range extensionm.ExtCommand {
installed := ""
if _, ok := installedManifests[extension.CommandName]; ok {
if _, ok := installedManifests[extension.Manifest.Name]; ok {
installed = "✅"
}
tw.AppendRow(table.Row{
extension.Name,
extension.Manifest.Name,
extension.CommandName,
strings.Join(extensionPlatforms(extension), ",\n"),
extension.Version,
extension.Manifest.Version,
installed,
extension.ExtensionAuthor,
extension.OriginalAuthor,
extension.RepoURL,
extension.Manifest.ExtensionAuthor,
extension.Manifest.OriginalAuthor,
extension.Manifest.RepoURL,
})
//}
}
con.Println(tw.Render())
}

func extensionPlatforms(extension *ExtensionManifest) []string {
func extensionPlatforms(extension *ExtCommand) []string {
platforms := map[string]string{}
for _, entry := range extension.Files {
platforms[fmt.Sprintf("%s/%s", entry.OS, entry.Arch)] = ""
Expand All @@ -109,17 +111,17 @@ func getInstalledManifests() map[string]*ExtensionManifest {
if err != nil {
continue
}
installedManifests[manifest.CommandName] = manifest
installedManifests[manifest.Name] = manifest
}
return installedManifests
}

// ExtensionsCommandNameCompleter - Completer for installed extensions command names
func ExtensionsCommandNameCompleter(con *console.SliverConsoleClient) carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
installedManifests := getInstalledManifests()
//installedManifests := getInstalledManifests()
results := []string{}
for _, manifest := range installedManifests {
for _, manifest := range loadedExtensions {
results = append(results, manifest.CommandName)
results = append(results, manifest.Help)
}
Expand Down
Loading

0 comments on commit 7815b67

Please sign in to comment.