]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
ast_tls_cert: Make certificate validity configurable.
authorNaveen Albert <asterisk@phreaknet.org>
Wed, 16 Jul 2025 13:06:35 +0000 (09:06 -0400)
committergithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Tue, 22 Jul 2025 13:20:20 +0000 (13:20 +0000)
Currently, the ast_tls_cert script is hardcoded to produce certificates
with a validity of 365 days, which is not generally desirable for self-
signed certificates. Make this parameter configurable.

Resolves: #1307

contrib/scripts/ast_tls_cert

index e2003554d6c5b2920728ecb9189615992895c6b7..e8bf3de276686b67c462a52679d1fb9b415a9408 100755 (executable)
@@ -4,6 +4,7 @@ DEFAULT_CA_CN="Asterisk Private CA"
 DEFAULT_CLIENT_CN="asterisk"
 DEFAULT_SERVER_CN=`hostname -f`
 CA_ENCRYPTION_OPT="-des3"
+VALIDITY_DAYS=365
 
 # arguments
 # $1 "ca" if we are to generate a CA cert
@@ -39,7 +40,7 @@ create_ca () {
                exit 1
        fi
        echo "Creating CA certificate ${CACERT}"
-       openssl req -new -config ${CACFG} -x509 -days 365 -key ${CAKEY} -out ${CACERT} > /dev/null
+       openssl req -new -config ${CACFG} -x509 -days ${VALIDITY_DAYS} -key ${CAKEY} -out ${CACERT} > /dev/null
        if [ $? -ne 0 ];
        then
                echo "Failed"
@@ -64,7 +65,7 @@ create_cert () {
                exit 1
        fi
        echo "Creating certificate ${base}.crt"
-       openssl x509 -req -days 365 -in ${base}.csr -CA ${CACERT} -CAkey ${CAKEY} -set_serial 01 -out ${base}.crt > /dev/null
+       openssl x509 -req -days ${VALIDITY_DAYS} -in ${base}.csr -CA ${CACERT} -CAkey ${CAKEY} -set_serial 01 -out ${base}.crt > /dev/null
        if [ $? -ne 0 ];
        then
                echo "Failed"
@@ -98,6 +99,7 @@ OPTIONS:
         An informational string (company name)
   -o  Output filename base (defaults to asterisk)
   -d  Output directory (defaults to the current directory)
+  -v  CA/certificate validity in days (defaults to 365)
 
 Example:
 
@@ -131,7 +133,7 @@ OUTPUT_BASE=asterisk # Our default cert basename
 CERT_MODE=server
 ORG_NAME=${DEFAULT_ORG}
 
-while getopts "hf:c:ek:o:d:m:C:O:b:" OPTION
+while getopts "hf:c:ek:o:d:m:C:O:b:v:" OPTION
 do
        case ${OPTION} in
                h)
@@ -153,6 +155,9 @@ do
                b)
                        KEYBITS=${OPTARG}
                        ;;
+               v)
+                       VALIDITY_DAYS=${OPTARG}
+                       ;;
                o)
                        OUTPUT_BASE=${OPTARG}
                        ;;