Skip to content

deprecate sha1 #526

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
version: "2"
run:
allow-parallel-runners: true
linters:
enable:
- "gosec"
disable:
- "errcheck"
settings:
gosec:
includes:
- G501 # Import blocklist: crypto/md5
- G502 # Import blocklist: crypto/des
- G503 # Import blocklist: crypto/rc4
- G504 # Import blocklist: net/http/cgi
- G505 # Import blocklist: crypto/sha1
- G506 # Import blocklist: golang.org/x/crypto/md4
- G507 # Import blocklist: golang.org/x/crypto/ripemd160

10 changes: 5 additions & 5 deletions mage/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package mage

import (
"bytes"
"crypto/sha1"
"crypto/sha3"
"errors"
"flag"
"fmt"
Expand Down Expand Up @@ -173,7 +173,7 @@ func ParseAndRun(stdout, stderr io.Writer, stdin io.Reader, args []string) int {
case None:
return Invoke(inv)
default:
panic(fmt.Errorf("Unknown command type: %v", cmd))
panic(fmt.Errorf("unknown command type: %v", cmd))
}
}

Expand Down Expand Up @@ -656,13 +656,13 @@ func ExeName(goCmd, cacheDir string, files []string) (string, error) {
}
// hash the mainfile template to ensure if it gets updated, we make a new
// binary.
hashes = append(hashes, fmt.Sprintf("%x", sha1.Sum([]byte(mageMainfileTplString))))
hashes = append(hashes, fmt.Sprintf("%x", sha3.Sum256([]byte(mageMainfileTplString))))
sort.Strings(hashes)
ver, err := internal.OutputDebug(goCmd, "version")
if err != nil {
return "", err
}
hash := sha1.Sum([]byte(strings.Join(hashes, "") + magicRebuildKey + ver))
hash := sha3.Sum256([]byte(strings.Join(hashes, "") + magicRebuildKey + ver))
filename := fmt.Sprintf("%x", hash)

out := filepath.Join(cacheDir, filename)
Expand All @@ -679,7 +679,7 @@ func hashFile(fn string) (string, error) {
}
defer f.Close()

h := sha1.New()
h := sha3.New256()
if _, err := io.Copy(h, f); err != nil {
return "", fmt.Errorf("can't write data to hash: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion mage/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ func TestOnlyStdLib(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if !filepath.HasPrefix(pkg.Dir, build.Default.GOROOT) {
if !strings.HasPrefix(pkg.Dir, build.Default.GOROOT) {
t.Errorf("import of non-stdlib package: %s", s.Path.Value)
}
}
Expand Down
8 changes: 4 additions & 4 deletions mg/deps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestDepError(t *testing.T) {
t.Fatal("expected panic, but didn't get one")
}
actual := fmt.Sprint(err)
if "ouch" != actual {
if actual != "ouch" {
t.Fatalf(`expected to get "ouch" but got "%s"`, actual)
}
}()
Expand All @@ -103,7 +103,7 @@ func TestDepFatal(t *testing.T) {
t.Fatal("expected panic, but didn't get one")
}
actual := fmt.Sprint(v)
if "ouch!" != actual {
if actual != "ouch!" {
t.Fatalf(`expected to get "ouch!" but got "%s"`, actual)
}
err, ok := v.(error)
Expand Down Expand Up @@ -132,7 +132,7 @@ func TestDepTwoFatal(t *testing.T) {
}
actual := fmt.Sprint(v)
// order is non-deterministic, so check for both orders
if "ouch!\nbang!" != actual && "bang!\nouch!" != actual {
if actual != "ouch!\nbang!" && actual != "bang!\nouch!" {
t.Fatalf(`expected to get "ouch!" and "bang!" but got "%s"`, actual)
}
err, ok := v.(error)
Expand All @@ -157,7 +157,7 @@ func TestDepWithUnhandledFunc(t *testing.T) {
t.Fatalf("Expected type error from panic")
}
}()
var NotValid func(string) string = func(a string) string {
var NotValid = func(a string) string {
return a
}
Deps(NotValid)
Expand Down
6 changes: 3 additions & 3 deletions mg/fn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestFuncCheck(t *testing.T) {
t.Error("func is not on a namespace")
}

hasContext, isNamespace, err = checkF(Foo.Bare, nil)
_, _, err = checkF(Foo.Bare, nil)
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -117,11 +117,11 @@ func TestFuncCheck(t *testing.T) {
}

defer func() {
if r := recover(); r !=nil {
if r := recover(); r != nil {
t.Error("expected a nil function argument to be handled gracefully")
}
}()
_, _, err = checkF(nil, []interface{}{1,2})
_, _, err = checkF(nil, []interface{}{1, 2})
if err == nil {
t.Error("expected a nil function argument to be invalid")
}
Expand Down
9 changes: 2 additions & 7 deletions parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func checkDupes(info *PkgInfo, imports []*Import) error {
for _, f := range funcs[alias] {
ids = append(ids, f.ID())
}
return fmt.Errorf("alias %q duplicates existing target(s): %s\n", alias, strings.Join(ids, ", "))
return fmt.Errorf("alias %q duplicates existing target(s): %s", alias, strings.Join(ids, ", "))
}
funcs[alias] = append(funcs[alias], f)
}
Expand Down Expand Up @@ -792,11 +792,6 @@ func hasContextParam(ft *ast.FuncType) (bool, error) {
return true, nil
}

func hasVoidReturn(ft *ast.FuncType) bool {
res := ft.Results
return res.NumFields() == 0
}

func hasErrorReturn(ft *ast.FuncType) (bool, error) {
res := ft.Results
if res.NumFields() == 0 {
Expand Down Expand Up @@ -847,7 +842,7 @@ func funcType(ft *ast.FuncType) (*Function, error) {
}

func toOneLine(s string) string {
return strings.TrimSpace(strings.Replace(s, "\n", " ", -1))
return strings.TrimSpace(strings.ReplaceAll(s, "\n", " "))
}

var argTypes = map[string]string{
Expand Down