Advertisement
fruffl

CA certificate chain factory

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