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

{

    unsigned char response[VNC_AUTH_CHALLENGE_SIZE];

    int i, j, pwlen;

    unsigned char key[8];

    time_t now = time(NULL);



    if (!vs->vd->password || !vs->vd->password[0]) {

        VNC_DEBUG("No password configured on server");

        goto reject;

    }

    if (vs->vd->expires < now) {

        VNC_DEBUG("Password is expired");

        goto reject;

    }



    memcpy(response, vs->challenge, VNC_AUTH_CHALLENGE_SIZE);



    /* Calculate the expected challenge response */

    pwlen = strlen(vs->vd->password);

    for (i=0; i<sizeof(key); i++)

        key[i] = i<pwlen ? vs->vd->password[i] : 0;

    deskey(key, EN0);

    for (j = 0; j < VNC_AUTH_CHALLENGE_SIZE; j += 8)

        des(response+j, response+j);



    /* Compare expected vs actual challenge response */

    if (memcmp(response, data, VNC_AUTH_CHALLENGE_SIZE) != 0) {

        VNC_DEBUG("Client challenge reponse did not match\n");

        goto reject;

    } else {

        VNC_DEBUG("Accepting VNC challenge response\n");

        vnc_write_u32(vs, 0); /* Accept auth */

        vnc_flush(vs);



        start_client_init(vs);

    }

    return 0;



reject:

    vnc_write_u32(vs, 1); /* Reject auth */

    if (vs->minor >= 8) {

        static const char err[] = "Authentication failed";

        vnc_write_u32(vs, sizeof(err));

        vnc_write(vs, err, sizeof(err));

    }

    vnc_flush(vs);

    vnc_client_error(vs);

    return 0;

}

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

{

    unsigned char response[VNC_AUTH_CHALLENGE_SIZE];

    int i, j, pwlen;

    unsigned char key[8];

    time_t now = time(NULL);



    if (!vs->vd->password || !vs->vd->password[0]) {

        VNC_DEBUG("No password configured on server");

        goto reject;

    }

    if (vs->vd->expires < now) {

        VNC_DEBUG("Password is expired");

        goto reject;

    }



    memcpy(response, vs->challenge, VNC_AUTH_CHALLENGE_SIZE);



    

    pwlen = strlen(vs->vd->password);

    for (i=0; i<sizeof(key); i++)

        key[i] = i<pwlen ? vs->vd->password[i] : 0;

    deskey(key, EN0);

    for (j = 0; j < VNC_AUTH_CHALLENGE_SIZE; j += 8)

        des(response+j, response+j);



    

    if (memcmp(response, data, VNC_AUTH_CHALLENGE_SIZE) != 0) {

        VNC_DEBUG("Client challenge reponse did not match\n");

        goto reject;

    } else {

        VNC_DEBUG("Accepting VNC challenge response\n");

        vnc_write_u32(vs, 0); 

        vnc_flush(vs);



        start_client_init(vs);

    }

    return 0;



reject:

    vnc_write_u32(vs, 1); 

    if (vs->minor >= 8) {

        static const char err[] = "Authentication failed";

        vnc_write_u32(vs, sizeof(err));

        vnc_write(vs, err, sizeof(err));

    }

    vnc_flush(vs);

    vnc_client_error(vs);

    return 0;

}

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

{

    unsigned char VAR_3[VNC_AUTH_CHALLENGE_SIZE];

    int VAR_4, VAR_5, VAR_6;

    unsigned char VAR_7[8];

    time_t now = time(NULL);



    if (!VAR_0->vd->password || !VAR_0->vd->password[0]) {

        VNC_DEBUG("No password configured on server");

        goto reject;

    }

    if (VAR_0->vd->expires < now) {

        VNC_DEBUG("Password is expired");

        goto reject;

    }



    memcpy(VAR_3, VAR_0->challenge, VNC_AUTH_CHALLENGE_SIZE);



    

    VAR_6 = strlen(VAR_0->vd->password);

    for (VAR_4=0; VAR_4<sizeof(VAR_7); VAR_4++)

        VAR_7[VAR_4] = VAR_4<VAR_6 ? VAR_0->vd->password[VAR_4] : 0;

    deskey(VAR_7, EN0);

    for (VAR_5 = 0; VAR_5 < VNC_AUTH_CHALLENGE_SIZE; VAR_5 += 8)

        des(VAR_3+VAR_5, VAR_3+VAR_5);



    

    if (memcmp(VAR_3, VAR_1, VNC_AUTH_CHALLENGE_SIZE) != 0) {

        VNC_DEBUG("Client challenge reponse did not match\n");

        goto reject;

    } else {

        VNC_DEBUG("Accepting VNC challenge VAR_3\n");

        vnc_write_u32(VAR_0, 0); 

        vnc_flush(VAR_0);



        start_client_init(VAR_0);

    }

    return 0;



reject:

    vnc_write_u32(VAR_0, 1); 

    if (VAR_0->minor >= 8) {

        static const char VAR_8[] = "Authentication failed";

        vnc_write_u32(VAR_0, sizeof(VAR_8));

        vnc_write(VAR_0, VAR_8, sizeof(VAR_8));

    }

    vnc_flush(VAR_0);

    vnc_client_error(VAR_0);

    return 0;

}

static int FUNC_0(VncState *VAR_0, uint8_t *VAR_1, size_t VAR_2)
{ unsigned char VAR_3[VNC_AUTH_CHALLENGE_SIZE]; int VAR_4, VAR_5, VAR_6; unsigned char VAR_7[8]; time_t now = time(NULL); if (!VAR_0->vd->password || !VAR_0->vd->password[0]) { VNC_DEBUG("No password configured on server"); goto reject; } if (VAR_0->vd->expires < now) { VNC_DEBUG("Password is expired"); goto reject; } memcpy(VAR_3, VAR_0->challenge, VNC_AUTH_CHALLENGE_SIZE); VAR_6 = strlen(VAR_0->vd->password); for (VAR_4=0; VAR_4<sizeof(VAR_7); VAR_4++) VAR_7[VAR_4] = VAR_4<VAR_6 ? VAR_0->vd->password[VAR_4] : 0; deskey(VAR_7, EN0); for (VAR_5 = 0; VAR_5 < VNC_AUTH_CHALLENGE_SIZE; VAR_5 += 8) des(VAR_3+VAR_5, VAR_3+VAR_5); if (memcmp(VAR_3, VAR_1, VNC_AUTH_CHALLENGE_SIZE) != 0) { VNC_DEBUG("Client challenge reponse did not match\n"); goto reject; } else { VNC_DEBUG("Accepting VNC challenge VAR_3\n"); vnc_write_u32(VAR_0, 0); vnc_flush(VAR_0); start_client_init(VAR_0); } return 0; reject:
vnc_write_u32(VAR_0, 1); if (VAR_0->minor >= 8) { static const char VAR_8[] = "Authentication failed"; vnc_write_u32(VAR_0, sizeof(VAR_8)); vnc_write(VAR_0, VAR_8, sizeof(VAR_8)); } vnc_flush(VAR_0); vnc_client_error(VAR_0); return 0; }