diff options
author | Andrew Gerrand <adg@golang.org> | 2013-11-01 11:09:06 +1100 |
---|---|---|
committer | Andrew Gerrand <adg@golang.org> | 2013-11-01 11:09:06 +1100 |
commit | f041f97c7dd09f59873c4bdbfe3ea9007042ced6 (patch) | |
tree | 903171ea4727d91f64c75cd41b8c6721358a6548 | |
parent | 5ea8e90a087e2aa4b48be6e477d3b710a5c4776b (diff) | |
download | go-f041f97c7dd09f59873c4bdbfe3ea9007042ced6.tar.gz |
[release-branch.go1.2] crypto/tls: advertise support for RSA+SHA1 in TLS 1.2 handshake.
??? CL 15650043 / 29d3ab5ced5a
crypto/tls: advertise support for RSA+SHA1 in TLS 1.2 handshake.
Despite SHA256 support being required for TLS 1.2 handshakes, some
servers are aborting handshakes that don't offer SHA1 support.
This change adds support for signing TLS 1.2 ServerKeyExchange messages
with SHA1. It does not add support for signing TLS 1.2 client
certificates with SHA1 as that would require the handshake to be
buffered.
Fixes issue 6618.
R=golang-dev, r
CC=golang-dev
https://codereview.appspot.com/15650043
???
R=golang-dev
CC=golang-dev
https://codereview.appspot.com/20570043
-rw-r--r-- | src/pkg/crypto/tls/common.go | 15 | ||||
-rw-r--r-- | src/pkg/crypto/tls/handshake_client.go | 2 | ||||
-rw-r--r-- | src/pkg/crypto/tls/handshake_client_test.go | 282 | ||||
-rw-r--r-- | src/pkg/crypto/tls/handshake_messages_test.go | 2 | ||||
-rw-r--r-- | src/pkg/crypto/tls/handshake_server.go | 2 | ||||
-rw-r--r-- | src/pkg/crypto/tls/key_agreement.go | 72 |
6 files changed, 218 insertions, 157 deletions
diff --git a/src/pkg/crypto/tls/common.go b/src/pkg/crypto/tls/common.go index d2e8fab09..b7229d29f 100644 --- a/src/pkg/crypto/tls/common.go +++ b/src/pkg/crypto/tls/common.go @@ -126,10 +126,19 @@ type signatureAndHash struct { hash, signature uint8 } -// supportedSignatureAlgorithms contains the signature and hash algorithms that -// the code can advertise as supported both in a TLS 1.2 ClientHello and +// supportedSKXSignatureAlgorithms contains the signature and hash algorithms +// that the code advertises as supported in a TLS 1.2 ClientHello. +var supportedSKXSignatureAlgorithms = []signatureAndHash{ + {hashSHA256, signatureRSA}, + {hashSHA256, signatureECDSA}, + {hashSHA1, signatureRSA}, + {hashSHA1, signatureECDSA}, +} + +// supportedClientCertSignatureAlgorithms contains the signature and hash +// algorithms that the code advertises as supported in a TLS 1.2 // CertificateRequest. -var supportedSignatureAlgorithms = []signatureAndHash{ +var supportedClientCertSignatureAlgorithms = []signatureAndHash{ {hashSHA256, signatureRSA}, {hashSHA256, signatureECDSA}, } diff --git a/src/pkg/crypto/tls/handshake_client.go b/src/pkg/crypto/tls/handshake_client.go index 9cd57c55f..85e4adefc 100644 --- a/src/pkg/crypto/tls/handshake_client.go +++ b/src/pkg/crypto/tls/handshake_client.go @@ -63,7 +63,7 @@ NextCipherSuite: } if hello.vers >= VersionTLS12 { - hello.signatureAndHashes = supportedSignatureAlgorithms + hello.signatureAndHashes = supportedSKXSignatureAlgorithms } c.writeRecord(recordTypeHandshake, hello.marshal()) diff --git a/src/pkg/crypto/tls/handshake_client_test.go b/src/pkg/crypto/tls/handshake_client_test.go index daaa09329..6c564001b 100644 --- a/src/pkg/crypto/tls/handshake_client_test.go +++ b/src/pkg/crypto/tls/handshake_client_test.go @@ -1834,30 +1834,30 @@ var clientChainCertificateScript = [][]byte{ // -minversion=0x0303 -maxversion=0x0303 var clientTLS12Script = [][]byte{ { - 0x16, 0x03, 0x01, 0x00, 0x54, 0x01, 0x00, 0x00, - 0x50, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x16, 0x03, 0x01, 0x00, 0x58, 0x01, 0x00, 0x00, + 0x54, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xc0, 0x13, - 0x01, 0x00, 0x00, 0x25, 0x00, 0x05, 0x00, 0x05, + 0x01, 0x00, 0x00, 0x29, 0x00, 0x05, 0x00, 0x05, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x06, 0x00, 0x17, 0x00, 0x18, 0x00, 0x19, 0x00, 0x0b, 0x00, 0x02, 0x01, 0x00, 0x00, - 0x0d, 0x00, 0x06, 0x00, 0x04, 0x04, 0x01, 0x04, - 0x03, + 0x0d, 0x00, 0x0a, 0x00, 0x08, 0x04, 0x01, 0x04, + 0x03, 0x02, 0x01, 0x02, 0x03, }, { 0x16, 0x03, 0x03, 0x00, 0x54, 0x02, 0x00, 0x00, - 0x50, 0x03, 0x03, 0x51, 0xe5, 0x78, 0x4c, 0x64, - 0x66, 0xd0, 0xee, 0x0b, 0x8b, 0xfd, 0x9b, 0xe0, - 0x54, 0x3c, 0x6e, 0x05, 0x04, 0x2f, 0x77, 0x07, - 0x8c, 0x04, 0xb9, 0xf6, 0xdd, 0xea, 0x1a, 0x7c, - 0xdf, 0x65, 0x39, 0x20, 0xea, 0xa2, 0xef, 0x53, - 0x96, 0xf5, 0x0b, 0x8a, 0x47, 0xa0, 0x7c, 0x20, - 0x53, 0x75, 0xee, 0x87, 0xb9, 0xd3, 0xe2, 0xa6, - 0x97, 0x64, 0xb9, 0xa6, 0xcc, 0xc0, 0xe5, 0xbf, - 0x92, 0x1d, 0xee, 0x4d, 0xc0, 0x13, 0x00, 0x00, + 0x50, 0x03, 0x03, 0x52, 0x65, 0x67, 0xbd, 0xe8, + 0x72, 0x03, 0x6a, 0x52, 0x8d, 0x28, 0x2c, 0x9a, + 0x53, 0xff, 0xc2, 0xa1, 0x62, 0x5f, 0x54, 0xfb, + 0x73, 0x00, 0xcf, 0x4d, 0x28, 0x36, 0xc2, 0xee, + 0xfd, 0x78, 0xf0, 0x20, 0x6f, 0xbe, 0x49, 0xec, + 0x5b, 0x6f, 0xf9, 0x53, 0x42, 0x69, 0x0d, 0x6d, + 0x8b, 0x68, 0x2e, 0xca, 0x3c, 0x3c, 0x88, 0x9e, + 0x8b, 0xf9, 0x32, 0x65, 0x09, 0xd6, 0xa0, 0x7d, + 0xea, 0xc6, 0xd5, 0xc4, 0xc0, 0x13, 0x00, 0x00, 0x08, 0x00, 0x0b, 0x00, 0x04, 0x03, 0x00, 0x01, 0x02, 0x16, 0x03, 0x03, 0x02, 0x39, 0x0b, 0x00, 0x02, 0x35, 0x00, 0x02, 0x32, 0x00, 0x02, 0x2f, @@ -1932,24 +1932,24 @@ var clientTLS12Script = [][]byte{ 0xbb, 0x77, 0xba, 0xe4, 0x12, 0xbb, 0xf4, 0xc8, 0x5e, 0x9c, 0x81, 0xa8, 0x97, 0x60, 0x4c, 0x16, 0x03, 0x03, 0x00, 0x8d, 0x0c, 0x00, 0x00, 0x89, - 0x03, 0x00, 0x17, 0x41, 0x04, 0x39, 0xe9, 0x59, - 0x24, 0x76, 0xf0, 0x1a, 0xd6, 0x21, 0xa5, 0xbc, - 0x28, 0xb9, 0xd5, 0x3d, 0xf7, 0xf3, 0xbe, 0x09, - 0xff, 0xc1, 0x79, 0x33, 0x82, 0xf8, 0xe1, 0x5f, - 0x1c, 0x34, 0x96, 0x3a, 0x10, 0xf2, 0x2c, 0x69, - 0xab, 0x57, 0xf6, 0x20, 0xb6, 0x59, 0x1f, 0x8c, - 0x3e, 0xa2, 0xac, 0x4d, 0xf2, 0x10, 0x58, 0x0b, - 0x61, 0x27, 0x6c, 0x47, 0xa0, 0x52, 0xc7, 0xe6, - 0x36, 0xfd, 0xb1, 0xa2, 0x49, 0x04, 0x01, 0x00, - 0x40, 0x99, 0x7e, 0xf9, 0xed, 0x8b, 0x62, 0x82, - 0x00, 0xde, 0x5f, 0x2f, 0xb9, 0xf9, 0x9d, 0xa1, - 0xb0, 0x14, 0x05, 0xc1, 0xdd, 0xa3, 0xb9, 0x08, - 0xa5, 0x36, 0xb6, 0xfe, 0x8a, 0x5b, 0x2d, 0x6e, - 0xd8, 0x5a, 0x5c, 0x89, 0x84, 0x85, 0x56, 0x01, - 0xaf, 0x43, 0xd3, 0x0f, 0x85, 0xd0, 0xb2, 0x35, - 0x3d, 0x1d, 0xd6, 0x67, 0x52, 0x48, 0xe8, 0x82, - 0x47, 0xbb, 0x2a, 0x54, 0x4a, 0x55, 0xcd, 0x10, - 0x54, 0x16, 0x03, 0x03, 0x00, 0x04, 0x0e, 0x00, + 0x03, 0x00, 0x17, 0x41, 0x04, 0x48, 0x93, 0x62, + 0x6a, 0xf8, 0x7c, 0x94, 0xcc, 0xcc, 0x0a, 0x9b, + 0x5e, 0x11, 0xad, 0x0b, 0x30, 0xc4, 0x5d, 0xf7, + 0x63, 0x24, 0xc1, 0xb0, 0x40, 0x5f, 0xff, 0x9f, + 0x0d, 0x7e, 0xd5, 0xa5, 0xd0, 0x4f, 0x80, 0x16, + 0xa8, 0x66, 0x18, 0x31, 0x1f, 0x81, 0xb2, 0x9a, + 0x41, 0x62, 0x5b, 0xcf, 0x73, 0xac, 0x4a, 0x64, + 0xb5, 0xc1, 0x46, 0x4d, 0x8a, 0xac, 0x25, 0xba, + 0x81, 0x7f, 0xbe, 0x64, 0x68, 0x04, 0x01, 0x00, + 0x40, 0x4e, 0x3f, 0x1e, 0x04, 0x4c, 0xef, 0xd2, + 0xa6, 0x82, 0xe6, 0x7c, 0x76, 0x23, 0x17, 0xb9, + 0xe7, 0x52, 0x15, 0x6b, 0x3d, 0xb2, 0xb1, 0x17, + 0x7d, 0xe6, 0xde, 0x06, 0x87, 0x30, 0xb0, 0xb5, + 0x57, 0xae, 0xdf, 0xb2, 0xdc, 0x8d, 0xab, 0x76, + 0x9c, 0xaa, 0x45, 0x6d, 0x23, 0x5d, 0xc1, 0xa8, + 0x7b, 0x79, 0x79, 0xb1, 0x3c, 0xdc, 0xf5, 0x33, + 0x2c, 0xa1, 0x62, 0x3e, 0xbd, 0xf5, 0x5d, 0x6c, + 0x87, 0x16, 0x03, 0x03, 0x00, 0x04, 0x0e, 0x00, 0x00, 0x00, }, { @@ -1965,74 +1965,74 @@ var clientTLS12Script = [][]byte{ 0xdc, 0x5a, 0x89, 0x14, 0x03, 0x03, 0x00, 0x01, 0x01, 0x16, 0x03, 0x03, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4e, 0xcb, - 0x97, 0x41, 0x63, 0x39, 0xeb, 0xda, 0x04, 0x39, - 0xfb, 0x67, 0x1d, 0x6d, 0xf8, 0x58, 0xd1, 0x22, - 0x35, 0xe3, 0xc3, 0x9d, 0xfc, 0x4e, 0xcc, 0x71, - 0x93, 0x78, 0x64, 0x39, 0x04, 0xa0, 0xa9, 0x41, - 0xcf, 0x4c, 0xd6, 0x34, 0xad, 0x5c, 0xc9, 0x7a, - 0x44, 0xb1, 0x1d, 0x77, 0x52, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xee, 0x17, + 0x54, 0x51, 0xb6, 0x1d, 0x8e, 0xe4, 0x6b, 0xed, + 0x5b, 0xa1, 0x27, 0x7f, 0xdc, 0xa9, 0xa5, 0xcf, + 0x38, 0xe6, 0x5d, 0x17, 0x34, 0xf9, 0xc0, 0x07, + 0xb8, 0xbe, 0x56, 0xe6, 0xd6, 0x6a, 0xb6, 0x26, + 0x4e, 0x45, 0x8d, 0x48, 0xe9, 0xc6, 0xb1, 0xa1, + 0xea, 0xdc, 0xb1, 0x37, 0xd9, 0xf6, }, { 0x14, 0x03, 0x03, 0x00, 0x01, 0x01, 0x16, 0x03, - 0x03, 0x00, 0x40, 0x55, 0x75, 0x8a, 0x57, 0xb4, - 0x53, 0xa2, 0x8f, 0xbf, 0xd3, 0x79, 0x72, 0x1e, - 0x94, 0x53, 0xb3, 0x03, 0x9d, 0x4d, 0x8a, 0x1f, - 0xbd, 0x25, 0x79, 0x69, 0x61, 0x65, 0xd7, 0x26, - 0xad, 0xa6, 0x0e, 0x89, 0x83, 0xc0, 0xbe, 0x46, - 0x51, 0xe4, 0x38, 0x7b, 0x65, 0x74, 0x6d, 0x24, - 0xff, 0xd4, 0x9f, 0xcb, 0xfc, 0xd7, 0x03, 0xaa, - 0x7b, 0x8e, 0x30, 0x09, 0xdb, 0xaa, 0x9d, 0xad, - 0xcd, 0x56, 0xcf, + 0x03, 0x00, 0x40, 0x00, 0x68, 0xc5, 0x27, 0xd5, + 0x3d, 0xba, 0x04, 0xde, 0x63, 0xf1, 0x5b, 0xc3, + 0x86, 0xb9, 0x82, 0xc7, 0xb3, 0x90, 0x31, 0xea, + 0x15, 0xe1, 0x42, 0x76, 0x7d, 0x90, 0xcb, 0xc9, + 0xd1, 0x05, 0xe6, 0x8c, 0x76, 0xc7, 0x9a, 0x35, + 0x67, 0xa2, 0x70, 0x9a, 0x8a, 0x6c, 0xb5, 0x6b, + 0xc7, 0x87, 0xf3, 0x65, 0x0a, 0xa0, 0x98, 0xba, + 0x57, 0xbb, 0x31, 0x7b, 0x1f, 0x1a, 0xf7, 0x2a, + 0xf3, 0x12, 0xf6, }, { 0x17, 0x03, 0x03, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0xab, 0x01, 0x46, - 0xa8, 0xdd, 0x62, 0x73, 0x67, 0x99, 0x01, 0x42, - 0xb2, 0x9e, 0x22, 0x18, 0xf5, 0x8f, 0x10, 0x97, - 0xde, 0x58, 0x24, 0x34, 0x36, 0xa2, 0x5d, 0xf4, - 0x96, 0x2a, 0xed, 0x6c, 0x06, 0x15, 0x03, 0x03, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x10, 0x80, + 0x54, 0x1e, 0x72, 0xd3, 0x1a, 0x86, 0x1c, 0xc4, + 0x4a, 0x9b, 0xd4, 0x80, 0xd2, 0x03, 0x35, 0x0d, + 0xe4, 0x12, 0xc2, 0x3d, 0x79, 0x4a, 0x2c, 0xba, + 0xc2, 0xad, 0xf3, 0xd2, 0x16, 0x15, 0x03, 0x03, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x9f, 0x7a, 0x9f, 0xab, 0xf5, 0x4e, - 0x1c, 0x4e, 0xf4, 0xcb, 0x1a, 0x39, 0xae, 0x21, - 0x85, 0x39, 0xc4, 0x51, 0xac, 0x14, 0xde, 0xa0, - 0xe7, 0x70, 0x7c, 0x6a, 0x53, 0x54, 0x19, 0xbc, - 0x2f, 0x32, + 0x00, 0x00, 0x04, 0x9b, 0x68, 0x78, 0x92, 0x28, + 0x62, 0x02, 0x65, 0x87, 0x90, 0xe4, 0x32, 0xd7, + 0x72, 0x08, 0x70, 0xb8, 0x52, 0x32, 0x1f, 0x97, + 0xd4, 0x6a, 0xc6, 0x28, 0x83, 0xb0, 0x1d, 0x6e, + 0x16, 0xd5, }, } // $ openssl s_server -tls1_2 -cert server.crt -key server.key \ -// -port 10443 +// -port 10443 -verify 0 // $ go test -test.run "TestRunClient" -connect -ciphersuites=0xc02f \ // -maxversion=0x0303 var clientTLS12ClientCertScript = [][]byte{ { - 0x16, 0x03, 0x01, 0x00, 0x54, 0x01, 0x00, 0x00, - 0x50, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x16, 0x03, 0x01, 0x00, 0x58, 0x01, 0x00, 0x00, + 0x54, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xc0, 0x2f, - 0x01, 0x00, 0x00, 0x25, 0x00, 0x05, 0x00, 0x05, + 0x01, 0x00, 0x00, 0x29, 0x00, 0x05, 0x00, 0x05, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x06, 0x00, 0x17, 0x00, 0x18, 0x00, 0x19, 0x00, 0x0b, 0x00, 0x02, 0x01, 0x00, 0x00, - 0x0d, 0x00, 0x06, 0x00, 0x04, 0x04, 0x01, 0x04, - 0x03, + 0x0d, 0x00, 0x0a, 0x00, 0x08, 0x04, 0x01, 0x04, + 0x03, 0x02, 0x01, 0x02, 0x03, }, { 0x16, 0x03, 0x03, 0x00, 0x54, 0x02, 0x00, 0x00, - 0x50, 0x03, 0x03, 0x52, 0x37, 0x21, 0x96, 0x1c, - 0x0a, 0x59, 0xc7, 0x16, 0x6d, 0x44, 0x76, 0xda, - 0x3f, 0x36, 0x12, 0x0c, 0x9d, 0xe1, 0xf7, 0xeb, - 0x45, 0x53, 0x89, 0xd6, 0x88, 0xc0, 0xe9, 0xce, - 0x8b, 0x40, 0xf5, 0x20, 0x13, 0x61, 0xd9, 0x3b, - 0x29, 0x74, 0x3c, 0x4b, 0x9c, 0x7b, 0x3d, 0xfa, - 0x7a, 0x8e, 0x5b, 0xf2, 0x27, 0x62, 0xc5, 0xdf, - 0xe4, 0x61, 0x7d, 0xe3, 0x8f, 0x03, 0x0c, 0x2b, - 0x38, 0x6c, 0xfe, 0x31, 0xc0, 0x2f, 0x00, 0x00, + 0x50, 0x03, 0x03, 0x52, 0x65, 0x67, 0xe0, 0xe8, + 0xf1, 0x13, 0x2a, 0x83, 0x28, 0xa8, 0x2e, 0x76, + 0x69, 0xe6, 0x89, 0x55, 0x6c, 0x48, 0x49, 0x2e, + 0x00, 0xf6, 0x87, 0x6c, 0x13, 0xa1, 0xd4, 0xaa, + 0xd0, 0x76, 0x3b, 0x20, 0xe4, 0xd6, 0x5b, 0x1d, + 0x11, 0xf2, 0x42, 0xf2, 0x82, 0x0c, 0x0d, 0x66, + 0x6d, 0xec, 0x52, 0xf8, 0x4a, 0xd9, 0x45, 0xcf, + 0xe4, 0x4a, 0xba, 0x8b, 0xf1, 0xab, 0x55, 0xe4, + 0x57, 0x18, 0xa9, 0x36, 0xc0, 0x2f, 0x00, 0x00, 0x08, 0x00, 0x0b, 0x00, 0x04, 0x03, 0x00, 0x01, 0x02, 0x16, 0x03, 0x03, 0x02, 0x39, 0x0b, 0x00, 0x02, 0x35, 0x00, 0x02, 0x32, 0x00, 0x02, 0x2f, @@ -2107,24 +2107,24 @@ var clientTLS12ClientCertScript = [][]byte{ 0xbb, 0x77, 0xba, 0xe4, 0x12, 0xbb, 0xf4, 0xc8, 0x5e, 0x9c, 0x81, 0xa8, 0x97, 0x60, 0x4c, 0x16, 0x03, 0x03, 0x00, 0x8d, 0x0c, 0x00, 0x00, 0x89, - 0x03, 0x00, 0x17, 0x41, 0x04, 0xdf, 0xc4, 0x75, - 0x20, 0x7f, 0xc1, 0x8f, 0x92, 0x2d, 0xab, 0x2d, - 0x65, 0x19, 0x40, 0xf6, 0x26, 0x19, 0x90, 0x84, - 0x40, 0x55, 0xd3, 0x50, 0xe5, 0x63, 0x9e, 0x4b, - 0x7a, 0x95, 0xdc, 0xb7, 0x2b, 0xa7, 0xa3, 0x5a, - 0x5e, 0x01, 0xa0, 0x3e, 0xc2, 0x3c, 0x5d, 0xf6, - 0x9a, 0xc8, 0xbe, 0x22, 0x23, 0x38, 0x31, 0x7c, - 0x51, 0x83, 0x5d, 0x4f, 0xfb, 0x08, 0x66, 0x5f, - 0xfe, 0xf5, 0x97, 0x9a, 0x93, 0x04, 0x01, 0x00, - 0x40, 0x81, 0x52, 0x86, 0xe6, 0x20, 0x49, 0x65, - 0x1b, 0x27, 0x46, 0x88, 0xd8, 0x0c, 0x44, 0x47, - 0xae, 0xbd, 0xc6, 0xe4, 0x4a, 0x2c, 0x10, 0xf4, - 0x3a, 0xd5, 0xbe, 0x5c, 0xfb, 0x5a, 0xe9, 0x85, - 0x57, 0xda, 0xf9, 0xb1, 0x8e, 0xce, 0x01, 0x43, - 0x84, 0x91, 0x68, 0x58, 0xa0, 0xbf, 0xd0, 0x24, - 0xaa, 0x86, 0xfa, 0x19, 0x59, 0x06, 0x16, 0xe8, - 0x82, 0x99, 0x90, 0x60, 0x02, 0x82, 0xaf, 0x7e, - 0x0e, 0x16, 0x03, 0x03, 0x00, 0x30, 0x0d, 0x00, + 0x03, 0x00, 0x17, 0x41, 0x04, 0xaa, 0xf0, 0x0c, + 0xa3, 0x60, 0xcf, 0x69, 0x1e, 0xad, 0x16, 0x9a, + 0x01, 0x40, 0xc6, 0x22, 0xc4, 0xbb, 0x06, 0x3b, + 0x84, 0x65, 0xea, 0xc7, 0xa2, 0x96, 0x79, 0x17, + 0x2f, 0xc7, 0xbe, 0x56, 0x39, 0xe4, 0x79, 0xf3, + 0xad, 0x17, 0xf3, 0x7e, 0xe2, 0x7b, 0xa2, 0x6f, + 0x3f, 0x96, 0xea, 0xe5, 0x0e, 0xea, 0x39, 0x79, + 0x77, 0xeb, 0x14, 0x18, 0xbb, 0x7c, 0x95, 0xda, + 0xa7, 0x51, 0x09, 0xba, 0xd7, 0x04, 0x01, 0x00, + 0x40, 0x82, 0x3e, 0xce, 0xee, 0x7e, 0xba, 0x3b, + 0x51, 0xb1, 0xba, 0x71, 0x2e, 0x54, 0xa9, 0xb9, + 0xe2, 0xb1, 0x59, 0x17, 0xa1, 0xac, 0x76, 0xb4, + 0x4e, 0xf1, 0xae, 0x65, 0x17, 0x2b, 0x43, 0x06, + 0x31, 0x29, 0x0b, 0xa0, 0x1e, 0xb6, 0xfa, 0x35, + 0xe8, 0x63, 0x06, 0xde, 0x13, 0x89, 0x83, 0x69, + 0x3b, 0xc2, 0x15, 0x73, 0x1c, 0xc5, 0x07, 0xe9, + 0x38, 0x9b, 0x06, 0x81, 0x1b, 0x97, 0x7c, 0xa6, + 0x89, 0x16, 0x03, 0x03, 0x00, 0x30, 0x0d, 0x00, 0x00, 0x28, 0x03, 0x01, 0x02, 0x40, 0x00, 0x20, 0x06, 0x01, 0x06, 0x02, 0x06, 0x03, 0x05, 0x01, 0x05, 0x02, 0x05, 0x03, 0x04, 0x01, 0x04, 0x02, @@ -2496,65 +2496,65 @@ var clientTLS12ClientCertScript = [][]byte{ 0xa6, 0xb5, 0x68, 0x1a, 0x41, 0x03, 0x56, 0x6b, 0xdc, 0x5a, 0x89, 0x16, 0x03, 0x03, 0x01, 0x08, 0x0f, 0x00, 0x01, 0x04, 0x04, 0x01, 0x01, 0x00, - 0x78, 0x13, 0xba, 0x6a, 0xc6, 0xec, 0xd8, 0x03, - 0x7f, 0x66, 0x83, 0xbd, 0xa6, 0xd0, 0x60, 0x05, - 0x20, 0xf7, 0x2b, 0xa3, 0xe3, 0x8c, 0xbf, 0xab, - 0x40, 0x95, 0x47, 0x31, 0xd0, 0xb6, 0x9e, 0x3c, - 0x82, 0xf1, 0xd9, 0x25, 0x89, 0x6b, 0x12, 0xf4, - 0xb4, 0xf4, 0x50, 0x44, 0xad, 0xa1, 0x96, 0x5a, - 0x2e, 0x2a, 0x75, 0xb5, 0x61, 0x71, 0x08, 0xa0, - 0x73, 0xc0, 0xdf, 0xa6, 0xd6, 0x34, 0x0f, 0xc8, - 0x3d, 0x8e, 0x67, 0x73, 0x15, 0x7d, 0x6e, 0xe7, - 0xe8, 0xf9, 0x79, 0xd2, 0x26, 0x28, 0xef, 0x94, - 0x06, 0x68, 0xf4, 0x41, 0xc9, 0x06, 0x3c, 0x38, - 0x27, 0xb9, 0xbe, 0xf3, 0x03, 0x9f, 0x3f, 0x17, - 0xa9, 0xf8, 0x3f, 0x2b, 0x98, 0x09, 0x69, 0xd2, - 0x98, 0x71, 0xa8, 0xec, 0xe6, 0xdc, 0xf3, 0x38, - 0xbc, 0x2f, 0x4a, 0x91, 0xe5, 0x4e, 0x1d, 0x83, - 0x49, 0xb4, 0xdb, 0x1c, 0x88, 0x6f, 0x0c, 0x5d, - 0xbd, 0xf4, 0x9a, 0xd3, 0xd1, 0x32, 0xd0, 0xa6, - 0xf1, 0xe9, 0xb8, 0xf6, 0xfe, 0x3c, 0x09, 0x67, - 0x40, 0xb5, 0x13, 0xe6, 0xd4, 0x82, 0xda, 0x67, - 0x27, 0x31, 0xc6, 0xac, 0xc8, 0xf4, 0x17, 0x99, - 0x2c, 0x1d, 0xf1, 0x6f, 0x1d, 0x25, 0x5f, 0x83, - 0x60, 0xa9, 0xaf, 0xf1, 0x24, 0x85, 0xd8, 0x01, - 0x2f, 0x61, 0x21, 0x64, 0xeb, 0xa3, 0x43, 0xb7, - 0x8f, 0x55, 0x1e, 0xb6, 0xda, 0x47, 0x30, 0xb2, - 0x30, 0x40, 0xd9, 0x35, 0xb7, 0x6f, 0x5e, 0x7b, - 0x6f, 0x00, 0x5a, 0x08, 0xa9, 0x67, 0xa4, 0xe5, - 0xe7, 0xe9, 0xe1, 0xa7, 0x5b, 0x9e, 0xbd, 0xdb, - 0xd1, 0x2a, 0x48, 0xb2, 0x4f, 0xf6, 0xd5, 0xe4, - 0x44, 0x4a, 0xb8, 0xd3, 0x68, 0x25, 0xf9, 0xe9, - 0xb2, 0xf5, 0xcc, 0xcd, 0x81, 0xe0, 0x01, 0x0e, - 0xb6, 0x1a, 0xe4, 0x23, 0xe9, 0xee, 0xb1, 0x7b, - 0xca, 0xa8, 0xaa, 0x45, 0xf4, 0x14, 0xeb, 0x2d, + 0x7e, 0xe4, 0x65, 0x02, 0x8e, 0xb3, 0x34, 0x6a, + 0x47, 0x71, 0xd1, 0xb0, 0x8d, 0x3c, 0x0c, 0xe1, + 0xde, 0x7e, 0x5f, 0xb4, 0x15, 0x2d, 0x32, 0x0a, + 0x2a, 0xdb, 0x9b, 0x40, 0xba, 0xce, 0x8b, 0xf5, + 0x74, 0xc1, 0x68, 0x20, 0x7c, 0x87, 0x23, 0x13, + 0xc3, 0x13, 0xa7, 0xdb, 0xec, 0x59, 0xa0, 0x40, + 0x9e, 0x64, 0x03, 0x60, 0xac, 0x76, 0xff, 0x01, + 0x34, 0x7b, 0x32, 0x26, 0xd9, 0x41, 0x31, 0x93, + 0xaa, 0x30, 0x51, 0x83, 0x85, 0x40, 0xeb, 0x4e, + 0x66, 0x39, 0x83, 0xb1, 0x30, 0x0d, 0x96, 0x01, + 0xee, 0x81, 0x53, 0x5e, 0xec, 0xa9, 0xc9, 0xdf, + 0x7e, 0xc1, 0x09, 0x47, 0x8b, 0x35, 0xdb, 0x10, + 0x15, 0xd4, 0xc7, 0x5a, 0x39, 0xe3, 0xc0, 0xf3, + 0x93, 0x38, 0x11, 0xdc, 0x71, 0xbb, 0xc7, 0x62, + 0x2b, 0x85, 0xad, 0x6b, 0x4f, 0x09, 0xb3, 0x31, + 0xa8, 0xe5, 0xd1, 0xb3, 0xa9, 0x21, 0x37, 0x50, + 0xc8, 0x7d, 0xc3, 0xd2, 0xf7, 0x00, 0xd3, 0xdb, + 0x0f, 0x82, 0xf2, 0x43, 0xcf, 0x36, 0x6c, 0x98, + 0x63, 0xd8, 0x1d, 0xb3, 0xf3, 0xde, 0x63, 0x79, + 0x64, 0xf0, 0xdb, 0x46, 0x04, 0xe1, 0x1c, 0x57, + 0x0f, 0x9e, 0x96, 0xb9, 0x93, 0x45, 0x71, 0x1c, + 0x8b, 0x65, 0x7d, 0x1e, 0xad, 0xbd, 0x03, 0x51, + 0xae, 0x44, 0xef, 0x97, 0x45, 0x0d, 0x8d, 0x41, + 0x5c, 0x80, 0x7b, 0xe6, 0xe0, 0xbc, 0xa6, 0x72, + 0x95, 0xa0, 0x97, 0xe1, 0xbb, 0xc0, 0xcc, 0xe5, + 0x1e, 0xc3, 0xbe, 0xd7, 0x42, 0x2a, 0xf3, 0x75, + 0x8a, 0x44, 0x67, 0x3c, 0xe5, 0x68, 0x78, 0xe5, + 0x40, 0x1f, 0xf0, 0x89, 0x57, 0xda, 0xee, 0x45, + 0xf4, 0x44, 0x81, 0x01, 0x77, 0xf0, 0x4a, 0x14, + 0xb1, 0x3f, 0x60, 0x2b, 0xeb, 0x42, 0x38, 0xa6, + 0xfb, 0xe5, 0x4d, 0x71, 0xdc, 0x7d, 0x0a, 0x72, + 0x56, 0x28, 0x9d, 0xa6, 0x8e, 0x74, 0x2d, 0xbd, 0x14, 0x03, 0x03, 0x00, 0x01, 0x01, 0x16, 0x03, 0x03, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x56, 0x37, 0x62, 0x42, 0xb3, - 0xdc, 0xa4, 0x01, 0x64, 0x7f, 0xa7, 0xcf, 0xb1, - 0xa4, 0x03, 0x4c, 0xf2, 0x4c, 0xe1, 0xee, 0xd6, - 0x29, 0x45, 0x71, 0x67, 0xeb, 0x3f, 0x82, 0x77, - 0x65, 0x0c, 0x13, + 0x00, 0x00, 0x00, 0x31, 0x4d, 0x58, 0x94, 0x0b, + 0x0b, 0x06, 0x5f, 0xae, 0x57, 0x17, 0x98, 0x86, + 0xaa, 0x49, 0x17, 0x7f, 0xbd, 0x41, 0x05, 0xa5, + 0x74, 0x1c, 0x58, 0xc8, 0x38, 0x2d, 0x99, 0x5d, + 0xe5, 0x12, 0x43, }, { 0x14, 0x03, 0x03, 0x00, 0x01, 0x01, 0x16, 0x03, - 0x03, 0x00, 0x28, 0xd3, 0x6b, 0x15, 0x0f, 0x23, - 0xd3, 0x5b, 0x93, 0x1d, 0x39, 0x6a, 0x74, 0xd9, - 0x78, 0x39, 0xf6, 0x76, 0x6d, 0x5d, 0x21, 0x98, - 0x7e, 0x10, 0xa4, 0x12, 0x11, 0x55, 0x25, 0xf7, - 0x6f, 0x12, 0xf1, 0x9b, 0x9f, 0xe1, 0xc0, 0xe6, - 0xbd, 0x93, 0xde, + 0x03, 0x00, 0x28, 0xf2, 0x60, 0xc2, 0x75, 0x27, + 0x64, 0xf4, 0x05, 0x98, 0xc9, 0xd3, 0xa8, 0x00, + 0x4c, 0xa0, 0x49, 0x82, 0x68, 0xf1, 0x21, 0x05, + 0x7b, 0x4b, 0x25, 0x3e, 0xe1, 0x5f, 0x0f, 0x84, + 0x26, 0x2d, 0x16, 0x2e, 0xc0, 0xfd, 0xdf, 0x0a, + 0xf4, 0xba, 0x19, }, { 0x17, 0x03, 0x03, 0x00, 0x1e, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x01, 0xc8, 0x95, 0x86, - 0xc0, 0xd0, 0xc2, 0x24, 0x1d, 0xf4, 0x20, 0xca, - 0x2b, 0x30, 0x08, 0xf1, 0xb7, 0xe3, 0x5d, 0xcf, - 0x86, 0xc3, 0xc5, 0x15, 0x03, 0x03, 0x00, 0x1a, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x35, 0xef, 0x9d, + 0x6a, 0x86, 0x98, 0xc5, 0xca, 0x55, 0xca, 0x89, + 0x29, 0xb4, 0x55, 0xd4, 0x41, 0x08, 0x96, 0xe0, + 0xf3, 0x39, 0xfc, 0x15, 0x03, 0x03, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, - 0x20, 0x13, 0xac, 0xc4, 0x6a, 0x48, 0x36, 0x04, - 0xdb, 0xae, 0x52, 0xc5, 0xc1, 0x6f, 0x4c, 0xc4, - 0x0a, 0x77, + 0x02, 0x63, 0x1b, 0xaa, 0xc6, 0xc9, 0x6d, 0x72, + 0x24, 0x10, 0x55, 0xa9, 0x8c, 0x3b, 0x23, 0xce, + 0xd8, 0x4a, }, } diff --git a/src/pkg/crypto/tls/handshake_messages_test.go b/src/pkg/crypto/tls/handshake_messages_test.go index a6da0d13f..4f569eeb1 100644 --- a/src/pkg/crypto/tls/handshake_messages_test.go +++ b/src/pkg/crypto/tls/handshake_messages_test.go @@ -136,7 +136,7 @@ func (*clientHelloMsg) Generate(rand *rand.Rand, size int) reflect.Value { } } if rand.Intn(10) > 5 { - m.signatureAndHashes = supportedSignatureAlgorithms + m.signatureAndHashes = supportedSKXSignatureAlgorithms } return reflect.ValueOf(m) diff --git a/src/pkg/crypto/tls/handshake_server.go b/src/pkg/crypto/tls/handshake_server.go index 1db10f289..c9ccf675c 100644 --- a/src/pkg/crypto/tls/handshake_server.go +++ b/src/pkg/crypto/tls/handshake_server.go @@ -318,7 +318,7 @@ func (hs *serverHandshakeState) doFullHandshake() error { } if c.vers >= VersionTLS12 { certReq.hasSignatureAndHash = true - certReq.signatureAndHashes = supportedSignatureAlgorithms + certReq.signatureAndHashes = supportedClientCertSignatureAlgorithms } // An empty list of certificateAuthorities signals to diff --git a/src/pkg/crypto/tls/key_agreement.go b/src/pkg/crypto/tls/key_agreement.go index f6cbcd4fe..7e820c1e7 100644 --- a/src/pkg/crypto/tls/key_agreement.go +++ b/src/pkg/crypto/tls/key_agreement.go @@ -117,15 +117,47 @@ func sha256Hash(slices [][]byte) []byte { } // hashForServerKeyExchange hashes the given slices and returns their digest -// and the identifier of the hash function used. -func hashForServerKeyExchange(sigType uint8, version uint16, slices ...[]byte) ([]byte, crypto.Hash) { +// and the identifier of the hash function used. The hashFunc argument is only +// used for >= TLS 1.2 and precisely identifies the hash function to use. +func hashForServerKeyExchange(sigType, hashFunc uint8, version uint16, slices ...[]byte) ([]byte, crypto.Hash, error) { if version >= VersionTLS12 { - return sha256Hash(slices), crypto.SHA256 + switch hashFunc { + case hashSHA256: + return sha256Hash(slices), crypto.SHA256, nil + case hashSHA1: + return sha1Hash(slices), crypto.SHA1, nil + default: + return nil, crypto.Hash(0), errors.New("tls: unknown hash function used by peer") + } } if sigType == signatureECDSA { - return sha1Hash(slices), crypto.SHA1 + return sha1Hash(slices), crypto.SHA1, nil } - return md5SHA1Hash(slices), crypto.MD5SHA1 + return md5SHA1Hash(slices), crypto.MD5SHA1, nil +} + +// pickTLS12HashForSignature returns a TLS 1.2 hash identifier for signing a +// ServerKeyExchange given the signature type being used and the client's +// advertized list of supported signature and hash combinations. +func pickTLS12HashForSignature(sigType uint8, clientSignatureAndHashes []signatureAndHash) (uint8, error) { + if len(clientSignatureAndHashes) == 0 { + // If the client didn't specify any signature_algorithms + // extension then we can assume that it supports SHA1. See + // http://tools.ietf.org/html/rfc5246#section-7.4.1.4.1 + return hashSHA1, nil + } + + for _, sigAndHash := range clientSignatureAndHashes { + if sigAndHash.signature != sigType { + continue + } + switch sigAndHash.hash { + case hashSHA1, hashSHA256: + return sigAndHash.hash, nil + } + } + + return 0, errors.New("tls: client doesn't support any common hash functions") } // ecdheRSAKeyAgreement implements a TLS key agreement where the server @@ -181,7 +213,17 @@ Curve: serverECDHParams[3] = byte(len(ecdhePublic)) copy(serverECDHParams[4:], ecdhePublic) - digest, hashFunc := hashForServerKeyExchange(ka.sigType, ka.version, clientHello.random, hello.random, serverECDHParams) + var tls12HashId uint8 + if ka.version >= VersionTLS12 { + if tls12HashId, err = pickTLS12HashForSignature(ka.sigType, clientHello.signatureAndHashes); err != nil { + return nil, err + } + } + + digest, hashFunc, err := hashForServerKeyExchange(ka.sigType, tls12HashId, ka.version, clientHello.random, hello.random, serverECDHParams) + if err != nil { + return nil, err + } var sig []byte switch ka.sigType { case signatureECDSA: @@ -216,7 +258,7 @@ Curve: copy(skx.key, serverECDHParams) k := skx.key[len(serverECDHParams):] if ka.version >= VersionTLS12 { - k[0] = hashSHA256 + k[0] = tls12HashId k[1] = ka.sigType k = k[2:] } @@ -279,9 +321,16 @@ func (ka *ecdheKeyAgreement) processServerKeyExchange(config *Config, clientHell if len(sig) < 2 { return errServerKeyExchange } + + var tls12HashId uint8 if ka.version >= VersionTLS12 { - // ignore SignatureAndHashAlgorithm - sig = sig[2:] + // handle SignatureAndHashAlgorithm + var sigAndHash []uint8 + sigAndHash, sig = sig[:2], sig[2:] + if sigAndHash[1] != ka.sigType { + return errServerKeyExchange + } + tls12HashId = sigAndHash[0] if len(sig) < 2 { return errServerKeyExchange } @@ -292,7 +341,10 @@ func (ka *ecdheKeyAgreement) processServerKeyExchange(config *Config, clientHell } sig = sig[2:] - digest, hashFunc := hashForServerKeyExchange(ka.sigType, ka.version, clientHello.random, serverHello.random, serverECDHParams) + digest, hashFunc, err := hashForServerKeyExchange(ka.sigType, tls12HashId, ka.version, clientHello.random, serverHello.random, serverECDHParams) + if err != nil { + return err + } switch ka.sigType { case signatureECDSA: pubKey, ok := cert.PublicKey.(*ecdsa.PublicKey) |