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; }
void vncws_tls_handshake_io(void *opaque) { struct VncState *vs = (struct VncState *)opaque; if (!vs->tls.session) { VNC_DEBUG("TLS Websocket setup\n"); if (vnc_tls_client_setup(vs, vs->vd->tls.x509cert != NULL) < 0) { return; } } VNC_DEBUG("Handshake IO continue\n"); vncws_start_tls_handshake(vs); }
void vncws_tls_handshake_peek(void *opaque) { VncState *vs = opaque; long ret; if (!vs->ws_tls.session) { char peek[4]; ret = qemu_recv(vs->csock, peek, sizeof(peek), MSG_PEEK); if (ret && (strncmp(peek, "\x16", 1) == 0 || strncmp(peek, "\x80", 1) == 0)) { VNC_DEBUG("TLS Websocket connection recognized"); vnc_tls_client_setup(vs, 1); vncws_start_tls_handshake(vs); } else { vncws_handshake_read(vs); } } else { qemu_set_fd_handler2(vs->csock, NULL, vncws_handshake_read, NULL, vs); } }