qio: non-default context for TLS handshake
A new parameter "context" is added to qio_channel_tls_handshake() is to allow the TLS to be run on a non-default context. Still, no functional change. Signed-off-by: Peter Xu <peterx@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
8005fdd8fa
commit
1939ccdaa6
@ -703,6 +703,7 @@ static void tcp_chr_tls_init(Chardev *chr)
|
|||||||
qio_channel_tls_handshake(tioc,
|
qio_channel_tls_handshake(tioc,
|
||||||
tcp_chr_tls_handshake,
|
tcp_chr_tls_handshake,
|
||||||
chr,
|
chr,
|
||||||
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,6 +116,8 @@ qio_channel_tls_new_client(QIOChannel *master,
|
|||||||
* @func: the callback to invoke when completed
|
* @func: the callback to invoke when completed
|
||||||
* @opaque: opaque data to pass to @func
|
* @opaque: opaque data to pass to @func
|
||||||
* @destroy: optional callback to free @opaque
|
* @destroy: optional callback to free @opaque
|
||||||
|
* @context: the context that TLS handshake will run with. If %NULL,
|
||||||
|
* the default context will be used
|
||||||
*
|
*
|
||||||
* Perform the TLS session handshake. This method
|
* Perform the TLS session handshake. This method
|
||||||
* will return immediately and the handshake will
|
* will return immediately and the handshake will
|
||||||
@ -126,7 +128,8 @@ qio_channel_tls_new_client(QIOChannel *master,
|
|||||||
void qio_channel_tls_handshake(QIOChannelTLS *ioc,
|
void qio_channel_tls_handshake(QIOChannelTLS *ioc,
|
||||||
QIOTaskFunc func,
|
QIOTaskFunc func,
|
||||||
gpointer opaque,
|
gpointer opaque,
|
||||||
GDestroyNotify destroy);
|
GDestroyNotify destroy,
|
||||||
|
GMainContext *context);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* qio_channel_tls_get_session:
|
* qio_channel_tls_get_session:
|
||||||
|
@ -140,13 +140,19 @@ qio_channel_tls_new_client(QIOChannel *master,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct QIOChannelTLSData {
|
||||||
|
QIOTask *task;
|
||||||
|
GMainContext *context;
|
||||||
|
};
|
||||||
|
typedef struct QIOChannelTLSData QIOChannelTLSData;
|
||||||
|
|
||||||
static gboolean qio_channel_tls_handshake_io(QIOChannel *ioc,
|
static gboolean qio_channel_tls_handshake_io(QIOChannel *ioc,
|
||||||
GIOCondition condition,
|
GIOCondition condition,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
|
|
||||||
static void qio_channel_tls_handshake_task(QIOChannelTLS *ioc,
|
static void qio_channel_tls_handshake_task(QIOChannelTLS *ioc,
|
||||||
QIOTask *task)
|
QIOTask *task,
|
||||||
|
GMainContext *context)
|
||||||
{
|
{
|
||||||
Error *err = NULL;
|
Error *err = NULL;
|
||||||
QCryptoTLSSessionHandshakeStatus status;
|
QCryptoTLSSessionHandshakeStatus status;
|
||||||
@ -171,6 +177,15 @@ static void qio_channel_tls_handshake_task(QIOChannelTLS *ioc,
|
|||||||
qio_task_complete(task);
|
qio_task_complete(task);
|
||||||
} else {
|
} else {
|
||||||
GIOCondition condition;
|
GIOCondition condition;
|
||||||
|
QIOChannelTLSData *data = g_new0(typeof(*data), 1);
|
||||||
|
|
||||||
|
data->task = task;
|
||||||
|
data->context = context;
|
||||||
|
|
||||||
|
if (context) {
|
||||||
|
g_main_context_ref(context);
|
||||||
|
}
|
||||||
|
|
||||||
if (status == QCRYPTO_TLS_HANDSHAKE_SENDING) {
|
if (status == QCRYPTO_TLS_HANDSHAKE_SENDING) {
|
||||||
condition = G_IO_OUT;
|
condition = G_IO_OUT;
|
||||||
} else {
|
} else {
|
||||||
@ -178,11 +193,12 @@ static void qio_channel_tls_handshake_task(QIOChannelTLS *ioc,
|
|||||||
}
|
}
|
||||||
|
|
||||||
trace_qio_channel_tls_handshake_pending(ioc, status);
|
trace_qio_channel_tls_handshake_pending(ioc, status);
|
||||||
qio_channel_add_watch(ioc->master,
|
qio_channel_add_watch_full(ioc->master,
|
||||||
condition,
|
condition,
|
||||||
qio_channel_tls_handshake_io,
|
qio_channel_tls_handshake_io,
|
||||||
task,
|
data,
|
||||||
NULL);
|
NULL,
|
||||||
|
context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,12 +207,18 @@ static gboolean qio_channel_tls_handshake_io(QIOChannel *ioc,
|
|||||||
GIOCondition condition,
|
GIOCondition condition,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
QIOTask *task = user_data;
|
QIOChannelTLSData *data = user_data;
|
||||||
|
QIOTask *task = data->task;
|
||||||
|
GMainContext *context = data->context;
|
||||||
QIOChannelTLS *tioc = QIO_CHANNEL_TLS(
|
QIOChannelTLS *tioc = QIO_CHANNEL_TLS(
|
||||||
qio_task_get_source(task));
|
qio_task_get_source(task));
|
||||||
|
|
||||||
qio_channel_tls_handshake_task(
|
g_free(data);
|
||||||
tioc, task);
|
qio_channel_tls_handshake_task(tioc, task, context);
|
||||||
|
|
||||||
|
if (context) {
|
||||||
|
g_main_context_unref(context);
|
||||||
|
}
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -204,7 +226,8 @@ static gboolean qio_channel_tls_handshake_io(QIOChannel *ioc,
|
|||||||
void qio_channel_tls_handshake(QIOChannelTLS *ioc,
|
void qio_channel_tls_handshake(QIOChannelTLS *ioc,
|
||||||
QIOTaskFunc func,
|
QIOTaskFunc func,
|
||||||
gpointer opaque,
|
gpointer opaque,
|
||||||
GDestroyNotify destroy)
|
GDestroyNotify destroy,
|
||||||
|
GMainContext *context)
|
||||||
{
|
{
|
||||||
QIOTask *task;
|
QIOTask *task;
|
||||||
|
|
||||||
@ -212,7 +235,7 @@ void qio_channel_tls_handshake(QIOChannelTLS *ioc,
|
|||||||
func, opaque, destroy);
|
func, opaque, destroy);
|
||||||
|
|
||||||
trace_qio_channel_tls_handshake_start(ioc);
|
trace_qio_channel_tls_handshake_start(ioc);
|
||||||
qio_channel_tls_handshake_task(ioc, task);
|
qio_channel_tls_handshake_task(ioc, task, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -105,6 +105,7 @@ void migration_tls_channel_process_incoming(MigrationState *s,
|
|||||||
qio_channel_tls_handshake(tioc,
|
qio_channel_tls_handshake(tioc,
|
||||||
migration_tls_incoming_handshake,
|
migration_tls_incoming_handshake,
|
||||||
NULL,
|
NULL,
|
||||||
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,5 +160,6 @@ void migration_tls_channel_connect(MigrationState *s,
|
|||||||
qio_channel_tls_handshake(tioc,
|
qio_channel_tls_handshake(tioc,
|
||||||
migration_tls_outgoing_handshake,
|
migration_tls_outgoing_handshake,
|
||||||
s,
|
s,
|
||||||
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
@ -579,6 +579,7 @@ static QIOChannel *nbd_receive_starttls(QIOChannel *ioc,
|
|||||||
qio_channel_tls_handshake(tioc,
|
qio_channel_tls_handshake(tioc,
|
||||||
nbd_tls_handshake,
|
nbd_tls_handshake,
|
||||||
&data,
|
&data,
|
||||||
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
if (!data.complete) {
|
if (!data.complete) {
|
||||||
|
@ -599,6 +599,7 @@ static QIOChannel *nbd_negotiate_handle_starttls(NBDClient *client,
|
|||||||
qio_channel_tls_handshake(tioc,
|
qio_channel_tls_handshake(tioc,
|
||||||
nbd_tls_handshake,
|
nbd_tls_handshake,
|
||||||
&data,
|
&data,
|
||||||
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
if (!data.complete) {
|
if (!data.complete) {
|
||||||
|
@ -203,10 +203,12 @@ static void test_io_channel_tls(const void *opaque)
|
|||||||
qio_channel_tls_handshake(clientChanTLS,
|
qio_channel_tls_handshake(clientChanTLS,
|
||||||
test_tls_handshake_done,
|
test_tls_handshake_done,
|
||||||
&clientHandshake,
|
&clientHandshake,
|
||||||
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
qio_channel_tls_handshake(serverChanTLS,
|
qio_channel_tls_handshake(serverChanTLS,
|
||||||
test_tls_handshake_done,
|
test_tls_handshake_done,
|
||||||
&serverHandshake,
|
&serverHandshake,
|
||||||
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -128,6 +128,7 @@ static int protocol_client_vencrypt_auth(VncState *vs, uint8_t *data, size_t len
|
|||||||
qio_channel_tls_handshake(tls,
|
qio_channel_tls_handshake(tls,
|
||||||
vnc_tls_handshake_done,
|
vnc_tls_handshake_done,
|
||||||
vs,
|
vs,
|
||||||
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -81,6 +81,7 @@ gboolean vncws_tls_handshake_io(QIOChannel *ioc G_GNUC_UNUSED,
|
|||||||
qio_channel_tls_handshake(tls,
|
qio_channel_tls_handshake(tls,
|
||||||
vncws_tls_handshake_done,
|
vncws_tls_handshake_done,
|
||||||
vs,
|
vs,
|
||||||
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
Loading…
Reference in New Issue
Block a user