/bash_completion.d/openssl

http://github.com/brinkman83/bashrc · #! · 251 lines · 240 code · 11 blank · 0 comment · 0 complexity · 6dc17627e7e0f0e20c36595e66c75393 MD5 · raw file

  1. # bash completion for openssl
  2. have openssl && {
  3. _openssl_sections()
  4. {
  5. local config f
  6. # check if a specific configuration file is used
  7. for (( i=2; i < COMP_CWORD; i++ )); do
  8. if [[ "${COMP_WORDS[i]}" == -config ]]; then
  9. config=${COMP_WORDS[i+1]}
  10. break
  11. fi
  12. done
  13. # if no config given, check some usual default locations
  14. if [ -z "$config" ]; then
  15. for f in /etc/ssl/openssl.cnf /etc/pki/tls/openssl.cnf \
  16. /usr/share/ssl/openssl.cnf; do
  17. [ -f $f ] && config=$f && break
  18. done
  19. fi
  20. [ ! -f "$config" ] && return 0
  21. COMPREPLY=( $( compgen -W "$( awk '/\[.*\]/ {print $2}' $config )" \
  22. -- "$cur" ) )
  23. }
  24. _openssl()
  25. {
  26. local cur prev commands command options formats
  27. COMPREPLY=()
  28. cur=`_get_cword`
  29. commands='asn1parse ca ciphers crl crl2pkcs7 dgst dh dhparam dsa \
  30. dsaparam ec ecparam enc engine errstr gendh gendsa genrsa \
  31. nseq ocsp passwd pkcs12 pkcs7 pkcs8 prime rand req rsa \
  32. rsautl s_client s_server s_time sess_id smime speed spkac \
  33. verify version x509 md2 md4 md5 rmd160 sha sha1 aes-128-cbc \
  34. aes-128-ecb aes-192-cbc aes-192-ecb aes-256-cbc aes-256-ecb \
  35. base64 bf bf-cbc bf-cfb bf-ecb bf-ofb camellia-128-cbc \
  36. camellia-128-ecb camellia-192-cbc camellia-192-ecb \
  37. camellia-256-cbc camellia-256-ecb cast cast-cbc cast5-cbc \
  38. cast5-cfb cast5-ecb cast5-ofb des des-cbc des-cfb des-ecb \
  39. des-ede des-ede-cbc des-ede-cfb des-ede-ofb des-ede3 \
  40. des-ede3-cbc des-ede3-cfb des-ede3-ofb des-ofb des3 desx rc2 \
  41. rc2-40-cbc rc2-64-cbc rc2-cbc rc2-cfb rc2-ecb rc2-ofb rc4 \
  42. rc4-40'
  43. if [ $COMP_CWORD -eq 1 ]; then
  44. COMPREPLY=( $( compgen -W "$commands" -- "$cur" ) )
  45. else
  46. command=${COMP_WORDS[1]}
  47. prev=${COMP_WORDS[COMP_CWORD-1]}
  48. case $prev in
  49. -@(CA|CAfile|CAkey|CAserial|cert|certfile|config|content|dcert|dkey|dhparam|extfile|in|inkey|kfile|key|keyout|out|oid|prvrify|rand|recip|revoke|sess_in|sess_out|spkac|sign|signkey|signer|signature|ss_cert|untrusted|verify))
  50. _filedir
  51. return 0
  52. ;;
  53. -@(outdir|CApath))
  54. _filedir -d
  55. return 0
  56. ;;
  57. -@(name|crlexts|extensions))
  58. _openssl_sections
  59. return 0
  60. ;;
  61. -@(in|out|key|cert|CA|CAkey|dkey|dcert)form)
  62. formats='DER PEM'
  63. case $command in
  64. x509)
  65. formats="$formats NET"
  66. ;;
  67. smime)
  68. formats="$formats SMIME"
  69. ;;
  70. esac
  71. COMPREPLY=( $( compgen -W "$formats" -- "$cur" ) )
  72. return 0
  73. ;;
  74. -connect)
  75. _known_hosts_real "$cur"
  76. return 0
  77. ;;
  78. -starttls)
  79. COMPREPLY=( $( compgen -W 'smtp pop3 imap ftp' \
  80. -- "$cur" ) )
  81. return 0
  82. ;;
  83. -cipher)
  84. COMPREPLY=( $( compgen -W "$(openssl ciphers | \
  85. tr ':' '\n')" -- "$cur" ) )
  86. return 0
  87. ;;
  88. esac
  89. if [[ "$cur" == -* ]]; then
  90. # possible options for the command
  91. case $command in
  92. asn1parse)
  93. options='-inform -in -out -noout -offset -length -i -oid \
  94. -strparse'
  95. ;;
  96. ca)
  97. options='-verbose -config -name -gencrl -revoke \
  98. -crl_reason -crl_hold -crl_compromise \
  99. -crl_CA_compromise -crldays -crlhours -crlexts \
  100. -startdate -enddate -days -md -policy -keyfile -key \
  101. -passin -cert -selfsig -in -out -notext -outdir \
  102. -infiles -spkac -ss_cert -preserveDN -noemailDN \
  103. -batch -msie_hack -extensions -extfile -engine \
  104. -subj -utf8 -multivalue-rdn'
  105. ;;
  106. ciphers)
  107. options='-v -ssl2 -ssl3 -tls1'
  108. ;;
  109. crl)
  110. options='-inform -outform -text -in -out -noout -hash \
  111. -issuer -lastupdate -nextupdate -CAfile -CApath'
  112. ;;
  113. crl2pkcs7)
  114. options='-inform -outform -in -out -print_certs'
  115. ;;
  116. dgst)
  117. options='-md5 -md4 -md2 -sha1 -sha -mdc2 -ripemd160 -dss1 \
  118. -c -d -hex -binary -out -sign -verify -prverify \
  119. -signature'
  120. ;;
  121. dsa)
  122. options='-inform -outform -in -passin -out -passout -des \
  123. -des3 -idea -text -noout -modulus -pubin -pubout'
  124. ;;
  125. dsaparam)
  126. options='-inform -outform -in -out -noout -text -C -rand \
  127. -genkey'
  128. ;;
  129. enc)
  130. options='-ciphername -in -out -pass -e -d -a -A -k -kfile \
  131. -S -K -iv -p -P -bufsize -debug'
  132. ;;
  133. dhparam)
  134. options='-inform -outform -in -out -dsaparam -noout -text \
  135. -C -2 -5 -rand'
  136. ;;
  137. gendsa)
  138. options='-out -des -des3 -idea -rand'
  139. ;;
  140. genrsa)
  141. options='-out -passout -des -des3 -idea -f4 -3 -rand'
  142. ;;
  143. pkcs7)
  144. options='-inform -outform -in -out -print_certs -text \
  145. -noout'
  146. ;;
  147. rand)
  148. options='-out -rand -base64'
  149. ;;
  150. req)
  151. options='-inform -outform -in -passin -out -passout -text \
  152. -noout -verify -modulus -new -rand -newkey -newkey \
  153. -nodes -key -keyform -keyout -md5 -sha1 -md2 -mdc2 \
  154. -config -x509 -days -asn1-kludge -newhdr -extensions \
  155. -reqexts section'
  156. ;;
  157. rsa)
  158. options='-inform -outform -in -passin -out -passout \
  159. -sgckey -des -des3 -idea -text -noout -modulus -check \
  160. -pubin -pubout -engine'
  161. ;;
  162. rsautl)
  163. options='-in -out -inkey -pubin -certin -sign -verify \
  164. -encrypt -decrypt -pkcs -ssl -raw -hexdump -asn1parse'
  165. ;;
  166. s_client)
  167. options='-connect -verify -cert -certform -key -keyform \
  168. -pass -CApath -CAfile -reconnect -pause -showcerts \
  169. -debug -msg -nbio_test -state -nbio -crlf -ign_eof \
  170. -quiet -ssl2 -ssl3 -tls1 -no_ssl2 -no_ssl3 -no_tls1 \
  171. -bugs -cipher -starttls -engine -tlsextdebug \
  172. -no_ticket -sess_out -sess_in -rand'
  173. ;;
  174. s_server)
  175. options='-accept -context -verify -Verify -crl_check \
  176. -crl_check_all -cert -certform -key -keyform -pass \
  177. -dcert -dcertform -dkey -dkeyform -dpass -dhparam \
  178. -nbio -nbio_test -crlf -debug -msg -state -CApath \
  179. -CAfile -nocert -cipher -quiet -no_tmp_rsa -ssl2 \
  180. -ssl3 -tls1 -no_ssl2 -no_ssl3 -no_tls1 -no_dhe \
  181. -bugs -hack -www -WWW -HTTP -engine -tlsextdebug \
  182. -no_ticket -id_prefix -rand'
  183. ;;
  184. s_time)
  185. options='-connect -www -cert -key -CApath -CAfile -reuse \
  186. -new -verify -nbio -time -ssl2 -ssl3 -bugs -cipher'
  187. ;;
  188. sess_id)
  189. options='-inform -outform -in -out -text -noout -context \
  190. ID'
  191. ;;
  192. smime)
  193. options='-encrypt -decrypt -sign -verify -pk7out -des \
  194. -des3 -rc2-40 -rc2-64 -rc2-128 -aes128 -aes192 -aes256 \
  195. -in -certfile -signer -recip -inform -passin -inkey \
  196. -out -outform -content -to -from -subject -text -rand'
  197. ;;
  198. speed)
  199. options='-engine'
  200. ;;
  201. verify)
  202. options='-CApath -CAfile -purpose -untrusted -help \
  203. -issuer_checks -verbose -certificates'
  204. ;;
  205. x509)
  206. options='-inform -outform -keyform -CAform -CAkeyform -in \
  207. -out -serial -hash -subject-hash -issuer_hash -subject \
  208. -issuer -nameopt -email -startdate -enddate -purpose \
  209. -dates -modulus -fingerprint -alias -noout -trustout \
  210. -clrtrust -clrreject -addtrust -addreject -setalias \
  211. -days -set_serial -signkey -x509toreq -req -CA -CAkey \
  212. -CAcreateserial -CAserial -text -C -md2 -md5 -sha1 \
  213. -mdc2 -clrext -extfile -extensions -engine'
  214. ;;
  215. @(md5|md4|md2|sha1|sha|mdc2|ripemd160))
  216. options='-c -d'
  217. ;;
  218. esac
  219. COMPREPLY=( $( compgen -W "$options" -- "$cur" ) )
  220. else
  221. if [[ "$command" == speed ]]; then
  222. COMPREPLY=( $( compgen -W 'md2 mdc2 md5 hmac sha1 rmd160 \
  223. idea-cbc rc2-cbc rc5-cbc bf-cbc des-cbc des-ede3 rc4 \
  224. rsa512 rsa1024 rsa2048 rsa4096 dsa512 dsa1024 dsa2048 idea \
  225. rc2 des rsa blowfish' -- "$cur" ) )
  226. else
  227. _filedir
  228. fi
  229. fi
  230. fi
  231. }
  232. complete -F _openssl $default openssl
  233. }
  234. # Local variables:
  235. # mode: shell-script
  236. # sh-basic-offset: 4
  237. # sh-indent-comment: t
  238. # indent-tabs-mode: nil
  239. # End:
  240. # ex: ts=4 sw=4 et filetype=sh