Adam Langley | dc7e9c4 | 2015-09-29 15:21:04 -0700 | [diff] [blame] | 1 | package runner |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2 | |
| 3 | import ( |
| 4 | "bytes" |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 5 | "crypto/ecdsa" |
| 6 | "crypto/elliptic" |
David Benjamin | 407a10c | 2014-07-16 12:58:59 -0400 | [diff] [blame] | 7 | "crypto/x509" |
David Benjamin | 2561dc3 | 2014-08-24 01:25:27 -0400 | [diff] [blame] | 8 | "encoding/base64" |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 9 | "encoding/pem" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 10 | "flag" |
| 11 | "fmt" |
| 12 | "io" |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 13 | "io/ioutil" |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 14 | "math/big" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 15 | "net" |
| 16 | "os" |
| 17 | "os/exec" |
David Benjamin | 884fdf1 | 2014-08-02 15:28:23 -0400 | [diff] [blame] | 18 | "path" |
David Benjamin | 2bc8e6f | 2014-08-02 15:22:37 -0400 | [diff] [blame] | 19 | "runtime" |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 20 | "strconv" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 21 | "strings" |
| 22 | "sync" |
| 23 | "syscall" |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 24 | "time" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 25 | ) |
| 26 | |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 27 | var ( |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 28 | useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind") |
| 29 | useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb") |
David Benjamin | d16bf34 | 2015-12-18 00:53:12 -0500 | [diff] [blame] | 30 | useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb") |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 31 | flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection") |
| 32 | mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.") |
| 33 | mallocTestDebug = flag.Bool("malloc-test-debug", false, "If true, ask bssl_shim to abort rather than fail a malloc. This can be used with a specific value for --malloc-test to identity the malloc failing that is causing problems.") |
| 34 | jsonOutput = flag.String("json-output", "", "The file to output JSON results to.") |
| 35 | pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.") |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 36 | testToRun = flag.String("test", "", "The name of a test to run, or empty to run all tests") |
| 37 | numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.") |
| 38 | shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.") |
| 39 | resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.") |
David Benjamin | f2b8363 | 2016-03-01 22:57:46 -0500 | [diff] [blame] | 40 | fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.") |
David Benjamin | 9867b7d | 2016-03-01 23:25:48 -0500 | [diff] [blame] | 41 | transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.") |
David Benjamin | 3ed5977 | 2016-03-08 12:50:21 -0500 | [diff] [blame] | 42 | timeout = flag.Int("timeout", 15, "The number of seconds to wait for a read or write to bssl_shim.") |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 43 | ) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 44 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 45 | const ( |
| 46 | rsaCertificateFile = "cert.pem" |
| 47 | ecdsaCertificateFile = "ecdsa_cert.pem" |
| 48 | ) |
| 49 | |
| 50 | const ( |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 51 | rsaKeyFile = "key.pem" |
| 52 | ecdsaKeyFile = "ecdsa_key.pem" |
| 53 | channelIDKeyFile = "channel_id_key.pem" |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 54 | ) |
| 55 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 56 | var rsaCertificate, ecdsaCertificate Certificate |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 57 | var channelIDKey *ecdsa.PrivateKey |
| 58 | var channelIDBytes []byte |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 59 | |
David Benjamin | 61f9527 | 2014-11-25 01:55:35 -0500 | [diff] [blame] | 60 | var testOCSPResponse = []byte{1, 2, 3, 4} |
| 61 | var testSCTList = []byte{5, 6, 7, 8} |
| 62 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 63 | func initCertificates() { |
| 64 | var err error |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 65 | rsaCertificate, err = LoadX509KeyPair(path.Join(*resourceDir, rsaCertificateFile), path.Join(*resourceDir, rsaKeyFile)) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 66 | if err != nil { |
| 67 | panic(err) |
| 68 | } |
David Benjamin | 61f9527 | 2014-11-25 01:55:35 -0500 | [diff] [blame] | 69 | rsaCertificate.OCSPStaple = testOCSPResponse |
| 70 | rsaCertificate.SignedCertificateTimestampList = testSCTList |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 71 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 72 | ecdsaCertificate, err = LoadX509KeyPair(path.Join(*resourceDir, ecdsaCertificateFile), path.Join(*resourceDir, ecdsaKeyFile)) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 73 | if err != nil { |
| 74 | panic(err) |
| 75 | } |
David Benjamin | 61f9527 | 2014-11-25 01:55:35 -0500 | [diff] [blame] | 76 | ecdsaCertificate.OCSPStaple = testOCSPResponse |
| 77 | ecdsaCertificate.SignedCertificateTimestampList = testSCTList |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 78 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 79 | channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile)) |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 80 | if err != nil { |
| 81 | panic(err) |
| 82 | } |
| 83 | channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock) |
| 84 | if channelIDDERBlock.Type != "EC PRIVATE KEY" { |
| 85 | panic("bad key type") |
| 86 | } |
| 87 | channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes) |
| 88 | if err != nil { |
| 89 | panic(err) |
| 90 | } |
| 91 | if channelIDKey.Curve != elliptic.P256() { |
| 92 | panic("bad curve") |
| 93 | } |
| 94 | |
| 95 | channelIDBytes = make([]byte, 64) |
| 96 | writeIntPadded(channelIDBytes[:32], channelIDKey.X) |
| 97 | writeIntPadded(channelIDBytes[32:], channelIDKey.Y) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | var certificateOnce sync.Once |
| 101 | |
| 102 | func getRSACertificate() Certificate { |
| 103 | certificateOnce.Do(initCertificates) |
| 104 | return rsaCertificate |
| 105 | } |
| 106 | |
| 107 | func getECDSACertificate() Certificate { |
| 108 | certificateOnce.Do(initCertificates) |
| 109 | return ecdsaCertificate |
| 110 | } |
| 111 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 112 | type testType int |
| 113 | |
| 114 | const ( |
| 115 | clientTest testType = iota |
| 116 | serverTest |
| 117 | ) |
| 118 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 119 | type protocol int |
| 120 | |
| 121 | const ( |
| 122 | tls protocol = iota |
| 123 | dtls |
| 124 | ) |
| 125 | |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 126 | const ( |
| 127 | alpn = 1 |
| 128 | npn = 2 |
| 129 | ) |
| 130 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 131 | type testCase struct { |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 132 | testType testType |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 133 | protocol protocol |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 134 | name string |
| 135 | config Config |
| 136 | shouldFail bool |
| 137 | expectedError string |
Adam Langley | ac61fa3 | 2014-06-23 12:03:11 -0700 | [diff] [blame] | 138 | // expectedLocalError, if not empty, contains a substring that must be |
| 139 | // found in the local error. |
| 140 | expectedLocalError string |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 141 | // expectedVersion, if non-zero, specifies the TLS version that must be |
| 142 | // negotiated. |
| 143 | expectedVersion uint16 |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 144 | // expectedResumeVersion, if non-zero, specifies the TLS version that |
| 145 | // must be negotiated on resumption. If zero, expectedVersion is used. |
| 146 | expectedResumeVersion uint16 |
David Benjamin | 90da8c8 | 2015-04-20 14:57:57 -0400 | [diff] [blame] | 147 | // expectedCipher, if non-zero, specifies the TLS cipher suite that |
| 148 | // should be negotiated. |
| 149 | expectedCipher uint16 |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 150 | // expectChannelID controls whether the connection should have |
| 151 | // negotiated a Channel ID with channelIDKey. |
| 152 | expectChannelID bool |
David Benjamin | ae2888f | 2014-09-06 12:58:58 -0400 | [diff] [blame] | 153 | // expectedNextProto controls whether the connection should |
| 154 | // negotiate a next protocol via NPN or ALPN. |
| 155 | expectedNextProto string |
David Benjamin | c7ce977 | 2015-10-09 19:32:41 -0400 | [diff] [blame] | 156 | // expectNoNextProto, if true, means that no next protocol should be |
| 157 | // negotiated. |
| 158 | expectNoNextProto bool |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 159 | // expectedNextProtoType, if non-zero, is the expected next |
| 160 | // protocol negotiation mechanism. |
| 161 | expectedNextProtoType int |
David Benjamin | ca6c826 | 2014-11-15 19:06:08 -0500 | [diff] [blame] | 162 | // expectedSRTPProtectionProfile is the DTLS-SRTP profile that |
| 163 | // should be negotiated. If zero, none should be negotiated. |
| 164 | expectedSRTPProtectionProfile uint16 |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 165 | // expectedOCSPResponse, if not nil, is the expected OCSP response to be received. |
| 166 | expectedOCSPResponse []uint8 |
Paul Lietar | 4fac72e | 2015-09-09 13:44:55 +0100 | [diff] [blame] | 167 | // expectedSCTList, if not nil, is the expected SCT list to be received. |
| 168 | expectedSCTList []uint8 |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 169 | // expectedClientCertSignatureHash, if not zero, is the TLS id of the |
| 170 | // hash function that the client should have used when signing the |
| 171 | // handshake with a client certificate. |
| 172 | expectedClientCertSignatureHash uint8 |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 173 | // messageLen is the length, in bytes, of the test message that will be |
| 174 | // sent. |
| 175 | messageLen int |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 176 | // messageCount is the number of test messages that will be sent. |
| 177 | messageCount int |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 178 | // digestPrefs is the list of digest preferences from the client. |
| 179 | digestPrefs string |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 180 | // certFile is the path to the certificate to use for the server. |
| 181 | certFile string |
| 182 | // keyFile is the path to the private key to use for the server. |
| 183 | keyFile string |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 184 | // resumeSession controls whether a second connection should be tested |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 185 | // which attempts to resume the first session. |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 186 | resumeSession bool |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 187 | // expectResumeRejected, if true, specifies that the attempted |
| 188 | // resumption must be rejected by the client. This is only valid for a |
| 189 | // serverTest. |
| 190 | expectResumeRejected bool |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 191 | // resumeConfig, if not nil, points to a Config to be used on |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 192 | // resumption. Unless newSessionsOnResume is set, |
| 193 | // SessionTicketKey, ServerSessionCache, and |
| 194 | // ClientSessionCache are copied from the initial connection's |
| 195 | // config. If nil, the initial connection's config is used. |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 196 | resumeConfig *Config |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 197 | // newSessionsOnResume, if true, will cause resumeConfig to |
| 198 | // use a different session resumption context. |
| 199 | newSessionsOnResume bool |
David Benjamin | ba4594a | 2015-06-18 18:36:15 -0400 | [diff] [blame] | 200 | // noSessionCache, if true, will cause the server to run without a |
| 201 | // session cache. |
| 202 | noSessionCache bool |
David Benjamin | 98e882e | 2014-08-08 13:24:34 -0400 | [diff] [blame] | 203 | // sendPrefix sends a prefix on the socket before actually performing a |
| 204 | // handshake. |
| 205 | sendPrefix string |
David Benjamin | e58c4f5 | 2014-08-24 03:47:07 -0400 | [diff] [blame] | 206 | // shimWritesFirst controls whether the shim sends an initial "hello" |
| 207 | // message before doing a roundtrip with the runner. |
| 208 | shimWritesFirst bool |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 209 | // shimShutsDown, if true, runs a test where the shim shuts down the |
| 210 | // connection immediately after the handshake rather than echoing |
| 211 | // messages from the runner. |
| 212 | shimShutsDown bool |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 213 | // renegotiate indicates the number of times the connection should be |
| 214 | // renegotiated during the exchange. |
| 215 | renegotiate int |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 216 | // renegotiateCiphers is a list of ciphersuite ids that will be |
| 217 | // switched in just before renegotiation. |
| 218 | renegotiateCiphers []uint16 |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 219 | // replayWrites, if true, configures the underlying transport |
| 220 | // to replay every write it makes in DTLS tests. |
| 221 | replayWrites bool |
David Benjamin | 5fa3eba | 2015-01-22 16:35:40 -0500 | [diff] [blame] | 222 | // damageFirstWrite, if true, configures the underlying transport to |
| 223 | // damage the final byte of the first application data write. |
| 224 | damageFirstWrite bool |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 225 | // exportKeyingMaterial, if non-zero, configures the test to exchange |
| 226 | // keying material and verify they match. |
| 227 | exportKeyingMaterial int |
| 228 | exportLabel string |
| 229 | exportContext string |
| 230 | useExportContext bool |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 231 | // flags, if not empty, contains a list of command-line flags that will |
| 232 | // be passed to the shim program. |
| 233 | flags []string |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 234 | // testTLSUnique, if true, causes the shim to send the tls-unique value |
| 235 | // which will be compared against the expected value. |
| 236 | testTLSUnique bool |
David Benjamin | a8ebe22 | 2015-06-06 03:04:39 -0400 | [diff] [blame] | 237 | // sendEmptyRecords is the number of consecutive empty records to send |
| 238 | // before and after the test message. |
| 239 | sendEmptyRecords int |
David Benjamin | 24f346d | 2015-06-06 03:28:08 -0400 | [diff] [blame] | 240 | // sendWarningAlerts is the number of consecutive warning alerts to send |
| 241 | // before and after the test message. |
| 242 | sendWarningAlerts int |
David Benjamin | 4f75aaf | 2015-09-01 16:53:10 -0400 | [diff] [blame] | 243 | // expectMessageDropped, if true, means the test message is expected to |
| 244 | // be dropped by the client rather than echoed back. |
| 245 | expectMessageDropped bool |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 246 | } |
| 247 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 248 | var testCases []testCase |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 249 | |
David Benjamin | 9867b7d | 2016-03-01 23:25:48 -0500 | [diff] [blame] | 250 | func writeTranscript(test *testCase, isResume bool, data []byte) { |
| 251 | if len(data) == 0 { |
| 252 | return |
| 253 | } |
| 254 | |
| 255 | protocol := "tls" |
| 256 | if test.protocol == dtls { |
| 257 | protocol = "dtls" |
| 258 | } |
| 259 | |
| 260 | side := "client" |
| 261 | if test.testType == serverTest { |
| 262 | side = "server" |
| 263 | } |
| 264 | |
| 265 | dir := path.Join(*transcriptDir, protocol, side) |
| 266 | if err := os.MkdirAll(dir, 0755); err != nil { |
| 267 | fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err) |
| 268 | return |
| 269 | } |
| 270 | |
| 271 | name := test.name |
| 272 | if isResume { |
| 273 | name += "-Resume" |
| 274 | } else { |
| 275 | name += "-Normal" |
| 276 | } |
| 277 | |
| 278 | if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil { |
| 279 | fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err) |
| 280 | } |
| 281 | } |
| 282 | |
David Benjamin | 3ed5977 | 2016-03-08 12:50:21 -0500 | [diff] [blame] | 283 | // A timeoutConn implements an idle timeout on each Read and Write operation. |
| 284 | type timeoutConn struct { |
| 285 | net.Conn |
| 286 | timeout time.Duration |
| 287 | } |
| 288 | |
| 289 | func (t *timeoutConn) Read(b []byte) (int, error) { |
| 290 | if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil { |
| 291 | return 0, err |
| 292 | } |
| 293 | return t.Conn.Read(b) |
| 294 | } |
| 295 | |
| 296 | func (t *timeoutConn) Write(b []byte) (int, error) { |
| 297 | if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil { |
| 298 | return 0, err |
| 299 | } |
| 300 | return t.Conn.Write(b) |
| 301 | } |
| 302 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 303 | func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool) error { |
David Benjamin | 3ed5977 | 2016-03-08 12:50:21 -0500 | [diff] [blame] | 304 | conn = &timeoutConn{conn, time.Duration(*timeout) * time.Second} |
David Benjamin | 65ea8ff | 2014-11-23 03:01:00 -0500 | [diff] [blame] | 305 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 306 | if test.protocol == dtls { |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 307 | config.Bugs.PacketAdaptor = newPacketAdaptor(conn) |
| 308 | conn = config.Bugs.PacketAdaptor |
David Benjamin | ebda9b3 | 2015-11-02 15:33:18 -0500 | [diff] [blame] | 309 | } |
| 310 | |
David Benjamin | 9867b7d | 2016-03-01 23:25:48 -0500 | [diff] [blame] | 311 | if *flagDebug || len(*transcriptDir) != 0 { |
David Benjamin | ebda9b3 | 2015-11-02 15:33:18 -0500 | [diff] [blame] | 312 | local, peer := "client", "server" |
| 313 | if test.testType == clientTest { |
| 314 | local, peer = peer, local |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 315 | } |
David Benjamin | ebda9b3 | 2015-11-02 15:33:18 -0500 | [diff] [blame] | 316 | connDebug := &recordingConn{ |
| 317 | Conn: conn, |
| 318 | isDatagram: test.protocol == dtls, |
| 319 | local: local, |
| 320 | peer: peer, |
| 321 | } |
| 322 | conn = connDebug |
David Benjamin | 9867b7d | 2016-03-01 23:25:48 -0500 | [diff] [blame] | 323 | if *flagDebug { |
| 324 | defer connDebug.WriteTo(os.Stdout) |
| 325 | } |
| 326 | if len(*transcriptDir) != 0 { |
| 327 | defer func() { |
| 328 | writeTranscript(test, isResume, connDebug.Transcript()) |
| 329 | }() |
| 330 | } |
David Benjamin | ebda9b3 | 2015-11-02 15:33:18 -0500 | [diff] [blame] | 331 | |
| 332 | if config.Bugs.PacketAdaptor != nil { |
| 333 | config.Bugs.PacketAdaptor.debug = connDebug |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | if test.replayWrites { |
| 338 | conn = newReplayAdaptor(conn) |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 339 | } |
| 340 | |
David Benjamin | 3ed5977 | 2016-03-08 12:50:21 -0500 | [diff] [blame] | 341 | var connDamage *damageAdaptor |
David Benjamin | 5fa3eba | 2015-01-22 16:35:40 -0500 | [diff] [blame] | 342 | if test.damageFirstWrite { |
| 343 | connDamage = newDamageAdaptor(conn) |
| 344 | conn = connDamage |
| 345 | } |
| 346 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 347 | if test.sendPrefix != "" { |
| 348 | if _, err := conn.Write([]byte(test.sendPrefix)); err != nil { |
| 349 | return err |
| 350 | } |
David Benjamin | 98e882e | 2014-08-08 13:24:34 -0400 | [diff] [blame] | 351 | } |
| 352 | |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 353 | var tlsConn *Conn |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 354 | if test.testType == clientTest { |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 355 | if test.protocol == dtls { |
| 356 | tlsConn = DTLSServer(conn, config) |
| 357 | } else { |
| 358 | tlsConn = Server(conn, config) |
| 359 | } |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 360 | } else { |
| 361 | config.InsecureSkipVerify = true |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 362 | if test.protocol == dtls { |
| 363 | tlsConn = DTLSClient(conn, config) |
| 364 | } else { |
| 365 | tlsConn = Client(conn, config) |
| 366 | } |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 367 | } |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 368 | defer tlsConn.Close() |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 369 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 370 | if err := tlsConn.Handshake(); err != nil { |
| 371 | return err |
| 372 | } |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 373 | |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 374 | // TODO(davidben): move all per-connection expectations into a dedicated |
| 375 | // expectations struct that can be specified separately for the two |
| 376 | // legs. |
| 377 | expectedVersion := test.expectedVersion |
| 378 | if isResume && test.expectedResumeVersion != 0 { |
| 379 | expectedVersion = test.expectedResumeVersion |
| 380 | } |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 381 | connState := tlsConn.ConnectionState() |
| 382 | if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion { |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 383 | return fmt.Errorf("got version %x, expected %x", vers, expectedVersion) |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 384 | } |
| 385 | |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 386 | if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher { |
David Benjamin | 90da8c8 | 2015-04-20 14:57:57 -0400 | [diff] [blame] | 387 | return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher) |
| 388 | } |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 389 | if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected { |
| 390 | return fmt.Errorf("didResume is %t, but we expected the opposite", didResume) |
| 391 | } |
David Benjamin | 90da8c8 | 2015-04-20 14:57:57 -0400 | [diff] [blame] | 392 | |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 393 | if test.expectChannelID { |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 394 | channelID := connState.ChannelID |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 395 | if channelID == nil { |
| 396 | return fmt.Errorf("no channel ID negotiated") |
| 397 | } |
| 398 | if channelID.Curve != channelIDKey.Curve || |
| 399 | channelIDKey.X.Cmp(channelIDKey.X) != 0 || |
| 400 | channelIDKey.Y.Cmp(channelIDKey.Y) != 0 { |
| 401 | return fmt.Errorf("incorrect channel ID") |
| 402 | } |
| 403 | } |
| 404 | |
David Benjamin | ae2888f | 2014-09-06 12:58:58 -0400 | [diff] [blame] | 405 | if expected := test.expectedNextProto; expected != "" { |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 406 | if actual := connState.NegotiatedProtocol; actual != expected { |
David Benjamin | ae2888f | 2014-09-06 12:58:58 -0400 | [diff] [blame] | 407 | return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected) |
| 408 | } |
| 409 | } |
| 410 | |
David Benjamin | c7ce977 | 2015-10-09 19:32:41 -0400 | [diff] [blame] | 411 | if test.expectNoNextProto { |
| 412 | if actual := connState.NegotiatedProtocol; actual != "" { |
| 413 | return fmt.Errorf("got unexpected next proto %s", actual) |
| 414 | } |
| 415 | } |
| 416 | |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 417 | if test.expectedNextProtoType != 0 { |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 418 | if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN { |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 419 | return fmt.Errorf("next proto type mismatch") |
| 420 | } |
| 421 | } |
| 422 | |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 423 | if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile { |
David Benjamin | ca6c826 | 2014-11-15 19:06:08 -0500 | [diff] [blame] | 424 | return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile) |
| 425 | } |
| 426 | |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 427 | if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) { |
| 428 | return fmt.Errorf("OCSP Response mismatch") |
| 429 | } |
| 430 | |
Paul Lietar | 4fac72e | 2015-09-09 13:44:55 +0100 | [diff] [blame] | 431 | if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) { |
| 432 | return fmt.Errorf("SCT list mismatch") |
| 433 | } |
| 434 | |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 435 | if expected := test.expectedClientCertSignatureHash; expected != 0 && expected != connState.ClientCertSignatureHash { |
| 436 | return fmt.Errorf("expected client to sign handshake with hash %d, but got %d", expected, connState.ClientCertSignatureHash) |
| 437 | } |
| 438 | |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 439 | if test.exportKeyingMaterial > 0 { |
| 440 | actual := make([]byte, test.exportKeyingMaterial) |
| 441 | if _, err := io.ReadFull(tlsConn, actual); err != nil { |
| 442 | return err |
| 443 | } |
| 444 | expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext) |
| 445 | if err != nil { |
| 446 | return err |
| 447 | } |
| 448 | if !bytes.Equal(actual, expected) { |
| 449 | return fmt.Errorf("keying material mismatch") |
| 450 | } |
| 451 | } |
| 452 | |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 453 | if test.testTLSUnique { |
| 454 | var peersValue [12]byte |
| 455 | if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil { |
| 456 | return err |
| 457 | } |
| 458 | expected := tlsConn.ConnectionState().TLSUnique |
| 459 | if !bytes.Equal(peersValue[:], expected) { |
| 460 | return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected) |
| 461 | } |
| 462 | } |
| 463 | |
David Benjamin | e58c4f5 | 2014-08-24 03:47:07 -0400 | [diff] [blame] | 464 | if test.shimWritesFirst { |
| 465 | var buf [5]byte |
| 466 | _, err := io.ReadFull(tlsConn, buf[:]) |
| 467 | if err != nil { |
| 468 | return err |
| 469 | } |
| 470 | if string(buf[:]) != "hello" { |
| 471 | return fmt.Errorf("bad initial message") |
| 472 | } |
| 473 | } |
| 474 | |
David Benjamin | a8ebe22 | 2015-06-06 03:04:39 -0400 | [diff] [blame] | 475 | for i := 0; i < test.sendEmptyRecords; i++ { |
| 476 | tlsConn.Write(nil) |
| 477 | } |
| 478 | |
David Benjamin | 24f346d | 2015-06-06 03:28:08 -0400 | [diff] [blame] | 479 | for i := 0; i < test.sendWarningAlerts; i++ { |
| 480 | tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage) |
| 481 | } |
| 482 | |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 483 | if test.renegotiate > 0 { |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 484 | if test.renegotiateCiphers != nil { |
| 485 | config.CipherSuites = test.renegotiateCiphers |
| 486 | } |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 487 | for i := 0; i < test.renegotiate; i++ { |
| 488 | if err := tlsConn.Renegotiate(); err != nil { |
| 489 | return err |
| 490 | } |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 491 | } |
| 492 | } else if test.renegotiateCiphers != nil { |
| 493 | panic("renegotiateCiphers without renegotiate") |
| 494 | } |
| 495 | |
David Benjamin | 5fa3eba | 2015-01-22 16:35:40 -0500 | [diff] [blame] | 496 | if test.damageFirstWrite { |
| 497 | connDamage.setDamage(true) |
| 498 | tlsConn.Write([]byte("DAMAGED WRITE")) |
| 499 | connDamage.setDamage(false) |
| 500 | } |
| 501 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 502 | messageLen := test.messageLen |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 503 | if messageLen < 0 { |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 504 | if test.protocol == dtls { |
| 505 | return fmt.Errorf("messageLen < 0 not supported for DTLS tests") |
| 506 | } |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 507 | // Read until EOF. |
| 508 | _, err := io.Copy(ioutil.Discard, tlsConn) |
| 509 | return err |
| 510 | } |
David Benjamin | 4417d05 | 2015-04-05 04:17:25 -0400 | [diff] [blame] | 511 | if messageLen == 0 { |
| 512 | messageLen = 32 |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 513 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 514 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 515 | messageCount := test.messageCount |
| 516 | if messageCount == 0 { |
| 517 | messageCount = 1 |
David Benjamin | a8ebe22 | 2015-06-06 03:04:39 -0400 | [diff] [blame] | 518 | } |
| 519 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 520 | for j := 0; j < messageCount; j++ { |
| 521 | testMessage := make([]byte, messageLen) |
| 522 | for i := range testMessage { |
| 523 | testMessage[i] = 0x42 ^ byte(j) |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 524 | } |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 525 | tlsConn.Write(testMessage) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 526 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 527 | for i := 0; i < test.sendEmptyRecords; i++ { |
| 528 | tlsConn.Write(nil) |
| 529 | } |
| 530 | |
| 531 | for i := 0; i < test.sendWarningAlerts; i++ { |
| 532 | tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage) |
| 533 | } |
| 534 | |
David Benjamin | 4f75aaf | 2015-09-01 16:53:10 -0400 | [diff] [blame] | 535 | if test.shimShutsDown || test.expectMessageDropped { |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 536 | // The shim will not respond. |
| 537 | continue |
| 538 | } |
| 539 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 540 | buf := make([]byte, len(testMessage)) |
| 541 | if test.protocol == dtls { |
| 542 | bufTmp := make([]byte, len(buf)+1) |
| 543 | n, err := tlsConn.Read(bufTmp) |
| 544 | if err != nil { |
| 545 | return err |
| 546 | } |
| 547 | if n != len(buf) { |
| 548 | return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf)) |
| 549 | } |
| 550 | copy(buf, bufTmp) |
| 551 | } else { |
| 552 | _, err := io.ReadFull(tlsConn, buf) |
| 553 | if err != nil { |
| 554 | return err |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | for i, v := range buf { |
| 559 | if v != testMessage[i]^0xff { |
| 560 | return fmt.Errorf("bad reply contents at byte %d", i) |
| 561 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 562 | } |
| 563 | } |
| 564 | |
| 565 | return nil |
| 566 | } |
| 567 | |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 568 | func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd { |
| 569 | valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"} |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 570 | if dbAttach { |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 571 | valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p") |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 572 | } |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 573 | valgrindArgs = append(valgrindArgs, path) |
| 574 | valgrindArgs = append(valgrindArgs, args...) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 575 | |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 576 | return exec.Command("valgrind", valgrindArgs...) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 577 | } |
| 578 | |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 579 | func gdbOf(path string, args ...string) *exec.Cmd { |
| 580 | xtermArgs := []string{"-e", "gdb", "--args"} |
| 581 | xtermArgs = append(xtermArgs, path) |
| 582 | xtermArgs = append(xtermArgs, args...) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 583 | |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 584 | return exec.Command("xterm", xtermArgs...) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 585 | } |
| 586 | |
David Benjamin | d16bf34 | 2015-12-18 00:53:12 -0500 | [diff] [blame] | 587 | func lldbOf(path string, args ...string) *exec.Cmd { |
| 588 | xtermArgs := []string{"-e", "lldb", "--"} |
| 589 | xtermArgs = append(xtermArgs, path) |
| 590 | xtermArgs = append(xtermArgs, args...) |
| 591 | |
| 592 | return exec.Command("xterm", xtermArgs...) |
| 593 | } |
| 594 | |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 595 | type moreMallocsError struct{} |
| 596 | |
| 597 | func (moreMallocsError) Error() string { |
| 598 | return "child process did not exhaust all allocation calls" |
| 599 | } |
| 600 | |
| 601 | var errMoreMallocs = moreMallocsError{} |
| 602 | |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 603 | // accept accepts a connection from listener, unless waitChan signals a process |
| 604 | // exit first. |
| 605 | func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) { |
| 606 | type connOrError struct { |
| 607 | conn net.Conn |
| 608 | err error |
| 609 | } |
| 610 | connChan := make(chan connOrError, 1) |
| 611 | go func() { |
| 612 | conn, err := listener.Accept() |
| 613 | connChan <- connOrError{conn, err} |
| 614 | close(connChan) |
| 615 | }() |
| 616 | select { |
| 617 | case result := <-connChan: |
| 618 | return result.conn, result.err |
| 619 | case childErr := <-waitChan: |
| 620 | waitChan <- childErr |
| 621 | return nil, fmt.Errorf("child exited early: %s", childErr) |
| 622 | } |
| 623 | } |
| 624 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 625 | func runTest(test *testCase, shimPath string, mallocNumToFail int64) error { |
Adam Langley | 3831173 | 2014-10-16 19:04:35 -0700 | [diff] [blame] | 626 | if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) { |
| 627 | panic("Error expected without shouldFail in " + test.name) |
| 628 | } |
| 629 | |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 630 | if test.expectResumeRejected && !test.resumeSession { |
| 631 | panic("expectResumeRejected without resumeSession in " + test.name) |
| 632 | } |
| 633 | |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 634 | if test.testType != clientTest && test.expectedClientCertSignatureHash != 0 { |
| 635 | panic("expectedClientCertSignatureHash non-zero with serverTest in " + test.name) |
| 636 | } |
| 637 | |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 638 | listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}}) |
| 639 | if err != nil { |
| 640 | panic(err) |
| 641 | } |
| 642 | defer func() { |
| 643 | if listener != nil { |
| 644 | listener.Close() |
| 645 | } |
| 646 | }() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 647 | |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 648 | flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)} |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 649 | if test.testType == serverTest { |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 650 | flags = append(flags, "-server") |
| 651 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 652 | flags = append(flags, "-key-file") |
| 653 | if test.keyFile == "" { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 654 | flags = append(flags, path.Join(*resourceDir, rsaKeyFile)) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 655 | } else { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 656 | flags = append(flags, path.Join(*resourceDir, test.keyFile)) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | flags = append(flags, "-cert-file") |
| 660 | if test.certFile == "" { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 661 | flags = append(flags, path.Join(*resourceDir, rsaCertificateFile)) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 662 | } else { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 663 | flags = append(flags, path.Join(*resourceDir, test.certFile)) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 664 | } |
| 665 | } |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 666 | |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 667 | if test.digestPrefs != "" { |
| 668 | flags = append(flags, "-digest-prefs") |
| 669 | flags = append(flags, test.digestPrefs) |
| 670 | } |
| 671 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 672 | if test.protocol == dtls { |
| 673 | flags = append(flags, "-dtls") |
| 674 | } |
| 675 | |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 676 | if test.resumeSession { |
| 677 | flags = append(flags, "-resume") |
| 678 | } |
| 679 | |
David Benjamin | e58c4f5 | 2014-08-24 03:47:07 -0400 | [diff] [blame] | 680 | if test.shimWritesFirst { |
| 681 | flags = append(flags, "-shim-writes-first") |
| 682 | } |
| 683 | |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 684 | if test.shimShutsDown { |
| 685 | flags = append(flags, "-shim-shuts-down") |
| 686 | } |
| 687 | |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 688 | if test.exportKeyingMaterial > 0 { |
| 689 | flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial)) |
| 690 | flags = append(flags, "-export-label", test.exportLabel) |
| 691 | flags = append(flags, "-export-context", test.exportContext) |
| 692 | if test.useExportContext { |
| 693 | flags = append(flags, "-use-export-context") |
| 694 | } |
| 695 | } |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 696 | if test.expectResumeRejected { |
| 697 | flags = append(flags, "-expect-session-miss") |
| 698 | } |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 699 | |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 700 | if test.testTLSUnique { |
| 701 | flags = append(flags, "-tls-unique") |
| 702 | } |
| 703 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 704 | flags = append(flags, test.flags...) |
| 705 | |
| 706 | var shim *exec.Cmd |
| 707 | if *useValgrind { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 708 | shim = valgrindOf(false, shimPath, flags...) |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 709 | } else if *useGDB { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 710 | shim = gdbOf(shimPath, flags...) |
David Benjamin | d16bf34 | 2015-12-18 00:53:12 -0500 | [diff] [blame] | 711 | } else if *useLLDB { |
| 712 | shim = lldbOf(shimPath, flags...) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 713 | } else { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 714 | shim = exec.Command(shimPath, flags...) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 715 | } |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 716 | shim.Stdin = os.Stdin |
| 717 | var stdoutBuf, stderrBuf bytes.Buffer |
| 718 | shim.Stdout = &stdoutBuf |
| 719 | shim.Stderr = &stderrBuf |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 720 | if mallocNumToFail >= 0 { |
David Benjamin | 9e128b0 | 2015-02-09 13:13:09 -0500 | [diff] [blame] | 721 | shim.Env = os.Environ() |
| 722 | shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10)) |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 723 | if *mallocTestDebug { |
David Benjamin | 184494d | 2015-06-12 18:23:47 -0400 | [diff] [blame] | 724 | shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1") |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 725 | } |
| 726 | shim.Env = append(shim.Env, "_MALLOC_CHECK=1") |
| 727 | } |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 728 | |
| 729 | if err := shim.Start(); err != nil { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 730 | panic(err) |
| 731 | } |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 732 | waitChan := make(chan error, 1) |
| 733 | go func() { waitChan <- shim.Wait() }() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 734 | |
| 735 | config := test.config |
David Benjamin | ba4594a | 2015-06-18 18:36:15 -0400 | [diff] [blame] | 736 | if !test.noSessionCache { |
| 737 | config.ClientSessionCache = NewLRUClientSessionCache(1) |
| 738 | config.ServerSessionCache = NewLRUServerSessionCache(1) |
| 739 | } |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 740 | if test.testType == clientTest { |
| 741 | if len(config.Certificates) == 0 { |
| 742 | config.Certificates = []Certificate{getRSACertificate()} |
| 743 | } |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 744 | } else { |
| 745 | // Supply a ServerName to ensure a constant session cache key, |
| 746 | // rather than falling back to net.Conn.RemoteAddr. |
| 747 | if len(config.ServerName) == 0 { |
| 748 | config.ServerName = "test" |
| 749 | } |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 750 | } |
David Benjamin | f2b8363 | 2016-03-01 22:57:46 -0500 | [diff] [blame] | 751 | if *fuzzer { |
| 752 | config.Bugs.NullAllCiphers = true |
| 753 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 754 | |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 755 | conn, err := acceptOrWait(listener, waitChan) |
| 756 | if err == nil { |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 757 | err = doExchange(test, &config, conn, false /* not a resumption */) |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 758 | conn.Close() |
| 759 | } |
David Benjamin | 65ea8ff | 2014-11-23 03:01:00 -0500 | [diff] [blame] | 760 | |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 761 | if err == nil && test.resumeSession { |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 762 | var resumeConfig Config |
| 763 | if test.resumeConfig != nil { |
| 764 | resumeConfig = *test.resumeConfig |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 765 | if len(resumeConfig.ServerName) == 0 { |
| 766 | resumeConfig.ServerName = config.ServerName |
| 767 | } |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 768 | if len(resumeConfig.Certificates) == 0 { |
| 769 | resumeConfig.Certificates = []Certificate{getRSACertificate()} |
| 770 | } |
David Benjamin | ba4594a | 2015-06-18 18:36:15 -0400 | [diff] [blame] | 771 | if test.newSessionsOnResume { |
| 772 | if !test.noSessionCache { |
| 773 | resumeConfig.ClientSessionCache = NewLRUClientSessionCache(1) |
| 774 | resumeConfig.ServerSessionCache = NewLRUServerSessionCache(1) |
| 775 | } |
| 776 | } else { |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 777 | resumeConfig.SessionTicketKey = config.SessionTicketKey |
| 778 | resumeConfig.ClientSessionCache = config.ClientSessionCache |
| 779 | resumeConfig.ServerSessionCache = config.ServerSessionCache |
| 780 | } |
David Benjamin | f2b8363 | 2016-03-01 22:57:46 -0500 | [diff] [blame] | 781 | if *fuzzer { |
| 782 | resumeConfig.Bugs.NullAllCiphers = true |
| 783 | } |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 784 | } else { |
| 785 | resumeConfig = config |
| 786 | } |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 787 | var connResume net.Conn |
| 788 | connResume, err = acceptOrWait(listener, waitChan) |
| 789 | if err == nil { |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 790 | err = doExchange(test, &resumeConfig, connResume, true /* resumption */) |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 791 | connResume.Close() |
| 792 | } |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 793 | } |
| 794 | |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 795 | // Close the listener now. This is to avoid hangs should the shim try to |
| 796 | // open more connections than expected. |
| 797 | listener.Close() |
| 798 | listener = nil |
| 799 | |
| 800 | childErr := <-waitChan |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 801 | if exitError, ok := childErr.(*exec.ExitError); ok { |
| 802 | if exitError.Sys().(syscall.WaitStatus).ExitStatus() == 88 { |
| 803 | return errMoreMallocs |
| 804 | } |
| 805 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 806 | |
David Benjamin | 9bea349 | 2016-03-02 10:59:16 -0500 | [diff] [blame] | 807 | // Account for Windows line endings. |
| 808 | stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1) |
| 809 | stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1) |
David Benjamin | ff3a149 | 2016-03-02 10:12:06 -0500 | [diff] [blame] | 810 | |
| 811 | // Separate the errors from the shim and those from tools like |
| 812 | // AddressSanitizer. |
| 813 | var extraStderr string |
| 814 | if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 { |
| 815 | stderr = stderrParts[0] |
| 816 | extraStderr = stderrParts[1] |
| 817 | } |
| 818 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 819 | failed := err != nil || childErr != nil |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 820 | correctFailure := len(test.expectedError) == 0 || strings.Contains(stderr, test.expectedError) |
Adam Langley | ac61fa3 | 2014-06-23 12:03:11 -0700 | [diff] [blame] | 821 | localError := "none" |
| 822 | if err != nil { |
| 823 | localError = err.Error() |
| 824 | } |
| 825 | if len(test.expectedLocalError) != 0 { |
| 826 | correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError) |
| 827 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 828 | |
| 829 | if failed != test.shouldFail || failed && !correctFailure { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 830 | childError := "none" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 831 | if childErr != nil { |
| 832 | childError = childErr.Error() |
| 833 | } |
| 834 | |
| 835 | var msg string |
| 836 | switch { |
| 837 | case failed && !test.shouldFail: |
| 838 | msg = "unexpected failure" |
| 839 | case !failed && test.shouldFail: |
| 840 | msg = "unexpected success" |
| 841 | case failed && !correctFailure: |
Adam Langley | ac61fa3 | 2014-06-23 12:03:11 -0700 | [diff] [blame] | 842 | msg = "bad error (wanted '" + test.expectedError + "' / '" + test.expectedLocalError + "')" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 843 | default: |
| 844 | panic("internal error") |
| 845 | } |
| 846 | |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 847 | return fmt.Errorf("%s: local error '%s', child error '%s', stdout:\n%s\nstderr:\n%s", msg, localError, childError, stdout, stderr) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 848 | } |
| 849 | |
David Benjamin | ff3a149 | 2016-03-02 10:12:06 -0500 | [diff] [blame] | 850 | if !*useValgrind && (len(extraStderr) > 0 || (!failed && len(stderr) > 0)) { |
| 851 | return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | return nil |
| 855 | } |
| 856 | |
| 857 | var tlsVersions = []struct { |
| 858 | name string |
| 859 | version uint16 |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 860 | flag string |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 861 | hasDTLS bool |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 862 | }{ |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 863 | {"SSL3", VersionSSL30, "-no-ssl3", false}, |
| 864 | {"TLS1", VersionTLS10, "-no-tls1", true}, |
| 865 | {"TLS11", VersionTLS11, "-no-tls11", false}, |
| 866 | {"TLS12", VersionTLS12, "-no-tls12", true}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | var testCipherSuites = []struct { |
| 870 | name string |
| 871 | id uint16 |
| 872 | }{ |
| 873 | {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 874 | {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 875 | {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 876 | {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 877 | {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 878 | {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 879 | {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 880 | {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 881 | {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 882 | {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 883 | {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384}, |
| 884 | {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 885 | {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 886 | {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 887 | {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 888 | {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256}, |
| 889 | {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 890 | {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 891 | {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384}, |
David Benjamin | 13414b3 | 2015-12-09 23:02:39 -0500 | [diff] [blame] | 892 | {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256}, |
David Benjamin | e320392 | 2015-12-09 21:21:31 -0500 | [diff] [blame] | 893 | {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 894 | {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 895 | {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 896 | {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 897 | {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 898 | {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 899 | {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 900 | {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384}, |
David Benjamin | 13414b3 | 2015-12-09 23:02:39 -0500 | [diff] [blame] | 901 | {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256}, |
David Benjamin | e320392 | 2015-12-09 21:21:31 -0500 | [diff] [blame] | 902 | {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 903 | {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA}, |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 904 | {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA}, |
| 905 | {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA}, |
Adam Langley | 85bc560 | 2015-06-09 09:54:04 -0700 | [diff] [blame] | 906 | {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA}, |
| 907 | {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA}, |
David Benjamin | 13414b3 | 2015-12-09 23:02:39 -0500 | [diff] [blame] | 908 | {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256}, |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 909 | {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 910 | {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 911 | {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA}, |
Matt Braithwaite | af09675 | 2015-09-02 19:48:16 -0700 | [diff] [blame] | 912 | {"NULL-SHA", TLS_RSA_WITH_NULL_SHA}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 913 | } |
| 914 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 915 | func hasComponent(suiteName, component string) bool { |
| 916 | return strings.Contains("-"+suiteName+"-", "-"+component+"-") |
| 917 | } |
| 918 | |
David Benjamin | 4298d77 | 2015-12-19 00:18:25 -0500 | [diff] [blame] | 919 | func isTLSOnly(suiteName string) bool { |
| 920 | // BoringSSL doesn't support ECDHE without a curves extension, and |
| 921 | // SSLv3 doesn't contain extensions. |
| 922 | return hasComponent(suiteName, "ECDHE") || isTLS12Only(suiteName) |
| 923 | } |
| 924 | |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 925 | func isTLS12Only(suiteName string) bool { |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 926 | return hasComponent(suiteName, "GCM") || |
| 927 | hasComponent(suiteName, "SHA256") || |
David Benjamin | e9a80ff | 2015-04-07 00:46:46 -0400 | [diff] [blame] | 928 | hasComponent(suiteName, "SHA384") || |
| 929 | hasComponent(suiteName, "POLY1305") |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | func isDTLSCipher(suiteName string) bool { |
Matt Braithwaite | af09675 | 2015-09-02 19:48:16 -0700 | [diff] [blame] | 933 | return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL") |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 934 | } |
| 935 | |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 936 | func bigFromHex(hex string) *big.Int { |
| 937 | ret, ok := new(big.Int).SetString(hex, 16) |
| 938 | if !ok { |
| 939 | panic("failed to parse hex number 0x" + hex) |
| 940 | } |
| 941 | return ret |
| 942 | } |
| 943 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 944 | func addBasicTests() { |
| 945 | basicTests := []testCase{ |
| 946 | { |
| 947 | name: "BadRSASignature", |
| 948 | config: Config{ |
| 949 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 950 | Bugs: ProtocolBugs{ |
| 951 | InvalidSKXSignature: true, |
| 952 | }, |
| 953 | }, |
| 954 | shouldFail: true, |
| 955 | expectedError: ":BAD_SIGNATURE:", |
| 956 | }, |
| 957 | { |
| 958 | name: "BadECDSASignature", |
| 959 | config: Config{ |
| 960 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 961 | Bugs: ProtocolBugs{ |
| 962 | InvalidSKXSignature: true, |
| 963 | }, |
| 964 | Certificates: []Certificate{getECDSACertificate()}, |
| 965 | }, |
| 966 | shouldFail: true, |
| 967 | expectedError: ":BAD_SIGNATURE:", |
| 968 | }, |
| 969 | { |
David Benjamin | 6de0e53 | 2015-07-28 22:43:19 -0400 | [diff] [blame] | 970 | testType: serverTest, |
| 971 | name: "BadRSASignature-ClientAuth", |
| 972 | config: Config{ |
| 973 | Bugs: ProtocolBugs{ |
| 974 | InvalidCertVerifySignature: true, |
| 975 | }, |
| 976 | Certificates: []Certificate{getRSACertificate()}, |
| 977 | }, |
| 978 | shouldFail: true, |
| 979 | expectedError: ":BAD_SIGNATURE:", |
| 980 | flags: []string{"-require-any-client-certificate"}, |
| 981 | }, |
| 982 | { |
| 983 | testType: serverTest, |
| 984 | name: "BadECDSASignature-ClientAuth", |
| 985 | config: Config{ |
| 986 | Bugs: ProtocolBugs{ |
| 987 | InvalidCertVerifySignature: true, |
| 988 | }, |
| 989 | Certificates: []Certificate{getECDSACertificate()}, |
| 990 | }, |
| 991 | shouldFail: true, |
| 992 | expectedError: ":BAD_SIGNATURE:", |
| 993 | flags: []string{"-require-any-client-certificate"}, |
| 994 | }, |
| 995 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 996 | name: "BadECDSACurve", |
| 997 | config: Config{ |
| 998 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 999 | Bugs: ProtocolBugs{ |
| 1000 | InvalidSKXCurve: true, |
| 1001 | }, |
| 1002 | Certificates: []Certificate{getECDSACertificate()}, |
| 1003 | }, |
| 1004 | shouldFail: true, |
| 1005 | expectedError: ":WRONG_CURVE:", |
| 1006 | }, |
| 1007 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1008 | name: "NoFallbackSCSV", |
| 1009 | config: Config{ |
| 1010 | Bugs: ProtocolBugs{ |
| 1011 | FailIfNotFallbackSCSV: true, |
| 1012 | }, |
| 1013 | }, |
| 1014 | shouldFail: true, |
| 1015 | expectedLocalError: "no fallback SCSV found", |
| 1016 | }, |
| 1017 | { |
| 1018 | name: "SendFallbackSCSV", |
| 1019 | config: Config{ |
| 1020 | Bugs: ProtocolBugs{ |
| 1021 | FailIfNotFallbackSCSV: true, |
| 1022 | }, |
| 1023 | }, |
| 1024 | flags: []string{"-fallback-scsv"}, |
| 1025 | }, |
| 1026 | { |
| 1027 | name: "ClientCertificateTypes", |
| 1028 | config: Config{ |
| 1029 | ClientAuth: RequestClientCert, |
| 1030 | ClientCertificateTypes: []byte{ |
| 1031 | CertTypeDSSSign, |
| 1032 | CertTypeRSASign, |
| 1033 | CertTypeECDSASign, |
| 1034 | }, |
| 1035 | }, |
| 1036 | flags: []string{ |
| 1037 | "-expect-certificate-types", |
| 1038 | base64.StdEncoding.EncodeToString([]byte{ |
| 1039 | CertTypeDSSSign, |
| 1040 | CertTypeRSASign, |
| 1041 | CertTypeECDSASign, |
| 1042 | }), |
| 1043 | }, |
| 1044 | }, |
| 1045 | { |
| 1046 | name: "NoClientCertificate", |
| 1047 | config: Config{ |
| 1048 | ClientAuth: RequireAnyClientCert, |
| 1049 | }, |
| 1050 | shouldFail: true, |
| 1051 | expectedLocalError: "client didn't provide a certificate", |
| 1052 | }, |
| 1053 | { |
| 1054 | name: "UnauthenticatedECDH", |
| 1055 | config: Config{ |
| 1056 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1057 | Bugs: ProtocolBugs{ |
| 1058 | UnauthenticatedECDH: true, |
| 1059 | }, |
| 1060 | }, |
| 1061 | shouldFail: true, |
| 1062 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 1063 | }, |
| 1064 | { |
| 1065 | name: "SkipCertificateStatus", |
| 1066 | config: Config{ |
| 1067 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1068 | Bugs: ProtocolBugs{ |
| 1069 | SkipCertificateStatus: true, |
| 1070 | }, |
| 1071 | }, |
| 1072 | flags: []string{ |
| 1073 | "-enable-ocsp-stapling", |
| 1074 | }, |
| 1075 | }, |
| 1076 | { |
| 1077 | name: "SkipServerKeyExchange", |
| 1078 | config: Config{ |
| 1079 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1080 | Bugs: ProtocolBugs{ |
| 1081 | SkipServerKeyExchange: true, |
| 1082 | }, |
| 1083 | }, |
| 1084 | shouldFail: true, |
| 1085 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 1086 | }, |
| 1087 | { |
| 1088 | name: "SkipChangeCipherSpec-Client", |
| 1089 | config: Config{ |
| 1090 | Bugs: ProtocolBugs{ |
| 1091 | SkipChangeCipherSpec: true, |
| 1092 | }, |
| 1093 | }, |
| 1094 | shouldFail: true, |
David Benjamin | a41280d | 2015-11-26 02:16:49 -0500 | [diff] [blame] | 1095 | expectedError: ":UNEXPECTED_RECORD:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1096 | }, |
| 1097 | { |
| 1098 | testType: serverTest, |
| 1099 | name: "SkipChangeCipherSpec-Server", |
| 1100 | config: Config{ |
| 1101 | Bugs: ProtocolBugs{ |
| 1102 | SkipChangeCipherSpec: true, |
| 1103 | }, |
| 1104 | }, |
| 1105 | shouldFail: true, |
David Benjamin | a41280d | 2015-11-26 02:16:49 -0500 | [diff] [blame] | 1106 | expectedError: ":UNEXPECTED_RECORD:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1107 | }, |
| 1108 | { |
| 1109 | testType: serverTest, |
| 1110 | name: "SkipChangeCipherSpec-Server-NPN", |
| 1111 | config: Config{ |
| 1112 | NextProtos: []string{"bar"}, |
| 1113 | Bugs: ProtocolBugs{ |
| 1114 | SkipChangeCipherSpec: true, |
| 1115 | }, |
| 1116 | }, |
| 1117 | flags: []string{ |
| 1118 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 1119 | }, |
| 1120 | shouldFail: true, |
David Benjamin | a41280d | 2015-11-26 02:16:49 -0500 | [diff] [blame] | 1121 | expectedError: ":UNEXPECTED_RECORD:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1122 | }, |
| 1123 | { |
| 1124 | name: "FragmentAcrossChangeCipherSpec-Client", |
| 1125 | config: Config{ |
| 1126 | Bugs: ProtocolBugs{ |
| 1127 | FragmentAcrossChangeCipherSpec: true, |
| 1128 | }, |
| 1129 | }, |
| 1130 | shouldFail: true, |
David Benjamin | a41280d | 2015-11-26 02:16:49 -0500 | [diff] [blame] | 1131 | expectedError: ":UNEXPECTED_RECORD:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1132 | }, |
| 1133 | { |
| 1134 | testType: serverTest, |
| 1135 | name: "FragmentAcrossChangeCipherSpec-Server", |
| 1136 | config: Config{ |
| 1137 | Bugs: ProtocolBugs{ |
| 1138 | FragmentAcrossChangeCipherSpec: true, |
| 1139 | }, |
| 1140 | }, |
| 1141 | shouldFail: true, |
David Benjamin | a41280d | 2015-11-26 02:16:49 -0500 | [diff] [blame] | 1142 | expectedError: ":UNEXPECTED_RECORD:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1143 | }, |
| 1144 | { |
| 1145 | testType: serverTest, |
| 1146 | name: "FragmentAcrossChangeCipherSpec-Server-NPN", |
| 1147 | config: Config{ |
| 1148 | NextProtos: []string{"bar"}, |
| 1149 | Bugs: ProtocolBugs{ |
| 1150 | FragmentAcrossChangeCipherSpec: true, |
| 1151 | }, |
| 1152 | }, |
| 1153 | flags: []string{ |
| 1154 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 1155 | }, |
| 1156 | shouldFail: true, |
David Benjamin | a41280d | 2015-11-26 02:16:49 -0500 | [diff] [blame] | 1157 | expectedError: ":UNEXPECTED_RECORD:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1158 | }, |
| 1159 | { |
| 1160 | testType: serverTest, |
| 1161 | name: "Alert", |
| 1162 | config: Config{ |
| 1163 | Bugs: ProtocolBugs{ |
| 1164 | SendSpuriousAlert: alertRecordOverflow, |
| 1165 | }, |
| 1166 | }, |
| 1167 | shouldFail: true, |
| 1168 | expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:", |
| 1169 | }, |
| 1170 | { |
| 1171 | protocol: dtls, |
| 1172 | testType: serverTest, |
| 1173 | name: "Alert-DTLS", |
| 1174 | config: Config{ |
| 1175 | Bugs: ProtocolBugs{ |
| 1176 | SendSpuriousAlert: alertRecordOverflow, |
| 1177 | }, |
| 1178 | }, |
| 1179 | shouldFail: true, |
| 1180 | expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:", |
| 1181 | }, |
| 1182 | { |
| 1183 | testType: serverTest, |
| 1184 | name: "FragmentAlert", |
| 1185 | config: Config{ |
| 1186 | Bugs: ProtocolBugs{ |
| 1187 | FragmentAlert: true, |
| 1188 | SendSpuriousAlert: alertRecordOverflow, |
| 1189 | }, |
| 1190 | }, |
| 1191 | shouldFail: true, |
| 1192 | expectedError: ":BAD_ALERT:", |
| 1193 | }, |
| 1194 | { |
| 1195 | protocol: dtls, |
| 1196 | testType: serverTest, |
| 1197 | name: "FragmentAlert-DTLS", |
| 1198 | config: Config{ |
| 1199 | Bugs: ProtocolBugs{ |
| 1200 | FragmentAlert: true, |
| 1201 | SendSpuriousAlert: alertRecordOverflow, |
| 1202 | }, |
| 1203 | }, |
| 1204 | shouldFail: true, |
| 1205 | expectedError: ":BAD_ALERT:", |
| 1206 | }, |
| 1207 | { |
| 1208 | testType: serverTest, |
| 1209 | name: "EarlyChangeCipherSpec-server-1", |
| 1210 | config: Config{ |
| 1211 | Bugs: ProtocolBugs{ |
| 1212 | EarlyChangeCipherSpec: 1, |
| 1213 | }, |
| 1214 | }, |
| 1215 | shouldFail: true, |
David Benjamin | a41280d | 2015-11-26 02:16:49 -0500 | [diff] [blame] | 1216 | expectedError: ":UNEXPECTED_RECORD:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1217 | }, |
| 1218 | { |
| 1219 | testType: serverTest, |
| 1220 | name: "EarlyChangeCipherSpec-server-2", |
| 1221 | config: Config{ |
| 1222 | Bugs: ProtocolBugs{ |
| 1223 | EarlyChangeCipherSpec: 2, |
| 1224 | }, |
| 1225 | }, |
| 1226 | shouldFail: true, |
David Benjamin | a41280d | 2015-11-26 02:16:49 -0500 | [diff] [blame] | 1227 | expectedError: ":UNEXPECTED_RECORD:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1228 | }, |
| 1229 | { |
| 1230 | name: "SkipNewSessionTicket", |
| 1231 | config: Config{ |
| 1232 | Bugs: ProtocolBugs{ |
| 1233 | SkipNewSessionTicket: true, |
| 1234 | }, |
| 1235 | }, |
| 1236 | shouldFail: true, |
David Benjamin | a41280d | 2015-11-26 02:16:49 -0500 | [diff] [blame] | 1237 | expectedError: ":UNEXPECTED_RECORD:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1238 | }, |
| 1239 | { |
| 1240 | testType: serverTest, |
| 1241 | name: "FallbackSCSV", |
| 1242 | config: Config{ |
| 1243 | MaxVersion: VersionTLS11, |
| 1244 | Bugs: ProtocolBugs{ |
| 1245 | SendFallbackSCSV: true, |
| 1246 | }, |
| 1247 | }, |
| 1248 | shouldFail: true, |
| 1249 | expectedError: ":INAPPROPRIATE_FALLBACK:", |
| 1250 | }, |
| 1251 | { |
| 1252 | testType: serverTest, |
| 1253 | name: "FallbackSCSV-VersionMatch", |
| 1254 | config: Config{ |
| 1255 | Bugs: ProtocolBugs{ |
| 1256 | SendFallbackSCSV: true, |
| 1257 | }, |
| 1258 | }, |
| 1259 | }, |
| 1260 | { |
| 1261 | testType: serverTest, |
| 1262 | name: "FragmentedClientVersion", |
| 1263 | config: Config{ |
| 1264 | Bugs: ProtocolBugs{ |
| 1265 | MaxHandshakeRecordLength: 1, |
| 1266 | FragmentClientVersion: true, |
| 1267 | }, |
| 1268 | }, |
| 1269 | expectedVersion: VersionTLS12, |
| 1270 | }, |
| 1271 | { |
| 1272 | testType: serverTest, |
| 1273 | name: "MinorVersionTolerance", |
| 1274 | config: Config{ |
| 1275 | Bugs: ProtocolBugs{ |
| 1276 | SendClientVersion: 0x03ff, |
| 1277 | }, |
| 1278 | }, |
| 1279 | expectedVersion: VersionTLS12, |
| 1280 | }, |
| 1281 | { |
| 1282 | testType: serverTest, |
| 1283 | name: "MajorVersionTolerance", |
| 1284 | config: Config{ |
| 1285 | Bugs: ProtocolBugs{ |
| 1286 | SendClientVersion: 0x0400, |
| 1287 | }, |
| 1288 | }, |
| 1289 | expectedVersion: VersionTLS12, |
| 1290 | }, |
| 1291 | { |
| 1292 | testType: serverTest, |
| 1293 | name: "VersionTooLow", |
| 1294 | config: Config{ |
| 1295 | Bugs: ProtocolBugs{ |
| 1296 | SendClientVersion: 0x0200, |
| 1297 | }, |
| 1298 | }, |
| 1299 | shouldFail: true, |
| 1300 | expectedError: ":UNSUPPORTED_PROTOCOL:", |
| 1301 | }, |
| 1302 | { |
| 1303 | testType: serverTest, |
| 1304 | name: "HttpGET", |
| 1305 | sendPrefix: "GET / HTTP/1.0\n", |
| 1306 | shouldFail: true, |
| 1307 | expectedError: ":HTTP_REQUEST:", |
| 1308 | }, |
| 1309 | { |
| 1310 | testType: serverTest, |
| 1311 | name: "HttpPOST", |
| 1312 | sendPrefix: "POST / HTTP/1.0\n", |
| 1313 | shouldFail: true, |
| 1314 | expectedError: ":HTTP_REQUEST:", |
| 1315 | }, |
| 1316 | { |
| 1317 | testType: serverTest, |
| 1318 | name: "HttpHEAD", |
| 1319 | sendPrefix: "HEAD / HTTP/1.0\n", |
| 1320 | shouldFail: true, |
| 1321 | expectedError: ":HTTP_REQUEST:", |
| 1322 | }, |
| 1323 | { |
| 1324 | testType: serverTest, |
| 1325 | name: "HttpPUT", |
| 1326 | sendPrefix: "PUT / HTTP/1.0\n", |
| 1327 | shouldFail: true, |
| 1328 | expectedError: ":HTTP_REQUEST:", |
| 1329 | }, |
| 1330 | { |
| 1331 | testType: serverTest, |
| 1332 | name: "HttpCONNECT", |
| 1333 | sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n", |
| 1334 | shouldFail: true, |
| 1335 | expectedError: ":HTTPS_PROXY_REQUEST:", |
| 1336 | }, |
| 1337 | { |
| 1338 | testType: serverTest, |
| 1339 | name: "Garbage", |
| 1340 | sendPrefix: "blah", |
| 1341 | shouldFail: true, |
David Benjamin | 97760d5 | 2015-07-24 23:02:49 -0400 | [diff] [blame] | 1342 | expectedError: ":WRONG_VERSION_NUMBER:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1343 | }, |
| 1344 | { |
| 1345 | name: "SkipCipherVersionCheck", |
| 1346 | config: Config{ |
| 1347 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 1348 | MaxVersion: VersionTLS11, |
| 1349 | Bugs: ProtocolBugs{ |
| 1350 | SkipCipherVersionCheck: true, |
| 1351 | }, |
| 1352 | }, |
| 1353 | shouldFail: true, |
| 1354 | expectedError: ":WRONG_CIPHER_RETURNED:", |
| 1355 | }, |
| 1356 | { |
| 1357 | name: "RSAEphemeralKey", |
| 1358 | config: Config{ |
| 1359 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA}, |
| 1360 | Bugs: ProtocolBugs{ |
| 1361 | RSAEphemeralKey: true, |
| 1362 | }, |
| 1363 | }, |
| 1364 | shouldFail: true, |
| 1365 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 1366 | }, |
| 1367 | { |
| 1368 | name: "DisableEverything", |
| 1369 | flags: []string{"-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"}, |
| 1370 | shouldFail: true, |
| 1371 | expectedError: ":WRONG_SSL_VERSION:", |
| 1372 | }, |
| 1373 | { |
| 1374 | protocol: dtls, |
| 1375 | name: "DisableEverything-DTLS", |
| 1376 | flags: []string{"-no-tls12", "-no-tls1"}, |
| 1377 | shouldFail: true, |
| 1378 | expectedError: ":WRONG_SSL_VERSION:", |
| 1379 | }, |
| 1380 | { |
| 1381 | name: "NoSharedCipher", |
| 1382 | config: Config{ |
| 1383 | CipherSuites: []uint16{}, |
| 1384 | }, |
| 1385 | shouldFail: true, |
| 1386 | expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:", |
| 1387 | }, |
| 1388 | { |
| 1389 | protocol: dtls, |
| 1390 | testType: serverTest, |
| 1391 | name: "MTU", |
| 1392 | config: Config{ |
| 1393 | Bugs: ProtocolBugs{ |
| 1394 | MaxPacketLength: 256, |
| 1395 | }, |
| 1396 | }, |
| 1397 | flags: []string{"-mtu", "256"}, |
| 1398 | }, |
| 1399 | { |
| 1400 | protocol: dtls, |
| 1401 | testType: serverTest, |
| 1402 | name: "MTUExceeded", |
| 1403 | config: Config{ |
| 1404 | Bugs: ProtocolBugs{ |
| 1405 | MaxPacketLength: 255, |
| 1406 | }, |
| 1407 | }, |
| 1408 | flags: []string{"-mtu", "256"}, |
| 1409 | shouldFail: true, |
| 1410 | expectedLocalError: "dtls: exceeded maximum packet length", |
| 1411 | }, |
| 1412 | { |
| 1413 | name: "CertMismatchRSA", |
| 1414 | config: Config{ |
| 1415 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 1416 | Certificates: []Certificate{getECDSACertificate()}, |
| 1417 | Bugs: ProtocolBugs{ |
| 1418 | SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 1419 | }, |
| 1420 | }, |
| 1421 | shouldFail: true, |
| 1422 | expectedError: ":WRONG_CERTIFICATE_TYPE:", |
| 1423 | }, |
| 1424 | { |
| 1425 | name: "CertMismatchECDSA", |
| 1426 | config: Config{ |
| 1427 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1428 | Certificates: []Certificate{getRSACertificate()}, |
| 1429 | Bugs: ProtocolBugs{ |
| 1430 | SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, |
| 1431 | }, |
| 1432 | }, |
| 1433 | shouldFail: true, |
| 1434 | expectedError: ":WRONG_CERTIFICATE_TYPE:", |
| 1435 | }, |
| 1436 | { |
| 1437 | name: "EmptyCertificateList", |
| 1438 | config: Config{ |
| 1439 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1440 | Bugs: ProtocolBugs{ |
| 1441 | EmptyCertificateList: true, |
| 1442 | }, |
| 1443 | }, |
| 1444 | shouldFail: true, |
| 1445 | expectedError: ":DECODE_ERROR:", |
| 1446 | }, |
| 1447 | { |
| 1448 | name: "TLSFatalBadPackets", |
| 1449 | damageFirstWrite: true, |
| 1450 | shouldFail: true, |
| 1451 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 1452 | }, |
| 1453 | { |
| 1454 | protocol: dtls, |
| 1455 | name: "DTLSIgnoreBadPackets", |
| 1456 | damageFirstWrite: true, |
| 1457 | }, |
| 1458 | { |
| 1459 | protocol: dtls, |
| 1460 | name: "DTLSIgnoreBadPackets-Async", |
| 1461 | damageFirstWrite: true, |
| 1462 | flags: []string{"-async"}, |
| 1463 | }, |
| 1464 | { |
David Benjamin | 4cf369b | 2015-08-22 01:35:43 -0400 | [diff] [blame] | 1465 | name: "AppDataBeforeHandshake", |
| 1466 | config: Config{ |
| 1467 | Bugs: ProtocolBugs{ |
| 1468 | AppDataBeforeHandshake: []byte("TEST MESSAGE"), |
| 1469 | }, |
| 1470 | }, |
| 1471 | shouldFail: true, |
| 1472 | expectedError: ":UNEXPECTED_RECORD:", |
| 1473 | }, |
| 1474 | { |
| 1475 | name: "AppDataBeforeHandshake-Empty", |
| 1476 | config: Config{ |
| 1477 | Bugs: ProtocolBugs{ |
| 1478 | AppDataBeforeHandshake: []byte{}, |
| 1479 | }, |
| 1480 | }, |
| 1481 | shouldFail: true, |
| 1482 | expectedError: ":UNEXPECTED_RECORD:", |
| 1483 | }, |
| 1484 | { |
| 1485 | protocol: dtls, |
| 1486 | name: "AppDataBeforeHandshake-DTLS", |
| 1487 | config: Config{ |
| 1488 | Bugs: ProtocolBugs{ |
| 1489 | AppDataBeforeHandshake: []byte("TEST MESSAGE"), |
| 1490 | }, |
| 1491 | }, |
| 1492 | shouldFail: true, |
| 1493 | expectedError: ":UNEXPECTED_RECORD:", |
| 1494 | }, |
| 1495 | { |
| 1496 | protocol: dtls, |
| 1497 | name: "AppDataBeforeHandshake-DTLS-Empty", |
| 1498 | config: Config{ |
| 1499 | Bugs: ProtocolBugs{ |
| 1500 | AppDataBeforeHandshake: []byte{}, |
| 1501 | }, |
| 1502 | }, |
| 1503 | shouldFail: true, |
| 1504 | expectedError: ":UNEXPECTED_RECORD:", |
| 1505 | }, |
| 1506 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1507 | name: "AppDataAfterChangeCipherSpec", |
| 1508 | config: Config{ |
| 1509 | Bugs: ProtocolBugs{ |
| 1510 | AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"), |
| 1511 | }, |
| 1512 | }, |
| 1513 | shouldFail: true, |
David Benjamin | a41280d | 2015-11-26 02:16:49 -0500 | [diff] [blame] | 1514 | expectedError: ":UNEXPECTED_RECORD:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1515 | }, |
| 1516 | { |
David Benjamin | 4cf369b | 2015-08-22 01:35:43 -0400 | [diff] [blame] | 1517 | name: "AppDataAfterChangeCipherSpec-Empty", |
| 1518 | config: Config{ |
| 1519 | Bugs: ProtocolBugs{ |
| 1520 | AppDataAfterChangeCipherSpec: []byte{}, |
| 1521 | }, |
| 1522 | }, |
| 1523 | shouldFail: true, |
David Benjamin | a41280d | 2015-11-26 02:16:49 -0500 | [diff] [blame] | 1524 | expectedError: ":UNEXPECTED_RECORD:", |
David Benjamin | 4cf369b | 2015-08-22 01:35:43 -0400 | [diff] [blame] | 1525 | }, |
| 1526 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1527 | protocol: dtls, |
| 1528 | name: "AppDataAfterChangeCipherSpec-DTLS", |
| 1529 | config: Config{ |
| 1530 | Bugs: ProtocolBugs{ |
| 1531 | AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"), |
| 1532 | }, |
| 1533 | }, |
| 1534 | // BoringSSL's DTLS implementation will drop the out-of-order |
| 1535 | // application data. |
| 1536 | }, |
| 1537 | { |
David Benjamin | 4cf369b | 2015-08-22 01:35:43 -0400 | [diff] [blame] | 1538 | protocol: dtls, |
| 1539 | name: "AppDataAfterChangeCipherSpec-DTLS-Empty", |
| 1540 | config: Config{ |
| 1541 | Bugs: ProtocolBugs{ |
| 1542 | AppDataAfterChangeCipherSpec: []byte{}, |
| 1543 | }, |
| 1544 | }, |
| 1545 | // BoringSSL's DTLS implementation will drop the out-of-order |
| 1546 | // application data. |
| 1547 | }, |
| 1548 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1549 | name: "AlertAfterChangeCipherSpec", |
| 1550 | config: Config{ |
| 1551 | Bugs: ProtocolBugs{ |
| 1552 | AlertAfterChangeCipherSpec: alertRecordOverflow, |
| 1553 | }, |
| 1554 | }, |
| 1555 | shouldFail: true, |
| 1556 | expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:", |
| 1557 | }, |
| 1558 | { |
| 1559 | protocol: dtls, |
| 1560 | name: "AlertAfterChangeCipherSpec-DTLS", |
| 1561 | config: Config{ |
| 1562 | Bugs: ProtocolBugs{ |
| 1563 | AlertAfterChangeCipherSpec: alertRecordOverflow, |
| 1564 | }, |
| 1565 | }, |
| 1566 | shouldFail: true, |
| 1567 | expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:", |
| 1568 | }, |
| 1569 | { |
| 1570 | protocol: dtls, |
| 1571 | name: "ReorderHandshakeFragments-Small-DTLS", |
| 1572 | config: Config{ |
| 1573 | Bugs: ProtocolBugs{ |
| 1574 | ReorderHandshakeFragments: true, |
| 1575 | // Small enough that every handshake message is |
| 1576 | // fragmented. |
| 1577 | MaxHandshakeRecordLength: 2, |
| 1578 | }, |
| 1579 | }, |
| 1580 | }, |
| 1581 | { |
| 1582 | protocol: dtls, |
| 1583 | name: "ReorderHandshakeFragments-Large-DTLS", |
| 1584 | config: Config{ |
| 1585 | Bugs: ProtocolBugs{ |
| 1586 | ReorderHandshakeFragments: true, |
| 1587 | // Large enough that no handshake message is |
| 1588 | // fragmented. |
| 1589 | MaxHandshakeRecordLength: 2048, |
| 1590 | }, |
| 1591 | }, |
| 1592 | }, |
| 1593 | { |
| 1594 | protocol: dtls, |
| 1595 | name: "MixCompleteMessageWithFragments-DTLS", |
| 1596 | config: Config{ |
| 1597 | Bugs: ProtocolBugs{ |
| 1598 | ReorderHandshakeFragments: true, |
| 1599 | MixCompleteMessageWithFragments: true, |
| 1600 | MaxHandshakeRecordLength: 2, |
| 1601 | }, |
| 1602 | }, |
| 1603 | }, |
| 1604 | { |
| 1605 | name: "SendInvalidRecordType", |
| 1606 | config: Config{ |
| 1607 | Bugs: ProtocolBugs{ |
| 1608 | SendInvalidRecordType: true, |
| 1609 | }, |
| 1610 | }, |
| 1611 | shouldFail: true, |
| 1612 | expectedError: ":UNEXPECTED_RECORD:", |
| 1613 | }, |
| 1614 | { |
| 1615 | protocol: dtls, |
| 1616 | name: "SendInvalidRecordType-DTLS", |
| 1617 | config: Config{ |
| 1618 | Bugs: ProtocolBugs{ |
| 1619 | SendInvalidRecordType: true, |
| 1620 | }, |
| 1621 | }, |
| 1622 | shouldFail: true, |
| 1623 | expectedError: ":UNEXPECTED_RECORD:", |
| 1624 | }, |
| 1625 | { |
| 1626 | name: "FalseStart-SkipServerSecondLeg", |
| 1627 | config: Config{ |
| 1628 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1629 | NextProtos: []string{"foo"}, |
| 1630 | Bugs: ProtocolBugs{ |
| 1631 | SkipNewSessionTicket: true, |
| 1632 | SkipChangeCipherSpec: true, |
| 1633 | SkipFinished: true, |
| 1634 | ExpectFalseStart: true, |
| 1635 | }, |
| 1636 | }, |
| 1637 | flags: []string{ |
| 1638 | "-false-start", |
| 1639 | "-handshake-never-done", |
| 1640 | "-advertise-alpn", "\x03foo", |
| 1641 | }, |
| 1642 | shimWritesFirst: true, |
| 1643 | shouldFail: true, |
| 1644 | expectedError: ":UNEXPECTED_RECORD:", |
| 1645 | }, |
| 1646 | { |
| 1647 | name: "FalseStart-SkipServerSecondLeg-Implicit", |
| 1648 | config: Config{ |
| 1649 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1650 | NextProtos: []string{"foo"}, |
| 1651 | Bugs: ProtocolBugs{ |
| 1652 | SkipNewSessionTicket: true, |
| 1653 | SkipChangeCipherSpec: true, |
| 1654 | SkipFinished: true, |
| 1655 | }, |
| 1656 | }, |
| 1657 | flags: []string{ |
| 1658 | "-implicit-handshake", |
| 1659 | "-false-start", |
| 1660 | "-handshake-never-done", |
| 1661 | "-advertise-alpn", "\x03foo", |
| 1662 | }, |
| 1663 | shouldFail: true, |
| 1664 | expectedError: ":UNEXPECTED_RECORD:", |
| 1665 | }, |
| 1666 | { |
| 1667 | testType: serverTest, |
| 1668 | name: "FailEarlyCallback", |
| 1669 | flags: []string{"-fail-early-callback"}, |
| 1670 | shouldFail: true, |
| 1671 | expectedError: ":CONNECTION_REJECTED:", |
| 1672 | expectedLocalError: "remote error: access denied", |
| 1673 | }, |
| 1674 | { |
| 1675 | name: "WrongMessageType", |
| 1676 | config: Config{ |
| 1677 | Bugs: ProtocolBugs{ |
| 1678 | WrongCertificateMessageType: true, |
| 1679 | }, |
| 1680 | }, |
| 1681 | shouldFail: true, |
| 1682 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 1683 | expectedLocalError: "remote error: unexpected message", |
| 1684 | }, |
| 1685 | { |
| 1686 | protocol: dtls, |
| 1687 | name: "WrongMessageType-DTLS", |
| 1688 | config: Config{ |
| 1689 | Bugs: ProtocolBugs{ |
| 1690 | WrongCertificateMessageType: true, |
| 1691 | }, |
| 1692 | }, |
| 1693 | shouldFail: true, |
| 1694 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 1695 | expectedLocalError: "remote error: unexpected message", |
| 1696 | }, |
| 1697 | { |
| 1698 | protocol: dtls, |
| 1699 | name: "FragmentMessageTypeMismatch-DTLS", |
| 1700 | config: Config{ |
| 1701 | Bugs: ProtocolBugs{ |
| 1702 | MaxHandshakeRecordLength: 2, |
| 1703 | FragmentMessageTypeMismatch: true, |
| 1704 | }, |
| 1705 | }, |
| 1706 | shouldFail: true, |
| 1707 | expectedError: ":FRAGMENT_MISMATCH:", |
| 1708 | }, |
| 1709 | { |
| 1710 | protocol: dtls, |
| 1711 | name: "FragmentMessageLengthMismatch-DTLS", |
| 1712 | config: Config{ |
| 1713 | Bugs: ProtocolBugs{ |
| 1714 | MaxHandshakeRecordLength: 2, |
| 1715 | FragmentMessageLengthMismatch: true, |
| 1716 | }, |
| 1717 | }, |
| 1718 | shouldFail: true, |
| 1719 | expectedError: ":FRAGMENT_MISMATCH:", |
| 1720 | }, |
| 1721 | { |
| 1722 | protocol: dtls, |
| 1723 | name: "SplitFragments-Header-DTLS", |
| 1724 | config: Config{ |
| 1725 | Bugs: ProtocolBugs{ |
| 1726 | SplitFragments: 2, |
| 1727 | }, |
| 1728 | }, |
| 1729 | shouldFail: true, |
| 1730 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 1731 | }, |
| 1732 | { |
| 1733 | protocol: dtls, |
| 1734 | name: "SplitFragments-Boundary-DTLS", |
| 1735 | config: Config{ |
| 1736 | Bugs: ProtocolBugs{ |
| 1737 | SplitFragments: dtlsRecordHeaderLen, |
| 1738 | }, |
| 1739 | }, |
| 1740 | shouldFail: true, |
| 1741 | expectedError: ":EXCESSIVE_MESSAGE_SIZE:", |
| 1742 | }, |
| 1743 | { |
| 1744 | protocol: dtls, |
| 1745 | name: "SplitFragments-Body-DTLS", |
| 1746 | config: Config{ |
| 1747 | Bugs: ProtocolBugs{ |
| 1748 | SplitFragments: dtlsRecordHeaderLen + 1, |
| 1749 | }, |
| 1750 | }, |
| 1751 | shouldFail: true, |
| 1752 | expectedError: ":EXCESSIVE_MESSAGE_SIZE:", |
| 1753 | }, |
| 1754 | { |
| 1755 | protocol: dtls, |
| 1756 | name: "SendEmptyFragments-DTLS", |
| 1757 | config: Config{ |
| 1758 | Bugs: ProtocolBugs{ |
| 1759 | SendEmptyFragments: true, |
| 1760 | }, |
| 1761 | }, |
| 1762 | }, |
| 1763 | { |
| 1764 | name: "UnsupportedCipherSuite", |
| 1765 | config: Config{ |
| 1766 | CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA}, |
| 1767 | Bugs: ProtocolBugs{ |
| 1768 | IgnorePeerCipherPreferences: true, |
| 1769 | }, |
| 1770 | }, |
| 1771 | flags: []string{"-cipher", "DEFAULT:!RC4"}, |
| 1772 | shouldFail: true, |
| 1773 | expectedError: ":WRONG_CIPHER_RETURNED:", |
| 1774 | }, |
| 1775 | { |
| 1776 | name: "UnsupportedCurve", |
| 1777 | config: Config{ |
David Benjamin | 64d9250 | 2015-12-19 02:20:57 -0500 | [diff] [blame] | 1778 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1779 | CurvePreferences: []CurveID{CurveP256}, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1780 | Bugs: ProtocolBugs{ |
| 1781 | IgnorePeerCurvePreferences: true, |
| 1782 | }, |
| 1783 | }, |
David Benjamin | 64d9250 | 2015-12-19 02:20:57 -0500 | [diff] [blame] | 1784 | flags: []string{"-p384-only"}, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1785 | shouldFail: true, |
| 1786 | expectedError: ":WRONG_CURVE:", |
| 1787 | }, |
| 1788 | { |
David Benjamin | bf82aed | 2016-03-01 22:57:40 -0500 | [diff] [blame] | 1789 | name: "BadFinished-Client", |
| 1790 | config: Config{ |
| 1791 | Bugs: ProtocolBugs{ |
| 1792 | BadFinished: true, |
| 1793 | }, |
| 1794 | }, |
| 1795 | shouldFail: true, |
| 1796 | expectedError: ":DIGEST_CHECK_FAILED:", |
| 1797 | }, |
| 1798 | { |
| 1799 | testType: serverTest, |
| 1800 | name: "BadFinished-Server", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1801 | config: Config{ |
| 1802 | Bugs: ProtocolBugs{ |
| 1803 | BadFinished: true, |
| 1804 | }, |
| 1805 | }, |
| 1806 | shouldFail: true, |
| 1807 | expectedError: ":DIGEST_CHECK_FAILED:", |
| 1808 | }, |
| 1809 | { |
| 1810 | name: "FalseStart-BadFinished", |
| 1811 | config: Config{ |
| 1812 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1813 | NextProtos: []string{"foo"}, |
| 1814 | Bugs: ProtocolBugs{ |
| 1815 | BadFinished: true, |
| 1816 | ExpectFalseStart: true, |
| 1817 | }, |
| 1818 | }, |
| 1819 | flags: []string{ |
| 1820 | "-false-start", |
| 1821 | "-handshake-never-done", |
| 1822 | "-advertise-alpn", "\x03foo", |
| 1823 | }, |
| 1824 | shimWritesFirst: true, |
| 1825 | shouldFail: true, |
| 1826 | expectedError: ":DIGEST_CHECK_FAILED:", |
| 1827 | }, |
| 1828 | { |
| 1829 | name: "NoFalseStart-NoALPN", |
| 1830 | config: Config{ |
| 1831 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1832 | Bugs: ProtocolBugs{ |
| 1833 | ExpectFalseStart: true, |
| 1834 | AlertBeforeFalseStartTest: alertAccessDenied, |
| 1835 | }, |
| 1836 | }, |
| 1837 | flags: []string{ |
| 1838 | "-false-start", |
| 1839 | }, |
| 1840 | shimWritesFirst: true, |
| 1841 | shouldFail: true, |
| 1842 | expectedError: ":TLSV1_ALERT_ACCESS_DENIED:", |
| 1843 | expectedLocalError: "tls: peer did not false start: EOF", |
| 1844 | }, |
| 1845 | { |
| 1846 | name: "NoFalseStart-NoAEAD", |
| 1847 | config: Config{ |
| 1848 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 1849 | NextProtos: []string{"foo"}, |
| 1850 | Bugs: ProtocolBugs{ |
| 1851 | ExpectFalseStart: true, |
| 1852 | AlertBeforeFalseStartTest: alertAccessDenied, |
| 1853 | }, |
| 1854 | }, |
| 1855 | flags: []string{ |
| 1856 | "-false-start", |
| 1857 | "-advertise-alpn", "\x03foo", |
| 1858 | }, |
| 1859 | shimWritesFirst: true, |
| 1860 | shouldFail: true, |
| 1861 | expectedError: ":TLSV1_ALERT_ACCESS_DENIED:", |
| 1862 | expectedLocalError: "tls: peer did not false start: EOF", |
| 1863 | }, |
| 1864 | { |
| 1865 | name: "NoFalseStart-RSA", |
| 1866 | config: Config{ |
| 1867 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 1868 | NextProtos: []string{"foo"}, |
| 1869 | Bugs: ProtocolBugs{ |
| 1870 | ExpectFalseStart: true, |
| 1871 | AlertBeforeFalseStartTest: alertAccessDenied, |
| 1872 | }, |
| 1873 | }, |
| 1874 | flags: []string{ |
| 1875 | "-false-start", |
| 1876 | "-advertise-alpn", "\x03foo", |
| 1877 | }, |
| 1878 | shimWritesFirst: true, |
| 1879 | shouldFail: true, |
| 1880 | expectedError: ":TLSV1_ALERT_ACCESS_DENIED:", |
| 1881 | expectedLocalError: "tls: peer did not false start: EOF", |
| 1882 | }, |
| 1883 | { |
| 1884 | name: "NoFalseStart-DHE_RSA", |
| 1885 | config: Config{ |
| 1886 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1887 | NextProtos: []string{"foo"}, |
| 1888 | Bugs: ProtocolBugs{ |
| 1889 | ExpectFalseStart: true, |
| 1890 | AlertBeforeFalseStartTest: alertAccessDenied, |
| 1891 | }, |
| 1892 | }, |
| 1893 | flags: []string{ |
| 1894 | "-false-start", |
| 1895 | "-advertise-alpn", "\x03foo", |
| 1896 | }, |
| 1897 | shimWritesFirst: true, |
| 1898 | shouldFail: true, |
| 1899 | expectedError: ":TLSV1_ALERT_ACCESS_DENIED:", |
| 1900 | expectedLocalError: "tls: peer did not false start: EOF", |
| 1901 | }, |
| 1902 | { |
| 1903 | testType: serverTest, |
| 1904 | name: "NoSupportedCurves", |
| 1905 | config: Config{ |
| 1906 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1907 | Bugs: ProtocolBugs{ |
| 1908 | NoSupportedCurves: true, |
| 1909 | }, |
| 1910 | }, |
David Benjamin | 4298d77 | 2015-12-19 00:18:25 -0500 | [diff] [blame] | 1911 | shouldFail: true, |
| 1912 | expectedError: ":NO_SHARED_CIPHER:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1913 | }, |
| 1914 | { |
| 1915 | testType: serverTest, |
| 1916 | name: "NoCommonCurves", |
| 1917 | config: Config{ |
| 1918 | CipherSuites: []uint16{ |
| 1919 | TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 1920 | TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, |
| 1921 | }, |
| 1922 | CurvePreferences: []CurveID{CurveP224}, |
| 1923 | }, |
| 1924 | expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, |
| 1925 | }, |
| 1926 | { |
| 1927 | protocol: dtls, |
| 1928 | name: "SendSplitAlert-Sync", |
| 1929 | config: Config{ |
| 1930 | Bugs: ProtocolBugs{ |
| 1931 | SendSplitAlert: true, |
| 1932 | }, |
| 1933 | }, |
| 1934 | }, |
| 1935 | { |
| 1936 | protocol: dtls, |
| 1937 | name: "SendSplitAlert-Async", |
| 1938 | config: Config{ |
| 1939 | Bugs: ProtocolBugs{ |
| 1940 | SendSplitAlert: true, |
| 1941 | }, |
| 1942 | }, |
| 1943 | flags: []string{"-async"}, |
| 1944 | }, |
| 1945 | { |
| 1946 | protocol: dtls, |
| 1947 | name: "PackDTLSHandshake", |
| 1948 | config: Config{ |
| 1949 | Bugs: ProtocolBugs{ |
| 1950 | MaxHandshakeRecordLength: 2, |
| 1951 | PackHandshakeFragments: 20, |
| 1952 | PackHandshakeRecords: 200, |
| 1953 | }, |
| 1954 | }, |
| 1955 | }, |
| 1956 | { |
| 1957 | testType: serverTest, |
| 1958 | protocol: dtls, |
| 1959 | name: "NoRC4-DTLS", |
| 1960 | config: Config{ |
| 1961 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_RC4_128_SHA}, |
| 1962 | Bugs: ProtocolBugs{ |
| 1963 | EnableAllCiphersInDTLS: true, |
| 1964 | }, |
| 1965 | }, |
| 1966 | shouldFail: true, |
| 1967 | expectedError: ":NO_SHARED_CIPHER:", |
| 1968 | }, |
| 1969 | { |
| 1970 | name: "SendEmptyRecords-Pass", |
| 1971 | sendEmptyRecords: 32, |
| 1972 | }, |
| 1973 | { |
| 1974 | name: "SendEmptyRecords", |
| 1975 | sendEmptyRecords: 33, |
| 1976 | shouldFail: true, |
| 1977 | expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:", |
| 1978 | }, |
| 1979 | { |
| 1980 | name: "SendEmptyRecords-Async", |
| 1981 | sendEmptyRecords: 33, |
| 1982 | flags: []string{"-async"}, |
| 1983 | shouldFail: true, |
| 1984 | expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:", |
| 1985 | }, |
| 1986 | { |
| 1987 | name: "SendWarningAlerts-Pass", |
| 1988 | sendWarningAlerts: 4, |
| 1989 | }, |
| 1990 | { |
| 1991 | protocol: dtls, |
| 1992 | name: "SendWarningAlerts-DTLS-Pass", |
| 1993 | sendWarningAlerts: 4, |
| 1994 | }, |
| 1995 | { |
| 1996 | name: "SendWarningAlerts", |
| 1997 | sendWarningAlerts: 5, |
| 1998 | shouldFail: true, |
| 1999 | expectedError: ":TOO_MANY_WARNING_ALERTS:", |
| 2000 | }, |
| 2001 | { |
| 2002 | name: "SendWarningAlerts-Async", |
| 2003 | sendWarningAlerts: 5, |
| 2004 | flags: []string{"-async"}, |
| 2005 | shouldFail: true, |
| 2006 | expectedError: ":TOO_MANY_WARNING_ALERTS:", |
| 2007 | }, |
David Benjamin | ba4594a | 2015-06-18 18:36:15 -0400 | [diff] [blame] | 2008 | { |
| 2009 | name: "EmptySessionID", |
| 2010 | config: Config{ |
| 2011 | SessionTicketsDisabled: true, |
| 2012 | }, |
| 2013 | noSessionCache: true, |
| 2014 | flags: []string{"-expect-no-session"}, |
| 2015 | }, |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 2016 | { |
| 2017 | name: "Unclean-Shutdown", |
| 2018 | config: Config{ |
| 2019 | Bugs: ProtocolBugs{ |
| 2020 | NoCloseNotify: true, |
| 2021 | ExpectCloseNotify: true, |
| 2022 | }, |
| 2023 | }, |
| 2024 | shimShutsDown: true, |
| 2025 | flags: []string{"-check-close-notify"}, |
| 2026 | shouldFail: true, |
| 2027 | expectedError: "Unexpected SSL_shutdown result: -1 != 1", |
| 2028 | }, |
| 2029 | { |
| 2030 | name: "Unclean-Shutdown-Ignored", |
| 2031 | config: Config{ |
| 2032 | Bugs: ProtocolBugs{ |
| 2033 | NoCloseNotify: true, |
| 2034 | }, |
| 2035 | }, |
| 2036 | shimShutsDown: true, |
| 2037 | }, |
David Benjamin | 4f75aaf | 2015-09-01 16:53:10 -0400 | [diff] [blame] | 2038 | { |
| 2039 | name: "LargePlaintext", |
| 2040 | config: Config{ |
| 2041 | Bugs: ProtocolBugs{ |
| 2042 | SendLargeRecords: true, |
| 2043 | }, |
| 2044 | }, |
| 2045 | messageLen: maxPlaintext + 1, |
| 2046 | shouldFail: true, |
| 2047 | expectedError: ":DATA_LENGTH_TOO_LONG:", |
| 2048 | }, |
| 2049 | { |
| 2050 | protocol: dtls, |
| 2051 | name: "LargePlaintext-DTLS", |
| 2052 | config: Config{ |
| 2053 | Bugs: ProtocolBugs{ |
| 2054 | SendLargeRecords: true, |
| 2055 | }, |
| 2056 | }, |
| 2057 | messageLen: maxPlaintext + 1, |
| 2058 | shouldFail: true, |
| 2059 | expectedError: ":DATA_LENGTH_TOO_LONG:", |
| 2060 | }, |
| 2061 | { |
| 2062 | name: "LargeCiphertext", |
| 2063 | config: Config{ |
| 2064 | Bugs: ProtocolBugs{ |
| 2065 | SendLargeRecords: true, |
| 2066 | }, |
| 2067 | }, |
| 2068 | messageLen: maxPlaintext * 2, |
| 2069 | shouldFail: true, |
| 2070 | expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:", |
| 2071 | }, |
| 2072 | { |
| 2073 | protocol: dtls, |
| 2074 | name: "LargeCiphertext-DTLS", |
| 2075 | config: Config{ |
| 2076 | Bugs: ProtocolBugs{ |
| 2077 | SendLargeRecords: true, |
| 2078 | }, |
| 2079 | }, |
| 2080 | messageLen: maxPlaintext * 2, |
| 2081 | // Unlike the other four cases, DTLS drops records which |
| 2082 | // are invalid before authentication, so the connection |
| 2083 | // does not fail. |
| 2084 | expectMessageDropped: true, |
| 2085 | }, |
David Benjamin | dd6fed9 | 2015-10-23 17:41:12 -0400 | [diff] [blame] | 2086 | { |
| 2087 | name: "SendEmptySessionTicket", |
| 2088 | config: Config{ |
| 2089 | Bugs: ProtocolBugs{ |
| 2090 | SendEmptySessionTicket: true, |
| 2091 | FailIfSessionOffered: true, |
| 2092 | }, |
| 2093 | }, |
| 2094 | flags: []string{"-expect-no-session"}, |
| 2095 | resumeSession: true, |
| 2096 | expectResumeRejected: true, |
| 2097 | }, |
David Benjamin | 99fdfb9 | 2015-11-02 12:11:35 -0500 | [diff] [blame] | 2098 | { |
| 2099 | name: "CheckLeafCurve", |
| 2100 | config: Config{ |
| 2101 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 2102 | Certificates: []Certificate{getECDSACertificate()}, |
| 2103 | }, |
| 2104 | flags: []string{"-p384-only"}, |
| 2105 | shouldFail: true, |
| 2106 | expectedError: ":BAD_ECC_CERT:", |
| 2107 | }, |
David Benjamin | 8411b24 | 2015-11-26 12:07:28 -0500 | [diff] [blame] | 2108 | { |
| 2109 | name: "BadChangeCipherSpec-1", |
| 2110 | config: Config{ |
| 2111 | Bugs: ProtocolBugs{ |
| 2112 | BadChangeCipherSpec: []byte{2}, |
| 2113 | }, |
| 2114 | }, |
| 2115 | shouldFail: true, |
| 2116 | expectedError: ":BAD_CHANGE_CIPHER_SPEC:", |
| 2117 | }, |
| 2118 | { |
| 2119 | name: "BadChangeCipherSpec-2", |
| 2120 | config: Config{ |
| 2121 | Bugs: ProtocolBugs{ |
| 2122 | BadChangeCipherSpec: []byte{1, 1}, |
| 2123 | }, |
| 2124 | }, |
| 2125 | shouldFail: true, |
| 2126 | expectedError: ":BAD_CHANGE_CIPHER_SPEC:", |
| 2127 | }, |
| 2128 | { |
| 2129 | protocol: dtls, |
| 2130 | name: "BadChangeCipherSpec-DTLS-1", |
| 2131 | config: Config{ |
| 2132 | Bugs: ProtocolBugs{ |
| 2133 | BadChangeCipherSpec: []byte{2}, |
| 2134 | }, |
| 2135 | }, |
| 2136 | shouldFail: true, |
| 2137 | expectedError: ":BAD_CHANGE_CIPHER_SPEC:", |
| 2138 | }, |
| 2139 | { |
| 2140 | protocol: dtls, |
| 2141 | name: "BadChangeCipherSpec-DTLS-2", |
| 2142 | config: Config{ |
| 2143 | Bugs: ProtocolBugs{ |
| 2144 | BadChangeCipherSpec: []byte{1, 1}, |
| 2145 | }, |
| 2146 | }, |
| 2147 | shouldFail: true, |
| 2148 | expectedError: ":BAD_CHANGE_CIPHER_SPEC:", |
| 2149 | }, |
David Benjamin | ef5dfd2 | 2015-12-06 13:17:07 -0500 | [diff] [blame] | 2150 | { |
| 2151 | name: "BadHelloRequest-1", |
| 2152 | renegotiate: 1, |
| 2153 | config: Config{ |
| 2154 | Bugs: ProtocolBugs{ |
| 2155 | BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1}, |
| 2156 | }, |
| 2157 | }, |
| 2158 | flags: []string{ |
| 2159 | "-renegotiate-freely", |
| 2160 | "-expect-total-renegotiations", "1", |
| 2161 | }, |
| 2162 | shouldFail: true, |
| 2163 | expectedError: ":BAD_HELLO_REQUEST:", |
| 2164 | }, |
| 2165 | { |
| 2166 | name: "BadHelloRequest-2", |
| 2167 | renegotiate: 1, |
| 2168 | config: Config{ |
| 2169 | Bugs: ProtocolBugs{ |
| 2170 | BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0}, |
| 2171 | }, |
| 2172 | }, |
| 2173 | flags: []string{ |
| 2174 | "-renegotiate-freely", |
| 2175 | "-expect-total-renegotiations", "1", |
| 2176 | }, |
| 2177 | shouldFail: true, |
| 2178 | expectedError: ":BAD_HELLO_REQUEST:", |
| 2179 | }, |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 2180 | { |
| 2181 | testType: serverTest, |
| 2182 | name: "SupportTicketsWithSessionID", |
| 2183 | config: Config{ |
| 2184 | SessionTicketsDisabled: true, |
| 2185 | }, |
| 2186 | resumeConfig: &Config{}, |
| 2187 | resumeSession: true, |
| 2188 | }, |
David Benjamin | 2b07fa4 | 2016-03-02 00:23:57 -0500 | [diff] [blame] | 2189 | { |
| 2190 | name: "InvalidECDHPoint-Client", |
| 2191 | config: Config{ |
| 2192 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2193 | CurvePreferences: []CurveID{CurveP256}, |
| 2194 | Bugs: ProtocolBugs{ |
| 2195 | InvalidECDHPoint: true, |
| 2196 | }, |
| 2197 | }, |
| 2198 | shouldFail: true, |
| 2199 | expectedError: ":INVALID_ENCODING:", |
| 2200 | }, |
| 2201 | { |
| 2202 | testType: serverTest, |
| 2203 | name: "InvalidECDHPoint-Server", |
| 2204 | config: Config{ |
| 2205 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2206 | CurvePreferences: []CurveID{CurveP256}, |
| 2207 | Bugs: ProtocolBugs{ |
| 2208 | InvalidECDHPoint: true, |
| 2209 | }, |
| 2210 | }, |
| 2211 | shouldFail: true, |
| 2212 | expectedError: ":INVALID_ENCODING:", |
| 2213 | }, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 2214 | } |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 2215 | testCases = append(testCases, basicTests...) |
| 2216 | } |
| 2217 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2218 | func addCipherSuiteTests() { |
| 2219 | for _, suite := range testCipherSuites { |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2220 | const psk = "12345" |
| 2221 | const pskIdentity = "luggage combo" |
| 2222 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2223 | var cert Certificate |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2224 | var certFile string |
| 2225 | var keyFile string |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 2226 | if hasComponent(suite.name, "ECDSA") { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2227 | cert = getECDSACertificate() |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2228 | certFile = ecdsaCertificateFile |
| 2229 | keyFile = ecdsaKeyFile |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2230 | } else { |
| 2231 | cert = getRSACertificate() |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2232 | certFile = rsaCertificateFile |
| 2233 | keyFile = rsaKeyFile |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2234 | } |
| 2235 | |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2236 | var flags []string |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 2237 | if hasComponent(suite.name, "PSK") { |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2238 | flags = append(flags, |
| 2239 | "-psk", psk, |
| 2240 | "-psk-identity", pskIdentity) |
| 2241 | } |
Matt Braithwaite | af09675 | 2015-09-02 19:48:16 -0700 | [diff] [blame] | 2242 | if hasComponent(suite.name, "NULL") { |
| 2243 | // NULL ciphers must be explicitly enabled. |
| 2244 | flags = append(flags, "-cipher", "DEFAULT:NULL-SHA") |
| 2245 | } |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2246 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2247 | for _, ver := range tlsVersions { |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 2248 | if ver.version < VersionTLS12 && isTLS12Only(suite.name) { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2249 | continue |
| 2250 | } |
| 2251 | |
David Benjamin | 4298d77 | 2015-12-19 00:18:25 -0500 | [diff] [blame] | 2252 | shouldFail := isTLSOnly(suite.name) && ver.version == VersionSSL30 |
| 2253 | |
| 2254 | expectedError := "" |
| 2255 | if shouldFail { |
| 2256 | expectedError = ":NO_SHARED_CIPHER:" |
| 2257 | } |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2258 | |
David Benjamin | 76d8abe | 2014-08-14 16:25:34 -0400 | [diff] [blame] | 2259 | testCases = append(testCases, testCase{ |
| 2260 | testType: serverTest, |
| 2261 | name: ver.name + "-" + suite.name + "-server", |
| 2262 | config: Config{ |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2263 | MinVersion: ver.version, |
| 2264 | MaxVersion: ver.version, |
| 2265 | CipherSuites: []uint16{suite.id}, |
| 2266 | Certificates: []Certificate{cert}, |
| 2267 | PreSharedKey: []byte(psk), |
| 2268 | PreSharedKeyIdentity: pskIdentity, |
David Benjamin | 76d8abe | 2014-08-14 16:25:34 -0400 | [diff] [blame] | 2269 | }, |
| 2270 | certFile: certFile, |
| 2271 | keyFile: keyFile, |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2272 | flags: flags, |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 2273 | resumeSession: true, |
David Benjamin | 4298d77 | 2015-12-19 00:18:25 -0500 | [diff] [blame] | 2274 | shouldFail: shouldFail, |
| 2275 | expectedError: expectedError, |
| 2276 | }) |
| 2277 | |
| 2278 | if shouldFail { |
| 2279 | continue |
| 2280 | } |
| 2281 | |
| 2282 | testCases = append(testCases, testCase{ |
| 2283 | testType: clientTest, |
| 2284 | name: ver.name + "-" + suite.name + "-client", |
| 2285 | config: Config{ |
| 2286 | MinVersion: ver.version, |
| 2287 | MaxVersion: ver.version, |
| 2288 | CipherSuites: []uint16{suite.id}, |
| 2289 | Certificates: []Certificate{cert}, |
| 2290 | PreSharedKey: []byte(psk), |
| 2291 | PreSharedKeyIdentity: pskIdentity, |
| 2292 | }, |
| 2293 | flags: flags, |
| 2294 | resumeSession: true, |
David Benjamin | 76d8abe | 2014-08-14 16:25:34 -0400 | [diff] [blame] | 2295 | }) |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 2296 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 2297 | if ver.hasDTLS && isDTLSCipher(suite.name) { |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 2298 | testCases = append(testCases, testCase{ |
| 2299 | testType: clientTest, |
| 2300 | protocol: dtls, |
| 2301 | name: "D" + ver.name + "-" + suite.name + "-client", |
| 2302 | config: Config{ |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2303 | MinVersion: ver.version, |
| 2304 | MaxVersion: ver.version, |
| 2305 | CipherSuites: []uint16{suite.id}, |
| 2306 | Certificates: []Certificate{cert}, |
| 2307 | PreSharedKey: []byte(psk), |
| 2308 | PreSharedKeyIdentity: pskIdentity, |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 2309 | }, |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2310 | flags: flags, |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 2311 | resumeSession: true, |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 2312 | }) |
| 2313 | testCases = append(testCases, testCase{ |
| 2314 | testType: serverTest, |
| 2315 | protocol: dtls, |
| 2316 | name: "D" + ver.name + "-" + suite.name + "-server", |
| 2317 | config: Config{ |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2318 | MinVersion: ver.version, |
| 2319 | MaxVersion: ver.version, |
| 2320 | CipherSuites: []uint16{suite.id}, |
| 2321 | Certificates: []Certificate{cert}, |
| 2322 | PreSharedKey: []byte(psk), |
| 2323 | PreSharedKeyIdentity: pskIdentity, |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 2324 | }, |
| 2325 | certFile: certFile, |
| 2326 | keyFile: keyFile, |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2327 | flags: flags, |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 2328 | resumeSession: true, |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 2329 | }) |
| 2330 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2331 | } |
David Benjamin | 2c99d28 | 2015-09-01 10:23:00 -0400 | [diff] [blame] | 2332 | |
| 2333 | // Ensure both TLS and DTLS accept their maximum record sizes. |
| 2334 | testCases = append(testCases, testCase{ |
| 2335 | name: suite.name + "-LargeRecord", |
| 2336 | config: Config{ |
| 2337 | CipherSuites: []uint16{suite.id}, |
| 2338 | Certificates: []Certificate{cert}, |
| 2339 | PreSharedKey: []byte(psk), |
| 2340 | PreSharedKeyIdentity: pskIdentity, |
| 2341 | }, |
| 2342 | flags: flags, |
| 2343 | messageLen: maxPlaintext, |
| 2344 | }) |
David Benjamin | 2c99d28 | 2015-09-01 10:23:00 -0400 | [diff] [blame] | 2345 | if isDTLSCipher(suite.name) { |
| 2346 | testCases = append(testCases, testCase{ |
| 2347 | protocol: dtls, |
| 2348 | name: suite.name + "-LargeRecord-DTLS", |
| 2349 | config: Config{ |
| 2350 | CipherSuites: []uint16{suite.id}, |
| 2351 | Certificates: []Certificate{cert}, |
| 2352 | PreSharedKey: []byte(psk), |
| 2353 | PreSharedKeyIdentity: pskIdentity, |
| 2354 | }, |
| 2355 | flags: flags, |
| 2356 | messageLen: maxPlaintext, |
| 2357 | }) |
| 2358 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2359 | } |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 2360 | |
| 2361 | testCases = append(testCases, testCase{ |
| 2362 | name: "WeakDH", |
| 2363 | config: Config{ |
| 2364 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2365 | Bugs: ProtocolBugs{ |
| 2366 | // This is a 1023-bit prime number, generated |
| 2367 | // with: |
| 2368 | // openssl gendh 1023 | openssl asn1parse -i |
| 2369 | DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"), |
| 2370 | }, |
| 2371 | }, |
| 2372 | shouldFail: true, |
David Benjamin | cd24a39 | 2015-11-11 13:23:05 -0800 | [diff] [blame] | 2373 | expectedError: ":BAD_DH_P_LENGTH:", |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 2374 | }) |
Adam Langley | cef7583 | 2015-09-03 14:51:12 -0700 | [diff] [blame] | 2375 | |
David Benjamin | cd24a39 | 2015-11-11 13:23:05 -0800 | [diff] [blame] | 2376 | testCases = append(testCases, testCase{ |
| 2377 | name: "SillyDH", |
| 2378 | config: Config{ |
| 2379 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2380 | Bugs: ProtocolBugs{ |
| 2381 | // This is a 4097-bit prime number, generated |
| 2382 | // with: |
| 2383 | // openssl gendh 4097 | openssl asn1parse -i |
| 2384 | DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"), |
| 2385 | }, |
| 2386 | }, |
| 2387 | shouldFail: true, |
| 2388 | expectedError: ":DH_P_TOO_LONG:", |
| 2389 | }) |
| 2390 | |
Adam Langley | c4f25ce | 2015-11-26 16:39:08 -0800 | [diff] [blame] | 2391 | // This test ensures that Diffie-Hellman public values are padded with |
| 2392 | // zeros so that they're the same length as the prime. This is to avoid |
| 2393 | // hitting a bug in yaSSL. |
| 2394 | testCases = append(testCases, testCase{ |
| 2395 | testType: serverTest, |
| 2396 | name: "DHPublicValuePadded", |
| 2397 | config: Config{ |
| 2398 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2399 | Bugs: ProtocolBugs{ |
| 2400 | RequireDHPublicValueLen: (1025 + 7) / 8, |
| 2401 | }, |
| 2402 | }, |
| 2403 | flags: []string{"-use-sparse-dh-prime"}, |
| 2404 | }) |
David Benjamin | cd24a39 | 2015-11-11 13:23:05 -0800 | [diff] [blame] | 2405 | |
David Benjamin | 241ae83 | 2016-01-15 03:04:54 -0500 | [diff] [blame] | 2406 | // The server must be tolerant to bogus ciphers. |
| 2407 | const bogusCipher = 0x1234 |
| 2408 | testCases = append(testCases, testCase{ |
| 2409 | testType: serverTest, |
| 2410 | name: "UnknownCipher", |
| 2411 | config: Config{ |
| 2412 | CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2413 | }, |
| 2414 | }) |
| 2415 | |
Adam Langley | cef7583 | 2015-09-03 14:51:12 -0700 | [diff] [blame] | 2416 | // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS |
| 2417 | // 1.1 specific cipher suite settings. A server is setup with the given |
| 2418 | // cipher lists and then a connection is made for each member of |
| 2419 | // expectations. The cipher suite that the server selects must match |
| 2420 | // the specified one. |
| 2421 | var versionSpecificCiphersTest = []struct { |
| 2422 | ciphersDefault, ciphersTLS10, ciphersTLS11 string |
| 2423 | // expectations is a map from TLS version to cipher suite id. |
| 2424 | expectations map[uint16]uint16 |
| 2425 | }{ |
| 2426 | { |
| 2427 | // Test that the null case (where no version-specific ciphers are set) |
| 2428 | // works as expected. |
| 2429 | "RC4-SHA:AES128-SHA", // default ciphers |
| 2430 | "", // no ciphers specifically for TLS ≥ 1.0 |
| 2431 | "", // no ciphers specifically for TLS ≥ 1.1 |
| 2432 | map[uint16]uint16{ |
| 2433 | VersionSSL30: TLS_RSA_WITH_RC4_128_SHA, |
| 2434 | VersionTLS10: TLS_RSA_WITH_RC4_128_SHA, |
| 2435 | VersionTLS11: TLS_RSA_WITH_RC4_128_SHA, |
| 2436 | VersionTLS12: TLS_RSA_WITH_RC4_128_SHA, |
| 2437 | }, |
| 2438 | }, |
| 2439 | { |
| 2440 | // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different |
| 2441 | // cipher. |
| 2442 | "RC4-SHA:AES128-SHA", // default |
| 2443 | "AES128-SHA", // these ciphers for TLS ≥ 1.0 |
| 2444 | "", // no ciphers specifically for TLS ≥ 1.1 |
| 2445 | map[uint16]uint16{ |
| 2446 | VersionSSL30: TLS_RSA_WITH_RC4_128_SHA, |
| 2447 | VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2448 | VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2449 | VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2450 | }, |
| 2451 | }, |
| 2452 | { |
| 2453 | // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different |
| 2454 | // cipher. |
| 2455 | "RC4-SHA:AES128-SHA", // default |
| 2456 | "", // no ciphers specifically for TLS ≥ 1.0 |
| 2457 | "AES128-SHA", // these ciphers for TLS ≥ 1.1 |
| 2458 | map[uint16]uint16{ |
| 2459 | VersionSSL30: TLS_RSA_WITH_RC4_128_SHA, |
| 2460 | VersionTLS10: TLS_RSA_WITH_RC4_128_SHA, |
| 2461 | VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2462 | VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2463 | }, |
| 2464 | }, |
| 2465 | { |
| 2466 | // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should |
| 2467 | // mask ciphers_tls10 for TLS 1.1 and 1.2. |
| 2468 | "RC4-SHA:AES128-SHA", // default |
| 2469 | "AES128-SHA", // these ciphers for TLS ≥ 1.0 |
| 2470 | "AES256-SHA", // these ciphers for TLS ≥ 1.1 |
| 2471 | map[uint16]uint16{ |
| 2472 | VersionSSL30: TLS_RSA_WITH_RC4_128_SHA, |
| 2473 | VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2474 | VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA, |
| 2475 | VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA, |
| 2476 | }, |
| 2477 | }, |
| 2478 | } |
| 2479 | |
| 2480 | for i, test := range versionSpecificCiphersTest { |
| 2481 | for version, expectedCipherSuite := range test.expectations { |
| 2482 | flags := []string{"-cipher", test.ciphersDefault} |
| 2483 | if len(test.ciphersTLS10) > 0 { |
| 2484 | flags = append(flags, "-cipher-tls10", test.ciphersTLS10) |
| 2485 | } |
| 2486 | if len(test.ciphersTLS11) > 0 { |
| 2487 | flags = append(flags, "-cipher-tls11", test.ciphersTLS11) |
| 2488 | } |
| 2489 | |
| 2490 | testCases = append(testCases, testCase{ |
| 2491 | testType: serverTest, |
| 2492 | name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version), |
| 2493 | config: Config{ |
| 2494 | MaxVersion: version, |
| 2495 | MinVersion: version, |
| 2496 | CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA}, |
| 2497 | }, |
| 2498 | flags: flags, |
| 2499 | expectedCipher: expectedCipherSuite, |
| 2500 | }) |
| 2501 | } |
| 2502 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2503 | } |
| 2504 | |
| 2505 | func addBadECDSASignatureTests() { |
| 2506 | for badR := BadValue(1); badR < NumBadValues; badR++ { |
| 2507 | for badS := BadValue(1); badS < NumBadValues; badS++ { |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2508 | testCases = append(testCases, testCase{ |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2509 | name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS), |
| 2510 | config: Config{ |
| 2511 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 2512 | Certificates: []Certificate{getECDSACertificate()}, |
| 2513 | Bugs: ProtocolBugs{ |
| 2514 | BadECDSAR: badR, |
| 2515 | BadECDSAS: badS, |
| 2516 | }, |
| 2517 | }, |
| 2518 | shouldFail: true, |
| 2519 | expectedError: "SIGNATURE", |
| 2520 | }) |
| 2521 | } |
| 2522 | } |
| 2523 | } |
| 2524 | |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2525 | func addCBCPaddingTests() { |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2526 | testCases = append(testCases, testCase{ |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2527 | name: "MaxCBCPadding", |
| 2528 | config: Config{ |
| 2529 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 2530 | Bugs: ProtocolBugs{ |
| 2531 | MaxPadding: true, |
| 2532 | }, |
| 2533 | }, |
| 2534 | messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size |
| 2535 | }) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2536 | testCases = append(testCases, testCase{ |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2537 | name: "BadCBCPadding", |
| 2538 | config: Config{ |
| 2539 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 2540 | Bugs: ProtocolBugs{ |
| 2541 | PaddingFirstByteBad: true, |
| 2542 | }, |
| 2543 | }, |
| 2544 | shouldFail: true, |
| 2545 | expectedError: "DECRYPTION_FAILED_OR_BAD_RECORD_MAC", |
| 2546 | }) |
| 2547 | // OpenSSL previously had an issue where the first byte of padding in |
| 2548 | // 255 bytes of padding wasn't checked. |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2549 | testCases = append(testCases, testCase{ |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2550 | name: "BadCBCPadding255", |
| 2551 | config: Config{ |
| 2552 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 2553 | Bugs: ProtocolBugs{ |
| 2554 | MaxPadding: true, |
| 2555 | PaddingFirstByteBadIf255: true, |
| 2556 | }, |
| 2557 | }, |
| 2558 | messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size |
| 2559 | shouldFail: true, |
| 2560 | expectedError: "DECRYPTION_FAILED_OR_BAD_RECORD_MAC", |
| 2561 | }) |
| 2562 | } |
| 2563 | |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 2564 | func addCBCSplittingTests() { |
| 2565 | testCases = append(testCases, testCase{ |
| 2566 | name: "CBCRecordSplitting", |
| 2567 | config: Config{ |
| 2568 | MaxVersion: VersionTLS10, |
| 2569 | MinVersion: VersionTLS10, |
| 2570 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 2571 | }, |
David Benjamin | ac8302a | 2015-09-01 17:18:15 -0400 | [diff] [blame] | 2572 | messageLen: -1, // read until EOF |
| 2573 | resumeSession: true, |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 2574 | flags: []string{ |
| 2575 | "-async", |
| 2576 | "-write-different-record-sizes", |
| 2577 | "-cbc-record-splitting", |
| 2578 | }, |
David Benjamin | a8e3e0e | 2014-08-06 22:11:10 -0400 | [diff] [blame] | 2579 | }) |
| 2580 | testCases = append(testCases, testCase{ |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 2581 | name: "CBCRecordSplittingPartialWrite", |
| 2582 | config: Config{ |
| 2583 | MaxVersion: VersionTLS10, |
| 2584 | MinVersion: VersionTLS10, |
| 2585 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 2586 | }, |
| 2587 | messageLen: -1, // read until EOF |
| 2588 | flags: []string{ |
| 2589 | "-async", |
| 2590 | "-write-different-record-sizes", |
| 2591 | "-cbc-record-splitting", |
| 2592 | "-partial-write", |
| 2593 | }, |
| 2594 | }) |
| 2595 | } |
| 2596 | |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2597 | func addClientAuthTests() { |
David Benjamin | 407a10c | 2014-07-16 12:58:59 -0400 | [diff] [blame] | 2598 | // Add a dummy cert pool to stress certificate authority parsing. |
| 2599 | // TODO(davidben): Add tests that those values parse out correctly. |
| 2600 | certPool := x509.NewCertPool() |
| 2601 | cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0]) |
| 2602 | if err != nil { |
| 2603 | panic(err) |
| 2604 | } |
| 2605 | certPool.AddCert(cert) |
| 2606 | |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2607 | for _, ver := range tlsVersions { |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2608 | testCases = append(testCases, testCase{ |
| 2609 | testType: clientTest, |
David Benjamin | 67666e7 | 2014-07-12 15:47:52 -0400 | [diff] [blame] | 2610 | name: ver.name + "-Client-ClientAuth-RSA", |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2611 | config: Config{ |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 2612 | MinVersion: ver.version, |
| 2613 | MaxVersion: ver.version, |
| 2614 | ClientAuth: RequireAnyClientCert, |
| 2615 | ClientCAs: certPool, |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2616 | }, |
| 2617 | flags: []string{ |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 2618 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 2619 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2620 | }, |
| 2621 | }) |
| 2622 | testCases = append(testCases, testCase{ |
David Benjamin | 67666e7 | 2014-07-12 15:47:52 -0400 | [diff] [blame] | 2623 | testType: serverTest, |
| 2624 | name: ver.name + "-Server-ClientAuth-RSA", |
| 2625 | config: Config{ |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 2626 | MinVersion: ver.version, |
| 2627 | MaxVersion: ver.version, |
David Benjamin | 67666e7 | 2014-07-12 15:47:52 -0400 | [diff] [blame] | 2628 | Certificates: []Certificate{rsaCertificate}, |
| 2629 | }, |
| 2630 | flags: []string{"-require-any-client-certificate"}, |
| 2631 | }) |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 2632 | if ver.version != VersionSSL30 { |
| 2633 | testCases = append(testCases, testCase{ |
| 2634 | testType: serverTest, |
| 2635 | name: ver.name + "-Server-ClientAuth-ECDSA", |
| 2636 | config: Config{ |
| 2637 | MinVersion: ver.version, |
| 2638 | MaxVersion: ver.version, |
| 2639 | Certificates: []Certificate{ecdsaCertificate}, |
| 2640 | }, |
| 2641 | flags: []string{"-require-any-client-certificate"}, |
| 2642 | }) |
| 2643 | testCases = append(testCases, testCase{ |
| 2644 | testType: clientTest, |
| 2645 | name: ver.name + "-Client-ClientAuth-ECDSA", |
| 2646 | config: Config{ |
| 2647 | MinVersion: ver.version, |
| 2648 | MaxVersion: ver.version, |
| 2649 | ClientAuth: RequireAnyClientCert, |
| 2650 | ClientCAs: certPool, |
| 2651 | }, |
| 2652 | flags: []string{ |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 2653 | "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile), |
| 2654 | "-key-file", path.Join(*resourceDir, ecdsaKeyFile), |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 2655 | }, |
| 2656 | }) |
| 2657 | } |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2658 | } |
| 2659 | } |
| 2660 | |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 2661 | func addExtendedMasterSecretTests() { |
| 2662 | const expectEMSFlag = "-expect-extended-master-secret" |
| 2663 | |
| 2664 | for _, with := range []bool{false, true} { |
| 2665 | prefix := "No" |
| 2666 | var flags []string |
| 2667 | if with { |
| 2668 | prefix = "" |
| 2669 | flags = []string{expectEMSFlag} |
| 2670 | } |
| 2671 | |
| 2672 | for _, isClient := range []bool{false, true} { |
| 2673 | suffix := "-Server" |
| 2674 | testType := serverTest |
| 2675 | if isClient { |
| 2676 | suffix = "-Client" |
| 2677 | testType = clientTest |
| 2678 | } |
| 2679 | |
| 2680 | for _, ver := range tlsVersions { |
| 2681 | test := testCase{ |
| 2682 | testType: testType, |
| 2683 | name: prefix + "ExtendedMasterSecret-" + ver.name + suffix, |
| 2684 | config: Config{ |
| 2685 | MinVersion: ver.version, |
| 2686 | MaxVersion: ver.version, |
| 2687 | Bugs: ProtocolBugs{ |
| 2688 | NoExtendedMasterSecret: !with, |
| 2689 | RequireExtendedMasterSecret: with, |
| 2690 | }, |
| 2691 | }, |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2692 | flags: flags, |
| 2693 | shouldFail: ver.version == VersionSSL30 && with, |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 2694 | } |
| 2695 | if test.shouldFail { |
| 2696 | test.expectedLocalError = "extended master secret required but not supported by peer" |
| 2697 | } |
| 2698 | testCases = append(testCases, test) |
| 2699 | } |
| 2700 | } |
| 2701 | } |
| 2702 | |
Adam Langley | ba5934b | 2015-06-02 10:50:35 -0700 | [diff] [blame] | 2703 | for _, isClient := range []bool{false, true} { |
| 2704 | for _, supportedInFirstConnection := range []bool{false, true} { |
| 2705 | for _, supportedInResumeConnection := range []bool{false, true} { |
| 2706 | boolToWord := func(b bool) string { |
| 2707 | if b { |
| 2708 | return "Yes" |
| 2709 | } |
| 2710 | return "No" |
| 2711 | } |
| 2712 | suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-" |
| 2713 | if isClient { |
| 2714 | suffix += "Client" |
| 2715 | } else { |
| 2716 | suffix += "Server" |
| 2717 | } |
| 2718 | |
| 2719 | supportedConfig := Config{ |
| 2720 | Bugs: ProtocolBugs{ |
| 2721 | RequireExtendedMasterSecret: true, |
| 2722 | }, |
| 2723 | } |
| 2724 | |
| 2725 | noSupportConfig := Config{ |
| 2726 | Bugs: ProtocolBugs{ |
| 2727 | NoExtendedMasterSecret: true, |
| 2728 | }, |
| 2729 | } |
| 2730 | |
| 2731 | test := testCase{ |
| 2732 | name: "ExtendedMasterSecret-" + suffix, |
| 2733 | resumeSession: true, |
| 2734 | } |
| 2735 | |
| 2736 | if !isClient { |
| 2737 | test.testType = serverTest |
| 2738 | } |
| 2739 | |
| 2740 | if supportedInFirstConnection { |
| 2741 | test.config = supportedConfig |
| 2742 | } else { |
| 2743 | test.config = noSupportConfig |
| 2744 | } |
| 2745 | |
| 2746 | if supportedInResumeConnection { |
| 2747 | test.resumeConfig = &supportedConfig |
| 2748 | } else { |
| 2749 | test.resumeConfig = &noSupportConfig |
| 2750 | } |
| 2751 | |
| 2752 | switch suffix { |
| 2753 | case "YesToYes-Client", "YesToYes-Server": |
| 2754 | // When a session is resumed, it should |
| 2755 | // still be aware that its master |
| 2756 | // secret was generated via EMS and |
| 2757 | // thus it's safe to use tls-unique. |
| 2758 | test.flags = []string{expectEMSFlag} |
| 2759 | case "NoToYes-Server": |
| 2760 | // If an original connection did not |
| 2761 | // contain EMS, but a resumption |
| 2762 | // handshake does, then a server should |
| 2763 | // not resume the session. |
| 2764 | test.expectResumeRejected = true |
| 2765 | case "YesToNo-Server": |
| 2766 | // Resuming an EMS session without the |
| 2767 | // EMS extension should cause the |
| 2768 | // server to abort the connection. |
| 2769 | test.shouldFail = true |
| 2770 | test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:" |
| 2771 | case "NoToYes-Client": |
| 2772 | // A client should abort a connection |
| 2773 | // where the server resumed a non-EMS |
| 2774 | // session but echoed the EMS |
| 2775 | // extension. |
| 2776 | test.shouldFail = true |
| 2777 | test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:" |
| 2778 | case "YesToNo-Client": |
| 2779 | // A client should abort a connection |
| 2780 | // where the server didn't echo EMS |
| 2781 | // when the session used it. |
| 2782 | test.shouldFail = true |
| 2783 | test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:" |
| 2784 | } |
| 2785 | |
| 2786 | testCases = append(testCases, test) |
| 2787 | } |
| 2788 | } |
| 2789 | } |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 2790 | } |
| 2791 | |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 2792 | // Adds tests that try to cover the range of the handshake state machine, under |
| 2793 | // various conditions. Some of these are redundant with other tests, but they |
| 2794 | // only cover the synchronous case. |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 2795 | func addStateMachineCoverageTests(async, splitHandshake bool, protocol protocol) { |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 2796 | var tests []testCase |
| 2797 | |
| 2798 | // Basic handshake, with resumption. Client and server, |
| 2799 | // session ID and session ticket. |
| 2800 | tests = append(tests, testCase{ |
| 2801 | name: "Basic-Client", |
| 2802 | resumeSession: true, |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 2803 | // Ensure session tickets are used, not session IDs. |
| 2804 | noSessionCache: true, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 2805 | }) |
| 2806 | tests = append(tests, testCase{ |
| 2807 | name: "Basic-Client-RenewTicket", |
| 2808 | config: Config{ |
| 2809 | Bugs: ProtocolBugs{ |
| 2810 | RenewTicketOnResume: true, |
| 2811 | }, |
| 2812 | }, |
David Benjamin | ba4594a | 2015-06-18 18:36:15 -0400 | [diff] [blame] | 2813 | flags: []string{"-expect-ticket-renewal"}, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 2814 | resumeSession: true, |
| 2815 | }) |
| 2816 | tests = append(tests, testCase{ |
| 2817 | name: "Basic-Client-NoTicket", |
| 2818 | config: Config{ |
| 2819 | SessionTicketsDisabled: true, |
| 2820 | }, |
| 2821 | resumeSession: true, |
| 2822 | }) |
| 2823 | tests = append(tests, testCase{ |
| 2824 | name: "Basic-Client-Implicit", |
| 2825 | flags: []string{"-implicit-handshake"}, |
| 2826 | resumeSession: true, |
| 2827 | }) |
| 2828 | tests = append(tests, testCase{ |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 2829 | testType: serverTest, |
| 2830 | name: "Basic-Server", |
| 2831 | config: Config{ |
| 2832 | Bugs: ProtocolBugs{ |
| 2833 | RequireSessionTickets: true, |
| 2834 | }, |
| 2835 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 2836 | resumeSession: true, |
| 2837 | }) |
| 2838 | tests = append(tests, testCase{ |
| 2839 | testType: serverTest, |
| 2840 | name: "Basic-Server-NoTickets", |
| 2841 | config: Config{ |
| 2842 | SessionTicketsDisabled: true, |
| 2843 | }, |
| 2844 | resumeSession: true, |
| 2845 | }) |
| 2846 | tests = append(tests, testCase{ |
| 2847 | testType: serverTest, |
| 2848 | name: "Basic-Server-Implicit", |
| 2849 | flags: []string{"-implicit-handshake"}, |
| 2850 | resumeSession: true, |
| 2851 | }) |
| 2852 | tests = append(tests, testCase{ |
| 2853 | testType: serverTest, |
| 2854 | name: "Basic-Server-EarlyCallback", |
| 2855 | flags: []string{"-use-early-callback"}, |
| 2856 | resumeSession: true, |
| 2857 | }) |
| 2858 | |
| 2859 | // TLS client auth. |
| 2860 | tests = append(tests, testCase{ |
| 2861 | testType: clientTest, |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame^] | 2862 | name: "ClientAuth-NoCertificate", |
| 2863 | config: Config{ |
| 2864 | ClientAuth: RequestClientCert, |
| 2865 | }, |
| 2866 | }) |
| 2867 | tests = append(tests, testCase{ |
| 2868 | testType: clientTest, |
| 2869 | name: "ClientAuth-NoCertificate-OldCallback", |
| 2870 | config: Config{ |
| 2871 | ClientAuth: RequestClientCert, |
| 2872 | }, |
| 2873 | flags: []string{"-use-old-client-cert-callback"}, |
| 2874 | }) |
| 2875 | tests = append(tests, testCase{ |
| 2876 | testType: clientTest, |
nagendra modadugu | 3398dbf | 2015-08-07 14:07:52 -0700 | [diff] [blame] | 2877 | name: "ClientAuth-RSA-Client", |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 2878 | config: Config{ |
| 2879 | ClientAuth: RequireAnyClientCert, |
| 2880 | }, |
| 2881 | flags: []string{ |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 2882 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 2883 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 2884 | }, |
| 2885 | }) |
nagendra modadugu | 3398dbf | 2015-08-07 14:07:52 -0700 | [diff] [blame] | 2886 | tests = append(tests, testCase{ |
| 2887 | testType: clientTest, |
| 2888 | name: "ClientAuth-ECDSA-Client", |
| 2889 | config: Config{ |
| 2890 | ClientAuth: RequireAnyClientCert, |
| 2891 | }, |
| 2892 | flags: []string{ |
| 2893 | "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile), |
| 2894 | "-key-file", path.Join(*resourceDir, ecdsaKeyFile), |
| 2895 | }, |
| 2896 | }) |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame^] | 2897 | tests = append(tests, testCase{ |
| 2898 | testType: clientTest, |
| 2899 | name: "ClientAuth-OldCallback", |
| 2900 | config: Config{ |
| 2901 | ClientAuth: RequireAnyClientCert, |
| 2902 | }, |
| 2903 | flags: []string{ |
| 2904 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 2905 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 2906 | "-use-old-client-cert-callback", |
| 2907 | }, |
| 2908 | }) |
| 2909 | |
David Benjamin | b4d65fd | 2015-05-29 17:11:21 -0400 | [diff] [blame] | 2910 | if async { |
nagendra modadugu | 3398dbf | 2015-08-07 14:07:52 -0700 | [diff] [blame] | 2911 | // Test async keys against each key exchange. |
David Benjamin | b4d65fd | 2015-05-29 17:11:21 -0400 | [diff] [blame] | 2912 | tests = append(tests, testCase{ |
nagendra modadugu | 3398dbf | 2015-08-07 14:07:52 -0700 | [diff] [blame] | 2913 | testType: serverTest, |
| 2914 | name: "Basic-Server-RSA", |
David Benjamin | b4d65fd | 2015-05-29 17:11:21 -0400 | [diff] [blame] | 2915 | config: Config{ |
nagendra modadugu | 3398dbf | 2015-08-07 14:07:52 -0700 | [diff] [blame] | 2916 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | b4d65fd | 2015-05-29 17:11:21 -0400 | [diff] [blame] | 2917 | }, |
| 2918 | flags: []string{ |
Adam Langley | 288d8d5 | 2015-06-18 16:24:31 -0700 | [diff] [blame] | 2919 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 2920 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | b4d65fd | 2015-05-29 17:11:21 -0400 | [diff] [blame] | 2921 | }, |
| 2922 | }) |
nagendra modadugu | 601448a | 2015-07-24 09:31:31 -0700 | [diff] [blame] | 2923 | tests = append(tests, testCase{ |
| 2924 | testType: serverTest, |
nagendra modadugu | 3398dbf | 2015-08-07 14:07:52 -0700 | [diff] [blame] | 2925 | name: "Basic-Server-ECDHE-RSA", |
| 2926 | config: Config{ |
| 2927 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2928 | }, |
nagendra modadugu | 601448a | 2015-07-24 09:31:31 -0700 | [diff] [blame] | 2929 | flags: []string{ |
| 2930 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 2931 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
nagendra modadugu | 601448a | 2015-07-24 09:31:31 -0700 | [diff] [blame] | 2932 | }, |
| 2933 | }) |
| 2934 | tests = append(tests, testCase{ |
| 2935 | testType: serverTest, |
nagendra modadugu | 3398dbf | 2015-08-07 14:07:52 -0700 | [diff] [blame] | 2936 | name: "Basic-Server-ECDHE-ECDSA", |
| 2937 | config: Config{ |
| 2938 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 2939 | }, |
nagendra modadugu | 601448a | 2015-07-24 09:31:31 -0700 | [diff] [blame] | 2940 | flags: []string{ |
| 2941 | "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile), |
| 2942 | "-key-file", path.Join(*resourceDir, ecdsaKeyFile), |
nagendra modadugu | 601448a | 2015-07-24 09:31:31 -0700 | [diff] [blame] | 2943 | }, |
| 2944 | }) |
David Benjamin | b4d65fd | 2015-05-29 17:11:21 -0400 | [diff] [blame] | 2945 | } |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 2946 | tests = append(tests, testCase{ |
| 2947 | testType: serverTest, |
| 2948 | name: "ClientAuth-Server", |
| 2949 | config: Config{ |
| 2950 | Certificates: []Certificate{rsaCertificate}, |
| 2951 | }, |
| 2952 | flags: []string{"-require-any-client-certificate"}, |
| 2953 | }) |
| 2954 | |
| 2955 | // No session ticket support; server doesn't send NewSessionTicket. |
| 2956 | tests = append(tests, testCase{ |
| 2957 | name: "SessionTicketsDisabled-Client", |
| 2958 | config: Config{ |
| 2959 | SessionTicketsDisabled: true, |
| 2960 | }, |
| 2961 | }) |
| 2962 | tests = append(tests, testCase{ |
| 2963 | testType: serverTest, |
| 2964 | name: "SessionTicketsDisabled-Server", |
| 2965 | config: Config{ |
| 2966 | SessionTicketsDisabled: true, |
| 2967 | }, |
| 2968 | }) |
| 2969 | |
| 2970 | // Skip ServerKeyExchange in PSK key exchange if there's no |
| 2971 | // identity hint. |
| 2972 | tests = append(tests, testCase{ |
| 2973 | name: "EmptyPSKHint-Client", |
| 2974 | config: Config{ |
| 2975 | CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA}, |
| 2976 | PreSharedKey: []byte("secret"), |
| 2977 | }, |
| 2978 | flags: []string{"-psk", "secret"}, |
| 2979 | }) |
| 2980 | tests = append(tests, testCase{ |
| 2981 | testType: serverTest, |
| 2982 | name: "EmptyPSKHint-Server", |
| 2983 | config: Config{ |
| 2984 | CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA}, |
| 2985 | PreSharedKey: []byte("secret"), |
| 2986 | }, |
| 2987 | flags: []string{"-psk", "secret"}, |
| 2988 | }) |
| 2989 | |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 2990 | tests = append(tests, testCase{ |
| 2991 | testType: clientTest, |
| 2992 | name: "OCSPStapling-Client", |
| 2993 | flags: []string{ |
| 2994 | "-enable-ocsp-stapling", |
| 2995 | "-expect-ocsp-response", |
| 2996 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
Paul Lietar | 8f1c268 | 2015-08-18 12:21:54 +0100 | [diff] [blame] | 2997 | "-verify-peer", |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 2998 | }, |
Paul Lietar | 62be8ac | 2015-09-16 10:03:30 +0100 | [diff] [blame] | 2999 | resumeSession: true, |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3000 | }) |
| 3001 | |
| 3002 | tests = append(tests, testCase{ |
David Benjamin | ec43534 | 2015-08-21 13:44:06 -0400 | [diff] [blame] | 3003 | testType: serverTest, |
| 3004 | name: "OCSPStapling-Server", |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3005 | expectedOCSPResponse: testOCSPResponse, |
| 3006 | flags: []string{ |
| 3007 | "-ocsp-response", |
| 3008 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
| 3009 | }, |
Paul Lietar | 62be8ac | 2015-09-16 10:03:30 +0100 | [diff] [blame] | 3010 | resumeSession: true, |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3011 | }) |
| 3012 | |
Paul Lietar | 8f1c268 | 2015-08-18 12:21:54 +0100 | [diff] [blame] | 3013 | tests = append(tests, testCase{ |
| 3014 | testType: clientTest, |
| 3015 | name: "CertificateVerificationSucceed", |
| 3016 | flags: []string{ |
| 3017 | "-verify-peer", |
| 3018 | }, |
| 3019 | }) |
| 3020 | |
| 3021 | tests = append(tests, testCase{ |
| 3022 | testType: clientTest, |
| 3023 | name: "CertificateVerificationFail", |
| 3024 | flags: []string{ |
| 3025 | "-verify-fail", |
| 3026 | "-verify-peer", |
| 3027 | }, |
| 3028 | shouldFail: true, |
| 3029 | expectedError: ":CERTIFICATE_VERIFY_FAILED:", |
| 3030 | }) |
| 3031 | |
| 3032 | tests = append(tests, testCase{ |
| 3033 | testType: clientTest, |
| 3034 | name: "CertificateVerificationSoftFail", |
| 3035 | flags: []string{ |
| 3036 | "-verify-fail", |
| 3037 | "-expect-verify-result", |
| 3038 | }, |
| 3039 | }) |
| 3040 | |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3041 | if protocol == tls { |
| 3042 | tests = append(tests, testCase{ |
| 3043 | name: "Renegotiate-Client", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 3044 | renegotiate: 1, |
| 3045 | flags: []string{ |
| 3046 | "-renegotiate-freely", |
| 3047 | "-expect-total-renegotiations", "1", |
| 3048 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3049 | }) |
| 3050 | // NPN on client and server; results in post-handshake message. |
| 3051 | tests = append(tests, testCase{ |
| 3052 | name: "NPN-Client", |
| 3053 | config: Config{ |
| 3054 | NextProtos: []string{"foo"}, |
| 3055 | }, |
| 3056 | flags: []string{"-select-next-proto", "foo"}, |
| 3057 | expectedNextProto: "foo", |
| 3058 | expectedNextProtoType: npn, |
| 3059 | }) |
| 3060 | tests = append(tests, testCase{ |
| 3061 | testType: serverTest, |
| 3062 | name: "NPN-Server", |
| 3063 | config: Config{ |
| 3064 | NextProtos: []string{"bar"}, |
| 3065 | }, |
| 3066 | flags: []string{ |
| 3067 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 3068 | "-expect-next-proto", "bar", |
| 3069 | }, |
| 3070 | expectedNextProto: "bar", |
| 3071 | expectedNextProtoType: npn, |
| 3072 | }) |
| 3073 | |
| 3074 | // TODO(davidben): Add tests for when False Start doesn't trigger. |
| 3075 | |
| 3076 | // Client does False Start and negotiates NPN. |
| 3077 | tests = append(tests, testCase{ |
| 3078 | name: "FalseStart", |
| 3079 | config: Config{ |
| 3080 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3081 | NextProtos: []string{"foo"}, |
| 3082 | Bugs: ProtocolBugs{ |
| 3083 | ExpectFalseStart: true, |
| 3084 | }, |
| 3085 | }, |
| 3086 | flags: []string{ |
| 3087 | "-false-start", |
| 3088 | "-select-next-proto", "foo", |
| 3089 | }, |
| 3090 | shimWritesFirst: true, |
| 3091 | resumeSession: true, |
| 3092 | }) |
| 3093 | |
| 3094 | // Client does False Start and negotiates ALPN. |
| 3095 | tests = append(tests, testCase{ |
| 3096 | name: "FalseStart-ALPN", |
| 3097 | config: Config{ |
| 3098 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3099 | NextProtos: []string{"foo"}, |
| 3100 | Bugs: ProtocolBugs{ |
| 3101 | ExpectFalseStart: true, |
| 3102 | }, |
| 3103 | }, |
| 3104 | flags: []string{ |
| 3105 | "-false-start", |
| 3106 | "-advertise-alpn", "\x03foo", |
| 3107 | }, |
| 3108 | shimWritesFirst: true, |
| 3109 | resumeSession: true, |
| 3110 | }) |
| 3111 | |
| 3112 | // Client does False Start but doesn't explicitly call |
| 3113 | // SSL_connect. |
| 3114 | tests = append(tests, testCase{ |
| 3115 | name: "FalseStart-Implicit", |
| 3116 | config: Config{ |
| 3117 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3118 | NextProtos: []string{"foo"}, |
| 3119 | }, |
| 3120 | flags: []string{ |
| 3121 | "-implicit-handshake", |
| 3122 | "-false-start", |
| 3123 | "-advertise-alpn", "\x03foo", |
| 3124 | }, |
| 3125 | }) |
| 3126 | |
| 3127 | // False Start without session tickets. |
| 3128 | tests = append(tests, testCase{ |
| 3129 | name: "FalseStart-SessionTicketsDisabled", |
| 3130 | config: Config{ |
| 3131 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3132 | NextProtos: []string{"foo"}, |
| 3133 | SessionTicketsDisabled: true, |
| 3134 | Bugs: ProtocolBugs{ |
| 3135 | ExpectFalseStart: true, |
| 3136 | }, |
| 3137 | }, |
| 3138 | flags: []string{ |
| 3139 | "-false-start", |
| 3140 | "-select-next-proto", "foo", |
| 3141 | }, |
| 3142 | shimWritesFirst: true, |
| 3143 | }) |
| 3144 | |
| 3145 | // Server parses a V2ClientHello. |
| 3146 | tests = append(tests, testCase{ |
| 3147 | testType: serverTest, |
| 3148 | name: "SendV2ClientHello", |
| 3149 | config: Config{ |
| 3150 | // Choose a cipher suite that does not involve |
| 3151 | // elliptic curves, so no extensions are |
| 3152 | // involved. |
| 3153 | CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA}, |
| 3154 | Bugs: ProtocolBugs{ |
| 3155 | SendV2ClientHello: true, |
| 3156 | }, |
| 3157 | }, |
| 3158 | }) |
| 3159 | |
| 3160 | // Client sends a Channel ID. |
| 3161 | tests = append(tests, testCase{ |
| 3162 | name: "ChannelID-Client", |
| 3163 | config: Config{ |
| 3164 | RequestChannelID: true, |
| 3165 | }, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 3166 | flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)}, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3167 | resumeSession: true, |
| 3168 | expectChannelID: true, |
| 3169 | }) |
| 3170 | |
| 3171 | // Server accepts a Channel ID. |
| 3172 | tests = append(tests, testCase{ |
| 3173 | testType: serverTest, |
| 3174 | name: "ChannelID-Server", |
| 3175 | config: Config{ |
| 3176 | ChannelID: channelIDKey, |
| 3177 | }, |
| 3178 | flags: []string{ |
| 3179 | "-expect-channel-id", |
| 3180 | base64.StdEncoding.EncodeToString(channelIDBytes), |
| 3181 | }, |
| 3182 | resumeSession: true, |
| 3183 | expectChannelID: true, |
| 3184 | }) |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 3185 | |
| 3186 | // Bidirectional shutdown with the runner initiating. |
| 3187 | tests = append(tests, testCase{ |
| 3188 | name: "Shutdown-Runner", |
| 3189 | config: Config{ |
| 3190 | Bugs: ProtocolBugs{ |
| 3191 | ExpectCloseNotify: true, |
| 3192 | }, |
| 3193 | }, |
| 3194 | flags: []string{"-check-close-notify"}, |
| 3195 | }) |
| 3196 | |
| 3197 | // Bidirectional shutdown with the shim initiating. The runner, |
| 3198 | // in the meantime, sends garbage before the close_notify which |
| 3199 | // the shim must ignore. |
| 3200 | tests = append(tests, testCase{ |
| 3201 | name: "Shutdown-Shim", |
| 3202 | config: Config{ |
| 3203 | Bugs: ProtocolBugs{ |
| 3204 | ExpectCloseNotify: true, |
| 3205 | }, |
| 3206 | }, |
| 3207 | shimShutsDown: true, |
| 3208 | sendEmptyRecords: 1, |
| 3209 | sendWarningAlerts: 1, |
| 3210 | flags: []string{"-check-close-notify"}, |
| 3211 | }) |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3212 | } else { |
| 3213 | tests = append(tests, testCase{ |
| 3214 | name: "SkipHelloVerifyRequest", |
| 3215 | config: Config{ |
| 3216 | Bugs: ProtocolBugs{ |
| 3217 | SkipHelloVerifyRequest: true, |
| 3218 | }, |
| 3219 | }, |
| 3220 | }) |
| 3221 | } |
| 3222 | |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3223 | for _, test := range tests { |
| 3224 | test.protocol = protocol |
David Benjamin | 16285ea | 2015-11-03 15:39:45 -0500 | [diff] [blame] | 3225 | if protocol == dtls { |
| 3226 | test.name += "-DTLS" |
| 3227 | } |
| 3228 | if async { |
| 3229 | test.name += "-Async" |
| 3230 | test.flags = append(test.flags, "-async") |
| 3231 | } else { |
| 3232 | test.name += "-Sync" |
| 3233 | } |
| 3234 | if splitHandshake { |
| 3235 | test.name += "-SplitHandshakeRecords" |
| 3236 | test.config.Bugs.MaxHandshakeRecordLength = 1 |
| 3237 | if protocol == dtls { |
| 3238 | test.config.Bugs.MaxPacketLength = 256 |
| 3239 | test.flags = append(test.flags, "-mtu", "256") |
| 3240 | } |
| 3241 | } |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3242 | testCases = append(testCases, test) |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 3243 | } |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 3244 | } |
| 3245 | |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 3246 | func addDDoSCallbackTests() { |
| 3247 | // DDoS callback. |
| 3248 | |
| 3249 | for _, resume := range []bool{false, true} { |
| 3250 | suffix := "Resume" |
| 3251 | if resume { |
| 3252 | suffix = "No" + suffix |
| 3253 | } |
| 3254 | |
| 3255 | testCases = append(testCases, testCase{ |
| 3256 | testType: serverTest, |
| 3257 | name: "Server-DDoS-OK-" + suffix, |
| 3258 | flags: []string{"-install-ddos-callback"}, |
| 3259 | resumeSession: resume, |
| 3260 | }) |
| 3261 | |
| 3262 | failFlag := "-fail-ddos-callback" |
| 3263 | if resume { |
| 3264 | failFlag = "-fail-second-ddos-callback" |
| 3265 | } |
| 3266 | testCases = append(testCases, testCase{ |
| 3267 | testType: serverTest, |
| 3268 | name: "Server-DDoS-Reject-" + suffix, |
| 3269 | flags: []string{"-install-ddos-callback", failFlag}, |
| 3270 | resumeSession: resume, |
| 3271 | shouldFail: true, |
| 3272 | expectedError: ":CONNECTION_REJECTED:", |
| 3273 | }) |
| 3274 | } |
| 3275 | } |
| 3276 | |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 3277 | func addVersionNegotiationTests() { |
| 3278 | for i, shimVers := range tlsVersions { |
| 3279 | // Assemble flags to disable all newer versions on the shim. |
| 3280 | var flags []string |
| 3281 | for _, vers := range tlsVersions[i+1:] { |
| 3282 | flags = append(flags, vers.flag) |
| 3283 | } |
| 3284 | |
| 3285 | for _, runnerVers := range tlsVersions { |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3286 | protocols := []protocol{tls} |
| 3287 | if runnerVers.hasDTLS && shimVers.hasDTLS { |
| 3288 | protocols = append(protocols, dtls) |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 3289 | } |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3290 | for _, protocol := range protocols { |
| 3291 | expectedVersion := shimVers.version |
| 3292 | if runnerVers.version < shimVers.version { |
| 3293 | expectedVersion = runnerVers.version |
| 3294 | } |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 3295 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3296 | suffix := shimVers.name + "-" + runnerVers.name |
| 3297 | if protocol == dtls { |
| 3298 | suffix += "-DTLS" |
| 3299 | } |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 3300 | |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 3301 | shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls))) |
| 3302 | |
David Benjamin | 1e29a6b | 2014-12-10 02:27:24 -0500 | [diff] [blame] | 3303 | clientVers := shimVers.version |
| 3304 | if clientVers > VersionTLS10 { |
| 3305 | clientVers = VersionTLS10 |
| 3306 | } |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3307 | testCases = append(testCases, testCase{ |
| 3308 | protocol: protocol, |
| 3309 | testType: clientTest, |
| 3310 | name: "VersionNegotiation-Client-" + suffix, |
| 3311 | config: Config{ |
| 3312 | MaxVersion: runnerVers.version, |
David Benjamin | 1e29a6b | 2014-12-10 02:27:24 -0500 | [diff] [blame] | 3313 | Bugs: ProtocolBugs{ |
| 3314 | ExpectInitialRecordVersion: clientVers, |
| 3315 | }, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3316 | }, |
| 3317 | flags: flags, |
| 3318 | expectedVersion: expectedVersion, |
| 3319 | }) |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 3320 | testCases = append(testCases, testCase{ |
| 3321 | protocol: protocol, |
| 3322 | testType: clientTest, |
| 3323 | name: "VersionNegotiation-Client2-" + suffix, |
| 3324 | config: Config{ |
| 3325 | MaxVersion: runnerVers.version, |
| 3326 | Bugs: ProtocolBugs{ |
| 3327 | ExpectInitialRecordVersion: clientVers, |
| 3328 | }, |
| 3329 | }, |
| 3330 | flags: []string{"-max-version", shimVersFlag}, |
| 3331 | expectedVersion: expectedVersion, |
| 3332 | }) |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3333 | |
| 3334 | testCases = append(testCases, testCase{ |
| 3335 | protocol: protocol, |
| 3336 | testType: serverTest, |
| 3337 | name: "VersionNegotiation-Server-" + suffix, |
| 3338 | config: Config{ |
| 3339 | MaxVersion: runnerVers.version, |
David Benjamin | 1e29a6b | 2014-12-10 02:27:24 -0500 | [diff] [blame] | 3340 | Bugs: ProtocolBugs{ |
| 3341 | ExpectInitialRecordVersion: expectedVersion, |
| 3342 | }, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3343 | }, |
| 3344 | flags: flags, |
| 3345 | expectedVersion: expectedVersion, |
| 3346 | }) |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 3347 | testCases = append(testCases, testCase{ |
| 3348 | protocol: protocol, |
| 3349 | testType: serverTest, |
| 3350 | name: "VersionNegotiation-Server2-" + suffix, |
| 3351 | config: Config{ |
| 3352 | MaxVersion: runnerVers.version, |
| 3353 | Bugs: ProtocolBugs{ |
| 3354 | ExpectInitialRecordVersion: expectedVersion, |
| 3355 | }, |
| 3356 | }, |
| 3357 | flags: []string{"-max-version", shimVersFlag}, |
| 3358 | expectedVersion: expectedVersion, |
| 3359 | }) |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3360 | } |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 3361 | } |
| 3362 | } |
| 3363 | } |
| 3364 | |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 3365 | func addMinimumVersionTests() { |
| 3366 | for i, shimVers := range tlsVersions { |
| 3367 | // Assemble flags to disable all older versions on the shim. |
| 3368 | var flags []string |
| 3369 | for _, vers := range tlsVersions[:i] { |
| 3370 | flags = append(flags, vers.flag) |
| 3371 | } |
| 3372 | |
| 3373 | for _, runnerVers := range tlsVersions { |
| 3374 | protocols := []protocol{tls} |
| 3375 | if runnerVers.hasDTLS && shimVers.hasDTLS { |
| 3376 | protocols = append(protocols, dtls) |
| 3377 | } |
| 3378 | for _, protocol := range protocols { |
| 3379 | suffix := shimVers.name + "-" + runnerVers.name |
| 3380 | if protocol == dtls { |
| 3381 | suffix += "-DTLS" |
| 3382 | } |
| 3383 | shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls))) |
| 3384 | |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 3385 | var expectedVersion uint16 |
| 3386 | var shouldFail bool |
| 3387 | var expectedError string |
David Benjamin | 87909c0 | 2014-12-13 01:55:01 -0500 | [diff] [blame] | 3388 | var expectedLocalError string |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 3389 | if runnerVers.version >= shimVers.version { |
| 3390 | expectedVersion = runnerVers.version |
| 3391 | } else { |
| 3392 | shouldFail = true |
| 3393 | expectedError = ":UNSUPPORTED_PROTOCOL:" |
David Benjamin | a565d29 | 2015-12-30 16:51:32 -0500 | [diff] [blame] | 3394 | expectedLocalError = "remote error: protocol version not supported" |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 3395 | } |
| 3396 | |
| 3397 | testCases = append(testCases, testCase{ |
| 3398 | protocol: protocol, |
| 3399 | testType: clientTest, |
| 3400 | name: "MinimumVersion-Client-" + suffix, |
| 3401 | config: Config{ |
| 3402 | MaxVersion: runnerVers.version, |
| 3403 | }, |
David Benjamin | 87909c0 | 2014-12-13 01:55:01 -0500 | [diff] [blame] | 3404 | flags: flags, |
| 3405 | expectedVersion: expectedVersion, |
| 3406 | shouldFail: shouldFail, |
| 3407 | expectedError: expectedError, |
| 3408 | expectedLocalError: expectedLocalError, |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 3409 | }) |
| 3410 | testCases = append(testCases, testCase{ |
| 3411 | protocol: protocol, |
| 3412 | testType: clientTest, |
| 3413 | name: "MinimumVersion-Client2-" + suffix, |
| 3414 | config: Config{ |
| 3415 | MaxVersion: runnerVers.version, |
| 3416 | }, |
David Benjamin | 87909c0 | 2014-12-13 01:55:01 -0500 | [diff] [blame] | 3417 | flags: []string{"-min-version", shimVersFlag}, |
| 3418 | expectedVersion: expectedVersion, |
| 3419 | shouldFail: shouldFail, |
| 3420 | expectedError: expectedError, |
| 3421 | expectedLocalError: expectedLocalError, |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 3422 | }) |
| 3423 | |
| 3424 | testCases = append(testCases, testCase{ |
| 3425 | protocol: protocol, |
| 3426 | testType: serverTest, |
| 3427 | name: "MinimumVersion-Server-" + suffix, |
| 3428 | config: Config{ |
| 3429 | MaxVersion: runnerVers.version, |
| 3430 | }, |
David Benjamin | 87909c0 | 2014-12-13 01:55:01 -0500 | [diff] [blame] | 3431 | flags: flags, |
| 3432 | expectedVersion: expectedVersion, |
| 3433 | shouldFail: shouldFail, |
| 3434 | expectedError: expectedError, |
| 3435 | expectedLocalError: expectedLocalError, |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 3436 | }) |
| 3437 | testCases = append(testCases, testCase{ |
| 3438 | protocol: protocol, |
| 3439 | testType: serverTest, |
| 3440 | name: "MinimumVersion-Server2-" + suffix, |
| 3441 | config: Config{ |
| 3442 | MaxVersion: runnerVers.version, |
| 3443 | }, |
David Benjamin | 87909c0 | 2014-12-13 01:55:01 -0500 | [diff] [blame] | 3444 | flags: []string{"-min-version", shimVersFlag}, |
| 3445 | expectedVersion: expectedVersion, |
| 3446 | shouldFail: shouldFail, |
| 3447 | expectedError: expectedError, |
| 3448 | expectedLocalError: expectedLocalError, |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 3449 | }) |
| 3450 | } |
| 3451 | } |
| 3452 | } |
| 3453 | } |
| 3454 | |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 3455 | func addExtensionTests() { |
| 3456 | testCases = append(testCases, testCase{ |
| 3457 | testType: clientTest, |
| 3458 | name: "DuplicateExtensionClient", |
| 3459 | config: Config{ |
| 3460 | Bugs: ProtocolBugs{ |
| 3461 | DuplicateExtension: true, |
| 3462 | }, |
| 3463 | }, |
| 3464 | shouldFail: true, |
| 3465 | expectedLocalError: "remote error: error decoding message", |
| 3466 | }) |
| 3467 | testCases = append(testCases, testCase{ |
| 3468 | testType: serverTest, |
| 3469 | name: "DuplicateExtensionServer", |
| 3470 | config: Config{ |
| 3471 | Bugs: ProtocolBugs{ |
| 3472 | DuplicateExtension: true, |
| 3473 | }, |
| 3474 | }, |
| 3475 | shouldFail: true, |
| 3476 | expectedLocalError: "remote error: error decoding message", |
| 3477 | }) |
| 3478 | testCases = append(testCases, testCase{ |
| 3479 | testType: clientTest, |
| 3480 | name: "ServerNameExtensionClient", |
| 3481 | config: Config{ |
| 3482 | Bugs: ProtocolBugs{ |
| 3483 | ExpectServerName: "example.com", |
| 3484 | }, |
| 3485 | }, |
| 3486 | flags: []string{"-host-name", "example.com"}, |
| 3487 | }) |
| 3488 | testCases = append(testCases, testCase{ |
| 3489 | testType: clientTest, |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 3490 | name: "ServerNameExtensionClientMismatch", |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 3491 | config: Config{ |
| 3492 | Bugs: ProtocolBugs{ |
| 3493 | ExpectServerName: "mismatch.com", |
| 3494 | }, |
| 3495 | }, |
| 3496 | flags: []string{"-host-name", "example.com"}, |
| 3497 | shouldFail: true, |
| 3498 | expectedLocalError: "tls: unexpected server name", |
| 3499 | }) |
| 3500 | testCases = append(testCases, testCase{ |
| 3501 | testType: clientTest, |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 3502 | name: "ServerNameExtensionClientMissing", |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 3503 | config: Config{ |
| 3504 | Bugs: ProtocolBugs{ |
| 3505 | ExpectServerName: "missing.com", |
| 3506 | }, |
| 3507 | }, |
| 3508 | shouldFail: true, |
| 3509 | expectedLocalError: "tls: unexpected server name", |
| 3510 | }) |
| 3511 | testCases = append(testCases, testCase{ |
| 3512 | testType: serverTest, |
| 3513 | name: "ServerNameExtensionServer", |
| 3514 | config: Config{ |
| 3515 | ServerName: "example.com", |
| 3516 | }, |
| 3517 | flags: []string{"-expect-server-name", "example.com"}, |
| 3518 | resumeSession: true, |
| 3519 | }) |
David Benjamin | ae2888f | 2014-09-06 12:58:58 -0400 | [diff] [blame] | 3520 | testCases = append(testCases, testCase{ |
| 3521 | testType: clientTest, |
| 3522 | name: "ALPNClient", |
| 3523 | config: Config{ |
| 3524 | NextProtos: []string{"foo"}, |
| 3525 | }, |
| 3526 | flags: []string{ |
| 3527 | "-advertise-alpn", "\x03foo\x03bar\x03baz", |
| 3528 | "-expect-alpn", "foo", |
| 3529 | }, |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 3530 | expectedNextProto: "foo", |
| 3531 | expectedNextProtoType: alpn, |
| 3532 | resumeSession: true, |
David Benjamin | ae2888f | 2014-09-06 12:58:58 -0400 | [diff] [blame] | 3533 | }) |
| 3534 | testCases = append(testCases, testCase{ |
| 3535 | testType: serverTest, |
| 3536 | name: "ALPNServer", |
| 3537 | config: Config{ |
| 3538 | NextProtos: []string{"foo", "bar", "baz"}, |
| 3539 | }, |
| 3540 | flags: []string{ |
| 3541 | "-expect-advertised-alpn", "\x03foo\x03bar\x03baz", |
| 3542 | "-select-alpn", "foo", |
| 3543 | }, |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 3544 | expectedNextProto: "foo", |
| 3545 | expectedNextProtoType: alpn, |
| 3546 | resumeSession: true, |
| 3547 | }) |
| 3548 | // Test that the server prefers ALPN over NPN. |
| 3549 | testCases = append(testCases, testCase{ |
| 3550 | testType: serverTest, |
| 3551 | name: "ALPNServer-Preferred", |
| 3552 | config: Config{ |
| 3553 | NextProtos: []string{"foo", "bar", "baz"}, |
| 3554 | }, |
| 3555 | flags: []string{ |
| 3556 | "-expect-advertised-alpn", "\x03foo\x03bar\x03baz", |
| 3557 | "-select-alpn", "foo", |
| 3558 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 3559 | }, |
| 3560 | expectedNextProto: "foo", |
| 3561 | expectedNextProtoType: alpn, |
| 3562 | resumeSession: true, |
| 3563 | }) |
| 3564 | testCases = append(testCases, testCase{ |
| 3565 | testType: serverTest, |
| 3566 | name: "ALPNServer-Preferred-Swapped", |
| 3567 | config: Config{ |
| 3568 | NextProtos: []string{"foo", "bar", "baz"}, |
| 3569 | Bugs: ProtocolBugs{ |
| 3570 | SwapNPNAndALPN: true, |
| 3571 | }, |
| 3572 | }, |
| 3573 | flags: []string{ |
| 3574 | "-expect-advertised-alpn", "\x03foo\x03bar\x03baz", |
| 3575 | "-select-alpn", "foo", |
| 3576 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 3577 | }, |
| 3578 | expectedNextProto: "foo", |
| 3579 | expectedNextProtoType: alpn, |
| 3580 | resumeSession: true, |
David Benjamin | ae2888f | 2014-09-06 12:58:58 -0400 | [diff] [blame] | 3581 | }) |
Adam Langley | efb0e16 | 2015-07-09 11:35:04 -0700 | [diff] [blame] | 3582 | var emptyString string |
| 3583 | testCases = append(testCases, testCase{ |
| 3584 | testType: clientTest, |
| 3585 | name: "ALPNClient-EmptyProtocolName", |
| 3586 | config: Config{ |
| 3587 | NextProtos: []string{""}, |
| 3588 | Bugs: ProtocolBugs{ |
| 3589 | // A server returning an empty ALPN protocol |
| 3590 | // should be rejected. |
| 3591 | ALPNProtocol: &emptyString, |
| 3592 | }, |
| 3593 | }, |
| 3594 | flags: []string{ |
| 3595 | "-advertise-alpn", "\x03foo", |
| 3596 | }, |
Doug Hogan | ecdf7f9 | 2015-07-09 18:27:28 -0700 | [diff] [blame] | 3597 | shouldFail: true, |
Adam Langley | efb0e16 | 2015-07-09 11:35:04 -0700 | [diff] [blame] | 3598 | expectedError: ":PARSE_TLSEXT:", |
| 3599 | }) |
| 3600 | testCases = append(testCases, testCase{ |
| 3601 | testType: serverTest, |
| 3602 | name: "ALPNServer-EmptyProtocolName", |
| 3603 | config: Config{ |
| 3604 | // A ClientHello containing an empty ALPN protocol |
| 3605 | // should be rejected. |
| 3606 | NextProtos: []string{"foo", "", "baz"}, |
| 3607 | }, |
| 3608 | flags: []string{ |
| 3609 | "-select-alpn", "foo", |
| 3610 | }, |
Doug Hogan | ecdf7f9 | 2015-07-09 18:27:28 -0700 | [diff] [blame] | 3611 | shouldFail: true, |
Adam Langley | efb0e16 | 2015-07-09 11:35:04 -0700 | [diff] [blame] | 3612 | expectedError: ":PARSE_TLSEXT:", |
| 3613 | }) |
David Benjamin | 76c2efc | 2015-08-31 14:24:29 -0400 | [diff] [blame] | 3614 | // Test that negotiating both NPN and ALPN is forbidden. |
| 3615 | testCases = append(testCases, testCase{ |
| 3616 | name: "NegotiateALPNAndNPN", |
| 3617 | config: Config{ |
| 3618 | NextProtos: []string{"foo", "bar", "baz"}, |
| 3619 | Bugs: ProtocolBugs{ |
| 3620 | NegotiateALPNAndNPN: true, |
| 3621 | }, |
| 3622 | }, |
| 3623 | flags: []string{ |
| 3624 | "-advertise-alpn", "\x03foo", |
| 3625 | "-select-next-proto", "foo", |
| 3626 | }, |
| 3627 | shouldFail: true, |
| 3628 | expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:", |
| 3629 | }) |
| 3630 | testCases = append(testCases, testCase{ |
| 3631 | name: "NegotiateALPNAndNPN-Swapped", |
| 3632 | config: Config{ |
| 3633 | NextProtos: []string{"foo", "bar", "baz"}, |
| 3634 | Bugs: ProtocolBugs{ |
| 3635 | NegotiateALPNAndNPN: true, |
| 3636 | SwapNPNAndALPN: true, |
| 3637 | }, |
| 3638 | }, |
| 3639 | flags: []string{ |
| 3640 | "-advertise-alpn", "\x03foo", |
| 3641 | "-select-next-proto", "foo", |
| 3642 | }, |
| 3643 | shouldFail: true, |
| 3644 | expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:", |
| 3645 | }) |
David Benjamin | 091c4b9 | 2015-10-26 13:33:21 -0400 | [diff] [blame] | 3646 | // Test that NPN can be disabled with SSL_OP_DISABLE_NPN. |
| 3647 | testCases = append(testCases, testCase{ |
| 3648 | name: "DisableNPN", |
| 3649 | config: Config{ |
| 3650 | NextProtos: []string{"foo"}, |
| 3651 | }, |
| 3652 | flags: []string{ |
| 3653 | "-select-next-proto", "foo", |
| 3654 | "-disable-npn", |
| 3655 | }, |
| 3656 | expectNoNextProto: true, |
| 3657 | }) |
Adam Langley | 3831173 | 2014-10-16 19:04:35 -0700 | [diff] [blame] | 3658 | // Resume with a corrupt ticket. |
| 3659 | testCases = append(testCases, testCase{ |
| 3660 | testType: serverTest, |
| 3661 | name: "CorruptTicket", |
| 3662 | config: Config{ |
| 3663 | Bugs: ProtocolBugs{ |
| 3664 | CorruptTicket: true, |
| 3665 | }, |
| 3666 | }, |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 3667 | resumeSession: true, |
| 3668 | expectResumeRejected: true, |
Adam Langley | 3831173 | 2014-10-16 19:04:35 -0700 | [diff] [blame] | 3669 | }) |
David Benjamin | d98452d | 2015-06-16 14:16:23 -0400 | [diff] [blame] | 3670 | // Test the ticket callback, with and without renewal. |
| 3671 | testCases = append(testCases, testCase{ |
| 3672 | testType: serverTest, |
| 3673 | name: "TicketCallback", |
| 3674 | resumeSession: true, |
| 3675 | flags: []string{"-use-ticket-callback"}, |
| 3676 | }) |
| 3677 | testCases = append(testCases, testCase{ |
| 3678 | testType: serverTest, |
| 3679 | name: "TicketCallback-Renew", |
| 3680 | config: Config{ |
| 3681 | Bugs: ProtocolBugs{ |
| 3682 | ExpectNewTicket: true, |
| 3683 | }, |
| 3684 | }, |
| 3685 | flags: []string{"-use-ticket-callback", "-renew-ticket"}, |
| 3686 | resumeSession: true, |
| 3687 | }) |
Adam Langley | 3831173 | 2014-10-16 19:04:35 -0700 | [diff] [blame] | 3688 | // Resume with an oversized session id. |
| 3689 | testCases = append(testCases, testCase{ |
| 3690 | testType: serverTest, |
| 3691 | name: "OversizedSessionId", |
| 3692 | config: Config{ |
| 3693 | Bugs: ProtocolBugs{ |
| 3694 | OversizedSessionId: true, |
| 3695 | }, |
| 3696 | }, |
| 3697 | resumeSession: true, |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 3698 | shouldFail: true, |
Adam Langley | 3831173 | 2014-10-16 19:04:35 -0700 | [diff] [blame] | 3699 | expectedError: ":DECODE_ERROR:", |
| 3700 | }) |
David Benjamin | ca6c826 | 2014-11-15 19:06:08 -0500 | [diff] [blame] | 3701 | // Basic DTLS-SRTP tests. Include fake profiles to ensure they |
| 3702 | // are ignored. |
| 3703 | testCases = append(testCases, testCase{ |
| 3704 | protocol: dtls, |
| 3705 | name: "SRTP-Client", |
| 3706 | config: Config{ |
| 3707 | SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42}, |
| 3708 | }, |
| 3709 | flags: []string{ |
| 3710 | "-srtp-profiles", |
| 3711 | "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32", |
| 3712 | }, |
| 3713 | expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80, |
| 3714 | }) |
| 3715 | testCases = append(testCases, testCase{ |
| 3716 | protocol: dtls, |
| 3717 | testType: serverTest, |
| 3718 | name: "SRTP-Server", |
| 3719 | config: Config{ |
| 3720 | SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42}, |
| 3721 | }, |
| 3722 | flags: []string{ |
| 3723 | "-srtp-profiles", |
| 3724 | "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32", |
| 3725 | }, |
| 3726 | expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80, |
| 3727 | }) |
| 3728 | // Test that the MKI is ignored. |
| 3729 | testCases = append(testCases, testCase{ |
| 3730 | protocol: dtls, |
| 3731 | testType: serverTest, |
| 3732 | name: "SRTP-Server-IgnoreMKI", |
| 3733 | config: Config{ |
| 3734 | SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80}, |
| 3735 | Bugs: ProtocolBugs{ |
| 3736 | SRTPMasterKeyIdentifer: "bogus", |
| 3737 | }, |
| 3738 | }, |
| 3739 | flags: []string{ |
| 3740 | "-srtp-profiles", |
| 3741 | "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32", |
| 3742 | }, |
| 3743 | expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80, |
| 3744 | }) |
| 3745 | // Test that SRTP isn't negotiated on the server if there were |
| 3746 | // no matching profiles. |
| 3747 | testCases = append(testCases, testCase{ |
| 3748 | protocol: dtls, |
| 3749 | testType: serverTest, |
| 3750 | name: "SRTP-Server-NoMatch", |
| 3751 | config: Config{ |
| 3752 | SRTPProtectionProfiles: []uint16{100, 101, 102}, |
| 3753 | }, |
| 3754 | flags: []string{ |
| 3755 | "-srtp-profiles", |
| 3756 | "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32", |
| 3757 | }, |
| 3758 | expectedSRTPProtectionProfile: 0, |
| 3759 | }) |
| 3760 | // Test that the server returning an invalid SRTP profile is |
| 3761 | // flagged as an error by the client. |
| 3762 | testCases = append(testCases, testCase{ |
| 3763 | protocol: dtls, |
| 3764 | name: "SRTP-Client-NoMatch", |
| 3765 | config: Config{ |
| 3766 | Bugs: ProtocolBugs{ |
| 3767 | SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32, |
| 3768 | }, |
| 3769 | }, |
| 3770 | flags: []string{ |
| 3771 | "-srtp-profiles", |
| 3772 | "SRTP_AES128_CM_SHA1_80", |
| 3773 | }, |
| 3774 | shouldFail: true, |
| 3775 | expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:", |
| 3776 | }) |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3777 | // Test SCT list. |
David Benjamin | 61f9527 | 2014-11-25 01:55:35 -0500 | [diff] [blame] | 3778 | testCases = append(testCases, testCase{ |
David Benjamin | c057762 | 2015-09-12 18:28:38 -0400 | [diff] [blame] | 3779 | name: "SignedCertificateTimestampList-Client", |
Paul Lietar | 4fac72e | 2015-09-09 13:44:55 +0100 | [diff] [blame] | 3780 | testType: clientTest, |
David Benjamin | 61f9527 | 2014-11-25 01:55:35 -0500 | [diff] [blame] | 3781 | flags: []string{ |
| 3782 | "-enable-signed-cert-timestamps", |
| 3783 | "-expect-signed-cert-timestamps", |
| 3784 | base64.StdEncoding.EncodeToString(testSCTList), |
| 3785 | }, |
Paul Lietar | 62be8ac | 2015-09-16 10:03:30 +0100 | [diff] [blame] | 3786 | resumeSession: true, |
David Benjamin | 61f9527 | 2014-11-25 01:55:35 -0500 | [diff] [blame] | 3787 | }) |
Adam Langley | 33ad2b5 | 2015-07-20 17:43:53 -0700 | [diff] [blame] | 3788 | testCases = append(testCases, testCase{ |
David Benjamin | c057762 | 2015-09-12 18:28:38 -0400 | [diff] [blame] | 3789 | name: "SignedCertificateTimestampList-Server", |
Paul Lietar | 4fac72e | 2015-09-09 13:44:55 +0100 | [diff] [blame] | 3790 | testType: serverTest, |
| 3791 | flags: []string{ |
| 3792 | "-signed-cert-timestamps", |
| 3793 | base64.StdEncoding.EncodeToString(testSCTList), |
| 3794 | }, |
| 3795 | expectedSCTList: testSCTList, |
Paul Lietar | 62be8ac | 2015-09-16 10:03:30 +0100 | [diff] [blame] | 3796 | resumeSession: true, |
Paul Lietar | 4fac72e | 2015-09-09 13:44:55 +0100 | [diff] [blame] | 3797 | }) |
| 3798 | testCases = append(testCases, testCase{ |
Adam Langley | 33ad2b5 | 2015-07-20 17:43:53 -0700 | [diff] [blame] | 3799 | testType: clientTest, |
| 3800 | name: "ClientHelloPadding", |
| 3801 | config: Config{ |
| 3802 | Bugs: ProtocolBugs{ |
| 3803 | RequireClientHelloSize: 512, |
| 3804 | }, |
| 3805 | }, |
| 3806 | // This hostname just needs to be long enough to push the |
| 3807 | // ClientHello into F5's danger zone between 256 and 511 bytes |
| 3808 | // long. |
| 3809 | flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"}, |
| 3810 | }) |
David Benjamin | c7ce977 | 2015-10-09 19:32:41 -0400 | [diff] [blame] | 3811 | |
| 3812 | // Extensions should not function in SSL 3.0. |
| 3813 | testCases = append(testCases, testCase{ |
| 3814 | testType: serverTest, |
| 3815 | name: "SSLv3Extensions-NoALPN", |
| 3816 | config: Config{ |
| 3817 | MaxVersion: VersionSSL30, |
| 3818 | NextProtos: []string{"foo", "bar", "baz"}, |
| 3819 | }, |
| 3820 | flags: []string{ |
| 3821 | "-select-alpn", "foo", |
| 3822 | }, |
| 3823 | expectNoNextProto: true, |
| 3824 | }) |
| 3825 | |
| 3826 | // Test session tickets separately as they follow a different codepath. |
| 3827 | testCases = append(testCases, testCase{ |
| 3828 | testType: serverTest, |
| 3829 | name: "SSLv3Extensions-NoTickets", |
| 3830 | config: Config{ |
| 3831 | MaxVersion: VersionSSL30, |
| 3832 | Bugs: ProtocolBugs{ |
| 3833 | // Historically, session tickets in SSL 3.0 |
| 3834 | // failed in different ways depending on whether |
| 3835 | // the client supported renegotiation_info. |
| 3836 | NoRenegotiationInfo: true, |
| 3837 | }, |
| 3838 | }, |
| 3839 | resumeSession: true, |
| 3840 | }) |
| 3841 | testCases = append(testCases, testCase{ |
| 3842 | testType: serverTest, |
| 3843 | name: "SSLv3Extensions-NoTickets2", |
| 3844 | config: Config{ |
| 3845 | MaxVersion: VersionSSL30, |
| 3846 | }, |
| 3847 | resumeSession: true, |
| 3848 | }) |
| 3849 | |
| 3850 | // But SSL 3.0 does send and process renegotiation_info. |
| 3851 | testCases = append(testCases, testCase{ |
| 3852 | testType: serverTest, |
| 3853 | name: "SSLv3Extensions-RenegotiationInfo", |
| 3854 | config: Config{ |
| 3855 | MaxVersion: VersionSSL30, |
| 3856 | Bugs: ProtocolBugs{ |
| 3857 | RequireRenegotiationInfo: true, |
| 3858 | }, |
| 3859 | }, |
| 3860 | }) |
| 3861 | testCases = append(testCases, testCase{ |
| 3862 | testType: serverTest, |
| 3863 | name: "SSLv3Extensions-RenegotiationInfo-SCSV", |
| 3864 | config: Config{ |
| 3865 | MaxVersion: VersionSSL30, |
| 3866 | Bugs: ProtocolBugs{ |
| 3867 | NoRenegotiationInfo: true, |
| 3868 | SendRenegotiationSCSV: true, |
| 3869 | RequireRenegotiationInfo: true, |
| 3870 | }, |
| 3871 | }, |
| 3872 | }) |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 3873 | } |
| 3874 | |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 3875 | func addResumptionVersionTests() { |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 3876 | for _, sessionVers := range tlsVersions { |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 3877 | for _, resumeVers := range tlsVersions { |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3878 | protocols := []protocol{tls} |
| 3879 | if sessionVers.hasDTLS && resumeVers.hasDTLS { |
| 3880 | protocols = append(protocols, dtls) |
David Benjamin | bdf5e72 | 2014-11-11 00:52:15 -0500 | [diff] [blame] | 3881 | } |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3882 | for _, protocol := range protocols { |
| 3883 | suffix := "-" + sessionVers.name + "-" + resumeVers.name |
| 3884 | if protocol == dtls { |
| 3885 | suffix += "-DTLS" |
| 3886 | } |
| 3887 | |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 3888 | if sessionVers.version == resumeVers.version { |
| 3889 | testCases = append(testCases, testCase{ |
| 3890 | protocol: protocol, |
| 3891 | name: "Resume-Client" + suffix, |
| 3892 | resumeSession: true, |
| 3893 | config: Config{ |
| 3894 | MaxVersion: sessionVers.version, |
| 3895 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA}, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3896 | }, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 3897 | expectedVersion: sessionVers.version, |
| 3898 | expectedResumeVersion: resumeVers.version, |
| 3899 | }) |
| 3900 | } else { |
| 3901 | testCases = append(testCases, testCase{ |
| 3902 | protocol: protocol, |
| 3903 | name: "Resume-Client-Mismatch" + suffix, |
| 3904 | resumeSession: true, |
| 3905 | config: Config{ |
| 3906 | MaxVersion: sessionVers.version, |
| 3907 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA}, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3908 | }, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 3909 | expectedVersion: sessionVers.version, |
| 3910 | resumeConfig: &Config{ |
| 3911 | MaxVersion: resumeVers.version, |
| 3912 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA}, |
| 3913 | Bugs: ProtocolBugs{ |
| 3914 | AllowSessionVersionMismatch: true, |
| 3915 | }, |
| 3916 | }, |
| 3917 | expectedResumeVersion: resumeVers.version, |
| 3918 | shouldFail: true, |
| 3919 | expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:", |
| 3920 | }) |
| 3921 | } |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3922 | |
| 3923 | testCases = append(testCases, testCase{ |
| 3924 | protocol: protocol, |
| 3925 | name: "Resume-Client-NoResume" + suffix, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3926 | resumeSession: true, |
| 3927 | config: Config{ |
| 3928 | MaxVersion: sessionVers.version, |
| 3929 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA}, |
| 3930 | }, |
| 3931 | expectedVersion: sessionVers.version, |
| 3932 | resumeConfig: &Config{ |
| 3933 | MaxVersion: resumeVers.version, |
| 3934 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA}, |
| 3935 | }, |
| 3936 | newSessionsOnResume: true, |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 3937 | expectResumeRejected: true, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3938 | expectedResumeVersion: resumeVers.version, |
| 3939 | }) |
| 3940 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3941 | testCases = append(testCases, testCase{ |
| 3942 | protocol: protocol, |
| 3943 | testType: serverTest, |
| 3944 | name: "Resume-Server" + suffix, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3945 | resumeSession: true, |
| 3946 | config: Config{ |
| 3947 | MaxVersion: sessionVers.version, |
| 3948 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA}, |
| 3949 | }, |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 3950 | expectedVersion: sessionVers.version, |
| 3951 | expectResumeRejected: sessionVers.version != resumeVers.version, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3952 | resumeConfig: &Config{ |
| 3953 | MaxVersion: resumeVers.version, |
| 3954 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA}, |
| 3955 | }, |
| 3956 | expectedResumeVersion: resumeVers.version, |
| 3957 | }) |
| 3958 | } |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 3959 | } |
| 3960 | } |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 3961 | |
| 3962 | testCases = append(testCases, testCase{ |
| 3963 | name: "Resume-Client-CipherMismatch", |
| 3964 | resumeSession: true, |
| 3965 | config: Config{ |
| 3966 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 3967 | }, |
| 3968 | resumeConfig: &Config{ |
| 3969 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 3970 | Bugs: ProtocolBugs{ |
| 3971 | SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 3972 | }, |
| 3973 | }, |
| 3974 | shouldFail: true, |
| 3975 | expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:", |
| 3976 | }) |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 3977 | } |
| 3978 | |
Adam Langley | 2ae77d2 | 2014-10-28 17:29:33 -0700 | [diff] [blame] | 3979 | func addRenegotiationTests() { |
David Benjamin | 44d3eed | 2015-05-21 01:29:55 -0400 | [diff] [blame] | 3980 | // Servers cannot renegotiate. |
David Benjamin | b16346b | 2015-04-08 19:16:58 -0400 | [diff] [blame] | 3981 | testCases = append(testCases, testCase{ |
| 3982 | testType: serverTest, |
David Benjamin | 44d3eed | 2015-05-21 01:29:55 -0400 | [diff] [blame] | 3983 | name: "Renegotiate-Server-Forbidden", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 3984 | renegotiate: 1, |
David Benjamin | b16346b | 2015-04-08 19:16:58 -0400 | [diff] [blame] | 3985 | shouldFail: true, |
| 3986 | expectedError: ":NO_RENEGOTIATION:", |
| 3987 | expectedLocalError: "remote error: no renegotiation", |
| 3988 | }) |
Adam Langley | 5021b22 | 2015-06-12 18:27:58 -0700 | [diff] [blame] | 3989 | // The server shouldn't echo the renegotiation extension unless |
| 3990 | // requested by the client. |
| 3991 | testCases = append(testCases, testCase{ |
| 3992 | testType: serverTest, |
| 3993 | name: "Renegotiate-Server-NoExt", |
| 3994 | config: Config{ |
| 3995 | Bugs: ProtocolBugs{ |
| 3996 | NoRenegotiationInfo: true, |
| 3997 | RequireRenegotiationInfo: true, |
| 3998 | }, |
| 3999 | }, |
| 4000 | shouldFail: true, |
| 4001 | expectedLocalError: "renegotiation extension missing", |
| 4002 | }) |
| 4003 | // The renegotiation SCSV should be sufficient for the server to echo |
| 4004 | // the extension. |
| 4005 | testCases = append(testCases, testCase{ |
| 4006 | testType: serverTest, |
| 4007 | name: "Renegotiate-Server-NoExt-SCSV", |
| 4008 | config: Config{ |
| 4009 | Bugs: ProtocolBugs{ |
| 4010 | NoRenegotiationInfo: true, |
| 4011 | SendRenegotiationSCSV: true, |
| 4012 | RequireRenegotiationInfo: true, |
| 4013 | }, |
| 4014 | }, |
| 4015 | }) |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4016 | testCases = append(testCases, testCase{ |
David Benjamin | 4b27d9f | 2015-05-12 22:42:52 -0400 | [diff] [blame] | 4017 | name: "Renegotiate-Client", |
David Benjamin | cdea40c | 2015-03-19 14:09:43 -0400 | [diff] [blame] | 4018 | config: Config{ |
| 4019 | Bugs: ProtocolBugs{ |
David Benjamin | 4b27d9f | 2015-05-12 22:42:52 -0400 | [diff] [blame] | 4020 | FailIfResumeOnRenego: true, |
David Benjamin | cdea40c | 2015-03-19 14:09:43 -0400 | [diff] [blame] | 4021 | }, |
| 4022 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4023 | renegotiate: 1, |
| 4024 | flags: []string{ |
| 4025 | "-renegotiate-freely", |
| 4026 | "-expect-total-renegotiations", "1", |
| 4027 | }, |
David Benjamin | cdea40c | 2015-03-19 14:09:43 -0400 | [diff] [blame] | 4028 | }) |
| 4029 | testCases = append(testCases, testCase{ |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4030 | name: "Renegotiate-Client-EmptyExt", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4031 | renegotiate: 1, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4032 | config: Config{ |
| 4033 | Bugs: ProtocolBugs{ |
| 4034 | EmptyRenegotiationInfo: true, |
| 4035 | }, |
| 4036 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4037 | flags: []string{"-renegotiate-freely"}, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4038 | shouldFail: true, |
| 4039 | expectedError: ":RENEGOTIATION_MISMATCH:", |
| 4040 | }) |
| 4041 | testCases = append(testCases, testCase{ |
| 4042 | name: "Renegotiate-Client-BadExt", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4043 | renegotiate: 1, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4044 | config: Config{ |
| 4045 | Bugs: ProtocolBugs{ |
| 4046 | BadRenegotiationInfo: true, |
| 4047 | }, |
| 4048 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4049 | flags: []string{"-renegotiate-freely"}, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4050 | shouldFail: true, |
| 4051 | expectedError: ":RENEGOTIATION_MISMATCH:", |
| 4052 | }) |
| 4053 | testCases = append(testCases, testCase{ |
David Benjamin | 3e052de | 2015-11-25 20:10:31 -0500 | [diff] [blame] | 4054 | name: "Renegotiate-Client-Downgrade", |
| 4055 | renegotiate: 1, |
| 4056 | config: Config{ |
| 4057 | Bugs: ProtocolBugs{ |
| 4058 | NoRenegotiationInfoAfterInitial: true, |
| 4059 | }, |
| 4060 | }, |
| 4061 | flags: []string{"-renegotiate-freely"}, |
| 4062 | shouldFail: true, |
| 4063 | expectedError: ":RENEGOTIATION_MISMATCH:", |
| 4064 | }) |
| 4065 | testCases = append(testCases, testCase{ |
| 4066 | name: "Renegotiate-Client-Upgrade", |
| 4067 | renegotiate: 1, |
| 4068 | config: Config{ |
| 4069 | Bugs: ProtocolBugs{ |
| 4070 | NoRenegotiationInfoInInitial: true, |
| 4071 | }, |
| 4072 | }, |
| 4073 | flags: []string{"-renegotiate-freely"}, |
| 4074 | shouldFail: true, |
| 4075 | expectedError: ":RENEGOTIATION_MISMATCH:", |
| 4076 | }) |
| 4077 | testCases = append(testCases, testCase{ |
David Benjamin | cff0b90 | 2015-05-15 23:09:47 -0400 | [diff] [blame] | 4078 | name: "Renegotiate-Client-NoExt-Allowed", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4079 | renegotiate: 1, |
David Benjamin | cff0b90 | 2015-05-15 23:09:47 -0400 | [diff] [blame] | 4080 | config: Config{ |
| 4081 | Bugs: ProtocolBugs{ |
| 4082 | NoRenegotiationInfo: true, |
| 4083 | }, |
| 4084 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4085 | flags: []string{ |
| 4086 | "-renegotiate-freely", |
| 4087 | "-expect-total-renegotiations", "1", |
| 4088 | }, |
David Benjamin | cff0b90 | 2015-05-15 23:09:47 -0400 | [diff] [blame] | 4089 | }) |
| 4090 | testCases = append(testCases, testCase{ |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4091 | name: "Renegotiate-Client-SwitchCiphers", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4092 | renegotiate: 1, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4093 | config: Config{ |
| 4094 | CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA}, |
| 4095 | }, |
| 4096 | renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4097 | flags: []string{ |
| 4098 | "-renegotiate-freely", |
| 4099 | "-expect-total-renegotiations", "1", |
| 4100 | }, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4101 | }) |
| 4102 | testCases = append(testCases, testCase{ |
| 4103 | name: "Renegotiate-Client-SwitchCiphers2", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4104 | renegotiate: 1, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4105 | config: Config{ |
| 4106 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 4107 | }, |
| 4108 | renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA}, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4109 | flags: []string{ |
| 4110 | "-renegotiate-freely", |
| 4111 | "-expect-total-renegotiations", "1", |
| 4112 | }, |
David Benjamin | b16346b | 2015-04-08 19:16:58 -0400 | [diff] [blame] | 4113 | }) |
| 4114 | testCases = append(testCases, testCase{ |
David Benjamin | c44b1df | 2014-11-23 12:11:01 -0500 | [diff] [blame] | 4115 | name: "Renegotiate-SameClientVersion", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4116 | renegotiate: 1, |
David Benjamin | c44b1df | 2014-11-23 12:11:01 -0500 | [diff] [blame] | 4117 | config: Config{ |
| 4118 | MaxVersion: VersionTLS10, |
| 4119 | Bugs: ProtocolBugs{ |
| 4120 | RequireSameRenegoClientVersion: true, |
| 4121 | }, |
| 4122 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4123 | flags: []string{ |
| 4124 | "-renegotiate-freely", |
| 4125 | "-expect-total-renegotiations", "1", |
| 4126 | }, |
David Benjamin | c44b1df | 2014-11-23 12:11:01 -0500 | [diff] [blame] | 4127 | }) |
Adam Langley | b558c4c | 2015-07-08 12:16:38 -0700 | [diff] [blame] | 4128 | testCases = append(testCases, testCase{ |
| 4129 | name: "Renegotiate-FalseStart", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4130 | renegotiate: 1, |
Adam Langley | b558c4c | 2015-07-08 12:16:38 -0700 | [diff] [blame] | 4131 | config: Config{ |
| 4132 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 4133 | NextProtos: []string{"foo"}, |
| 4134 | }, |
| 4135 | flags: []string{ |
| 4136 | "-false-start", |
| 4137 | "-select-next-proto", "foo", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4138 | "-renegotiate-freely", |
David Benjamin | 324dce4 | 2015-10-12 19:49:00 -0400 | [diff] [blame] | 4139 | "-expect-total-renegotiations", "1", |
Adam Langley | b558c4c | 2015-07-08 12:16:38 -0700 | [diff] [blame] | 4140 | }, |
| 4141 | shimWritesFirst: true, |
| 4142 | }) |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4143 | |
| 4144 | // Client-side renegotiation controls. |
| 4145 | testCases = append(testCases, testCase{ |
| 4146 | name: "Renegotiate-Client-Forbidden-1", |
| 4147 | renegotiate: 1, |
| 4148 | shouldFail: true, |
| 4149 | expectedError: ":NO_RENEGOTIATION:", |
| 4150 | expectedLocalError: "remote error: no renegotiation", |
| 4151 | }) |
| 4152 | testCases = append(testCases, testCase{ |
| 4153 | name: "Renegotiate-Client-Once-1", |
| 4154 | renegotiate: 1, |
| 4155 | flags: []string{ |
| 4156 | "-renegotiate-once", |
| 4157 | "-expect-total-renegotiations", "1", |
| 4158 | }, |
| 4159 | }) |
| 4160 | testCases = append(testCases, testCase{ |
| 4161 | name: "Renegotiate-Client-Freely-1", |
| 4162 | renegotiate: 1, |
| 4163 | flags: []string{ |
| 4164 | "-renegotiate-freely", |
| 4165 | "-expect-total-renegotiations", "1", |
| 4166 | }, |
| 4167 | }) |
| 4168 | testCases = append(testCases, testCase{ |
| 4169 | name: "Renegotiate-Client-Once-2", |
| 4170 | renegotiate: 2, |
| 4171 | flags: []string{"-renegotiate-once"}, |
| 4172 | shouldFail: true, |
| 4173 | expectedError: ":NO_RENEGOTIATION:", |
| 4174 | expectedLocalError: "remote error: no renegotiation", |
| 4175 | }) |
| 4176 | testCases = append(testCases, testCase{ |
| 4177 | name: "Renegotiate-Client-Freely-2", |
| 4178 | renegotiate: 2, |
| 4179 | flags: []string{ |
| 4180 | "-renegotiate-freely", |
| 4181 | "-expect-total-renegotiations", "2", |
| 4182 | }, |
| 4183 | }) |
Adam Langley | 27a0d08 | 2015-11-03 13:34:10 -0800 | [diff] [blame] | 4184 | testCases = append(testCases, testCase{ |
| 4185 | name: "Renegotiate-Client-NoIgnore", |
| 4186 | config: Config{ |
| 4187 | Bugs: ProtocolBugs{ |
| 4188 | SendHelloRequestBeforeEveryAppDataRecord: true, |
| 4189 | }, |
| 4190 | }, |
| 4191 | shouldFail: true, |
| 4192 | expectedError: ":NO_RENEGOTIATION:", |
| 4193 | }) |
| 4194 | testCases = append(testCases, testCase{ |
| 4195 | name: "Renegotiate-Client-Ignore", |
| 4196 | config: Config{ |
| 4197 | Bugs: ProtocolBugs{ |
| 4198 | SendHelloRequestBeforeEveryAppDataRecord: true, |
| 4199 | }, |
| 4200 | }, |
| 4201 | flags: []string{ |
| 4202 | "-renegotiate-ignore", |
| 4203 | "-expect-total-renegotiations", "0", |
| 4204 | }, |
| 4205 | }) |
Adam Langley | 2ae77d2 | 2014-10-28 17:29:33 -0700 | [diff] [blame] | 4206 | } |
| 4207 | |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 4208 | func addDTLSReplayTests() { |
| 4209 | // Test that sequence number replays are detected. |
| 4210 | testCases = append(testCases, testCase{ |
| 4211 | protocol: dtls, |
| 4212 | name: "DTLS-Replay", |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 4213 | messageCount: 200, |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 4214 | replayWrites: true, |
| 4215 | }) |
| 4216 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 4217 | // Test the incoming sequence number skipping by values larger |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 4218 | // than the retransmit window. |
| 4219 | testCases = append(testCases, testCase{ |
| 4220 | protocol: dtls, |
| 4221 | name: "DTLS-Replay-LargeGaps", |
| 4222 | config: Config{ |
| 4223 | Bugs: ProtocolBugs{ |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 4224 | SequenceNumberMapping: func(in uint64) uint64 { |
| 4225 | return in * 127 |
| 4226 | }, |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 4227 | }, |
| 4228 | }, |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 4229 | messageCount: 200, |
| 4230 | replayWrites: true, |
| 4231 | }) |
| 4232 | |
| 4233 | // Test the incoming sequence number changing non-monotonically. |
| 4234 | testCases = append(testCases, testCase{ |
| 4235 | protocol: dtls, |
| 4236 | name: "DTLS-Replay-NonMonotonic", |
| 4237 | config: Config{ |
| 4238 | Bugs: ProtocolBugs{ |
| 4239 | SequenceNumberMapping: func(in uint64) uint64 { |
| 4240 | return in ^ 31 |
| 4241 | }, |
| 4242 | }, |
| 4243 | }, |
| 4244 | messageCount: 200, |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 4245 | replayWrites: true, |
| 4246 | }) |
| 4247 | } |
| 4248 | |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 4249 | var testHashes = []struct { |
| 4250 | name string |
| 4251 | id uint8 |
| 4252 | }{ |
| 4253 | {"SHA1", hashSHA1}, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 4254 | {"SHA256", hashSHA256}, |
| 4255 | {"SHA384", hashSHA384}, |
| 4256 | {"SHA512", hashSHA512}, |
| 4257 | } |
| 4258 | |
| 4259 | func addSigningHashTests() { |
| 4260 | // Make sure each hash works. Include some fake hashes in the list and |
| 4261 | // ensure they're ignored. |
| 4262 | for _, hash := range testHashes { |
| 4263 | testCases = append(testCases, testCase{ |
| 4264 | name: "SigningHash-ClientAuth-" + hash.name, |
| 4265 | config: Config{ |
| 4266 | ClientAuth: RequireAnyClientCert, |
| 4267 | SignatureAndHashes: []signatureAndHash{ |
| 4268 | {signatureRSA, 42}, |
| 4269 | {signatureRSA, hash.id}, |
| 4270 | {signatureRSA, 255}, |
| 4271 | }, |
| 4272 | }, |
| 4273 | flags: []string{ |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 4274 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 4275 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 4276 | }, |
| 4277 | }) |
| 4278 | |
| 4279 | testCases = append(testCases, testCase{ |
| 4280 | testType: serverTest, |
| 4281 | name: "SigningHash-ServerKeyExchange-Sign-" + hash.name, |
| 4282 | config: Config{ |
| 4283 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 4284 | SignatureAndHashes: []signatureAndHash{ |
| 4285 | {signatureRSA, 42}, |
| 4286 | {signatureRSA, hash.id}, |
| 4287 | {signatureRSA, 255}, |
| 4288 | }, |
| 4289 | }, |
| 4290 | }) |
David Benjamin | 6e80765 | 2015-11-02 12:02:20 -0500 | [diff] [blame] | 4291 | |
| 4292 | testCases = append(testCases, testCase{ |
| 4293 | name: "SigningHash-ServerKeyExchange-Verify-" + hash.name, |
| 4294 | config: Config{ |
| 4295 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 4296 | SignatureAndHashes: []signatureAndHash{ |
| 4297 | {signatureRSA, 42}, |
| 4298 | {signatureRSA, hash.id}, |
| 4299 | {signatureRSA, 255}, |
| 4300 | }, |
| 4301 | }, |
| 4302 | flags: []string{"-expect-server-key-exchange-hash", strconv.Itoa(int(hash.id))}, |
| 4303 | }) |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 4304 | } |
| 4305 | |
| 4306 | // Test that hash resolution takes the signature type into account. |
| 4307 | testCases = append(testCases, testCase{ |
| 4308 | name: "SigningHash-ClientAuth-SignatureType", |
| 4309 | config: Config{ |
| 4310 | ClientAuth: RequireAnyClientCert, |
| 4311 | SignatureAndHashes: []signatureAndHash{ |
| 4312 | {signatureECDSA, hashSHA512}, |
| 4313 | {signatureRSA, hashSHA384}, |
| 4314 | {signatureECDSA, hashSHA1}, |
| 4315 | }, |
| 4316 | }, |
| 4317 | flags: []string{ |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 4318 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 4319 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 4320 | }, |
| 4321 | }) |
| 4322 | |
| 4323 | testCases = append(testCases, testCase{ |
| 4324 | testType: serverTest, |
| 4325 | name: "SigningHash-ServerKeyExchange-SignatureType", |
| 4326 | config: Config{ |
| 4327 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 4328 | SignatureAndHashes: []signatureAndHash{ |
| 4329 | {signatureECDSA, hashSHA512}, |
| 4330 | {signatureRSA, hashSHA384}, |
| 4331 | {signatureECDSA, hashSHA1}, |
| 4332 | }, |
| 4333 | }, |
| 4334 | }) |
| 4335 | |
| 4336 | // Test that, if the list is missing, the peer falls back to SHA-1. |
| 4337 | testCases = append(testCases, testCase{ |
| 4338 | name: "SigningHash-ClientAuth-Fallback", |
| 4339 | config: Config{ |
| 4340 | ClientAuth: RequireAnyClientCert, |
| 4341 | SignatureAndHashes: []signatureAndHash{ |
| 4342 | {signatureRSA, hashSHA1}, |
| 4343 | }, |
| 4344 | Bugs: ProtocolBugs{ |
| 4345 | NoSignatureAndHashes: true, |
| 4346 | }, |
| 4347 | }, |
| 4348 | flags: []string{ |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 4349 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 4350 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 4351 | }, |
| 4352 | }) |
| 4353 | |
| 4354 | testCases = append(testCases, testCase{ |
| 4355 | testType: serverTest, |
| 4356 | name: "SigningHash-ServerKeyExchange-Fallback", |
| 4357 | config: Config{ |
| 4358 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 4359 | SignatureAndHashes: []signatureAndHash{ |
| 4360 | {signatureRSA, hashSHA1}, |
| 4361 | }, |
| 4362 | Bugs: ProtocolBugs{ |
| 4363 | NoSignatureAndHashes: true, |
| 4364 | }, |
| 4365 | }, |
| 4366 | }) |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 4367 | |
| 4368 | // Test that hash preferences are enforced. BoringSSL defaults to |
| 4369 | // rejecting MD5 signatures. |
| 4370 | testCases = append(testCases, testCase{ |
| 4371 | testType: serverTest, |
| 4372 | name: "SigningHash-ClientAuth-Enforced", |
| 4373 | config: Config{ |
| 4374 | Certificates: []Certificate{rsaCertificate}, |
| 4375 | SignatureAndHashes: []signatureAndHash{ |
| 4376 | {signatureRSA, hashMD5}, |
| 4377 | // Advertise SHA-1 so the handshake will |
| 4378 | // proceed, but the shim's preferences will be |
| 4379 | // ignored in CertificateVerify generation, so |
| 4380 | // MD5 will be chosen. |
| 4381 | {signatureRSA, hashSHA1}, |
| 4382 | }, |
| 4383 | Bugs: ProtocolBugs{ |
| 4384 | IgnorePeerSignatureAlgorithmPreferences: true, |
| 4385 | }, |
| 4386 | }, |
| 4387 | flags: []string{"-require-any-client-certificate"}, |
| 4388 | shouldFail: true, |
| 4389 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 4390 | }) |
| 4391 | |
| 4392 | testCases = append(testCases, testCase{ |
| 4393 | name: "SigningHash-ServerKeyExchange-Enforced", |
| 4394 | config: Config{ |
| 4395 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 4396 | SignatureAndHashes: []signatureAndHash{ |
| 4397 | {signatureRSA, hashMD5}, |
| 4398 | }, |
| 4399 | Bugs: ProtocolBugs{ |
| 4400 | IgnorePeerSignatureAlgorithmPreferences: true, |
| 4401 | }, |
| 4402 | }, |
| 4403 | shouldFail: true, |
| 4404 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 4405 | }) |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 4406 | |
| 4407 | // Test that the agreed upon digest respects the client preferences and |
| 4408 | // the server digests. |
| 4409 | testCases = append(testCases, testCase{ |
| 4410 | name: "Agree-Digest-Fallback", |
| 4411 | config: Config{ |
| 4412 | ClientAuth: RequireAnyClientCert, |
| 4413 | SignatureAndHashes: []signatureAndHash{ |
| 4414 | {signatureRSA, hashSHA512}, |
| 4415 | {signatureRSA, hashSHA1}, |
| 4416 | }, |
| 4417 | }, |
| 4418 | flags: []string{ |
| 4419 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 4420 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 4421 | }, |
| 4422 | digestPrefs: "SHA256", |
| 4423 | expectedClientCertSignatureHash: hashSHA1, |
| 4424 | }) |
| 4425 | testCases = append(testCases, testCase{ |
| 4426 | name: "Agree-Digest-SHA256", |
| 4427 | config: Config{ |
| 4428 | ClientAuth: RequireAnyClientCert, |
| 4429 | SignatureAndHashes: []signatureAndHash{ |
| 4430 | {signatureRSA, hashSHA1}, |
| 4431 | {signatureRSA, hashSHA256}, |
| 4432 | }, |
| 4433 | }, |
| 4434 | flags: []string{ |
| 4435 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 4436 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 4437 | }, |
| 4438 | digestPrefs: "SHA256,SHA1", |
| 4439 | expectedClientCertSignatureHash: hashSHA256, |
| 4440 | }) |
| 4441 | testCases = append(testCases, testCase{ |
| 4442 | name: "Agree-Digest-SHA1", |
| 4443 | config: Config{ |
| 4444 | ClientAuth: RequireAnyClientCert, |
| 4445 | SignatureAndHashes: []signatureAndHash{ |
| 4446 | {signatureRSA, hashSHA1}, |
| 4447 | }, |
| 4448 | }, |
| 4449 | flags: []string{ |
| 4450 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 4451 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 4452 | }, |
| 4453 | digestPrefs: "SHA512,SHA256,SHA1", |
| 4454 | expectedClientCertSignatureHash: hashSHA1, |
| 4455 | }) |
| 4456 | testCases = append(testCases, testCase{ |
| 4457 | name: "Agree-Digest-Default", |
| 4458 | config: Config{ |
| 4459 | ClientAuth: RequireAnyClientCert, |
| 4460 | SignatureAndHashes: []signatureAndHash{ |
| 4461 | {signatureRSA, hashSHA256}, |
| 4462 | {signatureECDSA, hashSHA256}, |
| 4463 | {signatureRSA, hashSHA1}, |
| 4464 | {signatureECDSA, hashSHA1}, |
| 4465 | }, |
| 4466 | }, |
| 4467 | flags: []string{ |
| 4468 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 4469 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 4470 | }, |
| 4471 | expectedClientCertSignatureHash: hashSHA256, |
| 4472 | }) |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 4473 | } |
| 4474 | |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 4475 | // timeouts is the retransmit schedule for BoringSSL. It doubles and |
| 4476 | // caps at 60 seconds. On the 13th timeout, it gives up. |
| 4477 | var timeouts = []time.Duration{ |
| 4478 | 1 * time.Second, |
| 4479 | 2 * time.Second, |
| 4480 | 4 * time.Second, |
| 4481 | 8 * time.Second, |
| 4482 | 16 * time.Second, |
| 4483 | 32 * time.Second, |
| 4484 | 60 * time.Second, |
| 4485 | 60 * time.Second, |
| 4486 | 60 * time.Second, |
| 4487 | 60 * time.Second, |
| 4488 | 60 * time.Second, |
| 4489 | 60 * time.Second, |
| 4490 | 60 * time.Second, |
| 4491 | } |
| 4492 | |
| 4493 | func addDTLSRetransmitTests() { |
| 4494 | // Test that this is indeed the timeout schedule. Stress all |
| 4495 | // four patterns of handshake. |
| 4496 | for i := 1; i < len(timeouts); i++ { |
| 4497 | number := strconv.Itoa(i) |
| 4498 | testCases = append(testCases, testCase{ |
| 4499 | protocol: dtls, |
| 4500 | name: "DTLS-Retransmit-Client-" + number, |
| 4501 | config: Config{ |
| 4502 | Bugs: ProtocolBugs{ |
| 4503 | TimeoutSchedule: timeouts[:i], |
| 4504 | }, |
| 4505 | }, |
| 4506 | resumeSession: true, |
| 4507 | flags: []string{"-async"}, |
| 4508 | }) |
| 4509 | testCases = append(testCases, testCase{ |
| 4510 | protocol: dtls, |
| 4511 | testType: serverTest, |
| 4512 | name: "DTLS-Retransmit-Server-" + number, |
| 4513 | config: Config{ |
| 4514 | Bugs: ProtocolBugs{ |
| 4515 | TimeoutSchedule: timeouts[:i], |
| 4516 | }, |
| 4517 | }, |
| 4518 | resumeSession: true, |
| 4519 | flags: []string{"-async"}, |
| 4520 | }) |
| 4521 | } |
| 4522 | |
| 4523 | // Test that exceeding the timeout schedule hits a read |
| 4524 | // timeout. |
| 4525 | testCases = append(testCases, testCase{ |
| 4526 | protocol: dtls, |
| 4527 | name: "DTLS-Retransmit-Timeout", |
| 4528 | config: Config{ |
| 4529 | Bugs: ProtocolBugs{ |
| 4530 | TimeoutSchedule: timeouts, |
| 4531 | }, |
| 4532 | }, |
| 4533 | resumeSession: true, |
| 4534 | flags: []string{"-async"}, |
| 4535 | shouldFail: true, |
| 4536 | expectedError: ":READ_TIMEOUT_EXPIRED:", |
| 4537 | }) |
| 4538 | |
| 4539 | // Test that timeout handling has a fudge factor, due to API |
| 4540 | // problems. |
| 4541 | testCases = append(testCases, testCase{ |
| 4542 | protocol: dtls, |
| 4543 | name: "DTLS-Retransmit-Fudge", |
| 4544 | config: Config{ |
| 4545 | Bugs: ProtocolBugs{ |
| 4546 | TimeoutSchedule: []time.Duration{ |
| 4547 | timeouts[0] - 10*time.Millisecond, |
| 4548 | }, |
| 4549 | }, |
| 4550 | }, |
| 4551 | resumeSession: true, |
| 4552 | flags: []string{"-async"}, |
| 4553 | }) |
David Benjamin | 7eaab4c | 2015-03-02 19:01:16 -0500 | [diff] [blame] | 4554 | |
| 4555 | // Test that the final Finished retransmitting isn't |
| 4556 | // duplicated if the peer badly fragments everything. |
| 4557 | testCases = append(testCases, testCase{ |
| 4558 | testType: serverTest, |
| 4559 | protocol: dtls, |
| 4560 | name: "DTLS-Retransmit-Fragmented", |
| 4561 | config: Config{ |
| 4562 | Bugs: ProtocolBugs{ |
| 4563 | TimeoutSchedule: []time.Duration{timeouts[0]}, |
| 4564 | MaxHandshakeRecordLength: 2, |
| 4565 | }, |
| 4566 | }, |
| 4567 | flags: []string{"-async"}, |
| 4568 | }) |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 4569 | } |
| 4570 | |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 4571 | func addExportKeyingMaterialTests() { |
| 4572 | for _, vers := range tlsVersions { |
| 4573 | if vers.version == VersionSSL30 { |
| 4574 | continue |
| 4575 | } |
| 4576 | testCases = append(testCases, testCase{ |
| 4577 | name: "ExportKeyingMaterial-" + vers.name, |
| 4578 | config: Config{ |
| 4579 | MaxVersion: vers.version, |
| 4580 | }, |
| 4581 | exportKeyingMaterial: 1024, |
| 4582 | exportLabel: "label", |
| 4583 | exportContext: "context", |
| 4584 | useExportContext: true, |
| 4585 | }) |
| 4586 | testCases = append(testCases, testCase{ |
| 4587 | name: "ExportKeyingMaterial-NoContext-" + vers.name, |
| 4588 | config: Config{ |
| 4589 | MaxVersion: vers.version, |
| 4590 | }, |
| 4591 | exportKeyingMaterial: 1024, |
| 4592 | }) |
| 4593 | testCases = append(testCases, testCase{ |
| 4594 | name: "ExportKeyingMaterial-EmptyContext-" + vers.name, |
| 4595 | config: Config{ |
| 4596 | MaxVersion: vers.version, |
| 4597 | }, |
| 4598 | exportKeyingMaterial: 1024, |
| 4599 | useExportContext: true, |
| 4600 | }) |
| 4601 | testCases = append(testCases, testCase{ |
| 4602 | name: "ExportKeyingMaterial-Small-" + vers.name, |
| 4603 | config: Config{ |
| 4604 | MaxVersion: vers.version, |
| 4605 | }, |
| 4606 | exportKeyingMaterial: 1, |
| 4607 | exportLabel: "label", |
| 4608 | exportContext: "context", |
| 4609 | useExportContext: true, |
| 4610 | }) |
| 4611 | } |
| 4612 | testCases = append(testCases, testCase{ |
| 4613 | name: "ExportKeyingMaterial-SSL3", |
| 4614 | config: Config{ |
| 4615 | MaxVersion: VersionSSL30, |
| 4616 | }, |
| 4617 | exportKeyingMaterial: 1024, |
| 4618 | exportLabel: "label", |
| 4619 | exportContext: "context", |
| 4620 | useExportContext: true, |
| 4621 | shouldFail: true, |
| 4622 | expectedError: "failed to export keying material", |
| 4623 | }) |
| 4624 | } |
| 4625 | |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 4626 | func addTLSUniqueTests() { |
| 4627 | for _, isClient := range []bool{false, true} { |
| 4628 | for _, isResumption := range []bool{false, true} { |
| 4629 | for _, hasEMS := range []bool{false, true} { |
| 4630 | var suffix string |
| 4631 | if isResumption { |
| 4632 | suffix = "Resume-" |
| 4633 | } else { |
| 4634 | suffix = "Full-" |
| 4635 | } |
| 4636 | |
| 4637 | if hasEMS { |
| 4638 | suffix += "EMS-" |
| 4639 | } else { |
| 4640 | suffix += "NoEMS-" |
| 4641 | } |
| 4642 | |
| 4643 | if isClient { |
| 4644 | suffix += "Client" |
| 4645 | } else { |
| 4646 | suffix += "Server" |
| 4647 | } |
| 4648 | |
| 4649 | test := testCase{ |
| 4650 | name: "TLSUnique-" + suffix, |
| 4651 | testTLSUnique: true, |
| 4652 | config: Config{ |
| 4653 | Bugs: ProtocolBugs{ |
| 4654 | NoExtendedMasterSecret: !hasEMS, |
| 4655 | }, |
| 4656 | }, |
| 4657 | } |
| 4658 | |
| 4659 | if isResumption { |
| 4660 | test.resumeSession = true |
| 4661 | test.resumeConfig = &Config{ |
| 4662 | Bugs: ProtocolBugs{ |
| 4663 | NoExtendedMasterSecret: !hasEMS, |
| 4664 | }, |
| 4665 | } |
| 4666 | } |
| 4667 | |
| 4668 | if isResumption && !hasEMS { |
| 4669 | test.shouldFail = true |
| 4670 | test.expectedError = "failed to get tls-unique" |
| 4671 | } |
| 4672 | |
| 4673 | testCases = append(testCases, test) |
| 4674 | } |
| 4675 | } |
| 4676 | } |
| 4677 | } |
| 4678 | |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 4679 | func addCustomExtensionTests() { |
| 4680 | expectedContents := "custom extension" |
| 4681 | emptyString := "" |
| 4682 | |
| 4683 | for _, isClient := range []bool{false, true} { |
| 4684 | suffix := "Server" |
| 4685 | flag := "-enable-server-custom-extension" |
| 4686 | testType := serverTest |
| 4687 | if isClient { |
| 4688 | suffix = "Client" |
| 4689 | flag = "-enable-client-custom-extension" |
| 4690 | testType = clientTest |
| 4691 | } |
| 4692 | |
| 4693 | testCases = append(testCases, testCase{ |
| 4694 | testType: testType, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 4695 | name: "CustomExtensions-" + suffix, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 4696 | config: Config{ |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 4697 | Bugs: ProtocolBugs{ |
| 4698 | CustomExtension: expectedContents, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 4699 | ExpectedCustomExtension: &expectedContents, |
| 4700 | }, |
| 4701 | }, |
| 4702 | flags: []string{flag}, |
| 4703 | }) |
| 4704 | |
| 4705 | // If the parse callback fails, the handshake should also fail. |
| 4706 | testCases = append(testCases, testCase{ |
| 4707 | testType: testType, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 4708 | name: "CustomExtensions-ParseError-" + suffix, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 4709 | config: Config{ |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 4710 | Bugs: ProtocolBugs{ |
| 4711 | CustomExtension: expectedContents + "foo", |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 4712 | ExpectedCustomExtension: &expectedContents, |
| 4713 | }, |
| 4714 | }, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 4715 | flags: []string{flag}, |
| 4716 | shouldFail: true, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 4717 | expectedError: ":CUSTOM_EXTENSION_ERROR:", |
| 4718 | }) |
| 4719 | |
| 4720 | // If the add callback fails, the handshake should also fail. |
| 4721 | testCases = append(testCases, testCase{ |
| 4722 | testType: testType, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 4723 | name: "CustomExtensions-FailAdd-" + suffix, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 4724 | config: Config{ |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 4725 | Bugs: ProtocolBugs{ |
| 4726 | CustomExtension: expectedContents, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 4727 | ExpectedCustomExtension: &expectedContents, |
| 4728 | }, |
| 4729 | }, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 4730 | flags: []string{flag, "-custom-extension-fail-add"}, |
| 4731 | shouldFail: true, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 4732 | expectedError: ":CUSTOM_EXTENSION_ERROR:", |
| 4733 | }) |
| 4734 | |
| 4735 | // If the add callback returns zero, no extension should be |
| 4736 | // added. |
| 4737 | skipCustomExtension := expectedContents |
| 4738 | if isClient { |
| 4739 | // For the case where the client skips sending the |
| 4740 | // custom extension, the server must not “echo” it. |
| 4741 | skipCustomExtension = "" |
| 4742 | } |
| 4743 | testCases = append(testCases, testCase{ |
| 4744 | testType: testType, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 4745 | name: "CustomExtensions-Skip-" + suffix, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 4746 | config: Config{ |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 4747 | Bugs: ProtocolBugs{ |
| 4748 | CustomExtension: skipCustomExtension, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 4749 | ExpectedCustomExtension: &emptyString, |
| 4750 | }, |
| 4751 | }, |
| 4752 | flags: []string{flag, "-custom-extension-skip"}, |
| 4753 | }) |
| 4754 | } |
| 4755 | |
| 4756 | // The custom extension add callback should not be called if the client |
| 4757 | // doesn't send the extension. |
| 4758 | testCases = append(testCases, testCase{ |
| 4759 | testType: serverTest, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 4760 | name: "CustomExtensions-NotCalled-Server", |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 4761 | config: Config{ |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 4762 | Bugs: ProtocolBugs{ |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 4763 | ExpectedCustomExtension: &emptyString, |
| 4764 | }, |
| 4765 | }, |
| 4766 | flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"}, |
| 4767 | }) |
Adam Langley | 2deb984 | 2015-08-07 11:15:37 -0700 | [diff] [blame] | 4768 | |
| 4769 | // Test an unknown extension from the server. |
| 4770 | testCases = append(testCases, testCase{ |
| 4771 | testType: clientTest, |
| 4772 | name: "UnknownExtension-Client", |
| 4773 | config: Config{ |
| 4774 | Bugs: ProtocolBugs{ |
| 4775 | CustomExtension: expectedContents, |
| 4776 | }, |
| 4777 | }, |
| 4778 | shouldFail: true, |
| 4779 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 4780 | }) |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 4781 | } |
| 4782 | |
David Benjamin | b36a395 | 2015-12-01 18:53:13 -0500 | [diff] [blame] | 4783 | func addRSAClientKeyExchangeTests() { |
| 4784 | for bad := RSABadValue(1); bad < NumRSABadValues; bad++ { |
| 4785 | testCases = append(testCases, testCase{ |
| 4786 | testType: serverTest, |
| 4787 | name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad), |
| 4788 | config: Config{ |
| 4789 | // Ensure the ClientHello version and final |
| 4790 | // version are different, to detect if the |
| 4791 | // server uses the wrong one. |
| 4792 | MaxVersion: VersionTLS11, |
| 4793 | CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA}, |
| 4794 | Bugs: ProtocolBugs{ |
| 4795 | BadRSAClientKeyExchange: bad, |
| 4796 | }, |
| 4797 | }, |
| 4798 | shouldFail: true, |
| 4799 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 4800 | }) |
| 4801 | } |
| 4802 | } |
| 4803 | |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 4804 | var testCurves = []struct { |
| 4805 | name string |
| 4806 | id CurveID |
| 4807 | }{ |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 4808 | {"P-256", CurveP256}, |
| 4809 | {"P-384", CurveP384}, |
| 4810 | {"P-521", CurveP521}, |
David Benjamin | 4298d77 | 2015-12-19 00:18:25 -0500 | [diff] [blame] | 4811 | {"X25519", CurveX25519}, |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 4812 | } |
| 4813 | |
| 4814 | func addCurveTests() { |
| 4815 | for _, curve := range testCurves { |
| 4816 | testCases = append(testCases, testCase{ |
| 4817 | name: "CurveTest-Client-" + curve.name, |
| 4818 | config: Config{ |
| 4819 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 4820 | CurvePreferences: []CurveID{curve.id}, |
| 4821 | }, |
| 4822 | flags: []string{"-enable-all-curves"}, |
| 4823 | }) |
| 4824 | testCases = append(testCases, testCase{ |
| 4825 | testType: serverTest, |
| 4826 | name: "CurveTest-Server-" + curve.name, |
| 4827 | config: Config{ |
| 4828 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 4829 | CurvePreferences: []CurveID{curve.id}, |
| 4830 | }, |
| 4831 | flags: []string{"-enable-all-curves"}, |
| 4832 | }) |
| 4833 | } |
David Benjamin | 241ae83 | 2016-01-15 03:04:54 -0500 | [diff] [blame] | 4834 | |
| 4835 | // The server must be tolerant to bogus curves. |
| 4836 | const bogusCurve = 0x1234 |
| 4837 | testCases = append(testCases, testCase{ |
| 4838 | testType: serverTest, |
| 4839 | name: "UnknownCurve", |
| 4840 | config: Config{ |
| 4841 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 4842 | CurvePreferences: []CurveID{bogusCurve, CurveP256}, |
| 4843 | }, |
| 4844 | }) |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 4845 | } |
| 4846 | |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 4847 | func addKeyExchangeInfoTests() { |
| 4848 | testCases = append(testCases, testCase{ |
| 4849 | name: "KeyExchangeInfo-RSA-Client", |
| 4850 | config: Config{ |
| 4851 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 4852 | }, |
| 4853 | // key.pem is a 1024-bit RSA key. |
| 4854 | flags: []string{"-expect-key-exchange-info", "1024"}, |
| 4855 | }) |
| 4856 | // TODO(davidben): key_exchange_info doesn't work for plain RSA on the |
| 4857 | // server. Either fix this or change the API as it's not very useful in |
| 4858 | // this case. |
| 4859 | |
| 4860 | testCases = append(testCases, testCase{ |
| 4861 | name: "KeyExchangeInfo-DHE-Client", |
| 4862 | config: Config{ |
| 4863 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 4864 | Bugs: ProtocolBugs{ |
| 4865 | // This is a 1234-bit prime number, generated |
| 4866 | // with: |
| 4867 | // openssl gendh 1234 | openssl asn1parse -i |
| 4868 | DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"), |
| 4869 | }, |
| 4870 | }, |
| 4871 | flags: []string{"-expect-key-exchange-info", "1234"}, |
| 4872 | }) |
| 4873 | testCases = append(testCases, testCase{ |
| 4874 | testType: serverTest, |
| 4875 | name: "KeyExchangeInfo-DHE-Server", |
| 4876 | config: Config{ |
| 4877 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 4878 | }, |
| 4879 | // bssl_shim as a server configures a 2048-bit DHE group. |
| 4880 | flags: []string{"-expect-key-exchange-info", "2048"}, |
| 4881 | }) |
| 4882 | |
| 4883 | testCases = append(testCases, testCase{ |
| 4884 | name: "KeyExchangeInfo-ECDHE-Client", |
| 4885 | config: Config{ |
| 4886 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 4887 | CurvePreferences: []CurveID{CurveX25519}, |
| 4888 | }, |
| 4889 | flags: []string{"-expect-key-exchange-info", "29", "-enable-all-curves"}, |
| 4890 | }) |
| 4891 | testCases = append(testCases, testCase{ |
| 4892 | testType: serverTest, |
| 4893 | name: "KeyExchangeInfo-ECDHE-Server", |
| 4894 | config: Config{ |
| 4895 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 4896 | CurvePreferences: []CurveID{CurveX25519}, |
| 4897 | }, |
| 4898 | flags: []string{"-expect-key-exchange-info", "29", "-enable-all-curves"}, |
| 4899 | }) |
| 4900 | } |
| 4901 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 4902 | func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 4903 | defer wg.Done() |
| 4904 | |
| 4905 | for test := range c { |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 4906 | var err error |
| 4907 | |
| 4908 | if *mallocTest < 0 { |
| 4909 | statusChan <- statusMsg{test: test, started: true} |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 4910 | err = runTest(test, shimPath, -1) |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 4911 | } else { |
| 4912 | for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ { |
| 4913 | statusChan <- statusMsg{test: test, started: true} |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 4914 | if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs { |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 4915 | if err != nil { |
| 4916 | fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err) |
| 4917 | } |
| 4918 | break |
| 4919 | } |
| 4920 | } |
| 4921 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 4922 | statusChan <- statusMsg{test: test, err: err} |
| 4923 | } |
| 4924 | } |
| 4925 | |
| 4926 | type statusMsg struct { |
| 4927 | test *testCase |
| 4928 | started bool |
| 4929 | err error |
| 4930 | } |
| 4931 | |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 4932 | func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 4933 | var started, done, failed, lineLen int |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 4934 | |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 4935 | testOutput := newTestOutput() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 4936 | for msg := range statusChan { |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 4937 | if !*pipe { |
| 4938 | // Erase the previous status line. |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 4939 | var erase string |
| 4940 | for i := 0; i < lineLen; i++ { |
| 4941 | erase += "\b \b" |
| 4942 | } |
| 4943 | fmt.Print(erase) |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 4944 | } |
| 4945 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 4946 | if msg.started { |
| 4947 | started++ |
| 4948 | } else { |
| 4949 | done++ |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 4950 | |
| 4951 | if msg.err != nil { |
| 4952 | fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err) |
| 4953 | failed++ |
| 4954 | testOutput.addResult(msg.test.name, "FAIL") |
| 4955 | } else { |
| 4956 | if *pipe { |
| 4957 | // Print each test instead of a status line. |
| 4958 | fmt.Printf("PASSED (%s)\n", msg.test.name) |
| 4959 | } |
| 4960 | testOutput.addResult(msg.test.name, "PASS") |
| 4961 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 4962 | } |
| 4963 | |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 4964 | if !*pipe { |
| 4965 | // Print a new status line. |
| 4966 | line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total) |
| 4967 | lineLen = len(line) |
| 4968 | os.Stdout.WriteString(line) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 4969 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 4970 | } |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 4971 | |
| 4972 | doneChan <- testOutput |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 4973 | } |
| 4974 | |
| 4975 | func main() { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 4976 | flag.Parse() |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 4977 | *resourceDir = path.Clean(*resourceDir) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 4978 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 4979 | addBasicTests() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 4980 | addCipherSuiteTests() |
| 4981 | addBadECDSASignatureTests() |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 4982 | addCBCPaddingTests() |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 4983 | addCBCSplittingTests() |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 4984 | addClientAuthTests() |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 4985 | addDDoSCallbackTests() |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 4986 | addVersionNegotiationTests() |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4987 | addMinimumVersionTests() |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 4988 | addExtensionTests() |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 4989 | addResumptionVersionTests() |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 4990 | addExtendedMasterSecretTests() |
Adam Langley | 2ae77d2 | 2014-10-28 17:29:33 -0700 | [diff] [blame] | 4991 | addRenegotiationTests() |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 4992 | addDTLSReplayTests() |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 4993 | addSigningHashTests() |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 4994 | addDTLSRetransmitTests() |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 4995 | addExportKeyingMaterialTests() |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 4996 | addTLSUniqueTests() |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 4997 | addCustomExtensionTests() |
David Benjamin | b36a395 | 2015-12-01 18:53:13 -0500 | [diff] [blame] | 4998 | addRSAClientKeyExchangeTests() |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 4999 | addCurveTests() |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 5000 | addKeyExchangeInfoTests() |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 5001 | for _, async := range []bool{false, true} { |
| 5002 | for _, splitHandshake := range []bool{false, true} { |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 5003 | for _, protocol := range []protocol{tls, dtls} { |
| 5004 | addStateMachineCoverageTests(async, splitHandshake, protocol) |
| 5005 | } |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 5006 | } |
| 5007 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 5008 | |
| 5009 | var wg sync.WaitGroup |
| 5010 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 5011 | statusChan := make(chan statusMsg, *numWorkers) |
| 5012 | testChan := make(chan *testCase, *numWorkers) |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 5013 | doneChan := make(chan *testOutput) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 5014 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 5015 | go statusPrinter(doneChan, statusChan, len(testCases)) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 5016 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 5017 | for i := 0; i < *numWorkers; i++ { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 5018 | wg.Add(1) |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 5019 | go worker(statusChan, testChan, *shimPath, &wg) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 5020 | } |
| 5021 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 5022 | for i := range testCases { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 5023 | if len(*testToRun) == 0 || *testToRun == testCases[i].name { |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 5024 | testChan <- &testCases[i] |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 5025 | } |
| 5026 | } |
| 5027 | |
| 5028 | close(testChan) |
| 5029 | wg.Wait() |
| 5030 | close(statusChan) |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 5031 | testOutput := <-doneChan |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 5032 | |
| 5033 | fmt.Printf("\n") |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 5034 | |
| 5035 | if *jsonOutput != "" { |
| 5036 | if err := testOutput.writeTo(*jsonOutput); err != nil { |
| 5037 | fmt.Fprintf(os.Stderr, "Error: %s\n", err) |
| 5038 | } |
| 5039 | } |
David Benjamin | 2ab7a86 | 2015-04-04 17:02:18 -0400 | [diff] [blame] | 5040 | |
| 5041 | if !testOutput.allPassed { |
| 5042 | os.Exit(1) |
| 5043 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 5044 | } |