Skip to content

Commit 93d055e

Browse files
authored
Improve default crypto.go (#151)
1 parent e1f4896 commit 93d055e

File tree

17 files changed

+277
-181
lines changed

17 files changed

+277
-181
lines changed

aeacus.go

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,20 @@ import (
1616
// `Y888""8o `Y8bod8P' `Y888""8o `Y8bod8P' `V88V"V8P' 8""888P' //
1717
//////////////////////////////////////////////////////////////////
1818

19+
const (
20+
DEBUG_BUILD = true
21+
)
22+
1923
func main() {
2024
app := &cli.App{
2125
UseShortOptionHandling: true,
2226
EnableBashCompletion: true,
2327
Name: "aeacus",
24-
Usage: "setup and score vulnerabilities in an image",
28+
Usage: "score image vulnerabilities",
2529
Before: func(c *cli.Context) error {
30+
if debugEnabled {
31+
verboseEnabled = true
32+
}
2633
err := determineDirectory()
2734
if err != nil {
2835
return err
@@ -105,20 +112,7 @@ func main() {
105112
},
106113
},
107114
{
108-
Name: "decrypt",
109-
Aliases: []string{"d"},
110-
Usage: "Check that encrypted scoring data file is valid",
111-
Action: func(c *cli.Context) error {
112-
permsCheck()
113-
err := readScoringData()
114-
if err == nil && verboseEnabled {
115-
printConfig()
116-
}
117-
return err
118-
},
119-
},
120-
{
121-
Name: "idprompt",
115+
Name: "prompt",
122116
Aliases: []string{"p"},
123117
Usage: "Launch TeamID GUI prompt",
124118
Action: func(c *cli.Context) error {

checks.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ func (c cond) requireArgs(args ...interface{}) {
6868
} else if v.Field(i).String() != "" {
6969
warn(c.Type+":", "specifying unnecessary argument '"+vType.Field(i).Name+"'")
7070
}
71-
7271
}
7372
}
7473

@@ -103,6 +102,13 @@ func runCheck(cond cond) bool {
103102
not := "Not"
104103
condFunc := ""
105104
negation := false
105+
106+
// Ensure that condition type is a valid length
107+
if len(cond.Type) <= len(not) {
108+
fail(`Condition type "` + cond.Type + `" is not long enough to be valid`)
109+
return false
110+
}
111+
106112
condEnding := cond.Type[len(cond.Type)-len(not) : len(cond.Type)]
107113
if condEnding == not {
108114
negation = true
@@ -125,6 +131,11 @@ func runCheck(cond cond) bool {
125131
}
126132

127133
debug("Result is", result, "and error is", err)
134+
135+
if verboseEnabled && !err.IsNil() {
136+
warn(condFunc, "returned an error:", err)
137+
}
138+
128139
return err.IsNil() && result
129140
}
130141

@@ -164,8 +175,7 @@ func (c cond) DirContains() (bool, error) {
164175
files = append(files, path)
165176
}
166177
if len(files) > 10000 {
167-
fail("Recursive indexing has exceeded limit, erroring out.")
168-
return errors.New("Indexed too many files in recursive search")
178+
return errors.New("attempted to index too many files in recursive search")
169179
}
170180
return nil
171181
})
@@ -206,7 +216,6 @@ func (c cond) FileContains() (bool, error) {
206216
for _, line := range strings.Split(fileContent, "\n") {
207217
found, err = regexp.Match(c.Value, []byte(line))
208218
if err != nil {
209-
fail("There's an error with your regular expression for FileContains: " + err.Error())
210219
return false, err
211220
}
212221
if found {

checks_linux.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ func (c cond) Command() (bool, error) {
2323
}
2424
err := shellCommand(c.Cmd)
2525
if err != nil {
26+
// This check does not return errors, since it is based on successful
27+
// execution. If any errors occurred, it means that the check failed,
28+
// not errored out.
29+
//
30+
// It would be an error if failure to execute the command resulted in
31+
// an inability to meaningfully score the check (e.g., if the uname
32+
// syscall failed for KernelVersion).
2633
return false, nil
2734
}
2835
return true, nil
@@ -61,6 +68,7 @@ func (c cond) KernelVersion() (bool, error) {
6168
}
6269
releaseUint = append(releaseUint, uint8(utsname.Release[i]))
6370
}
71+
debug("System uname value is", string(releaseUint), "and our value is", c.Value)
6472
return string(releaseUint) == c.Value, err
6573
}
6674

@@ -73,8 +81,10 @@ func (c cond) PasswordChanged() (bool, error) {
7381
for _, line := range strings.Split(fileContent, "\n") {
7482
if strings.Contains(line, c.User+":") {
7583
if strings.Contains(line, c.User+":"+c.Value) {
84+
debug("Exact value found in /etc/shadow for user", c.User+":", line)
7685
return false, nil
7786
}
87+
debug("Differing value found in /etc/shadow for user", c.User+":", line)
7888
return true, nil
7989
}
8090
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ func TestCommand(t *testing.T) {
1313
t.Error(c, "failed:", out, err)
1414
}
1515

16-
// Should fail: command execution fails
16+
// Should fail: command return false
1717
c.Cmd = "commanddoesntexist"
1818
out, err = c.Command()
19-
if err == nil || out != false {
19+
if err != nil || out != false {
2020
t.Error(c, "failed:", out, err)
2121
}
2222

23-
// Should fail: command returns error
23+
// Should fail: command return false
2424
c.Cmd = "cat /etc/file/doesnt/exist"
2525
out, err = c.Command()
26-
if err == nil || out != false {
26+
if err != nil || out != false {
2727
t.Error(c, "failed:", out, err)
2828
}
2929
}

checks_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func (c cond) RegistryKey() (bool, error) {
171171
return false, errors.New("Unknown registry hive " + registryHiveText)
172172
}
173173

174-
debug("Getting key", keyPath, "from hive ", registryHiveText)
174+
debug("Getting key", keyPath, "from hive", registryHiveText)
175175
// Actually get the key
176176
k, err := registry.OpenKey(registryHive, keyPath, registry.QUERY_VALUE)
177177
if err != nil {

configs.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func parseConfig(configContent string) {
3030

3131
if conf.Remote != "" {
3232
if conf.Remote[len(conf.Remote)-1] == '/' {
33-
fail("Your remote URL must not end with a slash:", conf.Remote[:len(conf.Remote)-1])
33+
fail("Your remote URL must not end with a slash: try", conf.Remote[:len(conf.Remote)-1])
3434
os.Exit(1)
3535
}
3636
if conf.Name == "" {
@@ -70,11 +70,11 @@ func writeConfig() {
7070
}
7171

7272
// ReadConfig parses the scoring configuration file.
73-
func readConfig() error {
73+
func readConfig() {
7474
fileContent, err := readFile(dirPath + scoringConf)
7575
if err != nil {
7676
fail("Configuration file (" + dirPath + scoringConf + ") not found!")
77-
return err
77+
os.Exit(1)
7878
}
7979
parseConfig(fileContent)
8080
assignPoints()
@@ -83,7 +83,6 @@ func readConfig() error {
8383
printConfig()
8484
}
8585
obfuscateConfig()
86-
return nil
8786
}
8887

8988
// PrintConfig offers a printed representation of the config, as parsed

0 commit comments

Comments
 (0)