@@ -57,6 +57,77 @@ FreeBSD|NetBSD|Darwin)
;;
esac
+case $(uname -s) in
+MINGW*|MSYS*)
+ chmod()
+ {
+ local PERM=$1
+ local FILE=$2
+ local INH=
+
+ if test -d "${FILE}"; then
+ # Inheritance rules for folders: apply to a folder itself,
+ # subfolders and files within.
+ INH='(OI)(CI)'
+ fi
+
+ case "${PERM}" in
+ *700 | *600)
+ # Reset all own and inherited ACEs and grant full access to the
+ # "Creator Owner". We're giving full access even for 0600,
+ # because it doesn't matter for a use case of ovs-pki.
+ icacls "${FILE}" /inheritance:r /grant:r "*S-1-3-0:${INH}F"
+ ;;
+ *750)
+ # Reset all own and inherited ACEs, grant full access to the
+ # "Creator Owner" and a read+execute access to the "Creator Group".
+ icacls "${FILE}" /inheritance:r /grant:r \
+ "*S-1-3-0:${INH}F" "*S-1-3-1:${INH}RX"
+ ;;
+ *)
+ echo >&2 "Unable to set ${PERM} mode for ${FILE}."
+ exit 1
+ ;;
+ esac
+ }
+
+ mkdir()
+ {
+ ARG_P=
+ PERM=
+ for arg; do
+ shift
+ case ${arg} in
+ -m?*)
+ PERM=${arg#??}
+ continue
+ ;;
+ -m)
+ PERM=$1
+ shift
+ continue
+ ;;
+ -p)
+ ARG_P=-p
+ continue
+ ;;
+ *)
+ set -- "$@" "${arg}"
+ ;;
+ esac
+ done
+
+ command mkdir ${ARG_P} $@
+ if [ ${PERM} ]; then
+ for dir; do
+ shift
+ chmod ${PERM} ${dir}
+ done
+ fi
+ }
+ ;;
+esac
+
for option; do
# This option-parsing mechanism borrowed from a Autoconf-generated
# configure script under the following license:
@@ -466,14 +537,24 @@ CN = $cn
[ v3_req ]
subjectAltName = DNS:$cn
EOF
+ # It is important to create private keys in $TMP because umask doesn't
+ # work on Windows and permissions there are inherited from the folder.
+ # umask itself is still needed though to ensure correct permissions
+ # on non-Windows platforms.
if test $keytype = rsa; then
- (umask 077 && openssl genrsa -out "$1-privkey.pem" $bits) 1>&3 2>&3 \
- || exit $?
+ (umask 077 && openssl genrsa -out "$TMP/privkey.pem" $bits) \
+ 1>&3 2>&3 || exit $?
else
must_exist "$dsaparam"
- (umask 077 && openssl gendsa -out "$1-privkey.pem" "$dsaparam") \
+ (umask 077 && openssl gendsa -out "$TMP/privkey.pem" "$dsaparam") \
1>&3 2>&3 || exit $?
fi
+ # Windows: applying permissions (ACEs) to the file itself, just in case.
+ # 'mv' should technically preserve all the inherited ACEs from a TMP
+ # folder, but it's better to not rely on that.
+ chmod 0600 "$TMP/privkey.pem"
+ mv "$TMP/privkey.pem" "$1-privkey.pem"
+
openssl req -config "$TMP/req.cnf" -new -text \
-key "$1-privkey.pem" -out "$1-req.pem" 1>&3 2>&3
}