postinst is in openvas-server 2.0.3-6.
This file is a maintainer script. It is executed when installing (*inst) or removing (*rm) the package.
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 325 326 327 328 329 330 331 332 333 | #! /bin/bash
# Postinst script for OpenVAS, written by Javier Fernandez-Sanguino
# Uses code from openvas-mkcert, which was written by Renaud Deraison
# <deraison@cvs.nessus.org> and Michel Arboi <arboi@alussinan.org>
#
# This script is distributed under the Gnu General Public License (GPL)
#
set -e
. /usr/share/debconf/confmodule
test $DEBIAN_SCRIPT_DEBUG && set -v -x
# Location of the certificates
OPENVASPRIV="/var/lib/openvas/private/CA"
OPENVASPUB="/var/lib/openvas/CA"
CAKEY=$OPENVASPRIV/cakey.pem
CACERT=$OPENVASPUB/cacert.pem
#
SRVKEY=$OPENVASPRIV/serverkey.pem
SRVCERT=$OPENVASPUB/servercert.pem
# Our umask for all files
umask 077
openvas_mkcert ()
{
RANDFLAG=""
PATH=/usr/sbin:/usr/bin:/bin:/sbin
if [ ! -d "$OPENVASPRIV" ]; then
mkdir -p "$OPENVASPRIV"
chmod 0700 "$OPENVASPRIV"
echo "$OPENVASPRIV created"
fi
if [ ! -d "$OPENVASPUB" ]; then
mkdir -p "$OPENVASPUB"
chmod a+rx "$OPENVASPUB"
echo "$OPENVASPUB created"
fi
# Set environment
BASEDIR=`mktemp -d -t openvas-mkcert.XXXXXX` || { echo "$program: Cannot create temporary dir!" >&2 ; exit 1; }
trap " [ -d \"$BASEDIR\" ] && rm -rf -- \"$BASEDIR\"" 0 1 2 3 13 15
SRVREQ=$BASEDIR/serverreq.pem
# Defaults
[ -n "$CACERT_LIFETIME" ] && CACERT_LIFETIME=1460
[ -n "$SRVCERT_LIFETIME" ] && SRVCERT_LIFETIME=365
if [ ! -z "$LANG" ]; then
DC=`echo $LANG | sed -n 's/^..*_\(..\).*$/\1/p'`
fi
[ -z "$DC" ] && DC="??"
[ -z "$COUNTRY" ] && COUNTRY=$DC
[ -z "$PROVINCE" ] && PROVINCE=""
[ -z "$LOCATION" ] && LOCATION=""
[ -z "$ORGANIZATION" ] && ORGANIZATION="OpenVAS"
cat <<EOF>$BASEDIR/std000.cnf
RANDFILE = $HOME/.rnd
#
[ ca ]
default_ca = OpenVASCA
[ OpenVASCA ]
dir = $BASEDIR # Where everything is kept
certs = \$dir # Where the issued certs are kept
crl_dir = \$dir # Where the issued crl are kept
database = \$dir/index.txt # database index file.
new_certs_dir = \$dir # default place for new certs.
certificate = $CACERT # The CA certificate
serial = \$dir/serial # The current serial number
crl = \$dir/crl.pem # The current CRL
private_key = $CAKEY # The private key
x509_extensions = usr_cert # The extentions to add to the cert
crl_extensions = crl_ext
default_days = 365 # how long to certify for
default_crl_days= 30 # how long before next CRL
default_md = md5 # which md to use.
preserve = no # keep passed DN ordering
policy = policy_anything
[ policy_anything ]
countryName = optional
stateOrProvinceName = optional
localityName = optional
organizationName = optional
organizationalUnitName = optional
commonName = supplied
emailAddress = optional
[ req ]
default_bits = 1024
distinguished_name = req_distinguished_name
# attributes = req_attributes
x509_extensions = v3_ca # The extentions to add to the self signed cert
[ req_distinguished_name ]
countryName = Country Name (2 letter code)
countryName_default = FR
countryName_min = 2
countryName_max = 2
stateOrProvinceName = State or Province Name (full name)
stateOrProvinceName_default = Some-State
localityName = Locality Name (eg, city)
0.organizationName = Organization Name (eg, company)
0.organizationName_default = Internet Widgits Pty Ltd
# we can do this but it is not needed normally :-)
#1.organizationName = Second Organization Name (eg, company)
#1.organizationName_default = World Wide Web Pty Ltd
organizationalUnitName = Organizational Unit Name (eg, section)
#organizationalUnitName_default =
commonName = Common Name (eg, your name or your server\'s hostname)
commonName_max = 255
emailAddress = Email Address
emailAddress_max = 255
# SET-ex3 = SET extension number 3
[ usr_cert ]
# These extensions are added when 'ca' signs a request.
# This goes against PKIX guidelines but some CAs do it and some software
# requires this to avoid interpreting an end user certificate as a CA.
#basicConstraints=CA:FALSE
# Here are some examples of the usage of nsCertType. If it is omitted
# the certificate can be used for anything *except* object signing.
# This is OK for an SSL server.
# nsCertType = nsCertType
# For normal client use this is typical
# nsCertType = client, email
nsCertType = NSCERTTYPE
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
# This will be displayed in Netscape's comment listbox.
nsComment = "OpenSSL Generated Certificate"
# PKIX recommendations harmless if included in all certificates.
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid,issuer:always
# This stuff is for subjectAltName and issuerAltname.
# Import the email address.
subjectAltName=email:copy
# Copy subject details
issuerAltName=issuer:copy
#nsCaRevocationUrl = http://www.domain.dom/ca-crl.pem
#nsBaseUrl
#nsRevocationUrl
#nsRenewalUrl
#nsCaPolicyUrl
#nsSslServerName
[ v3_ca ]
# PKIX recommendation.
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid:always,issuer:always
# This is what PKIX recommends but some broken software chokes on critical
# extensions.
basicConstraints = critical,CA:true
# So we do this instead.
#basicConstraints = CA:true
# Key usage: this is typical for a CA certificate. However since it will
# prevent it being used as an test self-signed certificate it is best
# left out by default.
keyUsage = cRLSign, keyCertSign
nsCertType = sslCA
EOF
#####
sed 's/NSCERTTYPE/server/g' < $BASEDIR/std000.cnf > $BASEDIR/std.cnf
sed 's/NSCERTTYPE/client/g' < $BASEDIR/std000.cnf > $BASEDIR/stdC.cnf
hostname=`hostname`
if [ -z "$hostname" ];
then
echo "An error occured while trying to determine hostname !"
exit 1
fi
# The value for organizationalUnitName must be 64 chars or less;
# thus, hostname must be 36 chars or less. If it's too big,
# try removing domain.
hostname_len=`echo $hostname| wc -c`
if [ $hostname_len -gt 36 ];
then
hostname=`echo $hostname | cut -d '.' -f 1`
fi
CAMAIL=ca@$hostname
#cln CLNMAIL=openvas@$hostname
SRVMAIL=openvasd@$hostname
#
# Create the root CA
#
echo 01 > $BASEDIR/serial
touch $BASEDIR/index.txt
openssl genrsa $RANDFLAG -out $CAKEY 1024 2> $BASEDIR/openssl-log
echo "$COUNTRY
$PROVINCE
$LOCATION
$ORGANIZATION
Certification Authority for $hostname
$hostname
$CAMAIL" |
openssl req -config $BASEDIR/std.cnf -new -x509 -days $CACERT_LIFETIME -key $CAKEY -out $CACERT 2>> $BASEDIR/openssl-log
# Server key
openssl genrsa $RANDFLAG -out $SRVKEY 1024 2>> $BASEDIR/openssl-log
# Server certificate "request"
echo "$COUNTRY
$PROVINCE
$LOCATION
$ORGANIZATION
Server certificate for $hostname
$hostname
$SRVMAIL" |
openssl req -config $BASEDIR/std.cnf -new -key $SRVKEY -out $SRVREQ 2>> $BASEDIR/openssl-log
# Sign the server certificate
openssl ca -config $BASEDIR/std.cnf -name OpenVASCA -batch -days $SRVCERT_LIFETIME -in $SRVREQ -out $SRVCERT 2>> $BASEDIR/openssl-log
chmod a+r $CACERT $SRVCERT #cln $CLNCERT
if [ -s "$CACERT" ] && [ -s "$CAKEY" ] && [ -s "$SRVCERT" ] && [ -s "$SRVKEY" ];
then
echo "Congratulations. Your server certificate was properly created."
echo "The following files were created : "
echo
echo ". Certification authority : "
echo " Certificate = $CACERT"
echo " Private key = $CAKEY"
echo
echo ". OpenVAS Server : "
echo " Certificate = $SRVCERT"
echo " Private key = $SRVKEY"
return 0
else
echo "ERROR: An error occured while generating the certificates and/or keys !"
return 1
fi
}
openvas_mkcert_add ()
{
CF=/etc/openvas/openvasd.conf
if [ -s "$CACERT" ] && [ -s "$CAKEY" ] && [ -s "$SRVCERT" ] && [ -s "$SRVKEY" ];
then
egrep -v '^ *(pem_password|cert_file|key_file|ca_file|force_pubkey_auth) *=' "$CF" > "$CF.tmp"
echo "#
# Added by openvas-mkcert
#
cert_file=$SRVCERT
key_file=$SRVKEY
ca_file=$CACERT
# If you decide to protect your private key with a password,
# uncomment and change next line
# pem_password=password
# If you want to force the use of a client certificate, uncomment next line
# force_pubkey_auth = yes" >> "$CF.tmp"
mv -f "$CF.tmp" "$CF"
echo "$CF updated to use the server's certificate / keys"
return 0
else
echo "ERROR: Cannot find server certificate and/or keys !"
return 1
fi
}
if [ "$1" = "configure" ]; then
if [ ! -f /var/lib/openvas/CA/cacert.pem ] || [ ! -f /var/lib/openvas/CA/servercert.pem ]; then
db_get openvas-server/califetime || true; CACERT_LIFETIME="$RET"
db_get openvas-server/srvlifetime || true; SRVCERT_LIFETIME="$RET"
db_get openvas-server/country || true; COUNTRY="$RET"
db_get openvas-server/province || true; PROVINCE="$RET"
db_get openvas-server/location || true; LOCATION="$RET"
db_get openvas-server/organization || true; ORGANIZATION="$RET"
export CACERT_LIFETIME SRVCERT_LIFETIME COUNTRY PROVINCE
export LOCATION ORGANIZATION
openvas_mkcert
fi
# Check if the CA files exist but the openvasd.conf does not have the ca_file
# definition. This happens when the package is first installed but also if the
# configuration file gets overwrriten (because the user 'upgrades' the conffiles)
if [ -s /var/lib/openvas/CA/cacert.pem ] && [ -s /var/lib/openvas/CA/servercert.pem ] \
&& ! grep -q ^ca_file /etc/openvas/openvasd.conf ; then
openvas_mkcert_add
fi
# Restart the OpenVAS daemon if running
if [ -x /etc/init.d/openvas-server ] && \
/etc/init.d/openvas-server status 2>&1 >/dev/null; then
if which invoke-rc.d >/dev/null 2>&1; then
invoke-rc.d openvas-server restart
else
/etc/init.d/openvas-server restart
fi
fi
fi
# We don't let dh_installinit touch this so we do it byhand
update-rc.d openvas-server stop 20 0 6 . >/dev/null
|