From 5abcdf5362ca356f9268bbddfff1119e2dd19d05 Mon Sep 17 00:00:00 2001 From: naiba Date: Sun, 29 Aug 2021 14:41:00 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20agent:=20SSL=E8=AF=81?= =?UTF-8?q?=E4=B9=A6=E6=A0=A1=E9=AA=8C=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/agent/main.go | 26 ++++---------------------- go.mod | 1 - go.sum | 2 -- 3 files changed, 4 insertions(+), 25 deletions(-) diff --git a/cmd/agent/main.go b/cmd/agent/main.go index 9989b8e..ca85982 100644 --- a/cmd/agent/main.go +++ b/cmd/agent/main.go @@ -2,7 +2,6 @@ package main import ( "context" - "crypto/tls" "encoding/json" "errors" "fmt" @@ -10,13 +9,11 @@ import ( "log" "net" "net/http" - "net/url" "os" "os/exec" "time" "github.com/blang/semver" - "github.com/genkiroid/cert" "github.com/go-ping/ping" "github.com/gorilla/websocket" "github.com/p14yground/go-github-selfupdate/selfupdate" @@ -33,7 +30,6 @@ import ( ) func init() { - cert.TimeoutSeconds = 30 http.DefaultClient.Timeout = time.Second * 5 flag.CommandLine.ParseErrorsWhitelist.UnknownFlags = true } @@ -49,9 +45,6 @@ var ( inited bool updateCh = make(chan struct{}) // Agent 自动更新间隔 httpClient = &http.Client{ - Transport: &http.Transport{ - TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, - }, CheckRedirect: func(req *http.Request, via []*http.Request) error { return http.ErrUseLastResponse }, @@ -274,22 +267,11 @@ func handleHttpGetTask(task *pb.Task, result *pb.TaskResult) { } if err == nil { // 检查 SSL 证书信息 - serviceUrl, err := url.Parse(task.GetData()) - if err == nil { - if serviceUrl.Scheme == "https" { - c := cert.NewCert(serviceUrl.Host) - if c.Error != "" { - result.Data = "SSL证书错误:" + c.Error - } else { - result.Data = c.Issuer + "|" + c.NotAfter - result.Successful = true - } - } else { - result.Successful = true - } - } else { - result.Data = "URL解析错误:" + err.Error() + if len(resp.TLS.PeerCertificates) > 0 { + c := resp.TLS.PeerCertificates[0] + result.Data = c.Issuer.CommonName + "|" + c.NotAfter.In(time.Local).String() } + result.Successful = true } else { // HTTP 请求失败 result.Data = err.Error() diff --git a/go.mod b/go.mod index 1ebe3ab..8654ef5 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,6 @@ require ( github.com/blang/semver v3.5.1+incompatible github.com/creack/pty v1.1.14 github.com/fsnotify/fsnotify v1.4.9 - github.com/genkiroid/cert v0.0.0-20191007122723-897560fbbe50 github.com/gin-contrib/pprof v1.3.0 github.com/gin-gonic/gin v1.7.0 github.com/go-ping/ping v0.0.0-20210407214646-e4e642a95741 diff --git a/go.sum b/go.sum index 569a236..5373241 100644 --- a/go.sum +++ b/go.sum @@ -80,8 +80,6 @@ github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5Kwzbycv github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= -github.com/genkiroid/cert v0.0.0-20191007122723-897560fbbe50 h1:vLwmYBduhnWWqShoUGbVgDulhcLdanoYtCQxYMzwaqQ= -github.com/genkiroid/cert v0.0.0-20191007122723-897560fbbe50/go.mod h1:Pb7nyGYAfDyE/IkU6AJeRshIFko0wJC9cOqeYzYQffk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gin-contrib/pprof v1.3.0 h1:G9eK6HnbkSqDZBYbzG4wrjCsA4e+cvYAHUZw6W+W9K0= github.com/gin-contrib/pprof v1.3.0/go.mod h1:waMjT1H9b179t3CxuG1cV3DHpga6ybizwfBaM5OXaB0=