all: Remove crypto/md5 (#7493)

This is a mostly pointless change to make security scanners and static
analysis tools happy, as they all hate seeing md5. None of our md5 uses
were security relevant, but still. Only visible effect of this change is
that our temp file names for very long file names become slightly longer
than they were previously...
This commit is contained in:
Jakob Borg
2021-03-17 22:22:49 +01:00
committed by GitHub
parent f39477bbd5
commit f4372710bf
6 changed files with 44 additions and 52 deletions
+3 -4
View File
@@ -7,11 +7,12 @@
package fs
import (
"crypto/md5"
"fmt"
"path/filepath"
"runtime"
"strings"
"github.com/syncthing/syncthing/lib/sha256"
)
const (
@@ -50,9 +51,7 @@ func TempNameWithPrefix(name, prefix string) string {
tdir := filepath.Dir(name)
tbase := filepath.Base(name)
if len(tbase) > maxFilenameLength {
hash := md5.New()
hash.Write([]byte(name))
tbase = fmt.Sprintf("%x", hash.Sum(nil))
tbase = fmt.Sprintf("%x", sha256.Sum256([]byte(name)))
}
tname := fmt.Sprintf("%s%s.tmp", prefix, tbase)
return filepath.Join(tdir, tname)
+2 -2
View File
@@ -9,7 +9,6 @@ package ignore
import (
"bufio"
"bytes"
"crypto/md5"
"errors"
"fmt"
"io"
@@ -22,6 +21,7 @@ import (
"github.com/syncthing/syncthing/lib/fs"
"github.com/syncthing/syncthing/lib/osutil"
"github.com/syncthing/syncthing/lib/sha256"
"github.com/syncthing/syncthing/lib/sync"
)
@@ -373,7 +373,7 @@ func (m *Matcher) SkipIgnoredDirs() bool {
}
func hashPatterns(patterns []Pattern) string {
h := md5.New()
h := sha256.New()
for _, pat := range patterns {
h.Write([]byte(pat.String()))
h.Write([]byte("\n"))
+4 -3
View File
@@ -607,8 +607,9 @@ func TestHashOfEmpty(t *testing.T) {
firstHash := p1.Hash()
// Reloading with a non-existent file should empty the patterns and
// recalculate the hash. d41d8cd98f00b204e9800998ecf8427e is the md5 of
// nothing.
// recalculate the hash.
// e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 is
// the sah256 of nothing.
p1.Load("file/does/not/exist")
secondHash := p1.Hash()
@@ -616,7 +617,7 @@ func TestHashOfEmpty(t *testing.T) {
if firstHash == secondHash {
t.Error("hash did not change")
}
if secondHash != "d41d8cd98f00b204e9800998ecf8427e" {
if secondHash != "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" {
t.Error("second hash is not hash of empty string")
}
if len(p1.patterns) != 0 {