Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

cipher_suites.go 11 KiB

crypto/tls: decouple handshake signatures from the handshake hash. Prior to TLS 1.2, the handshake had a pleasing property that one could incrementally hash it and, from that, get the needed hashes for both the CertificateVerify and Finished messages. TLS 1.2 introduced negotiation for the signature and hash and it became possible for the handshake hash to be, say, SHA-384, but for the CertificateVerify to sign the handshake with SHA-1. The problem is that one doesn't know in advance which hashes will be needed and thus the handshake needs to be buffered. Go ignored this, always kept a single handshake hash, and any signatures over the handshake had to use that hash. However, there are a set of servers that inspect the client's offered signature hash functions and will abort the handshake if one of the server's certificates is signed with a hash function outside of that set. https://robertsspaceindustries.com/ is an example of such a server. Clearly not a lot of thought happened when that server code was written, but its out there and we have to deal with it. This change decouples the handshake hash from the CertificateVerify hash. This lays the groundwork for advertising support for SHA-384 but doesn't actually make that change in the interests of reviewability. Updating the advertised hash functions will cause changes in many of the testdata/ files and some errors might get lost in the noise. This change only needs to update four testdata/ files: one because a SHA-384-based handshake is now being signed with SHA-256 and the others because the TLS 1.2 CertificateRequest message now includes SHA-1. This change also has the effect of adding support for client-certificates in SSLv3 servers. However, SSLv3 is now disabled by default so this should be moot. It would be possible to avoid much of this change and just support SHA-384 for the ServerKeyExchange as the SKX only signs over the nonces and SKX params (a design mistake in TLS). However, that would leave Go in the odd situation where it advertised support for SHA-384, but would only use the handshake hash when signing client certificates. I fear that'll just cause problems in the future. Much of this code was written by davidben@ for the purposes of testing BoringSSL. Partly addresses #9757 Change-Id: I5137a472b6076812af387a5a69fc62c7373cd485 Reviewed-on: https://go-review.googlesource.com/9415 Run-TryBot: Adam Langley <agl@golang.org> Reviewed-by: Adam Langley <agl@golang.org>
il y a 9 ans
crypto/tls: decouple handshake signatures from the handshake hash. Prior to TLS 1.2, the handshake had a pleasing property that one could incrementally hash it and, from that, get the needed hashes for both the CertificateVerify and Finished messages. TLS 1.2 introduced negotiation for the signature and hash and it became possible for the handshake hash to be, say, SHA-384, but for the CertificateVerify to sign the handshake with SHA-1. The problem is that one doesn't know in advance which hashes will be needed and thus the handshake needs to be buffered. Go ignored this, always kept a single handshake hash, and any signatures over the handshake had to use that hash. However, there are a set of servers that inspect the client's offered signature hash functions and will abort the handshake if one of the server's certificates is signed with a hash function outside of that set. https://robertsspaceindustries.com/ is an example of such a server. Clearly not a lot of thought happened when that server code was written, but its out there and we have to deal with it. This change decouples the handshake hash from the CertificateVerify hash. This lays the groundwork for advertising support for SHA-384 but doesn't actually make that change in the interests of reviewability. Updating the advertised hash functions will cause changes in many of the testdata/ files and some errors might get lost in the noise. This change only needs to update four testdata/ files: one because a SHA-384-based handshake is now being signed with SHA-256 and the others because the TLS 1.2 CertificateRequest message now includes SHA-1. This change also has the effect of adding support for client-certificates in SSLv3 servers. However, SSLv3 is now disabled by default so this should be moot. It would be possible to avoid much of this change and just support SHA-384 for the ServerKeyExchange as the SKX only signs over the nonces and SKX params (a design mistake in TLS). However, that would leave Go in the odd situation where it advertised support for SHA-384, but would only use the handshake hash when signing client certificates. I fear that'll just cause problems in the future. Much of this code was written by davidben@ for the purposes of testing BoringSSL. Partly addresses #9757 Change-Id: I5137a472b6076812af387a5a69fc62c7373cd485 Reviewed-on: https://go-review.googlesource.com/9415 Run-TryBot: Adam Langley <agl@golang.org> Reviewed-by: Adam Langley <agl@golang.org>
il y a 9 ans
crypto/tls: decouple handshake signatures from the handshake hash. Prior to TLS 1.2, the handshake had a pleasing property that one could incrementally hash it and, from that, get the needed hashes for both the CertificateVerify and Finished messages. TLS 1.2 introduced negotiation for the signature and hash and it became possible for the handshake hash to be, say, SHA-384, but for the CertificateVerify to sign the handshake with SHA-1. The problem is that one doesn't know in advance which hashes will be needed and thus the handshake needs to be buffered. Go ignored this, always kept a single handshake hash, and any signatures over the handshake had to use that hash. However, there are a set of servers that inspect the client's offered signature hash functions and will abort the handshake if one of the server's certificates is signed with a hash function outside of that set. https://robertsspaceindustries.com/ is an example of such a server. Clearly not a lot of thought happened when that server code was written, but its out there and we have to deal with it. This change decouples the handshake hash from the CertificateVerify hash. This lays the groundwork for advertising support for SHA-384 but doesn't actually make that change in the interests of reviewability. Updating the advertised hash functions will cause changes in many of the testdata/ files and some errors might get lost in the noise. This change only needs to update four testdata/ files: one because a SHA-384-based handshake is now being signed with SHA-256 and the others because the TLS 1.2 CertificateRequest message now includes SHA-1. This change also has the effect of adding support for client-certificates in SSLv3 servers. However, SSLv3 is now disabled by default so this should be moot. It would be possible to avoid much of this change and just support SHA-384 for the ServerKeyExchange as the SKX only signs over the nonces and SKX params (a design mistake in TLS). However, that would leave Go in the odd situation where it advertised support for SHA-384, but would only use the handshake hash when signing client certificates. I fear that'll just cause problems in the future. Much of this code was written by davidben@ for the purposes of testing BoringSSL. Partly addresses #9757 Change-Id: I5137a472b6076812af387a5a69fc62c7373cd485 Reviewed-on: https://go-review.googlesource.com/9415 Run-TryBot: Adam Langley <agl@golang.org> Reviewed-by: Adam Langley <agl@golang.org>
il y a 9 ans
crypto/tls: decouple handshake signatures from the handshake hash. Prior to TLS 1.2, the handshake had a pleasing property that one could incrementally hash it and, from that, get the needed hashes for both the CertificateVerify and Finished messages. TLS 1.2 introduced negotiation for the signature and hash and it became possible for the handshake hash to be, say, SHA-384, but for the CertificateVerify to sign the handshake with SHA-1. The problem is that one doesn't know in advance which hashes will be needed and thus the handshake needs to be buffered. Go ignored this, always kept a single handshake hash, and any signatures over the handshake had to use that hash. However, there are a set of servers that inspect the client's offered signature hash functions and will abort the handshake if one of the server's certificates is signed with a hash function outside of that set. https://robertsspaceindustries.com/ is an example of such a server. Clearly not a lot of thought happened when that server code was written, but its out there and we have to deal with it. This change decouples the handshake hash from the CertificateVerify hash. This lays the groundwork for advertising support for SHA-384 but doesn't actually make that change in the interests of reviewability. Updating the advertised hash functions will cause changes in many of the testdata/ files and some errors might get lost in the noise. This change only needs to update four testdata/ files: one because a SHA-384-based handshake is now being signed with SHA-256 and the others because the TLS 1.2 CertificateRequest message now includes SHA-1. This change also has the effect of adding support for client-certificates in SSLv3 servers. However, SSLv3 is now disabled by default so this should be moot. It would be possible to avoid much of this change and just support SHA-384 for the ServerKeyExchange as the SKX only signs over the nonces and SKX params (a design mistake in TLS). However, that would leave Go in the odd situation where it advertised support for SHA-384, but would only use the handshake hash when signing client certificates. I fear that'll just cause problems in the future. Much of this code was written by davidben@ for the purposes of testing BoringSSL. Partly addresses #9757 Change-Id: I5137a472b6076812af387a5a69fc62c7373cd485 Reviewed-on: https://go-review.googlesource.com/9415 Run-TryBot: Adam Langley <agl@golang.org> Reviewed-by: Adam Langley <agl@golang.org>
il y a 9 ans
crypto/tls: decouple handshake signatures from the handshake hash. Prior to TLS 1.2, the handshake had a pleasing property that one could incrementally hash it and, from that, get the needed hashes for both the CertificateVerify and Finished messages. TLS 1.2 introduced negotiation for the signature and hash and it became possible for the handshake hash to be, say, SHA-384, but for the CertificateVerify to sign the handshake with SHA-1. The problem is that one doesn't know in advance which hashes will be needed and thus the handshake needs to be buffered. Go ignored this, always kept a single handshake hash, and any signatures over the handshake had to use that hash. However, there are a set of servers that inspect the client's offered signature hash functions and will abort the handshake if one of the server's certificates is signed with a hash function outside of that set. https://robertsspaceindustries.com/ is an example of such a server. Clearly not a lot of thought happened when that server code was written, but its out there and we have to deal with it. This change decouples the handshake hash from the CertificateVerify hash. This lays the groundwork for advertising support for SHA-384 but doesn't actually make that change in the interests of reviewability. Updating the advertised hash functions will cause changes in many of the testdata/ files and some errors might get lost in the noise. This change only needs to update four testdata/ files: one because a SHA-384-based handshake is now being signed with SHA-256 and the others because the TLS 1.2 CertificateRequest message now includes SHA-1. This change also has the effect of adding support for client-certificates in SSLv3 servers. However, SSLv3 is now disabled by default so this should be moot. It would be possible to avoid much of this change and just support SHA-384 for the ServerKeyExchange as the SKX only signs over the nonces and SKX params (a design mistake in TLS). However, that would leave Go in the odd situation where it advertised support for SHA-384, but would only use the handshake hash when signing client certificates. I fear that'll just cause problems in the future. Much of this code was written by davidben@ for the purposes of testing BoringSSL. Partly addresses #9757 Change-Id: I5137a472b6076812af387a5a69fc62c7373cd485 Reviewed-on: https://go-review.googlesource.com/9415 Run-TryBot: Adam Langley <agl@golang.org> Reviewed-by: Adam Langley <agl@golang.org>
il y a 9 ans
crypto/tls: decouple handshake signatures from the handshake hash. Prior to TLS 1.2, the handshake had a pleasing property that one could incrementally hash it and, from that, get the needed hashes for both the CertificateVerify and Finished messages. TLS 1.2 introduced negotiation for the signature and hash and it became possible for the handshake hash to be, say, SHA-384, but for the CertificateVerify to sign the handshake with SHA-1. The problem is that one doesn't know in advance which hashes will be needed and thus the handshake needs to be buffered. Go ignored this, always kept a single handshake hash, and any signatures over the handshake had to use that hash. However, there are a set of servers that inspect the client's offered signature hash functions and will abort the handshake if one of the server's certificates is signed with a hash function outside of that set. https://robertsspaceindustries.com/ is an example of such a server. Clearly not a lot of thought happened when that server code was written, but its out there and we have to deal with it. This change decouples the handshake hash from the CertificateVerify hash. This lays the groundwork for advertising support for SHA-384 but doesn't actually make that change in the interests of reviewability. Updating the advertised hash functions will cause changes in many of the testdata/ files and some errors might get lost in the noise. This change only needs to update four testdata/ files: one because a SHA-384-based handshake is now being signed with SHA-256 and the others because the TLS 1.2 CertificateRequest message now includes SHA-1. This change also has the effect of adding support for client-certificates in SSLv3 servers. However, SSLv3 is now disabled by default so this should be moot. It would be possible to avoid much of this change and just support SHA-384 for the ServerKeyExchange as the SKX only signs over the nonces and SKX params (a design mistake in TLS). However, that would leave Go in the odd situation where it advertised support for SHA-384, but would only use the handshake hash when signing client certificates. I fear that'll just cause problems in the future. Much of this code was written by davidben@ for the purposes of testing BoringSSL. Partly addresses #9757 Change-Id: I5137a472b6076812af387a5a69fc62c7373cd485 Reviewed-on: https://go-review.googlesource.com/9415 Run-TryBot: Adam Langley <agl@golang.org> Reviewed-by: Adam Langley <agl@golang.org>
il y a 9 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. // Copyright 2010 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package tls
  5. import (
  6. "crypto/aes"
  7. "crypto/cipher"
  8. "crypto/des"
  9. "crypto/hmac"
  10. "crypto/rc4"
  11. "crypto/sha1"
  12. "crypto/sha256"
  13. "crypto/x509"
  14. "hash"
  15. )
  16. // a keyAgreement implements the client and server side of a TLS key agreement
  17. // protocol by generating and processing key exchange messages.
  18. type keyAgreement interface {
  19. // On the server side, the first two methods are called in order.
  20. // In the case that the key agreement protocol doesn't use a
  21. // ServerKeyExchange message, generateServerKeyExchange can return nil,
  22. // nil.
  23. generateServerKeyExchange(*Config, *Certificate, *clientHelloMsg, *serverHelloMsg) (*serverKeyExchangeMsg, error)
  24. processClientKeyExchange(*Config, *Certificate, *clientKeyExchangeMsg, uint16) ([]byte, error)
  25. // On the client side, the next two methods are called in order.
  26. // This method may not be called if the server doesn't send a
  27. // ServerKeyExchange message.
  28. processServerKeyExchange(*Config, *clientHelloMsg, *serverHelloMsg, *x509.Certificate, *serverKeyExchangeMsg) error
  29. generateClientKeyExchange(*Config, *clientHelloMsg, *x509.Certificate) ([]byte, *clientKeyExchangeMsg, error)
  30. }
  31. const (
  32. // suiteECDH indicates that the cipher suite involves elliptic curve
  33. // Diffie-Hellman. This means that it should only be selected when the
  34. // client indicates that it supports ECC with a curve and point format
  35. // that we're happy with.
  36. suiteECDHE = 1 << iota
  37. // suiteECDSA indicates that the cipher suite involves an ECDSA
  38. // signature and therefore may only be selected when the server's
  39. // certificate is ECDSA. If this is not set then the cipher suite is
  40. // RSA based.
  41. suiteECDSA
  42. // suiteTLS12 indicates that the cipher suite should only be advertised
  43. // and accepted when using TLS 1.2.
  44. suiteTLS12
  45. // suiteSHA384 indicates that the cipher suite uses SHA384 as the
  46. // handshake hash.
  47. suiteSHA384
  48. // suiteDefaultOff indicates that this cipher suite is not included by
  49. // default.
  50. suiteDefaultOff
  51. )
  52. // A cipherSuite is a specific combination of key agreement, cipher and MAC
  53. // function. All cipher suites currently assume RSA key agreement.
  54. type cipherSuite struct {
  55. id uint16
  56. // the lengths, in bytes, of the key material needed for each component.
  57. keyLen int
  58. macLen int
  59. ivLen int
  60. ka func(version uint16) keyAgreement
  61. // flags is a bitmask of the suite* values, above.
  62. flags int
  63. cipher func(key, iv []byte, isRead bool) interface{}
  64. mac func(version uint16, macKey []byte) macFunction
  65. aead func(key, fixedNonce []byte) cipher.AEAD
  66. }
  67. var cipherSuites = []*cipherSuite{
  68. // Ciphersuite order is chosen so that ECDHE comes before plain RSA and
  69. // GCM is top preference.
  70. {TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, 16, 0, 4, ecdheRSAKA, suiteECDHE | suiteTLS12, nil, nil, aeadAESGCM},
  71. {TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, 16, 0, 4, ecdheECDSAKA, suiteECDHE | suiteECDSA | suiteTLS12, nil, nil, aeadAESGCM},
  72. {TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, 32, 0, 4, ecdheRSAKA, suiteECDHE | suiteTLS12 | suiteSHA384, nil, nil, aeadAESGCM},
  73. {TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, 32, 0, 4, ecdheECDSAKA, suiteECDHE | suiteECDSA | suiteTLS12 | suiteSHA384, nil, nil, aeadAESGCM},
  74. {TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, 16, 32, 16, ecdheRSAKA, suiteECDHE | suiteTLS12, cipherAES, macSHA256, nil},
  75. {TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, 16, 20, 16, ecdheRSAKA, suiteECDHE, cipherAES, macSHA1, nil},
  76. {TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, 16, 32, 16, ecdheECDSAKA, suiteECDHE | suiteECDSA | suiteTLS12, cipherAES, macSHA256, nil},
  77. {TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, 16, 20, 16, ecdheECDSAKA, suiteECDHE | suiteECDSA, cipherAES, macSHA1, nil},
  78. {TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, 32, 20, 16, ecdheRSAKA, suiteECDHE, cipherAES, macSHA1, nil},
  79. {TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, 32, 20, 16, ecdheECDSAKA, suiteECDHE | suiteECDSA, cipherAES, macSHA1, nil},
  80. {TLS_RSA_WITH_AES_128_GCM_SHA256, 16, 0, 4, rsaKA, suiteTLS12, nil, nil, aeadAESGCM},
  81. {TLS_RSA_WITH_AES_256_GCM_SHA384, 32, 0, 4, rsaKA, suiteTLS12 | suiteSHA384, nil, nil, aeadAESGCM},
  82. {TLS_RSA_WITH_AES_128_CBC_SHA256, 16, 32, 16, rsaKA, suiteTLS12, cipherAES, macSHA256, nil},
  83. {TLS_RSA_WITH_AES_128_CBC_SHA, 16, 20, 16, rsaKA, 0, cipherAES, macSHA1, nil},
  84. {TLS_RSA_WITH_AES_256_CBC_SHA, 32, 20, 16, rsaKA, 0, cipherAES, macSHA1, nil},
  85. {TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, 24, 20, 8, ecdheRSAKA, suiteECDHE, cipher3DES, macSHA1, nil},
  86. {TLS_RSA_WITH_3DES_EDE_CBC_SHA, 24, 20, 8, rsaKA, 0, cipher3DES, macSHA1, nil},
  87. // RC4-based cipher suites are disabled by default.
  88. {TLS_RSA_WITH_RC4_128_SHA, 16, 20, 0, rsaKA, suiteDefaultOff, cipherRC4, macSHA1, nil},
  89. {TLS_ECDHE_RSA_WITH_RC4_128_SHA, 16, 20, 0, ecdheRSAKA, suiteECDHE | suiteDefaultOff, cipherRC4, macSHA1, nil},
  90. {TLS_ECDHE_ECDSA_WITH_RC4_128_SHA, 16, 20, 0, ecdheECDSAKA, suiteECDHE | suiteECDSA | suiteDefaultOff, cipherRC4, macSHA1, nil},
  91. }
  92. func cipherRC4(key, iv []byte, isRead bool) interface{} {
  93. cipher, _ := rc4.NewCipher(key)
  94. return cipher
  95. }
  96. func cipher3DES(key, iv []byte, isRead bool) interface{} {
  97. block, _ := des.NewTripleDESCipher(key)
  98. if isRead {
  99. return cipher.NewCBCDecrypter(block, iv)
  100. }
  101. return cipher.NewCBCEncrypter(block, iv)
  102. }
  103. func cipherAES(key, iv []byte, isRead bool) interface{} {
  104. block, _ := aes.NewCipher(key)
  105. if isRead {
  106. return cipher.NewCBCDecrypter(block, iv)
  107. }
  108. return cipher.NewCBCEncrypter(block, iv)
  109. }
  110. // macSHA1 returns a macFunction for the given protocol version.
  111. func macSHA1(version uint16, key []byte) macFunction {
  112. if version == VersionSSL30 {
  113. mac := ssl30MAC{
  114. h: sha1.New(),
  115. key: make([]byte, len(key)),
  116. }
  117. copy(mac.key, key)
  118. return mac
  119. }
  120. return tls10MAC{hmac.New(sha1.New, key)}
  121. }
  122. // macSHA256 returns a SHA-256 based MAC. These are only supported in TLS 1.2
  123. // so the given version is ignored.
  124. func macSHA256(version uint16, key []byte) macFunction {
  125. return tls10MAC{hmac.New(sha256.New, key)}
  126. }
  127. type macFunction interface {
  128. Size() int
  129. MAC(digestBuf, seq, header, data []byte) []byte
  130. }
  131. // fixedNonceAEAD wraps an AEAD and prefixes a fixed portion of the nonce to
  132. // each call.
  133. type fixedNonceAEAD struct {
  134. // sealNonce and openNonce are buffers where the larger nonce will be
  135. // constructed. Since a seal and open operation may be running
  136. // concurrently, there is a separate buffer for each.
  137. sealNonce, openNonce []byte
  138. aead cipher.AEAD
  139. }
  140. func (f *fixedNonceAEAD) NonceSize() int { return 8 }
  141. func (f *fixedNonceAEAD) Overhead() int { return f.aead.Overhead() }
  142. func (f *fixedNonceAEAD) Seal(out, nonce, plaintext, additionalData []byte) []byte {
  143. copy(f.sealNonce[len(f.sealNonce)-8:], nonce)
  144. return f.aead.Seal(out, f.sealNonce, plaintext, additionalData)
  145. }
  146. func (f *fixedNonceAEAD) Open(out, nonce, plaintext, additionalData []byte) ([]byte, error) {
  147. copy(f.openNonce[len(f.openNonce)-8:], nonce)
  148. return f.aead.Open(out, f.openNonce, plaintext, additionalData)
  149. }
  150. func aeadAESGCM(key, fixedNonce []byte) cipher.AEAD {
  151. aes, err := aes.NewCipher(key)
  152. if err != nil {
  153. panic(err)
  154. }
  155. aead, err := cipher.NewGCM(aes)
  156. if err != nil {
  157. panic(err)
  158. }
  159. nonce1, nonce2 := make([]byte, 12), make([]byte, 12)
  160. copy(nonce1, fixedNonce)
  161. copy(nonce2, fixedNonce)
  162. return &fixedNonceAEAD{nonce1, nonce2, aead}
  163. }
  164. // ssl30MAC implements the SSLv3 MAC function, as defined in
  165. // www.mozilla.org/projects/security/pki/nss/ssl/draft302.txt section 5.2.3.1
  166. type ssl30MAC struct {
  167. h hash.Hash
  168. key []byte
  169. }
  170. func (s ssl30MAC) Size() int {
  171. return s.h.Size()
  172. }
  173. var ssl30Pad1 = [48]byte{0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36}
  174. var ssl30Pad2 = [48]byte{0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c}
  175. func (s ssl30MAC) MAC(digestBuf, seq, header, data []byte) []byte {
  176. padLength := 48
  177. if s.h.Size() == 20 {
  178. padLength = 40
  179. }
  180. s.h.Reset()
  181. s.h.Write(s.key)
  182. s.h.Write(ssl30Pad1[:padLength])
  183. s.h.Write(seq)
  184. s.h.Write(header[:1])
  185. s.h.Write(header[3:5])
  186. s.h.Write(data)
  187. digestBuf = s.h.Sum(digestBuf[:0])
  188. s.h.Reset()
  189. s.h.Write(s.key)
  190. s.h.Write(ssl30Pad2[:padLength])
  191. s.h.Write(digestBuf)
  192. return s.h.Sum(digestBuf[:0])
  193. }
  194. // tls10MAC implements the TLS 1.0 MAC function. RFC 2246, section 6.2.3.
  195. type tls10MAC struct {
  196. h hash.Hash
  197. }
  198. func (s tls10MAC) Size() int {
  199. return s.h.Size()
  200. }
  201. func (s tls10MAC) MAC(digestBuf, seq, header, data []byte) []byte {
  202. s.h.Reset()
  203. s.h.Write(seq)
  204. s.h.Write(header)
  205. s.h.Write(data)
  206. return s.h.Sum(digestBuf[:0])
  207. }
  208. func rsaKA(version uint16) keyAgreement {
  209. return rsaKeyAgreement{}
  210. }
  211. func ecdheECDSAKA(version uint16) keyAgreement {
  212. return &ecdheKeyAgreement{
  213. sigType: signatureECDSA,
  214. version: version,
  215. }
  216. }
  217. func ecdheRSAKA(version uint16) keyAgreement {
  218. return &ecdheKeyAgreement{
  219. sigType: signatureRSA,
  220. version: version,
  221. }
  222. }
  223. // mutualCipherSuite returns a cipherSuite given a list of supported
  224. // ciphersuites and the id requested by the peer.
  225. func mutualCipherSuite(have []uint16, want uint16) *cipherSuite {
  226. for _, id := range have {
  227. if id == want {
  228. for _, suite := range cipherSuites {
  229. if suite.id == want {
  230. return suite
  231. }
  232. }
  233. return nil
  234. }
  235. }
  236. return nil
  237. }
  238. // A list of cipher suite IDs that are, or have been, implemented by this
  239. // package.
  240. //
  241. // Taken from http://www.iana.org/assignments/tls-parameters/tls-parameters.xml
  242. const (
  243. TLS_RSA_WITH_RC4_128_SHA uint16 = 0x0005
  244. TLS_RSA_WITH_3DES_EDE_CBC_SHA uint16 = 0x000a
  245. TLS_RSA_WITH_AES_128_CBC_SHA uint16 = 0x002f
  246. TLS_RSA_WITH_AES_256_CBC_SHA uint16 = 0x0035
  247. TLS_RSA_WITH_AES_128_CBC_SHA256 uint16 = 0x003c
  248. TLS_RSA_WITH_AES_128_GCM_SHA256 uint16 = 0x009c
  249. TLS_RSA_WITH_AES_256_GCM_SHA384 uint16 = 0x009d
  250. TLS_ECDHE_ECDSA_WITH_RC4_128_SHA uint16 = 0xc007
  251. TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA uint16 = 0xc009
  252. TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA uint16 = 0xc00a
  253. TLS_ECDHE_RSA_WITH_RC4_128_SHA uint16 = 0xc011
  254. TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA uint16 = 0xc012
  255. TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA uint16 = 0xc013
  256. TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA uint16 = 0xc014
  257. TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 uint16 = 0xc023
  258. TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 uint16 = 0xc027
  259. TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 uint16 = 0xc02f
  260. TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 uint16 = 0xc02b
  261. TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 uint16 = 0xc030
  262. TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 uint16 = 0xc02c
  263. // TLS_FALLBACK_SCSV isn't a standard cipher suite but an indicator
  264. // that the client is doing version fallback. See
  265. // https://tools.ietf.org/html/rfc7507.
  266. TLS_FALLBACK_SCSV uint16 = 0x5600
  267. )