Skip to contentSkip to conversation

chardev: Add IRC char driver

PATCH In review Max Reitz 3 participants 9 messages Apr 1, 2015 – Apr 2, 2015

lore
Share & tools
lore

Max Reitz

author
#0 lore raw

cover chardev: Add IRC char driver

This series adds a long-missing IRC character device driver to qemu. See patch 1 for an explanation why you should have been missing it.

To make it short: IRC is a very well tested and more reliable, social, human-friendly, and ubiquitous[1] communication interface than any of the other character devices qemu has to offer.

"Social?", you ask? "Exactly!", I say. Again, see patch 1.

"But why do we need 'social'?" Because what is it that separates qemu from the other well-known type-2 hypervisors? Besides simply being better (of course!), it is free software which is written by and maintained by a community. It is social.

Now we need to capitalize on this very fact even further, not only embracing it in qemu development, but also in qemu usage.

Already, everyone can work on the qemu project.

In the future, everyone will be able to work with a qemu instance.

This is what this patch series embodies. The future is now.

What a time to be alive.

Oh, and don't forget the reliability and ubiquity.

Finally, there has been no encryption whatsoever in qemu's character devices so far. For IRC, SSL is a well-known and commonly implemented client-to-server encryption method (patch 3), and this series will furthermore introduce a widely used and easy to implement, yet secure enough even for military standards, end-to-end encryption (patch 4).

[1] Google search for:
- irc: 1.27e+8 results
- tcp: 1.08e+8 results
- udp: 6.28e+7 results
- telnet: 2.29e+7 results
- stdio: 9.04e+6 results
- "unix sockets": 1.37e+5 results

Max Reitz (5):
chardev: Add IRC char driver
chardev/irc: Add sockfd option
chardev/irc: Add SSL support
chardev/irc: Add end-to-end encryption
Documentation: Document IRC char driver

 configure        |  43 +++-
 qapi-schema.json |  32 +++
 qemu-char.c      | 714 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 qemu-options.hx  |  28 +++
 4 files changed, 806 insertions(+), 11 deletions(-)
Signature · 1 line
2.3.4
author
#1 lore raw

PATCH 1/5 chardev: Add IRC char driver

In order for qemu to become more human-friendly, we require an interface which is actually used by humans in their normal day-to-day communication. Many people in the qemu community will agree that IRC is indeed such a communication platform. By adding that support to qemu, users no longer have to switch from IRC to command line and back to debug QMP issues and the like while discussing it in the #qemu channel.

Furthermore, debugging has never been this social: In the past, people needed to ask the debugging person to try specific commands and that person had to paste the reply back to IRC. Now, you can simply let qemu connect to a discussion channel and everyone can participate in debugging.

And finally, there are technical merits as well: IRC is a well-tested, fault-tolerant network with redundant nodes. This gives us much greater reliability than any of the existing character devices, which is especially important for remote debugging.

---
 qapi-schema.json |  16 ++
 qemu-char.c      | 492 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 508 insertions(+)
qapi-schema.json +16 -0
index ac9594d..f427e04 100644
@@ -2876,6 +2876,21 @@
 { 'type': 'ChardevRingbuf', 'data': { '*size'  : 'int' } }
 
 ##
+# @ChardevIrc
+#
+# Configuration info for IRC chardevs.
+#
+# @addr:    IRC server
+# @nick:    Nick for qemu to use
+# @channel: Channel to join, or nick to query
+#
+# Since: 2.4
+##
+{ 'type': 'ChardevIrc', 'data': { 'addr'        : 'SocketAddress',
+                                  'nick'        : 'str',
+                                  'channel'     : 'str' } }
+
+##
 # @ChardevBackend:
 #
 # Configuration info for the new chardev backend.
@@ -2902,6 +2917,7 @@
                                        'spiceport' : 'ChardevSpicePort',
                                        'vc'     : 'ChardevVC',
                                        'ringbuf': 'ChardevRingbuf',
+                                       'irc'    : 'ChardevIrc',
                                        # next one is just for compatibility
                                        'memory' : 'ChardevRingbuf' } }
 
qemu-char.c +492 -0

534 lines not on this page · raw message

Signature · 1 line
2.3.4
author
#2 lore raw

PATCH 2/5 chardev/irc: Add sockfd option

In reply to Max Reitz

IRC being well on the way to deprecate other character devices, it must be exposed to management tools as well. These often prefer to pass a socket FD instead of a host and port to connect to, so this patch adds an appropriate option.

---
 qemu-char.c | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)
qemu-char.c +23 -6
index a68fef3..4507e5f 100644
@@ -3937,19 +3937,26 @@ static void qemu_chr_parse_udp(QemuOpts *opts, ChardevBackend *backend,
 static void qemu_chr_parse_irc(QemuOpts *opts, ChardevBackend *backend,
                                Error **errp)
 {
-    const char *host, *port, *nick, *channel;
+    const char *host, *port, *nick, *channel, *sockfd;
     SocketAddress *addr;
 
     host    = qemu_opt_get(opts, "host");
     port    = qemu_opt_get(opts, "port") ?: "6667";
+    sockfd  = qemu_opt_get(opts, "sockfd");
     nick    = qemu_opt_get(opts, "nick");
     channel = qemu_opt_get(opts, "channel");
 
-    if (!host || !nick || !channel) {
+    if ((!host && !sockfd) || !nick || !channel) {
         error_setg(errp, "chardev: irc: Missing options");
         return;
     }
 
+    if ((host || port) && sockfd) {
+        error_setg(errp,
+                   "chardev: irc: Both sockfd and host and/or port specified");
+        return;
+    }
+
     if (strlen(nick) > 64 || strlen(channel) > 64) {
         error_setg(errp, "chardev: irc: Nick or channel too long");
         return;
@@ -3958,10 +3965,17 @@ static void qemu_chr_parse_irc(QemuOpts *opts, ChardevBackend *backend,
     backend->irc = g_new0(ChardevIrc, 1);
 
     addr = g_new0(SocketAddress, 1);
-    addr->kind = SOCKET_ADDRESS_KIND_INET;
-    addr->inet = g_new0(InetSocketAddress, 1);
-    addr->inet->host = g_strdup(host);
-    addr->inet->port = g_strdup(port);
+    if (host) {
+        addr->kind = SOCKET_ADDRESS_KIND_INET;
+        addr->inet = g_new0(InetSocketAddress, 1);
+        addr->inet->host = g_strdup(host);
+        addr->inet->port = g_strdup(port);
+    } else {
+        addr->kind = SOCKET_ADDRESS_KIND_FD;
+        addr->fd = g_new(String, 1);
+        addr->fd->str = g_strdup(sockfd);
+    }
+
     backend->irc->addr = addr;
 
     backend->irc->nick = g_strdup(nick);
@@ -4332,6 +4346,9 @@ QemuOptsList qemu_chardev_opts = {
         },{
             .name = "channel",
             .type = QEMU_OPT_STRING,
+        },{
+            .name = "sockfd",
+            .type = QEMU_OPT_STRING,
         },
         { /* end of list */ }
     },
Signature · 1 line
2.3.4
author
#3 lore raw

PATCH 3/5 chardev/irc: Add SSL support

In reply to Max Reitz

qemu already makes use of gnutls, so it is only natural to extend its use to the IRC char driver. Furthermore, though IRC is ubiquitous, there may be servers which allow only SSL connections for some sense of additional security, be it real or not. Adding that support to qemu therefore means greater compatibility which should be the goal of any software implementing an open standard such as IRC.

The Heartbleed crisis influences this patch in two ways: First, it does not use OpenSSL. As GnuTLS is not nearly used as commonly, this will give us an advantage regarding attackers which prefer to attack the most widespread platform. Second, certificates can be stolen any time and revoking them does not work. Therefore, authentication in SSL is broken by design and we do not need to care for it. This guideline is generally followed by IRC servers as well, for instance OFTC, which hosts the #qemu IRC channel, does offer a self-signed certificate. Thus, this policy seems widely accepted and to be current industry practice.

---
 configure        |  43 ++++++++++++++++------
 qapi-schema.json |   3 +-
 qemu-char.c      | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 140 insertions(+), 12 deletions(-)
configure +32 -11
index 09c9225..63ea221 100755
@@ -246,6 +246,7 @@ vnc_sasl=""
 vnc_jpeg=""
 vnc_png=""
 vnc_ws=""
+gnutls=""
 xen=""
 xen_ctrl_version=""
 xen_pci_passthrough=""
@@ -889,6 +890,10 @@ for opt do
   ;;
   --enable-vnc-ws) vnc_ws="yes"
   ;;
+  --disable-gnutls) gnutls="no"
+  ;;
+  --enable-gnutls) gnutls="yes"
+  ;;
   --disable-slirp) slirp="no"
   ;;
   --disable-uuid) uuid="no"
@@ -2283,32 +2288,43 @@ EOF
 fi
 
 ##########################################
-# VNC TLS/WS detection
-if test "$vnc" = "yes" -a \( "$vnc_tls" != "no" -o "$vnc_ws" != "no" \) ; then
+# GnuTLS detection
+if test "$gnutls" != "no" ; then
   cat > $TMPC <<EOF
 #include <gnutls/gnutls.h>
 int main(void) { gnutls_session_t s; gnutls_init(&s, GNUTLS_SERVER); return 0; }
 EOF
-  vnc_tls_cflags=`$pkg_config --cflags gnutls 2> /dev/null`
-  vnc_tls_libs=`$pkg_config --libs gnutls 2> /dev/null`
-  if compile_prog "$vnc_tls_cflags" "$vnc_tls_libs" ; then
+  gnutls_cflags=`$pkg_config --cflags gnutls 2> /dev/null`
+  gnutls_libs=`$pkg_config --libs gnutls 2> /dev/null`
+  if compile_prog "$gnutls_cflags" "$gnutls_libs" ; then
+    gnutls=yes
+    libs_softmmu="$gnutls_libs $libs_softmmu"
+    QEMU_CFLAGS="$QEMU_CFLAGS $gnutls_cflags"
+  else
+    if test "$gnutls" = "yes" ; then
+      feature_not_found "gnutls" "Install gnutls devel"
+    fi
+    gnutls=no
+  fi
+fi
+
+##########################################
+# VNC TLS/WS detection
+if test "$vnc" = "yes" -a \( "$vnc_tls" != "no" -o "$vnc_ws" != "no" \) ; then
+  if test "$gnutls" = "yes" ; then
     if test "$vnc_tls" != "no" ; then
       vnc_tls=yes
     fi
     if test "$vnc_ws" != "no" ; then
       vnc_ws=yes
     fi
-    libs_softmmu="$vnc_tls_libs $libs_softmmu"
-    QEMU_CFLAGS="$QEMU_CFLAGS $vnc_tls_cflags"
   else
     if test "$vnc_tls" = "yes" ; then
-      feature_not_found "vnc-tls" "Install gnutls devel"
+      feature_not_found "vnc-tls" "Enable gnutls"
     fi
     if test "$vnc_ws" = "yes" ; then
-      feature_not_found "vnc-ws" "Install gnutls devel"
+      feature_not_found "vnc-ws" "Enable gnutls"
     fi
-    vnc_tls=no
-    vnc_ws=no
   fi
 fi
 
@@ -4440,6 +4456,7 @@ echo "lzo support       $lzo"
 echo "snappy support    $snappy"
 echo "bzip2 support     $bzip2"
 echo "NUMA host support $numa"
+echo "GnuTLS support    $gnutls"
 
 if test "$sdl_too_old" = "yes"; then
 echo "-> Your SDL version is too old - please upgrade to have SDL support"
@@ -4921,6 +4938,10 @@ if test "$tpm" = "yes"; then
   fi
 fi
 
+if test "$gnutls" = "yes" ; then
+  echo "CONFIG_GNUTLS=y" >> $config_host_mak
+fi
+
 echo "TRACE_BACKENDS=$trace_backends" >> $config_host_mak
 if have_backend "nop"; then
   echo "CONFIG_TRACE_NOP=y" >> $config_host_mak
qapi-schema.json +2 -1
index f427e04..e4f93fd 100644
@@ -2888,7 +2888,8 @@
 ##
 { 'type': 'ChardevIrc', 'data': { 'addr'        : 'SocketAddress',
                                   'nick'        : 'str',
-                                  'channel'     : 'str' } }
+                                  'channel'     : 'str',
+                                  'ssl'         : 'bool' } }
 
 ##
 # @ChardevBackend:
qemu-char.c +106 -0

166 lines not on this page · raw message

Signature · 1 line
2.3.4
author
#4 lore raw

PATCH 4/5 chardev/irc: Add end-to-end encryption

In reply to Max Reitz

IRC being usable for remote configuration, offering a secure channel is indispensable. As can be seen from its alias "Caesar's cipher", ROT13 has been in use since ancient times and has been employed for state and military secrets, so it is definitely well-tested, stable and secure enough to manage a continent-spanning empire.

Its security is further proven by its ubiquity. For instance, vim supports encryption and decryption by hfvat gur t? pbzznaq.

However, some concerns have been raised in the past whether ROT13 and consequently all of Caesar's ciphers are actually secure for data with non-maximum entropy. Another cipher has shown in the past how to deal with these accusations: As DES is considered insecure, Triple DES (3DES) has been introduced. Likewise, this patch implements Triple ROT13 in addition to simple ROT13 to greatly improve security.

---
 qapi-schema.json |  17 +++++++-
 qemu-char.c      | 129 ++++++++++++++++++++++++++++++++++++++++++++++++-------
 2 files changed, 130 insertions(+), 16 deletions(-)
qapi-schema.json +16 -1
index e4f93fd..d365352 100644
@@ -2876,6 +2876,20 @@
 { 'type': 'ChardevRingbuf', 'data': { '*size'  : 'int' } }
 
 ##
+# @ChardevIrcEncryption
+#
+# Enumeration of supported encryption modes over IRC.
+#
+# @none:    No encryption
+# @weak:    ROT13
+# @strong:  Triple ROT13
+#
+# Since: 2.4
+##
+{ 'enum': 'ChardevIrcEncryption',
+  'data': [ 'none', 'weak', 'strong' ] }
+
+##
 # @ChardevIrc
 #
 # Configuration info for IRC chardevs.
@@ -2889,7 +2903,8 @@
 { 'type': 'ChardevIrc', 'data': { 'addr'        : 'SocketAddress',
                                   'nick'        : 'str',
                                   'channel'     : 'str',
-                                  'ssl'         : 'bool' } }
+                                  'ssl'         : 'bool',
+                                  'encryption'  : 'ChardevIrcEncryption' } }
 
 ##
 # @ChardevBackend:
qemu-char.c +114 -15

201 lines not on this page · raw message

Signature · 1 line
2.3.4
author
#5 lore raw

PATCH 5/5 Documentation: Document IRC char driver

In reply to Max Reitz

With the IRC char driver being fully functional, it now needs to be exposed to the broad audience. Adding documentation has been proven a valuable step in this process.

Regarding the next steps, mouth-to-mouth propaganda will probably suffice, considering that IRC is objectively the single best character device qemu has to offer.

---
 qemu-options.hx | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
qemu-options.hx +28 -0
index 319d971..e6e0cb2 100644
@@ -2799,6 +2799,34 @@ or fake device.
 
 @item msmouse
 Three button serial mouse. Configure the guest to use Microsoft protocol.
+
+@item irc[,host=@var{hostname}[,port=@var{port}]][,sockfd=@var{socket_fd}],nick=@var{nick},channel=@var{channel}[,ssl=@var{ssl}][,encryption=@var{cipher}]
+Connects to the specified @var{hostname} on the given @var{port} (defaults to
+6667), using the given @var{nick}.  Alternatively, a socket file descriptor may
+be specified as @var{socket_fd}.  Once connected, the channel @var{channel} is
+joined.  A nick may be specify instead of a channel, in which case all
+communication is done through a query.
+
+TLS is enabled or disabled through the @var{ssl} option.  It is disabled by
+default.
+
+All messages are encrypted and decrypted with the selected @var{cipher}.  Valid
+options are:
+@table @option
+@item none
+No encryption
+@item weak
+ROT13
+@item strong
+Triple ROT13
+@end table
+
+Messages to QEMU must be prefixed with @var{nick} if communicating through a
+channel; when queried, no prefix must be used.  This prefix has to be encrypted
+if encryption is used.
+
+All output is emitted to @var{channel}.  There is no limitation for input
+sources, so anyone may query the QEMU instance and submit data.
 @end table
 ETEXI
 
Signature · 1 line
2.3.4
#6 lore raw
In reply to Max Reitz
Quoted 6 lines · Max Reitz

This series adds a long-missing IRC character device driver to qemu. See patch 1 for an explanation why you should have been missing it.

To make it short: IRC is a very well tested and more reliable, social, human-friendly, and ubiquitous[1] communication interface than any of the other character devices qemu has to offer.

Next year please do ELIZA:
https://en.wikipedia.org/wiki/ELIZA

:)
Stefan

author
#7 lore raw
Quoted 9 lines · Stefan Hajnoczi
Quoted 6 lines · Max Reitz

This series adds a long-missing IRC character device driver to qemu. See patch 1 for an explanation why you should have been missing it.

To make it short: IRC is a very well tested and more reliable, social, human-friendly, and ubiquitous[1] communication interface than any of the other character devices qemu has to offer.

Next year please do ELIZA:
https://en.wikipedia.org/wiki/ELIZA

Why not complete Emacs integration? ;-)

Max

Quoted 2 lines

:)
Stefan