-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rebase auditor-cli code onto refactored cli package
- Loading branch information
Showing
21 changed files
with
266 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package auditor | ||
|
||
import ( | ||
"github.com/coniks-sys/coniks-go/application" | ||
"github.com/coniks-sys/coniks-go/crypto/sign" | ||
"github.com/coniks-sys/coniks-go/protocol" | ||
) | ||
|
||
// directoryConfig contains the auditor's configuration needed to send a | ||
// request to a CONIKS server: the path to the server's signing public-key | ||
// file and the actual public-key parsed from that file; the path to | ||
// the server's initial STR file and the actual STR parsed from that file; | ||
// the server's address for receiving STR history requests. | ||
type directoryConfig struct { | ||
SignPubkeyPath string `toml:"sign_pubkey_path"` | ||
SigningPubKey sign.PublicKey | ||
|
||
InitSTRPath string `toml:"init_str_path"` | ||
InitSTR *protocol.DirSTR | ||
|
||
Address string `toml:"address"` | ||
} | ||
|
||
// Config maintains the auditor's configurations for all CONIKS | ||
// directories it tracks. | ||
type Config struct { | ||
TrackedDirs []*directoryConfig | ||
// TODO: Add server-side auditor config | ||
} | ||
|
||
var _ application.AppConfig = (*Config)(nil) | ||
|
||
func newDirectoryConfig(signPubkeyPath, initSTRPath, serverAddr string) *directoryConfig { | ||
var dconf = directoryConfig{ | ||
SignPubkeyPath: signPubkeyPath, | ||
InitSTRPath: initSTRPath, | ||
Address: serverAddr, | ||
} | ||
|
||
return &dconf | ||
} | ||
|
||
// NewConfig initializes a new auditor configuration with the given | ||
// server signing public key path, registration address, and | ||
// server address. | ||
func NewConfig() *Config { | ||
var conf = Config{ | ||
TrackedDirs: make([]*directoryConfig, 0), | ||
} | ||
return &conf | ||
} | ||
|
||
// AddDirectoryConfig adds the given CONIKS server settings to the | ||
// auditor's configuration. | ||
func (conf *Config) AddDirectoryConfig(signPubkeyPath, initSTRPath, serverAddr string) { | ||
dconf := newDirectoryConfig(signPubkeyPath, initSTRPath, serverAddr) | ||
conf.TrackedDirs = append(conf.TrackedDirs, dconf) | ||
} | ||
|
||
// Load initializes an auditor's configuration from the given file. | ||
// For each directory in the configuration, it reads the signing public-key file | ||
// and initial STR file, and parses the actual key and initial STR. | ||
func (conf *Config) Load(file string) error { | ||
tmp, err := application.LoadConfig(file) | ||
if err != nil { | ||
return err | ||
} | ||
conf = tmp.(*Config) | ||
|
||
for _, dconf := range conf.TrackedDirs { | ||
// load signing key | ||
signPubKey, err := application.LoadSigningPubKey(dconf.SignPubkeyPath, file) | ||
if err != nil { | ||
return err | ||
} | ||
dconf.SigningPubKey = signPubKey | ||
|
||
// load initial STR | ||
initSTR, err := application.LoadInitSTR(dconf.InitSTRPath, file) | ||
if err != nil { | ||
return err | ||
} | ||
dconf.InitSTR = initSTR | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
/* | ||
Package coniksauditor provides an executable of | ||
an auditor for the CONIKS key management system. | ||
Package auditor implements the CONIKS auditor service | ||
protocol. | ||
Note: The auditor can current only be used in | ||
interactive test mode with a server, and does not | ||
accept auditing requests from CONIKS clients. | ||
*/ | ||
package coniksauditor | ||
package auditor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Executable CONIKS auditor. See README for | ||
// usage instructions. | ||
package main | ||
|
||
import ( | ||
"github.com/coniks-sys/coniks-go/cli" | ||
"github.com/coniks-sys/coniks-go/cli/coniksauditor/internal/cmd" | ||
) | ||
|
||
func main() { | ||
cli.Execute(cmd.RootCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path" | ||
|
||
"github.com/coniks-sys/coniks-go/application" | ||
"github.com/coniks-sys/coniks-go/application/auditor" | ||
"github.com/coniks-sys/coniks-go/cli" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var initCmd = cli.NewInitCommand("CONIKS auditor", mkConfigOrExit) | ||
|
||
func init() { | ||
RootCmd.AddCommand(initCmd) | ||
initCmd.Flags().StringP("dir", "d", ".", | ||
"Location of directory for storing generated files") | ||
} | ||
|
||
func mkConfigOrExit(cmd *cobra.Command, args []string) { | ||
dir := cmd.Flag("dir").Value.String() | ||
file := path.Join(dir, "config.toml") | ||
|
||
conf := auditor.NewConfig() | ||
conf.AddDirectoryConfig("../../keyserver/coniksserver/sign.pub", | ||
"../../keyserver/coniksserver/init_str", | ||
"tcp://127.0.0.1:3000") | ||
|
||
if err := application.SaveConfig(file, conf); err != nil { | ||
fmt.Println("Couldn't save config. Error message: [" + | ||
err.Error() + "]") | ||
os.Exit(-1) | ||
} | ||
} |
Oops, something went wrong.