Beispiel #1
0
// Init starts initialization rutine
func Init() {
	args, errs := arg.Parse(argMap)

	if len(errs) != 0 {
		fmtc.Println("{r}Arguments parsing errors:{!}")

		for _, err := range errs {
			fmtc.Printf("  {r}%v{!}\n", err)
		}

		os.Exit(1)
	}

	if arg.GetB(ARG_NO_COLOR) {
		fmtc.DisableColors = true
	}

	if arg.GetB(ARG_VER) {
		showAbout()
		return
	}

	if arg.GetB(ARG_HELP) || len(args) == 0 {
		showUsage()
		return
	}

	runtime.GOMAXPROCS(2)

	process(args)
}
Beispiel #2
0
// quietCheck check some host without any output to console
func quietCheck(host string) (string, *HostCheckInfo) {
	var err error
	var info *sslscan.AnalyzeInfo

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

	params := sslscan.AnalyzeParams{
		Public:         arg.GetB(ARG_PUBLIC),
		StartNew:       arg.GetB(ARG_AVOID_CACHE),
		FromCache:      !arg.GetB(ARG_AVOID_CACHE),
		IgnoreMismatch: arg.GetB(ARG_IGNORE_MISMATCH),
	}

	ap, err := api.Analyze(host, params)

	if err != nil {
		return "Err", checkInfo
	}

	for {
		info, err = ap.Info()

		if err != nil {
			return "Err", checkInfo
		}

		if info.Status == sslscan.STATUS_ERROR {
			return "Err", checkInfo
		} else if info.Status == sslscan.STATUS_READY {
			break
		}

		time.Sleep(time.Second)
	}

	appendEndpointsInfo(checkInfo, info.Endpoints)

	lowestGrade, highestGrade := getGrades(info.Endpoints)

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

	return lowestGrade, checkInfo
}
Beispiel #3
0
func main() {
	args, errs := arg.Parse(argMap)

	if len(errs) != 0 {
		fmtc.Println("Arguments parsing errors:")

		for _, err := range errs {
			fmtc.Printf("  %s\n", err.Error())
		}

		os.Exit(1)
	}

	if arg.GetB(ARG_NO_COLOR) {
		fmtc.DisableColors = true
	}

	if arg.GetB(ARG_VER) {
		showAbout()
		return
	}

	if arg.GetB(ARG_HELP) || len(args) == 0 {
		showUsage()
		return
	}

	switch len(args) {
	case 1:
		process(args[0], "")
	case 2:
		process(args[0], args[1])
	default:
		showUsage()
	}
}
Beispiel #4
0
// check check some host
func check(host string) string {
	var err error
	var info *sslscan.AnalyzeInfo

	showServerMessage()

	params := sslscan.AnalyzeParams{
		Public:         arg.GetB(ARG_PUBLIC),
		StartNew:       arg.GetB(ARG_AVOID_CACHE),
		FromCache:      !arg.GetB(ARG_AVOID_CACHE),
		IgnoreMismatch: arg.GetB(ARG_IGNORE_MISMATCH),
	}

	fmtc.Printf("{*}%s{!} → ", host)

	ap, err := api.Analyze(host, params)

	if err != nil {
		fmtc.Printf("{r}%v{!}\n", err)
		return "T"
	}

	t := &fmtc.T{}

	for {
		info, err = ap.Info()

		if err != nil {
			t.Printf("{r}%v{!}\n", err)
			return "Err"
		}

		if info.Status == sslscan.STATUS_ERROR {
			t.Printf("{r}%s{!}\n", info.StatusMessage)
			return "Err"
		} else if info.Status == sslscan.STATUS_READY {
			break
		}

		if len(info.Endpoints) != 0 {
			message := getStatusInProgress(info.Endpoints)

			if message != "" {
				t.Printf("{s}%s...{!}", message)
			}
		}

		if info.Status == sslscan.STATUS_IN_PROGRESS {
			time.Sleep(6 * time.Second)
		} else {
			time.Sleep(2 * time.Second)
		}
	}

	if len(info.Endpoints) == 1 {
		t.Println(getColoredGrade(info.Endpoints[0].Grade))
	} else {
		t.Println(getColoredGrades(info.Endpoints))
	}

	if arg.GetB(ARG_DETAILED) {
		printDetailedInfo(ap, info)
	}

	lowestGrade, _ := getGrades(info.Endpoints)

	return lowestGrade
}
Beispiel #5
0
// process starting request processing
func process(args []string) {
	var (
		ok    bool
		err   error
		hosts []string
	)

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

	if err != nil {
		if !arg.GetB(ARG_FORMAT) {
			fmtc.Printf("{r}%v{!}\n", err)
		}

		os.Exit(1)
	}

	// By default all fine
	ok = true
	hosts = args

	if fsutil.CheckPerms("FR", hosts[0]) {
		hosts, err = readHostList(hosts[0])

		if err != nil && arg.GetB(ARG_FORMAT) {
			fmtc.Printf("{r}%v{!}\n", err)
			os.Exit(1)
		}
	}

	var (
		grade      string
		checksInfo []*HostCheckInfo
		checkInfo  *HostCheckInfo
	)

	for _, host := range hosts {

		switch {
		case arg.GetB(ARG_QUIET):
			grade, _ = quietCheck(host)
		case arg.GetB(ARG_FORMAT):
			grade, checkInfo = quietCheck(host)
			checksInfo = append(checksInfo, checkInfo)
		default:
			grade = check(host)
		}

		switch {
		case arg.GetB(ARG_PERFECT) && grade != "A+":
			ok = false
		case grade[:1] != "A":
			ok = false
		}
	}

	if arg.GetB(ARG_FORMAT) {
		switch arg.GetS(ARG_FORMAT) {
		case FORMAT_TEXT:
			encodeAsText(checksInfo)
		case FORMAT_JSON:
			encodeAsJSON(checksInfo)
		case FORMAT_XML:
			encodeAsXML(checksInfo)
		case FORMAT_YAML:
			encodeAsYAML(checksInfo)
		default:
			os.Exit(1)
		}
	}

	if arg.GetB(ARG_NOTIFY) {
		fmtc.Bell()
	}

	if !ok {
		os.Exit(1)
	}
}