2009-03-07 07:44:29 +08:00
|
|
|
/*
|
|
|
|
* QEMU VNC display driver: VeNCrypt authentication setup
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Anthony Liguori <anthony@codemonkey.ws>
|
|
|
|
* Copyright (C) 2006 Fabrice Bellard
|
|
|
|
* Copyright (C) 2009 Red Hat, Inc
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2016-01-30 01:49:51 +08:00
|
|
|
#include "qemu/osdep.h"
|
2009-03-07 07:44:29 +08:00
|
|
|
#include "vnc.h"
|
include/qemu/osdep.h: Don't include qapi/error.h
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the
Error typedef. Since then, we've moved to include qemu/osdep.h
everywhere. Its file comment explains: "To avoid getting into
possible circular include dependencies, this file should not include
any other QEMU headers, with the exceptions of config-host.h,
compiler.h, os-posix.h and os-win32.h, all of which are doing a
similar job to this file and are under similar constraints."
qapi/error.h doesn't do a similar job, and it doesn't adhere to
similar constraints: it includes qapi-types.h. That's in excess of
100KiB of crap most .c files don't actually need.
Add the typedef to qemu/typedefs.h, and include that instead of
qapi/error.h. Include qapi/error.h in .c files that need it and don't
get it now. Include qapi-types.h in qom/object.h for uint16List.
Update scripts/clean-includes accordingly. Update it further to match
reality: replace config.h by config-target.h, add sysemu/os-posix.h,
sysemu/os-win32.h. Update the list of includes in the qemu/osdep.h
comment quoted above similarly.
This reduces the number of objects depending on qapi/error.h from "all
of them" to less than a third. Unfortunately, the number depending on
qapi-types.h shrinks only a little. More work is needed for that one.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[Fix compilation without the spice devel packages. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-14 16:01:28 +08:00
|
|
|
#include "qapi/error.h"
|
2013-08-21 23:02:47 +08:00
|
|
|
#include "qemu/main-loop.h"
|
2017-09-21 20:15:27 +08:00
|
|
|
#include "trace.h"
|
2009-03-07 07:44:29 +08:00
|
|
|
|
|
|
|
static void start_auth_vencrypt_subauth(VncState *vs)
|
|
|
|
{
|
2011-06-23 20:31:41 +08:00
|
|
|
switch (vs->subauth) {
|
2009-03-07 07:44:29 +08:00
|
|
|
case VNC_AUTH_VENCRYPT_TLSNONE:
|
|
|
|
case VNC_AUTH_VENCRYPT_X509NONE:
|
|
|
|
vnc_write_u32(vs, 0); /* Accept auth completion */
|
|
|
|
start_client_init(vs);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VNC_AUTH_VENCRYPT_TLSVNC:
|
|
|
|
case VNC_AUTH_VENCRYPT_X509VNC:
|
|
|
|
start_auth_vnc(vs);
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef CONFIG_VNC_SASL
|
|
|
|
case VNC_AUTH_VENCRYPT_TLSSASL:
|
|
|
|
case VNC_AUTH_VENCRYPT_X509SASL:
|
2012-07-08 14:56:53 +08:00
|
|
|
start_auth_sasl(vs);
|
|
|
|
break;
|
2009-03-07 07:44:29 +08:00
|
|
|
#endif /* CONFIG_VNC_SASL */
|
|
|
|
|
|
|
|
default: /* Should not be possible, but just in case */
|
2017-09-21 20:15:28 +08:00
|
|
|
trace_vnc_auth_fail(vs, vs->auth, "Unhandled VeNCrypt subauth", "");
|
2009-03-07 07:44:29 +08:00
|
|
|
vnc_write_u8(vs, 1);
|
|
|
|
if (vs->minor >= 8) {
|
|
|
|
static const char err[] = "Unsupported authentication type";
|
|
|
|
vnc_write_u32(vs, sizeof(err));
|
|
|
|
vnc_write(vs, err, sizeof(err));
|
|
|
|
}
|
|
|
|
vnc_client_error(vs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-11 22:20:58 +08:00
|
|
|
static void vnc_tls_handshake_done(QIOTask *task,
|
2015-03-03 03:01:05 +08:00
|
|
|
gpointer user_data)
|
2015-04-09 02:04:11 +08:00
|
|
|
{
|
2015-03-03 03:01:05 +08:00
|
|
|
VncState *vs = user_data;
|
2016-08-11 22:20:58 +08:00
|
|
|
Error *err = NULL;
|
2009-03-07 07:44:29 +08:00
|
|
|
|
2016-08-11 22:20:58 +08:00
|
|
|
if (qio_task_propagate_error(task, &err)) {
|
2017-09-21 20:15:28 +08:00
|
|
|
trace_vnc_auth_fail(vs, vs->auth, "TLS handshake failed",
|
|
|
|
error_get_pretty(err));
|
2015-03-03 03:01:05 +08:00
|
|
|
vnc_client_error(vs);
|
2016-08-11 22:20:58 +08:00
|
|
|
error_free(err);
|
2015-03-03 03:01:05 +08:00
|
|
|
} else {
|
2017-09-12 23:21:47 +08:00
|
|
|
if (vs->ioc_tag) {
|
|
|
|
g_source_remove(vs->ioc_tag);
|
|
|
|
}
|
2015-02-28 00:20:57 +08:00
|
|
|
vs->ioc_tag = qio_channel_add_watch(
|
|
|
|
vs->ioc, G_IO_IN | G_IO_OUT, vnc_client_io, vs, NULL);
|
ui: convert VNC server to use QCryptoTLSSession
Switch VNC server over to using the QCryptoTLSSession object
for the TLS session. This removes the direct use of gnutls
from the VNC server code. It also removes most knowledge
about TLS certificate handling from the VNC server code.
This has the nice effect that all the CONFIG_VNC_TLS
conditionals go away and the user gets an actual error
message when requesting TLS instead of it being silently
ignored.
With this change, the existing configuration options for
enabling TLS with -vnc are deprecated.
Old syntax for anon-DH credentials:
-vnc hostname:0,tls
New syntax:
-object tls-creds-anon,id=tls0,endpoint=server \
-vnc hostname:0,tls-creds=tls0
Old syntax for x509 credentials, no client certs:
-vnc hostname:0,tls,x509=/path/to/certs
New syntax:
-object tls-creds-x509,id=tls0,dir=/path/to/certs,endpoint=server,verify-peer=no \
-vnc hostname:0,tls-creds=tls0
Old syntax for x509 credentials, requiring client certs:
-vnc hostname:0,tls,x509verify=/path/to/certs
New syntax:
-object tls-creds-x509,id=tls0,dir=/path/to/certs,endpoint=server,verify-peer=yes \
-vnc hostname:0,tls-creds=tls0
This aligns VNC with the way TLS credentials are to be
configured in the future for chardev, nbd and migration
backends. It also has the benefit that the same TLS
credentials can be shared across multiple VNC server
instances, if desired.
If someone uses the deprecated syntax, it will internally
result in the creation of a 'tls-creds' object with an ID
based on the VNC server ID. This allows backwards compat
with the CLI syntax, while still deleting all the original
TLS code from the VNC server.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2015-08-06 21:39:32 +08:00
|
|
|
start_auth_vencrypt_subauth(vs);
|
|
|
|
}
|
2009-03-07 07:44:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int protocol_client_vencrypt_auth(VncState *vs, uint8_t *data, size_t len)
|
|
|
|
{
|
|
|
|
int auth = read_u32(data, 0);
|
|
|
|
|
2017-09-21 20:15:28 +08:00
|
|
|
trace_vnc_auth_vencrypt_subauth(vs, auth);
|
2011-06-23 20:31:41 +08:00
|
|
|
if (auth != vs->subauth) {
|
2017-09-21 20:15:28 +08:00
|
|
|
trace_vnc_auth_fail(vs, vs->auth, "Unsupported sub-auth version", "");
|
2009-03-07 07:44:29 +08:00
|
|
|
vnc_write_u8(vs, 0); /* Reject auth */
|
|
|
|
vnc_flush(vs);
|
|
|
|
vnc_client_error(vs);
|
|
|
|
} else {
|
ui: convert VNC server to use QCryptoTLSSession
Switch VNC server over to using the QCryptoTLSSession object
for the TLS session. This removes the direct use of gnutls
from the VNC server code. It also removes most knowledge
about TLS certificate handling from the VNC server code.
This has the nice effect that all the CONFIG_VNC_TLS
conditionals go away and the user gets an actual error
message when requesting TLS instead of it being silently
ignored.
With this change, the existing configuration options for
enabling TLS with -vnc are deprecated.
Old syntax for anon-DH credentials:
-vnc hostname:0,tls
New syntax:
-object tls-creds-anon,id=tls0,endpoint=server \
-vnc hostname:0,tls-creds=tls0
Old syntax for x509 credentials, no client certs:
-vnc hostname:0,tls,x509=/path/to/certs
New syntax:
-object tls-creds-x509,id=tls0,dir=/path/to/certs,endpoint=server,verify-peer=no \
-vnc hostname:0,tls-creds=tls0
Old syntax for x509 credentials, requiring client certs:
-vnc hostname:0,tls,x509verify=/path/to/certs
New syntax:
-object tls-creds-x509,id=tls0,dir=/path/to/certs,endpoint=server,verify-peer=yes \
-vnc hostname:0,tls-creds=tls0
This aligns VNC with the way TLS credentials are to be
configured in the future for chardev, nbd and migration
backends. It also has the benefit that the same TLS
credentials can be shared across multiple VNC server
instances, if desired.
If someone uses the deprecated syntax, it will internally
result in the creation of a 'tls-creds' object with an ID
based on the VNC server ID. This allows backwards compat
with the CLI syntax, while still deleting all the original
TLS code from the VNC server.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2015-08-06 21:39:32 +08:00
|
|
|
Error *err = NULL;
|
2015-03-03 03:01:05 +08:00
|
|
|
QIOChannelTLS *tls;
|
2009-03-07 07:44:29 +08:00
|
|
|
vnc_write_u8(vs, 1); /* Accept auth */
|
|
|
|
vnc_flush(vs);
|
|
|
|
|
2015-03-03 03:01:05 +08:00
|
|
|
if (vs->ioc_tag) {
|
|
|
|
g_source_remove(vs->ioc_tag);
|
|
|
|
vs->ioc_tag = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
tls = qio_channel_tls_new_server(
|
|
|
|
vs->ioc,
|
|
|
|
vs->vd->tlscreds,
|
2016-02-19 02:40:24 +08:00
|
|
|
vs->vd->tlsauthzid,
|
2015-03-03 03:01:05 +08:00
|
|
|
&err);
|
|
|
|
if (!tls) {
|
2017-09-21 20:15:28 +08:00
|
|
|
trace_vnc_auth_fail(vs, vs->auth, "TLS setup failed",
|
|
|
|
error_get_pretty(err));
|
ui: convert VNC server to use QCryptoTLSSession
Switch VNC server over to using the QCryptoTLSSession object
for the TLS session. This removes the direct use of gnutls
from the VNC server code. It also removes most knowledge
about TLS certificate handling from the VNC server code.
This has the nice effect that all the CONFIG_VNC_TLS
conditionals go away and the user gets an actual error
message when requesting TLS instead of it being silently
ignored.
With this change, the existing configuration options for
enabling TLS with -vnc are deprecated.
Old syntax for anon-DH credentials:
-vnc hostname:0,tls
New syntax:
-object tls-creds-anon,id=tls0,endpoint=server \
-vnc hostname:0,tls-creds=tls0
Old syntax for x509 credentials, no client certs:
-vnc hostname:0,tls,x509=/path/to/certs
New syntax:
-object tls-creds-x509,id=tls0,dir=/path/to/certs,endpoint=server,verify-peer=no \
-vnc hostname:0,tls-creds=tls0
Old syntax for x509 credentials, requiring client certs:
-vnc hostname:0,tls,x509verify=/path/to/certs
New syntax:
-object tls-creds-x509,id=tls0,dir=/path/to/certs,endpoint=server,verify-peer=yes \
-vnc hostname:0,tls-creds=tls0
This aligns VNC with the way TLS credentials are to be
configured in the future for chardev, nbd and migration
backends. It also has the benefit that the same TLS
credentials can be shared across multiple VNC server
instances, if desired.
If someone uses the deprecated syntax, it will internally
result in the creation of a 'tls-creds' object with an ID
based on the VNC server ID. This allows backwards compat
with the CLI syntax, while still deleting all the original
TLS code from the VNC server.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2015-08-06 21:39:32 +08:00
|
|
|
error_free(err);
|
|
|
|
vnc_client_error(vs);
|
2009-03-07 07:44:29 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-09-30 18:57:14 +08:00
|
|
|
qio_channel_set_name(QIO_CHANNEL(tls), "vnc-server-tls");
|
2015-03-03 03:01:05 +08:00
|
|
|
object_unref(OBJECT(vs->ioc));
|
|
|
|
vs->ioc = QIO_CHANNEL(tls);
|
2017-09-21 20:15:27 +08:00
|
|
|
trace_vnc_client_io_wrap(vs, vs->ioc, "tls");
|
2015-03-03 03:01:05 +08:00
|
|
|
vs->tls = qio_channel_tls_get_session(tls);
|
|
|
|
|
|
|
|
qio_channel_tls_handshake(tls,
|
|
|
|
vnc_tls_handshake_done,
|
|
|
|
vs,
|
2018-03-05 14:43:24 +08:00
|
|
|
NULL,
|
2015-03-03 03:01:05 +08:00
|
|
|
NULL);
|
2009-03-07 07:44:29 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int protocol_client_vencrypt_init(VncState *vs, uint8_t *data, size_t len)
|
|
|
|
{
|
2017-09-21 20:15:28 +08:00
|
|
|
trace_vnc_auth_vencrypt_version(vs, (int)data[0], (int)data[1]);
|
2009-03-07 07:44:29 +08:00
|
|
|
if (data[0] != 0 ||
|
|
|
|
data[1] != 2) {
|
2017-09-21 20:15:28 +08:00
|
|
|
trace_vnc_auth_fail(vs, vs->auth, "Unsupported version", "");
|
2009-03-07 07:44:29 +08:00
|
|
|
vnc_write_u8(vs, 1); /* Reject version */
|
|
|
|
vnc_flush(vs);
|
|
|
|
vnc_client_error(vs);
|
|
|
|
} else {
|
|
|
|
vnc_write_u8(vs, 0); /* Accept version */
|
|
|
|
vnc_write_u8(vs, 1); /* Number of sub-auths */
|
2011-06-23 20:31:41 +08:00
|
|
|
vnc_write_u32(vs, vs->subauth); /* The supported auth */
|
2009-03-07 07:44:29 +08:00
|
|
|
vnc_flush(vs);
|
|
|
|
vnc_read_when(vs, protocol_client_vencrypt_auth, 4);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void start_auth_vencrypt(VncState *vs)
|
|
|
|
{
|
|
|
|
/* Send VeNCrypt version 0.2 */
|
|
|
|
vnc_write_u8(vs, 0);
|
|
|
|
vnc_write_u8(vs, 2);
|
|
|
|
|
|
|
|
vnc_read_when(vs, protocol_client_vencrypt_init, 2);
|
|
|
|
}
|
|
|
|
|