From a list of proposed ciphersuites, this function returns a list of
    usable cipher suites, i.e. for which key exchange, cipher and hash
    algorithms are known to be implemented and usable in current version of the
    TLS extension. The order of the cipher suites in the list returned by the
    function matches the one of the proposal.

def get_usable_ciphersuites(l, kx):
    """
    From a list of proposed ciphersuites, this function returns a list of
    usable cipher suites, i.e. for which key exchange, cipher and hash
    algorithms are known to be implemented and usable in current version of the
    TLS extension. The order of the cipher suites in the list returned by the
    function matches the one of the proposal.
    """
    res = []
    for c in l:
        if c in _tls_cipher_suites_cls:
            ciph = _tls_cipher_suites_cls[c]
            if ciph.usable:
                # XXX select among RSA and ECDSA cipher suites
                # according to the key(s) the server was given
                if ciph.kx_alg.anonymous or kx in ciph.kx_alg.name:
                    res.append(c)
    return res