(self, tctx)
| 287 | ) |
| 288 | |
| 289 | def test_simple(self, tctx): |
| 290 | playbook = tutils.Playbook(tls.ServerTLSLayer(tctx)) |
| 291 | tctx.server.address = ("example.mitmproxy.org", 443) |
| 292 | tctx.server.state = ConnectionState.OPEN |
| 293 | tctx.server.sni = "example.mitmproxy.org" |
| 294 | |
| 295 | tssl = SSLTest(server_side=True) |
| 296 | |
| 297 | # send ClientHello, receive ClientHello |
| 298 | data = tutils.Placeholder(bytes) |
| 299 | assert ( |
| 300 | playbook |
| 301 | << tls.TlsStartServerHook(tutils.Placeholder()) |
| 302 | >> reply_tls_start_server() |
| 303 | << commands.SendData(tctx.server, data) |
| 304 | ) |
| 305 | tssl.bio_write(data()) |
| 306 | with pytest.raises(ssl.SSLWantReadError): |
| 307 | tssl.do_handshake() |
| 308 | |
| 309 | # finish handshake (mitmproxy) |
| 310 | finish_handshake(playbook, tctx.server, tssl) |
| 311 | |
| 312 | # finish handshake (locally) |
| 313 | tssl.do_handshake() |
| 314 | playbook >> events.DataReceived(tctx.server, tssl.bio_read()) |
| 315 | playbook << None |
| 316 | assert playbook |
| 317 | |
| 318 | assert tctx.server.tls_established |
| 319 | |
| 320 | # Echo |
| 321 | assert ( |
| 322 | playbook |
| 323 | >> events.DataReceived(tctx.client, b"foo") |
| 324 | << layer.NextLayerHook(tutils.Placeholder()) |
| 325 | >> tutils.reply_next_layer(TlsEchoLayer) |
| 326 | << commands.SendData(tctx.client, b"foo") |
| 327 | ) |
| 328 | _test_echo(playbook, tssl, tctx.server) |
| 329 | |
| 330 | with pytest.raises(ssl.SSLWantReadError): |
| 331 | tssl.obj.unwrap() |
| 332 | assert ( |
| 333 | playbook |
| 334 | >> events.DataReceived(tctx.server, tssl.bio_read()) |
| 335 | << commands.CloseConnection(tctx.server) |
| 336 | >> events.ConnectionClosed(tctx.server) |
| 337 | << None |
| 338 | ) |
| 339 | |
| 340 | def test_untrusted_cert(self, tctx): |
| 341 | """If the certificate is not trusted, we should fail.""" |
nothing calls this directly
no test coverage detected