mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-04-15 16:39:14 +00:00
FS-3777: --resolve
This commit is contained in:
parent
883de14f30
commit
faf40311c6
@ -1,7 +1,8 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
CONFDIR=@prefix@/conf/ssl
|
CONFDIR=@prefix@/conf/ssl
|
||||||
DAYS=365
|
DAYS=2190
|
||||||
|
KEY_SIZE=2048
|
||||||
|
|
||||||
TMPFILE="/tmp/fs-ca-$$-$(date +%Y%m%d%H%M%S)"
|
TMPFILE="/tmp/fs-ca-$$-$(date +%Y%m%d%H%M%S)"
|
||||||
|
|
||||||
@ -38,7 +39,7 @@ setup_ca() {
|
|||||||
if [ ! -e "${CONFDIR}/CA/config.tpl" ]; then
|
if [ ! -e "${CONFDIR}/CA/config.tpl" ]; then
|
||||||
cat > "${CONFDIR}/CA/config.tpl" <<-EOF
|
cat > "${CONFDIR}/CA/config.tpl" <<-EOF
|
||||||
[ req ]
|
[ req ]
|
||||||
default_bits = 1024
|
default_bits = $ENV::KEY_SIZE
|
||||||
prompt = no
|
prompt = no
|
||||||
distinguished_name = req_dn
|
distinguished_name = req_dn
|
||||||
|
|
||||||
@ -46,11 +47,23 @@ setup_ca() {
|
|||||||
commonName = %CN%
|
commonName = %CN%
|
||||||
organizationName = %ORG%
|
organizationName = %ORG%
|
||||||
|
|
||||||
[ ext ]
|
[ server ]
|
||||||
|
nsComment="FS Server Cert"
|
||||||
basicConstraints=CA:FALSE
|
basicConstraints=CA:FALSE
|
||||||
subjectKeyIdentifier=hash
|
subjectKeyIdentifier=hash
|
||||||
authorityKeyIdentifier=keyid,issuer:always
|
authorityKeyIdentifier=keyid,issuer:always
|
||||||
subjectAltName=%ALTNAME%
|
subjectAltName=%ALTNAME%
|
||||||
|
nsCertType=server
|
||||||
|
extendedKeyUsage=serverAuth
|
||||||
|
|
||||||
|
[ client ]
|
||||||
|
nsComment="FS Client Cert"
|
||||||
|
basicConstraints=CA:FALSE
|
||||||
|
subjectKeyIdentifier=hash
|
||||||
|
authorityKeyIdentifier=keyid,issuer:always
|
||||||
|
subjectAltName=%ALTNAME%
|
||||||
|
nsCertType=client
|
||||||
|
extendedKeyUsage=clientAuth
|
||||||
EOF
|
EOF
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -62,14 +75,10 @@ setup_ca() {
|
|||||||
"${CONFDIR}/CA/config.tpl" \
|
"${CONFDIR}/CA/config.tpl" \
|
||||||
> "${TMPFILE}.cfg" || exit 1
|
> "${TMPFILE}.cfg" || exit 1
|
||||||
|
|
||||||
openssl req -new -out "${CONFDIR}/CA/careq.pem" \
|
openssl req -out "${CONFDIR}/CA/cacert.pem" \
|
||||||
-newkey rsa:1024 -keyout "${CONFDIR}/CA/cakey.pem" \
|
-new -x509 -keyout "${CONFDIR}/CA/cakey.pem" \
|
||||||
-config "${TMPFILE}.cfg" -nodes -sha1 >/dev/null || exit 1
|
-config "${TMPFILE}.cfg" -nodes -sha1 >/dev/null || exit 1
|
||||||
|
cat "${CONFDIR}/CA/cacert.pem" > "${CONFDIR}/cafile.pem"
|
||||||
openssl x509 -req -signkey "${CONFDIR}/CA/cakey.pem" -in "${CONFDIR}/CA/careq.pem" \
|
|
||||||
-out "${CONFDIR}/CA/cacert.pem" -extfile "${TMPFILE}.cfg" \
|
|
||||||
-extensions ext -days ${DAYS} -sha1 >/dev/null || exit 1
|
|
||||||
|
|
||||||
rm "${TMPFILE}.cfg"
|
rm "${TMPFILE}.cfg"
|
||||||
|
|
||||||
echo "DONE"
|
echo "DONE"
|
||||||
@ -108,14 +117,13 @@ generate_cert() {
|
|||||||
> "${TMPFILE}.cfg" || exit 1
|
> "${TMPFILE}.cfg" || exit 1
|
||||||
|
|
||||||
openssl req -new -out "${TMPFILE}.req" \
|
openssl req -new -out "${TMPFILE}.req" \
|
||||||
-newkey rsa:1024 -keyout "${TMPFILE}.key" \
|
-newkey rsa: -keyout "${TMPFILE}.key" \
|
||||||
-config "${TMPFILE}.cfg" -nodes -sha1 >/dev/null || exit 1
|
-config "${TMPFILE}.cfg" -nodes -sha1 >/dev/null || exit 1
|
||||||
|
|
||||||
openssl x509 -req -CAkey "${CONFDIR}/CA/cakey.pem" -CA "${CONFDIR}/CA/cacert.pem" -CAcreateserial \
|
openssl x509 -req -CAkey "${CONFDIR}/CA/cakey.pem" -CA "${CONFDIR}/CA/cacert.pem" -CAcreateserial \
|
||||||
-in "${TMPFILE}.req" -out "${TMPFILE}.crt" -extfile "${TMPFILE}.cfg" \
|
-in "${TMPFILE}.req" -out "${TMPFILE}.crt" -extfile "${TMPFILE}.cfg" \
|
||||||
-extensions ext -days ${DAYS} -sha1 >/dev/null || exit 1
|
-extensions "${EXTENSIONS}" -days ${DAYS} -sha1 >/dev/null || exit 1
|
||||||
|
|
||||||
cat "${CONFDIR}/CA/cacert.pem" > "${CONFDIR}/cafile.pem"
|
|
||||||
cat "${TMPFILE}.crt" "${TMPFILE}.key" > "${CONFDIR}/${OUTFILE}"
|
cat "${TMPFILE}.crt" "${TMPFILE}.key" > "${CONFDIR}/${OUTFILE}"
|
||||||
|
|
||||||
rm "${TMPFILE}.cfg" "${TMPFILE}.crt" "${TMPFILE}.key" "${TMPFILE}.req"
|
rm "${TMPFILE}.cfg" "${TMPFILE}.crt" "${TMPFILE}.key" "${TMPFILE}.req"
|
||||||
@ -133,7 +141,7 @@ remove_ca() {
|
|||||||
|
|
||||||
echo "DONE"
|
echo "DONE"
|
||||||
}
|
}
|
||||||
|
OUTFILESET="0"
|
||||||
command="$1"
|
command="$1"
|
||||||
shift
|
shift
|
||||||
|
|
||||||
@ -154,6 +162,7 @@ while [ $# -gt 0 ]; do
|
|||||||
-out)
|
-out)
|
||||||
shift
|
shift
|
||||||
OUTFILE="$1"
|
OUTFILE="$1"
|
||||||
|
OUTFILESET="1"
|
||||||
;;
|
;;
|
||||||
-days)
|
-days)
|
||||||
shift
|
shift
|
||||||
@ -170,6 +179,18 @@ case ${command} in
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
create)
|
create)
|
||||||
|
EXTENSIONS="server"
|
||||||
|
generate_cert
|
||||||
|
;;
|
||||||
|
create_server)
|
||||||
|
EXTENSIONS="server"
|
||||||
|
generate_cert
|
||||||
|
;;
|
||||||
|
create_client)
|
||||||
|
EXTENSIONS="client"
|
||||||
|
if [ "${OUTFILESET}" = "0" ]; then
|
||||||
|
OUTFILE="client.pem"
|
||||||
|
fi
|
||||||
generate_cert
|
generate_cert
|
||||||
;;
|
;;
|
||||||
|
|
||||||
@ -185,15 +206,15 @@ case ${command} in
|
|||||||
|
|
||||||
*)
|
*)
|
||||||
cat <<-EOF
|
cat <<-EOF
|
||||||
$0 <setup|create|clean> [options]
|
$0 <setup|create_server|create_client|clean> [options]
|
||||||
|
|
||||||
* commands:
|
* commands:
|
||||||
|
|
||||||
setup - Setup new CA
|
setup - Setup new CA
|
||||||
remove - Remove CA
|
remove - Remove CA
|
||||||
|
|
||||||
create - Create new certificate (overwriting old!)
|
create_server - Create new certificate (overwriting existing!)
|
||||||
|
create_client - Create a new client certificate (overwrites existing!)
|
||||||
|
|
||||||
* options:
|
* options:
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user