static int protocol_client_vencrypt_auth(VncState *vs, uint8_t *data, size_t len)

{

    int auth = read_u32(data, 0);



    if (auth != vs->vd->subauth) {

        VNC_DEBUG("Rejecting auth %d\n", auth);

        vnc_write_u8(vs, 0); /* Reject auth */

        vnc_flush(vs);

        vnc_client_error(vs);

    } else {

        VNC_DEBUG("Accepting auth %d, setting up TLS for handshake\n", auth);

        vnc_write_u8(vs, 1); /* Accept auth */

        vnc_flush(vs);



        if (vnc_tls_client_setup(vs, NEED_X509_AUTH(vs)) < 0) {

            VNC_DEBUG("Failed to setup TLS\n");

            return 0;

        }



        VNC_DEBUG("Start TLS VeNCrypt handshake process\n");

        if (vnc_start_vencrypt_handshake(vs) < 0) {

            VNC_DEBUG("Failed to start TLS handshake\n");

            return 0;

        }

    }

    return 0;

}

static int protocol_client_vencrypt_auth(VncState *vs, uint8_t *data, size_t len)

{

    int auth = read_u32(data, 0);



    if (auth != vs->vd->subauth) {

        VNC_DEBUG("Rejecting auth %d\n", auth);

        vnc_write_u8(vs, 0); 

        vnc_flush(vs);

        vnc_client_error(vs);

    } else {

        VNC_DEBUG("Accepting auth %d, setting up TLS for handshake\n", auth);

        vnc_write_u8(vs, 1); 

        vnc_flush(vs);



        if (vnc_tls_client_setup(vs, NEED_X509_AUTH(vs)) < 0) {

            VNC_DEBUG("Failed to setup TLS\n");

            return 0;

        }



        VNC_DEBUG("Start TLS VeNCrypt handshake process\n");

        if (vnc_start_vencrypt_handshake(vs) < 0) {

            VNC_DEBUG("Failed to start TLS handshake\n");

            return 0;

        }

    }

    return 0;

}

static int FUNC_0(VncState *VAR_0, uint8_t *VAR_1, size_t VAR_2)

{

    int VAR_3 = read_u32(VAR_1, 0);



    if (VAR_3 != VAR_0->vd->subauth) {

        VNC_DEBUG("Rejecting VAR_3 %d\n", VAR_3);

        vnc_write_u8(VAR_0, 0); 

        vnc_flush(VAR_0);

        vnc_client_error(VAR_0);

    } else {

        VNC_DEBUG("Accepting VAR_3 %d, setting up TLS for handshake\n", VAR_3);

        vnc_write_u8(VAR_0, 1); 

        vnc_flush(VAR_0);



        if (vnc_tls_client_setup(VAR_0, NEED_X509_AUTH(VAR_0)) < 0) {

            VNC_DEBUG("Failed to setup TLS\n");

            return 0;

        }



        VNC_DEBUG("Start TLS VeNCrypt handshake process\n");

        if (vnc_start_vencrypt_handshake(VAR_0) < 0) {

            VNC_DEBUG("Failed to start TLS handshake\n");

            return 0;

        }

    }

    return 0;

}

static int FUNC_0(VncState *VAR_0, uint8_t *VAR_1, size_t VAR_2)
{ int VAR_3 = read_u32(VAR_1, 0); if (VAR_3 != VAR_0->vd->subauth) { VNC_DEBUG("Rejecting VAR_3 %d\n", VAR_3); vnc_write_u8(VAR_0, 0); vnc_flush(VAR_0); vnc_client_error(VAR_0); } else { VNC_DEBUG("Accepting VAR_3 %d, setting up TLS for handshake\n", VAR_3); vnc_write_u8(VAR_0, 1); vnc_flush(VAR_0); if (vnc_tls_client_setup(VAR_0, NEED_X509_AUTH(VAR_0)) < 0) { VNC_DEBUG("Failed to setup TLS\n"); return 0; } VNC_DEBUG("Start TLS VeNCrypt handshake process\n"); if (vnc_start_vencrypt_handshake(VAR_0) < 0) { VNC_DEBUG("Failed to start TLS handshake\n"); return 0; } } return 0; }