• M
    DTLSv1_listen rewrite · e3d0dae7
    Matt Caswell 提交于
    The existing implementation of DTLSv1_listen() is fundamentally flawed. This
    function is used in DTLS solutions to listen for new incoming connections
    from DTLS clients. A client will send an initial ClientHello. The server
    will respond with a HelloVerifyRequest containing a unique cookie. The
    client the responds with a second ClientHello - which this time contains the
    cookie.
    
    Once the cookie has been verified then DTLSv1_listen() returns to user code,
    which is typically expected to continue the handshake with a call to (for
    example) SSL_accept().
    
    Whilst listening for incoming ClientHellos, the underlying BIO is usually in
    an unconnected state. Therefore ClientHellos can come in from *any* peer.
    The arrival of the first ClientHello without the cookie, and the second one
    with it, could be interspersed with other intervening messages from
    different clients.
    
    The whole purpose of this mechanism is as a defence against DoS attacks. The
    idea is to avoid allocating state on the server until the client has
    verified that it is capable of receiving messages at the address it claims
    to come from. However the existing DTLSv1_listen() implementation completely
    fails to do this. It attempts to super-impose itself on the standard state
    machine and reuses all of this code. However the standard state machine
    expects to operate in a stateful manner with a single client, and this can
    cause various problems.
    
    A second more minor issue is that the return codes from this function are
    quite confused, with no distinction made between fatal and non-fatal errors.
    Most user code treats all errors as non-fatal, and simply retries the call
    to DTLSv1_listen().
    
    This commit completely rewrites the implementation of DTLSv1_listen() and
    provides a stand alone implementation that does not rely on the existing
    state machine. It also provides more consistent return codes.
    Reviewed-by: NAndy Polyakov <appro@openssl.org>
    e3d0dae7
ssl.h 117.4 KB