X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=utilities%2Fovs-pki.in;h=0255251321e411a32f2cc7fcb4ac61821d1b2ea6;hb=4cf41591f33c9c2ca0ac288ffafd3be68d62f823;hp=b91d0614b3d396134862a4917b9b5d6e84aeb6d7;hpb=7cdc630f61b34dc4d54eb9fc0379dd18d0930a79;p=openvswitch diff --git a/utilities/ovs-pki.in b/utilities/ovs-pki.in index b91d0614..02552513 100755 --- a/utilities/ovs-pki.in +++ b/utilities/ovs-pki.in @@ -1,6 +1,6 @@ #! /bin/sh -# Copyright (c) 2008, 2009, 2010 Nicira Networks, Inc. +# Copyright (c) 2008, 2009, 2010, 2011 Nicira Networks, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -173,9 +173,18 @@ if test -z "$dsaparam"; then fi case $log in /*) ;; - *) $log="$PWD/$log" ;; + *) log="$PWD/$log" ;; esac +logdir=$(dirname "$log") +if test ! -d "$logdir"; then + mkdir -p -m755 "$logdir" 2>/dev/null || true + if test ! -d "$logdir"; then + echo "$0: log directory $logdir does not exist and cannot be created" >&2 + exit 1 + fi +fi + if test "$command" = "init"; then if test -e "$pkidir" && test "$force" != "yes"; then echo "$0: $pkidir already exists and --force not specified" >&2 @@ -352,7 +361,7 @@ fingerprint() { file=$1 name=${1-$2} date=$(date -r $file) - if grep -q -e '-BEGIN CERTIFICATE-' "$file"; then + if grep -e '-BEGIN CERTIFICATE-' "$file" > /dev/null; then fingerprint=$(openssl x509 -noout -in "$file" -fingerprint | sed 's/SHA1 Fingerprint=//' | tr -d ':') else @@ -451,13 +460,15 @@ OU = Open vSwitch certifier CN = Open vSwitch certificate for $arg1 EOF if test $keytype = rsa; then - newkey=rsa:$bits + (umask 077 && openssl genrsa -out "$1-privkey.pem" $bits) 1>&3 2>&3 \ + || exit $? else must_exist "$dsaparam" - newkey=dsa:$dsaparam + (umask 077 && openssl gendsa -out "$1-privkey.pem" "$dsaparam") \ + 1>&3 2>&3 || exit $? fi - openssl req -config "$TMP/req.cnf" -text -nodes \ - -newkey $newkey -keyout "$1-privkey.pem" -out "$1-req.pem" 1>&3 2>&3 + openssl req -config "$TMP/req.cnf" -new -text \ + -key "$1-privkey.pem" -out "$1-req.pem" 1>&3 2>&3 } sign_request() { @@ -515,8 +526,14 @@ elif test "$command" = self-sign; then must_exist "$arg1-privkey.pem" must_not_exist "$arg1-cert.pem" - openssl x509 -in "$arg1-req.pem" -out "$arg1-cert.pem" \ - -signkey "$arg1-privkey.pem" -req -text 2>&3 + # Create both the private key and certificate with restricted permissions. + (umask 077 && \ + openssl x509 -in "$arg1-req.pem" -out "$arg1-cert.pem.tmp" \ + -signkey "$arg1-privkey.pem" -req -text) 2>&3 || exit $? + + # Reset the permissions on the certificate to the user's default. + cat "$arg1-cert.pem.tmp" > "$arg1-cert.pem" + rm -f "$arg1-cert.pem.tmp" elif test "$command" = ls; then check_type "$arg2"