summaryrefslogtreecommitdiffstats
path: root/recipes-extended/libvirt/libvirt
diff options
context:
space:
mode:
authorHe Zhe <zhe.he@windriver.com>2019-07-13 12:33:03 +0800
committerBruce Ashfield <bruce.ashfield@gmail.com>2019-07-16 19:41:05 +0000
commit37a554a2491499aabc88959348544e325e533f71 (patch)
treeb74970ecbe5354fb9c516f16fdc8027a2973de21 /recipes-extended/libvirt/libvirt
parent990d6d8d2bc9c1551cb5df36bac3e4b544841f12 (diff)
downloadmeta-virtualization-37a554a2491499aabc88959348544e325e533f71.tar.gz
libvirt: libvirtd: Facilitate using tls connection mode
tls is the default network connection mode of libvirtd upstream, though we use tcp mode as default. tls requires necessary keys and certificates of certificate authority, server and client to be properly generated and deployed. Otherwise servers and clients cannot be connected. This patch, - integrates sample keys and certificats of certificate authority, server and client for users to be able to use tls mode out of box. - sets default server IP address to 127.0.0.1 for users to use local client out of box. - integrates certtool and provides gnutls-help.py for users to generate keys and certificates on targets in their own ways. - adds a PACKAGECONFIG option "gnutls" to control all of the above integration but disables it to keep the same default behavior as before. Signed-off-by: He Zhe <zhe.he@windriver.com> Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
Diffstat (limited to 'recipes-extended/libvirt/libvirt')
-rwxr-xr-xrecipes-extended/libvirt/libvirt/gnutls-helper.py136
1 files changed, 136 insertions, 0 deletions
diff --git a/recipes-extended/libvirt/libvirt/gnutls-helper.py b/recipes-extended/libvirt/libvirt/gnutls-helper.py
new file mode 100755
index 00000000..b9949469
--- /dev/null
+++ b/recipes-extended/libvirt/libvirt/gnutls-helper.py
@@ -0,0 +1,136 @@
1#!/usr/bin/env python3
2#
3# Copyright (C) 2019 Wind River Systems, Inc.
4#
5# SPDX-License-Identifier: GPL-2.0-only
6#
7
8import os, sys, getopt
9
10banner = \
11'''\
12!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
13!! "ip_address" field of server.info must be IP address of the server. !!
14!! For more details, please refer to: !!
15!! https://libvirt.org/remote.html#Remote_certificates !!
16!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
17
18Please deploy cacert.pem to CA and server and client /etc/pki/CA/cacert.pem
19Please deploy serverkey.pem to server /etc/pki/libvirt/private/serverkey.pem
20Please deploy servercert.pem to server /etc/pki/libvirt/servercert.pem
21Please deploy clientkey.pem to client /etc/pki/libvirt/private/clientkey.pem
22Please deploy clientcert.pem to client /etc/pki/libvirt/clientcert.pem"
23'''
24
25if os.system('which certtool > /dev/null 2>&1') != 0:
26 print('certtool is not available. It is provided by \n\
27gnutls-bin on Yocto like Linux or \n\
28gnutls-bin on Debian like distribution or \n\
29gnutls-utils on Redhat like distribution.')
30 sys.exit()
31
32cainfo = ""
33serverinfo = ""
34clientinfo = ""
35yes = 0
36
37try:
38 opts, args = getopt.getopt(sys.argv[1:], "ha:b:c:y", ["help", "ca-info=", "server-info=", "client-info=", "yes"])
39except getopt.GetoptError:
40 print('Usage:\n{} [-a|--ca-info] <ca.info> [-b|--server-info] <server.info> [-c|--client-info] <client.info> [-y|--yes]'.format(sys.argv[0]))
41 print('If ca.info or server.info or client.info is not provided, a corresponding sample file will be generated.')
42 sys.exit(2)
43for opt, arg in opts:
44 if opt in ("-h", "--help"):
45 print('Usage:\n{} [-a|--ca-info] <ca.info> [-b|--server-info] <server.info> [-c|--client-info] <client.info> [-y|--yes]'.format(sys.argv[0]))
46 print('If ca.info or server.info or client.info is not provided, a corresponding sample file will be generated.\n')
47 print(banner)
48 sys.exit()
49 elif opt in ("-a", "--ca-info"):
50 cainfo = arg
51 elif opt in ("-b", "--server-info"):
52 serverinfo = arg
53 elif opt in ("-c", "--client-info"):
54 clientinfo = arg
55 elif opt in ("-y", "--yes"):
56 yes = 1
57
58cainfodefault = \
59'''cn = CA
60ca
61cert_signing_key
62'''
63
64serverinfodefault = \
65'''organization = Organization
66cn = Server
67dns_name = DNS Name
68ip_address = 127.0.0.1
69tls_www_server
70encryption_key
71signing_key
72'''
73
74clientinfodefault = \
75'''country = Country
76state = State
77locality = Locality
78organization = Organization
79cn = Client
80tls_www_client
81encryption_key
82signing_key
83'''
84
85if not cainfo:
86 if yes == 0:
87 opt = input('{}\nca.info not provided by -a, the above will be used [y/n]?'.format(cainfodefault))
88 if opt != 'y':
89 exit()
90 cainfo = "ca.info"
91 with open(cainfo, mode='w') as f:
92 f.write(cainfodefault)
93
94if not serverinfo:
95 if yes == 0:
96 opt = input('{}\nserver.info not provided by -b, the above will be used [y/n]?'.format(serverinfodefault))
97 if opt != 'y':
98 exit()
99 serverinfo = "server.info"
100 with open(serverinfo, mode='w') as f:
101 f.write(serverinfodefault)
102
103if not clientinfo:
104 if yes == 0:
105 opt = input('{}\nclient.info not provided by -c, the above will be used [y/n]?'.format(clientinfodefault))
106 if opt != 'y':
107 sys.exit()
108 clientinfo = "client.info"
109 with open(clientinfo, mode='w') as f:
110 f.write(clientinfodefault)
111
112if os.system("certtool --generate-privkey > cakey.pem") != 0:
113 print('ca private key failed.')
114 sys.exit()
115
116if os.system("certtool --generate-self-signed --load-privkey cakey.pem --template {} --outfile cacert.pem".format(cainfo)) != 0:
117 print('ca cert failed.')
118 sys.exit()
119
120if os.system("certtool --generate-privkey > serverkey.pem") != 0:
121 print('server private key failed.')
122 sys.exit()
123
124if os.system("certtool --generate-certificate --load-privkey serverkey.pem --load-ca-certificate cacert.pem --load-ca-privkey cakey.pem --template {} --outfile servercert.pem".format(serverinfo)) != 0:
125 print('server cert failed.')
126 sys.exit()
127
128if os.system("certtool --generate-privkey > clientkey.pem") != 0:
129 print('client private key failed.')
130 sys.exit()
131
132if os.system("certtool --generate-certificate --load-privkey clientkey.pem --load-ca-certificate cacert.pem --load-ca-privkey cakey.pem --template {} --outfile clientcert.pem".format(clientinfo)) != 0:
133 print('client cert failed.')
134 sys.exit()
135
136print(banner)