Commit f21f7202 authored by Lukas Schauer's avatar Lukas Schauer

Merge pull request #165 from bahamat/portability

Use of 'grep -o' doesn't work on SunOS (fixes #164)
parents bfeb21ad 4b8883b4
......@@ -25,7 +25,7 @@ check_dependencies() {
# just execute some dummy and/or version commands to see if required tools exist and are actually usable
openssl version > /dev/null 2>&1 || _exiterr "This script requires an openssl binary."
_sed "" < /dev/null > /dev/null 2>&1 || _exiterr "This script requires sed with support for extended (modern) regular expressions."
grep -V > /dev/null 2>&1 || _exiterr "This script requires grep."
command -v grep > /dev/null 2>&1 || _exiterr "This script requires grep."
mktemp -u -t XXXXXX > /dev/null 2>&1 || _exiterr "This script requires mktemp."
# curl returns with an error code in some ancient versions so we have to catch that
......@@ -160,7 +160,7 @@ init_system() {
openssl rsa -in "${PRIVATE_KEY}" -check 2>/dev/null > /dev/null || _exiterr "Private key is not valid, can not continue."
# Get public components from private key and calculate thumbprint
pubExponent64="$(openssl rsa -in "${PRIVATE_KEY}" -noout -text | grep publicExponent | grep -oE "0x[a-f0-9]+" | cut -d'x' -f2 | hex2bin | urlbase64)"
pubExponent64="$(printf '%x' $(openssl rsa -in "${PRIVATE_KEY}" -noout -text | awk '/publicExponent/ {print $2}') | hex2bin | urlbase64)"
pubMod64="$(openssl rsa -in "${PRIVATE_KEY}" -noout -modulus | cut -d'=' -f2 | hex2bin | urlbase64)"
thumbprint="$(printf '{"e":"%s","kty":"RSA","n":"%s"}' "${pubExponent64}" "${pubMod64}" | openssl dgst -sha256 -binary | urlbase64)"
......@@ -211,7 +211,8 @@ hex2bin() {
# Get string value from json dictionary
get_json_string_value() {
grep -Eo '"'"${1}"'":[[:space:]]*"[^"]*"' | cut -d'"' -f4
local filter=$(printf 's/.*"%s": *"\([^"]*\)".*/\\1/p' "$1")
sed -n "$filter"
}
# OpenSSL writes to stderr/stdout even when there are no errors. So just
......@@ -363,7 +364,7 @@ sign_csr() {
echo " + Requesting challenge for ${altname}..."
response="$(signed_request "${CA_NEW_AUTHZ}" '{"resource": "new-authz", "identifier": {"type": "dns", "value": "'"${altname}"'"}}')"
challenges="$(printf '%s\n' "${response}" | grep -Eo '"challenges":[^\[]*\[[^]]*]')"
challenges="$(printf '%s\n' "${response}" | sed -n 's/.*\("challenges":[^\[]*\[[^]]*]\).*/\1/p')"
repl=$'\n''{' # fix syntax highlighting in Vim
challenge="$(printf "%s" "${challenges//\{/${repl}}" | grep \""${CHALLENGETYPE}"\")"
challenge_token="$(printf '%s' "${challenge}" | get_json_string_value token | _sed 's/[^A-Za-z0-9_\-]/_/g')"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment