Advertisement
xe1phix

Xe1phix-[Certtool]-Cheatsheet-[v7.4.95].sh

Nov 10th, 2022
1,027
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 8.72 KB | None | 0 0
  1. #!/bin/sh
  2. ##-===================================================-##
  3. ##   [+] Xe1phix-Certtool-Cheatsheet-[v7.4.95].sh
  4. ##-===================================================-##
  5. ##
  6. ##
  7.  
  8.  
  9. ##-=======================================-##
  10. ##   [+] Print Public Key Information:
  11. ##-=======================================-##
  12. certtool --pubkey-info --infile $Key.pem
  13.  
  14.  
  15. ##-=======================================-##
  16. ##    [+] View Certificate Information
  17. ##-=======================================-##
  18. certtool --certificate-info --infile $Cert.pem
  19.  
  20.  
  21. ##-==================================-##
  22. ##   [+] Fingerprint Certificate:
  23. ##-==================================-##
  24. certtool --fingerprint $Key.pem
  25.  
  26.  
  27. ##-====================================-##
  28. ##    [+] Create An RSA Private Key:
  29. ##-====================================-##
  30. certtool --generate-privkey --rsa --outfile $Key.pem
  31.  
  32.  
  33. ##-==========================================-##
  34. ##    [+] Create Self-Signed Certificate
  35. ##-==========================================-##
  36. certtool --generate-privkey --outfile $Key.pem
  37. certtool --generate-self-signed --load-privkey $Key.pem --outfile $Key.pem
  38. certtool --generate-certificate --load-request $Request.pem --outfile $Cert.pem --load-ca-certificate $CACert.pem --load-ca-privkey $CAKey.pem
  39.  
  40.  
  41. ##-========================================================-##
  42. ##    [+] Generate A Certificate Using The Private Key
  43. ##-========================================================-##
  44. certtool --generate-certificate --load-privkey $Key.pem --outfile $Cert.pem --load-ca-certificate $CACert.pem --load-ca-privkey $CAKey.pem
  45.  
  46.  
  47. ##-==========================================-##
  48. ##    [+] Generate A Certificate Request:
  49. ##-==========================================-##
  50. ## ----------------------------------------------------------- ##
  51. ##    [?]  When the private key is stored in a smart card
  52. ## ----------------------------------------------------------- ##
  53. certtool --generate-request --load-privkey "pkcs11:..." --load-pubkey "pkcs11:..."
  54.  
  55.  
  56. ##-=======================================-##
  57. ##    [+] Generate a PKCS #12 Structure
  58. ##-=======================================-##
  59. ## ------------------------------------------------- ##
  60. ##    [?] Using the previous key and certificate
  61. ## ------------------------------------------------- ##
  62. certtool --load-certificate $Cert.pem --load-privkey $Key.pem --to-p12 --outder --outfile $Key.p12
  63. certtool --load-ca-certificate $CA.pem --load-certificate $Cert.pem --load-privkey $Key.pem --to-p12 --outder --outfile $Key.p12
  64. certtool --load-ca-certificate $CACert.pem --load-certificate $Cert.pem --load-privkey $Key.pem --to-p12 --outder --outfile $Key.p12
  65.  
  66.  
  67. ##-=============================================================-##
  68. ##    [+] Generate Diffie-Hellman Key Exchange Parameters:
  69. ##-=============================================================-##
  70. certtool --generate-dh-params --outfile $DH.pem --sec-param medium
  71. certtool --generate-privkey > $Key.pem
  72. certtool --generate-proxy --load-ca-privkey $Key.pem --load-privkey $ProxyKey.pem --load-certificate $Cert.pem --outfile $ProxyCert.pem
  73.  
  74.  
  75. ##-================================-##
  76. ##   [+] Verifying a certificate
  77. ##-================================-##
  78. certtool --verify --infile $Cert.pem
  79. certtool --verify --verify-hostname $HostName --infile $Cert.pem
  80.  
  81.  
  82. ##-=============================================================-##
  83. ##    [+] Certificate Revocation List (CRL) Generation
  84. ##-=============================================================-##
  85. ## ------------------------------------------------------------- ##
  86. ##    [?] Create an empty Certificate Revocation List (CRL):
  87. ## ------------------------------------------------------------- ##
  88. certtool --generate-crl --load-ca-privkey $x509CAKey.pem --load-ca-certificate $x509CA.pem
  89.  
  90. ## ------------------------------------------------------------- ##
  91. ##    [?] Create a CRL that contains revoked certificates
  92. ## ------------------------------------------------------------- ##
  93. certtool --generate-crl --load-ca-privkey $x509CAKey.pem --load-ca-certificate $x509CA.pem --load-certificate $RevokedCerts.pem
  94.  
  95.  
  96.  
  97. ##-======================================================-##
  98. ##    [+] Verify A Certificate Revocation List (CRL):
  99. ##-======================================================-##
  100. certtool --verify-crl --load-ca-certificate $x509CACert.pem < $CRL.pem
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108. ##-===============================================================================-##
  109. ##   [+] generate an OCSP request for a certificate and to verify the response
  110. ##-===============================================================================-##
  111.  
  112.  
  113.  
  114. ##-=======================================================================-##
  115. ##   [+] Use gnutls-cli to get a copy of the server certificate chain:
  116. ##-=======================================================================-##
  117. echo | gnutls-cli -p 443 $Domain --save-cert $Chain.pem
  118.  
  119.  
  120.  
  121. ##-=============================-##
  122. ##   [+] Verify The Response
  123. ##-=============================-##
  124. certtool -i < $Chain.pem
  125.  
  126.  
  127. ##-=======================================================-##
  128. ##   [+] Request Information on the Chain Certificates.
  129. ##-=======================================================-##
  130. ocsptool --ask --load-chain $Chain.pem
  131.  
  132.  
  133. ##-=======================================================-##
  134. ##   [+] Ask information on a particular certificate
  135. ##-=======================================================-##
  136. ## ------------------------------------------------------- ##
  137. ##   [?] using --load-cert and --load-issuer
  138. ## ------------------------------------------------------- ##
  139. ocsptool --ask http://ocsp.CAcert.org/ --load-chain $Chain.pem
  140.  
  141.  
  142.  
  143. ##-======================================================-##
  144. ##   [+] Parse  an OCSP request and print information:
  145. ##-======================================================-##
  146. ## -------------------------------------------------------------------- ##
  147. ##   [?] specify the name of the file containing the OCSP request
  148. ## -------------------------------------------------------------------- ##
  149. ##   [?] It should contain the OCSP request in binary DER format.
  150. ## -------------------------------------------------------------------- ##
  151. ocsptool -i -Q $OCSPRequest.der
  152.  
  153.  
  154. ## ---------------------------------------------------------------------- ##
  155. ##   [?] The input file may also be sent to standard input like this:
  156. ## ---------------------------------------------------------------------- ##
  157. cat $OCSPRequest.der | ocsptool --request-info
  158.  
  159.  
  160.  
  161. ##-==================================================-##
  162. ##   [+] Print information about an OCSP response:
  163. ##-==================================================-##
  164.  
  165. ##-================================-##
  166. ##   [+] Parse an OCSP Response
  167. ##-================================-##
  168. ocsptool -j -Q $OCSPRequest.der
  169. cat $OCSPRequest.der | ocsptool --response-info
  170.  
  171.  
  172.  
  173.  
  174.  
  175. ##-==================================-##
  176. ##   [+] Generate an OCSP request
  177. ##-==================================-##
  178. ocsptool -q --load-issuer $Issuer.pem --load-cert $Client.pem --outfile $OCSPRequest.der
  179.  
  180.  
  181. ##-===========================================-##
  182. ##   [+] Verify signature in OCSP response
  183. ##-===========================================-##
  184. ##
  185. ## ------------------------------------------------------------------------- ##
  186. ##   [?] The OCSP response is verified against a set of trust anchors
  187. ## ------------------------------------------------------------------------- ##
  188. ##
  189. ## ------------------------------------------------------------------------- ##
  190. ##   [?] The trust anchors are concatenated certificates in PEM format.
  191. ## ------------------------------------------------------------------------- ##
  192. ##
  193. ## ------------------------------------------------------------------------- ##
  194. ##   [?] The certificate that signed the OCSP response
  195. ##       needs to be in the set of trust anchors
  196. ## ------------------------------------------------------------------------- ##
  197. ##
  198. ##
  199. ##                          or
  200. ##
  201. ## ----------------------------------------------------- ##
  202. ##   [?] The issuer of the signer certificate
  203. ##       needs to be in the set of trust anchors
  204. ##       and the OCSP Extended Key Usage bit has to
  205. ##       be asserted in the signer certificate.
  206. ## ----------------------------------------------------- ##
  207. ocsptool -e --load-trust $Issuer.pem --load-response $OCSPResponse.der
  208.  
  209.  
  210.  
  211. ##-=====================================================================-##
  212. ##   [+] Verify signature in OCSP response against given certificate
  213. ##-=====================================================================-##
  214. ocsptool -e --load-signer $OCSPSigner.pem --load-response $OCSPResponse.der
  215.  
  216.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement