cmd/geth: implement vulnerability check (#21859)
* cmd/geth: implement vulnerability check * cmd/geth: use minisign to verify vulnerability feed * cmd/geth: add the test too * cmd/geth: more minisig/signify testing * cmd/geth: support multiple pubfiles for signing * cmd/geth: add @holiman minisig pubkey * cmd/geth: polishes on vulnerability check * cmd/geth: fix ineffassign linter nit * cmd/geth: add CVE to version check struct * cmd/geth/testdata: add missing testfile * cmd/geth: add more keys to versionchecker * cmd/geth: support file:// URLs in version check * cmd/geth: improve key ID printing when signature check fails Co-authored-by: Felix Lange <fjl@twurst.com>
This commit is contained in:
parent
7770e41cb5
commit
15339cf1c9
|
@ -242,6 +242,7 @@ func init() {
|
|||
makecacheCommand,
|
||||
makedagCommand,
|
||||
versionCommand,
|
||||
versionCheckCommand,
|
||||
licenseCommand,
|
||||
// See config.go
|
||||
dumpConfigCommand,
|
||||
|
|
|
@ -31,6 +31,18 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
VersionCheckUrlFlag = cli.StringFlag{
|
||||
Name: "check.url",
|
||||
Usage: "URL to use when checking vulnerabilities",
|
||||
Value: "https://geth.ethereum.org/docs/vulnerabilities/vulnerabilities.json",
|
||||
}
|
||||
VersionCheckVersionFlag = cli.StringFlag{
|
||||
Name: "check.version",
|
||||
Usage: "Version to check",
|
||||
Value: fmt.Sprintf("Geth/v%v/%v-%v/%v",
|
||||
params.VersionWithCommit(gitCommit, gitDate),
|
||||
runtime.GOOS, runtime.GOARCH, runtime.Version()),
|
||||
}
|
||||
makecacheCommand = cli.Command{
|
||||
Action: utils.MigrateFlags(makecache),
|
||||
Name: "makecache",
|
||||
|
@ -65,6 +77,21 @@ Regular users do not need to execute it.
|
|||
Category: "MISCELLANEOUS COMMANDS",
|
||||
Description: `
|
||||
The output of this command is supposed to be machine-readable.
|
||||
`,
|
||||
}
|
||||
versionCheckCommand = cli.Command{
|
||||
Action: utils.MigrateFlags(versionCheck),
|
||||
Flags: []cli.Flag{
|
||||
VersionCheckUrlFlag,
|
||||
VersionCheckVersionFlag,
|
||||
},
|
||||
Name: "version-check",
|
||||
Usage: "Checks (online) whether the current version suffers from any known security vulnerabilities",
|
||||
ArgsUsage: "<versionstring (optional)>",
|
||||
Category: "MISCELLANEOUS COMMANDS",
|
||||
Description: `
|
||||
The version-check command fetches vulnerability-information from https://geth.ethereum.org/docs/vulnerabilities/vulnerabilities.json,
|
||||
and displays information about any security vulnerabilities that affect the currently executing version.
|
||||
`,
|
||||
}
|
||||
licenseCommand = cli.Command{
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
[
|
||||
{
|
||||
"name": "CorruptedDAG",
|
||||
"uid": "GETH-2020-01",
|
||||
"summary": "Mining nodes will generate erroneous PoW on epochs > `385`.",
|
||||
"description": "A mining flaw could cause miners to erroneously calculate PoW, due to an index overflow, if DAG size is exceeding the maximum 32 bit unsigned value.\n\nThis occurred on the ETC chain on 2020-11-06. This is likely to trigger for ETH mainnet around block `11550000`/epoch `385`, slated to occur early January 2021.\n\nThis issue is relevant only for miners, non-mining nodes are unaffected, since non-mining nodes use a smaller verification cache instead of a full DAG.",
|
||||
"links": [
|
||||
"https://github.com/ethereum/go-ethereum/pull/21793",
|
||||
"https://blog.ethereum.org/2020/11/12/geth_security_release/",
|
||||
"https://github.com/ethereum/go-ethereum/commit/567d41d9363706b4b13ce0903804e8acf214af49"
|
||||
],
|
||||
"introduced": "v1.6.0",
|
||||
"fixed": "v1.9.24",
|
||||
"published": "2020-11-12",
|
||||
"severity": "Medium",
|
||||
"check": "Geth\\/v1\\.(6|7|8)\\..*|Geth\\/v1\\.9\\.2(1|2|3)-.*"
|
||||
},
|
||||
{
|
||||
"name": "GoCrash",
|
||||
"uid": "GETH-2020-02",
|
||||
"summary": "A denial-of-service issue can be used to crash Geth nodes during block processing, due to an underlying bug in Go (CVE-2020-28362) versions < `1.15.5`, or `<1.14.12`",
|
||||
"description": "The DoS issue can be used to crash all Geth nodes during block processing, the effects of which would be that a major part of the Ethereum network went offline.\n\nOutside of Go-Ethereum, the issue is most likely relevant for all forks of Geth (such as TurboGeth or ETC’s core-geth) which is built with versions of Go which contains the vulnerability.",
|
||||
"links": [
|
||||
"https://blog.ethereum.org/2020/11/12/geth_security_release/",
|
||||
"https://groups.google.com/g/golang-announce/c/NpBGTTmKzpM",
|
||||
"https://github.com/golang/go/issues/42552"
|
||||
],
|
||||
"fixed": "v1.9.24",
|
||||
"published": "2020-11-12",
|
||||
"severity": "Critical",
|
||||
"check": "Geth.*\\/go1\\.(11(.*)|12(.*)|13(.*)|14|14\\.(\\d|10|11|)|15|15\\.[0-4])$"
|
||||
},
|
||||
{
|
||||
"name": "ShallowCopy",
|
||||
"uid": "GETH-2020-03",
|
||||
"summary": "A consensus flaw in Geth, related to `datacopy` precompile",
|
||||
"description": "Geth erroneously performed a 'shallow' copy when the precompiled `datacopy` (at `0x00...04`) was invoked. An attacker could deploy a contract that uses the shallow copy to corrupt the contents of the `RETURNDATA`, thus causing a consensus failure.",
|
||||
"links": [
|
||||
"https://blog.ethereum.org/2020/11/12/geth_security_release/"
|
||||
],
|
||||
"introduced": "v1.9.7",
|
||||
"fixed": "v1.9.17",
|
||||
"published": "2020-11-12",
|
||||
"severity": "Critical",
|
||||
"check": "Geth\\/v1\\.9\\.(7|8|9|10|11|12|13|14|15|16).*$"
|
||||
},
|
||||
{
|
||||
"name": "GethCrash",
|
||||
"uid": "GETH-2020-04",
|
||||
"summary": "A denial-of-service issue can be used to crash Geth nodes during block processing",
|
||||
"description": "Full details to be disclosed at a later date",
|
||||
"links": [
|
||||
"https://blog.ethereum.org/2020/11/12/geth_security_release/"
|
||||
],
|
||||
"introduced": "v1.9.16",
|
||||
"fixed": "v1.9.18",
|
||||
"published": "2020-11-12",
|
||||
"severity": "Critical",
|
||||
"check": "Geth\\/v1\\.9.(16|17).*$"
|
||||
}
|
||||
]
|
|
@ -0,0 +1,62 @@
|
|||
[
|
||||
{
|
||||
"name": "CorruptedDAG",
|
||||
"uid": "GETH-2020-01",
|
||||
"summary": "Mining nodes will generate erroneous PoW on epochs > `385`.",
|
||||
"description": "A mining flaw could cause miners to erroneously calculate PoW, due to an index overflow, if DAG size is exceeding the maximum 32 bit unsigned value.\n\nThis occurred on the ETC chain on 2020-11-06. This is likely to trigger for ETH mainnet around block `11550000`/epoch `385`, slated to occur early January 2021.\n\nThis issue is relevant only for miners, non-mining nodes are unaffected, since non-mining nodes use a smaller verification cache instead of a full DAG.",
|
||||
"links": [
|
||||
"https://github.com/ethereum/go-ethereum/pull/21793",
|
||||
"https://blog.ethereum.org/2020/11/12/geth_security_release/",
|
||||
"https://github.com/ethereum/go-ethereum/commit/567d41d9363706b4b13ce0903804e8acf214af49"
|
||||
],
|
||||
"introduced": "v1.6.0",
|
||||
"fixed": "v1.9.24",
|
||||
"published": "2020-11-12",
|
||||
"severity": "Medium",
|
||||
"check": "Geth\\/v1\\.(6|7|8)\\..*|Geth\\/v1\\.9\\.2(1|2|3)-.*",
|
||||
"CVE": "correct"
|
||||
},
|
||||
{
|
||||
"name": "GoCrash",
|
||||
"uid": "GETH-2020-02",
|
||||
"summary": "A denial-of-service issue can be used to crash Geth nodes during block processing, due to an underlying bug in Go (CVE-2020-28362) versions < `1.15.5`, or `<1.14.12`",
|
||||
"description": "The DoS issue can be used to crash all Geth nodes during block processing, the effects of which would be that a major part of the Ethereum network went offline.\n\nOutside of Go-Ethereum, the issue is most likely relevant for all forks of Geth (such as TurboGeth or ETC’s core-geth) which is built with versions of Go which contains the vulnerability.",
|
||||
"links": [
|
||||
"https://blog.ethereum.org/2020/11/12/geth_security_release/",
|
||||
"https://groups.google.com/g/golang-announce/c/NpBGTTmKzpM",
|
||||
"https://github.com/golang/go/issues/42552"
|
||||
],
|
||||
"fixed": "v1.9.24",
|
||||
"published": "2020-11-12",
|
||||
"severity": "Critical",
|
||||
"check": "Geth.*\\/go1\\.(11(.*)|12(.*)|13(.*)|14|14\\.(\\d|10|11|)|15|15\\.[0-4])$"
|
||||
},
|
||||
{
|
||||
"name": "ShallowCopy",
|
||||
"uid": "GETH-2020-03",
|
||||
"summary": "A consensus flaw in Geth, related to `datacopy` precompile",
|
||||
"description": "Geth erroneously performed a 'shallow' copy when the precompiled `datacopy` (at `0x00...04`) was invoked. An attacker could deploy a contract that uses the shallow copy to corrupt the contents of the `RETURNDATA`, thus causing a consensus failure.",
|
||||
"links": [
|
||||
"https://blog.ethereum.org/2020/11/12/geth_security_release/"
|
||||
],
|
||||
"introduced": "v1.9.7",
|
||||
"fixed": "v1.9.17",
|
||||
"published": "2020-11-12",
|
||||
"severity": "Critical",
|
||||
"check": "Geth\\/v1\\.9\\.(7|8|9|10|11|12|13|14|15|16).*$"
|
||||
},
|
||||
{
|
||||
"name": "GethCrash",
|
||||
"uid": "GETH-2020-04",
|
||||
"summary": "A denial-of-service issue can be used to crash Geth nodes during block processing",
|
||||
"description": "Full details to be disclosed at a later date",
|
||||
"links": [
|
||||
"https://blog.ethereum.org/2020/11/12/geth_security_release/"
|
||||
],
|
||||
"introduced": "v1.9.16",
|
||||
"fixed": "v1.9.18",
|
||||
"published": "2020-11-12",
|
||||
"severity": "Critical",
|
||||
"check": "Geth\\/v1\\.9.(16|17).*$"
|
||||
}
|
||||
]
|
|
@ -0,0 +1,4 @@
|
|||
untrusted comment: signature from minisign secret key
|
||||
RWQkliYstQBOKFQFQTjmCd6TPw07VZyWFSB3v4+1BM1kv8eHLE5FDy2OkPEqtdaL53xftlrHoJQie0uCcovdlSV8kpyxiLrxEQ0=
|
||||
trusted comment: timestamp:1605618622 file:vulnerabilities.json
|
||||
osAPs4QPdDkmiWQxqeMIzYv/b+ZGxJ+19Sbrk1Cpq4t2gHBT+lqFtwL3OCzKWWyjGRTmHfsVGBYpzEdPRQ0/BQ==
|
|
@ -0,0 +1,4 @@
|
|||
untrusted comment: Here's a comment
|
||||
RWQkliYstQBOKFQFQTjmCd6TPw07VZyWFSB3v4+1BM1kv8eHLE5FDy2OkPEqtdaL53xftlrHoJQie0uCcovdlSV8kpyxiLrxEQ0=
|
||||
trusted comment: Here's a trusted comment
|
||||
3CnkIuz9MEDa7uNyGZAbKZhuirwfiqm7E1uQHrd2SiO4Y8+Akw9vs052AyKw0s5nhbYHCZE2IMQdHNjKwxEGAQ==
|
|
@ -0,0 +1,4 @@
|
|||
untrusted comment: One more (untrusted) comment
|
||||
RWQkliYstQBOKFQFQTjmCd6TPw07VZyWFSB3v4+1BM1kv8eHLE5FDy2OkPEqtdaL53xftlrHoJQie0uCcovdlSV8kpyxiLrxEQ0=
|
||||
trusted comment: Here's a trusted comment
|
||||
3CnkIuz9MEDa7uNyGZAbKZhuirwfiqm7E1uQHrd2SiO4Y8+Akw9vs052AyKw0s5nhbYHCZE2IMQdHNjKwxEGAQ==
|
|
@ -0,0 +1,2 @@
|
|||
untrusted comment: minisign public key 284E00B52C269624
|
||||
RWQkliYstQBOKOdtClfgC3IypIPX6TAmoEi7beZ4gyR3wsaezvqOMWsp
|
|
@ -0,0 +1,2 @@
|
|||
untrusted comment: minisign encrypted secret key
|
||||
RWRTY0Iyz8kmPMKrqk6DCtlO9a33akKiaOQG1aLolqDxs52qvPoAAAACAAAAAAAAAEAAAAAArEiggdvyn6+WzTprirLtgiYQoU+ihz/HyGgjhuF+Pz2ddMduyCO+xjCHeq+vgVVW039fbsI8hW6LRGJZLBKV5/jdxCXAVVQE7qTQ6xpEdO0z8Z731/pV1hlspQXG2PNd16NMtwd9dWw=
|
|
@ -0,0 +1,2 @@
|
|||
untrusted comment: verify with ./signifykey.pub
|
||||
RWSKLNhZb0KdAbhRUhW2LQZXdnwttu2SYhM9EuC4mMgOJB85h7/YIPupf8/ldTs4N8e9Y/fhgdY40q5LQpt5IFC62fq0v8U1/w8=
|
|
@ -0,0 +1,2 @@
|
|||
untrusted comment: signify public key
|
||||
RWSKLNhZb0KdATtRT7mZC/bybI3t3+Hv/O2i3ye04Dq9fnT9slpZ1a2/
|
|
@ -0,0 +1,2 @@
|
|||
untrusted comment: signify secret key
|
||||
RWRCSwAAACpLQDLawSQCtI7eAVIvaiHzjTsTyJsfV5aKLNhZb0KdAWeICXJGa93/bHAcsY6jUh9I8RdEcDWEoGxmaXZC+IdVBPxDpkix9fBRGEUdKWHi3dOfqME0YRzErWI5AVg3cRw=
|
|
@ -0,0 +1,4 @@
|
|||
untrusted comment: signature from minisign secret key
|
||||
RWQkliYstQBOKFQFQTjmCd6TPw07VZyWFSB3v4+1BM1kv8eHLE5FDy2OkPEqtdaL53xftlrHoJQie0uCcovdlSV8kpyxiLrxEQ0=
|
||||
trusted comment: timestamp:1605618622 file:vulnerabilities.json
|
||||
osAPs4QPdDkmiWQxqeMIzYv/b+ZGxJ+19Sbrk1Cpq4t2gHBT+lqFtwL3OCzKWWyjGRTmHfsVGBYpzEdPRQ0/BQ==
|
|
@ -0,0 +1,4 @@
|
|||
untrusted comment: Here's a comment
|
||||
RWQkliYstQBOKFQFQTjmCd6TPw07VZyWFSB3v4+1BM1kv8eHLE5FDy2OkPEqtdaL53xftlrHoJQie0uCcovdlSV8kpyxiLrxEQ0=
|
||||
trusted comment: Here's a trusted comment
|
||||
3CnkIuz9MEDa7uNyGZAbKZhuirwfiqm7E1uQHrd2SiO4Y8+Akw9vs052AyKw0s5nhbYHCZE2IMQdHNjKwxEGAQ==
|
|
@ -0,0 +1,4 @@
|
|||
untrusted comment: One more (untrusted) comment
|
||||
RWQkliYstQBOKFQFQTjmCd6TPw07VZyWFSB3v4+1BM1kv8eHLE5FDy2OkPEqtdaL53xftlrHoJQie0uCcovdlSV8kpyxiLrxEQ0=
|
||||
trusted comment: Here's a trusted comment
|
||||
3CnkIuz9MEDa7uNyGZAbKZhuirwfiqm7E1uQHrd2SiO4Y8+Akw9vs052AyKw0s5nhbYHCZE2IMQdHNjKwxEGAQ==
|
|
@ -0,0 +1,169 @@
|
|||
// Copyright 2020 The go-ethereum Authors
|
||||
// This file is part of go-ethereum.
|
||||
//
|
||||
// go-ethereum is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// go-ethereum is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/jedisct1/go-minisign"
|
||||
"gopkg.in/urfave/cli.v1"
|
||||
)
|
||||
|
||||
var gethPubKeys []string = []string{
|
||||
//@holiman, minisign public key FB1D084D39BAEC24
|
||||
"RWQk7Lo5TQgd+wxBNZM+Zoy+7UhhMHaWKzqoes9tvSbFLJYZhNTbrIjx",
|
||||
//minisign public key 138B1CA303E51687
|
||||
"RWSHFuUDoxyLEzjszuWZI1xStS66QTyXFFZG18uDfO26CuCsbckX1e9J",
|
||||
//minisign public key FD9813B2D2098484
|
||||
"RWSEhAnSshOY/b+GmaiDkObbCWefsAoavjoLcPjBo1xn71yuOH5I+Lts",
|
||||
}
|
||||
|
||||
type vulnJson struct {
|
||||
Name string
|
||||
Uid string
|
||||
Summary string
|
||||
Description string
|
||||
Links []string
|
||||
Introduced string
|
||||
Fixed string
|
||||
Published string
|
||||
Severity string
|
||||
Check string
|
||||
CVE string
|
||||
}
|
||||
|
||||
func versionCheck(ctx *cli.Context) error {
|
||||
url := ctx.String(VersionCheckUrlFlag.Name)
|
||||
version := ctx.String(VersionCheckVersionFlag.Name)
|
||||
log.Info("Checking vulnerabilities", "version", version, "url", url)
|
||||
return checkCurrent(url, version)
|
||||
}
|
||||
|
||||
func checkCurrent(url, current string) error {
|
||||
var (
|
||||
data []byte
|
||||
sig []byte
|
||||
err error
|
||||
)
|
||||
if data, err = fetch(url); err != nil {
|
||||
return fmt.Errorf("could not retrieve data: %w", err)
|
||||
}
|
||||
if sig, err = fetch(fmt.Sprintf("%v.minisig", url)); err != nil {
|
||||
return fmt.Errorf("could not retrieve signature: %w", err)
|
||||
}
|
||||
if err = verifySignature(gethPubKeys, data, sig); err != nil {
|
||||
return err
|
||||
}
|
||||
var vulns []vulnJson
|
||||
if err = json.Unmarshal(data, &vulns); err != nil {
|
||||
return err
|
||||
}
|
||||
allOk := true
|
||||
for _, vuln := range vulns {
|
||||
r, err := regexp.Compile(vuln.Check)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.MatchString(current) {
|
||||
allOk = false
|
||||
fmt.Printf("## Vulnerable to %v (%v)\n\n", vuln.Uid, vuln.Name)
|
||||
fmt.Printf("Severity: %v\n", vuln.Severity)
|
||||
fmt.Printf("Summary : %v\n", vuln.Summary)
|
||||
fmt.Printf("Fixed in: %v\n", vuln.Fixed)
|
||||
if len(vuln.CVE) > 0 {
|
||||
fmt.Printf("CVE: %v\n", vuln.CVE)
|
||||
}
|
||||
if len(vuln.Links) > 0 {
|
||||
fmt.Printf("References:\n")
|
||||
for _, ref := range vuln.Links {
|
||||
fmt.Printf("\t- %v\n", ref)
|
||||
}
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
}
|
||||
if allOk {
|
||||
fmt.Println("No vulnerabilities found")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// fetch makes an HTTP request to the given url and returns the response body
|
||||
func fetch(url string) ([]byte, error) {
|
||||
if filep := strings.TrimPrefix(url, "file://"); filep != url {
|
||||
return ioutil.ReadFile(filep)
|
||||
}
|
||||
res, err := http.Get(url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
body, err := ioutil.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return body, nil
|
||||
}
|
||||
|
||||
// verifySignature checks that the sigData is a valid signature of the given
|
||||
// data, for pubkey GethPubkey
|
||||
func verifySignature(pubkeys []string, data, sigdata []byte) error {
|
||||
sig, err := minisign.DecodeSignature(string(sigdata))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// find the used key
|
||||
var key *minisign.PublicKey
|
||||
for _, pubkey := range pubkeys {
|
||||
pub, err := minisign.NewPublicKey(pubkey)
|
||||
if err != nil {
|
||||
// our pubkeys should be parseable
|
||||
return err
|
||||
}
|
||||
if pub.KeyId != sig.KeyId {
|
||||
continue
|
||||
}
|
||||
key = &pub
|
||||
break
|
||||
}
|
||||
if key == nil {
|
||||
log.Info("Signing key not trusted", "keyid", keyID(sig.KeyId), "error", err)
|
||||
return errors.New("signature could not be verified")
|
||||
}
|
||||
if ok, err := key.Verify(data, sig); !ok || err != nil {
|
||||
log.Info("Verification failed error", "keyid", keyID(key.KeyId), "error", err)
|
||||
return errors.New("signature could not be verified")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// keyID turns a binary minisign key ID into a hex string.
|
||||
// Note: key IDs are printed in reverse byte order.
|
||||
func keyID(id [8]byte) string {
|
||||
var rev [8]byte
|
||||
for i := range id {
|
||||
rev[len(rev)-1-i] = id[i]
|
||||
}
|
||||
return fmt.Sprintf("%X", rev)
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
// Copyright 2020 The go-ethereum Authors
|
||||
// This file is part of go-ethereum.
|
||||
//
|
||||
// go-ethereum is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// go-ethereum is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestVerification(t *testing.T) {
|
||||
// Signatures generated with `minisign`
|
||||
t.Run("minisig", func(t *testing.T) {
|
||||
// For this test, the pubkey is in testdata/minisign.pub
|
||||
// (the privkey is `minisign.sec`, if we want to expand this test. Password 'test' )
|
||||
pub := "RWQkliYstQBOKOdtClfgC3IypIPX6TAmoEi7beZ4gyR3wsaezvqOMWsp"
|
||||
testVerification(t, pub, "./testdata/vcheck/minisig-sigs/")
|
||||
})
|
||||
// Signatures generated with `signify-openbsd`
|
||||
t.Run("signify-openbsd", func(t *testing.T) {
|
||||
t.Skip("This currently fails, minisign expects 4 lines of data, signify provides only 2")
|
||||
// For this test, the pubkey is in testdata/signifykey.pub
|
||||
// (the privkey is `signifykey.sec`, if we want to expand this test. Password 'test' )
|
||||
pub := "RWSKLNhZb0KdATtRT7mZC/bybI3t3+Hv/O2i3ye04Dq9fnT9slpZ1a2/"
|
||||
testVerification(t, pub, "./testdata/vcheck/signify-sigs/")
|
||||
})
|
||||
}
|
||||
|
||||
func testVerification(t *testing.T, pubkey, sigdir string) {
|
||||
// Data to verify
|
||||
data, err := ioutil.ReadFile("./testdata/vcheck/data.json")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Signatures, with and without comments, both trusted and untrusted
|
||||
files, err := ioutil.ReadDir(sigdir)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, f := range files {
|
||||
sig, err := ioutil.ReadFile(filepath.Join(sigdir, f.Name()))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = verifySignature([]string{pubkey}, data, sig)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestJson(t *testing.T) {
|
||||
data, _ := ioutil.ReadFile("./testdata/vcheck/data2.json")
|
||||
var vulns []vulnJson
|
||||
if err := json.Unmarshal(data, &vulns); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(vulns) == 0 {
|
||||
t.Fatal("expected data, got none")
|
||||
}
|
||||
if have, want := vulns[0].CVE, "correct"; have != want {
|
||||
t.Errorf("have %v, want %v", have, want)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue