X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=utilities%2Fovs-pki.in;h=0255251321e411a32f2cc7fcb4ac61821d1b2ea6;hb=19993ef3caac9964c2bef6e31fc8699c4f4b53c8;hp=22b5f2a0c8a72c398becb39508921be0b581badd;hpb=496d0fe53648c34b1fbcce008314c6bbf1582ee2;p=sliver-openvswitch.git diff --git a/utilities/ovs-pki.in b/utilities/ovs-pki.in index 22b5f2a0c..025525132 100755 --- a/utilities/ovs-pki.in +++ b/utilities/ovs-pki.in @@ -1,6 +1,6 @@ #! /bin/sh -# Copyright (c) 2008, 2009 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. @@ -161,11 +161,11 @@ if test -z "$command"; then exit 1 fi if test "$keytype" != rsa && test "$keytype" != dsa; then - echo "$0: argument to -k or --key must be rsa or dsa" + echo "$0: argument to -k or --key must be rsa or dsa" >&2 exit 1 fi if test "$bits" -lt 1024; then - echo "$0: argument to -B or --bits must be at least 1024" + echo "$0: argument to -B or --bits must be at least 1024" >&2 exit 1 fi if test -z "$dsaparam"; then @@ -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 @@ -249,6 +258,7 @@ email_in_dn = no # Don't add the email into cert DN name_opt = ca_default # Subject name display option cert_opt = ca_default # Certificate display option copy_extensions = none # Don't copy extensions from request +unique_subject = no # Allow certs with duplicate subjects # For the CA policy [ policy ] @@ -271,7 +281,7 @@ EOF -newkey $newkey -keyout private/cakey.pem -out careq.pem \ 1>&3 2>&3 openssl ca -config ca.cnf -create_serial -out cacert.pem \ - -days 1095 -batch -keyfile private/cakey.pem -selfsign \ + -days 2191 -batch -keyfile private/cakey.pem -selfsign \ -infiles careq.pem 1>&3 2>&3 chmod 0700 private/cakey.pem @@ -315,7 +325,7 @@ resolve_prefix() { ????*) ;; *) - echo "Prefix $arg1 is too short (less than 4 hex digits)" + echo "Prefix $arg1 is too short (less than 4 hex digits)" >&2 exit 0 ;; esac @@ -323,13 +333,13 @@ resolve_prefix() { fingerprint=$(cd "$pkidir/${type}ca/incoming" && echo "$1"*-req.pem | sed 's/-req\.pem$//') case $fingerprint in "${1}*") - echo "No certificate requests matching $1" + echo "No certificate requests matching $1" >&2 exit 1 ;; *" "*) - echo "$1 matches more than one certificate request:" + echo "$1 matches more than one certificate request:" >&2 echo $fingerprint | sed 's/ /\ -/g' +/g' >&2 exit 1 ;; *) @@ -348,11 +358,10 @@ make_tmpdir() { } fingerprint() { - local file=$1 - local name=${1-$2} - local date=$(date -r $file) - local fingerprint - if grep -q -e '-BEGIN CERTIFICATE-' "$file"; then + file=$1 + name=${1-$2} + date=$(date -r $file) + 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() { @@ -472,7 +483,7 @@ sign_request() { } glob() { - local files=$(echo $1) + files=$(echo $1) if test "$files" != "$1"; then echo "$files" fi @@ -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"