crypto/tls: add a SignatureScheme type.

The SignatureAndHashAlgorithm from TLS 1.2[1] is being changed to
SignatureScheme in TLS 1.3[2]. (The actual values are compatible
however.)

Since we expect to support TLS 1.3 in the future, we're already using
the name and style of SignatureScheme in the recently augmented
ClientHelloInfo. As this is public API, it seems that SignatureScheme
should have its own type and exported values, which is implemented in
this change.

[1] https://tools.ietf.org/html/rfc5246#section-7.4.1.4.1
[2] https://tools.ietf.org/html/draft-ietf-tls-tls13-18#section-4.2.3

Change-Id: I0482755d02bb9a04eaf075c012696103eb806645
Reviewed-on: https://go-review.googlesource.com/32119
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Adam Langley <agl@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Adam Langley 2016-10-26 12:30:30 -07:00
parent 54967fbddc
commit ce1c25b814
2 changed files with 22 additions and 3 deletions

View File

@ -215,6 +215,25 @@ type ClientSessionCache interface {
Put(sessionKey string, cs *ClientSessionState) Put(sessionKey string, cs *ClientSessionState)
} }
// SignatureScheme identifies a signature algorithm supported by TLS. See
// https://tools.ietf.org/html/draft-ietf-tls-tls13-18#section-4.2.3.
type SignatureScheme uint16
const (
PKCS1WithSHA1 SignatureScheme = 0x0201
PKCS1WithSHA256 SignatureScheme = 0x0401
PKCS1WithSHA384 SignatureScheme = 0x0501
PKCS1WithSHA512 SignatureScheme = 0x0601
PSSWithSHA256 SignatureScheme = 0x0804
PSSWithSHA384 SignatureScheme = 0x0805
PSSWithSHA512 SignatureScheme = 0x0806
ECDSAWithP256AndSHA256 SignatureScheme = 0x0403
ECDSAWithP384AndSHA384 SignatureScheme = 0x0503
ECDSAWithP521AndSHA512 SignatureScheme = 0x0603
)
// ClientHelloInfo contains information from a ClientHello message in order to // ClientHelloInfo contains information from a ClientHello message in order to
// guide certificate selection in the GetCertificate callback. // guide certificate selection in the GetCertificate callback.
type ClientHelloInfo struct { type ClientHelloInfo struct {
@ -244,7 +263,7 @@ type ClientHelloInfo struct {
// is willing to verify. SignatureSchemes is set only if the Signature // is willing to verify. SignatureSchemes is set only if the Signature
// Algorithms Extension is being used (see // Algorithms Extension is being used (see
// https://tools.ietf.org/html/rfc5246#section-7.4.1.4.1). // https://tools.ietf.org/html/rfc5246#section-7.4.1.4.1).
SignatureSchemes []uint16 SignatureSchemes []SignatureScheme
// SupportedProtos lists the application protocols supported by the client. // SupportedProtos lists the application protocols supported by the client.
// SupportedProtos is set only if the Application-Layer Protocol // SupportedProtos is set only if the Application-Layer Protocol

View File

@ -822,9 +822,9 @@ func (hs *serverHandshakeState) clientHelloInfo() *ClientHelloInfo {
supportedVersions = suppVersArray[VersionTLS12-hs.clientHello.vers:] supportedVersions = suppVersArray[VersionTLS12-hs.clientHello.vers:]
} }
signatureSchemes := make([]uint16, 0, len(hs.clientHello.signatureAndHashes)) signatureSchemes := make([]SignatureScheme, 0, len(hs.clientHello.signatureAndHashes))
for _, sah := range hs.clientHello.signatureAndHashes { for _, sah := range hs.clientHello.signatureAndHashes {
signatureSchemes = append(signatureSchemes, uint16(sah.hash)<<8+uint16(sah.signature)) signatureSchemes = append(signatureSchemes, SignatureScheme(sah.hash)<<8+SignatureScheme(sah.signature))
} }
hs.cachedClientHelloInfo = &ClientHelloInfo{ hs.cachedClientHelloInfo = &ClientHelloInfo{