crypto/tls: return correct hash function when using client certificates in handshake

Commit f1d669aee994b28e1afcfe974680565932d25b70 added support for
AES_256_GCM_SHA384 cipher suites as specified in RFC5289. However, it
did not take the arbitrary hash function into account in the TLS client
handshake when using client certificates.

The hashForClientCertificate method always returned SHA256 as its
hashing function, even if it actually used a different one to calculate
its digest. Setting up the connection would eventually fail with the
error "tls: failed to sign handshake with client certificate:
crypto/rsa: input must be hashed message".

Included is an additional test for this specific situation that uses the
SHA384 hash.

Fixes #9808

Change-Id: Iccbf4ab225633471ef897907c208ad31f92855a3
Reviewed-on: https://go-review.googlesource.com/7040
Reviewed-by: Adam Langley <agl@golang.org>
Run-TryBot: Adam Langley <agl@golang.org>
This commit is contained in:
Joël Stemmer 2015-03-06 14:08:55 +01:00 committed by Adam Langley
parent 921f871f9e
commit c32a7dcd6d
4 changed files with 167 additions and 4 deletions

View File

@ -123,6 +123,7 @@ const (
const (
hashSHA1 uint8 = 2
hashSHA256 uint8 = 4
hashSHA384 uint8 = 5
)
// Signature algorithms for TLS 1.2 (See RFC 5246, section A.4.1)

View File

@ -344,6 +344,16 @@ func TestHandshakeClientCertRSA(t *testing.T) {
runClientTestTLS10(t, test)
runClientTestTLS12(t, test)
test = &clientTest{
name: "ClientCert-RSA-AES256-GCM-SHA384",
command: []string{"openssl", "s_server", "-cipher", "ECDHE-RSA-AES256-GCM-SHA384", "-verify", "1"},
config: &config,
cert: testRSACertificate,
key: testRSAPrivateKey,
}
runClientTestTLS12(t, test)
}
func TestHandshakeClientCertECDSA(t *testing.T) {

20
prf.go
View File

@ -169,16 +169,18 @@ func keysFromMasterSecret(version uint16, tls12Hash crypto.Hash, masterSecret, c
func newFinishedHash(version uint16, tls12Hash crypto.Hash) finishedHash {
if version >= VersionTLS12 {
return finishedHash{tls12Hash.New(), tls12Hash.New(), nil, nil, version, prfForVersion(version, tls12Hash)}
return finishedHash{tls12Hash.New(), tls12Hash.New(), tls12Hash, nil, nil, version, prfForVersion(version, tls12Hash)}
}
return finishedHash{sha1.New(), sha1.New(), md5.New(), md5.New(), version, prfForVersion(version, tls12Hash)}
return finishedHash{sha1.New(), sha1.New(), crypto.MD5SHA1, md5.New(), md5.New(), version, prfForVersion(version, tls12Hash)}
}
// A finishedHash calculates the hash of a set of handshake messages suitable
// for including in a Finished message.
type finishedHash struct {
client hash.Hash
server hash.Hash
serverHash crypto.Hash
// Prior to TLS 1.2, an additional MD5 hash is required.
clientMD5 hash.Hash
@ -279,7 +281,7 @@ func (h finishedHash) serverSum(masterSecret []byte) []byte {
func (h finishedHash) hashForClientCertificate(sigType uint8) ([]byte, crypto.Hash, uint8) {
if h.version >= VersionTLS12 {
digest := h.server.Sum(nil)
return digest, crypto.SHA256, hashSHA256
return digest, h.serverHash, tls12HashID(h.serverHash)
}
if sigType == signatureECDSA {
digest := h.server.Sum(nil)
@ -291,3 +293,15 @@ func (h finishedHash) hashForClientCertificate(sigType uint8) ([]byte, crypto.Ha
digest = h.server.Sum(digest)
return digest, crypto.MD5SHA1, 0 /* not specified in TLS 1.2. */
}
// tls12HashID returns the HashAlgorithm id corresponding to the hash h, as
// specified in RFC 5246, section A.4.1.
func tls12HashID(h crypto.Hash) uint8 {
switch h {
case crypto.SHA256:
return hashSHA256
case crypto.SHA384:
return hashSHA384
}
return 0
}

View File

@ -0,0 +1,138 @@
>>> Flow 1 (client to server)
00000000 16 03 01 00 79 01 00 00 75 03 03 00 00 00 00 00 |....y...u.......|
00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 1e c0 2f |.............../|
00000030 c0 2b c0 30 c0 2c c0 11 c0 07 c0 13 c0 09 c0 14 |.+.0.,..........|
00000040 c0 0a 00 05 00 2f 00 35 c0 12 00 0a 01 00 00 2e |...../.5........|
00000050 00 05 00 05 01 00 00 00 00 00 0a 00 08 00 06 00 |................|
00000060 17 00 18 00 19 00 0b 00 02 01 00 00 0d 00 0a 00 |................|
00000070 08 04 01 04 03 02 01 02 03 ff 01 00 01 00 |..............|
>>> Flow 2 (server to client)
00000000 16 03 03 00 59 02 00 00 55 03 03 2d 12 aa 2a 67 |....Y...U..-..*g|
00000010 e1 6c 55 dc 1c 0b 3f 94 39 7a 2f e3 4e d4 85 cb |.lU...?.9z/.N...|
00000020 31 ff da 09 dd e0 92 75 6c e8 0b 20 e1 e7 fc 09 |1......ul.. ....|
00000030 bd 12 b8 5c b2 54 75 01 7a f5 65 95 d7 87 66 77 |...\.Tu.z.e...fw|
00000040 03 1f 25 23 cb 39 9f 47 2b 5c fd bd c0 30 00 00 |..%#.9.G+\...0..|
00000050 0d ff 01 00 01 00 00 0b 00 04 03 00 01 02 16 03 |................|
00000060 03 02 be 0b 00 02 ba 00 02 b7 00 02 b4 30 82 02 |.............0..|
00000070 b0 30 82 02 19 a0 03 02 01 02 02 09 00 85 b0 bb |.0..............|
00000080 a4 8a 7f b8 ca 30 0d 06 09 2a 86 48 86 f7 0d 01 |.....0...*.H....|
00000090 01 05 05 00 30 45 31 0b 30 09 06 03 55 04 06 13 |....0E1.0...U...|
000000a0 02 41 55 31 13 30 11 06 03 55 04 08 13 0a 53 6f |.AU1.0...U....So|
000000b0 6d 65 2d 53 74 61 74 65 31 21 30 1f 06 03 55 04 |me-State1!0...U.|
000000c0 0a 13 18 49 6e 74 65 72 6e 65 74 20 57 69 64 67 |...Internet Widg|
000000d0 69 74 73 20 50 74 79 20 4c 74 64 30 1e 17 0d 31 |its Pty Ltd0...1|
000000e0 30 30 34 32 34 30 39 30 39 33 38 5a 17 0d 31 31 |00424090938Z..11|
000000f0 30 34 32 34 30 39 30 39 33 38 5a 30 45 31 0b 30 |0424090938Z0E1.0|
00000100 09 06 03 55 04 06 13 02 41 55 31 13 30 11 06 03 |...U....AU1.0...|
00000110 55 04 08 13 0a 53 6f 6d 65 2d 53 74 61 74 65 31 |U....Some-State1|
00000120 21 30 1f 06 03 55 04 0a 13 18 49 6e 74 65 72 6e |!0...U....Intern|
00000130 65 74 20 57 69 64 67 69 74 73 20 50 74 79 20 4c |et Widgits Pty L|
00000140 74 64 30 81 9f 30 0d 06 09 2a 86 48 86 f7 0d 01 |td0..0...*.H....|
00000150 01 01 05 00 03 81 8d 00 30 81 89 02 81 81 00 bb |........0.......|
00000160 79 d6 f5 17 b5 e5 bf 46 10 d0 dc 69 be e6 2b 07 |y......F...i..+.|
00000170 43 5a d0 03 2d 8a 7a 43 85 b7 14 52 e7 a5 65 4c |CZ..-.zC...R..eL|
00000180 2c 78 b8 23 8c b5 b4 82 e5 de 1f 95 3b 7e 62 a5 |,x.#........;~b.|
00000190 2c a5 33 d6 fe 12 5c 7a 56 fc f5 06 bf fa 58 7b |,.3...\zV.....X{|
000001a0 26 3f b5 cd 04 d3 d0 c9 21 96 4a c7 f4 54 9f 5a |&?......!.J..T.Z|
000001b0 bf ef 42 71 00 fe 18 99 07 7f 7e 88 7d 7d f1 04 |..Bq......~.}}..|
000001c0 39 c4 a2 2e db 51 c9 7c e3 c0 4c 3b 32 66 01 cf |9....Q.|..L;2f..|
000001d0 af b1 1d b8 71 9a 1d db db 89 6b ae da 2d 79 02 |....q.....k..-y.|
000001e0 03 01 00 01 a3 81 a7 30 81 a4 30 1d 06 03 55 1d |.......0..0...U.|
000001f0 0e 04 16 04 14 b1 ad e2 85 5a cf cb 28 db 69 ce |.........Z..(.i.|
00000200 23 69 de d3 26 8e 18 88 39 30 75 06 03 55 1d 23 |#i..&...90u..U.#|
00000210 04 6e 30 6c 80 14 b1 ad e2 85 5a cf cb 28 db 69 |.n0l......Z..(.i|
00000220 ce 23 69 de d3 26 8e 18 88 39 a1 49 a4 47 30 45 |.#i..&...9.I.G0E|
00000230 31 0b 30 09 06 03 55 04 06 13 02 41 55 31 13 30 |1.0...U....AU1.0|
00000240 11 06 03 55 04 08 13 0a 53 6f 6d 65 2d 53 74 61 |...U....Some-Sta|
00000250 74 65 31 21 30 1f 06 03 55 04 0a 13 18 49 6e 74 |te1!0...U....Int|
00000260 65 72 6e 65 74 20 57 69 64 67 69 74 73 20 50 74 |ernet Widgits Pt|
00000270 79 20 4c 74 64 82 09 00 85 b0 bb a4 8a 7f b8 ca |y Ltd...........|
00000280 30 0c 06 03 55 1d 13 04 05 30 03 01 01 ff 30 0d |0...U....0....0.|
00000290 06 09 2a 86 48 86 f7 0d 01 01 05 05 00 03 81 81 |..*.H...........|
000002a0 00 08 6c 45 24 c7 6b b1 59 ab 0c 52 cc f2 b0 14 |..lE$.k.Y..R....|
000002b0 d7 87 9d 7a 64 75 b5 5a 95 66 e4 c5 2b 8e ae 12 |...zdu.Z.f..+...|
000002c0 66 1f eb 4f 38 b3 6e 60 d3 92 fd f7 41 08 b5 25 |f..O8.n`....A..%|
000002d0 13 b1 18 7a 24 fb 30 1d ba ed 98 b9 17 ec e7 d7 |...z$.0.........|
000002e0 31 59 db 95 d3 1d 78 ea 50 56 5c d5 82 5a 2d 5a |1Y....x.PV\..Z-Z|
000002f0 5f 33 c4 b6 d8 c9 75 90 96 8c 0f 52 98 b5 cd 98 |_3....u....R....|
00000300 1f 89 20 5f f2 a0 1c a3 1b 96 94 dd a9 fd 57 e9 |.. _..........W.|
00000310 70 e8 26 6d 71 99 9b 26 6e 38 50 29 6c 90 a7 bd |p.&mq..&n8P)l...|
00000320 d9 16 03 03 00 cd 0c 00 00 c9 03 00 17 41 04 99 |.............A..|
00000330 91 58 07 9b 2b 79 26 ad cb 37 07 5e f3 e3 75 81 |.X..+y&..7.^..u.|
00000340 32 50 39 59 a4 7c c0 b8 c2 f4 16 de dc c3 9f ba |2P9Y.|..........|
00000350 04 42 a4 15 9c 8f 4e da 35 88 fc e5 b1 03 70 85 |.B....N.5.....p.|
00000360 64 a3 6e 59 15 8c 92 11 4c 10 d9 90 f4 a9 9b 04 |d.nY....L.......|
00000370 01 00 80 4e d1 02 4d d0 a7 7d 01 42 7a b6 75 ed |...N..M..}.Bz.u.|
00000380 ea 10 a3 66 a2 35 94 2d 2d 7a 32 55 63 23 df 8c |...f.5.--z2Uc#..|
00000390 9e ec d2 19 df bb e0 02 70 c0 50 4f 05 d8 ec 1c |........p.PO....|
000003a0 40 a1 a5 ae 2c 80 5b 6f b1 f9 f9 74 20 dc 4f d7 |@...,.[o...t .O.|
000003b0 23 b3 25 61 a7 5e 76 37 a7 17 f3 54 47 08 d9 2c |#.%a.^v7...TG..,|
000003c0 fb ea 4f 56 51 ee 5c cc 2f 4d 80 66 7b 21 78 1d |..OVQ.\./M.f{!x.|
000003d0 ef a0 71 96 cc 3d 09 8e 37 fd bc 9f 26 be 75 48 |..q..=..7...&.uH|
000003e0 b2 a1 39 0e b3 d3 73 f5 f1 68 4f aa 03 92 c0 1f |..9...s..hO.....|
000003f0 90 74 a9 16 03 03 00 2e 0d 00 00 26 03 01 02 40 |.t.........&...@|
00000400 00 1e 06 01 06 02 06 03 05 01 05 02 05 03 04 01 |................|
00000410 04 02 04 03 03 01 03 02 03 03 02 01 02 02 02 03 |................|
00000420 00 00 0e 00 00 00 |......|
>>> Flow 3 (client to server)
00000000 16 03 03 01 fb 0b 00 01 f7 00 01 f4 00 01 f1 30 |...............0|
00000010 82 01 ed 30 82 01 58 a0 03 02 01 02 02 01 00 30 |...0..X........0|
00000020 0b 06 09 2a 86 48 86 f7 0d 01 01 05 30 26 31 10 |...*.H......0&1.|
00000030 30 0e 06 03 55 04 0a 13 07 41 63 6d 65 20 43 6f |0...U....Acme Co|
00000040 31 12 30 10 06 03 55 04 03 13 09 31 32 37 2e 30 |1.0...U....127.0|
00000050 2e 30 2e 31 30 1e 17 0d 31 31 31 32 30 38 30 37 |.0.10...11120807|
00000060 35 35 31 32 5a 17 0d 31 32 31 32 30 37 30 38 30 |5512Z..121207080|
00000070 30 31 32 5a 30 26 31 10 30 0e 06 03 55 04 0a 13 |012Z0&1.0...U...|
00000080 07 41 63 6d 65 20 43 6f 31 12 30 10 06 03 55 04 |.Acme Co1.0...U.|
00000090 03 13 09 31 32 37 2e 30 2e 30 2e 31 30 81 9c 30 |...127.0.0.10..0|
000000a0 0b 06 09 2a 86 48 86 f7 0d 01 01 01 03 81 8c 00 |...*.H..........|
000000b0 30 81 88 02 81 80 4e d0 7b 31 e3 82 64 d9 59 c0 |0.....N.{1..d.Y.|
000000c0 c2 87 a4 5e 1e 8b 73 33 c7 63 53 df 66 92 06 84 |...^..s3.cS.f...|
000000d0 f6 64 d5 8f e4 36 a7 1d 2b e8 b3 20 36 45 23 b5 |.d...6..+.. 6E#.|
000000e0 e3 95 ae ed e0 f5 20 9c 8d 95 df 7f 5a 12 ef 87 |...... .....Z...|
000000f0 e4 5b 68 e4 e9 0e 74 ec 04 8a 7f de 93 27 c4 01 |.[h...t......'..|
00000100 19 7a bd f2 dc 3d 14 ab d0 54 ca 21 0c d0 4d 6e |.z...=...T.!..Mn|
00000110 87 2e 5c c5 d2 bb 4d 4b 4f ce b6 2c f7 7e 88 ec |..\...MKO..,.~..|
00000120 7c d7 02 91 74 a6 1e 0c 1a da e3 4a 5a 2e de 13 ||...t......JZ...|
00000130 9c 4c 40 88 59 93 02 03 01 00 01 a3 32 30 30 30 |.L@.Y.......2000|
00000140 0e 06 03 55 1d 0f 01 01 ff 04 04 03 02 00 a0 30 |...U...........0|
00000150 0d 06 03 55 1d 0e 04 06 04 04 01 02 03 04 30 0f |...U..........0.|
00000160 06 03 55 1d 23 04 08 30 06 80 04 01 02 03 04 30 |..U.#..0.......0|
00000170 0b 06 09 2a 86 48 86 f7 0d 01 01 05 03 81 81 00 |...*.H..........|
00000180 36 1f b3 7a 0c 75 c9 6e 37 46 61 2b d5 bd c0 a7 |6..z.u.n7Fa+....|
00000190 4b cc 46 9a 81 58 7c 85 79 29 c8 c8 c6 67 dd 32 |K.F..X|.y)...g.2|
000001a0 56 45 2b 75 b6 e9 24 a9 50 9a be 1f 5a fa 1a 15 |VE+u..$.P...Z...|
000001b0 d9 cc 55 95 72 16 83 b9 c2 b6 8f fd 88 8c 38 84 |..U.r.........8.|
000001c0 1d ab 5d 92 31 13 4f fd 83 3b c6 9d f1 11 62 b6 |..].1.O..;....b.|
000001d0 8b ec ab 67 be c8 64 b0 11 50 46 58 17 6b 99 1c |...g..d..PFX.k..|
000001e0 d3 1d fc 06 f1 0e e5 96 a8 0c f9 78 20 b7 44 18 |...........x .D.|
000001f0 51 8d 10 7e 4f 94 67 df a3 4e 70 73 8e 90 91 85 |Q..~O.g..Nps....|
00000200 16 03 03 00 46 10 00 00 42 41 04 1e 18 37 ef 0d |....F...BA...7..|
00000210 19 51 88 35 75 71 b5 e5 54 5b 12 2e 8f 09 67 fd |.Q.5uq..T[....g.|
00000220 a7 24 20 3e b2 56 1c ce 97 28 5e f8 2b 2d 4f 9e |.$ >.V...(^.+-O.|
00000230 f1 07 9f 6c 4b 5b 83 56 e2 32 42 e9 58 b6 d7 49 |...lK[.V.2B.X..I|
00000240 a6 b5 68 1a 41 03 56 6b dc 5a 89 16 03 03 00 88 |..h.A.Vk.Z......|
00000250 0f 00 00 84 05 01 00 80 2c 1c b4 c4 d6 73 62 3a |........,....sb:|
00000260 86 37 c5 cb 3d 28 5f 3b 7f e2 08 f8 38 ef dc c4 |.7..=(_;....8...|
00000270 a9 13 b6 82 28 0a 3a 67 48 01 c7 54 1d 4f b4 b4 |....(.:gH..T.O..|
00000280 4e a8 5b fc b6 9b 27 7c e3 a6 d7 88 62 2d 2c ca |N.[...'|....b-,.|
00000290 35 55 b3 99 ac 4e 28 45 55 29 3e 30 fc 46 6b 86 |5U...N(EU)>0.Fk.|
000002a0 20 0b b1 d0 7c c5 07 cd d8 49 5a 88 dd c2 bc 5d | ...|....IZ....]|
000002b0 5f ad 52 d8 be 56 e4 fd f8 ab ef 17 04 08 50 a5 |_.R..V........P.|
000002c0 2f 52 58 e5 31 51 e4 83 44 41 c0 8e 16 cf 39 4f |/RX.1Q..DA....9O|
000002d0 3d de c8 19 1e 5c c3 a7 14 03 03 00 01 01 16 03 |=....\..........|
000002e0 03 00 28 00 00 00 00 00 00 00 00 2c e0 65 72 59 |..(........,.erY|
000002f0 1e 0a ff 8b 58 74 14 c8 c5 fa db 08 06 4f a1 d4 |....Xt.......O..|
00000300 20 cc f4 3e 6a f5 5c 0f 8e 26 1d | ..>j.\..&.|
>>> Flow 4 (server to client)
00000000 14 03 03 00 01 01 16 03 03 00 28 59 f7 e1 f5 7c |..........(Y...||
00000010 ef 54 7c ee 08 29 50 82 d2 43 32 f5 c1 bc af 0c |.T|..)P..C2.....|
00000020 5f 4f 6e 9a fd 65 8c 4d ef c4 0e ec 6a ea 46 73 |_On..e.M....j.Fs|
00000030 e2 9f 4a |..J|
>>> Flow 5 (client to server)
00000000 17 03 03 00 1e 00 00 00 00 00 00 00 01 4d b2 6d |.............M.m|
00000010 73 75 d3 68 3d a5 7c 98 32 3f b2 4a 47 3f b2 95 |su.h=.|.2?.JG?..|
00000020 8f cd 99 15 03 03 00 1a 00 00 00 00 00 00 00 02 |................|
00000030 91 31 70 57 68 0a e1 e1 1b ca f0 62 ab 22 da 3d |.1pWh......b.".=|
00000040 e1 64 |.d|