fn handshake_anti_deadlock() {
        let mut buf = [0; 65535];

        let mut config = Config::new(PROTOCOL_VERSION).unwrap();
        config
            .load_cert_chain_from_pem_file("examples/cert-big.crt")
            .unwrap();
        config
            .load_priv_key_from_pem_file("examples/cert.key")
            .unwrap();
        config
            .set_application_protos(b"\x06proto1\06proto2")
            .unwrap();

        let mut pipe = testing::Pipe::with_server_config(&mut config).unwrap();

        assert_eq!(pipe.client.handshake_status().has_handshake_keys, false);
        assert_eq!(pipe.client.handshake_status().peer_verified_address, false);
        assert_eq!(pipe.server.handshake_status().has_handshake_keys, false);
        assert_eq!(pipe.server.handshake_status().peer_verified_address, true);

        // Client sends padded Initial.
        let (len, _) = pipe.client.send(&mut buf).unwrap();
        assert_eq!(len, 1200);

        // Server receives client's Initial and sends own Initial and Handshake
        // until it's blocked by the anti-amplification limit.
        assert_eq!(pipe.server_recv(&mut buf[..len]), Ok(len));
        let flight = testing::emit_flight(&mut pipe.server).unwrap();

        assert_eq!(pipe.client.handshake_status().has_handshake_keys, false);
        assert_eq!(pipe.client.handshake_status().peer_verified_address, false);
        assert_eq!(pipe.server.handshake_status().has_handshake_keys, true);
        assert_eq!(pipe.server.handshake_status().peer_verified_address, true);

        // Client receives the server flight and sends Handshake ACK, but it is
        // lost.
        testing::process_flight(&mut pipe.client, flight).unwrap();
        testing::emit_flight(&mut pipe.client).unwrap();

        assert_eq!(pipe.client.handshake_status().has_handshake_keys, true);
        assert_eq!(pipe.client.handshake_status().peer_verified_address, false);
        assert_eq!(pipe.server.handshake_status().has_handshake_keys, true);
        assert_eq!(pipe.server.handshake_status().peer_verified_address, true);

        // Make sure client's PTO timer is armed.
        assert!(pipe.client.timeout().is_some());
    }
/// Tests that client avoids handshake deadlock by arming PTO.
Tests that client avoids handshake deadlock by arming PTO.
Tests that client avoids handshake deadlock by arming PTO .
fn handshake_anti_deadlock() {
        let mut buf = [0; 65535];
        let mut config = Config::new(PROTOCOL_VERSION).unwrap();
        config
            .load_cert_chain_from_pem_file("examples/cert-big.crt")
            .unwrap();
        config
            .load_priv_key_from_pem_file("examples/cert.key")
            .unwrap();
        config
            .set_application_protos(b"\x06proto1\06proto2")
            .unwrap();
        let mut pipe = testing::Pipe::with_server_config(&mut config).unwrap();
        assert_eq!(pipe.client.handshake_status().has_handshake_keys, false);
        assert_eq!(pipe.client.handshake_status().peer_verified_address, false);
        assert_eq!(pipe.server.handshake_status().has_handshake_keys, false);
        assert_eq!(pipe.server.handshake_status().peer_verified_address, true);
        // Client sends padded Initial.
        let (len, _) = pipe.client.send(&mut buf).unwrap();
        assert_eq!(len, 1200);
        // Server receives client's Initial and sends own Initial and Handshake
        // until it's blocked by the anti-amplification limit.
        assert_eq!(pipe.server_recv(&mut buf[..len]), Ok(len));
        let flight = testing::emit_flight(&mut pipe.server).unwrap();
        assert_eq!(pipe.client.handshake_status().has_handshake_keys, false);
        assert_eq!(pipe.client.handshake_status().peer_verified_address, false);
        assert_eq!(pipe.server.handshake_status().has_handshake_keys, true);
        assert_eq!(pipe.server.handshake_status().peer_verified_address, true);
        // Client receives the server flight and sends Handshake ACK, but it is
        // lost.
        testing::process_flight(&mut pipe.client, flight).unwrap();
        testing::emit_flight(&mut pipe.client).unwrap();
        assert_eq!(pipe.client.handshake_status().has_handshake_keys, true);
        assert_eq!(pipe.client.handshake_status().peer_verified_address, false);
        assert_eq!(pipe.server.handshake_status().has_handshake_keys, true);
        assert_eq!(pipe.server.handshake_status().peer_verified_address, true);
        // Make sure client's PTO timer is armed.
        assert!(pipe.client.timeout().is_some());
    }
fn handshake_anti_deadlock ( ) { let mut buf = [ 0 ; 65535 ] ; let mut config = Config :: new ( PROTOCOL_VERSION ) . unwrap ( ) ; config . load_cert_chain_from_pem_file ( " " ) . unwrap ( ) ; config . load_priv_key_from_pem_file ( " " ) . unwrap ( ) ; config . set_application_protos ( b" \x06 \0 " ) . unwrap ( ) ; let mut pipe = testing :: Pipe :: with_server_config ( & mut config ) . unwrap ( ) ; assert_eq ! ( pipe client handshake_status ( ) has_handshake_keys false ) ; assert_eq ! ( pipe client handshake_status ( ) peer_verified_address false ) ; assert_eq ! ( pipe server handshake_status ( ) has_handshake_keys false ) ; assert_eq ! ( pipe server handshake_status ( ) peer_verified_address true ) ; // Client sends padded Initial. let ( len , _ ) = pipe . client . send ( & mut buf ) . unwrap ( ) ; assert_eq ! ( len 1200 ) ; // Server receives client's Initial and sends own Initial and Handshake // until it's blocked by the anti-amplification limit. assert_eq ! ( pipe server_recv ( mut buf [ len ] ) Ok ( len ) ) ; let flight = testing :: emit_flight ( & mut pipe . server ) . unwrap ( ) ; assert_eq ! ( pipe client handshake_status ( ) has_handshake_keys false ) ; assert_eq ! ( pipe client handshake_status ( ) peer_verified_address false ) ; assert_eq ! ( pipe server handshake_status ( ) has_handshake_keys true ) ; assert_eq ! ( pipe server handshake_status ( ) peer_verified_address true ) ; // Client receives the server flight and sends Handshake ACK, but it is // lost. testing :: process_flight ( & mut pipe . client , flight ) . unwrap ( ) ; testing :: emit_flight ( & mut pipe . client ) . unwrap ( ) ; assert_eq ! ( pipe client handshake_status ( ) has_handshake_keys true ) ; assert_eq ! ( pipe client handshake_status ( ) peer_verified_address false ) ; assert_eq ! ( pipe server handshake_status ( ) has_handshake_keys true ) ; assert_eq ! ( pipe server handshake_status ( ) peer_verified_address true ) ; // Make sure client's PTO timer is armed. assert ! ( pipe client timeout ( ) is_some ( ) ) ; }
Tests that client avoids handshake deadlock by arming PTO.
Tests that client avoids handshake deadlock by arming PTO .