使用Go linter遇到安全问题

问题描述

我们使用以下lib

import "crypto/sha1"

在运行golangci-lint时,出现以下错误

G505: Blocklisted import crypto/sha1: weak cryptographic primitive (gosec) for "crypto/sha1"


 G401: Use of weak cryptographic primitive (gosec)
        sha := sha1.New()

是否可以做一些不排除它们的事情?不知道我了解那些问题。如果与安全无关,则排除...很简单。

更新

我们正在做什么

fdrContent,err := IoUtil.ReadFile(filepath.Join(path))
// gets the hashcode of the fdr file
h := sha1.New()
code,err := h.Write(fdrContent)
return code,err

解决方法

我在自己的gtarsum project中将h.Write用作in here

        h := sha256.New()
        for {
            buf := make([]byte,1024*1024)

            bytesRead,err := tr.Read(buf)
            if err != nil {
                if err != io.EOF {
                    panic(err)
                }
            }

            if bytesRead > 0 {
                _,err := h.Write(buf[:bytesRead])

如果没有明显的性能问题,您要做的就是切换到sha256
不再警告。
问题来自documented here项目中的我有shattered.io的sha1冲突。