Skip to content

Instantly share code, notes, and snippets.

@jmcabandara
Forked from alfredodeza/generate.sh
Created September 3, 2021 17:16
Show Gist options
  • Select an option

  • Save jmcabandara/140b70e203485d0f6eab390e2d8cf95a to your computer and use it in GitHub Desktop.

Select an option

Save jmcabandara/140b70e203485d0f6eab390e2d8cf95a to your computer and use it in GitHub Desktop.

Revisions

  1. @alfredodeza alfredodeza created this gist Jul 14, 2016.
    44 changes: 44 additions & 0 deletions generate.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    #!/bin/bash
    # Easily generate a 10 year SSL certificate and key for development. It
    # creates a configuration file for wild card domains, if no argument is passed
    # in will fallback to "node.a" as the domain to use.
    #
    # Upon completion, these files should now exist::
    #
    # * openssl.cnf
    # * ssl.key
    # * ssl.crt
    #
    # If those files exist they will be overwritten


    set -e


    if [ ! -z $1 ]
    then
    domain=$1
    else
    domain="node.a"
    fi


    template="[req]
    distinguished_name = req_distinguished_name
    x509_extensions = v3_req
    prompt = no
    [req_distinguished_name]
    CN = *.${domain}
    [v3_req]
    keyUsage = keyEncipherment, dataEncipherment
    extendedKeyUsage = serverAuth
    subjectAltName = @alt_names
    [alt_names]
    DNS.1 = *.${domain}"

    echo "-> generating openssl.cnf configuration file"
    echo "$template" > openssl.cnf
    command="openssl req -new -newkey rsa:2048 -sha1 -days 3650 -nodes -x509 -keyout ssl.key -out ssl.crt -config openssl.cnf"
    echo "-> running: $command"
    openssl req -new -newkey rsa:2048 -sha1 -days 3650 -nodes -x509 -keyout ssl.key -out ssl.crt -config openssl.cnf
    echo "-> completed self signed certs"