Skip to content

Commit

Permalink
multimanifest extension support
Browse files Browse the repository at this point in the history
  • Loading branch information
C-Sto committed Aug 31, 2023
1 parent a9f885a commit 9d4486f
Show file tree
Hide file tree
Showing 7 changed files with 379 additions and 193 deletions.
8 changes: 4 additions & 4 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.ExtensionManifest
Extension extensions.MultiManifest
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...)
}
}
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...)
}
}
return true
Expand Down Expand Up @@ -533,7 +533,7 @@ func fetchPackageSignature(wg *sync.WaitGroup, armoryConfig *assets.ArmoryConfig
if armoryPkg.IsAlias {
pkgCacheEntry.Alias, err = alias.ParseAliasManifest(manifestData)
} else {
pkgCacheEntry.Extension, err = extensions.ParseExtensionManifest(manifestData)
pkgCacheEntry.Extension, err = extensions.ParseMultiManifest(manifestData)
}
if err != nil {
pkgCacheEntry.LastErr = fmt.Errorf("failed to parse trusted manifest in pkg signature: %s", err)
Expand Down
39 changes: 21 additions & 18 deletions client/command/armory/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,24 +222,25 @@ func resolveExtensionPackageDependencies(name string, deps map[string]struct{},
if entry == nil {
return
}
for _, multiExt := range entry.Extension {
if multiExt.DependsOn == "" {
continue // Avoid adding empty dependency
}

if entry.Extension.DependsOn == "" {
return // Avoid adding empty dependency
}

if entry.Extension.DependsOn == name {
return // Avoid infinite loop of something that depends on itself
}
// We also need to look out for circular dependencies, so if we've already
// seen this dependency, we stop resolving
if _, ok := deps[entry.Extension.DependsOn]; ok {
return // Already resolved
}
if maxDepDepth < len(deps) {
return
if multiExt.DependsOn == name {
continue // Avoid infinite loop of something that depends on itself
}
// We also need to look out for circular dependencies, so if we've already
// seen this dependency, we stop resolving
if _, ok := deps[multiExt.DependsOn]; ok {
continue // Already resolved
}
if maxDepDepth < len(deps) {
continue
}
deps[multiExt.DependsOn] = struct{}{}
resolveExtensionPackageDependencies(multiExt.DependsOn, deps, clientConfig, con)
}
deps[entry.Extension.DependsOn] = struct{}{}
resolveExtensionPackageDependencies(entry.Extension.DependsOn, deps, clientConfig, con)
}

func installExtensionPackageByName(name string, clientConfig ArmoryHTTPConfig, con *console.SliverConsoleClient) error {
Expand Down Expand Up @@ -301,7 +302,7 @@ func installExtensionPackageByName(name string, clientConfig ArmoryHTTPConfig, c
if installPath == nil {
return errors.New("failed to install extension")
}
extCmd, err := extensions.LoadExtensionManifest(filepath.Join(*installPath, extensions.ManifestFileName))
manyfest, err := extensions.LoadExtensionManifest(filepath.Join(*installPath, extensions.ManifestFileName))
if err != nil {
return err
}
Expand All @@ -311,6 +312,8 @@ func installExtensionPackageByName(name string, clientConfig ArmoryHTTPConfig, c
// if extensions.CmdExists(extCmd.Name, sliverMenu.Command) {
// con.App.Commands().Remove(extCmd.Name)
// }
extensions.ExtensionRegisterCommand(extCmd, sliverMenu.Command, con)
for _, extCmd := range manyfest {
extensions.ExtensionRegisterCommand(extCmd, sliverMenu.Command, con)
}
return nil
}
14 changes: 8 additions & 6 deletions client/command/armory/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,17 @@ func checkForExtensionUpdates(clientConfig ArmoryHTTPConfig, con *console.Sliver
if err != nil {
continue
}
localManifest, err := extensions.ParseExtensionManifest(data)
manyfest, err := extensions.ParseMultiManifest(data)
if err != nil {
continue
}
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 _, 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)
}
}
}
}
Expand Down
Loading

0 comments on commit 9d4486f

Please sign in to comment.