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