1 | /* Vuls - Vulnerability Scanner |
||
2 | Copyright (C) 2016 Future Architect, Inc. Japan. |
||
3 | |||
4 | This program is free software: you can redistribute it and/or modify |
||
5 | it under the terms of the GNU General Public License as published by |
||
6 | the Free Software Foundation, either version 3 of the License, or |
||
7 | (at your option) any later version. |
||
8 | |||
9 | This program is distributed in the hope that it will be useful, |
||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
12 | GNU General Public License for more details. |
||
13 | |||
14 | You should have received a copy of the GNU General Public License |
||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
16 | */ |
||
17 | |||
18 | package gost |
||
19 | |||
20 | import ( |
||
21 | "fmt" |
||
22 | "net/http" |
||
23 | "strings" |
||
24 | |||
25 | cnf "github.com/future-architect/vuls/config" |
||
26 | "github.com/future-architect/vuls/models" |
||
27 | "github.com/knqyf263/gost/db" |
||
28 | "github.com/parnurzeal/gorequest" |
||
29 | "golang.org/x/xerrors" |
||
30 | ) |
||
31 | |||
32 | // Client is the interface of OVAL client. |
||
33 | type Client interface { |
||
34 | FillWithGost(db.DB, *models.ScanResult) (int, error) |
||
35 | |||
36 | //TODO implement |
||
37 | // CheckHTTPHealth() error |
||
38 | // CheckIfGostFetched checks if Gost entries are fetched |
||
39 | // CheckIfGostFetched(db.DB, string, string) (bool, error) |
||
40 | // CheckIfGostFresh(db.DB, string, string) (bool, error) |
||
41 | } |
||
42 | |||
43 | // NewClient make Client by family |
||
44 | func NewClient(family string) Client { |
||
45 | switch family { |
||
46 | case cnf.RedHat, cnf.CentOS: |
||
47 | return RedHat{} |
||
48 | case cnf.Debian: |
||
49 | return Debian{} |
||
50 | case cnf.Windows: |
||
51 | return Microsoft{} |
||
52 | default: |
||
53 | return Pseudo{} |
||
54 | } |
||
55 | } |
||
56 | |||
57 | // Base is a base struct |
||
58 | type Base struct { |
||
59 | family string |
||
60 | } |
||
61 | |||
62 | // CheckHTTPHealth do health check |
||
63 | func (b Base) CheckHTTPHealth() error { |
||
64 | if !cnf.Conf.Gost.IsFetchViaHTTP() { |
||
65 | return nil |
||
66 | } |
||
67 | |||
68 | url := fmt.Sprintf("%s/health", cnf.Conf.Gost.URL) |
||
69 | var errs []error |
||
70 | var resp *http.Response |
||
71 | resp, _, errs = gorequest.New().Get(url).End() |
||
72 | // resp, _, errs = gorequest.New().SetDebug(config.Conf.Debug).Get(url).End() |
||
73 | // resp, _, errs = gorequest.New().Proxy(api.httpProxy).Get(url).End() |
||
74 | if 0 < len(errs) || resp == nil || resp.StatusCode != 200 { |
||
75 | return xerrors.Errorf("Failed to connect to gost server. url: %s, errs: %w", url, errs) |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
76 | } |
||
77 | return nil |
||
78 | } |
||
79 | |||
80 | // CheckIfGostFetched checks if oval entries are in DB by family, release. |
||
81 | func (b Base) CheckIfGostFetched(driver db.DB, osFamily string) (fetched bool, err error) { |
||
82 | //TODO |
||
83 | return true, nil |
||
84 | } |
||
85 | |||
86 | // CheckIfGostFresh checks if oval entries are fresh enough |
||
87 | func (b Base) CheckIfGostFresh(driver db.DB, osFamily string) (ok bool, err error) { |
||
88 | //TODO |
||
89 | return true, nil |
||
90 | } |
||
91 | |||
92 | // Pseudo is Gost client except for RedHat family and Debian |
||
93 | type Pseudo struct { |
||
94 | Base |
||
95 | } |
||
96 | |||
97 | // FillWithGost fills cve information that has in Gost |
||
98 | func (pse Pseudo) FillWithGost(driver db.DB, r *models.ScanResult) (int, error) { |
||
99 | return 0, nil |
||
100 | } |
||
101 | |||
102 | func major(osVer string) (majorVersion string) { |
||
103 | return strings.Split(osVer, ".")[0] |
||
104 | } |
||
105 |