Skip to content

Commit

Permalink
Merge pull request #18 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 1.2.0
  • Loading branch information
andyone authored Oct 14, 2016
2 parents a4816be + da8d6f4 commit f005e28
Show file tree
Hide file tree
Showing 5 changed files with 255 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ matrix:

before_install:
- go get -v pkg.re/essentialkaos/ek.v5
- go get -v pkg.re/essentialkaos/sslscan.v2
- go get -v pkg.re/essentialkaos/sslscan.v3

script:
- go build sslcli.go
73 changes: 53 additions & 20 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,16 @@ import (
"pkg.re/essentialkaos/ek.v5/fmtc"
"pkg.re/essentialkaos/ek.v5/fmtutil"
"pkg.re/essentialkaos/ek.v5/fsutil"
"pkg.re/essentialkaos/ek.v5/req"
"pkg.re/essentialkaos/ek.v5/usage"

"pkg.re/essentialkaos/sslscan.v2"
"pkg.re/essentialkaos/sslscan.v3"
)

// ////////////////////////////////////////////////////////////////////////////////// //

const (
APP = "SSLScan Client"
VER = "1.1.1"
VER = "1.2.0"
DESC = "Command-line client for the SSL Labs API"
)

Expand All @@ -49,22 +48,26 @@ const (

const (
FORMAT_TEXT = "text"
FORMAT_YAML = "yaml"
FORMAT_JSON = "json"
FORMAT_XML = "xml"
)

// ////////////////////////////////////////////////////////////////////////////////// //

type HostCheckInfo struct {
Host string `json:"host"`
LowestGrade string `json:"lowestGrade"`
HighestGrade string `json:"highestGrade"`
Endpoints []*EndpointCheckInfo `json:"endpoints"`
Host string `json:"host"`
LowestGrade string `json:"lowestGrade"`
HighestGrade string `json:"highestGrade"`
LowestGradeNum float64 `json:"lowestGradeNum"`
HighestGradeNum float64 `json:"highestGradeNum"`
Endpoints []*EndpointCheckInfo `json:"endpoints"`
}

type EndpointCheckInfo struct {
IPAdress string `json:"ipAddress"`
Grade string `json:"grade"`
IPAdress string `json:"ipAddress"`
Grade string `json:"grade"`
GradeNum float64 `json:"gradeNum"`
}

// ////////////////////////////////////////////////////////////////////////////////// //
Expand All @@ -83,6 +86,20 @@ var argMap = arg.Map{
ARG_VER: &arg.V{Type: arg.BOOL, Alias: "ver"},
}

var gradeNumMap = map[string]float64{
"A+": 4.3,
"A": 4.0,
"A-": 3.7,
"B": 3.0,
"C": 2.0,
"D": 1.0,
"E": 0.5,
"F": 0.0,
"T": 0.0,
"M": 0.0,
"Err": 0.0,
}

var api *sslscan.API

// ////////////////////////////////////////////////////////////////////////////////// //
Expand Down Expand Up @@ -117,8 +134,6 @@ func Init() {

runtime.GOMAXPROCS(2)

req.SetUserAgent(APP, VER)

process(args)
}

Expand All @@ -130,7 +145,7 @@ func process(args []string) {
hosts []string
)

api, err = sslscan.NewAPI()
api, err = sslscan.NewAPI("SSLCli", VER)

if err != nil {
if !arg.GetB(ARG_FORMAT) {
Expand Down Expand Up @@ -187,6 +202,8 @@ func process(args []string) {
encodeAsJSON(checksInfo)
case FORMAT_XML:
encodeAsXML(checksInfo)
case FORMAT_YAML:
encodeAsYAML(checksInfo)
default:
os.Exit(1)
}
Expand Down Expand Up @@ -274,8 +291,16 @@ func check(host string) string {
// showServerMessage show message from SSL Labs API
func showServerMessage() {
serverMessage := strings.Join(api.Info.Messages, " ")
wrappedMessage := fmtutil.Wrap(serverMessage, "", 80)

var coloredMessage string

fmtc.Printf("\n{s-}%s{!}\n\n", fmtutil.Wrap(serverMessage, "", 80))
for _, line := range strings.Split(wrappedMessage, "\n") {
coloredMessage += "{s-}" + line + "{!}\n"
}

fmtc.NewLine()
fmtc.Println(coloredMessage)
}

// quietCheck check some host without any output to console
Expand All @@ -284,10 +309,12 @@ func quietCheck(host string) (string, *HostCheckInfo) {
var info *sslscan.AnalyzeInfo

var checkInfo = &HostCheckInfo{
Host: host,
LowestGrade: "T",
HighestGrade: "T",
Endpoints: make([]*EndpointCheckInfo, 0),
Host: host,
LowestGrade: "T",
HighestGrade: "T",
LowestGradeNum: 0.0,
HighestGradeNum: 0.0,
Endpoints: make([]*EndpointCheckInfo, 0),
}

params := sslscan.AnalyzeParams{
Expand Down Expand Up @@ -323,7 +350,10 @@ func quietCheck(host string) (string, *HostCheckInfo) {

lowestGrade, highestGrade := getGrades(info.Endpoints)

checkInfo.LowestGrade, checkInfo.HighestGrade = lowestGrade, highestGrade
checkInfo.LowestGrade = lowestGrade
checkInfo.HighestGrade = highestGrade
checkInfo.LowestGradeNum = gradeNumMap[lowestGrade]
checkInfo.HighestGradeNum = gradeNumMap[highestGrade]

return lowestGrade, checkInfo
}
Expand Down Expand Up @@ -439,9 +469,12 @@ func readHostList(file string) ([]string, error) {
// appendEndpointsInfo append endpoint check result to struct with info about all checks for host
func appendEndpointsInfo(checkInfo *HostCheckInfo, endpoints []*sslscan.EndpointInfo) {
for _, endpoint := range endpoints {
grade := getNormGrade(endpoint.Grade)

checkInfo.Endpoints = append(checkInfo.Endpoints, &EndpointCheckInfo{
IPAdress: endpoint.IPAdress,
Grade: getNormGrade(endpoint.Grade),
Grade: grade,
GradeNum: gradeNumMap[grade],
})
}
}
Expand All @@ -461,7 +494,7 @@ func getNormGrade(grade string) string {
func showUsage() {
info := usage.NewInfo("", "host...")

info.AddOption(ARG_FORMAT, "Output result in different formats", "text|json|xml")
info.AddOption(ARG_FORMAT, "Output result in different formats", "text|json|yaml|xml")
info.AddOption(ARG_DETAILED, "Show detailed info for each endpoint")
info.AddOption(ARG_IGNORE_MISMATCH, "Proceed with assessments on certificate mismatch")
info.AddOption(ARG_AVOID_CACHE, "Disable cache usage")
Expand Down
Loading

0 comments on commit f005e28

Please sign in to comment.