]> git.proxmox.com Git - mirror_qemu.git/blame - ui/vnc-ws.c
Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging
[mirror_qemu.git] / ui / vnc-ws.c
CommitLineData
7536ee4b
TH
1/*
2 * QEMU VNC display driver: Websockets support
3 *
4 * Copyright (C) 2010 Joel Martin
5 * Copyright (C) 2012 Tim Hardeck
6 *
7 * This is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this software; if not, see <http://www.gnu.org/licenses/>.
19 */
20
e16f4c87 21#include "qemu/osdep.h"
da34e65c 22#include "qapi/error.h"
7536ee4b 23#include "vnc.h"
d5f04223 24#include "io/channel-websock.h"
58369e22 25#include "qemu/bswap.h"
0057a0d5 26
2cc45228
DB
27static void vncws_tls_handshake_done(Object *source,
28 Error *err,
29 gpointer user_data)
30{
31 VncState *vs = user_data;
4a48aaa9 32
2cc45228
DB
33 if (err) {
34 VNC_DEBUG("Handshake failed %s\n", error_get_pretty(err));
35 vnc_client_error(vs);
36 } else {
d5f04223 37 VNC_DEBUG("TLS handshake complete, starting websocket handshake\n");
04d2529d 38 vs->ioc_tag = qio_channel_add_watch(
2cc45228 39 QIO_CHANNEL(vs->ioc), G_IO_IN, vncws_handshake_io, vs, NULL);
3e305e4a 40 }
0057a0d5
TH
41}
42
2cc45228 43
04d2529d
DB
44gboolean vncws_tls_handshake_io(QIOChannel *ioc G_GNUC_UNUSED,
45 GIOCondition condition G_GNUC_UNUSED,
46 void *opaque)
0057a0d5 47{
2cc45228
DB
48 VncState *vs = opaque;
49 QIOChannelTLS *tls;
3e305e4a 50 Error *err = NULL;
0057a0d5 51
2cc45228
DB
52 VNC_DEBUG("TLS Websocket connection required\n");
53 if (vs->ioc_tag) {
54 g_source_remove(vs->ioc_tag);
55 vs->ioc_tag = 0;
56 }
57
58 tls = qio_channel_tls_new_server(
59 vs->ioc,
60 vs->vd->tlscreds,
61 vs->vd->tlsaclname,
62 &err);
63 if (!tls) {
64 VNC_DEBUG("Failed to setup TLS %s\n", error_get_pretty(err));
3e305e4a
DB
65 error_free(err);
66 vnc_client_error(vs);
04d2529d 67 return TRUE;
0057a0d5 68 }
3e305e4a 69
3e305e4a 70 VNC_DEBUG("Start TLS WS handshake process\n");
2cc45228
DB
71 object_unref(OBJECT(vs->ioc));
72 vs->ioc = QIO_CHANNEL(tls);
73 vs->tls = qio_channel_tls_get_session(tls);
74
75 qio_channel_tls_handshake(tls,
76 vncws_tls_handshake_done,
77 vs,
78 NULL);
79
04d2529d 80 return TRUE;
0057a0d5 81}
0057a0d5 82
7536ee4b 83
d5f04223
DB
84static void vncws_handshake_done(Object *source,
85 Error *err,
86 gpointer user_data)
87{
88 VncState *vs = user_data;
7536ee4b 89
d5f04223
DB
90 if (err) {
91 VNC_DEBUG("Websock handshake failed %s\n", error_get_pretty(err));
92 vnc_client_error(vs);
93 } else {
94 VNC_DEBUG("Websock handshake complete, starting VNC protocol\n");
95 vnc_init_state(vs);
04d2529d
DB
96 vs->ioc_tag = qio_channel_add_watch(
97 vs->ioc, G_IO_IN, vnc_client_io, vs, NULL);
7536ee4b
TH
98 }
99}
100
101
04d2529d
DB
102gboolean vncws_handshake_io(QIOChannel *ioc G_GNUC_UNUSED,
103 GIOCondition condition G_GNUC_UNUSED,
104 void *opaque)
105{
106 VncState *vs = opaque;
d5f04223 107 QIOChannelWebsock *wioc;
7536ee4b 108
d5f04223
DB
109 VNC_DEBUG("Websocket negotiate starting\n");
110 if (vs->ioc_tag) {
111 g_source_remove(vs->ioc_tag);
112 vs->ioc_tag = 0;
7536ee4b
TH
113 }
114
d5f04223 115 wioc = qio_channel_websock_new_server(vs->ioc);
7536ee4b 116
d5f04223
DB
117 object_unref(OBJECT(vs->ioc));
118 vs->ioc = QIO_CHANNEL(wioc);
7536ee4b 119
d5f04223
DB
120 qio_channel_websock_handshake(wioc,
121 vncws_handshake_done,
122 vs,
123 NULL);
7536ee4b 124
d5f04223 125 return TRUE;
7536ee4b 126}