Skip to contentSkip to conversation

Extract TLS handling code from VNC server

PATCH In review Daniel P. Berrange 3 participants 14 messages Sep 2, 2015 – Sep 8, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v6 cover Extract TLS handling code from VNC server

This small patch series is a formal submission of another part of my previous series

v1: https://lists.gnu.org/archive/html/qemu-devel/2015-04/msg02038.html
v2: https://lists.gnu.org/archive/html/qemu-devel/2015-08/msg01267.html
v3: https://lists.gnu.org/archive/html/qemu-devel/2015-08/msg01386.html
v4: https://lists.gnu.org/archive/html/qemu-devel/2015-08/msg02655.html
v5: https://lists.gnu.org/archive/html/qemu-devel/2015-08/msg03159.html

Now we have the basic crypto module defined for hash/cipher APIs, we extend it to also cover TLS credential and TLS session handling APIs. These new TLS related APIs obsolete the vast majority of the TLS handling code in the current VNC server. As a result the VNC server no longer has to worry about conditional compilation for GNUTLS. It also gives us code reuse for future patches which intend to add TLS support to chardevs, migration, nbd, etc.

This series deprecates the existing way of configuring TLS for VNC on the command line, but maintains support for back-compat reasons.

Since the TLS code is now totally isolated from the VNC server it is also practical to provide significant unit test coverage of what is security critical code.

Aside from the new CLI syntax for configuring TLS with VNC, the only other functional change is to allow diffie-hellman params to be loaded from a file, instead of being generated at startup.

Changes in v6:

- Remove use of -Wl,--whole-archive added in v5 since it bloated the binary sizes too much
- Move crypto code out of libqemuutil.a to allow linking with QOM without problem of linker dropping objects only referenced via constructors
- Allow tools to link to QOM objects
- Remove repetition in unit test object deps
- Remove trailing '.' from error messages in TLS code
- Remove leading '_' from struct name in TLS session
- Fix leak of TLS credentials in cert checking error path
- Added docs for enhancement to enum code generator
- Misc docs typos & indentation fixes
- Add more sanity checking to enum code generator
- Add tests to cover enum code generator enhancement
- Fix dereference of Error **errp variables
- Fix overwriting of already set Error * variable in tests
- Use CHAR_BIT constant in sasl code
- Fix incorrect return status in VNC TLS code errorpath

Changes in v5:

- Introduce use of -Wl,--whole-archive with libqemuutil.a to ensure QOM objects are not discarded by linker
- Remove nasty back dummy functions used to prevent QOM object discard by linker
- Extend QAPI enum generator to allow enum name prefix spec to override heuristics
- Switch to use QAPI to generate QCryptoTLSCredsEndpoint enum definition
- Fix misc bugs in error message strings
- Use alternate definition for DPRINTF

Changes in v4:

- Fix build when GNUTLS is disabled
- Add missed return type conversion in vnc.h

Changes in v3:

- Switched "tls-creds" object to be just an abstract base class
- Created "tls-creds-anon" object subclass in new file
- Created "tls-creds-x509" object subclass in new file

Daniel P. Berrange (11):
qapi: allow override of default enum prefix naming
tests: remove repetition in unit test object deps
crypto: move crypto objects out of libqemuutil.la
qom: allow QOM to be linked into tools binaries
crypto: introduce new base module for TLS credentials
crypto: introduce new module for TLS anonymous credentials
crypto: introduce new module for TLS x509 credentials
crypto: add sanity checking of TLS x509 credentials
crypto: introduce new module for handling TLS sessions
ui: fix return type for VNC I/O functions to be ssize_t
ui: convert VNC server to use QCryptoTLSSession

 Makefile                                |   10 +-
 Makefile.objs                           |   10 +-
 Makefile.target                         |    4 +
 configure                               |   53 +-
 crypto/Makefile.objs                    |   14 +-
 crypto/tlscreds.c                       |  262 ++++++++
 crypto/tlscredsanon.c                   |  236 +++++++
 crypto/tlscredspriv.h                   |   41 ++
 crypto/tlscredsx509.c                   |  820 +++++++++++++++++++++++
 crypto/tlssession.c                     |  586 ++++++++++++++++
 docs/qapi-code-gen.txt                  |    8 +
 include/crypto/tlscreds.h               |   68 ++
 include/crypto/tlscredsanon.h           |  112 ++++
 include/crypto/tlscredsx509.h           |  113 ++++
 include/crypto/tlssession.h             |  322 +++++++++
 qapi-schema.json                        |    3 +
 qapi/crypto.json                        |   21 +
 qemu-options.hx                         |   75 ++-
 qom/Makefile.objs                       |    7 +-
 scripts/qapi-types.py                   |   16 +-
 scripts/qapi.py                         |   10 +-
 tests/.gitignore                        |    7 +
 tests/Makefile                          |  106 +--
 tests/crypto-tls-x509-helpers.c         |  486 ++++++++++++++
 tests/crypto-tls-x509-helpers.h         |  133 ++++
 tests/pkix_asn1_tab.c                   | 1104 +++++++++++++++++++++++++++++++
 tests/qapi-schema/enum-bad-prefix.err   |    1 +
 tests/qapi-schema/enum-bad-prefix.exit  |    1 +
 tests/qapi-schema/enum-bad-prefix.json  |    2 +
 tests/qapi-schema/enum-bad-prefix.out   |    0
 tests/qapi-schema/qapi-schema-test.json |    5 +
 tests/qapi-schema/qapi-schema-test.out  |    2 +
 tests/test-crypto-tlscredsx509.c        |  733 ++++++++++++++++++++
 tests/test-crypto-tlssession.c          |  537 +++++++++++++++
 ui/Makefile.objs                        |    2 +-
 ui/vnc-auth-sasl.c                      |   36 +-
 ui/vnc-auth-vencrypt.c                  |   80 ++-
 ui/vnc-tls.c                            |  474 -------------
 ui/vnc-tls.h                            |   69 --
 ui/vnc-ws.c                             |   84 +--
 ui/vnc-ws.h                             |    2 -
 ui/vnc.c                                |  362 ++++++----
 ui/vnc.h                                |   21 +-
 43 files changed, 6157 insertions(+), 881 deletions(-)
 create mode 100644 crypto/tlscreds.c
 create mode 100644 crypto/tlscredsanon.c
 create mode 100644 crypto/tlscredspriv.h
 create mode 100644 crypto/tlscredsx509.c
 create mode 100644 crypto/tlssession.c
 create mode 100644 include/crypto/tlscreds.h
 create mode 100644 include/crypto/tlscredsanon.h
 create mode 100644 include/crypto/tlscredsx509.h
 create mode 100644 include/crypto/tlssession.h
 create mode 100644 qapi/crypto.json
 create mode 100644 tests/crypto-tls-x509-helpers.c
 create mode 100644 tests/crypto-tls-x509-helpers.h
 create mode 100644 tests/pkix_asn1_tab.c
 create mode 100644 tests/qapi-schema/enum-bad-prefix.err
 create mode 100644 tests/qapi-schema/enum-bad-prefix.exit
 create mode 100644 tests/qapi-schema/enum-bad-prefix.json
 create mode 100644 tests/qapi-schema/enum-bad-prefix.out
 create mode 100644 tests/test-crypto-tlscredsx509.c
 create mode 100644 tests/test-crypto-tlssession.c
 delete mode 100644 ui/vnc-tls.c
 delete mode 100644 ui/vnc-tls.h
Signature · 1 line
2.4.3
#1 lore raw

PATCH v6 1/11 qapi: allow override of default enum prefix naming

The camel_to_upper() method applies some heuristics to turn a mixed case type name into an all-uppercase name. This is used for example, to generate enum constant name prefixes.

The heuristics don't also generate a satisfactory name though. eg

{ 'enum': 'QCryptoTLSCredsEndpoint',

    'data': ['client', 'server']}

Results in Q_CRYPTOTLS_CREDS_ENDPOINT_CLIENT. This has an undesirable _ after the initial Q and is missing an _ between the CRYPTO & TLS strings.

Rather than try to add more and more heuristics to try to cope with this, simply allow the QAPI schema to specify the desired enum constant prefix explicitly.

eg

{ 'enum': 'QCryptoTLSCredsEndpoint',

    'prefix': 'QCRYPTO_TLS_CREDS_ENDPOINT',
    'data': ['client', 'server']}

Now gives the QCRYPTO_TLS_CREDS_ENDPOINT_CLIENT name.

---
 docs/qapi-code-gen.txt                  |  8 ++++++++
 scripts/qapi-types.py                   | 16 +++++++++-------
 scripts/qapi.py                         | 10 ++++++++--
 tests/Makefile                          |  5 +++--
 tests/qapi-schema/enum-bad-prefix.err   |  1 +
 tests/qapi-schema/enum-bad-prefix.exit  |  1 +
 tests/qapi-schema/enum-bad-prefix.json  |  2 ++
 tests/qapi-schema/enum-bad-prefix.out   |  0
 tests/qapi-schema/qapi-schema-test.json |  5 +++++
 tests/qapi-schema/qapi-schema-test.out  |  2 ++
 10 files changed, 39 insertions(+), 11 deletions(-)
 create mode 100644 tests/qapi-schema/enum-bad-prefix.err
 create mode 100644 tests/qapi-schema/enum-bad-prefix.exit
 create mode 100644 tests/qapi-schema/enum-bad-prefix.json
 create mode 100644 tests/qapi-schema/enum-bad-prefix.out
docs/qapi-code-gen.txt +8 -0
index 61b5be4..2d16f30 100644
@@ -236,6 +236,7 @@ both fields like this:
 === Enumeration types ===
 
 Usage: { 'enum': STRING, 'data': ARRAY-OF-STRING }
+       { 'enum': STRING, 'prefix': STRING, 'data': ARRAY-OF-STRING }
 
 An enumeration type is a dictionary containing a single 'data' key
 whose value is a list of strings.  An example enumeration is:
@@ -247,6 +248,13 @@ useful.  The list of strings should be lower case; if an enum name
 represents multiple words, use '-' between words.  The string 'max' is
 not allowed as an enum value, and values should not be repeated.
 
+The enum constants will be named by using a heuristic to turn the
+type name into a set of underscore separated words. For the example
+above, 'MyEnum' will turn into 'MY_ENUM' giving a constant name
+of 'MY_ENUM_VALUE1' for the first value. If the default heuristic
+does not result in a desirable name, the optional 'prefix' field
+can be used when defining the enum.
+
 The enumeration values are passed as strings over the Client JSON
 Protocol, but are encoded as C enum integral values in generated code.
 While the C code starts numbering at 0, it is better to use explicit
scripts/qapi-types.py +9 -7
index e6eb4b6..5ae92ae 100644
@@ -103,20 +103,20 @@ struct %(name)s
 
     return ret
 
-def generate_enum_lookup(name, values):
+def generate_enum_lookup(name, values, prefix=None):
     ret = mcgen('''
 const char * const %(name)s_lookup[] = {
 ''',
                 name=c_name(name))
     i = 0
     for value in values:
-        index = c_enum_const(name, value)
+        index = c_enum_const(name, value, prefix)
         ret += mcgen('''
     [%(index)s] = "%(value)s",
 ''',
                      index = index, value = value)
 
-    max_index = c_enum_const(name, 'MAX')
+    max_index = c_enum_const(name, 'MAX', prefix)
     ret += mcgen('''
     [%(max_index)s] = NULL,
 };
@@ -125,7 +125,7 @@ const char * const %(name)s_lookup[] = {
         max_index=max_index)
     return ret
 
-def generate_enum(name, values):
+def generate_enum(name, values, prefix=None):
     name = c_name(name)
     lookup_decl = mcgen('''
 extern const char * const %(name)s_lookup[];
@@ -143,7 +143,7 @@ typedef enum %(name)s
 
     i = 0
     for value in enum_values:
-        enum_full_value = c_enum_const(name, value)
+        enum_full_value = c_enum_const(name, value, prefix)
         enum_decl += mcgen('''
     %(enum_full_value)s = %(i)d,
 ''',
@@ -336,9 +336,11 @@ for expr in exprs:
     if expr.has_key('struct'):
         ret += generate_fwd_struct(expr['struct'])
     elif expr.has_key('enum'):
-        ret += generate_enum(expr['enum'], expr['data']) + "\n"
+        ret += generate_enum(expr['enum'], expr['data'],
+                             expr.get('prefix')) + "\n"
         ret += generate_fwd_enum_struct(expr['enum'])
-        fdef.write(generate_enum_lookup(expr['enum'], expr['data']))
+        fdef.write(generate_enum_lookup(expr['enum'], expr['data'],
+                                        expr.get('prefix')))
     elif expr.has_key('union'):
         ret += generate_fwd_struct(expr['union']) + "\n"
         enum_define = discriminator_find_enum_define(expr)
scripts/qapi.py +8 -2
index 06d7fc2..ce2a864 100644
@@ -639,11 +639,15 @@ def check_alternate(expr, expr_info):
 def check_enum(expr, expr_info):
     name = expr['enum']
     members = expr.get('data')
+    prefix = expr.get('prefix')
     values = { 'MAX': '(automatic)' }
 
     if not isinstance(members, list):
         raise QAPIExprError(expr_info,
                             "Enum '%s' requires an array for 'data'" % name)
+    if prefix is not None and not isinstance(prefix, str):
+        raise QAPIExprError(expr_info,
+                            "Enum '%s' requires a string for 'prefix'" % name)
     for member in members:
         check_name(expr_info, "Member of enum '%s'" %name, member,
                    enum_member=True)
@@ -698,7 +702,7 @@ def check_exprs(exprs):
         expr = expr_elem['expr']
         info = expr_elem['info']
         if expr.has_key('enum'):
-            check_keys(expr_elem, 'enum', ['data'])
+            check_keys(expr_elem, 'enum', ['data'], ['prefix'])
             add_enum(expr['enum'], info, expr['data'])
         elif expr.has_key('union'):
             check_keys(expr_elem, 'union', ['data'],
@@ -818,7 +822,9 @@ def camel_to_upper(value):
         new_name += c
     return new_name.lstrip('_').upper()
 
-def c_enum_const(type_name, const_name):
+def c_enum_const(type_name, const_name, prefix=None):
+    if prefix is not None:
+        type_name = prefix
     return camel_to_upper(type_name + '_' + const_name)
 
 c_name_trans = string.maketrans('.-', '__')
tests/Makefile +3 -2
index 5271123..dfac417 100644
@@ -220,7 +220,8 @@ check-qapi-schema-y := $(addprefix tests/qapi-schema/, \
 	comments.json empty.json enum-empty.json enum-missing-data.json \
 	enum-wrong-data.json enum-int-member.json enum-dict-member.json \
 	enum-clash-member.json enum-max-member.json enum-union-clash.json \
-	enum-bad-name.json funny-char.json indented-expr.json \
+	enum-bad-name.json enum-bad-prefix.json \
+	funny-char.json indented-expr.json \
 	missing-type.json bad-ident.json ident-with-escape.json \
 	escape-outside-string.json unknown-escape.json \
 	escape-too-short.json escape-too-big.json unicode-str.json \
@@ -513,7 +514,7 @@ $(patsubst %, check-%, $(check-qapi-schema-y)): check-%.json: $(SRC_PATH)/%.json
 		"  TEST  $*.out")
 	@diff -q $(SRC_PATH)/$*.out $*.test.out
 	@# Sanitize error messages (make them independent of build directory)
-	@perl -p -e 's|\Q$(SRC_PATH)\E/||g' $*.test.err | diff -q $(SRC_PATH)/$*.err -
+	@perl -p -e 's|\Q$(SRC_PATH)\E/||g' $*.test.err | diff  $(SRC_PATH)/$*.err -
 	@diff -q $(SRC_PATH)/$*.exit $*.test.exit
 
 # Consolidated targets
tests/qapi-schema/enum-bad-prefix.err new file +1 -0
new file mode 100644
index 0000000..399f5f7
@@ -0,0 +1 @@
+tests/qapi-schema/enum-bad-prefix.json:2: Enum 'MyEnum' requires a string for 'prefix'
tests/qapi-schema/enum-bad-prefix.exit new file +1 -0
new file mode 100644
index 0000000..d00491f
@@ -0,0 +1 @@
+1
tests/qapi-schema/enum-bad-prefix.json new file +2 -0
new file mode 100644
index 0000000..996f628
@@ -0,0 +1,2 @@
+# The prefix must be a string type
+{ 'enum': 'MyEnum', 'data': [ 'one' ], 'prefix': [ 'fish' ] }
tests/qapi-schema/enum-bad-prefix.out new file +0 -0
new file mode 100644
index 0000000..e69de29
tests/qapi-schema/qapi-schema-test.json +5 -0
index c7eaa86..124039c 100644
@@ -6,6 +6,11 @@
 { 'struct': 'NestedEnumsOne',
   'data': { 'enum1': 'EnumOne', '*enum2': 'EnumOne', 'enum3': 'EnumOne', '*enum4': 'EnumOne' } }
 
+# for testing override of default naming heuristic
+{ 'enum': 'QEnumTwo',
+  'prefix': 'QENUM_TWO',
+  'data': [ 'value1', 'value2' ] }
+
 # for testing nested structs
 { 'struct': 'UserDefZero',
   'data': { 'integer': 'int' } }
tests/qapi-schema/qapi-schema-test.out +2 -0
index cf0ccc4..f2497bd 100644
@@ -1,5 +1,6 @@
 [OrderedDict([('enum', 'EnumOne'), ('data', ['value1', 'value2', 'value3'])]),
  OrderedDict([('struct', 'NestedEnumsOne'), ('data', OrderedDict([('enum1', 'EnumOne'), ('*enum2', 'EnumOne'), ('enum3', 'EnumOne'), ('*enum4', 'EnumOne')]))]),
+ OrderedDict([('enum', 'QEnumTwo'), ('prefix', 'QENUM_TWO'), ('data', ['value1', 'value2'])]),
  OrderedDict([('struct', 'UserDefZero'), ('data', OrderedDict([('integer', 'int')]))]),
  OrderedDict([('struct', 'UserDefOne'), ('base', 'UserDefZero'), ('data', OrderedDict([('string', 'str'), ('*enum1', 'EnumOne')]))]),
  OrderedDict([('struct', 'UserDefTwoDictDict'), ('data', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')]))]),
@@ -33,6 +34,7 @@
  OrderedDict([('event', '__ORG.QEMU_X-EVENT'), ('data', '__org.qemu_x-Struct')]),
  OrderedDict([('command', '__org.qemu_x-command'), ('data', OrderedDict([('a', ['__org.qemu_x-Enum']), ('b', ['__org.qemu_x-Struct']), ('c', '__org.qemu_x-Union2'), ('d', '__org.qemu_x-Alt')])), ('returns', '__org.qemu_x-Union1')])]
 [{'enum_name': 'EnumOne', 'enum_values': ['value1', 'value2', 'value3']},
+ {'enum_name': 'QEnumTwo', 'enum_values': ['value1', 'value2']},
  {'enum_name': '__org.qemu_x-Enum', 'enum_values': ['__org.qemu_x-value']},
  {'enum_name': 'UserDefAlternateKind', 'enum_values': None},
  {'enum_name': 'UserDefNativeListUnionKind', 'enum_values': None},
Signature · 1 line
2.4.3
#2 lore raw

PATCH v6 2/11 tests: remove repetition in unit test object deps

In reply to Daniel P. Berrange

Most of the unit tests have identical sets of object deps. For example all block unit tests need to depend on

$(block-obj-y) libqemuutil.a libqemustub.a

Currently each unit test repeats this list of test deps. This list of deps will grow as future patches add more modules to the build, so define some common variables that can be used by all unit tests to remove the repetition.

---
 tests/Makefile | 94 ++++++++++++++++++++++++++++++----------------------------
 1 file changed, 49 insertions(+), 45 deletions(-)
tests/Makefile +49 -45
index dfac417..f7e3619 100644
@@ -271,47 +271,51 @@ test-obj-y = tests/check-qint.o tests/check-qstring.o tests/check-qdict.o \
 	tests/test-opts-visitor.o tests/test-qmp-event.o \
 	tests/rcutorture.o tests/test-rcu-list.o
 
-test-qapi-obj-y = tests/test-qapi-visit.o tests/test-qapi-types.o \
-		  tests/test-qapi-event.o
-
 $(test-obj-y): QEMU_INCLUDES += -Itests
 QEMU_CFLAGS += -I$(SRC_PATH)/tests
-qom-core-obj = qom/object.o qom/qom-qobject.o qom/container.o qom/object_interfaces.o
-
-tests/check-qint$(EXESUF): tests/check-qint.o libqemuutil.a
-tests/check-qstring$(EXESUF): tests/check-qstring.o libqemuutil.a
-tests/check-qdict$(EXESUF): tests/check-qdict.o libqemuutil.a
-tests/check-qlist$(EXESUF): tests/check-qlist.o libqemuutil.a
-tests/check-qfloat$(EXESUF): tests/check-qfloat.o libqemuutil.a
-tests/check-qjson$(EXESUF): tests/check-qjson.o libqemuutil.a libqemustub.a
-tests/check-qom-interface$(EXESUF): tests/check-qom-interface.o $(qom-core-obj) libqemuutil.a libqemustub.a
-tests/check-qom-proplist$(EXESUF): tests/check-qom-proplist.o $(qom-core-obj) libqemuutil.a libqemustub.a
-tests/test-coroutine$(EXESUF): tests/test-coroutine.o $(block-obj-y) libqemuutil.a libqemustub.a
-tests/test-aio$(EXESUF): tests/test-aio.o $(block-obj-y) libqemuutil.a libqemustub.a
-tests/test-rfifolock$(EXESUF): tests/test-rfifolock.o libqemuutil.a libqemustub.a
-tests/test-throttle$(EXESUF): tests/test-throttle.o $(block-obj-y) libqemuutil.a libqemustub.a
-tests/test-thread-pool$(EXESUF): tests/test-thread-pool.o $(block-obj-y) libqemuutil.a libqemustub.a
-tests/test-iov$(EXESUF): tests/test-iov.o libqemuutil.a
-tests/test-hbitmap$(EXESUF): tests/test-hbitmap.o libqemuutil.a libqemustub.a
+
+
+# Deps that are common to various different sets of tests below
+test-util-obj-y = libqemuutil.a libqemustub.a
+test-qom-obj-y = qom/object.o qom/qom-qobject.o \
+	qom/container.o qom/object_interfaces.o \
+	$(test-util-obj-y)
+test-qapi-obj-y = tests/test-qapi-visit.o tests/test-qapi-types.o \
+	tests/test-qapi-event.o \
+	$(test-qom-obj-y)
+test-block-obj-y = $(block-obj-y) $(test-util-obj-y)
+
+tests/check-qint$(EXESUF): tests/check-qint.o $(test-util-obj-y)
+tests/check-qstring$(EXESUF): tests/check-qstring.o $(test-util-obj-y)
+tests/check-qdict$(EXESUF): tests/check-qdict.o $(test-util-obj-y)
+tests/check-qlist$(EXESUF): tests/check-qlist.o $(test-util-obj-y)
+tests/check-qfloat$(EXESUF): tests/check-qfloat.o $(test-util-obj-y)
+tests/check-qjson$(EXESUF): tests/check-qjson.o $(test-util-obj-y)
+tests/check-qom-interface$(EXESUF): tests/check-qom-interface.o $(test-qom-obj-y)
+tests/check-qom-proplist$(EXESUF): tests/check-qom-proplist.o $(test-qom-obj-y)
+tests/test-coroutine$(EXESUF): tests/test-coroutine.o $(test-block-obj-y)
+tests/test-aio$(EXESUF): tests/test-aio.o $(test-block-obj-y)
+tests/test-rfifolock$(EXESUF): tests/test-rfifolock.o $(test-util-obj-y)
+tests/test-throttle$(EXESUF): tests/test-throttle.o $(test-block-obj-y)
+tests/test-thread-pool$(EXESUF): tests/test-thread-pool.o $(test-block-obj-y)
+tests/test-iov$(EXESUF): tests/test-iov.o $(test-util-obj-y)
+tests/test-hbitmap$(EXESUF): tests/test-hbitmap.o $(test-util-obj-y)
 tests/test-x86-cpuid$(EXESUF): tests/test-x86-cpuid.o
-tests/test-xbzrle$(EXESUF): tests/test-xbzrle.o migration/xbzrle.o page_cache.o libqemuutil.a
+tests/test-xbzrle$(EXESUF): tests/test-xbzrle.o migration/xbzrle.o page_cache.o $(test-util-obj-y)
 tests/test-cutils$(EXESUF): tests/test-cutils.o util/cutils.o
 tests/test-int128$(EXESUF): tests/test-int128.o
-tests/rcutorture$(EXESUF): tests/rcutorture.o libqemuutil.a libqemustub.a
-tests/test-rcu-list$(EXESUF): tests/test-rcu-list.o libqemuutil.a libqemustub.a
+tests/rcutorture$(EXESUF): tests/rcutorture.o $(test-util-obj-y)
+tests/test-rcu-list$(EXESUF): tests/test-rcu-list.o $(test-util-obj-y)
 
 tests/test-qdev-global-props$(EXESUF): tests/test-qdev-global-props.o \
 	hw/core/qdev.o hw/core/qdev-properties.o hw/core/hotplug.o\
 	hw/core/irq.o \
 	hw/core/fw-path-provider.o \
-	$(qom-core-obj) \
-	$(test-qapi-obj-y) \
-	libqemuutil.a libqemustub.a
+	$(test-qapi-obj-y)
 tests/test-vmstate$(EXESUF): tests/test-vmstate.o \
 	migration/vmstate.o migration/qemu-file.o migration/qemu-file-buf.o \
         migration/qemu-file-unix.o qjson.o \
-	$(qom-core-obj) \
-	libqemuutil.a libqemustub.a
+	$(test-qom-obj-y)
 
 tests/test-qapi-types.c tests/test-qapi-types.h :\
 $(SRC_PATH)/tests/qapi-schema/qapi-schema-test.json $(SRC_PATH)/scripts/qapi-types.py $(qapi-py)
@@ -334,20 +338,20 @@ $(SRC_PATH)/tests/qapi-schema/qapi-schema-test.json $(SRC_PATH)/scripts/qapi-eve
 		$(gen-out-type) -o tests -p "test-" $<, \
 		"  GEN   $@")
 
-tests/test-string-output-visitor$(EXESUF): tests/test-string-output-visitor.o $(test-qapi-obj-y) libqemuutil.a libqemustub.a
-tests/test-string-input-visitor$(EXESUF): tests/test-string-input-visitor.o $(test-qapi-obj-y) libqemuutil.a libqemustub.a
-tests/test-qmp-event$(EXESUF): tests/test-qmp-event.o $(test-qapi-obj-y) libqemuutil.a libqemustub.a
-tests/test-qmp-output-visitor$(EXESUF): tests/test-qmp-output-visitor.o $(test-qapi-obj-y) libqemuutil.a libqemustub.a
-tests/test-qmp-input-visitor$(EXESUF): tests/test-qmp-input-visitor.o $(test-qapi-obj-y) libqemuutil.a libqemustub.a
-tests/test-qmp-input-strict$(EXESUF): tests/test-qmp-input-strict.o $(test-qapi-obj-y) libqemuutil.a libqemustub.a
-tests/test-qmp-commands$(EXESUF): tests/test-qmp-commands.o tests/test-qmp-marshal.o $(test-qapi-obj-y) libqemuutil.a libqemustub.a
-tests/test-visitor-serialization$(EXESUF): tests/test-visitor-serialization.o $(test-qapi-obj-y) libqemuutil.a libqemustub.a
-tests/test-opts-visitor$(EXESUF): tests/test-opts-visitor.o $(test-qapi-obj-y) libqemuutil.a libqemustub.a
-
-tests/test-mul64$(EXESUF): tests/test-mul64.o libqemuutil.a
-tests/test-bitops$(EXESUF): tests/test-bitops.o libqemuutil.a
-tests/test-crypto-hash$(EXESUF): tests/test-crypto-hash.o libqemuutil.a libqemustub.a
-tests/test-crypto-cipher$(EXESUF): tests/test-crypto-cipher.o libqemuutil.a libqemustub.a
+tests/test-string-output-visitor$(EXESUF): tests/test-string-output-visitor.o $(test-qapi-obj-y)
+tests/test-string-input-visitor$(EXESUF): tests/test-string-input-visitor.o $(test-qapi-obj-y)
+tests/test-qmp-event$(EXESUF): tests/test-qmp-event.o $(test-qapi-obj-y)
+tests/test-qmp-output-visitor$(EXESUF): tests/test-qmp-output-visitor.o $(test-qapi-obj-y)
+tests/test-qmp-input-visitor$(EXESUF): tests/test-qmp-input-visitor.o $(test-qapi-obj-y)
+tests/test-qmp-input-strict$(EXESUF): tests/test-qmp-input-strict.o $(test-qapi-obj-y)
+tests/test-qmp-commands$(EXESUF): tests/test-qmp-commands.o tests/test-qmp-marshal.o $(test-qapi-obj-y)
+tests/test-visitor-serialization$(EXESUF): tests/test-visitor-serialization.o $(test-qapi-obj-y)
+tests/test-opts-visitor$(EXESUF): tests/test-opts-visitor.o $(test-qapi-obj-y)
+
+tests/test-mul64$(EXESUF): tests/test-mul64.o $(test-util-obj-y)
+tests/test-bitops$(EXESUF): tests/test-bitops.o $(test-util-obj-y)
+tests/test-crypto-hash$(EXESUF): tests/test-crypto-hash.o $(test-util-obj-y)
+tests/test-crypto-cipher$(EXESUF): tests/test-crypto-cipher.o $(test-util-obj-y)
 
 libqos-obj-y = tests/libqos/pci.o tests/libqos/fw_cfg.o tests/libqos/malloc.o
 libqos-obj-y += tests/libqos/i2c.o tests/libqos/libqos.o
@@ -408,8 +412,8 @@ tests/usb-hcd-xhci-test$(EXESUF): tests/usb-hcd-xhci-test.o $(libqos-usb-obj-y)
 tests/pc-cpu-test$(EXESUF): tests/pc-cpu-test.o
 tests/vhost-user-test$(EXESUF): tests/vhost-user-test.o qemu-char.o qemu-timer.o $(qtest-obj-y)
 tests/qemu-iotests/socket_scm_helper$(EXESUF): tests/qemu-iotests/socket_scm_helper.o
-tests/test-qemu-opts$(EXESUF): tests/test-qemu-opts.o libqemuutil.a libqemustub.a
-tests/test-write-threshold$(EXESUF): tests/test-write-threshold.o $(block-obj-y) libqemuutil.a libqemustub.a
+tests/test-qemu-opts$(EXESUF): tests/test-qemu-opts.o $(test-util-obj-y)
+tests/test-write-threshold$(EXESUF): tests/test-write-threshold.o $(test-block-obj-y)
 
 ifeq ($(CONFIG_POSIX),y)
 LIBS += -lutil
@@ -423,7 +427,7 @@ QTEST_TARGETS=$(foreach TARGET,$(TARGETS), $(if $(check-qtest-$(TARGET)-y), $(TA
 check-qtest-y=$(foreach TARGET,$(TARGETS), $(check-qtest-$(TARGET)-y))
 endif
 
-qtest-obj-y = tests/libqtest.o libqemuutil.a libqemustub.a
+qtest-obj-y = tests/libqtest.o $(test-util-obj-y)
 $(check-qtest-y): $(qtest-obj-y)
 
 .PHONY: check-help
Signature · 1 line
2.4.3
#3 lore raw

PATCH v6 3/11 crypto: move crypto objects out of libqemuutil.la

In reply to Daniel P. Berrange

Future patches will be adding more crypto related APIs which rely on QOM infrastructure. This creates a problem, because QOM relies on library constructors to register objects. When you have a file in a static .a library though which is only referenced by a constructor the linker is dumb and will drop that file when linking to the final executable :-( The only workaround for this is to link the .a library to the executable using the -Wl,--whole-archive flag, but this creates its own set of problems because QEMU is relying on lazy linking for libqemuutil.a. Using --whole-archive majorly increases the size of final executables as they now contain a bunch of object code they don't actually use.

The least bad option is to thus not include the crypto objects in libqemuutil.la, and instead define a crypto-obj-y variable that is referenced directly by all the executables that need this code (tools + softmmu, but not qemu-ga).

---
 Makefile             |  8 +++++---
 Makefile.objs        |  5 ++++-
 Makefile.target      |  2 ++
 crypto/Makefile.objs | 10 +++++-----
 tests/Makefile       |  7 ++++---
 5 files changed, 20 insertions(+), 12 deletions(-)
Makefile +5 -3
index 340d9c8..5e63da8 100644
@@ -151,6 +151,7 @@ dummy := $(call unnest-vars,, \
                 qga-vss-dll-obj-y \
                 block-obj-y \
                 block-obj-m \
+                crypto-obj-y \
                 common-obj-y \
                 common-obj-m)
 
@@ -172,6 +173,7 @@ SUBDIR_RULES=$(patsubst %,subdir-%, $(TARGET_DIRS))
 SOFTMMU_SUBDIR_RULES=$(filter %-softmmu,$(SUBDIR_RULES))
 
 $(SOFTMMU_SUBDIR_RULES): $(block-obj-y)
+$(SOFTMMU_SUBDIR_RULES): $(crypto-obj-y)
 $(SOFTMMU_SUBDIR_RULES): config-all-devices.mak
 
 subdir-%:
@@ -226,9 +228,9 @@ util/module.o-cflags = -D'CONFIG_BLOCK_MODULES=$(block-modules)'
 
 qemu-img.o: qemu-img-cmds.h
 
-qemu-img$(EXESUF): qemu-img.o $(block-obj-y) libqemuutil.a libqemustub.a
-qemu-nbd$(EXESUF): qemu-nbd.o $(block-obj-y) libqemuutil.a libqemustub.a
-qemu-io$(EXESUF): qemu-io.o $(block-obj-y) libqemuutil.a libqemustub.a
+qemu-img$(EXESUF): qemu-img.o $(block-obj-y) $(crypto-obj-y) libqemuutil.a libqemustub.a
+qemu-nbd$(EXESUF): qemu-nbd.o $(block-obj-y) $(crypto-obj-y) libqemuutil.a libqemustub.a
+qemu-io$(EXESUF): qemu-io.o $(block-obj-y) $(crypto-obj-y) libqemuutil.a libqemustub.a
 
 qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o
 
Makefile.objs +4 -1
index f094eff..c7ed989 100644
@@ -2,7 +2,6 @@
 # Common libraries for tools and emulators
 stub-obj-y = stubs/
 util-obj-y = util/ qobject/ qapi/ qapi-types.o qapi-visit.o qapi-event.o
-util-obj-y += crypto/
 
 #######################################################################
 # block-obj-y is code used by both qemu system emulation and qemu-img
@@ -21,6 +20,10 @@ block-obj-y += coroutine-$(CONFIG_COROUTINE_BACKEND).o
 
 block-obj-m = block/
 
+#######################################################################
+# crypto-obj-y is code used by both qemu system emulation and qemu-img
+
+crypto-obj-y = crypto/
 
 ######################################################################
 # smartcard
Makefile.target +2 -0
index 3e7aafd..2053ecd 100644
@@ -170,12 +170,14 @@ target-obj-y-save := $(target-obj-y)
 dummy := $(call unnest-vars,.., \
                block-obj-y \
                block-obj-m \
+               crypto-obj-y \
                common-obj-y \
                common-obj-m)
 target-obj-y := $(target-obj-y-save)
 all-obj-y += $(common-obj-y)
 all-obj-y += $(target-obj-y)
 all-obj-$(CONFIG_SOFTMMU) += $(block-obj-y)
+all-obj-$(CONFIG_SOFTMMU) += $(crypto-obj-y)
 
 $(QEMU_PROG_BUILD): config-devices.mak
 
crypto/Makefile.objs +5 -5
index b050138..2cf5b70 100644
@@ -1,5 +1,5 @@
-util-obj-y += init.o
-util-obj-y += hash.o
-util-obj-y += aes.o
-util-obj-y += desrfb.o
-util-obj-y += cipher.o
+crypto-obj-y = init.o
+crypto-obj-y += hash.o
+crypto-obj-y += aes.o
+crypto-obj-y += desrfb.o
+crypto-obj-y += cipher.o
tests/Makefile +4 -3
index f7e3619..938e8d5 100644
@@ -283,7 +283,8 @@ test-qom-obj-y = qom/object.o qom/qom-qobject.o \
 test-qapi-obj-y = tests/test-qapi-visit.o tests/test-qapi-types.o \
 	tests/test-qapi-event.o \
 	$(test-qom-obj-y)
-test-block-obj-y = $(block-obj-y) $(test-util-obj-y)
+test-crypto-obj-y = $(crypto-obj-y) $(test-util-obj-y)
+test-block-obj-y = $(block-obj-y) $(test-crypto-obj-y)
 
 tests/check-qint$(EXESUF): tests/check-qint.o $(test-util-obj-y)
 tests/check-qstring$(EXESUF): tests/check-qstring.o $(test-util-obj-y)
@@ -350,8 +351,8 @@ tests/test-opts-visitor$(EXESUF): tests/test-opts-visitor.o $(test-qapi-obj-y)
 
 tests/test-mul64$(EXESUF): tests/test-mul64.o $(test-util-obj-y)
 tests/test-bitops$(EXESUF): tests/test-bitops.o $(test-util-obj-y)
-tests/test-crypto-hash$(EXESUF): tests/test-crypto-hash.o $(test-util-obj-y)
-tests/test-crypto-cipher$(EXESUF): tests/test-crypto-cipher.o $(test-util-obj-y)
+tests/test-crypto-hash$(EXESUF): tests/test-crypto-hash.o $(test-crypto-obj-y)
+tests/test-crypto-cipher$(EXESUF): tests/test-crypto-cipher.o $(test-crypto-obj-y)
 
 libqos-obj-y = tests/libqos/pci.o tests/libqos/fw_cfg.o tests/libqos/malloc.o
 libqos-obj-y += tests/libqos/i2c.o tests/libqos/libqos.o
Signature · 1 line
2.4.3
#4 lore raw

PATCH v6 4/11 qom: allow QOM to be linked into tools binaries

In reply to Daniel P. Berrange

The qom objects are currently added to common-obj-y which is only linked into the system emulators. The later crypto patches will depend on QOM infrastructure and will also be used from tools binaries. Thus the QOM objects are moved into a new qom-obj-y variable which can be referenced when linking tools, system emulators and tests.

---
 Makefile          | 8 +++++---
 Makefile.objs     | 5 +++++
 Makefile.target   | 2 ++
 qom/Makefile.objs | 7 ++++---
 tests/Makefile    | 4 +---
 5 files changed, 17 insertions(+), 9 deletions(-)
Makefile +5 -3
index 5e63da8..ee78930 100644
@@ -152,6 +152,7 @@ dummy := $(call unnest-vars,, \
                 block-obj-y \
                 block-obj-m \
                 crypto-obj-y \
+                qom-obj-y \
                 common-obj-y \
                 common-obj-m)
 
@@ -174,6 +175,7 @@ SOFTMMU_SUBDIR_RULES=$(filter %-softmmu,$(SUBDIR_RULES))
 
 $(SOFTMMU_SUBDIR_RULES): $(block-obj-y)
 $(SOFTMMU_SUBDIR_RULES): $(crypto-obj-y)
+$(SOFTMMU_SUBDIR_RULES): $(qom-obj-y)
 $(SOFTMMU_SUBDIR_RULES): config-all-devices.mak
 
 subdir-%:
@@ -228,9 +230,9 @@ util/module.o-cflags = -D'CONFIG_BLOCK_MODULES=$(block-modules)'
 
 qemu-img.o: qemu-img-cmds.h
 
-qemu-img$(EXESUF): qemu-img.o $(block-obj-y) $(crypto-obj-y) libqemuutil.a libqemustub.a
-qemu-nbd$(EXESUF): qemu-nbd.o $(block-obj-y) $(crypto-obj-y) libqemuutil.a libqemustub.a
-qemu-io$(EXESUF): qemu-io.o $(block-obj-y) $(crypto-obj-y) libqemuutil.a libqemustub.a
+qemu-img$(EXESUF): qemu-img.o $(block-obj-y) $(crypto-obj-y) $(qom-obj-y) libqemuutil.a libqemustub.a
+qemu-nbd$(EXESUF): qemu-nbd.o $(block-obj-y) $(crypto-obj-y) $(qom-obj-y) libqemuutil.a libqemustub.a
+qemu-io$(EXESUF): qemu-io.o $(block-obj-y) $(crypto-obj-y) $(qom-obj-y) libqemuutil.a libqemustub.a
 
 qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o
 
Makefile.objs +5 -0
index c7ed989..2ff4224 100644
@@ -25,6 +25,11 @@ block-obj-m = block/
 
 crypto-obj-y = crypto/
 
+#######################################################################
+# qom-obj-y is code used by both qemu system emulation and qemu-img
+
+qom-obj-y = qom/
+
 ######################################################################
 # smartcard
 
Makefile.target +2 -0
index 2053ecd..0d968d6 100644
@@ -171,6 +171,7 @@ dummy := $(call unnest-vars,.., \
                block-obj-y \
                block-obj-m \
                crypto-obj-y \
+               qom-obj-y \
                common-obj-y \
                common-obj-m)
 target-obj-y := $(target-obj-y-save)
@@ -178,6 +179,7 @@ all-obj-y += $(common-obj-y)
 all-obj-y += $(target-obj-y)
 all-obj-$(CONFIG_SOFTMMU) += $(block-obj-y)
 all-obj-$(CONFIG_SOFTMMU) += $(crypto-obj-y)
+all-obj-$(CONFIG_SOFTMMU) += $(qom-obj-y)
 
 $(QEMU_PROG_BUILD): config-devices.mak
 
qom/Makefile.objs +4 -3
index 985003b..516349e 100644
@@ -1,3 +1,4 @@
-common-obj-y = object.o container.o qom-qobject.o
-common-obj-y += cpu.o
-common-obj-y += object_interfaces.o
+qom-obj-y = object.o container.o qom-qobject.o
+qom-obj-y += object_interfaces.o
+
+common-obj-y = cpu.o
tests/Makefile +1 -3
index 938e8d5..214caf2 100644
@@ -277,9 +277,7 @@ QEMU_CFLAGS += -I$(SRC_PATH)/tests
 
 # Deps that are common to various different sets of tests below
 test-util-obj-y = libqemuutil.a libqemustub.a
-test-qom-obj-y = qom/object.o qom/qom-qobject.o \
-	qom/container.o qom/object_interfaces.o \
-	$(test-util-obj-y)
+test-qom-obj-y = $(qom-obj-y) $(test-util-obj-y)
 test-qapi-obj-y = tests/test-qapi-visit.o tests/test-qapi-types.o \
 	tests/test-qapi-event.o \
 	$(test-qom-obj-y)
Signature · 1 line
2.4.3
#5 lore raw

PATCH v6 5/11 crypto: introduce new base module for TLS credentials

In reply to Daniel P. Berrange

Introduce a QCryptoTLSCreds class to act as the base class for storing TLS credentials. This will be later subclassed to provide handling of anonymous and x509 credential types. The subclasses will be user creatable objects, so instances can be created & deleted via 'object-add' and 'object-del' QMP commands respectively, or via the -object command line arg.

If the credentials cannot be initialized an error will be reported as a QMP reply, or on stderr respectively.

The idea is to make it possible to represent and manage TLS credentials independently of the network service that is using them. This will enable multiple services to use the same set of credentials and minimize code duplication. A later patch will convert the current VNC server TLS code over to use this object.

The representation of credentials will be functionally equivalent to that currently implemented in the VNC server with one exception. The new code has the ability to (optionally) load a pre-generated set of diffie-hellman parameters, if the file dh-params.pem exists, whereas the current VNC server will always generate them on startup. This is beneficial for admins who wish to avoid the (small) time sink of generating DH parameters at startup and/or avoid depleting entropy.

---
 crypto/Makefile.objs      |   1 +
 crypto/tlscreds.c         | 262 ++++++++++++++++++++++++++++++++++++++++++++++
 crypto/tlscredspriv.h     |  41 ++++++++
 include/crypto/tlscreds.h |  68 ++++++++++++
 qapi-schema.json          |   3 +
 qapi/crypto.json          |  21 ++++
 tests/Makefile            |   2 +-
 7 files changed, 397 insertions(+), 1 deletion(-)
 create mode 100644 crypto/tlscreds.c
 create mode 100644 crypto/tlscredspriv.h
 create mode 100644 include/crypto/tlscreds.h
 create mode 100644 qapi/crypto.json
crypto/Makefile.objs +1 -0
index 2cf5b70..ca90d1b 100644
@@ -3,3 +3,4 @@ crypto-obj-y += hash.o
 crypto-obj-y += aes.o
 crypto-obj-y += desrfb.o
 crypto-obj-y += cipher.o
+crypto-obj-y += tlscreds.o
crypto/tlscreds.c new file +262 -0

262 lines not on this page · raw message

crypto/tlscredspriv.h new file +41 -0

41 lines not on this page · raw message

include/crypto/tlscreds.h new file +68 -0

68 lines not on this page · raw message

qapi-schema.json +3 -0
index 4342a08..ae4858c 100644
@@ -5,6 +5,9 @@
 # QAPI common definitions
 { 'include': 'qapi/common.json' }
 
+# QAPI crypto definitions
+{ 'include': 'qapi/crypto.json' }
+
 # QAPI block definitions
 { 'include': 'qapi/block.json' }
 
qapi/crypto.json new file +21 -0
new file mode 100644
index 0000000..b058b14
@@ -0,0 +1,21 @@
+# -*- Mode: Python -*-
+#
+# QAPI crypto definitions
+
+##
+# QCryptoTLSCredsEndpoint:
+#
+# The type of network endpoint that will be using the credentials.
+# Most types of credential require different setup / structures
+# depending on whether they will be used in a server versus a
+# client.
+#
+# @client: the network endpoint is acting as the client
+#
+# @server: the network endpoint is acting as the server
+#
+# Since: 2.5
+##
+{ 'enum': 'QCryptoTLSCredsEndpoint',
+  'prefix': 'QCRYPTO_TLS_CREDS_ENDPOINT',
+  'data': ['client', 'server']}
tests/Makefile +1 -1
index 214caf2..a34a321 100644
@@ -281,7 +281,7 @@ test-qom-obj-y = $(qom-obj-y) $(test-util-obj-y)
 test-qapi-obj-y = tests/test-qapi-visit.o tests/test-qapi-types.o \
 	tests/test-qapi-event.o \
 	$(test-qom-obj-y)
-test-crypto-obj-y = $(crypto-obj-y) $(test-util-obj-y)
+test-crypto-obj-y = $(crypto-obj-y) $(test-qom-obj-y)
 test-block-obj-y = $(block-obj-y) $(test-crypto-obj-y)
 
 tests/check-qint$(EXESUF): tests/check-qint.o $(test-util-obj-y)
Signature · 1 line
2.4.3
#6 lore raw

PATCH v6 6/11 crypto: introduce new module for TLS anonymous credentials

In reply to Daniel P. Berrange

Introduce a QCryptoTLSCredsAnon class which is used to manage anonymous TLS credentials. Use of this class is generally discouraged since it does not offer strong security, but it is required for backwards compatibility with the current VNC server implementation.

Simple example CLI configuration:

$QEMU -object tls-creds-anon,id=tls0,endpoint=server

Example using pre-created diffie-hellman parameters

$QEMU -object tls-creds-anon,id=tls0,endpoint=server,\
dir=/path/to/creds/dir

The 'id' value in the -object args will be used to associate the credentials with the network services. For example, when the VNC server is later converted it would use

 $QEMU -object tls-creds-anon,id=tls0,.... \
       -vnc 127.0.0.1:1,tls-creds=tls0
---
 crypto/Makefile.objs          |   1 +
 crypto/tlscredsanon.c         | 236 ++++++++++++++++++++++++++++++++++++++++++
 include/crypto/tlscredsanon.h | 112 ++++++++++++++++++++
 qemu-options.hx               |  20 ++++
 4 files changed, 369 insertions(+)
 create mode 100644 crypto/tlscredsanon.c
 create mode 100644 include/crypto/tlscredsanon.h
crypto/Makefile.objs +1 -0
index ca90d1b..2080c5d 100644
@@ -4,3 +4,4 @@ crypto-obj-y += aes.o
 crypto-obj-y += desrfb.o
 crypto-obj-y += cipher.o
 crypto-obj-y += tlscreds.o
+crypto-obj-y += tlscredsanon.o
crypto/tlscredsanon.c new file +236 -0

236 lines not on this page · raw message

include/crypto/tlscredsanon.h new file +112 -0

112 lines not on this page · raw message

qemu-options.hx +20 -0
index 77f5853..057801a 100644
@@ -3568,6 +3568,26 @@ the @option{virtio-rng} device. The @option{chardev} parameter is
 the unique ID of a character device backend that provides the connection
 to the RNG daemon.
 
+@item -object tls-creds-anon,id=@var{id},endpoint=@var{endpoint},dir=@var{/path/to/cred/dir},verify-peer=@var{on|off}
+
+Creates a TLS anonymous credentials object, which can be used to provide
+TLS support on network backends. The @option{id} parameter is a unique
+ID which network backends will use to access the credentials. The
+@option{endpoint} is either @option{server} or @option{client} depending
+on whether the QEMU network backend that uses the credentials will be
+acting as a client or as a server. If @option{verify-peer} is enabled
+(the default) then once the handshake is completed, the peer credentials
+will be verified, though this is a no-op for anonymous credentials.
+
+The @var{dir} parameter tells QEMU where to find the credential
+files. For server endpoints, this directory may contain a file
+@var{dh-params.pem} providing diffie-hellman parameters to use
+for the TLS server. If the file is missing, QEMU will generate
+a set of DH parameters at startup. This is a computationally
+expensive operation that consumes random pool entropy, so it is
+recommended that a persistent set of parameters be generated
+upfront and saved.
+
 @end table
 
 ETEXI
Signature · 1 line
2.4.3
#7 lore raw

PATCH v6 7/11 crypto: introduce new module for TLS x509 credentials

In reply to Daniel P. Berrange

Introduce a QCryptoTLSCredsX509 class which is used to manage x509 certificate TLS credentials. This will be the preferred credential type offering strong security characteristics

Example CLI configuration:

$QEMU -object tls-creds-x509,id=tls0,endpoint=server,\
dir=/path/to/creds/dir,verify-peer=yes

The 'id' value in the -object args will be used to associate the credentials with the network services. For example, when the VNC server is later converted it would use

 $QEMU -object tls-creds-x509,id=tls0,.... \
       -vnc 127.0.0.1:1,tls-creds=tls0
---
 crypto/Makefile.objs          |   1 +
 crypto/tlscredsx509.c         | 276 ++++++++++++++++++++++++++++++++++++++++++
 include/crypto/tlscredsx509.h | 112 +++++++++++++++++
 qemu-options.hx               |  27 +++++
 4 files changed, 416 insertions(+)
 create mode 100644 crypto/tlscredsx509.c
 create mode 100644 include/crypto/tlscredsx509.h
crypto/Makefile.objs +1 -0
index 2080c5d..5894c88 100644
@@ -5,3 +5,4 @@ crypto-obj-y += desrfb.o
 crypto-obj-y += cipher.o
 crypto-obj-y += tlscreds.o
 crypto-obj-y += tlscredsanon.o
+crypto-obj-y += tlscredsx509.o
crypto/tlscredsx509.c new file +276 -0

276 lines not on this page · raw message

include/crypto/tlscredsx509.h new file +112 -0

112 lines not on this page · raw message

qemu-options.hx +27 -0
index 057801a..23c91d5 100644
@@ -3588,6 +3588,33 @@ expensive operation that consumes random pool entropy, so it is
 recommended that a persistent set of parameters be generated
 upfront and saved.
 
+@item -object tls-creds-x509,id=@var{id},endpoint=@var{endpoint},dir=@var{/path/to/cred/dir},verify-peer=@var{on|off}
+
+Creates a TLS anonymous credentials object, which can be used to provide
+TLS support on network backends. The @option{id} parameter is a unique
+ID which network backends will use to access the credentials. The
+@option{endpoint} is either @option{server} or @option{client} depending
+on whether the QEMU network backend that uses the credentials will be
+acting as a client or as a server. If @option{verify-peer} is enabled
+(the default) then once the handshake is completed, the peer credentials
+will be verified. With x509 certificates, this implies that the clients
+must be provided with valid client certificates too.
+
+The @var{dir} parameter tells QEMU where to find the credential
+files. For server endpoints, this directory may contain a file
+@var{dh-params.pem} providing diffie-hellman parameters to use
+for the TLS server. If the file is missing, QEMU will generate
+a set of DH parameters at startup. This is a computationally
+expensive operation that consumes random pool entropy, so it is
+recommended that a persistent set of parameters be generated
+upfront and saved.
+
+For x509 certificate credentials the directory will contain further files
+providing the x509 certificates. The certificates must be stored
+in PEM format, in filenames @var{ca-cert.pem}, @var{ca-crl.pem} (optional),
+@var{server-cert.pem} (only servers), @var{server-key.pem} (only servers),
+@var{client-cert.pem} (only clients), and @var{client-key.pem} (only clients).
+
 @end table
 
 ETEXI
Signature · 1 line
2.4.3
#8 lore raw

PATCH v6 8/11 crypto: add sanity checking of TLS x509 credentials

In reply to Daniel P. Berrange

If the administrator incorrectly sets up their x509 certificates, the errors seen at runtime during connection attempts are very obscure and difficult to diagnose. This has been a particular problem for people using openssl to generate their certificates instead of the gnutls certtool, because the openssl tools don't turn on the various x509 extensions that gnutls expects to be present by default.

This change thus adds support in the TLS credentials object to sanity check the certificates when QEMU first loads them. This gives the administrator immediate feedback for the majority of common configuration mistakes, reducing the pain involved in setting up TLS. The code is derived from equivalent code that has been part of libvirt's TLS support and has been seen to be valuable in assisting admins.

It is possible to disable the sanity checking, however, via the new 'sanity-check' property on the tls-creds object type, with a value of 'no'.

Unit tests are included in this change to verify the correctness of the sanity checking code in all the key scenarios it is intended to cope with. As part of the test suite, the pkix_asn1_tab.c from gnutls is imported. This file is intentionally copied from the (long since obsolete) gnutls 1.6.3 source tree, since that version was still under GPLv2+, rather than the GPLv3+ of gnutls >= 2.0.

---
 configure                        |   22 +
 crypto/tlscredsx509.c            |  544 +++++++++++++++++++
 include/crypto/tlscredsx509.h    |    1 +
 tests/.gitignore                 |    3 +
 tests/Makefile                   |    5 +
 tests/crypto-tls-x509-helpers.c  |  486 +++++++++++++++++
 tests/crypto-tls-x509-helpers.h  |  133 +++++
 tests/pkix_asn1_tab.c            | 1104 ++++++++++++++++++++++++++++++++++++++
 tests/test-crypto-tlscredsx509.c |  733 +++++++++++++++++++++++++
 9 files changed, 3031 insertions(+)
 create mode 100644 tests/crypto-tls-x509-helpers.c
 create mode 100644 tests/crypto-tls-x509-helpers.h
 create mode 100644 tests/pkix_asn1_tab.c
 create mode 100644 tests/test-crypto-tlscredsx509.c
configure +22 -0
index 9d24d59..00e28f2 100755
@@ -415,6 +415,9 @@ if test "$debug_info" = "yes"; then
     LDFLAGS="-g $LDFLAGS"
 fi
 
+test_cflags=""
+test_libs=""
+
 # make source path absolute
 source_path=`cd "$source_path"; pwd`
 
@@ -2215,6 +2218,19 @@ if test "$gnutls_nettle" != "no"; then
     fi
 fi
 
+##########################################
+# libtasn1 - only for the TLS creds/session test suite
+
+tasn1=yes
+if $pkg_config --exists "libtasn1"; then
+    tasn1_cflags=`$pkg_config --cflags libtasn1`
+    tasn1_libs=`$pkg_config --libs libtasn1`
+    test_cflags="$test_cflags $tasn1_cflags"
+    test_libs="$test_libs $tasn1_libs"
+else
+    tasn1=no
+fi
+
 
 ##########################################
 # VTE probe
@@ -4513,6 +4529,7 @@ echo "GNUTLS support    $gnutls"
 echo "GNUTLS hash       $gnutls_hash"
 echo "GNUTLS gcrypt     $gnutls_gcrypt"
 echo "GNUTLS nettle     $gnutls_nettle ${gnutls_nettle+($nettle_version)}"
+echo "libtasn1          $tasn1"
 echo "VTE support       $vte"
 echo "curses support    $curses"
 echo "curl support      $curl"
@@ -4881,6 +4898,9 @@ if test "$gnutls_nettle" = "yes" ; then
   echo "CONFIG_GNUTLS_NETTLE=y" >> $config_host_mak
   echo "CONFIG_NETTLE_VERSION_MAJOR=${nettle_version%%.*}" >> $config_host_mak
 fi
+if test "$tasn1" = "yes" ; then
+  echo "CONFIG_TASN1=y" >> $config_host_mak
+fi
 if test "$vte" = "yes" ; then
   echo "CONFIG_VTE=y" >> $config_host_mak
   echo "VTE_CFLAGS=$vte_cflags" >> $config_host_mak
@@ -5204,6 +5224,8 @@ echo "EXESUF=$EXESUF" >> $config_host_mak
 echo "DSOSUF=$DSOSUF" >> $config_host_mak
 echo "LDFLAGS_SHARED=$LDFLAGS_SHARED" >> $config_host_mak
 echo "LIBS_QGA+=$libs_qga" >> $config_host_mak
+echo "TEST_LIBS=$test_libs" >> $config_host_mak
+echo "TEST_CFLAGS=$test_cflags" >> $config_host_mak
 echo "POD2MAN=$POD2MAN" >> $config_host_mak
 echo "TRANSLATE_OPT_CFLAGS=$TRANSLATE_OPT_CFLAGS" >> $config_host_mak
 if test "$gcov" = "yes" ; then
crypto/tlscredsx509.c +544 -0

572 lines not on this page · raw message

include/crypto/tlscredsx509.h +1 -0
index abdb128..b9785fd 100644
@@ -100,6 +100,7 @@ struct QCryptoTLSCredsX509 {
 #ifdef CONFIG_GNUTLS
     gnutls_certificate_credentials_t data;
 #endif
+    bool sanityCheck;
 };
 
 
tests/.gitignore +3 -0
index ccc92e4..7b4ee23 100644
@@ -12,6 +12,9 @@ test-bitops
 test-coroutine
 test-crypto-cipher
 test-crypto-hash
+test-crypto-tlscredsx509
+test-crypto-tlscredsx509-work/
+test-crypto-tlscredsx509-certs/
 test-cutils
 test-hbitmap
 test-int128
tests/Makefile +5 -0
index a34a321..f595942 100644
@@ -76,6 +76,7 @@ check-unit-y += tests/test-write-threshold$(EXESUF)
 gcov-files-test-write-threshold-y = block/write-threshold.c
 check-unit-$(CONFIG_GNUTLS_HASH) += tests/test-crypto-hash$(EXESUF)
 check-unit-y += tests/test-crypto-cipher$(EXESUF)
+check-unit-$(CONFIG_GNUTLS) += tests/test-crypto-tlscredsx509$(EXESUF)
 
 check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
 
@@ -351,6 +352,8 @@ tests/test-mul64$(EXESUF): tests/test-mul64.o $(test-util-obj-y)
 tests/test-bitops$(EXESUF): tests/test-bitops.o $(test-util-obj-y)
 tests/test-crypto-hash$(EXESUF): tests/test-crypto-hash.o $(test-crypto-obj-y)
 tests/test-crypto-cipher$(EXESUF): tests/test-crypto-cipher.o $(test-crypto-obj-y)
+tests/test-crypto-tlscredsx509$(EXESUF): tests/test-crypto-tlscredsx509.o \
+	tests/crypto-tls-x509-helpers.o tests/pkix_asn1_tab.o $(test-crypto-obj-y)
 
 libqos-obj-y = tests/libqos/pci.o tests/libqos/fw_cfg.o tests/libqos/malloc.o
 libqos-obj-y += tests/libqos/i2c.o tests/libqos/libqos.o
@@ -417,6 +420,8 @@ tests/test-write-threshold$(EXESUF): tests/test-write-threshold.o $(test-block-o
 ifeq ($(CONFIG_POSIX),y)
 LIBS += -lutil
 endif
+LIBS += $(TEST_LIBS)
+CFLAGS += $(TEST_CFLAGS)
 
 # QTest rules
 
tests/crypto-tls-x509-helpers.c new file +486 -0

486 lines not on this page · raw message

tests/crypto-tls-x509-helpers.h new file +133 -0

133 lines not on this page · raw message

tests/pkix_asn1_tab.c new file +1104 -0

1,104 lines not on this page · raw message

tests/test-crypto-tlscredsx509.c new file +733 -0

614 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.4.3

Part of the diff is not shown here. View the raw message.

#9 lore raw

PATCH v6 9/11 crypto: introduce new module for handling TLS sessions

In reply to Daniel P. Berrange

Introduce a QCryptoTLSSession object that will encapsulate all the code for setting up and using a client/sever TLS session. This isolates the code which depends on the gnutls library, avoiding #ifdefs in the rest of the codebase, as well as facilitating any possible future port to other TLS libraries, if desired. It makes use of the previously defined QCryptoTLSCreds object to access credentials to use with the session. It also includes further unit tests to validate the correctness of the TLS session handshake and certificate validation. This is functionally equivalent to the current TLS session handling code embedded in the VNC server, and will obsolete it.

---
 crypto/Makefile.objs           |   1 +
 crypto/tlssession.c            | 586 +++++++++++++++++++++++++++++++++++++++++
 include/crypto/tlssession.h    | 322 ++++++++++++++++++++++
 tests/.gitignore               |   4 +
 tests/Makefile                 |   3 +
 tests/test-crypto-tlssession.c | 537 +++++++++++++++++++++++++++++++++++++
 6 files changed, 1453 insertions(+)
 create mode 100644 crypto/tlssession.c
 create mode 100644 include/crypto/tlssession.h
 create mode 100644 tests/test-crypto-tlssession.c
crypto/Makefile.objs +1 -0
index 5894c88..5567a51 100644
@@ -6,3 +6,4 @@ crypto-obj-y += cipher.o
 crypto-obj-y += tlscreds.o
 crypto-obj-y += tlscredsanon.o
 crypto-obj-y += tlscredsx509.o
+crypto-obj-y += tlssession.o
crypto/tlssession.c new file +586 -0

586 lines not on this page · raw message

include/crypto/tlssession.h new file +322 -0

322 lines not on this page · raw message

tests/.gitignore +4 -0
index 7b4ee23..2c5e2c3 100644
@@ -15,6 +15,10 @@ test-crypto-hash
 test-crypto-tlscredsx509
 test-crypto-tlscredsx509-work/
 test-crypto-tlscredsx509-certs/
+test-crypto-tlssession
+test-crypto-tlssession-work/
+test-crypto-tlssession-client/
+test-crypto-tlssession-server/
 test-cutils
 test-hbitmap
 test-int128
tests/Makefile +3 -0
index f595942..e184424 100644
@@ -77,6 +77,7 @@ gcov-files-test-write-threshold-y = block/write-threshold.c
 check-unit-$(CONFIG_GNUTLS_HASH) += tests/test-crypto-hash$(EXESUF)
 check-unit-y += tests/test-crypto-cipher$(EXESUF)
 check-unit-$(CONFIG_GNUTLS) += tests/test-crypto-tlscredsx509$(EXESUF)
+check-unit-$(CONFIG_GNUTLS) += tests/test-crypto-tlssession$(EXESUF)
 
 check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
 
@@ -354,6 +355,8 @@ tests/test-crypto-hash$(EXESUF): tests/test-crypto-hash.o $(test-crypto-obj-y)
 tests/test-crypto-cipher$(EXESUF): tests/test-crypto-cipher.o $(test-crypto-obj-y)
 tests/test-crypto-tlscredsx509$(EXESUF): tests/test-crypto-tlscredsx509.o \
 	tests/crypto-tls-x509-helpers.o tests/pkix_asn1_tab.o $(test-crypto-obj-y)
+tests/test-crypto-tlssession$(EXESUF): tests/test-crypto-tlssession.o \
+	tests/crypto-tls-x509-helpers.o tests/pkix_asn1_tab.o $(test-crypto-obj-y)
 
 libqos-obj-y = tests/libqos/pci.o tests/libqos/fw_cfg.o tests/libqos/malloc.o
 libqos-obj-y += tests/libqos/i2c.o tests/libqos/libqos.o
tests/test-crypto-tlssession.c new file +537 -0

537 lines not on this page · raw message

Signature · 1 line
2.4.3
#10 lore raw

PATCH v6 10/11 ui: fix return type for VNC I/O functions to be ssize_t

In reply to Daniel P. Berrange

Various VNC server I/O functions return 'long' and then also pass this to a method accepting 'int'. All these should be ssize_t to match the signature of read/write APIs and thus avoid potential for integer truncation / wraparound.

---
 ui/vnc.c | 36 ++++++++++++++++++------------------
 ui/vnc.h |  6 +++---
 2 files changed, 21 insertions(+), 21 deletions(-)
ui/vnc.c +18 -18
index caf82f5..19ad088 100644
@@ -1268,7 +1268,7 @@ void vnc_disconnect_finish(VncState *vs)
     g_free(vs);
 }
 
-int vnc_client_io_error(VncState *vs, int ret, int last_errno)
+ssize_t vnc_client_io_error(VncState *vs, ssize_t ret, int last_errno)
 {
     if (ret == 0 || ret == -1) {
         if (ret == -1) {
@@ -1284,7 +1284,7 @@ int vnc_client_io_error(VncState *vs, int ret, int last_errno)
             }
         }
 
-        VNC_DEBUG("Closing down client sock: ret %d, errno %d\n",
+        VNC_DEBUG("Closing down client sock: ret %zd, errno %d\n",
                   ret, ret < 0 ? last_errno : 0);
         vnc_disconnect_start(vs);
 
@@ -1301,11 +1301,11 @@ void vnc_client_error(VncState *vs)
 }
 
 #ifdef CONFIG_VNC_TLS
-static long vnc_client_write_tls(gnutls_session_t *session,
-                                 const uint8_t *data,
-                                 size_t datalen)
+static ssize_t vnc_client_write_tls(gnutls_session_t *session,
+                                    const uint8_t *data,
+                                    size_t datalen)
 {
-    long ret = gnutls_write(*session, data, datalen);
+    ssize_t ret = gnutls_write(*session, data, datalen);
     if (ret < 0) {
         if (ret == GNUTLS_E_AGAIN) {
             errno = EAGAIN;
@@ -1333,9 +1333,9 @@ static long vnc_client_write_tls(gnutls_session_t *session,
  * the requested 'datalen' if the socket would block. Returns
  * -1 on error, and disconnects the client socket.
  */
-long vnc_client_write_buf(VncState *vs, const uint8_t *data, size_t datalen)
+ssize_t vnc_client_write_buf(VncState *vs, const uint8_t *data, size_t datalen)
 {
-    long ret;
+    ssize_t ret;
 #ifdef CONFIG_VNC_TLS
     if (vs->tls.session) {
         ret = vnc_client_write_tls(&vs->tls.session, data, datalen);
@@ -1360,9 +1360,9 @@ long vnc_client_write_buf(VncState *vs, const uint8_t *data, size_t datalen)
  * the buffered output data if the socket would block. Returns
  * -1 on error, and disconnects the client socket.
  */
-static long vnc_client_write_plain(VncState *vs)
+static ssize_t vnc_client_write_plain(VncState *vs)
 {
-    long ret;
+    ssize_t ret;
 
 #ifdef CONFIG_VNC_SASL
     VNC_DEBUG("Write Plain: Pending output %p size %zd offset %zd. Wait SSF %d\n",
@@ -1436,10 +1436,10 @@ void vnc_read_when(VncState *vs, VncReadEvent *func, size_t expecting)
 }
 
 #ifdef CONFIG_VNC_TLS
-static long vnc_client_read_tls(gnutls_session_t *session, uint8_t *data,
-                                size_t datalen)
+static ssize_t vnc_client_read_tls(gnutls_session_t *session, uint8_t *data,
+                                   size_t datalen)
 {
-    long ret = gnutls_read(*session, data, datalen);
+    ssize_t ret = gnutls_read(*session, data, datalen);
     if (ret < 0) {
         if (ret == GNUTLS_E_AGAIN) {
             errno = EAGAIN;
@@ -1467,9 +1467,9 @@ static long vnc_client_read_tls(gnutls_session_t *session, uint8_t *data,
  * the requested 'datalen' if the socket would block. Returns
  * -1 on error, and disconnects the client socket.
  */
-long vnc_client_read_buf(VncState *vs, uint8_t *data, size_t datalen)
+ssize_t vnc_client_read_buf(VncState *vs, uint8_t *data, size_t datalen)
 {
-    long ret;
+    ssize_t ret;
 #ifdef CONFIG_VNC_TLS
     if (vs->tls.session) {
         ret = vnc_client_read_tls(&vs->tls.session, data, datalen);
@@ -1492,9 +1492,9 @@ long vnc_client_read_buf(VncState *vs, uint8_t *data, size_t datalen)
  * Returns the number of bytes read. Returns -1 on error, and
  * disconnects the client socket.
  */
-static long vnc_client_read_plain(VncState *vs)
+static ssize_t vnc_client_read_plain(VncState *vs)
 {
-    int ret;
+    ssize_t ret;
     VNC_DEBUG("Read plain %p size %zd offset %zd\n",
               vs->input.buffer, vs->input.capacity, vs->input.offset);
     buffer_reserve(&vs->input, 4096);
@@ -1520,7 +1520,7 @@ static void vnc_jobs_bh(void *opaque)
 void vnc_client_read(void *opaque)
 {
     VncState *vs = opaque;
-    long ret;
+    ssize_t ret;
 
 #ifdef CONFIG_VNC_SASL
     if (vs->sasl.conn && vs->sasl.runSSF)
ui/vnc.h +3 -3
index 814d720..194ccf7 100644
@@ -513,8 +513,8 @@ enum {
 void vnc_client_read(void *opaque);
 void vnc_client_write(void *opaque);
 
-long vnc_client_read_buf(VncState *vs, uint8_t *data, size_t datalen);
-long vnc_client_write_buf(VncState *vs, const uint8_t *data, size_t datalen);
+ssize_t vnc_client_read_buf(VncState *vs, uint8_t *data, size_t datalen);
+ssize_t vnc_client_write_buf(VncState *vs, const uint8_t *data, size_t datalen);
 
 /* Protocol I/O functions */
 void vnc_write(VncState *vs, const void *data, size_t len);
@@ -533,7 +533,7 @@ uint32_t read_u32(uint8_t *data, size_t offset);
 
 /* Protocol stage functions */
 void vnc_client_error(VncState *vs);
-int vnc_client_io_error(VncState *vs, int ret, int last_errno);
+ssize_t vnc_client_io_error(VncState *vs, ssize_t ret, int last_errno);
 
 void start_client_init(VncState *vs);
 void start_auth_vnc(VncState *vs);
Signature · 1 line
2.4.3
#11 lore raw

PATCH v6 11/11 ui: convert VNC server to use QCryptoTLSSession

In reply to Daniel P. Berrange

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.

---
 configure              |  31 ----
 qemu-options.hx        |  28 ++-
 ui/Makefile.objs       |   2 +-
 ui/vnc-auth-sasl.c     |  36 ++--
 ui/vnc-auth-vencrypt.c |  80 +++++----
 ui/vnc-tls.c           | 474 -------------------------------------------------
 ui/vnc-tls.h           |  69 -------
 ui/vnc-ws.c            |  84 +++++----
 ui/vnc-ws.h            |   2 -
 ui/vnc.c               | 340 ++++++++++++++++++++++-------------
 ui/vnc.h               |  15 +-
 11 files changed, 362 insertions(+), 799 deletions(-)
 delete mode 100644 ui/vnc-tls.c
 delete mode 100644 ui/vnc-tls.h
configure +0 -31
index 00e28f2..a9f2b38 100755
@@ -242,7 +242,6 @@ vnc="yes"
 sparse="no"
 uuid=""
 vde=""
-vnc_tls=""
 vnc_sasl=""
 vnc_jpeg=""
 vnc_png=""
@@ -882,10 +881,6 @@ for opt do
   ;;
   --disable-strip) strip_opt="no"
   ;;
-  --disable-vnc-tls) vnc_tls="no"
-  ;;
-  --enable-vnc-tls) vnc_tls="yes"
-  ;;
   --disable-vnc-sasl) vnc_sasl="no"
   ;;
   --enable-vnc-sasl) vnc_sasl="yes"
@@ -2375,28 +2370,6 @@ EOF
   fi
 fi
 
-##########################################
-# VNC TLS/WS detection
-if test "$vnc" = "yes" -a "$vnc_tls" != "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
-    if test "$vnc_tls" != "no" ; then
-      vnc_tls=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"
-    fi
-    vnc_tls=no
-  fi
-fi
 
 ##########################################
 # VNC SASL detection
@@ -4540,7 +4513,6 @@ echo "Block whitelist (ro) $block_drv_ro_whitelist"
 echo "VirtFS support    $virtfs"
 echo "VNC support       $vnc"
 if test "$vnc" = "yes" ; then
-    echo "VNC TLS support   $vnc_tls"
     echo "VNC SASL support  $vnc_sasl"
     echo "VNC JPEG support  $vnc_jpeg"
     echo "VNC PNG support   $vnc_png"
@@ -4746,9 +4718,6 @@ echo "CONFIG_BDRV_RO_WHITELIST=$block_drv_ro_whitelist" >> $config_host_mak
 if test "$vnc" = "yes" ; then
   echo "CONFIG_VNC=y" >> $config_host_mak
 fi
-if test "$vnc_tls" = "yes" ; then
-  echo "CONFIG_VNC_TLS=y" >> $config_host_mak
-fi
 if test "$vnc_sasl" = "yes" ; then
   echo "CONFIG_VNC_SASL=y" >> $config_host_mak
 fi
qemu-options.hx +26 -2
index 23c91d5..9918874 100644
@@ -1214,8 +1214,9 @@ By definition the Websocket port is 5700+@var{display}. If @var{host} is
 specified connections will only be allowed from this host.
 As an alternative the Websocket port could be specified by using
 @code{websocket}=@var{port}.
-TLS encryption for the Websocket connection is supported if the required
-certificates are specified with the VNC option @option{x509}.
+If no TLS credentials are provided, the websocket connection runs in
+unencrypted mode. If TLS credentials are provided, the websocket connection
+requires encrypted client connections.
 
 @item password
 
@@ -1236,6 +1237,20 @@ date and time).
 You can also use keywords "now" or "never" for the expiration time to
 allow <protocol> password to expire immediately or never expire.
 
+@item tls-creds=@var{ID}
+
+Provides the ID of a set of TLS credentials to use to secure the
+VNC server. They will apply to both the normal VNC server socket
+and the websocket socket (if enabled). Setting TLS credentials
+will cause the VNC server socket to enable the VeNCrypt auth
+mechanism.  The credentials should have been previously created
+using the @option{-object tls-creds} argument.
+
+The @option{tls-creds} parameter obsoletes the @option{tls},
+@option{x509}, and @option{x509verify} options, and as such
+it is not permitted to set both new and old type options at
+the same time.
+
 @item tls
 
 Require that client use TLS when communicating with the VNC server. This
@@ -1243,6 +1258,9 @@ uses anonymous TLS credentials so is susceptible to a man-in-the-middle
 attack. It is recommended that this option be combined with either the
 @option{x509} or @option{x509verify} options.
 
+This option is now deprecated in favor of using the @option{tls-creds}
+argument.
+
 @item x509=@var{/path/to/certificate/dir}
 
 Valid if @option{tls} is specified. Require that x509 credentials are used
@@ -1252,6 +1270,9 @@ to provide authentication of the client when this is used. The path following
 this option specifies where the x509 certificates are to be loaded from.
 See the @ref{vnc_security} section for details on generating certificates.
 
+This option is now deprecated in favour of using the @option{tls-creds}
+argument.
+
 @item x509verify=@var{/path/to/certificate/dir}
 
 Valid if @option{tls} is specified. Require that x509 credentials are used
@@ -1265,6 +1286,9 @@ path following this option specifies where the x509 certificates are to
 be loaded from. See the @ref{vnc_security} section for details on generating
 certificates.
 
+This option is now deprecated in favour of using the @option{tls-creds}
+argument.
+
 @item sasl
 
 Require that the client use SASL to authenticate with the VNC server.
ui/Makefile.objs +1 -1
index c62d4d9..0034fbb 100644
@@ -2,7 +2,7 @@ vnc-obj-y += vnc.o
 vnc-obj-y += vnc-enc-zlib.o vnc-enc-hextile.o
 vnc-obj-y += vnc-enc-tight.o vnc-palette.o
 vnc-obj-y += vnc-enc-zrle.o
-vnc-obj-$(CONFIG_VNC_TLS) += vnc-tls.o vnc-auth-vencrypt.o
+vnc-obj-y += vnc-auth-vencrypt.o
 vnc-obj-$(CONFIG_VNC_SASL) += vnc-auth-sasl.o
 vnc-obj-y += vnc-ws.o
 vnc-obj-y += vnc-jobs.o
ui/vnc-auth-sasl.c +19 -17
index 62a5fc4..fc732bd 100644
@@ -525,21 +525,24 @@ void start_auth_sasl(VncState *vs)
         goto authabort;
     }
 
-#ifdef CONFIG_VNC_TLS
     /* Inform SASL that we've got an external SSF layer from TLS/x509 */
     if (vs->auth == VNC_AUTH_VENCRYPT &&
         vs->subauth == VNC_AUTH_VENCRYPT_X509SASL) {
-        gnutls_cipher_algorithm_t cipher;
+        Error *local_err = NULL;
+        int keysize;
         sasl_ssf_t ssf;
 
-        cipher = gnutls_cipher_get(vs->tls.session);
-        if (!(ssf = (sasl_ssf_t)gnutls_cipher_get_key_size(cipher))) {
-            VNC_DEBUG("%s", "cannot TLS get cipher size\n");
+        keysize = qcrypto_tls_session_get_key_size(vs->tls,
+                                                   &local_err);
+        if (keysize < 0) {
+            VNC_DEBUG("cannot TLS get cipher size: %s\n",
+                      error_get_pretty(local_err));
+            error_free(local_err);
             sasl_dispose(&vs->sasl.conn);
             vs->sasl.conn = NULL;
             goto authabort;
         }
-        ssf *= 8; /* tls key size is bytes, sasl wants bits */
+        ssf = keysize * CHAR_BIT; /* tls key size is bytes, sasl wants bits */
 
         err = sasl_setprop(vs->sasl.conn, SASL_SSF_EXTERNAL, &ssf);
         if (err != SASL_OK) {
@@ -549,20 +552,19 @@ void start_auth_sasl(VncState *vs)
             vs->sasl.conn = NULL;
             goto authabort;
         }
-    } else
-#endif /* CONFIG_VNC_TLS */
+    } else {
         vs->sasl.wantSSF = 1;
+    }
 
     memset (&secprops, 0, sizeof secprops);
-    /* Inform SASL that we've got an external SSF layer from TLS */
-    if (vs->vd->is_unix
-#ifdef CONFIG_VNC_TLS
-        /* Disable SSF, if using TLS+x509+SASL only. TLS without x509
-           is not sufficiently strong */
-        || (vs->auth == VNC_AUTH_VENCRYPT &&
-            vs->subauth == VNC_AUTH_VENCRYPT_X509SASL)
-#endif /* CONFIG_VNC_TLS */
-        ) {
+    /* Inform SASL that we've got an external SSF layer from TLS.
+     *
+     * Disable SSF, if using TLS+x509+SASL only. TLS without x509
+     * is not sufficiently strong
+     */
+    if (vs->vd->is_unix ||
+        (vs->auth == VNC_AUTH_VENCRYPT &&
+         vs->subauth == VNC_AUTH_VENCRYPT_X509SASL)) {
         /* If we've got TLS or UNIX domain sock, we don't care about SSF */
         secprops.min_ssf = 0;
         secprops.max_ssf = 0;
ui/vnc-auth-vencrypt.c +45 -35

112 lines not on this page · raw message

ui/vnc-tls.c deleted +0 -474

474 lines not on this page · raw message

ui/vnc-tls.h deleted +0 -69

69 lines not on this page · raw message

ui/vnc-ws.c +47 -37

107 lines not on this page · raw message

ui/vnc-ws.h +0 -2
index 9494225..4ab0a8c 100644
@@ -72,9 +72,7 @@ enum {
     WS_OPCODE_PONG = 0xA
 };
 
-#ifdef CONFIG_VNC_TLS
 void vncws_tls_handshake_io(void *opaque);
-#endif /* CONFIG_VNC_TLS */
 void vncws_handshake_read(void *opaque);
 long vnc_client_write_ws(VncState *vs);
 long vnc_client_read_ws(VncState *vs);
ui/vnc.c +218 -122

563 lines not on this page · raw message

ui/vnc.h +6 -9
index 194ccf7..4dd769c 100644
@@ -33,6 +33,7 @@
 #include "ui/console.h"
 #include "audio/audio.h"
 #include "qemu/bitmap.h"
+#include "crypto/tlssession.h"
 #include <zlib.h>
 #include <stdbool.h>
 
@@ -101,10 +102,7 @@ typedef void VncSendHextileTile(VncState *vs,
 
 typedef struct VncDisplay VncDisplay;
 
-#ifdef CONFIG_VNC_TLS
-#include "vnc-tls.h"
 #include "vnc-auth-vencrypt.h"
-#endif
 #ifdef CONFIG_VNC_SASL
 #include "vnc-auth-sasl.h"
 #endif
@@ -181,9 +179,8 @@ struct VncDisplay
     bool ws_tls; /* Used by websockets */
     bool lossy;
     bool non_adaptive;
-#ifdef CONFIG_VNC_TLS
-    VncDisplayTLS tls;
-#endif
+    QCryptoTLSCreds *tlscreds;
+    char *tlsaclname;
 #ifdef CONFIG_VNC_SASL
     VncDisplaySASL sasl;
 #endif
@@ -284,9 +281,7 @@ struct VncState
     int auth;
     int subauth; /* Used by VeNCrypt */
     char challenge[VNC_AUTH_CHALLENGE_SIZE];
-#ifdef CONFIG_VNC_TLS
-    VncStateTLS tls;
-#endif
+    QCryptoTLSSession *tls;
 #ifdef CONFIG_VNC_SASL
     VncStateSASL sasl;
 #endif
@@ -515,6 +510,8 @@ void vnc_client_write(void *opaque);
 
 ssize_t vnc_client_read_buf(VncState *vs, uint8_t *data, size_t datalen);
 ssize_t vnc_client_write_buf(VncState *vs, const uint8_t *data, size_t datalen);
+ssize_t vnc_tls_pull(char *buf, size_t len, void *opaque);
+ssize_t vnc_tls_push(const char *buf, size_t len, void *opaque);
 
 /* Protocol I/O functions */
 void vnc_write(VncState *vs, const void *data, size_t len);
Signature · 1 line
2.4.3
#12 lore raw
In reply to Daniel P. Berrange
Quoted 41 lines · Daniel P. Berrange

This small patch series is a formal submission of another part of my previous series

v1: https://lists.gnu.org/archive/html/qemu-devel/2015-04/msg02038.html
v2: https://lists.gnu.org/archive/html/qemu-devel/2015-08/msg01267.html
v3: https://lists.gnu.org/archive/html/qemu-devel/2015-08/msg01386.html
v4: https://lists.gnu.org/archive/html/qemu-devel/2015-08/msg02655.html
v5: https://lists.gnu.org/archive/html/qemu-devel/2015-08/msg03159.html

Now we have the basic crypto module defined for hash/cipher APIs, we extend it to also cover TLS credential and TLS session handling APIs. These new TLS related APIs obsolete the vast majority of the TLS handling code in the current VNC server. As a result the VNC server no longer has to worry about conditional compilation for GNUTLS. It also gives us code reuse for future patches which intend to add TLS support to chardevs, migration, nbd, etc.

This series deprecates the existing way of configuring TLS for VNC on the command line, but maintains support for back-compat reasons.

Since the TLS code is now totally isolated from the VNC server it is also practical to provide significant unit test coverage of what is security critical code.

Aside from the new CLI syntax for configuring TLS with VNC, the only other functional change is to allow diffie-hellman params to be loaded from a file, instead of being generated at startup.

Changes in v6:

- Remove use of -Wl,--whole-archive added in v5 since it bloated the binary sizes too much
- Move crypto code out of libqemuutil.a to allow linking with QOM without problem of linker dropping objects only referenced via constructors
- Allow tools to link to QOM objects
- Remove repetition in unit test object deps
- Remove trailing '.' from error messages in TLS code
- Remove leading '_' from struct name in TLS session
- Fix leak of TLS credentials in cert checking error path

Quoted 8 lines

- Added docs for enhancement to enum code generator
- Misc docs typos & indentation fixes
- Add more sanity checking to enum code generator
- Add tests to cover enum code generator enhancement
- Fix dereference of Error **errp variables
- Fix overwriting of already set Error * variable in tests
- Use CHAR_BIT constant in sasl code
- Fix incorrect return status in VNC TLS code errorpath

I think the patches are great, and I'm not sure if anyone is in a better position than you to decide if they're ready. I don't even know if anyone really understands the VNC TLS code and thus can review patch 11. :) So I would just ask you to send a pull request.

Paolo

#13 lore raw

Hi,

Quoted 2 lines

I think the patches are great, and I'm not sure if anyone is in a better position than you to decide if they're ready.

Lets have a look:

# scripts/get_maintainer.pl -f crypto
"Daniel P. Berrange" <[email protected]> (maintainer:Cryptography)
Quoted 3 lines

I don't even know if anyone really understands the VNC TLS code and thus can review patch 11. :) So I would just ask you to send a pull request.

Agree. Don't be shy, send a pull request. Including the vnc bits is fine with me. I've briefly looked over the vnc changes, they look sane to me, and consolidating all the crypto stuff in a nice, reusable way instead of sprinkling gnutls ifdefs all over the place (including vnc) certainly is a step into the right direction.

cheers,
Gerd