Commit ee769922 authored by Filippo Valsorda's avatar Filippo Valsorda

crypto/tls,crypto/x509: normalize RFC references

Use the format "RFC XXXX, Section X.X" (or "Appendix Y.X") as it fits
more properly in prose than a link, is more future-proof, and as there
are multiple ways to render an RFC. Capital "S" to follow the quoting
standard of RFCs themselves.

Applied the new goimports grouping to all files in those packages, too.

Change-Id: I01267bb3a3b02664f8f822e97b129075bb14d404
Reviewed-on: https://go-review.googlesource.com/c/141918Reviewed-by: default avatarDmitri Shuralyov <dmitshur@golang.org>
parent 9c039ea2
...@@ -23,10 +23,9 @@ import ( ...@@ -23,10 +23,9 @@ import (
func pickSignatureAlgorithm(pubkey crypto.PublicKey, peerSigAlgs, ourSigAlgs []SignatureScheme, tlsVersion uint16) (sigAlg SignatureScheme, sigType uint8, hashFunc crypto.Hash, err error) { func pickSignatureAlgorithm(pubkey crypto.PublicKey, peerSigAlgs, ourSigAlgs []SignatureScheme, tlsVersion uint16) (sigAlg SignatureScheme, sigType uint8, hashFunc crypto.Hash, err error) {
if tlsVersion < VersionTLS12 || len(peerSigAlgs) == 0 { if tlsVersion < VersionTLS12 || len(peerSigAlgs) == 0 {
// For TLS 1.1 and before, the signature algorithm could not be // For TLS 1.1 and before, the signature algorithm could not be
// negotiated and the hash is fixed based on the signature type. // negotiated and the hash is fixed based on the signature type. For TLS
// For TLS 1.2, if the client didn't send signature_algorithms // 1.2, if the client didn't send signature_algorithms extension then we
// extension then we can assume that it supports SHA1. See // can assume that it supports SHA1. See RFC 5246, Section 7.4.1.4.1.
// https://tools.ietf.org/html/rfc5246#section-7.4.1.4.1
switch pubkey.(type) { switch pubkey.(type) {
case *rsa.PublicKey: case *rsa.PublicKey:
if tlsVersion < VersionTLS12 { if tlsVersion < VersionTLS12 {
......
...@@ -13,9 +13,8 @@ import ( ...@@ -13,9 +13,8 @@ import (
"crypto/sha1" "crypto/sha1"
"crypto/sha256" "crypto/sha256"
"crypto/x509" "crypto/x509"
"hash"
"golang_org/x/crypto/chacha20poly1305" "golang_org/x/crypto/chacha20poly1305"
"hash"
) )
// a keyAgreement implements the client and server side of a TLS key agreement // a keyAgreement implements the client and server side of a TLS key agreement
...@@ -303,7 +302,7 @@ func newConstantTimeHash(h func() hash.Hash) func() hash.Hash { ...@@ -303,7 +302,7 @@ func newConstantTimeHash(h func() hash.Hash) func() hash.Hash {
} }
} }
// tls10MAC implements the TLS 1.0 MAC function. RFC 2246, section 6.2.3. // tls10MAC implements the TLS 1.0 MAC function. RFC 2246, Section 6.2.3.
type tls10MAC struct { type tls10MAC struct {
h hash.Hash h hash.Hash
} }
...@@ -390,7 +389,6 @@ const ( ...@@ -390,7 +389,6 @@ const (
TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305 uint16 = 0xcca9 TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305 uint16 = 0xcca9
// TLS_FALLBACK_SCSV isn't a standard cipher suite but an indicator // TLS_FALLBACK_SCSV isn't a standard cipher suite but an indicator
// that the client is doing version fallback. See // that the client is doing version fallback. See RFC 7507.
// https://tools.ietf.org/html/rfc7507.
TLS_FALLBACK_SCSV uint16 = 0x5600 TLS_FALLBACK_SCSV uint16 = 0x5600
) )
...@@ -79,7 +79,7 @@ const ( ...@@ -79,7 +79,7 @@ const (
extensionSupportedPoints uint16 = 11 extensionSupportedPoints uint16 = 11
extensionSignatureAlgorithms uint16 = 13 extensionSignatureAlgorithms uint16 = 13
extensionALPN uint16 = 16 extensionALPN uint16 = 16
extensionSCT uint16 = 18 // https://tools.ietf.org/html/rfc6962#section-6 extensionSCT uint16 = 18 // RFC 6962, Section 6
extensionSessionTicket uint16 = 35 extensionSessionTicket uint16 = 35
extensionNextProtoNeg uint16 = 13172 // not IANA assigned extensionNextProtoNeg uint16 = 13172 // not IANA assigned
extensionRenegotiationInfo uint16 = 0xff01 extensionRenegotiationInfo uint16 = 0xff01
...@@ -128,7 +128,7 @@ const ( ...@@ -128,7 +128,7 @@ const (
) )
// Signature algorithms (for internal signaling use). Starting at 16 to avoid overlap with // Signature algorithms (for internal signaling use). Starting at 16 to avoid overlap with
// TLS 1.2 codepoints (RFC 5246, section A.4.1), with which these have nothing to do. // TLS 1.2 codepoints (RFC 5246, Appendix A.4.1), with which these have nothing to do.
const ( const (
signaturePKCS1v15 uint8 = iota + 16 signaturePKCS1v15 uint8 = iota + 16
signatureECDSA signatureECDSA
...@@ -177,9 +177,9 @@ type ConnectionState struct { ...@@ -177,9 +177,9 @@ type ConnectionState struct {
} }
// ExportKeyingMaterial returns length bytes of exported key material in a new // ExportKeyingMaterial returns length bytes of exported key material in a new
// slice as defined in https://tools.ietf.org/html/rfc5705. If context is nil, // slice as defined in RFC 5705. If context is nil, it is not used as part of
// it is not used as part of the seed. If the connection was set to allow // the seed. If the connection was set to allow renegotiation via
// renegotiation via Config.Renegotiation, this function will return an error. // Config.Renegotiation, this function will return an error.
func (cs *ConnectionState) ExportKeyingMaterial(label string, context []byte, length int) ([]byte, error) { func (cs *ConnectionState) ExportKeyingMaterial(label string, context []byte, length int) ([]byte, error) {
return cs.ekm(label, context, length) return cs.ekm(label, context, length)
} }
...@@ -222,7 +222,7 @@ type ClientSessionCache interface { ...@@ -222,7 +222,7 @@ type ClientSessionCache interface {
} }
// SignatureScheme identifies a signature algorithm supported by TLS. See // SignatureScheme identifies a signature algorithm supported by TLS. See
// https://tools.ietf.org/html/draft-ietf-tls-tls13-18#section-4.2.3. // RFC 8446, Section 4.2.3.
type SignatureScheme uint16 type SignatureScheme uint16
const ( const (
...@@ -252,32 +252,27 @@ type ClientHelloInfo struct { ...@@ -252,32 +252,27 @@ type ClientHelloInfo struct {
// ServerName indicates the name of the server requested by the client // ServerName indicates the name of the server requested by the client
// in order to support virtual hosting. ServerName is only set if the // in order to support virtual hosting. ServerName is only set if the
// client is using SNI (see // client is using SNI (see RFC 4366, Section 3.1).
// https://tools.ietf.org/html/rfc4366#section-3.1).
ServerName string ServerName string
// SupportedCurves lists the elliptic curves supported by the client. // SupportedCurves lists the elliptic curves supported by the client.
// SupportedCurves is set only if the Supported Elliptic Curves // SupportedCurves is set only if the Supported Elliptic Curves
// Extension is being used (see // Extension is being used (see RFC 4492, Section 5.1.1).
// https://tools.ietf.org/html/rfc4492#section-5.1.1).
SupportedCurves []CurveID SupportedCurves []CurveID
// SupportedPoints lists the point formats supported by the client. // SupportedPoints lists the point formats supported by the client.
// SupportedPoints is set only if the Supported Point Formats Extension // SupportedPoints is set only if the Supported Point Formats Extension
// is being used (see // is being used (see RFC 4492, Section 5.1.2).
// https://tools.ietf.org/html/rfc4492#section-5.1.2).
SupportedPoints []uint8 SupportedPoints []uint8
// SignatureSchemes lists the signature and hash schemes that the client // SignatureSchemes lists the signature and hash schemes that the client
// 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 RFC 5246, Section 7.4.1.4.1).
// https://tools.ietf.org/html/rfc5246#section-7.4.1.4.1).
SignatureSchemes []SignatureScheme 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
// Negotiation Extension is being used (see // Negotiation Extension is being used (see RFC 7301, Section 3.1).
// https://tools.ietf.org/html/rfc7301#section-3.1).
// //
// Servers can select a protocol by setting Config.NextProtos in a // Servers can select a protocol by setting Config.NextProtos in a
// GetConfigForClient return value. // GetConfigForClient return value.
......
...@@ -205,7 +205,7 @@ func (hc *halfConn) incSeq() { ...@@ -205,7 +205,7 @@ func (hc *halfConn) incSeq() {
// extractPadding returns, in constant time, the length of the padding to remove // extractPadding returns, in constant time, the length of the padding to remove
// from the end of payload. It also returns a byte which is equal to 255 if the // from the end of payload. It also returns a byte which is equal to 255 if the
// padding was valid and 0 otherwise. See RFC 2246, section 6.2.3.2 // padding was valid and 0 otherwise. See RFC 2246, Section 6.2.3.2.
func extractPadding(payload []byte) (toRemove int, good byte) { func extractPadding(payload []byte) (toRemove int, good byte) {
if len(payload) < 1 { if len(payload) < 1 {
return 0, 0 return 0, 0
......
...@@ -845,7 +845,7 @@ func mutualProtocol(protos, preferenceProtos []string) (string, bool) { ...@@ -845,7 +845,7 @@ func mutualProtocol(protos, preferenceProtos []string) (string, bool) {
// hostnameInSNI converts name into an approriate hostname for SNI. // hostnameInSNI converts name into an approriate hostname for SNI.
// Literal IP addresses and absolute FQDNs are not permitted as SNI values. // Literal IP addresses and absolute FQDNs are not permitted as SNI values.
// See https://tools.ietf.org/html/rfc6066#section-3. // See RFC 6066, Section 3.
func hostnameInSNI(name string) string { func hostnameInSNI(name string) string {
host := name host := name
if len(host) > 0 && host[0] == '[' && host[len(host)-1] == ']' { if len(host) > 0 && host[0] == '[' && host[len(host)-1] == ']' {
......
...@@ -155,7 +155,7 @@ func (m *clientHelloMsg) marshal() []byte { ...@@ -155,7 +155,7 @@ func (m *clientHelloMsg) marshal() []byte {
z[3] = byte(l) z[3] = byte(l)
z = z[4:] z = z[4:]
// RFC 3546, section 3.1 // RFC 3546, Section 3.1
// //
// struct { // struct {
// NameType name_type; // NameType name_type;
...@@ -182,7 +182,7 @@ func (m *clientHelloMsg) marshal() []byte { ...@@ -182,7 +182,7 @@ func (m *clientHelloMsg) marshal() []byte {
z = z[l:] z = z[l:]
} }
if m.ocspStapling { if m.ocspStapling {
// RFC 4366, section 3.6 // RFC 4366, Section 3.6
z[0] = byte(extensionStatusRequest >> 8) z[0] = byte(extensionStatusRequest >> 8)
z[1] = byte(extensionStatusRequest) z[1] = byte(extensionStatusRequest)
z[2] = 0 z[2] = 0
...@@ -192,7 +192,7 @@ func (m *clientHelloMsg) marshal() []byte { ...@@ -192,7 +192,7 @@ func (m *clientHelloMsg) marshal() []byte {
z = z[9:] z = z[9:]
} }
if len(m.supportedCurves) > 0 { if len(m.supportedCurves) > 0 {
// https://tools.ietf.org/html/rfc4492#section-5.5.1 // RFC 4492, Section 5.5.1
z[0] = byte(extensionSupportedCurves >> 8) z[0] = byte(extensionSupportedCurves >> 8)
z[1] = byte(extensionSupportedCurves) z[1] = byte(extensionSupportedCurves)
l := 2 + 2*len(m.supportedCurves) l := 2 + 2*len(m.supportedCurves)
...@@ -209,7 +209,7 @@ func (m *clientHelloMsg) marshal() []byte { ...@@ -209,7 +209,7 @@ func (m *clientHelloMsg) marshal() []byte {
} }
} }
if len(m.supportedPoints) > 0 { if len(m.supportedPoints) > 0 {
// https://tools.ietf.org/html/rfc4492#section-5.5.2 // RFC 4492, Section 5.5.2
z[0] = byte(extensionSupportedPoints >> 8) z[0] = byte(extensionSupportedPoints >> 8)
z[1] = byte(extensionSupportedPoints) z[1] = byte(extensionSupportedPoints)
l := 1 + len(m.supportedPoints) l := 1 + len(m.supportedPoints)
...@@ -224,7 +224,7 @@ func (m *clientHelloMsg) marshal() []byte { ...@@ -224,7 +224,7 @@ func (m *clientHelloMsg) marshal() []byte {
} }
} }
if m.ticketSupported { if m.ticketSupported {
// https://tools.ietf.org/html/rfc5077#section-3.2 // RFC 5077, Section 3.2
z[0] = byte(extensionSessionTicket >> 8) z[0] = byte(extensionSessionTicket >> 8)
z[1] = byte(extensionSessionTicket) z[1] = byte(extensionSessionTicket)
l := len(m.sessionTicket) l := len(m.sessionTicket)
...@@ -235,7 +235,7 @@ func (m *clientHelloMsg) marshal() []byte { ...@@ -235,7 +235,7 @@ func (m *clientHelloMsg) marshal() []byte {
z = z[len(m.sessionTicket):] z = z[len(m.sessionTicket):]
} }
if len(m.supportedSignatureAlgorithms) > 0 { if len(m.supportedSignatureAlgorithms) > 0 {
// https://tools.ietf.org/html/rfc5246#section-7.4.1.4.1 // RFC 5246, Section 7.4.1.4.1
z[0] = byte(extensionSignatureAlgorithms >> 8) z[0] = byte(extensionSignatureAlgorithms >> 8)
z[1] = byte(extensionSignatureAlgorithms) z[1] = byte(extensionSignatureAlgorithms)
l := 2 + 2*len(m.supportedSignatureAlgorithms) l := 2 + 2*len(m.supportedSignatureAlgorithms)
...@@ -285,7 +285,7 @@ func (m *clientHelloMsg) marshal() []byte { ...@@ -285,7 +285,7 @@ func (m *clientHelloMsg) marshal() []byte {
lengths[1] = byte(stringsLength) lengths[1] = byte(stringsLength)
} }
if m.scts { if m.scts {
// https://tools.ietf.org/html/rfc6962#section-3.3.1 // RFC 6962, Section 3.3.1
z[0] = byte(extensionSCT >> 8) z[0] = byte(extensionSCT >> 8)
z[1] = byte(extensionSCT) z[1] = byte(extensionSCT)
// zero uint16 for the zero-length extension_data // zero uint16 for the zero-length extension_data
...@@ -396,9 +396,8 @@ func (m *clientHelloMsg) unmarshal(data []byte) bool { ...@@ -396,9 +396,8 @@ func (m *clientHelloMsg) unmarshal(data []byte) bool {
} }
if nameType == 0 { if nameType == 0 {
m.serverName = string(d[:nameLen]) m.serverName = string(d[:nameLen])
// An SNI value may not include a // An SNI value may not include a trailing dot.
// trailing dot. See // See RFC 6066, Section 3.
// https://tools.ietf.org/html/rfc6066#section-3.
if strings.HasSuffix(m.serverName, ".") { if strings.HasSuffix(m.serverName, ".") {
return false return false
} }
...@@ -414,7 +413,7 @@ func (m *clientHelloMsg) unmarshal(data []byte) bool { ...@@ -414,7 +413,7 @@ func (m *clientHelloMsg) unmarshal(data []byte) bool {
case extensionStatusRequest: case extensionStatusRequest:
m.ocspStapling = length > 0 && data[0] == statusTypeOCSP m.ocspStapling = length > 0 && data[0] == statusTypeOCSP
case extensionSupportedCurves: case extensionSupportedCurves:
// https://tools.ietf.org/html/rfc4492#section-5.5.1 // RFC 4492, Section 5.5.1
if length < 2 { if length < 2 {
return false return false
} }
...@@ -430,7 +429,7 @@ func (m *clientHelloMsg) unmarshal(data []byte) bool { ...@@ -430,7 +429,7 @@ func (m *clientHelloMsg) unmarshal(data []byte) bool {
d = d[2:] d = d[2:]
} }
case extensionSupportedPoints: case extensionSupportedPoints:
// https://tools.ietf.org/html/rfc4492#section-5.5.2 // RFC 4492, Section 5.5.2
if length < 1 { if length < 1 {
return false return false
} }
...@@ -441,11 +440,11 @@ func (m *clientHelloMsg) unmarshal(data []byte) bool { ...@@ -441,11 +440,11 @@ func (m *clientHelloMsg) unmarshal(data []byte) bool {
m.supportedPoints = make([]uint8, l) m.supportedPoints = make([]uint8, l)
copy(m.supportedPoints, data[1:]) copy(m.supportedPoints, data[1:])
case extensionSessionTicket: case extensionSessionTicket:
// https://tools.ietf.org/html/rfc5077#section-3.2 // RFC 5077, Section 3.2
m.ticketSupported = true m.ticketSupported = true
m.sessionTicket = data[:length] m.sessionTicket = data[:length]
case extensionSignatureAlgorithms: case extensionSignatureAlgorithms:
// https://tools.ietf.org/html/rfc5246#section-7.4.1.4.1 // RFC 5246, Section 7.4.1.4.1
if length < 2 || length&1 != 0 { if length < 2 || length&1 != 0 {
return false return false
} }
...@@ -1224,7 +1223,7 @@ func (m *certificateRequestMsg) marshal() (x []byte) { ...@@ -1224,7 +1223,7 @@ func (m *certificateRequestMsg) marshal() (x []byte) {
return m.raw return m.raw
} }
// See https://tools.ietf.org/html/rfc4346#section-7.4.4 // See RFC 4346, Section 7.4.4.
length := 1 + len(m.certificateTypes) + 2 length := 1 + len(m.certificateTypes) + 2
casLength := 0 casLength := 0
for _, ca := range m.certificateAuthorities { for _, ca := range m.certificateAuthorities {
...@@ -1374,7 +1373,7 @@ func (m *certificateVerifyMsg) marshal() (x []byte) { ...@@ -1374,7 +1373,7 @@ func (m *certificateVerifyMsg) marshal() (x []byte) {
return m.raw return m.raw
} }
// See https://tools.ietf.org/html/rfc4346#section-7.4.8 // See RFC 4346, Section 7.4.8.
siglength := len(m.signature) siglength := len(m.signature)
length := 2 + siglength length := 2 + siglength
if m.hasSignatureAndHash { if m.hasSignatureAndHash {
...@@ -1452,7 +1451,7 @@ func (m *newSessionTicketMsg) marshal() (x []byte) { ...@@ -1452,7 +1451,7 @@ func (m *newSessionTicketMsg) marshal() (x []byte) {
return m.raw return m.raw
} }
// See https://tools.ietf.org/html/rfc5077#section-3.3 // See RFC 5077, Section 3.3.
ticketLen := len(m.ticket) ticketLen := len(m.ticket)
length := 2 + 4 + ticketLen length := 2 + 4 + ticketLen
x = make([]byte, 4+length) x = make([]byte, 4+length)
......
...@@ -271,8 +271,7 @@ func (*sessionState) Generate(rand *rand.Rand, size int) reflect.Value { ...@@ -271,8 +271,7 @@ func (*sessionState) Generate(rand *rand.Rand, size int) reflect.Value {
} }
func TestRejectEmptySCTList(t *testing.T) { func TestRejectEmptySCTList(t *testing.T) {
// https://tools.ietf.org/html/rfc6962#section-3.3.1 specifies that // RFC 6962, Section 3.3.1 specifies that empty SCT lists are invalid.
// empty SCT lists are invalid.
var random [32]byte var random [32]byte
sct := []byte{0x42, 0x42, 0x42, 0x42} sct := []byte{0x42, 0x42, 0x42, 0x42}
......
...@@ -49,7 +49,7 @@ func (c *Conn) serverHandshake() error { ...@@ -49,7 +49,7 @@ func (c *Conn) serverHandshake() error {
return err return err
} }
// For an overview of TLS handshaking, see https://tools.ietf.org/html/rfc5246#section-7.3 // For an overview of TLS handshaking, see RFC 5246, Section 7.3.
c.buffering = true c.buffering = true
if isResume { if isResume {
// The client has included a session ticket and so we do an abbreviated handshake. // The client has included a session ticket and so we do an abbreviated handshake.
...@@ -268,7 +268,7 @@ Curves: ...@@ -268,7 +268,7 @@ Curves:
return false, errors.New("tls: no cipher suite supported by both client and server") return false, errors.New("tls: no cipher suite supported by both client and server")
} }
// See https://tools.ietf.org/html/rfc7507. // See RFC 7507.
for _, id := range hs.clientHello.cipherSuites { for _, id := range hs.clientHello.cipherSuites {
if id == TLS_FALLBACK_SCSV { if id == TLS_FALLBACK_SCSV {
// The client is doing a fallback connection. // The client is doing a fallback connection.
......
...@@ -12,10 +12,9 @@ import ( ...@@ -12,10 +12,9 @@ import (
"crypto/sha1" "crypto/sha1"
"crypto/x509" "crypto/x509"
"errors" "errors"
"golang_org/x/crypto/curve25519"
"io" "io"
"math/big" "math/big"
"golang_org/x/crypto/curve25519"
) )
var errClientKeyExchange = errors.New("tls: invalid ClientKeyExchange message") var errClientKeyExchange = errors.New("tls: invalid ClientKeyExchange message")
...@@ -200,7 +199,7 @@ NextCandidate: ...@@ -200,7 +199,7 @@ NextCandidate:
ecdhePublic = elliptic.Marshal(curve, x, y) ecdhePublic = elliptic.Marshal(curve, x, y)
} }
// https://tools.ietf.org/html/rfc4492#section-5.4 // See RFC 4492, Section 5.4.
serverECDHParams := make([]byte, 1+2+1+len(ecdhePublic)) serverECDHParams := make([]byte, 1+2+1+len(ecdhePublic))
serverECDHParams[0] = 3 // named curve serverECDHParams[0] = 3 // named curve
serverECDHParams[1] = byte(ka.curveid >> 8) serverECDHParams[1] = byte(ka.curveid >> 8)
......
...@@ -16,14 +16,14 @@ import ( ...@@ -16,14 +16,14 @@ import (
"hash" "hash"
) )
// Split a premaster secret in two as specified in RFC 4346, section 5. // Split a premaster secret in two as specified in RFC 4346, Section 5.
func splitPreMasterSecret(secret []byte) (s1, s2 []byte) { func splitPreMasterSecret(secret []byte) (s1, s2 []byte) {
s1 = secret[0 : (len(secret)+1)/2] s1 = secret[0 : (len(secret)+1)/2]
s2 = secret[len(secret)/2:] s2 = secret[len(secret)/2:]
return return
} }
// pHash implements the P_hash function, as defined in RFC 4346, section 5. // pHash implements the P_hash function, as defined in RFC 4346, Section 5.
func pHash(result, secret, seed []byte, hash func() hash.Hash) { func pHash(result, secret, seed []byte, hash func() hash.Hash) {
h := hmac.New(hash, secret) h := hmac.New(hash, secret)
h.Write(seed) h.Write(seed)
...@@ -44,7 +44,7 @@ func pHash(result, secret, seed []byte, hash func() hash.Hash) { ...@@ -44,7 +44,7 @@ func pHash(result, secret, seed []byte, hash func() hash.Hash) {
} }
} }
// prf10 implements the TLS 1.0 pseudo-random function, as defined in RFC 2246, section 5. // prf10 implements the TLS 1.0 pseudo-random function, as defined in RFC 2246, Section 5.
func prf10(result, secret, label, seed []byte) { func prf10(result, secret, label, seed []byte) {
hashSHA1 := sha1.New hashSHA1 := sha1.New
hashMD5 := md5.New hashMD5 := md5.New
...@@ -63,7 +63,7 @@ func prf10(result, secret, label, seed []byte) { ...@@ -63,7 +63,7 @@ func prf10(result, secret, label, seed []byte) {
} }
} }
// prf12 implements the TLS 1.2 pseudo-random function, as defined in RFC 5246, section 5. // prf12 implements the TLS 1.2 pseudo-random function, as defined in RFC 5246, Section 5.
func prf12(hashFunc func() hash.Hash) func(result, secret, label, seed []byte) { func prf12(hashFunc func() hash.Hash) func(result, secret, label, seed []byte) {
return func(result, secret, label, seed []byte) { return func(result, secret, label, seed []byte) {
labelAndSeed := make([]byte, len(label)+len(seed)) labelAndSeed := make([]byte, len(label)+len(seed))
...@@ -140,7 +140,7 @@ func prfForVersion(version uint16, suite *cipherSuite) func(result, secret, labe ...@@ -140,7 +140,7 @@ func prfForVersion(version uint16, suite *cipherSuite) func(result, secret, labe
} }
// masterFromPreMasterSecret generates the master secret from the pre-master // masterFromPreMasterSecret generates the master secret from the pre-master
// secret. See https://tools.ietf.org/html/rfc5246#section-8.1 // secret. See RFC 5246, Section 8.1.
func masterFromPreMasterSecret(version uint16, suite *cipherSuite, preMasterSecret, clientRandom, serverRandom []byte) []byte { func masterFromPreMasterSecret(version uint16, suite *cipherSuite, preMasterSecret, clientRandom, serverRandom []byte) []byte {
seed := make([]byte, 0, len(clientRandom)+len(serverRandom)) seed := make([]byte, 0, len(clientRandom)+len(serverRandom))
seed = append(seed, clientRandom...) seed = append(seed, clientRandom...)
...@@ -153,7 +153,7 @@ func masterFromPreMasterSecret(version uint16, suite *cipherSuite, preMasterSecr ...@@ -153,7 +153,7 @@ func masterFromPreMasterSecret(version uint16, suite *cipherSuite, preMasterSecr
// keysFromMasterSecret generates the connection keys from the master // keysFromMasterSecret generates the connection keys from the master
// secret, given the lengths of the MAC key, cipher key and IV, as defined in // secret, given the lengths of the MAC key, cipher key and IV, as defined in
// RFC 2246, section 6.3. // RFC 2246, Section 6.3.
func keysFromMasterSecret(version uint16, suite *cipherSuite, masterSecret, clientRandom, serverRandom []byte, macLen, keyLen, ivLen int) (clientMAC, serverMAC, clientKey, serverKey, clientIV, serverIV []byte) { func keysFromMasterSecret(version uint16, suite *cipherSuite, masterSecret, clientRandom, serverRandom []byte, macLen, keyLen, ivLen int) (clientMAC, serverMAC, clientKey, serverKey, clientIV, serverIV []byte) {
seed := make([]byte, 0, len(serverRandom)+len(clientRandom)) seed := make([]byte, 0, len(serverRandom)+len(clientRandom))
seed = append(seed, serverRandom...) seed = append(seed, serverRandom...)
...@@ -353,8 +353,7 @@ func noExportedKeyingMaterial(label string, context []byte, length int) ([]byte, ...@@ -353,8 +353,7 @@ func noExportedKeyingMaterial(label string, context []byte, length int) ([]byte,
return nil, errors.New("crypto/tls: ExportKeyingMaterial is unavailable when renegotiation is enabled") return nil, errors.New("crypto/tls: ExportKeyingMaterial is unavailable when renegotiation is enabled")
} }
// ekmFromMasterSecret generates exported keying material as defined in // ekmFromMasterSecret generates exported keying material as defined in RFC 5705.
// https://tools.ietf.org/html/rfc5705.
func ekmFromMasterSecret(version uint16, suite *cipherSuite, masterSecret, clientRandom, serverRandom []byte) func(string, []byte, int) ([]byte, error) { func ekmFromMasterSecret(version uint16, suite *cipherSuite, masterSecret, clientRandom, serverRandom []byte) func(string, []byte, int) ([]byte, error) {
return func(label string, context []byte, length int) ([]byte, error) { return func(label string, context []byte, length int) ([]byte, error) {
switch label { switch label {
......
...@@ -203,7 +203,7 @@ func EncryptPEMBlock(rand io.Reader, blockType string, data, password []byte, al ...@@ -203,7 +203,7 @@ func EncryptPEMBlock(rand io.Reader, blockType string, data, password []byte, al
// the data separately, but it doesn't seem worth the additional // the data separately, but it doesn't seem worth the additional
// code. // code.
copy(encrypted, data) copy(encrypted, data)
// See RFC 1423, section 1.1 // See RFC 1423, Section 1.1.
for i := 0; i < pad; i++ { for i := 0; i < pad; i++ {
encrypted = append(encrypted, byte(pad)) encrypted = append(encrypted, byte(pad))
} }
......
...@@ -95,7 +95,7 @@ func (r RDNSequence) String() string { ...@@ -95,7 +95,7 @@ func (r RDNSequence) String() string {
type RelativeDistinguishedNameSET []AttributeTypeAndValue type RelativeDistinguishedNameSET []AttributeTypeAndValue
// AttributeTypeAndValue mirrors the ASN.1 structure of the same name in // AttributeTypeAndValue mirrors the ASN.1 structure of the same name in
// https://tools.ietf.org/html/rfc5280#section-4.1.2.4 // RFC 5280, Section 4.1.2.4.
type AttributeTypeAndValue struct { type AttributeTypeAndValue struct {
Type asn1.ObjectIdentifier Type asn1.ObjectIdentifier
Value interface{} Value interface{}
......
...@@ -222,10 +222,9 @@ type rfc2821Mailbox struct { ...@@ -222,10 +222,9 @@ type rfc2821Mailbox struct {
} }
// parseRFC2821Mailbox parses an email address into local and domain parts, // parseRFC2821Mailbox parses an email address into local and domain parts,
// based on the ABNF for a “Mailbox” from RFC 2821. According to // based on the ABNF for a “Mailbox” from RFC 2821. According to RFC 5280,
// https://tools.ietf.org/html/rfc5280#section-4.2.1.6 that's correct for an // Section 4.2.1.6 that's correct for an rfc822Name from a certificate: “The
// rfc822Name from a certificate: “The format of an rfc822Name is a "Mailbox" // format of an rfc822Name is a "Mailbox" as defined in RFC 2821, Section 4.1.2”.
// as defined in https://tools.ietf.org/html/rfc2821#section-4.1.2”.
func parseRFC2821Mailbox(in string) (mailbox rfc2821Mailbox, ok bool) { func parseRFC2821Mailbox(in string) (mailbox rfc2821Mailbox, ok bool) {
if len(in) == 0 { if len(in) == 0 {
return mailbox, false return mailbox, false
...@@ -242,9 +241,8 @@ func parseRFC2821Mailbox(in string) (mailbox rfc2821Mailbox, ok bool) { ...@@ -242,9 +241,8 @@ func parseRFC2821Mailbox(in string) (mailbox rfc2821Mailbox, ok bool) {
// quoted-pair = ("\" text) / obs-qp // quoted-pair = ("\" text) / obs-qp
// text = %d1-9 / %d11 / %d12 / %d14-127 / obs-text // text = %d1-9 / %d11 / %d12 / %d14-127 / obs-text
// //
// (Names beginning with “obs-” are the obsolete syntax from // (Names beginning with “obs-” are the obsolete syntax from RFC 2822,
// https://tools.ietf.org/html/rfc2822#section-4. Since it has // Section 4. Since it has been 16 years, we no longer accept that.)
// been 16 years, we no longer accept that.)
in = in[1:] in = in[1:]
QuotedString: QuotedString:
for { for {
...@@ -298,7 +296,7 @@ func parseRFC2821Mailbox(in string) (mailbox rfc2821Mailbox, ok bool) { ...@@ -298,7 +296,7 @@ func parseRFC2821Mailbox(in string) (mailbox rfc2821Mailbox, ok bool) {
// Atom ("." Atom)* // Atom ("." Atom)*
NextChar: NextChar:
for len(in) > 0 { for len(in) > 0 {
// atext from https://tools.ietf.org/html/rfc2822#section-3.2.4 // atext from RFC 2822, Section 3.2.4
c := in[0] c := in[0]
switch { switch {
...@@ -334,7 +332,7 @@ func parseRFC2821Mailbox(in string) (mailbox rfc2821Mailbox, ok bool) { ...@@ -334,7 +332,7 @@ func parseRFC2821Mailbox(in string) (mailbox rfc2821Mailbox, ok bool) {
return mailbox, false return mailbox, false
} }
// https://tools.ietf.org/html/rfc3696#section-3 // From RFC 3696, Section 3:
// “period (".") may also appear, but may not be used to start // “period (".") may also appear, but may not be used to start
// or end the local part, nor may two or more consecutive // or end the local part, nor may two or more consecutive
// periods appear.” // periods appear.”
...@@ -415,7 +413,7 @@ func matchEmailConstraint(mailbox rfc2821Mailbox, constraint string) (bool, erro ...@@ -415,7 +413,7 @@ func matchEmailConstraint(mailbox rfc2821Mailbox, constraint string) (bool, erro
} }
func matchURIConstraint(uri *url.URL, constraint string) (bool, error) { func matchURIConstraint(uri *url.URL, constraint string) (bool, error) {
// https://tools.ietf.org/html/rfc5280#section-4.2.1.10 // From RFC 5280, Section 4.2.1.10:
// “a uniformResourceIdentifier that does not include an authority // “a uniformResourceIdentifier that does not include an authority
// component with a host name specified as a fully qualified domain // component with a host name specified as a fully qualified domain
// name (e.g., if the URI either does not include an authority // name (e.g., if the URI either does not include an authority
...@@ -987,7 +985,7 @@ func (c *Certificate) VerifyHostname(h string) error { ...@@ -987,7 +985,7 @@ func (c *Certificate) VerifyHostname(h string) error {
} }
if ip := net.ParseIP(candidateIP); ip != nil { if ip := net.ParseIP(candidateIP); ip != nil {
// We only match IP addresses against IP SANs. // We only match IP addresses against IP SANs.
// https://tools.ietf.org/html/rfc6125#appendix-B.2 // See RFC 6125, Appendix B.2.
for _, candidate := range c.IPAddresses { for _, candidate := range c.IPAddresses {
if ip.Equal(candidate) { if ip.Equal(candidate) {
return nil return nil
......
...@@ -24,6 +24,8 @@ import ( ...@@ -24,6 +24,8 @@ import (
"encoding/pem" "encoding/pem"
"errors" "errors"
"fmt" "fmt"
"golang_org/x/crypto/cryptobyte"
cryptobyte_asn1 "golang_org/x/crypto/cryptobyte/asn1"
"io" "io"
"math/big" "math/big"
"net" "net"
...@@ -32,9 +34,6 @@ import ( ...@@ -32,9 +34,6 @@ import (
"strings" "strings"
"time" "time"
"unicode/utf8" "unicode/utf8"
"golang_org/x/crypto/cryptobyte"
cryptobyte_asn1 "golang_org/x/crypto/cryptobyte/asn1"
) )
// pkixPublicKey reflects a PKIX public key structure. See SubjectPublicKeyInfo // pkixPublicKey reflects a PKIX public key structure. See SubjectPublicKeyInfo
...@@ -78,7 +77,7 @@ func marshalPublicKey(pub interface{}) (publicKeyBytes []byte, publicKeyAlgorith ...@@ -78,7 +77,7 @@ func marshalPublicKey(pub interface{}) (publicKeyBytes []byte, publicKeyAlgorith
} }
publicKeyAlgorithm.Algorithm = oidPublicKeyRSA publicKeyAlgorithm.Algorithm = oidPublicKeyRSA
// This is a NULL parameters value which is required by // This is a NULL parameters value which is required by
// https://tools.ietf.org/html/rfc3279#section-2.3.1. // RFC 3279, Section 2.3.1.
publicKeyAlgorithm.Parameters = asn1.NullRawValue publicKeyAlgorithm.Parameters = asn1.NullRawValue
case *ecdsa.PublicKey: case *ecdsa.PublicKey:
publicKeyBytes = elliptic.Marshal(pub.Curve, pub.X, pub.Y) publicKeyBytes = elliptic.Marshal(pub.Curve, pub.X, pub.Y)
...@@ -334,7 +333,7 @@ var signatureAlgorithmDetails = []struct { ...@@ -334,7 +333,7 @@ var signatureAlgorithmDetails = []struct {
} }
// pssParameters reflects the parameters in an AlgorithmIdentifier that // pssParameters reflects the parameters in an AlgorithmIdentifier that
// specifies RSA PSS. See https://tools.ietf.org/html/rfc3447#appendix-A.2.3 // specifies RSA PSS. See RFC 3447, Appendix A.2.3.
type pssParameters struct { type pssParameters struct {
// The following three fields are not marked as // The following three fields are not marked as
// optional because the default values specify SHA-1, // optional because the default values specify SHA-1,
...@@ -413,13 +412,11 @@ func getSignatureAlgorithmFromAI(ai pkix.AlgorithmIdentifier) SignatureAlgorithm ...@@ -413,13 +412,11 @@ func getSignatureAlgorithmFromAI(ai pkix.AlgorithmIdentifier) SignatureAlgorithm
return UnknownSignatureAlgorithm return UnknownSignatureAlgorithm
} }
// PSS is greatly overburdened with options. This code forces // PSS is greatly overburdened with options. This code forces them into
// them into three buckets by requiring that the MGF1 hash // three buckets by requiring that the MGF1 hash function always match the
// function always match the message hash function (as // message hash function (as recommended in RFC 3447, Section 8.1), that the
// recommended in // salt length matches the hash length, and that the trailer field has the
// https://tools.ietf.org/html/rfc3447#section-8.1), that the // default value.
// salt length matches the hash length, and that the trailer
// field has the default value.
if (len(params.Hash.Parameters.FullBytes) != 0 && !bytes.Equal(params.Hash.Parameters.FullBytes, asn1.NullBytes)) || if (len(params.Hash.Parameters.FullBytes) != 0 && !bytes.Equal(params.Hash.Parameters.FullBytes, asn1.NullBytes)) ||
!params.MGF.Algorithm.Equal(oidMGF1) || !params.MGF.Algorithm.Equal(oidMGF1) ||
!mgf1HashFunc.Algorithm.Equal(params.Hash.Algorithm) || !mgf1HashFunc.Algorithm.Equal(params.Hash.Algorithm) ||
...@@ -987,8 +984,8 @@ func parsePublicKey(algo PublicKeyAlgorithm, keyData *publicKeyInfo) (interface{ ...@@ -987,8 +984,8 @@ func parsePublicKey(algo PublicKeyAlgorithm, keyData *publicKeyInfo) (interface{
asn1Data := keyData.PublicKey.RightAlign() asn1Data := keyData.PublicKey.RightAlign()
switch algo { switch algo {
case RSA: case RSA:
// RSA public keys must have a NULL in the parameters // RSA public keys must have a NULL in the parameters.
// (https://tools.ietf.org/html/rfc3279#section-2.3.1). // See RFC 3279, Section 2.3.1.
if !bytes.Equal(keyData.Algorithm.Parameters.FullBytes, asn1.NullBytes) { if !bytes.Equal(keyData.Algorithm.Parameters.FullBytes, asn1.NullBytes) {
return nil, errors.New("x509: RSA key missing NULL parameters") return nil, errors.New("x509: RSA key missing NULL parameters")
} }
...@@ -1203,7 +1200,7 @@ func parseNameConstraintsExtension(out *Certificate, e pkix.Extension) (unhandle ...@@ -1203,7 +1200,7 @@ func parseNameConstraintsExtension(out *Certificate, e pkix.Extension) (unhandle
} }
if !havePermitted && !haveExcluded || len(permitted) == 0 && len(excluded) == 0 { if !havePermitted && !haveExcluded || len(permitted) == 0 && len(excluded) == 0 {
// https://tools.ietf.org/html/rfc5280#section-4.2.1.10: // From RFC 5280, Section 4.2.1.10:
// “either the permittedSubtrees field // “either the permittedSubtrees field
// or the excludedSubtrees MUST be // or the excludedSubtrees MUST be
// present” // present”
...@@ -1798,7 +1795,7 @@ func buildExtensions(template *Certificate, subjectIsEmpty bool, authorityKeyId ...@@ -1798,7 +1795,7 @@ func buildExtensions(template *Certificate, subjectIsEmpty bool, authorityKeyId
if (len(template.DNSNames) > 0 || len(template.EmailAddresses) > 0 || len(template.IPAddresses) > 0 || len(template.URIs) > 0) && if (len(template.DNSNames) > 0 || len(template.EmailAddresses) > 0 || len(template.IPAddresses) > 0 || len(template.URIs) > 0) &&
!oidInExtensions(oidExtensionSubjectAltName, template.ExtraExtensions) { !oidInExtensions(oidExtensionSubjectAltName, template.ExtraExtensions) {
ret[n].Id = oidExtensionSubjectAltName ret[n].Id = oidExtensionSubjectAltName
// https://tools.ietf.org/html/rfc5280#section-4.2.1.6 // From RFC 5280, Section 4.2.1.6:
// “If the subject field contains an empty sequence ... then // “If the subject field contains an empty sequence ... then
// subjectAltName extension ... is marked as critical” // subjectAltName extension ... is marked as critical”
ret[n].Critical = subjectIsEmpty ret[n].Critical = subjectIsEmpty
...@@ -2357,8 +2354,7 @@ func parseRawAttributes(rawAttributes []asn1.RawValue) []pkix.AttributeTypeAndVa ...@@ -2357,8 +2354,7 @@ func parseRawAttributes(rawAttributes []asn1.RawValue) []pkix.AttributeTypeAndVa
// parseCSRExtensions parses the attributes from a CSR and extracts any // parseCSRExtensions parses the attributes from a CSR and extracts any
// requested extensions. // requested extensions.
func parseCSRExtensions(rawAttributes []asn1.RawValue) ([]pkix.Extension, error) { func parseCSRExtensions(rawAttributes []asn1.RawValue) ([]pkix.Extension, error) {
// pkcs10Attribute reflects the Attribute structure from section 4.1 of // pkcs10Attribute reflects the Attribute structure from RFC 2986, Section 4.1.
// https://tools.ietf.org/html/rfc2986.
type pkcs10Attribute struct { type pkcs10Attribute struct {
Id asn1.ObjectIdentifier Id asn1.ObjectIdentifier
Values []asn1.RawValue `asn1:"set"` Values []asn1.RawValue `asn1:"set"`
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment