Advertisement
Guest User

Make-new-OpenSSL-PoC-CA.sh

a guest
Jan 3rd, 2017
1,796
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 8.00 KB | None | 0 0
  1. mkdir -p -- private
  2. chmod 700 -- private
  3.  
  4. echo 1000 > serial
  5. echo 1000 > crlnumber
  6. touch index.txt
  7.  
  8. openssl req -x509 -nodes -days 999 -subj '/CN=MyDemoCAServer' -newkey rsa:2048 -keyout private/cakey.pem -out cacert.pem
  9. chmod 400 -- private/cakey.pem
  10.  
  11.  
  12. cat > openssl.cnf << 'HereDocENDopensslcnf'
  13. #Sample file from https://www.phildev.net/ssl/opensslconf.html, https://archive.is/2ErFc
  14. HOME                    = .
  15. RANDFILE                = $ENV::HOME/.rnd
  16.  
  17. ####################################################################
  18. # CA Definition
  19. [ ca ]
  20. default_ca      = CA_default            # The default ca section
  21.  
  22. ####################################################################
  23. # Per the above, this is where we define CA values
  24. [ CA_default ]
  25.  
  26. dir             = .                     # Where everything is kept
  27. certs           = $dir/certsdb          # Where the issued certs are kept
  28. new_certs_dir   = $certs                # default place for new certs.
  29. database        = $dir/index.txt        # database index file.
  30. certificate     = $dir/cacert.pem       # The CA certificate
  31. private_key     = $dir/private/cakey.pem# The private key
  32. serial          = $dir/serial           # The current serial number
  33. RANDFILE        = $dir/private/.rand    # private random number file
  34.  
  35. crldir          = $dir/crl
  36. crlnumber       = $dir/crlnumber        # the current crl number
  37. crl             = $crldir/crl.pem       # The current CRL
  38.  
  39. # By default we use "user certificate" extensions when signing
  40. x509_extensions = usr_cert              # The extentions to add to the cert
  41.  
  42. # Honor extensions requested of us
  43. copy_extensions = copy
  44.  
  45. # Comment out the following two lines for the "traditional"
  46. # (and highly broken) format.
  47. name_opt        = ca_default            # Subject Name options
  48. cert_opt        = ca_default            # Certificate field options
  49.  
  50. # Extensions to add to a CRL. Note: Netscape communicator chokes on V2 CRLs
  51. # so this is commented out by default to leave a V1 CRL.
  52. # crlnumber must also be commented out to leave a V1 CRL.
  53. #crl_extensions        = crl_ext
  54. default_days    = 365                   # how long to certify for
  55. default_crl_days= 30                    # how long before next CRL
  56. default_md      = sha1                  # which md to use.
  57. preserve        = no                    # keep passed DN ordering
  58.  
  59. # A few difference way of specifying how similar the request should look
  60. # For type CA, the listed attributes must be the same, and the optional
  61. # and supplied fields are just that :-)
  62. policy          = policy_match
  63.  
  64. ####################################################################
  65. # The default policy for the CA when signing requests, requires some
  66. # resemblence to the CA cert
  67. #
  68. [ policy_match ]
  69. countryName             = match         # Must be the same as the CA
  70. stateOrProvinceName     = match         # Must be the same as the CA
  71. organizationName        = match         # Must be the same as the CA
  72. organizationalUnitName  = optional      # not required
  73. commonName              = supplied      # must be there, whatever it is
  74. emailAddress            = optional      # not required
  75.  
  76. ####################################################################
  77. # An alternative policy not referred to anywhere in this file. Can
  78. # be used by specifying '-policy policy_anything' to ca(8).
  79. #
  80. [ policy_anything ]
  81. countryName             = optional
  82. stateOrProvinceName     = optional
  83. localityName            = optional
  84. organizationName        = optional
  85. organizationalUnitName  = optional
  86. commonName              = supplied
  87. emailAddress            = optional
  88.  
  89. ####################################################################
  90. # This is where we define how to generate CSRs
  91. [ req ]
  92. default_bits            = 2048
  93. default_keyfile         = privkey.pem
  94. distinguished_name      = req_distinguished_name # where to get DN for reqs
  95. attributes              = req_attributes         # req attributes
  96. x509_extensions     = v3_ca  # The extentions to add to self signed certs
  97. req_extensions      = v3_req # The extensions to add to req's
  98.  
  99. # This sets a mask for permitted string types. There are several options.
  100. # default: PrintableString, T61String, BMPString.
  101. # pkix   : PrintableString, BMPString.
  102. # utf8only: only UTF8Strings.
  103. # nombstr : PrintableString, T61String (no BMPStrings or UTF8Strings).
  104. # MASK:XXXX a literal mask value.
  105. # WARNING: current versions of Netscape crash on BMPStrings or UTF8Strings
  106. # so use this option with caution!
  107. string_mask = nombstr
  108.  
  109.  
  110. ####################################################################
  111. # Per "req" section, this is where we define DN info
  112. [ req_distinguished_name ]
  113. countryName                     = Country Name (2 letter code)
  114. countryName_default             = US
  115. countryName_min                 = 2
  116. countryName_max                 = 2
  117.  
  118. stateOrProvinceName             = State or Province Name (full name)
  119. stateOrProvinceName_default     = California
  120.  
  121. localityName                    = Locality Name (eg, city)
  122. localityName_default            = Hawthorne
  123.  
  124. 0.organizationName              = Organization Name (eg, company)
  125. 0.organizationName_default      = PhilNet
  126.  
  127. organizationalUnitName          = Organizational Unit Name (eg, section)
  128.  
  129. commonName                      = Common Name (eg, YOUR name)
  130. commonName_max                  = 64
  131.  
  132. emailAddress                    = Email Address
  133. emailAddress_max                = 64
  134.  
  135.  
  136. ####################################################################
  137. # We don't want these, but the section must exist
  138. [ req_attributes ]
  139. #challengePassword              = A challenge password
  140. #challengePassword_min          = 4
  141. #challengePassword_max          = 20
  142. #unstructuredName               = An optional company name
  143.  
  144.  
  145. ####################################################################
  146. # Extensions for when we sign normal certs (specified as default)
  147. [ usr_cert ]
  148.  
  149. # User certs aren't CAs, by definition
  150. basicConstraints=CA:false
  151.  
  152. # Here are some examples of the usage of nsCertType. If it is omitted
  153. # the certificate can be used for anything *except* object signing.
  154. # This is OK for an SSL server.
  155. #nsCertType = server
  156. # For an object signing certificate this would be used.
  157. #nsCertType = objsign
  158. # For normal client use this is typical
  159. #nsCertType = client, email
  160. # and for everything including object signing:
  161. #nsCertType = client, email, objsign
  162. # This is typical in keyUsage for a client certificate.
  163. #keyUsage = nonRepudiation, digitalSignature, keyEncipherment
  164.  
  165. # PKIX recommendations harmless if included in all certificates.
  166. subjectKeyIdentifier=hash
  167. authorityKeyIdentifier=keyid,issuer
  168.  
  169. # This stuff is for subjectAltName and issuerAltname.
  170. # Import the email address.
  171. #subjectAltName=email:copy
  172. # An alternative to produce certificates that aren't
  173. # deprecated according to PKIX.
  174. #subjectAltName=email:move
  175.  
  176.  
  177. ####################################################################
  178. # Extension for requests
  179. [ v3_req ]
  180. # Lets at least make our requests PKIX complaint
  181. subjectAltName=email:move
  182.  
  183.  
  184. ####################################################################
  185. # An alternative section of extensions, not referred to anywhere
  186. # else in the config. We'll use this via '-extensions v3_ca' when
  187. # using ca(8) to sign another CA.
  188. #
  189. [ v3_ca ]
  190.  
  191. # PKIX recommendation.
  192. subjectKeyIdentifier=hash
  193. authorityKeyIdentifier=keyid:always,issuer:always
  194.  
  195. # This is what PKIX recommends but some broken software chokes on critical
  196. # extensions.
  197. #basicConstraints = critical,CA:true
  198. # So we do this instead.
  199. basicConstraints = CA:true
  200.  
  201. # Key usage: this is typical for a CA certificate. However since it will
  202. # prevent it being used as an test self-signed certificate it is best
  203. # left out by default.
  204. # keyUsage = cRLSign, keyCertSign
  205.  
  206. # Some might want this also
  207. # nsCertType = sslCA, emailCA
  208.  
  209. # Include email address in subject alt name: another PKIX recommendation
  210. #subjectAltName=email:move
  211. # Copy issuer details
  212. #issuerAltName=issuer:copy
  213. HereDocENDopensslcnf
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement