Skip to content

proposal: crypto/x509: expose hash algorithm for SignatureAlgorithm #33317

@bodgit

Description

@bodgit

What version of Go are you using (go version)?

$ go version
go version go1.12.7 darwin/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/matt/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/matt/Documents/work"
GOPROXY=""
GORACE=""
GOROOT="/opt/local/lib/go"
GOTMPDIR=""
GOTOOLDIR="/opt/local/lib/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="/usr/bin/clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/_k/xdj1vdy51gb4pbncgvq0p03w0000gn/T/go-build134256866=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

As part of generating TLS channel bindings (RFC 5929) it is necessary to generate a hash of a given certificate using the hashing algorithm used in its SignatureAlgorithm, (with some exceptions documented in the RFC). So for example a SignatureAlgorithm of x509.SHA256WithRSA should use crypto.SHA256 to generate its tls-server-end-point channel binding type, etc.

What did you expect to see?

I was hoping to have a method on SignatureAlgorithm to return its associated crypto.Hash. This information is available in the unexported signatureAlgorithmDetails struct.

What did you see instead?

For now, I have made my own map[x509.SignatureAlgorithm]crypto.Hash but as new algorithms are added this needs to be kept in sync, (x509.PureEd25519 for example has been added to the source since 1.12.7).

I propose adding a simple method along the lines of:

func (algo SignatureAlgorithm) Hash() crypto.Hash {                                 
        for _, details := range signatureAlgorithmDetails {                         
                if details.algo == algo {                                           
                        return details.hash                                         
                }                                                                   
        }                                                                           
        return crypto.Hash(0)                                                       
}                                                                                   

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ProposalProposal-CryptoProposal related to crypto packages or other security issues

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions