This file is indexed.

/usr/bin/virt-pki-validate is in libvirt-bin 0.9.8-2ubuntu17.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#!/bin/sh
#
# This shell script checks the TLS certificates and options needed
# for the secure client/server support of libvirt as documented at
# http://libvirt.org/remote.html#Remote_certificates
#
# Daniel Veillard <veillard@redhat.com>
#
USER=`who am i | awk '{ print $1 }'`
SERVER=1
CLIENT=1
PORT=16514
#
# First get certtool
#
CERTOOL=`which certtool 2>/dev/null`
if [ ! -x "$CERTOOL" ]
then
    echo "Could not locate the certtool program"
    echo "make sure the gnutls-utils (or gnutls-bin) package is installed"
    exit 1
fi
echo Found "$CERTOOL"

#
# Check the directory structure
#
SYSCONFDIR="/etc"
PKI="$SYSCONFDIR/pki"
if [ ! -d "$PKI" ]
then
    echo the $PKI directory is missing, it is usually
    echo installed as part of the filesystem or openssl packages
    exit 1
fi

if [ ! -r "$PKI" ]
then
    echo the $PKI directory is not readable by $USER
    echo "as root do: chmod a+rx $PKI"
    exit 1
fi
if [ ! -x "$PKI" ]
then
    echo the $PKI directory is not listable by $USER
    echo "as root do: chmod a+rx $PKI"
    exit 1
fi

CA="$PKI/CA"
if [ ! -d "$CA" ]
then
    echo the $CA directory is missing, it is usually
    echo installed as part of the or openssl package
    exit 1
fi

if [ ! -r "$CA" ]
then
    echo the $CA directory is not readable by $USER
    echo "as root do: chmod a+rx $CA"
    exit 1
fi
if [ ! -x "$CA" ]
then
    echo the $CA directory is not listable by $USER
    echo "as root do: chmod a+rx $CA"
    exit 1
fi

LIBVIRT="$PKI/libvirt"
if [ ! -d "$LIBVIRT" ]
then
    echo the $LIBVIRT directory is missing, it is usually
    echo installed by the libvirt package
    echo "as root do: mkdir -m 755 $LIBVIRT ; chown root:root $LIBVIRT"
    exit 1
fi

if [ ! -r "$LIBVIRT" ]
then
    echo the $LIBVIRT directory is not readable by $USER
    echo "as root do: chown root:root $LIBVIRT ; chmod 755 $LIBVIRT"
    exit 1
fi
if [ ! -x "$LIBVIRT" ]
then
    echo the $LIBVIRT directory is not listable by $USER
    echo "as root do: chown root:root $LIBVIRT ; chmod 755 $LIBVIRT"
    exit 1
fi

LIBVIRTP="$LIBVIRT/private"
if [ ! -d "$LIBVIRTP" ]
then
    echo the $LIBVIRTP directory is missing, it is usually
    echo installed by the libvirt package
    echo "as root do: mkdir -m 755 $LIBVIRTP ; chown root:root $LIBVIRTP"
    exit 1
fi

if [ ! -r "$LIBVIRTP" ]
then
    echo the $LIBVIRTP directory is not readable by $USER
    echo "as root do: chown root:root $LIBVIRTP ; chmod 755 $LIBVIRTP"
    exit 1
fi
if [ ! -x "$LIBVIRTP" ]
then
    echo the $LIBVIRTP directory is not listable by $USER
    echo "as root do: chown root:root $LIBVIRTP ; chmod 755 $LIBVIRTP"
    exit 1
fi

#
# Now check the certificates
# First the CA certificate
#
if [ ! -f "$CA/cacert.pem" ]
then
    echo the CA certificate $CA/cacert.pem is missing while it
    echo should be installed on both client and servers
    echo "see http://libvirt.org/remote.html#Remote_TLS_CA"
    echo on how to install it
    exit 1
fi
if [ ! -r "$CA/cacert.pem" ]
then
    echo the CA certificate $CA/cacert.pem is not readable by $USER
    echo "as root do: chmod 644 $CA/cacert.pem"
    exit 1
fi
sed_get_org='/Issuer:/ {
  s/.*Issuer:.*CN=//
  s/,.*//
  p
}'
ORG=`"$CERTOOL" -i --infile "$CA/cacert.pem" | sed -n "$sed_get_org"`
if [ "$ORG" = "" ]
then
    echo the CA certificate $CA/cacert.pem does not define the organization
    echo it should probably regenerated
    echo "see http://libvirt.org/remote.html#Remote_TLS_CA"
    echo on how to regenerate it
    exit 1
fi
echo Found CA certificate $CA/cacert.pem for $ORG

# Second the client certificates

if [ -f "$LIBVIRT/clientcert.pem" ]
then
    if [ ! -r "$LIBVIRT/clientcert.pem" ]
    then
        echo Client certificate $LIBVIRT/clientcert.pem should be world readable
        echo "as root do: chown root:root $LIBVIRT/clientcert.pem ; chmod 644 $LIBVIRT/clientcert.pem"
    else
        S_ORG=`"$CERTOOL" -i --infile "$LIBVIRT/clientcert.pem" | grep Subject: | sed 's+.*O=\([a-zA-Z \._-]*\).*+\1+'`
        if [ "$ORG" != "$S_ORG" ]
        then
            echo The CA certificate and the client certificate do not match
            echo CA organization: $ORG
            echo Client organization: $S_ORG
        fi
        CLIENT=`"$CERTOOL" -i --infile "$LIBVIRT/clientcert.pem" | grep Subject: | sed 's+.*CN=\(.[a-zA-Z \._-]*\).*+\1+'`
        echo Found client certificate $LIBVIRT/clientcert.pem for $CLIENT
        if [ ! -e "$LIBVIRTP/clientkey.pem" ]
        then
            echo Missing client private key $LIBVIRTP/clientkey.pem
        else
            echo Found client private key $LIBVIRTP/clientkey.pem
            OWN=`ls -l "$LIBVIRTP/clientkey.pem" | awk '{ print $3 }'`
            MOD=`ls -l "$LIBVIRTP/clientkey.pem" | awk '{ print $1 }'`
            if [ "$OWN" != "root" ]
            then
                echo The client private key should be owned by root
                echo "as root do: chown root $LIBVIRTP/clientkey.pem"
            fi
            if [ "$MOD" != "-rw-r--r--" ]
            then
                echo The client private key need to be read by client tools
                echo "as root do: chmod 644 $LIBVIRTP/clientkey.pem"
            fi
        fi

    fi
else
    echo Did not find "$LIBVIRT/clientcert.pem" client certificate
    echo The machine cannot act as a client
    echo "see http://libvirt.org/remote.html#Remote_TLS_client_certificates"
    echo on how to regenerate it
    CLIENT=0
fi

# Third the server certificates

if [ -f "$LIBVIRT/servercert.pem" ]
then
    if [ ! -r "$LIBVIRT/servercert.pem" ]
    then
        echo Server certificate $LIBVIRT/servercert.pem should be world readable
        echo "as root do: chown root:root $LIBVIRT/servercert.pem ; chmod 644 $LIBVIRT/servercert.pem"
    else
        S_ORG=`"$CERTOOL" -i --infile "$LIBVIRT/servercert.pem" | grep Subject: | sed 's+.*O=\([a-zA-Z\. _-]*\).*+\1+'`
        if [ "$ORG" != "$S_ORG" ]
        then
            echo The CA certificate and the server certificate do not match
            echo CA organization: $ORG
            echo Server organization: $S_ORG
        fi
        S_HOST=`"$CERTOOL" -i --infile "$LIBVIRT/servercert.pem" | grep Subject: | sed 's+.*CN=\([a-zA-Z\. _-]*\)+\1+'`
        if test "$S_HOST" != "`hostname -s`" && test "$S_HOST" != "`hostname`"
        then
            echo The server certificate does not seem to match the host name
            echo hostname: '"'`hostname`'"'
            echo Server certificate CN: '"'$S_HOST'"'
        fi
        echo Found server certificate $LIBVIRT/servercert.pem for $S_HOST
        if [ ! -e "$LIBVIRTP/serverkey.pem" ]
        then
            echo Missing server private key $LIBVIRTP/serverkey.pem
        else
            echo Found server private key $LIBVIRTP/serverkey.pem
            OWN=`ls -l "$LIBVIRTP/serverkey.pem" | awk '{ print $3 }'`
            MOD=`ls -l "$LIBVIRTP/serverkey.pem" | awk '{ print $1 }'`
            if [ "$OWN" != "root" ]
            then
                echo The server private key should be owned by root
                echo "as root do: chown root $LIBVIRTP/serverkey.pem"
            fi
            if [ "$MOD" != "-rw-------" ]
            then
                echo The server private key need to be read only by root
                echo "as root do: chmod 600 $LIBVIRTP/serverkey.pem"
            fi
        fi

    fi
else
    echo Did not find $LIBVIRT/servercert.pem server certificate
    echo The machine cannot act as a server
    echo "see http://libvirt.org/remote.html#Remote_TLS_server_certificates"
    echo on how to regenerate it
    SERVER=0
fi

if [ "$SERVER" = "1" ]
then
    if [ -r "$SYSCONFDIR"/sysconfig/libvirtd ]
    then
        if grep "^LIBVIRTD_ARGS.*--listen" "$SYSCONFDIR"/sysconfig/libvirtd \
            >/dev/null 2>&1
        then
            :
        else
            echo Make sure "$SYSCONFDIR"/sysconfig/libvirtd is setup to listen to
            echo TCP/IP connections and restart the libvirtd service
        fi
    fi
    if [ -r "$SYSCONFDIR"/sysconfig/iptables ]
    then
        if grep "$PORT" "$SYSCONFDIR"/sysconfig/iptables >/dev/null 2>&1
        then
            :
        else
            echo Make sure "$SYSCONFDIR"/sysconfig/iptables is setup to allow
            echo incoming TCP/IP connections on port $PORT and
            echo restart the iptables service
        fi
    fi
fi


exit 0

: <<=cut
=pod

=head1 NAME

  virt-pki-validate - validate libvirt PKI files are configured correctly

=head1 SYNOPSIS

  virt-pki-validate

=head1 DESCRIPTION

This tool validates that the necessary PKI files are configured for
a secure libvirt server or client using the TLS encryption protocol.
It will report any missing certificate or key files on the host. It
should be run as root to ensure it can read all the necessary files

=head1 EXIT STATUS

Upon successful validation, an exit status of 0 will be set. Upon
failure a non-zero status will be set.

=head1 AUTHOR

Richard Jones

=head1 BUGS

Report any bugs discovered to the libvirt community via the
mailing list C<http://libvirt.org/contact.html> or bug tracker C<http://libvirt.org/bugs.html>.
Alternatively report bugs to your software distributor / vendor.

=head1 COPYRIGHT

Copyright (C) 2006-2010 by Red Hat, Inc.

=head1 LICENSE

virt-pki-validate is distributed under the terms of the GNU GPL v2+.
This is free software; see the source for copying conditions. There
is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE

=head1 SEE ALSO

C<virsh(1)>, online PKI setup instructions C<http://libvirt.org/remote.html>

=cut