Advertisement
fruffl

CA certificate chain factory

Nov 12th, 2015
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 67.91 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. export SCRIPT_PATH=$( cd "$(dirname "${BASH_SOURCE}")" ; pwd -P )
  4.  
  5.  
  6. # debug
  7. #rm -rf $SCRIPT_PATH/$DEFAULT_DOMAIN/* > /dev/null 2>&1
  8. #find $SCRIPT_PATH/$DEFAULT_DOMAIN/ -name "*.crt" -type f|xargs rm -f
  9.  
  10. ##
  11. # Create a simple CA-chain with openssl.
  12. #
  13. # Source: http://pki-tutorial.readthedocs.org/en/latest/advanced/index.html
  14. #
  15. # We create the Root CA based on reverse host. The Root CA signs the TLS CA for the reverse host and intermediate CAs for each domain.
  16. # The intermediate CAs are signing the Email CA, TLS CA, the Software (Code Signing) CA for the domain; it signs also the Intermediate CA for each subdomain.
  17. #
  18. # ---
  19. # #!/bin bash
  20. # root_ca 'reverse.com' 'domain1.com;domain2.com' 'sub1;sub2'
  21. # root_ca 'reverse.com' 'domain1.com' 'sub3'
  22. # root_ca 'reverse.com' 'domain2.com' 'sub4'
  23. # root_ca 'reverse.com' 'domain3.com'
  24. # ---
  25. # result
  26. #   - ./reverse.com
  27. #       - reverse.com.ca.crt (root CA)
  28. #       - reverse.com.ca-tls.crt
  29. #       - ./intermediate
  30. #           - ./domain1.com
  31. #               - domain1.com.ca.crt (sub root CA)
  32. #               - domain1.com.ca-tls.crt
  33. #               - domain1.com.ca-email.crt
  34. #               - domain1.com.ca-software.crt
  35. #               - ./intermediate
  36. #                   - ./sub1.domain1.com
  37. #                       - sub1.domain1.com.ca.crt (sub sub root CA)
  38. #                       - sub1.domain1.com.ca-tls.crt
  39. #                       - sub1.domain1.com.ca-email.crt
  40. #                       - sub1.domain1.com.ca-software.crt
  41. #                   - ./sub2.domain1.com
  42. #                       - sub2.domain1.com.ca.crt (sub sub root CA)
  43. #                       - sub2.domain1.com.ca-tls.crt
  44. #                       - sub2.domain1.com.ca-email.crt
  45. #                       - sub2.domain1.com.ca-software.crt
  46. #                   - ./sub3.domain1.com
  47. #                       - sub3.domain1.com.ca.crt (sub sub root CA)
  48. #                       - sub3.domain1.com.ca-tls.crt
  49. #                       - sub3.domain1.com.ca-email.crt
  50. #                       - sub3.domain1.com.ca-software.crt
  51. #           - ./domain2.com
  52. #               - domain2.com.ca.crt (sub root CA)
  53. #               - domain2.com.ca-tls.crt
  54. #               - domain2.com.ca-email.crt
  55. #               - domain2.com.ca-software.crt
  56. #               - ./intermediate
  57. #                   - ./sub1.domain1.com
  58. #                       - sub1.domain2.com.ca.crt (sub sub root CA)
  59. #                       - sub1.domain2.com.ca-tls.crt
  60. #                       - sub1.domain2.com.ca-email.crt
  61. #                       - sub1.domain2.com.ca-software.crt
  62. #                   - ./sub2.domain1.com
  63. #                       - sub2.domain2.com.ca.crt (sub sub root CA)
  64. #                       - sub2.domain2.com.ca-tls.crt
  65. #                       - sub2.domain2.com.ca-email.crt
  66. #                       - sub2.domain2.com.ca-software.crt
  67. #                   - ./sub4.domain1.com
  68. #                       - sub4.domain2.com.ca.crt (sub sub root CA)
  69. #                       - sub4.domain2.com.ca-tls.crt
  70. #                       - sub4.domain2.com.ca-email.crt
  71. #                       - sub4.domain2.com.ca-software.crt
  72. #           - ./domain3.com
  73. #               - domain3.com.ca.crt (sub root CA)
  74. #               - domain3.com.ca-tls.crt
  75. #               - domain3.com.ca-email.crt
  76. #               - domain3.com.ca-software.crt
  77. #
  78. #
  79. # ---
  80. # add mini lookup
  81. root_ca()
  82. {
  83.  
  84.     #local DEFAULT_CA_RSA_KEYSIZE_PASSWORD=8192
  85.     #local DEFAULT_CA_RSA_KEYSIZE_PRIVATE_KEY=8192
  86.     #local DEFAULT_CA_RSA_KEYSIZE_REQUEST=4096
  87.    
  88.     local DEFAULT_CA_RSA_KEYSIZE_PASSWORD=2048
  89.     local DEFAULT_CA_RSA_KEYSIZE_PRIVATE_KEY=2048
  90.     local DEFAULT_CA_RSA_KEYSIZE_REQUEST=2048
  91.    
  92.     local DEFAULT_CA_PWD_GEN_PUBEXP=7
  93.     local DEFAULT_CA_MD=sha512
  94.     local DEFAULT_CA_MD_REQUEST=sha512
  95.    
  96.     ##############################################################
  97.     #
  98.     # constants
  99.     #
  100.     ##############################################################
  101.    
  102.     declare -A DIR_NAME
  103.     DIR_NAME[cnf]='etc'
  104.     DIR_NAME[db]='db'
  105.     DIR_NAME[private]='private'
  106.     DIR_NAME[public]='public'
  107.     DIR_NAME[intermediateDir]='intermediate'
  108.     DIR_NAME[lookup]='lookup'
  109.     DIR_NAME[caRoot]='ca'
  110.     DIR_NAME[caEmail]='ca-email'
  111.     DIR_NAME[caSoftware]='ca-software'
  112.     DIR_NAME[caTls]='ca-tls'
  113.     DIR_NAME[crtEmail]='crt-email'
  114.     DIR_NAME[crtSoftware]='crt-software'
  115.     DIR_NAME[crtTls]='crt-tls'
  116.     DIR_NAME[email]='email'
  117.     DIR_NAME[software]='software'
  118.     DIR_NAME[tls]='tls'
  119.    
  120.     declare -A FILE_NAME
  121.     FILE_NAME[cnf]='%s.%s.cnf'
  122.     FILE_NAME[csr]='%s.%s.csr'
  123.     FILE_NAME[crt]='%s.%s.crt'
  124.     FILE_NAME[chainPem]='%s.%s.chain.pem'
  125.     FILE_NAME[crtDb]='%s.%s.crt.db'
  126.     FILE_NAME[crtSrl]='%s.%s.crt.srl'
  127.     FILE_NAME[crl]='%s.%s.crl'
  128.     FILE_NAME[crlPem]='%s.%s.crl.pem'
  129.     FILE_NAME[crlSrl]='%s.%s.crl.srl'
  130.     FILE_NAME[key]='%s.%s.key'
  131.     FILE_NAME[password]='%s.%s.pwd'
  132.    
  133.     declare -A DIRECTORIES_CA_ROOT
  134.     DIRECTORIES_CA_ROOT[caPath]="${DIR_NAME[caRoot]}"
  135.     DIRECTORIES_CA_ROOT[dbPath]="${DIR_NAME[caRoot]}/${DIR_NAME[db]}"
  136.     DIRECTORIES_CA_ROOT[cnfPath]="${DIR_NAME[caRoot]}/${DIR_NAME[cnf]}"
  137.     DIRECTORIES_CA_ROOT[privatePath]="${DIR_NAME[caRoot]}/${DIR_NAME[private]}"
  138.    
  139.     declare -A DIRECTORIES_CA_EMAIL
  140.     DIRECTORIES_CA_EMAIL[caPath]="${DIR_NAME[caEmail]}"
  141.     DIRECTORIES_CA_EMAIL[dbPath]="${DIR_NAME[caEmail]}/${DIR_NAME[db]}"
  142.     DIRECTORIES_CA_EMAIL[cnfPath]="${DIR_NAME[caEmail]}/${DIR_NAME[cnf]}"
  143.     DIRECTORIES_CA_EMAIL[privatePath]="${DIR_NAME[caEmail]}/${DIR_NAME[private]}"
  144.    
  145.     declare -A DIRECTORIES_CRT_EMAIL
  146.     DIRECTORIES_CRT_EMAIL[crtPath]="${DIR_NAME[crtEmail]}"
  147.     DIRECTORIES_CRT_EMAIL[cnfPath]="${DIR_NAME[crtEmail]}/${DIR_NAME[cnf]}"
  148.     DIRECTORIES_CRT_EMAIL[privatePath]="${DIR_NAME[crtEmail]}/${DIR_NAME[private]}"
  149.    
  150.     declare -A DIRECTORIES_CA_SOFTWARE
  151.     DIRECTORIES_CA_SOFTWARE[caPath]="${DIR_NAME[caSoftware]}"
  152.     DIRECTORIES_CA_SOFTWARE[dbPath]="${DIR_NAME[caSoftware]}/${DIR_NAME[db]}"
  153.     DIRECTORIES_CA_SOFTWARE[cnfPath]="${DIR_NAME[caSoftware]}/${DIR_NAME[cnf]}"
  154.     DIRECTORIES_CA_SOFTWARE[privatePath]="${DIR_NAME[caSoftware]}/${DIR_NAME[private]}"
  155.    
  156.     declare -A DIRECTORIES_CRT_SOFTWARE
  157.     DIRECTORIES_CRT_SOFTWARE[crtPath]="${DIR_NAME[crtSoftware]}"
  158.     DIRECTORIES_CRT_SOFTWARE[cnfPath]="${DIR_NAME[crtSoftware]}/${DIR_NAME[cnf]}"
  159.     DIRECTORIES_CRT_SOFTWARE[privatePath]="${DIR_NAME[crtSoftware]}/${DIR_NAME[private]}"
  160.    
  161.     declare -A DIRECTORIES_CA_TLS
  162.     DIRECTORIES_CA_TLS[caPath]="${DIR_NAME[caTls]}"
  163.     DIRECTORIES_CA_TLS[dbPath]="${DIR_NAME[caTls]}/${DIR_NAME[db]}"
  164.     DIRECTORIES_CA_TLS[cnfPath]="${DIR_NAME[caTls]}/${DIR_NAME[cnf]}"
  165.     DIRECTORIES_CA_TLS[privatePath]="${DIR_NAME[caTls]}/${DIR_NAME[private]}"
  166.    
  167.     declare -A DIRECTORIES_CRT_TLS
  168.     DIRECTORIES_CRT_TLS[crtPath]="${DIR_NAME[crtTls]}"
  169.     DIRECTORIES_CRT_TLS[cnfPath]="${DIR_NAME[crtTls]}/${DIR_NAME[cnf]}"
  170.     DIRECTORIES_CRT_TLS[privatePath]="${DIR_NAME[crtTls]}/${DIR_NAME[private]}"
  171.    
  172.     declare -A DIRECTORIES_CRT
  173.     DIRECTORIES_CRT[email]="${DIR_NAME[public]}/${DIR_NAME[email]}"
  174.     DIRECTORIES_CRT[software]="${DIR_NAME[public]}/${DIR_NAME[software]}"
  175.     DIRECTORIES_CRT[tls]="${DIR_NAME[public]}/${DIR_NAME[tls]}"
  176.    
  177.    
  178.    
  179.     ##############################################################
  180.     #
  181.     # CRT config partial factories
  182.     #
  183.     ##############################################################
  184.    
  185.     makeModulCsrConfigBlock_title()
  186.     {
  187.         local outputFile=$1
  188.         local domain=$2
  189.         local title=$3
  190.        
  191.         {
  192.             echo "# $title certificate request for $domain"
  193.             echo ''
  194.         } >> $outputFile
  195.     }
  196.    
  197.     makeModulCsrConfigBlock_csr_dn()
  198.     {
  199.         local outputFile=$1
  200.         local domain=$2
  201.         local defaultDn=$3
  202.         local defaultDn=$3
  203.        
  204.         {
  205.             echo "[ $defaultDn ]"
  206.             echo 'countryName             = "1. Country Name (2 letters) (eg, US)       "'
  207.             echo 'countryName_max         = 2'
  208.             echo 'countryName_default     = "BE"'
  209.             echo 'stateOrProvinceName     = "2. State or Province Name   (eg, region)   "'
  210.             echo 'localityName            = "3. Locality Name            (eg, city)     "'
  211.             echo 'organizationName        = "4. Organization Name        (eg, company)  "'
  212.             echo "organizationName_default = \""### Network $domain\"""
  213.             echo 'organizationalUnitName  = "5. Organizational Unit Name (eg, section)  "'
  214.             echo 'commonName              = "6. Common Name              (eg, full name)"'
  215.             echo 'commonName_max          = 64'
  216.             echo "commonName_default      = \""### Network $domain\"""
  217.             echo 'emailAddress            = "7. Email Address            (eg, name@fqdn)"'
  218.             echo 'emailAddress_max        = 40'
  219.             echo ''
  220.         } >> $outputFile
  221.     }
  222.    
  223.     ##############################################################
  224.     #
  225.     # CRT config factories
  226.     #
  227.     ##############################################################
  228.    
  229.     modulCsrEmailConfig()
  230.     {
  231.         local outputFile=$1
  232.         local domain=$2
  233.        
  234.         {
  235.             makeModulCsrConfigBlock_title $outputFile $domain 'Email'
  236.             echo '[ req ]'
  237.             echo 'default_bits            = 2048                  # RSA key size'
  238.             echo 'encrypt_key             = yes                   # Protect private key'
  239.             echo 'default_md              = sha1                  # MD to use'
  240.             echo 'utf8                    = yes                   # Input is UTF-8'
  241.             echo 'string_mask             = utf8only              # Emit UTF-8 strings'
  242.             echo 'prompt                  = yes                   # Prompt for DN'
  243.             echo 'distinguished_name      = email_dn              # DN template'
  244.             echo 'req_extensions          = email_reqext          # Desired extensions'
  245.             echo ''
  246.             makeModulCsrConfigBlock_csr_dn $outputFile $domain 'email_dn'
  247.             echo '[ email_reqext ]'
  248.             echo 'keyUsage                = critical,digitalSignature,keyEncipherment'
  249.             echo 'extendedKeyUsage        = emailProtection,clientAuth'
  250.             echo 'subjectKeyIdentifier    = hash'
  251.             echo 'subjectAltName          = email:move'
  252.         } >> $outputFile
  253.     }
  254.    
  255.     modulCsrTlsClientConfig()
  256.     {
  257.         local outputFile=$1
  258.         local domain=$2
  259.        
  260.         {
  261.             makeModulCsrConfigBlock_title $outputFile $domain 'TLS Client'
  262.             echo '[ req ]'
  263.             echo 'default_bits            = 2048                  # RSA key size'
  264.             echo 'encrypt_key             = yes                   # Protect private key'
  265.             echo 'default_md              = sha1                  # MD to use'
  266.             echo 'utf8                    = yes                   # Input is UTF-8'
  267.             echo 'string_mask             = utf8only              # Emit UTF-8 strings'
  268.             echo 'prompt                  = yes                   # Prompt for DN'
  269.             echo 'distinguished_name      = client_dn             # DN template'
  270.             echo 'req_extensions          = client_reqext         # Desired extensions'
  271.             echo ''
  272.             makeModulCsrConfigBlock_csr_dn $outputFile $domain 'client_dn'
  273.             echo ''
  274.             echo '[ client_reqext ]'
  275.             echo 'keyUsage                = critical,digitalSignature'
  276.             echo 'extendedKeyUsage        = clientAuth'
  277.             echo 'subjectKeyIdentifier    = hash'
  278.             echo 'subjectAltName          = email:move'
  279.         } >> $outputFile
  280.     }
  281.    
  282.     modulCsrTlsServerConfig()
  283.     {
  284.         local outputFile=$1
  285.         local domain=$2
  286.        
  287.         {
  288.             makeModulCsrConfigBlock_title $outputFile $domain 'TLS Server'
  289.             echo '[ req ]'
  290.             echo 'default_bits            = 2048                  # RSA key size'
  291.             echo 'encrypt_key             = no                    # Protect private key'
  292.             echo 'default_md              = sha1                  # MD to use'
  293.             echo 'utf8                    = yes                   # Input is UTF-8'
  294.             echo 'string_mask             = utf8only              # Emit UTF-8 strings'
  295.             echo 'prompt                  = yes                   # Prompt for DN'
  296.             echo 'distinguished_name      = server_dn             # DN template'
  297.             echo 'req_extensions          = server_reqext         # Desired extensions'
  298.             echo ''
  299.             makeModulCsrConfigBlock_csr_dn $outputFile $domain 'server_dn'
  300.             echo ''
  301.             echo '[ server_reqext ]'
  302.             echo 'keyUsage                = critical,digitalSignature,keyEncipherment'
  303.             echo 'extendedKeyUsage        = serverAuth,clientAuth'
  304.             echo 'subjectKeyIdentifier    = hash'
  305.             echo 'subjectAltName          = $ENV::SAN'
  306.         } >> $outputFile
  307.     }
  308.    
  309.     modulCsrSoftwareConfig()
  310.     {
  311.         local outputFile=$1
  312.         local domain=$2
  313.        
  314.         {
  315.             makeModulCsrConfigBlock_title $outputFile $domain 'Software'
  316.             echo '[ req ]'
  317.             echo 'default_bits            = 2048                  # RSA key size'
  318.             echo 'encrypt_key             = yes                   # Protect private key'
  319.             echo 'default_md              = sha1                  # MD to use'
  320.             echo 'utf8                    = yes                   # Input is UTF-8'
  321.             echo 'string_mask             = utf8only              # Emit UTF-8 strings'
  322.             echo 'prompt                  = yes                   # Prompt for DN'
  323.             echo 'distinguished_name      = codesign_dn           # DN template'
  324.             echo 'req_extensions          = codesign_reqext       # Desired extensions'
  325.             echo ''
  326.             echo '[ codesign_dn ]'
  327.             echo 'countryName             = "1. Country Name (2 letters) (eg, US)       "'
  328.             echo 'countryName_max         = 2'
  329.             echo 'stateOrProvinceName     = "2. State or Province Name   (eg, region)   "'
  330.             echo 'localityName            = "3. Locality Name            (eg, city)     "'
  331.             echo 'organizationName        = "4. Organization Name        (eg, company)  "'
  332.             echo 'organizationalUnitName  = "5. Organizational Unit Name (eg, section)  "'
  333.             echo 'commonName              = "6. Common Name              (eg, full name)"'
  334.             echo 'commonName_max          = 64'
  335.             echo ''
  336.             echo '[ codesign_reqext ]'
  337.             echo 'keyUsage                = critical,digitalSignature'
  338.             echo 'extendedKeyUsage        = critical,codeSigning'
  339.             echo 'subjectKeyIdentifier    = hash'
  340.         } >> $outputFile
  341.     }
  342.    
  343.     ##############################################################
  344.     #
  345.     # CA config partial factories
  346.     #
  347.     ##############################################################
  348.    
  349.     makeModulCaConfigBlock_title()
  350.     {
  351.         local outputFile=$1
  352.         local title=$2
  353.        
  354.         {
  355.             echo "# $title"
  356.             echo ''
  357.         } >> $outputFile
  358.     }
  359.    
  360.     makeModulCaConfigBlock_section()
  361.     {
  362.         local outputFile=$1
  363.         local title=$2
  364.        
  365.         {
  366.             echo ''
  367.             echo ''
  368.             echo "# $title"
  369.             echo ''
  370.         } >> $outputFile
  371.     }
  372.    
  373.     makeModulCaConfigBlock_default()
  374.     {
  375.         local outputFile=$1
  376.         local domain=$2
  377.         local level=$3
  378.         local type=$4
  379.        
  380.         {
  381.             echo '[ default ]'
  382.             echo "ca                      = $domain"
  383.             echo "ca_type                 = $type"
  384.             echo 'ca_dir                  = $ca_type'
  385.             echo "db_dir                  = \$ca_dir/${DIR_NAME[db]}"
  386.             echo "private_dir             = \$ca_dir/${DIR_NAME[private]}"
  387.             echo "dir                     = \$ENV::CA_${level}_SCRIPT_PATH  # Top dir"
  388.             echo "base_url                = http://$domain # CA base URL"
  389.             echo "ip_url                  = http://$DEFAULT_IP # CA base URL on IP"
  390.             echo 'aia_url                 = $base_url/$ca.$ca_type.cer       # CA certificate URL'
  391.             echo 'ip_aia_url              = $ip_url/$ca.$ca_type.cer         # CA certificate URL'
  392.             echo 'crl_url                 = $base_url/$ca.$ca_type.crl       # CRL distribution point'
  393.             echo 'ip_crl_url              = $ip_url/$ca.$ca_type.cer         # CRL distribution point'
  394.             echo 'name_opt                = multiline,-esc_msb,utf8 # Display UTF-8 characters'
  395.             echo ''
  396.         } >> $outputFile
  397.     }
  398.    
  399.    
  400.     makeModulCaConfigBlock_req()
  401.     {
  402.         local outputFile=$1
  403.        
  404.         {
  405.             echo '[ req ]'
  406.             echo "default_bits            = $DEFAULT_CA_RSA_KEYSIZE_REQUEST                 # RSA key size"
  407.             echo 'encrypt_key             = yes                   # Protect private key'
  408.             echo "default_md              = $DEFAULT_CA_MD_REQUEST                # MD to use"
  409.             echo 'utf8                    = yes                   # Input is UTF-8'
  410.             echo 'string_mask             = utf8only              # Emit UTF-8 strings'
  411.             echo 'prompt                  = no                    # Dont prompt for DN'
  412.             echo 'distinguished_name      = ca_dn                 # DN section'
  413.             echo 'req_extensions          = ca_reqext             # Desired extensions'
  414.             echo ''
  415.         } >> $outputFile
  416.     }
  417.    
  418.     makeModulCaConfigBlock_ca_dn()
  419.     {
  420.         local outputFile=$1
  421.         local oN=$2
  422.         local cN=$3
  423.        
  424.         {
  425.             echo '[ ca_dn ]'
  426.             echo 'countryName             = "BE"'
  427.             echo "organizationName        = \""### Network $oN\"""
  428.             echo 'organizationalUnitName  = "interop"'
  429.             echo "commonName              = \""### Network $cN\"""
  430.             echo ''
  431.         } >> $outputFile
  432.     }
  433.    
  434.     makeModulCaConfigBlock_ca_reqext()
  435.     {
  436.         local outputFile=$1
  437.         local case=$2
  438.        
  439.         if [ "$case" == 'signing' ]; then
  440.             {
  441.                 echo '[ ca_reqext ]'
  442.                 echo 'keyUsage                = critical,keyCertSign,cRLSign'
  443.                 echo 'basicConstraints        = critical,CA:true,pathlen:0'
  444.                 echo 'subjectKeyIdentifier    = hash'
  445.                 echo ''
  446.             } >> $outputFile
  447.         else
  448.             {
  449.                 echo '[ ca_reqext ]'
  450.                 echo 'keyUsage                = critical,keyCertSign,cRLSign'
  451.                 echo 'basicConstraints        = critical,CA:true'
  452.                 echo 'subjectKeyIdentifier    = hash'
  453.                 echo ''
  454.             } >> $outputFile
  455.         fi
  456.     }
  457.    
  458.     makeModulCaConfigBlock_ca()
  459.     {
  460.         local outputFile=$1
  461.         local defaultCa=$2
  462.         local x509_extensions=$3
  463.         local copy_extensions=$4
  464.         local policy=$5
  465.         local days=$6
  466.         local crlDays=$7
  467.        
  468.         local keyFileFormat=$(printf ${FILE_NAME[key]} '$ca' '$ca_type')
  469.         local crtSrlFileFormat=$(printf ${FILE_NAME[crtSrl]} '$ca' '$ca_type')
  470.         local crlSrlFileFormat=$(printf ${FILE_NAME[crlSrl]} '$ca' '$ca_type')
  471.         local crtDbFileFormat=$(printf ${FILE_NAME[crtDb]} '$ca' '$ca_type')
  472.         local crtFileFormat=$(printf ${FILE_NAME[crt]} '$ca' '$ca_type')
  473.        
  474.         local pDir='$dir/$private_dir'
  475.         local dDir='$dir/$db_dir'
  476.        
  477.         {
  478.             echo '[ ca ]'
  479.             echo "default_ca              = $defaultCa # The default CA section"
  480.             echo ''
  481.             echo "[ $defaultCa ]"
  482.             echo "certificate             = \$dir/$crtFileFormat                   # The CA cert"
  483.             echo 'new_certs_dir           = $dir/$ca_dir                            # Certificate archive'
  484.             echo "private_key             = $pDir/$keyFileFormat        # CA private key"
  485.             echo "serial                  = $dDir/$crtSrlFileFormat       # Serial number file"
  486.             echo "crlnumber               = $dDir/$crlSrlFileFormat       # CRL number file"
  487.             echo "database                = $dDir/$crtDbFileFormat        # Index file"
  488.             echo 'unique_subject          = no                    # Require unique subject'
  489.             echo "default_days            = $days          # How long to certify for"
  490.             echo "default_md              = $DEFAULT_CA_MD                  # MD to use"
  491.             echo "policy                  = $policy             # Default naming policy"
  492.             echo 'email_in_dn             = no                    # Add email to cert DN'
  493.             echo 'preserve                = yes                    # Keep passed DN ordering'
  494.             echo 'name_opt                = $name_opt             # Subject DN display options'
  495.             echo 'cert_opt                = ca_default            # Certificate display options'
  496.             echo "copy_extensions         = $copy_extensions                  # Copy extensions from CSR"
  497.             echo "x509_extensions         = $x509_extensions          # Default cert extensions"
  498.             echo "default_crl_days        = $crlDays                    # How long before next CRL"
  499.             echo 'crl_extensions          = crl_ext               # CRL extensions'
  500.             echo ''
  501.         } >> $outputFile
  502.     }
  503.    
  504.    
  505.    
  506.     ##############################################################
  507.     #
  508.     # CA config factories
  509.     #
  510.     ##############################################################
  511.    
  512.     # args: out file, domain, nesting level (required for $ENV)
  513.     modulCaConfig()
  514.     {
  515.         local outputFile=$1
  516.         local domain=$2
  517.         local level=$3
  518.        
  519.         if [ -z "$3" ]; then
  520.             level=0
  521.         fi
  522.        
  523.         local suffix='CA'
  524.         if [ $level == '0' ]; then
  525.             suffix='Root CA'
  526.         fi
  527.        
  528.         makeModulCaConfigBlock_title            $outputFile "Network $domain $suffix"
  529.         makeModulCaConfigBlock_default          $outputFile $domain $level 'ca'
  530.         makeModulCaConfigBlock_section          $outputFile 'CA certificate request'
  531.         makeModulCaConfigBlock_req              $outputFile
  532.         makeModulCaConfigBlock_ca_dn            $outputFile $domain "$domain $suffix"
  533.         makeModulCaConfigBlock_ca_reqext        $outputFile
  534.         makeModulCaConfigBlock_section          $outputFile 'CA operational settings'
  535.         makeModulCaConfigBlock_ca               $outputFile 'root_ca' 'server_ext' 'none' 'root_ca_pol' '730' '365'
  536.        
  537.         {
  538.             echo '[ root_ca_pol ]'
  539.             echo 'countryName             = match                 # Must match'
  540.             echo 'stateOrProvinceName     = optional              # Included if present'
  541.             echo 'localityName            = optional              # Included if present'
  542.             echo 'organizationName        = match                 # Must match'
  543.             echo 'organizationalUnitName  = optional              # Included if present'
  544.             echo 'commonName              = match                 # Must match'
  545.             echo ''
  546.             echo '[ extension_ca_pol ]'
  547.             echo 'countryName             = match                 # Must match'
  548.             echo 'stateOrProvinceName     = optional              # Included if present'
  549.             echo 'localityName            = optional              # Included if present'
  550.             echo 'organizationName        = match                 # Must match'
  551.             echo 'organizationalUnitName  = optional              # Included if present'
  552.             echo 'commonName              = supplied              # Must be present'
  553.             echo ''
  554.             echo '[ intermediate_ca_pol ]'
  555.             echo 'countryName             = supplied              # Must be present'
  556.             echo 'stateOrProvinceName     = optional              # Included if present'
  557.             echo 'localityName            = optional              # Included if present'
  558.             echo 'organizationName        = supplied              # Must be present'
  559.             echo 'organizationalUnitName  = optional              # Included if present'
  560.             echo 'commonName              = supplied              # Must be present'
  561.             echo ''
  562.             echo ''
  563.             echo '# Extensions'
  564.             echo ''
  565.             echo '[ root_ca_ext ]'
  566.             echo 'keyUsage                = critical,keyCertSign,cRLSign'
  567.             echo 'basicConstraints        = critical,CA:true'
  568.             echo 'subjectKeyIdentifier    = hash'
  569.             echo 'authorityKeyIdentifier  = keyid:always'
  570.             echo ''
  571.             echo '[ signing_ca_ext ]'
  572.             echo 'keyUsage                = critical,keyCertSign,cRLSign'
  573.             echo 'basicConstraints        = critical,CA:true,pathlen:0'
  574.             echo 'subjectKeyIdentifier    = hash'
  575.             echo 'authorityKeyIdentifier  = keyid:always'
  576.             echo 'authorityInfoAccess     = @issuer_info'
  577.             echo 'crlDistributionPoints   = @crl_info'
  578.             echo ''
  579.             echo '[ crl_ext ]'
  580.             echo 'authorityKeyIdentifier  = keyid:always'
  581.             echo 'authorityInfoAccess     = @issuer_info'
  582.             echo ''
  583.             echo '[ issuer_info ]'
  584.             echo 'caIssuers;URI.0         = $aia_url'
  585.             echo 'caIssuers;URI.1         = $ip_aia_url'
  586.             echo ''
  587.             echo '[ crl_info ]'
  588.             echo 'URI.0                   = $crl_url'
  589.             echo 'URI.1                   = $ip_crl_url'
  590.         } >> $outputFile
  591.     }
  592.    
  593.     # args: out file, domain, nesting level (required for $ENV)
  594.     modulCaTlsConfig()
  595.     {
  596.         local outputFile=$1
  597.         local domain=$2
  598.         local level=$3
  599.        
  600.         makeModulCaConfigBlock_title            $outputFile "Network $domain TLS CA"
  601.         makeModulCaConfigBlock_default          $outputFile $domain $level 'ca-tls'
  602.         makeModulCaConfigBlock_section          $outputFile 'CA certificate request'
  603.         makeModulCaConfigBlock_req              $outputFile
  604.         makeModulCaConfigBlock_ca_dn            $outputFile $domain "$domain TLS CA"
  605.         makeModulCaConfigBlock_ca_reqext        $outputFile 'signing'
  606.         makeModulCaConfigBlock_section          $outputFile 'CA operational settings'
  607.         makeModulCaConfigBlock_ca               $outputFile 'tls_ca' 'server_ext' 'copy' 'match_pol' '730' '1'
  608.        
  609.         {
  610.             echo '[ match_pol ]'
  611.             echo 'countryName             = match                 # Must match NO'
  612.             echo 'stateOrProvinceName     = optional              # Included if present'
  613.             echo 'localityName            = optional              # Included if present'
  614.             echo 'organizationName        = match                 # Must match Green AS'
  615.             echo 'organizationalUnitName  = optional              # Included if present'
  616.             echo 'commonName              = supplied              # Must be present'
  617.             echo ''
  618.             echo '[ extern_pol ]'
  619.             echo 'countryName             = supplied              # Must be present'
  620.             echo 'stateOrProvinceName     = optional              # Included if present'
  621.             echo 'localityName            = optional              # Included if present'
  622.             echo 'organizationName        = supplied              # Must be present'
  623.             echo 'organizationalUnitName  = optional              # Included if present'
  624.             echo 'commonName              = supplied              # Must be present'
  625.             echo ''
  626.             echo '[ any_pol ]'
  627.             echo 'domainComponent         = optional'
  628.             echo 'countryName             = optional'
  629.             echo 'stateOrProvinceName     = optional'
  630.             echo 'localityName            = optional'
  631.             echo 'organizationName        = optional'
  632.             echo 'organizationalUnitName  = optional'
  633.             echo 'commonName              = optional'
  634.             echo 'emailAddress            = optional'
  635.             echo ''
  636.             echo ''
  637.             echo '# Extensions'
  638.             echo ''
  639.             echo '[ server_ext ]'
  640.             echo 'keyUsage                = critical,digitalSignature,keyEncipherment'
  641.             echo 'basicConstraints        = CA:false'
  642.             echo 'extendedKeyUsage        = serverAuth,clientAuth'
  643.             echo 'subjectKeyIdentifier    = hash'
  644.             echo 'authorityKeyIdentifier  = keyid:always'
  645.             echo 'authorityInfoAccess     = @issuer_info'
  646.             echo 'crlDistributionPoints   = @crl_info'
  647.             echo ''
  648.             echo '[ client_ext ]'
  649.             echo 'keyUsage                = critical,digitalSignature'
  650.             echo 'basicConstraints        = CA:false'
  651.             echo 'extendedKeyUsage        = clientAuth'
  652.             echo 'subjectKeyIdentifier    = hash'
  653.             echo 'authorityKeyIdentifier  = keyid:always'
  654.             echo 'authorityInfoAccess     = @issuer_info'
  655.             echo 'crlDistributionPoints   = @crl_info'
  656.             echo ''
  657.             echo '[ crl_ext ]'
  658.             echo 'authorityKeyIdentifier  = keyid:always'
  659.             echo 'authorityInfoAccess     = @issuer_info'
  660.             echo ''
  661.             echo '[ issuer_info ]'
  662.             echo 'caIssuers;URI.0         = $aia_url'
  663.             echo ''
  664.             echo '[ crl_info ]'
  665.             echo 'URI.0                   = $crl_url'
  666.         } >> $outputFile
  667.     }
  668.    
  669.     # args: out file, domain, nesting level (required for $ENV)
  670.     modulCaEmailConfig()
  671.     {
  672.         local outputFile=$1
  673.         local domain=$2
  674.         local level=$3
  675.        
  676.         makeModulCaConfigBlock_title            $outputFile "Network $domain Email CA"
  677.         makeModulCaConfigBlock_default          $outputFile $domain $level 'ca-email'
  678.         makeModulCaConfigBlock_section          $outputFile 'CA certificate request'
  679.         makeModulCaConfigBlock_req              $outputFile
  680.         makeModulCaConfigBlock_ca_dn            $outputFile $domain "$domain Email CA"
  681.         makeModulCaConfigBlock_ca_reqext        $outputFile 'signing'
  682.         makeModulCaConfigBlock_section          $outputFile 'CA operational settings'
  683.         makeModulCaConfigBlock_ca               $outputFile 'email_ca' 'email_ext' 'copy' 'match_pol' '730' '1'
  684.        
  685.         {
  686.             echo '[ match_pol ]'
  687.             echo 'countryName             = match                 # Must match NO'
  688.             echo 'stateOrProvinceName     = optional              # Included if present'
  689.             echo 'localityName            = optional              # Included if present'
  690.             echo 'organizationName        = match                 # Must match Green AS'
  691.             echo 'organizationalUnitName  = optional              # Included if present'
  692.             echo 'commonName              = supplied              # Must be present'
  693.             echo ''
  694.             echo '[ any_pol ]'
  695.             echo 'domainComponent         = optional'
  696.             echo 'countryName             = optional'
  697.             echo 'stateOrProvinceName     = optional'
  698.             echo 'localityName            = optional'
  699.             echo 'organizationName        = optional'
  700.             echo 'organizationalUnitName  = optional'
  701.             echo 'commonName              = optional'
  702.             echo 'emailAddress            = optional'
  703.             echo ''
  704.             echo ''
  705.             echo '# Extensions'
  706.             echo ''
  707.             echo '[ email_ext ]'
  708.             echo 'keyUsage                = critical,digitalSignature,keyEncipherment'
  709.             echo 'basicConstraints        = CA:false'
  710.             echo 'extendedKeyUsage        = emailProtection,clientAuth,anyExtendedKeyUsage'
  711.             echo 'subjectKeyIdentifier    = hash'
  712.             echo 'authorityKeyIdentifier  = keyid:always'
  713.             echo 'authorityInfoAccess     = @issuer_info'
  714.             echo 'crlDistributionPoints   = @crl_info'
  715.             echo ''
  716.             echo '[ crl_ext ]'
  717.             echo 'authorityKeyIdentifier  = keyid:always'
  718.             echo 'authorityInfoAccess     = @issuer_info'
  719.             echo ''
  720.             echo '[ issuer_info ]'
  721.             echo 'caIssuers;URI.0         = $aia_url'
  722.             echo ''
  723.             echo '[ crl_info ]'
  724.             echo 'URI.0                   = $crl_url'
  725.         } >> $outputFile
  726.     }
  727.    
  728.     # args: out file, domain, nesting level (required for $ENV)
  729.     modulCaSoftwareConfig()
  730.     {
  731.         local outputFile=$1
  732.         local domain=$2
  733.         local level=$3
  734.        
  735.         makeModulCaConfigBlock_title            $outputFile "Network $domain Software CA"
  736.         makeModulCaConfigBlock_default          $outputFile $domain $level 'ca-software'
  737.         makeModulCaConfigBlock_section          $outputFile 'CA certificate request'
  738.         makeModulCaConfigBlock_req              $outputFile
  739.         makeModulCaConfigBlock_ca_dn            $outputFile $domain "$domain Software CA"
  740.         makeModulCaConfigBlock_ca_reqext        $outputFile 'signing'
  741.         makeModulCaConfigBlock_section          $outputFile 'CA operational settings'
  742.         makeModulCaConfigBlock_ca               $outputFile 'software_ca' 'codesign_ext' 'copy' 'match_pol' '1826' '30'
  743.        
  744.         {
  745.             echo '[ match_pol ]'
  746.             echo 'countryName             = match                 # Must match NO'
  747.             echo 'stateOrProvinceName     = optional              # Included if present'
  748.             echo 'localityName            = optional              # Included if present'
  749.             echo 'organizationName        = match                 # Must match Green AS'
  750.             echo 'organizationalUnitName  = optional              # Included if present'
  751.             echo 'commonName              = supplied              # Must be present'
  752.             echo ''
  753.             echo '[ any_pol ]'
  754.             echo 'domainComponent         = optional'
  755.             echo 'countryName             = optional'
  756.             echo 'stateOrProvinceName     = optional'
  757.             echo 'localityName            = optional'
  758.             echo 'organizationName        = optional'
  759.             echo 'organizationalUnitName  = optional'
  760.             echo 'commonName              = optional'
  761.             echo 'emailAddress            = optional'
  762.             echo ''
  763.             echo ''
  764.             echo '# Extensions'
  765.             echo ''
  766.             echo '[ codesign_ext ]'
  767.             echo 'keyUsage                = critical,digitalSignature'
  768.             echo 'basicConstraints        = CA:false'
  769.             echo 'extendedKeyUsage        = critical,codeSigning'
  770.             echo 'subjectKeyIdentifier    = hash'
  771.             echo 'authorityKeyIdentifier  = keyid:always'
  772.             echo 'authorityInfoAccess     = @issuer_info'
  773.             echo 'crlDistributionPoints   = @crl_info'
  774.             echo ''
  775.             echo '[ crl_ext ]'
  776.             echo 'authorityKeyIdentifier  = keyid:always'
  777.             echo 'authorityInfoAccess     = @issuer_info'
  778.             echo ''
  779.             echo '[ issuer_info ]'
  780.             echo 'caIssuers;URI.0         = $aia_url'
  781.             echo ''
  782.             echo '[ crl_info ]'
  783.             echo 'URI.0                   = $crl_url'
  784.         } >> $outputFile
  785.     }
  786.    
  787.     ##############################################################
  788.     #
  789.     # consolol
  790.     #
  791.     ##############################################################
  792.  
  793.     writeNewCert()
  794.     {
  795.         local domain=$1
  796.         local x=$(printf '%-64s' "create certificates for")
  797.         local y=$(printf '%-64s' "$domain")
  798.         local z=$(printf '%-64s' '')
  799.        
  800.         echo -e "\e[90m$z\e[39m"
  801.         echo -e "\e[90m$x\e[39m"
  802.         echo -e "\e[96m$y\e[39m"
  803.         echo -e "\e[90m$z\e[39m"
  804.     }
  805.    
  806.     writeNewType()
  807.     {
  808.         local type=$1
  809.         echo -e "\e[97m• create $type\e[39m"
  810.     }
  811.    
  812.     writeNewItem()
  813.     {
  814.         local item=$1
  815.         echo -e "\e[90m  - $item\e[39m"
  816.     }
  817.    
  818.     writeNewItem2()
  819.     {
  820.         local item=$1
  821.         #echo -e "\e[90m  --- $item\e[39m"
  822.     }
  823.    
  824.     check_result()
  825.     {
  826.         if [ $1 -ne 0 ]; then
  827.             echo -e "\e[91m        Error\e[39m $2"
  828.             exit $1
  829.         else
  830.             echo -e "\e[92m        +\e[39m"
  831.         fi
  832.     }
  833.    
  834.     ##############################################################
  835.     #
  836.     # more factories!!!
  837.     #
  838.     ##############################################################
  839.    
  840.     makeConfigFile()
  841.     {
  842.         local domain=$1
  843.         local modul=$2
  844.         local outputFile=$3
  845.         local level=$4
  846.        
  847.         if [ ! -e "$outputFile" ]; then
  848.             writeNewItem "CA config $modul"
  849.             eval $modul $outputFile $domain $level
  850.             check_result $? 'unable to create config'
  851.         fi
  852.     }
  853.    
  854.     makeCsrConfigFile()
  855.     {
  856.         local domain=$1
  857.         local modul=$2
  858.         local outputFile=$3
  859.        
  860.         if [ ! -e "$outputFile" ]; then
  861.             writeNewItem "certificate request config $modul"
  862.             eval $modul $outputFile $domain
  863.             check_result $? 'unable to create config'
  864.         fi
  865.     }
  866.    
  867.     makeUserTlsCsrFiles()
  868.     {
  869.         local domain=$1
  870.         local cnfPath=$2
  871.        
  872.         makeCsrConfigFile \
  873.             $domain \
  874.             'modulCsrTlsClientConfig' \
  875.             $cnfPath/$(printf ${FILE_NAME[cnf]} $domain 'tls-client')
  876.            
  877.         makeCsrConfigFile \
  878.             $domain \
  879.             'modulCsrTlsServerConfig' \
  880.             $cnfPath/$(printf ${FILE_NAME[cnf]} $domain 'tls-server')
  881.     }
  882.    
  883.     makeUserSoftwareCsrFiles()
  884.     {
  885.         local domain=$1
  886.         local cnfPath=$2
  887.        
  888.         makeCsrConfigFile \
  889.             $domain \
  890.             'modulCsrSoftwareConfig' \
  891.             $cnfPath/$(printf ${FILE_NAME[cnf]} $domain 'code-signing')
  892.     }
  893.    
  894.     makeUserEmailCsrFiles()
  895.     {
  896.         local domain=$1
  897.         local cnfPath=$2
  898.        
  899.         makeCsrConfigFile \
  900.             $domain \
  901.             'modulCsrEmailConfig' \
  902.             $cnfPath/$(printf ${FILE_NAME[cnf]} $domain 'email')
  903.     }
  904.    
  905.     makePasswordFile()
  906.     {
  907.         local domain=$1
  908.         local pwdFile=$2
  909.        
  910.         if [ ! -e $pwdFile ]; then
  911.             writeNewItem 'pass'
  912.             openssl genpkey -algorithm RSA -out $pwdFile -pkeyopt rsa_keygen_bits:$DEFAULT_CA_RSA_KEYSIZE_PASSWORD -pkeyopt rsa_keygen_pubexp:$DEFAULT_CA_PWD_GEN_PUBEXP
  913.             check_result $? 'unable to create password'
  914.         fi
  915.     }
  916.    
  917.     makeKeyFile()
  918.     {
  919.         local domain=$1
  920.         local keyFile=$2
  921.         local pwdFile=$3
  922.        
  923.         if [ ! -e $keyFile ]; then
  924.             writeNewItem 'key'
  925.             openssl genrsa -aes256 -passout file:$pwdFile -out $keyFile $DEFAULT_CA_RSA_KEYSIZE_PRIVATE_KEY
  926.             check_result $? 'unable to create private key'
  927.         fi
  928.     }
  929.    
  930.     makeDbFiles()
  931.     {
  932.         local domain=$1
  933.         local database=$2
  934.         local crtSerial=$3
  935.         local crlSerial=$4
  936.        
  937.         if [ ! -e $database ]; then
  938.             writeNewItem 'database'
  939.             touch $database
  940.             check_result $? 'unable to create database'
  941.             writeNewItem 'crt serial'
  942.             echo 1000 > $crtSerial
  943.             check_result $? 'unable to create crt serial'
  944.             writeNewItem 'crl serial'
  945.             echo 1000 > $crlSerial
  946.             check_result $? 'unable to create crl serial'
  947.         fi
  948.     }
  949.    
  950.     makeCsrFile()
  951.     {
  952.         local domain=$1
  953.         local cnfFile=$2
  954.         local csrFile=$3
  955.         local keyFile=$4
  956.         local pwdFile=$5
  957.        
  958.         if [ ! -e $csrFile ]; then
  959.             writeNewItem 'csr'
  960.             openssl req -new \
  961.                 -config $cnfFile \
  962.                 -out $csrFile \
  963.                 -key $keyFile -passin file:$pwdFile \
  964.                     > /dev/null 2>&1
  965.             check_result $? 'unable to create csr'
  966.         fi
  967.     }
  968.    
  969.     makeCrtFile()
  970.     {
  971.         local domain=$1
  972.         local cnfFile=$2
  973.         local csrFile=$3
  974.         local crtFile=$4
  975.         local pwdFile=$5
  976.         local case=$6
  977.        
  978.         if [ ! -e $crtFile ]; then
  979.             writeNewItem 'crt'
  980.            
  981.             if [ "$case" == 'root_ca' ]; then
  982.                 openssl ca -selfsign -batch \
  983.                     -config $cnfFile \
  984.                     -in $csrFile \
  985.                     -passin file:$pwdFile \
  986.                     -out $crtFile \
  987.                     -extensions root_ca_ext \
  988.                     -enddate 20820508235959Z \
  989.                         > /dev/null 2>&1
  990.                 check_result $? 'unable to create crt'
  991.             fi
  992.            
  993.             if [ "$case" == 'intermediate_ca' ]; then
  994.                 openssl ca -batch \
  995.                     -config $cnfFile \
  996.                     -in $csrFile \
  997.                     -passin file:$pwdFile \
  998.                     -out $crtFile \
  999.                     -extensions root_ca_ext \
  1000.                     -policy intermediate_ca_pol \
  1001.                     -enddate 20820508235959Z \
  1002.                         > /dev/null 2>&1
  1003.                 check_result $? 'unable to create crt'
  1004.             fi
  1005.            
  1006.             if [ "$case" == 'signing_ca' ]; then
  1007.                 openssl ca -batch \
  1008.                     -config $cnfFile \
  1009.                     -in $csrFile \
  1010.                     -passin file:$pwdFile \
  1011.                     -out $crtFile \
  1012.                     -extensions signing_ca_ext \
  1013.                     -policy extension_ca_pol \
  1014.                     -enddate 20820508235959Z \
  1015.                         > /dev/null 2>&1
  1016.                 check_result $? 'unable to create crt'
  1017.             fi
  1018.         fi
  1019.     }
  1020.    
  1021.     makeCrlFile()
  1022.     {
  1023.         local domain=$1
  1024.         local cnfFile=$2
  1025.         local crlFile=$3
  1026.         local pwdFile=$4
  1027.        
  1028.         if [ ! -e $crlFile ]; then
  1029.             writeNewItem 'crl'
  1030.             openssl ca -gencrl \
  1031.                 -config $cnfFile \
  1032.                 -passin file:$pwdFile \
  1033.                 -out $crlFile \
  1034.                     > /dev/null 2>&1
  1035.                 check_result $? 'unable to create crl'
  1036.         fi
  1037.     }
  1038.    
  1039.     makeChain()
  1040.     {
  1041.         local domain=$1
  1042.         local child=$2
  1043.         local parents=$3
  1044.         local chainFile=$4
  1045.        
  1046.         if [ ! -e $chainFile ]; then
  1047.             writeNewItem 'chained certificates'
  1048.             cat $child $parents > $chainFile
  1049.             check_result $? 'unable to create chained certificates'
  1050.         fi
  1051.     }
  1052.    
  1053.     ##############################################################
  1054.     #
  1055.     # CA factories
  1056.     #
  1057.     ##############################################################
  1058.    
  1059.     #
  1060.     # the root! rooooooooooot!
  1061.     #
  1062.     # note: we need the env var for openssl config
  1063.     #
  1064.     # ./reverse root CA
  1065.     #
  1066.     makeRootCa()
  1067.     {
  1068.         local domain=$1
  1069.         local baseDir=$2
  1070.         local cnfFile=$3
  1071.         local csrFile=$4
  1072.         local keyFile=$5
  1073.         local pwdFile=$6
  1074.         local crtFile=$7
  1075.         local crlFile=$8
  1076.        
  1077.         export CA_0_SCRIPT_PATH="$baseDir"
  1078.        
  1079.         makeCsrFile $domain $cnfFile $csrFile $keyFile $pwdFile
  1080.         makeCrtFile $domain $cnfFile $csrFile $crtFile $pwdFile 'root_ca'
  1081.         makeCrlFile $domain $cnfFile $crlFile $pwdFile
  1082.     }
  1083.    
  1084.     #
  1085.     # intermediate CA level 1
  1086.     #
  1087.     # note: we need the env vars for openssl config
  1088.     #
  1089.     # ./reverse/domain root CA
  1090.     #
  1091.     makeIntermediateCa()
  1092.     {
  1093.         local domain=$1
  1094.         local baseDir=$2
  1095.         local cnfFile=$3
  1096.         local csrFile=$4
  1097.         local keyFile=$5
  1098.         local pwdFile=$6
  1099.         local crtFile=$7
  1100.         local crlFile=$8
  1101.         local chainFile=$9
  1102.         local rootBaseDir=${10}
  1103.         local rootCnfFile=${11}
  1104.         local rootPwdFile=${12}
  1105.         local rootCrtFile=${13}
  1106.        
  1107.         export CA_1_SCRIPT_PATH="$baseDir"
  1108.         export CA_0_SCRIPT_PATH="$rootBaseDir"
  1109.        
  1110.         makeCsrFile $domain $cnfFile $csrFile $keyFile $pwdFile
  1111.         makeCrtFile $domain $rootCnfFile $csrFile $crtFile $rootPwdFile 'intermediate_ca'
  1112.         makeCrlFile $domain $cnfFile $crlFile $pwdFile
  1113.         makeChain   $domain $crtFile $rootCrtFile $chainFile
  1114.     }
  1115.    
  1116.     #
  1117.     # intermediate CA level 2
  1118.     #
  1119.     # note: we need the env vars for openssl config
  1120.     #
  1121.     # ./reverse/domain/subdomain root CA
  1122.     #
  1123.     makeIntermediateIntermediateCa()
  1124.     {
  1125.         local domain=$1
  1126.         local baseDir=$2
  1127.         local cnfFile=$3
  1128.         local csrFile=$4
  1129.         local keyFile=$5
  1130.         local pwdFile=$6
  1131.         local crtFile=$7
  1132.         local crlFile=$8
  1133.         local chainFile=$9
  1134.         local rootBaseDir=${10}
  1135.         local rootCnfFile=${11}
  1136.         local rootPwdFile=${12}
  1137.         local rootCrtFile=${13}
  1138.        
  1139.         export CA_2_SCRIPT_PATH="$baseDir"
  1140.         export CA_1_SCRIPT_PATH="$rootBaseDir"
  1141.        
  1142.         makeCsrFile $domain $cnfFile $csrFile $keyFile $pwdFile
  1143.         makeCrtFile $domain $rootCnfFile $csrFile $crtFile $rootPwdFile 'intermediate_ca'
  1144.         makeCrlFile $domain $cnfFile $crlFile $pwdFile
  1145.         makeChain   $domain $crtFile $rootCrtFile $chainFile
  1146.     }
  1147.    
  1148.     #
  1149.     # signing CA
  1150.     #
  1151.     # note: we need the env var for openssl config
  1152.     #
  1153.     # ./reverse-tls
  1154.     # ./reverse/domain-[tls|email|software]
  1155.     # ./reverse/domain/subdomain-[tls|email|software]
  1156.     #
  1157.     makeSigningCa()
  1158.     {
  1159.         local domain=$1
  1160.         local baseDir=$2
  1161.         local cnfFile=$3
  1162.         local csrFile=$4
  1163.         local keyFile=$5
  1164.         local pwdFile=$6
  1165.         local crtFile=$7
  1166.         local crlFile=$8
  1167.         local chainFile=$9
  1168.         local rootCnfFile=${10}
  1169.         local rootPwdFile=${11}
  1170.         local rootCrtFile=${12}
  1171.        
  1172.         export CA_0_SCRIPT_PATH="$baseDir"
  1173.        
  1174.         makeCsrFile $domain $cnfFile $csrFile $keyFile $pwdFile
  1175.         makeCrtFile $domain $rootCnfFile $csrFile $crtFile $rootPwdFile 'signing_ca'
  1176.         makeCrlFile $domain $cnfFile $crlFile $pwdFile
  1177.         makeChain   $domain $crtFile $rootCrtFile $chainFile
  1178.     }
  1179.    
  1180.    
  1181.     ##############################################################
  1182.     #
  1183.     # output
  1184.     #
  1185.     ##############################################################
  1186.    
  1187.     #
  1188.     # LEVEL 0 (reverse)
  1189.     #
  1190.    
  1191.     declare -A LEVEL0
  1192.     LEVEL0[domain]=$1
  1193.     LEVEL0[path]="$SCRIPT_PATH/$1"
  1194.    
  1195.     declare -A LEVEL0_PATH
  1196.     # lookup table
  1197.     LEVEL0_PATH[lookup]="${LEVEL0[path]}/${DIR_NAME[lookup]}"
  1198.     # root ca
  1199.     LEVEL0_PATH[caPath]="${LEVEL0[path]}/${DIRECTORIES_CA_ROOT[caPath]}"
  1200.     LEVEL0_PATH[caDbPath]="${LEVEL0[path]}/${DIRECTORIES_CA_ROOT[dbPath]}"
  1201.     LEVEL0_PATH[caCnfPath]="${LEVEL0[path]}/${DIRECTORIES_CA_ROOT[cnfPath]}"
  1202.     LEVEL0_PATH[caPrvPath]="${LEVEL0[path]}/${DIRECTORIES_CA_ROOT[privatePath]}"
  1203.     # tls ca
  1204.     LEVEL0_PATH[caTlsPath]="${LEVEL0[path]}/${DIRECTORIES_CA_TLS[caPath]}"
  1205.     LEVEL0_PATH[caTlsDbPath]="${LEVEL0[path]}/${DIRECTORIES_CA_TLS[dbPath]}"
  1206.     LEVEL0_PATH[caTlsCnfPath]="${LEVEL0[path]}/${DIRECTORIES_CA_TLS[cnfPath]}"
  1207.     LEVEL0_PATH[caTlsPrvPath]="${LEVEL0[path]}/${DIRECTORIES_CA_TLS[privatePath]}"
  1208.     # domains
  1209.     LEVEL0_PATH[intermediatePath]="${LEVEL0[path]}/${DIR_NAME[intermediateDir]}"
  1210.     # tls crt
  1211.     LEVEL0_PATH[crtTlsPath]="${LEVEL0[path]}/${DIRECTORIES_CRT_TLS[crtPath]}"
  1212.     LEVEL0_PATH[crtTlsCnfPath]="${LEVEL0[path]}/${DIRECTORIES_CRT_TLS[cnfPath]}"
  1213.     LEVEL0_PATH[crtTlsPrvPath]="${LEVEL0[path]}/${DIRECTORIES_CRT_TLS[privatePath]}"
  1214.     # pub
  1215.     LEVEL0_PATH[crtTls]="${LEVEL0[path]}/${DIRECTORIES_CRT[tls]}"
  1216.    
  1217.     writeNewCert ${LEVEL0[domain]}
  1218.    
  1219.     writeNewType 'directories'
  1220.     for index in "${!LEVEL0_PATH[@]}"
  1221.     do
  1222.         echo "create dir ${LEVEL0_PATH[$index]}"
  1223.         mkdir -p "${LEVEL0_PATH[$index]}" > /dev/null 2>&1
  1224.         check_result $? 'unable to create directory'
  1225.     done
  1226.    
  1227.    
  1228.    
  1229.     ##############################################################
  1230.     #
  1231.     # lookup
  1232.     #
  1233.     # ca=$(head -n 1 $lookup/$domain)
  1234.     #
  1235.     ##############################################################
  1236.     lookupAdd()
  1237.     {
  1238.         local domain=$1
  1239.         local path=$2
  1240.         local lookup=${LEVEL0_PATH[lookup]}
  1241.        
  1242.         rm $lookup/$domain > /dev/null 2>&1
  1243.         echo $path >> $lookup/$domain
  1244.     }
  1245.    
  1246.    
  1247.     writeNewType 'lookup'
  1248.     lookupAdd ${LEVEL0[domain]} ${LEVEL0[path]}
  1249.  
  1250.     writeNewType 'user request configs'
  1251.     makeUserTlsCsrFiles \
  1252.         ${LEVEL0[domain]} \
  1253.         ${LEVEL0_PATH[crtTlsCnfPath]}
  1254.    
  1255.     #
  1256.     # The following part is the worst thing you've ever seen. \o/
  1257.     # Thanks to openssl's path party.
  1258.     #
  1259.    
  1260.     #
  1261.     # root CA
  1262.     #
  1263.     writeNewType 'Root CA'
  1264.     # ./
  1265.     local __0__caCsr=${LEVEL0[path]}/$(printf ${FILE_NAME[csr]} ${LEVEL0[domain]} ${DIR_NAME[caRoot]})
  1266.     local __0__caCrt=${LEVEL0[path]}/$(printf ${FILE_NAME[crt]} ${LEVEL0[domain]} ${DIR_NAME[caRoot]})
  1267.     # ./db
  1268.     local __0__caCrtDb=${LEVEL0_PATH[caDbPath]}/$(printf ${FILE_NAME[crtDb]} ${LEVEL0[domain]} ${DIR_NAME[caRoot]})
  1269.     local __0__caCrtSrl=${LEVEL0_PATH[caDbPath]}/$(printf ${FILE_NAME[crtSrl]} ${LEVEL0[domain]} ${DIR_NAME[caRoot]})
  1270.     local __0__caCrlSrl=${LEVEL0_PATH[caDbPath]}/$(printf ${FILE_NAME[crlSrl]} ${LEVEL0[domain]} ${DIR_NAME[caRoot]})
  1271.     local __0__caCrl=${LEVEL0_PATH[caDbPath]}/$(printf ${FILE_NAME[crl]} ${LEVEL0[domain]} ${DIR_NAME[caRoot]})
  1272.     # ./etc
  1273.     local __0__caConfig=${LEVEL0_PATH[caCnfPath]}/$(printf ${FILE_NAME[cnf]} ${LEVEL0[domain]} ${DIR_NAME[caRoot]})
  1274.     # ./private
  1275.     local __0__caPwd=${LEVEL0_PATH[caPrvPath]}/$(printf ${FILE_NAME[password]} ${LEVEL0[domain]} ${DIR_NAME[caRoot]})
  1276.     local __0__caKey=${LEVEL0_PATH[caPrvPath]}/$(printf ${FILE_NAME[key]} ${LEVEL0[domain]} ${DIR_NAME[caRoot]})
  1277.    
  1278.     makeConfigFile \
  1279.         ${LEVEL0[domain]} \
  1280.         'modulCaConfig' \
  1281.         $__0__caConfig \
  1282.         '0'
  1283.    
  1284.     makePasswordFile \
  1285.         ${LEVEL0[domain]} \
  1286.         $__0__caPwd
  1287.    
  1288.     makeKeyFile \
  1289.         ${LEVEL0[domain]} \
  1290.         $__0__caKey \
  1291.         $__0__caPwd
  1292.        
  1293.     makeDbFiles \
  1294.         ${LEVEL0[domain]} \
  1295.         $__0__caCrtDb \
  1296.         $__0__caCrtSrl \
  1297.         $__0__caCrlSrl
  1298.        
  1299.     makeRootCa \
  1300.         ${LEVEL0[domain]} \
  1301.         ${LEVEL0[path]} \
  1302.         $__0__caConfig \
  1303.         $__0__caCsr \
  1304.         $__0__caKey \
  1305.         $__0__caPwd \
  1306.         $__0__caCrt \
  1307.         $__0__caCrl
  1308.        
  1309.     #
  1310.     # tls CA
  1311.     #
  1312.     writeNewType 'TLS CA'
  1313.     # ./
  1314.     local __0__tlsCsr=${LEVEL0[path]}/$(printf ${FILE_NAME[csr]} ${LEVEL0[domain]} ${DIR_NAME[caTls]})
  1315.     local __0__tlsCrt=${LEVEL0[path]}/$(printf ${FILE_NAME[crt]} ${LEVEL0[domain]} ${DIR_NAME[caTls]})
  1316.     local __0__tlsChainPem=${LEVEL0[path]}/$(printf ${FILE_NAME[chainPem]} ${LEVEL0[domain]} ${DIR_NAME[caTls]})
  1317.     # ./db
  1318.     local __0__tlsCrtDb=${LEVEL0_PATH[caTlsDbPath]}/$(printf ${FILE_NAME[crtDb]} ${LEVEL0[domain]} ${DIR_NAME[caTls]})
  1319.     local __0__tlsCrtSrl=${LEVEL0_PATH[caTlsDbPath]}/$(printf ${FILE_NAME[crtSrl]} ${LEVEL0[domain]} ${DIR_NAME[caTls]})
  1320.     local __0__tlsCrlSrl=${LEVEL0_PATH[caTlsDbPath]}/$(printf ${FILE_NAME[crlSrl]} ${LEVEL0[domain]} ${DIR_NAME[caTls]})
  1321.     local __0__tlsCrl=${LEVEL0_PATH[caTlsDbPath]}/$(printf ${FILE_NAME[crl]} ${LEVEL0[domain]} ${DIR_NAME[caTls]})
  1322.     # ./etc
  1323.     local __0__tlsConfig=${LEVEL0_PATH[caTlsCnfPath]}/$(printf ${FILE_NAME[cnf]} ${LEVEL0[domain]} ${DIR_NAME[caTls]})
  1324.     # ./private
  1325.     local __0__tlsPwd=${LEVEL0_PATH[caTlsPrvPath]}/$(printf ${FILE_NAME[password]} ${LEVEL0[domain]} ${DIR_NAME[caTls]})
  1326.     local __0__tlsKey=${LEVEL0_PATH[caTlsPrvPath]}/$(printf ${FILE_NAME[key]} ${LEVEL0[domain]} ${DIR_NAME[caTls]})
  1327.    
  1328.     makeConfigFile \
  1329.         ${LEVEL0[domain]} \
  1330.         'modulCaTlsConfig' \
  1331.         $__0__tlsConfig \
  1332.         '0'
  1333.    
  1334.     makePasswordFile \
  1335.         ${LEVEL0[domain]} \
  1336.         $__0__tlsPwd
  1337.    
  1338.     makeKeyFile \
  1339.         ${LEVEL0[domain]} \
  1340.         $__0__tlsKey \
  1341.         $__0__tlsPwd
  1342.        
  1343.     makeDbFiles \
  1344.         ${LEVEL0[domain]} \
  1345.         $__0__tlsCrtDb \
  1346.         $__0__tlsCrtSrl \
  1347.         $__0__tlsCrlSrl
  1348.    
  1349.     makeSigningCa \
  1350.         ${LEVEL0[domain]} \
  1351.         ${LEVEL0[path]} \
  1352.         $__0__tlsConfig \
  1353.         $__0__tlsCsr \
  1354.         $__0__tlsKey \
  1355.         $__0__tlsPwd \
  1356.         $__0__tlsCrt \
  1357.         $__0__tlsCrl \
  1358.         $__0__tlsChainPem \
  1359.         $__0__caConfig \
  1360.         $__0__caPwd \
  1361.         $__0__caCrt
  1362.    
  1363.     #
  1364.     # LEVEL 1 (domain)
  1365.     #
  1366.    
  1367.     # intermediate CA for domain level
  1368.     # ./intermediate
  1369.     if [ ! -z "$2" ]; then
  1370.         level1domains=$(echo $2 | tr ";" "\n")
  1371.         for level1domain in $level1domains
  1372.         do
  1373.             #
  1374.             # LEVEL 1 (domain)
  1375.             #
  1376.             declare -A LEVEL1
  1377.             LEVEL1[domain]=$level1domain
  1378.             LEVEL1[path]="${LEVEL0_PATH[intermediatePath]}/$level1domain"
  1379.            
  1380.             declare -A LEVEL1_PATH
  1381.             # sub root ca
  1382.             LEVEL1_PATH[caPath]="${LEVEL1[path]}/${DIRECTORIES_CA_ROOT[caPath]}"
  1383.             LEVEL1_PATH[caDbPath]="${LEVEL1[path]}/${DIRECTORIES_CA_ROOT[dbPath]}"
  1384.             LEVEL1_PATH[caCnfPath]="${LEVEL1[path]}/${DIRECTORIES_CA_ROOT[cnfPath]}"
  1385.             LEVEL1_PATH[caPrvPath]="${LEVEL1[path]}/${DIRECTORIES_CA_ROOT[privatePath]}"
  1386.             # email ca
  1387.             LEVEL1_PATH[caEmailPath]="${LEVEL1[path]}/${DIRECTORIES_CA_EMAIL[caPath]}"
  1388.             LEVEL1_PATH[caEmailDbPath]="${LEVEL1[path]}/${DIRECTORIES_CA_EMAIL[dbPath]}"
  1389.             LEVEL1_PATH[caEmailCnfPath]="${LEVEL1[path]}/${DIRECTORIES_CA_EMAIL[cnfPath]}"
  1390.             LEVEL1_PATH[caEmailPrvPath]="${LEVEL1[path]}/${DIRECTORIES_CA_EMAIL[privatePath]}"
  1391.             # software ca
  1392.             LEVEL1_PATH[caSoftwarePath]="${LEVEL1[path]}/${DIRECTORIES_CA_SOFTWARE[caPath]}"
  1393.             LEVEL1_PATH[caSoftwareDbPath]="${LEVEL1[path]}/${DIRECTORIES_CA_SOFTWARE[dbPath]}"
  1394.             LEVEL1_PATH[caSoftwareCnfPath]="${LEVEL1[path]}/${DIRECTORIES_CA_SOFTWARE[cnfPath]}"
  1395.             LEVEL1_PATH[caSoftwarePrvPath]="${LEVEL1[path]}/${DIRECTORIES_CA_SOFTWARE[privatePath]}"
  1396.             # tls ca
  1397.             LEVEL1_PATH[caTlsPath]="${LEVEL1[path]}/${DIRECTORIES_CA_TLS[caPath]}"
  1398.             LEVEL1_PATH[caTlsDbPath]="${LEVEL1[path]}/${DIRECTORIES_CA_TLS[dbPath]}"
  1399.             LEVEL1_PATH[caTlsCnfPath]="${LEVEL1[path]}/${DIRECTORIES_CA_TLS[cnfPath]}"
  1400.             LEVEL1_PATH[caTlsPrvPath]="${LEVEL1[path]}/${DIRECTORIES_CA_TLS[privatePath]}"
  1401.             # email crt
  1402.             LEVEL1_PATH[crtEmailPath]="${LEVEL1[path]}/${DIRECTORIES_CRT_EMAIL[crtPath]}"
  1403.             LEVEL1_PATH[crtEmailCnfPath]="${LEVEL1[path]}/${DIRECTORIES_CRT_EMAIL[cnfPath]}"
  1404.             LEVEL1_PATH[crtEmailPrvPath]="${LEVEL1[path]}/${DIRECTORIES_CRT_EMAIL[privatePath]}"
  1405.             # software crt
  1406.             LEVEL1_PATH[crtSoftwarePath]="${LEVEL1[path]}/${DIRECTORIES_CRT_SOFTWARE[crtPath]}"
  1407.             LEVEL1_PATH[crtSoftwareCnfPath]="${LEVEL1[path]}/${DIRECTORIES_CRT_SOFTWARE[cnfPath]}"
  1408.             LEVEL1_PATH[crtSoftwarePrvPath]="${LEVEL1[path]}/${DIRECTORIES_CRT_SOFTWARE[privatePath]}"
  1409.             # tls crt
  1410.             LEVEL1_PATH[crtTlsPath]="${LEVEL1[path]}/${DIRECTORIES_CRT_TLS[crtPath]}"
  1411.             LEVEL1_PATH[crtTlsCnfPath]="${LEVEL1[path]}/${DIRECTORIES_CRT_TLS[cnfPath]}"
  1412.             LEVEL1_PATH[crtTlsPrvPath]="${LEVEL1[path]}/${DIRECTORIES_CRT_TLS[privatePath]}"
  1413.             # subdomains
  1414.             LEVEL1_PATH[intermediatePath]="${LEVEL1[path]}/${DIR_NAME[intermediateDir]}"
  1415.             # pub
  1416.             LEVEL1_PATH[pubTls]="${LEVEL1[path]}/${DIRECTORIES_CRT[tls]}"
  1417.             LEVEL1_PATH[pubSoftware]="${LEVEL1[path]}/${DIRECTORIES_CRT[software]}"
  1418.             LEVEL1_PATH[pubEmail]="${LEVEL1[path]}/${DIRECTORIES_CRT[email]}"
  1419.            
  1420.             writeNewCert ${LEVEL1[domain]}
  1421.            
  1422.             writeNewType 'directories'
  1423.             for index in "${!LEVEL1_PATH[@]}"
  1424.             do
  1425.                 mkdir -p "${LEVEL1_PATH[$index]}" > /dev/null 2>&1
  1426.             done
  1427.             check_result $? 'unable to create directory'
  1428.            
  1429.             writeNewType 'lookup'
  1430.             lookupAdd ${LEVEL1[domain]} ${LEVEL1[path]}
  1431.            
  1432.             writeNewType 'user request configs'
  1433.             makeUserSoftwareCsrFiles \
  1434.                 ${LEVEL1[domain]} \
  1435.                 ${LEVEL1_PATH[crtSoftwareCnfPath]}
  1436.                
  1437.             makeUserEmailCsrFiles \
  1438.                 ${LEVEL1[domain]} \
  1439.                 ${LEVEL1_PATH[crtEmailCnfPath]}
  1440.            
  1441.             makeUserTlsCsrFiles \
  1442.                 ${LEVEL1[domain]} \
  1443.                 ${LEVEL1_PATH[crtTlsCnfPath]}
  1444.            
  1445.             #
  1446.             # sub root CA
  1447.             #
  1448.             writeNewType 'Intermediate CA'
  1449.             # ./
  1450.             local __1__caCsr=${LEVEL1[path]}/$(printf ${FILE_NAME[csr]} ${LEVEL1[domain]} ${DIR_NAME[caRoot]})
  1451.             local __1__caCrt=${LEVEL1[path]}/$(printf ${FILE_NAME[crt]} ${LEVEL1[domain]} ${DIR_NAME[caRoot]})
  1452.             local __1__caChainPem=${LEVEL1[path]}/$(printf ${FILE_NAME[chainPem]} ${LEVEL1[domain]} ${DIR_NAME[caRoot]})
  1453.             # ./db
  1454.             local __1__caCrtDb=${LEVEL1_PATH[caDbPath]}/$(printf ${FILE_NAME[crtDb]} ${LEVEL1[domain]} ${DIR_NAME[caRoot]})
  1455.             local __1__caCrtSrl=${LEVEL1_PATH[caDbPath]}/$(printf ${FILE_NAME[crtSrl]} ${LEVEL1[domain]} ${DIR_NAME[caRoot]})
  1456.             local __1__caCrlSrl=${LEVEL1_PATH[caDbPath]}/$(printf ${FILE_NAME[crlSrl]} ${LEVEL1[domain]} ${DIR_NAME[caRoot]})
  1457.             local __1__caCrl=${LEVEL1_PATH[caDbPath]}/$(printf ${FILE_NAME[crl]} ${LEVEL1[domain]} ${DIR_NAME[caRoot]})
  1458.             # ./etc
  1459.             local __1__caConfig=${LEVEL1_PATH[caCnfPath]}/$(printf ${FILE_NAME[cnf]} ${LEVEL1[domain]} ${DIR_NAME[caRoot]})
  1460.             # ./private
  1461.             local __1__caPwd=${LEVEL1_PATH[caPrvPath]}/$(printf ${FILE_NAME[password]} ${LEVEL1[domain]} ${DIR_NAME[caRoot]})
  1462.             local __1__caKey=${LEVEL1_PATH[caPrvPath]}/$(printf ${FILE_NAME[key]} ${LEVEL1[domain]} ${DIR_NAME[caRoot]})
  1463.            
  1464.             makeConfigFile \
  1465.                 ${LEVEL1[domain]} \
  1466.                 'modulCaConfig' \
  1467.                 $__1__caConfig \
  1468.                 '1'
  1469.            
  1470.             makePasswordFile \
  1471.                 ${LEVEL1[domain]} \
  1472.                 $__1__caPwd
  1473.            
  1474.             makeKeyFile \
  1475.                 ${LEVEL1[domain]} \
  1476.                 $__1__caKey \
  1477.                 $__1__caPwd
  1478.                
  1479.             makeDbFiles \
  1480.                 ${LEVEL1[domain]} \
  1481.                 $__1__caCrtDb \
  1482.                 $__1__caCrtSrl \
  1483.                 $__1__caCrlSrl
  1484.            
  1485.             makeIntermediateCa \
  1486.                 ${LEVEL1[domain]} \
  1487.                 ${LEVEL1[path]} \
  1488.                 $__1__caConfig \
  1489.                 $__1__caCsr \
  1490.                 $__1__caKey \
  1491.                 $__1__caPwd \
  1492.                 $__1__caCrt \
  1493.                 $__1__caCrl \
  1494.                 $__1__caChainPem \
  1495.                 ${LEVEL0[path]} \
  1496.                 $__0__caConfig \
  1497.                 $__0__caPwd \
  1498.                 $__0__caCrt
  1499.                
  1500.             #
  1501.             # tls CA
  1502.             #
  1503.             writeNewType 'TLS CA'
  1504.             # ./
  1505.             local __1__tlsCsr=${LEVEL1[path]}/$(printf ${FILE_NAME[csr]} ${LEVEL1[domain]} ${DIR_NAME[caTls]})
  1506.             local __1__tlsCrt=${LEVEL1[path]}/$(printf ${FILE_NAME[crt]} ${LEVEL1[domain]} ${DIR_NAME[caTls]})
  1507.             local __1__tlsChainPem=${LEVEL1[path]}/$(printf ${FILE_NAME[chainPem]} ${LEVEL1[domain]} ${DIR_NAME[caTls]})
  1508.             # ./db
  1509.             local __1__tlsCrtDb=${LEVEL1_PATH[caTlsDbPath]}/$(printf ${FILE_NAME[crtDb]} ${LEVEL1[domain]} ${DIR_NAME[caTls]})
  1510.             local __1__tlsCrtSrl=${LEVEL1_PATH[caTlsDbPath]}/$(printf ${FILE_NAME[crtSrl]} ${LEVEL1[domain]} ${DIR_NAME[caTls]})
  1511.             local __1__tlsCrlSrl=${LEVEL1_PATH[caTlsDbPath]}/$(printf ${FILE_NAME[crlSrl]} ${LEVEL1[domain]} ${DIR_NAME[caTls]})
  1512.             local __1__tlsCrl=${LEVEL1_PATH[caTlsDbPath]}/$(printf ${FILE_NAME[crl]} ${LEVEL1[domain]} ${DIR_NAME[caTls]})
  1513.             # ./etc
  1514.             local __1__tlsConfig=${LEVEL1_PATH[caTlsCnfPath]}/$(printf ${FILE_NAME[cnf]} ${LEVEL1[domain]} ${DIR_NAME[caTls]})
  1515.             # ./private
  1516.             local __1__tlsPwd=${LEVEL1_PATH[caTlsPrvPath]}/$(printf ${FILE_NAME[password]} ${LEVEL1[domain]} ${DIR_NAME[caTls]})
  1517.             local __1__tlsKey=${LEVEL1_PATH[caTlsPrvPath]}/$(printf ${FILE_NAME[key]} ${LEVEL1[domain]} ${DIR_NAME[caTls]})
  1518.            
  1519.             makeConfigFile \
  1520.                 ${LEVEL1[domain]} \
  1521.                 'modulCaTlsConfig' \
  1522.                 $__1__tlsConfig \
  1523.                 '1'
  1524.            
  1525.             makePasswordFile \
  1526.                 ${LEVEL1[domain]} \
  1527.                 $__1__tlsPwd
  1528.            
  1529.             makeKeyFile \
  1530.                 ${LEVEL1[domain]} \
  1531.                 $__1__tlsKey \
  1532.                 $__1__tlsPwd
  1533.                
  1534.             makeDbFiles \
  1535.                 ${LEVEL1[domain]} \
  1536.                 $__1__tlsCrtDb \
  1537.                 $__1__tlsCrtSrl \
  1538.                 $__1__tlsCrlSrl
  1539.            
  1540.             makeSigningCa \
  1541.                 ${LEVEL1[domain]} \
  1542.                 ${LEVEL1[path]} \
  1543.                 $__1__tlsConfig \
  1544.                 $__1__tlsCsr \
  1545.                 $__1__tlsKey \
  1546.                 $__1__tlsPwd \
  1547.                 $__1__tlsCrt \
  1548.                 $__1__tlsCrl \
  1549.                 $__1__tlsChainPem \
  1550.                 $__1__caConfig \
  1551.                 $__1__caPwd \
  1552.                 $__1__caChainPem
  1553.            
  1554.             #
  1555.             # email CA
  1556.             #
  1557.             writeNewType 'Email CA'
  1558.             # ./
  1559.             local __1__emailCsr=${LEVEL1[path]}/$(printf ${FILE_NAME[csr]} ${LEVEL1[domain]} ${DIR_NAME[caEmail]})
  1560.             local __1__emailCrt=${LEVEL1[path]}/$(printf ${FILE_NAME[crt]} ${LEVEL1[domain]} ${DIR_NAME[caEmail]})
  1561.             local __1__emailChainPem=${LEVEL1[path]}/$(printf ${FILE_NAME[chainPem]} ${LEVEL1[domain]} ${DIR_NAME[caEmail]})
  1562.             # ./db
  1563.             local __1__emailCrtDb=${LEVEL1_PATH[caEmailDbPath]}/$(printf ${FILE_NAME[crtDb]} ${LEVEL1[domain]} ${DIR_NAME[caEmail]})
  1564.             local __1__emailCrtSrl=${LEVEL1_PATH[caEmailDbPath]}/$(printf ${FILE_NAME[crtSrl]} ${LEVEL1[domain]} ${DIR_NAME[caEmail]})
  1565.             local __1__emailCrlSrl=${LEVEL1_PATH[caEmailDbPath]}/$(printf ${FILE_NAME[crlSrl]} ${LEVEL1[domain]} ${DIR_NAME[caEmail]})
  1566.             local __1__emailCrl=${LEVEL1_PATH[caEmailDbPath]}/$(printf ${FILE_NAME[crl]} ${LEVEL1[domain]} ${DIR_NAME[caEmail]})
  1567.             # ./etc
  1568.             local __1__emailConfig=${LEVEL1_PATH[caEmailCnfPath]}/$(printf ${FILE_NAME[cnf]} ${LEVEL1[domain]} ${DIR_NAME[caEmail]})
  1569.             # ./private
  1570.             local __1__emailPwd=${LEVEL1_PATH[caEmailPrvPath]}/$(printf ${FILE_NAME[password]} ${LEVEL1[domain]} ${DIR_NAME[caEmail]})
  1571.             local __1__emailKey=${LEVEL1_PATH[caEmailPrvPath]}/$(printf ${FILE_NAME[key]} ${LEVEL1[domain]} ${DIR_NAME[caEmail]})
  1572.            
  1573.             makeConfigFile \
  1574.                 ${LEVEL1[domain]} \
  1575.                 'modulCaEmailConfig' \
  1576.                 $__1__emailConfig \
  1577.                 '1'
  1578.            
  1579.             makePasswordFile \
  1580.                 ${LEVEL1[domain]} \
  1581.                 $__1__emailPwd
  1582.            
  1583.             makeKeyFile \
  1584.                 ${LEVEL1[domain]} \
  1585.                 $__1__emailKey \
  1586.                 $__1__emailPwd
  1587.                
  1588.             makeDbFiles \
  1589.                 ${LEVEL1[domain]} \
  1590.                 $__1__emailCrtDb \
  1591.                 $__1__emailCrtSrl \
  1592.                 $__1__emailCrlSrl
  1593.            
  1594.             makeSigningCa \
  1595.                 ${LEVEL1[domain]} \
  1596.                 ${LEVEL1[path]} \
  1597.                 $__1__emailConfig \
  1598.                 $__1__emailCsr \
  1599.                 $__1__emailKey \
  1600.                 $__1__emailPwd \
  1601.                 $__1__emailCrt \
  1602.                 $__1__emailCrl \
  1603.                 $__1__emailChainPem \
  1604.                 $__1__caConfig \
  1605.                 $__1__caPwd \
  1606.                 $__1__caChainPem
  1607.  
  1608.             #
  1609.             # software CA
  1610.             #
  1611.             writeNewType 'Software CA'
  1612.             # ./
  1613.             local __1__softwareCsr=${LEVEL1[path]}/$(printf ${FILE_NAME[csr]} ${LEVEL1[domain]} ${DIR_NAME[caSoftware]})
  1614.             local __1__softwareCrt=${LEVEL1[path]}/$(printf ${FILE_NAME[crt]} ${LEVEL1[domain]} ${DIR_NAME[caSoftware]})
  1615.             local __1__softwareChainPem=${LEVEL1[path]}/$(printf ${FILE_NAME[chainPem]} ${LEVEL1[domain]} ${DIR_NAME[caSoftware]})
  1616.             # ./db
  1617.             local __1__softwareCrtDb=${LEVEL1_PATH[caSoftwareDbPath]}/$(printf ${FILE_NAME[crtDb]} ${LEVEL1[domain]} ${DIR_NAME[caSoftware]})
  1618.             local __1__softwareCrtSrl=${LEVEL1_PATH[caSoftwareDbPath]}/$(printf ${FILE_NAME[crtSrl]} ${LEVEL1[domain]} ${DIR_NAME[caSoftware]})
  1619.             local __1__softwareCrlSrl=${LEVEL1_PATH[caSoftwareDbPath]}/$(printf ${FILE_NAME[crlSrl]} ${LEVEL1[domain]} ${DIR_NAME[caSoftware]})
  1620.             local __1__softwareCrl=${LEVEL1_PATH[caSoftwareDbPath]}/$(printf ${FILE_NAME[crl]} ${LEVEL1[domain]} ${DIR_NAME[caSoftware]})
  1621.             # ./etc
  1622.             local __1__softwareConfig=${LEVEL1_PATH[caSoftwareCnfPath]}/$(printf ${FILE_NAME[cnf]} ${LEVEL1[domain]} ${DIR_NAME[caSoftware]})
  1623.             # ./private
  1624.             local __1__softwarePwd=${LEVEL1_PATH[caSoftwarePrvPath]}/$(printf ${FILE_NAME[password]} ${LEVEL1[domain]} ${DIR_NAME[caSoftware]})
  1625.             local __1__softwareKey=${LEVEL1_PATH[caSoftwarePrvPath]}/$(printf ${FILE_NAME[key]} ${LEVEL1[domain]} ${DIR_NAME[caSoftware]})
  1626.            
  1627.             makeConfigFile \
  1628.                 ${LEVEL1[domain]} \
  1629.                 'modulCaSoftwareConfig' \
  1630.                 $__1__softwareConfig \
  1631.                 '1'
  1632.            
  1633.             makePasswordFile \
  1634.                 ${LEVEL1[domain]} \
  1635.                 $__1__softwarePwd
  1636.            
  1637.             makeKeyFile \
  1638.                 ${LEVEL1[domain]} \
  1639.                 $__1__softwareKey \
  1640.                 $__1__softwarePwd
  1641.                
  1642.             makeDbFiles \
  1643.                 ${LEVEL1[domain]} \
  1644.                 $__1__softwareCrtDb \
  1645.                 $__1__softwareCrtSrl \
  1646.                 $__1__softwareCrlSrl
  1647.            
  1648.             makeSigningCa \
  1649.                 ${LEVEL1[domain]} \
  1650.                 ${LEVEL1[path]} \
  1651.                 $__1__softwareConfig \
  1652.                 $__1__softwareCsr \
  1653.                 $__1__softwareKey \
  1654.                 $__1__softwarePwd \
  1655.                 $__1__softwareCrt \
  1656.                 $__1__softwareCrl \
  1657.                 $__1__softwareChainPem \
  1658.                 $__1__caConfig \
  1659.                 $__1__caPwd \
  1660.                 $__1__caChainPem
  1661.  
  1662.             #
  1663.             # LEVEL 2 (subdomains)
  1664.             #
  1665.            
  1666.             # intermediate intermediate CA for subdomain level
  1667.             # ./intermediate/domain/intermediate
  1668.             if [ ! -z "$3" ]; then
  1669.                 level2domains=$(echo $3 | tr ";" "\n")
  1670.                 for level2domain in $level2domains
  1671.                 do
  1672.                     #
  1673.                     # LEVEL 2 (subs)
  1674.                     #
  1675.                     # I don't split anything by '.' - a mail.foo.tld is like bob.mail.foo.tld.
  1676.                     # feel free to create the third level for bob.
  1677.                     #
  1678.                     # in that case
  1679.                     # - intermediate CA @ level 3:
  1680.                     #   - you MUST fork the makeIntermediateIntermediateCa function as makeIntermediateIntermediateIntermediateCa (or whatever);
  1681.                     #   - you MUST redefine export CA_2_SCRIPT_PATH="$baseDir" and export CA_1_SCRIPT_PATH="$rootBaseDir"
  1682.                     #                    as export CA_3_SCRIPT_PATH="$baseDir" and export CA_2_SCRIPT_PATH="$rootBaseDir"
  1683.                     #   - you MUST call makeConfigFile with '4' as the fourth parameter
  1684.                     #   otherwise openssl fails on relative paths. you can walk through the directories - but that's also nasty.
  1685.                     #   @see makeModulCaConfigBlock_default::$level
  1686.                     # - signing CAs @ level 3 are fun: s/2/3/ && s/1/2/
  1687.                     #
  1688.                     declare -A LEVEL2
  1689.                     LEVEL2[domain]="$level2domain.${LEVEL1[domain]}"
  1690.                     LEVEL2[path]="${LEVEL1_PATH[intermediatePath]}/$level2domain"
  1691.                    
  1692.                     declare -A LEVEL2_PATH
  1693.                     # sub sub root ca
  1694.                     LEVEL2_PATH[caPath]="${LEVEL2[path]}/${DIRECTORIES_CA_ROOT[caPath]}"
  1695.                     LEVEL2_PATH[caDbPath]="${LEVEL2[path]}/${DIRECTORIES_CA_ROOT[dbPath]}"
  1696.                     LEVEL2_PATH[caCnfPath]="${LEVEL2[path]}/${DIRECTORIES_CA_ROOT[cnfPath]}"
  1697.                     LEVEL2_PATH[caPrvPath]="${LEVEL2[path]}/${DIRECTORIES_CA_ROOT[privatePath]}"
  1698.                     # email ca
  1699.                     LEVEL2_PATH[caEmailPath]="${LEVEL2[path]}/${DIRECTORIES_CA_EMAIL[caPath]}"
  1700.                     LEVEL2_PATH[caEmailDbPath]="${LEVEL2[path]}/${DIRECTORIES_CA_EMAIL[dbPath]}"
  1701.                     LEVEL2_PATH[caEmailCnfPath]="${LEVEL2[path]}/${DIRECTORIES_CA_EMAIL[cnfPath]}"
  1702.                     LEVEL2_PATH[caEmailPrvPath]="${LEVEL2[path]}/${DIRECTORIES_CA_EMAIL[privatePath]}"
  1703.                     # software ca
  1704.                     LEVEL2_PATH[caSoftwarePath]="${LEVEL2[path]}/${DIRECTORIES_CA_SOFTWARE[caPath]}"
  1705.                     LEVEL2_PATH[caSoftwareDbPath]="${LEVEL2[path]}/${DIRECTORIES_CA_SOFTWARE[dbPath]}"
  1706.                     LEVEL2_PATH[caSoftwareCnfPath]="${LEVEL2[path]}/${DIRECTORIES_CA_SOFTWARE[cnfPath]}"
  1707.                     LEVEL2_PATH[caSoftwarePrvPath]="${LEVEL2[path]}/${DIRECTORIES_CA_SOFTWARE[privatePath]}"
  1708.                     # tls ca
  1709.                     LEVEL2_PATH[caTlsPath]="${LEVEL2[path]}/${DIRECTORIES_CA_TLS[caPath]}"
  1710.                     LEVEL2_PATH[caTlsDbPath]="${LEVEL2[path]}/${DIRECTORIES_CA_TLS[dbPath]}"
  1711.                     LEVEL2_PATH[caTlsCnfPath]="${LEVEL2[path]}/${DIRECTORIES_CA_TLS[cnfPath]}"
  1712.                     LEVEL2_PATH[caTlsPrvPath]="${LEVEL2[path]}/${DIRECTORIES_CA_TLS[privatePath]}"
  1713.                     # email crt
  1714.                     LEVEL2_PATH[crtEmailPath]="${LEVEL2[path]}/${DIRECTORIES_CRT_EMAIL[crtPath]}"
  1715.                     LEVEL2_PATH[crtEmailCnfPath]="${LEVEL2[path]}/${DIRECTORIES_CRT_EMAIL[cnfPath]}"
  1716.                     LEVEL2_PATH[crtEmailPrvPath]="${LEVEL2[path]}/${DIRECTORIES_CRT_EMAIL[privatePath]}"
  1717.                     # software crt
  1718.                     LEVEL2_PATH[crtSoftwarePath]="${LEVEL2[path]}/${DIRECTORIES_CRT_SOFTWARE[crtPath]}"
  1719.                     LEVEL2_PATH[crtSoftwareCnfPath]="${LEVEL2[path]}/${DIRECTORIES_CRT_SOFTWARE[cnfPath]}"
  1720.                     LEVEL2_PATH[crtSoftwarePrvPath]="${LEVEL2[path]}/${DIRECTORIES_CRT_SOFTWARE[privatePath]}"
  1721.                     # tls crt
  1722.                     LEVEL2_PATH[crtTlsPath]="${LEVEL2[path]}/${DIRECTORIES_CRT_TLS[crtPath]}"
  1723.                     LEVEL2_PATH[crtTlsCnfPath]="${LEVEL2[path]}/${DIRECTORIES_CRT_TLS[cnfPath]}"
  1724.                     LEVEL2_PATH[crtTlsPrvPath]="${LEVEL2[path]}/${DIRECTORIES_CRT_TLS[privatePath]}"
  1725.                     # pub
  1726.                     LEVEL2_PATH[pubTls]="${LEVEL2[path]}/${DIRECTORIES_CRT[tls]}"
  1727.                     LEVEL2_PATH[pubSoftware]="${LEVEL2[path]}/${DIRECTORIES_CRT[software]}"
  1728.                     LEVEL2_PATH[pubEmail]="${LEVEL2[path]}/${DIRECTORIES_CRT[email]}"
  1729.            
  1730.                     writeNewCert ${LEVEL2[domain]}
  1731.                    
  1732.                     writeNewType 'directories'
  1733.                     for index in "${!LEVEL2_PATH[@]}"
  1734.                     do
  1735.                         mkdir -p "${LEVEL2_PATH[$index]}" > /dev/null 2>&1
  1736.                     done
  1737.                     check_result $? 'unable to create directory'
  1738.                    
  1739.                     writeNewType 'lookup'
  1740.                     lookupAdd ${LEVEL2[domain]} ${LEVEL2[path]}
  1741.            
  1742.                     writeNewType 'user request configs'
  1743.                     makeUserSoftwareCsrFiles \
  1744.                         ${LEVEL2[domain]} \
  1745.                         ${LEVEL2_PATH[crtSoftwareCnfPath]}
  1746.                        
  1747.                     makeUserEmailCsrFiles \
  1748.                         ${LEVEL2[domain]} \
  1749.                         ${LEVEL2_PATH[crtEmailCnfPath]}
  1750.                    
  1751.                     makeUserTlsCsrFiles \
  1752.                         ${LEVEL2[domain]} \
  1753.                         ${LEVEL2_PATH[crtTlsCnfPath]}
  1754.                    
  1755.                     #
  1756.                     # sub sub root CA
  1757.                     #
  1758.                     writeNewType 'Intermediate CA'
  1759.                     # ./
  1760.                     local __2__caCsr=${LEVEL2[path]}/$(printf ${FILE_NAME[csr]} ${LEVEL2[domain]} ${DIR_NAME[caRoot]})
  1761.                     local __2__caCrt=${LEVEL2[path]}/$(printf ${FILE_NAME[crt]} ${LEVEL2[domain]} ${DIR_NAME[caRoot]})
  1762.                     local __2__caChainPem=${LEVEL2[path]}/$(printf ${FILE_NAME[chainPem]} ${LEVEL2[domain]} ${DIR_NAME[caRoot]})
  1763.                     # ./db
  1764.                     local __2__caCrtDb=${LEVEL2_PATH[caDbPath]}/$(printf ${FILE_NAME[crtDb]} ${LEVEL2[domain]} ${DIR_NAME[caRoot]})
  1765.                     local __2__caCrtSrl=${LEVEL2_PATH[caDbPath]}/$(printf ${FILE_NAME[crtSrl]} ${LEVEL2[domain]} ${DIR_NAME[caRoot]})
  1766.                     local __2__caCrlSrl=${LEVEL2_PATH[caDbPath]}/$(printf ${FILE_NAME[crlSrl]} ${LEVEL2[domain]} ${DIR_NAME[caRoot]})
  1767.                     local __2__caCrl=${LEVEL2_PATH[caDbPath]}/$(printf ${FILE_NAME[crl]} ${LEVEL2[domain]} ${DIR_NAME[caRoot]})
  1768.                     # ./etc
  1769.                     local __2__caConfig=${LEVEL2_PATH[caCnfPath]}/$(printf ${FILE_NAME[cnf]} ${LEVEL2[domain]} ${DIR_NAME[caRoot]})
  1770.                     # ./private
  1771.                     local __2__caPwd=${LEVEL2_PATH[caPrvPath]}/$(printf ${FILE_NAME[password]} ${LEVEL2[domain]} ${DIR_NAME[caRoot]})
  1772.                     local __2__caKey=${LEVEL2_PATH[caPrvPath]}/$(printf ${FILE_NAME[key]} ${LEVEL2[domain]} ${DIR_NAME[caRoot]})
  1773.                    
  1774.                     makeConfigFile \
  1775.                         ${LEVEL2[domain]} \
  1776.                         'modulCaConfig' \
  1777.                         $__2__caConfig \
  1778.                         '2'
  1779.                    
  1780.                     makePasswordFile \
  1781.                         ${LEVEL2[domain]} \
  1782.                         $__2__caPwd
  1783.                    
  1784.                     makeKeyFile \
  1785.                         ${LEVEL2[domain]} \
  1786.                         $__2__caKey \
  1787.                         $__2__caPwd
  1788.                        
  1789.                     makeDbFiles \
  1790.                         ${LEVEL2[domain]} \
  1791.                         $__2__caCrtDb \
  1792.                         $__2__caCrtSrl \
  1793.                         $__2__caCrlSrl
  1794.                    
  1795.                     makeIntermediateIntermediateCa \
  1796.                         ${LEVEL2[domain]} \
  1797.                         ${LEVEL2[path]} \
  1798.                         $__2__caConfig \
  1799.                         $__2__caCsr \
  1800.                         $__2__caKey \
  1801.                         $__2__caPwd \
  1802.                         $__2__caCrt \
  1803.                         $__2__caCrl \
  1804.                         $__2__caChainPem \
  1805.                         ${LEVEL1[path]} \
  1806.                         $__1__caConfig \
  1807.                         $__1__caPwd \
  1808.                         $__1__caChainPem
  1809.                    
  1810.                     #
  1811.                     # tls CA
  1812.                     #
  1813.                     writeNewType 'TLS CA'
  1814.                     # ./
  1815.                     local __2__tlsCsr=${LEVEL2[path]}/$(printf ${FILE_NAME[csr]} ${LEVEL2[domain]} ${DIR_NAME[caTls]})
  1816.                     local __2__tlsCrt=${LEVEL2[path]}/$(printf ${FILE_NAME[crt]} ${LEVEL2[domain]} ${DIR_NAME[caTls]})
  1817.                     local __2__tlsChainPem=${LEVEL2[path]}/$(printf ${FILE_NAME[chainPem]} ${LEVEL2[domain]} ${DIR_NAME[caTls]})
  1818.                     # ./db
  1819.                     local __2__tlsCrtDb=${LEVEL2_PATH[caTlsDbPath]}/$(printf ${FILE_NAME[crtDb]} ${LEVEL2[domain]} ${DIR_NAME[caTls]})
  1820.                     local __2__tlsCrtSrl=${LEVEL2_PATH[caTlsDbPath]}/$(printf ${FILE_NAME[crtSrl]} ${LEVEL2[domain]} ${DIR_NAME[caTls]})
  1821.                     local __2__tlsCrlSrl=${LEVEL2_PATH[caTlsDbPath]}/$(printf ${FILE_NAME[crlSrl]} ${LEVEL2[domain]} ${DIR_NAME[caTls]})
  1822.                     local __2__tlsCrl=${LEVEL2_PATH[caTlsDbPath]}/$(printf ${FILE_NAME[crl]} ${LEVEL2[domain]} ${DIR_NAME[caTls]})
  1823.                     # ./etc
  1824.                     local __2__tlsConfig=${LEVEL2_PATH[caTlsCnfPath]}/$(printf ${FILE_NAME[cnf]} ${LEVEL2[domain]} ${DIR_NAME[caTls]})
  1825.                     # ./private
  1826.                     local __2__tlsPwd=${LEVEL2_PATH[caTlsPrvPath]}/$(printf ${FILE_NAME[password]} ${LEVEL2[domain]} ${DIR_NAME[caTls]})
  1827.                     local __2__tlsKey=${LEVEL2_PATH[caTlsPrvPath]}/$(printf ${FILE_NAME[key]} ${LEVEL2[domain]} ${DIR_NAME[caTls]})
  1828.                    
  1829.                     makeConfigFile \
  1830.                         ${LEVEL2[domain]} \
  1831.                         'modulCaTlsConfig' \
  1832.                         $__2__tlsConfig \
  1833.                         '2'
  1834.                    
  1835.                     makePasswordFile \
  1836.                         ${LEVEL2[domain]} \
  1837.                         $__2__tlsPwd
  1838.                    
  1839.                     makeKeyFile \
  1840.                         ${LEVEL2[domain]} \
  1841.                         $__2__tlsKey \
  1842.                         $__2__tlsPwd
  1843.                        
  1844.                     makeDbFiles \
  1845.                         ${LEVEL2[domain]} \
  1846.                         $__2__tlsCrtDb \
  1847.                         $__2__tlsCrtSrl \
  1848.                         $__2__tlsCrlSrl
  1849.                    
  1850.                     makeSigningCa \
  1851.                         ${LEVEL2[domain]} \
  1852.                         ${LEVEL2[path]} \
  1853.                         $__2__tlsConfig \
  1854.                         $__2__tlsCsr \
  1855.                         $__2__tlsKey \
  1856.                         $__2__tlsPwd \
  1857.                         $__2__tlsCrt \
  1858.                         $__2__tlsCrl \
  1859.                         $__2__tlsChainPem \
  1860.                         $__2__caConfig \
  1861.                         $__2__caPwd \
  1862.                         $__2__caChainPem
  1863.                    
  1864.                     #
  1865.                     # email CA
  1866.                     #
  1867.                     writeNewType 'Email CA'
  1868.                     # ./
  1869.                     local __2__emailCsr=${LEVEL2[path]}/$(printf ${FILE_NAME[csr]} ${LEVEL2[domain]} ${DIR_NAME[caEmail]})
  1870.                     local __2__emailCrt=${LEVEL2[path]}/$(printf ${FILE_NAME[crt]} ${LEVEL2[domain]} ${DIR_NAME[caEmail]})
  1871.                     local __2__emailChainPem=${LEVEL2[path]}/$(printf ${FILE_NAME[chainPem]} ${LEVEL2[domain]} ${DIR_NAME[caEmail]})
  1872.                     # ./db
  1873.                     local __2__emailCrtDb=${LEVEL2_PATH[caEmailDbPath]}/$(printf ${FILE_NAME[crtDb]} ${LEVEL2[domain]} ${DIR_NAME[caEmail]})
  1874.                     local __2__emailCrtSrl=${LEVEL2_PATH[caEmailDbPath]}/$(printf ${FILE_NAME[crtSrl]} ${LEVEL2[domain]} ${DIR_NAME[caEmail]})
  1875.                     local __2__emailCrlSrl=${LEVEL2_PATH[caEmailDbPath]}/$(printf ${FILE_NAME[crlSrl]} ${LEVEL2[domain]} ${DIR_NAME[caEmail]})
  1876.                     local __2__emailCrl=${LEVEL2_PATH[caEmailDbPath]}/$(printf ${FILE_NAME[crl]} ${LEVEL2[domain]} ${DIR_NAME[caEmail]})
  1877.                     # ./etc
  1878.                     local __2__emailConfig=${LEVEL2_PATH[caEmailCnfPath]}/$(printf ${FILE_NAME[cnf]} ${LEVEL2[domain]} ${DIR_NAME[caEmail]})
  1879.                     # ./private
  1880.                     local __2__emailPwd=${LEVEL2_PATH[caEmailPrvPath]}/$(printf ${FILE_NAME[password]} ${LEVEL2[domain]} ${DIR_NAME[caEmail]})
  1881.                     local __2__emailKey=${LEVEL2_PATH[caEmailPrvPath]}/$(printf ${FILE_NAME[key]} ${LEVEL2[domain]} ${DIR_NAME[caEmail]})
  1882.                    
  1883.                     makeConfigFile \
  1884.                         ${LEVEL2[domain]} \
  1885.                         'modulCaEmailConfig' \
  1886.                         $__2__emailConfig \
  1887.                         '2'
  1888.                    
  1889.                     makePasswordFile \
  1890.                         ${LEVEL2[domain]} \
  1891.                         $__2__emailPwd
  1892.                    
  1893.                     makeKeyFile \
  1894.                         ${LEVEL2[domain]} \
  1895.                         $__2__emailKey \
  1896.                         $__2__emailPwd
  1897.                        
  1898.                     makeDbFiles \
  1899.                         ${LEVEL2[domain]} \
  1900.                         $__2__emailCrtDb \
  1901.                         $__2__emailCrtSrl \
  1902.                         $__2__emailCrlSrl
  1903.                    
  1904.                     makeSigningCa \
  1905.                         ${LEVEL2[domain]} \
  1906.                         ${LEVEL2[path]} \
  1907.                         $__2__emailConfig \
  1908.                         $__2__emailCsr \
  1909.                         $__2__emailKey \
  1910.                         $__2__emailPwd \
  1911.                         $__2__emailCrt \
  1912.                         $__2__emailCrl \
  1913.                         $__2__emailChainPem \
  1914.                         $__2__caConfig \
  1915.                         $__2__caPwd \
  1916.                         $__2__caChainPem
  1917.  
  1918.                     #
  1919.                     # software CA
  1920.                     #
  1921.                     writeNewType 'Software CA'
  1922.                     # ./
  1923.                     local __2__softwareCsr=${LEVEL2[path]}/$(printf ${FILE_NAME[csr]} ${LEVEL2[domain]} ${DIR_NAME[caSoftware]})
  1924.                     local __2__softwareCrt=${LEVEL2[path]}/$(printf ${FILE_NAME[crt]} ${LEVEL2[domain]} ${DIR_NAME[caSoftware]})
  1925.                     local __2__softwareChainPem=${LEVEL2[path]}/$(printf ${FILE_NAME[chainPem]} ${LEVEL2[domain]} ${DIR_NAME[caSoftware]})
  1926.                     # ./db
  1927.                     local __2__softwareCrtDb=${LEVEL2_PATH[caSoftwareDbPath]}/$(printf ${FILE_NAME[crtDb]} ${LEVEL2[domain]} ${DIR_NAME[caSoftware]})
  1928.                     local __2__softwareCrtSrl=${LEVEL2_PATH[caSoftwareDbPath]}/$(printf ${FILE_NAME[crtSrl]} ${LEVEL2[domain]} ${DIR_NAME[caSoftware]})
  1929.                     local __2__softwareCrlSrl=${LEVEL2_PATH[caSoftwareDbPath]}/$(printf ${FILE_NAME[crlSrl]} ${LEVEL2[domain]} ${DIR_NAME[caSoftware]})
  1930.                     local __2__softwareCrl=${LEVEL2_PATH[caSoftwareDbPath]}/$(printf ${FILE_NAME[crl]} ${LEVEL2[domain]} ${DIR_NAME[caSoftware]})
  1931.                     # ./etc
  1932.                     local __2__softwareConfig=${LEVEL2_PATH[caSoftwareCnfPath]}/$(printf ${FILE_NAME[cnf]} ${LEVEL2[domain]} ${DIR_NAME[caSoftware]})
  1933.                     # ./private
  1934.                     local __2__softwarePwd=${LEVEL2_PATH[caSoftwarePrvPath]}/$(printf ${FILE_NAME[password]} ${LEVEL2[domain]} ${DIR_NAME[caSoftware]})
  1935.                     local __2__softwareKey=${LEVEL2_PATH[caSoftwarePrvPath]}/$(printf ${FILE_NAME[key]} ${LEVEL2[domain]} ${DIR_NAME[caSoftware]})
  1936.                    
  1937.                     makeConfigFile \
  1938.                         ${LEVEL2[domain]} \
  1939.                         'modulCaSoftwareConfig' \
  1940.                         $__2__softwareConfig \
  1941.                         '2'
  1942.                    
  1943.                     makePasswordFile \
  1944.                         ${LEVEL2[domain]} \
  1945.                         $__2__softwarePwd
  1946.                    
  1947.                     makeKeyFile \
  1948.                         ${LEVEL2[domain]} \
  1949.                         $__2__softwareKey \
  1950.                         $__2__softwarePwd
  1951.                        
  1952.                     makeDbFiles \
  1953.                         ${LEVEL2[domain]} \
  1954.                         $__2__softwareCrtDb \
  1955.                         $__2__softwareCrtSrl \
  1956.                         $__2__softwareCrlSrl
  1957.                    
  1958.                     makeSigningCa \
  1959.                         ${LEVEL2[domain]} \
  1960.                         ${LEVEL2[path]} \
  1961.                         $__2__softwareConfig \
  1962.                         $__2__softwareCsr \
  1963.                         $__2__softwareKey \
  1964.                         $__2__softwarePwd \
  1965.                         $__2__softwareCrt \
  1966.                         $__2__softwareCrl \
  1967.                         $__2__softwareChainPem \
  1968.                         $__2__caConfig \
  1969.                         $__2__caPwd \
  1970.                         $__2__caChainPem
  1971.                 done
  1972.             fi
  1973.         done
  1974.     fi
  1975. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement