Advertisement
xe1phix

Xe1phix-[OCSPTool]-Cheatsheet-[v4.8.5].sh

Jun 28th, 2023
671
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.43 KB | Cybersecurity | 0 0
  1. #!/bin/sh
  2. ##-===================================================-##
  3. ##   [+] Xe1phix-[OCSPTool]-Cheatsheet-[v4.8.5].sh
  4. ##-===================================================-##
  5. ##
  6. ##
  7. ##-===============================================================================-##
  8. ##   [+] generate an OCSP request for a certificate and to verify the response
  9. ##-===============================================================================-##
  10.  
  11.  
  12.  
  13. ##-=======================================================================-##
  14. ##   [+] Use gnutls-cli to get a copy of the server certificate chain:
  15. ##-=======================================================================-##
  16. echo | gnutls-cli -p 443 $Domain --save-cert $Chain.pem
  17.  
  18.  
  19.  
  20. ##-=============================-##
  21. ##   [+] Verify The Response
  22. ##-=============================-##
  23. certtool -i < $Chain.pem
  24.  
  25.  
  26. ##-=======================================================-##
  27. ##   [+] Request Information on the Chain Certificates.
  28. ##-=======================================================-##
  29. ocsptool --ask --load-chain $Chain.pem
  30.  
  31.  
  32. ##-=======================================================-##
  33. ##   [+] Ask information on a particular certificate
  34. ##-=======================================================-##
  35. ## ------------------------------------------------------- ##
  36. ##   [?] using --load-cert and --load-issuer
  37. ## ------------------------------------------------------- ##
  38. ocsptool --ask http://ocsp.CAcert.org/ --load-chain $Chain.pem
  39.  
  40.  
  41.  
  42. ##-======================================================-##
  43. ##   [+] Parse  an OCSP request and print information:
  44. ##-======================================================-##
  45. ## -------------------------------------------------------------------- ##
  46. ##   [?] specify the name of the file containing the OCSP request
  47. ## -------------------------------------------------------------------- ##
  48. ##   [?] It should contain the OCSP request in binary DER format.
  49. ## -------------------------------------------------------------------- ##
  50. ocsptool -i -Q $OCSPRequest.der
  51.  
  52.  
  53. ## ---------------------------------------------------------------------- ##
  54. ##   [?] The input file may also be sent to standard input like this:
  55. ## ---------------------------------------------------------------------- ##
  56. cat $OCSPRequest.der | ocsptool --request-info
  57.  
  58.  
  59.  
  60. ##-==================================================-##
  61. ##   [+] Print information about an OCSP response:
  62. ##-==================================================-##
  63.  
  64. ##-================================-##
  65. ##   [+] Parse an OCSP Response
  66. ##-================================-##
  67. ocsptool -j -Q $OCSPRequest.der
  68. cat $OCSPRequest.der | ocsptool --response-info
  69.  
  70.  
  71.  
  72.  
  73.  
  74. ##-==================================-##
  75. ##   [+] Generate an OCSP request
  76. ##-==================================-##
  77. ocsptool -q --load-issuer $Issuer.pem --load-cert $Client.pem --outfile $OCSPRequest.der
  78.  
  79.  
  80. ##-===========================================-##
  81. ##   [+] Verify signature in OCSP response
  82. ##-===========================================-##
  83. ##
  84. ## ------------------------------------------------------------------------- ##
  85. ##   [?] The OCSP response is verified against a set of trust anchors
  86. ## ------------------------------------------------------------------------- ##
  87. ##
  88. ## ------------------------------------------------------------------------- ##
  89. ##   [?] The trust anchors are concatenated certificates in PEM format.
  90. ## ------------------------------------------------------------------------- ##
  91. ##
  92. ## ------------------------------------------------------------------------- ##
  93. ##   [?] The certificate that signed the OCSP response
  94. ##       needs to be in the set of trust anchors
  95. ## ------------------------------------------------------------------------- ##
  96. ##
  97. ##
  98. ##                          or
  99. ##
  100. ## ----------------------------------------------------- ##
  101. ##   [?] The issuer of the signer certificate
  102. ##       needs to be in the set of trust anchors
  103. ##       and the OCSP Extended Key Usage bit has to
  104. ##       be asserted in the signer certificate.
  105. ## ----------------------------------------------------- ##
  106. ocsptool -e --load-trust $Issuer.pem --load-response $OCSPResponse.der
  107.  
  108.  
  109.  
  110.  
  111. ##-=====================================================================-##
  112. ##   [+] Verify signature in OCSP response against given certificate
  113. ##-=====================================================================-##
  114. ocsptool -e --load-signer $OCSPSigner.pem --load-response $OCSPResponse.der
  115.  
  116.  
  117.  
  118.  
  119. ##-================================-##
  120. ##   [+] Certificate information
  121. ##-================================-##
  122. certtool --certificate-info --infile $Cert.pem
  123.  
  124.  
  125.  
  126. ##-========================================-##
  127. ##   [+] PKCS #12 structure generation
  128. ##-========================================-##
  129. certtool --load-certificate $Cert.pem --load-privkey $Key.pem --to-p12 --outder --outfile $Key.p12
  130.  
  131. certtool --load-ca-certificate $CA.pem --load-certificate $Cert.pem --load-privkey $Key.pem --to-p12 --outder --outfile $Key.p12
  132.  
  133.  
  134. ##-================================-##
  135. ##   [+] Verifying a certificate
  136. ##-================================-##
  137. certtool --verify --infile $Cert.pem
  138.  
  139. certtool --verify --verify-hostname $HostName --infile $Cert.pem
  140.  
  141.  
  142.  
  143.  
  144.  
  145. certtool --pubkey-info --infile $Key.pem
  146. certtool --certificate-info $Cert.pem
  147. certtool --fingerprint $Key.pem
  148.  
  149.  
  150.  
  151. certtool --generate-self-signed
  152.  
  153.  
  154.  
  155.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement