| 1 |
#!/usr/bin/env bash |
| 2 |
|
| 3 |
_check_ssl_cert() { |
| 4 |
|
| 5 |
local cur prev opts |
| 6 |
|
| 7 |
COMPREPLY=() |
| 8 |
|
| 9 |
cur="${COMP_WORDS[COMP_CWORD]}" |
| 10 |
prev="${COMP_WORDS[COMP_CWORD - 1]}" |
| 11 |
|
| 12 |
# |
| 13 |
# list of command line options |
| 14 |
# only the autocompletion with long options is implemented: long options are more readable and quick to enter since we are |
| 15 |
# using autocompletion. |
| 16 |
# |
| 17 |
opts="--file --host --noauth --all --all-local --allow-empty-san --clientcert --configuration --critical --check-chain --check-ciphers --check-ciphers-warnings --check-http-headers --check-ssl-labs --check-ssl-labs-warn --clientpass --crl --curl-bin --user-agent --custom-http-header --dane --date --debug-cert --debug-file --debug-headers --debug-time --default-format --dig-bin --do-not-resolve --dtls --dtls1 --dtls1_2 --ecdsa --element --file-bin --fingerprint --first-element-only --force-dconv-date --force-perl-date --format --grep-bin --http-headers-path --http-use-get --ignore-altnames --jks-alias --ignore-connection-problems --ignore-crl --ignore-exp --ignore-http-headers --ignore-host-cn --ignore-incomplete-chain --ignore-maximum-validity --ignore-ocsp --ignore-ocsp-errors --ignore-ocsp-timeout --ignore-sct --ignore-sig-alg --ignore-ssl-labs-cache --ignore-tls-renegotiation --ignore-unexpected-eof --inetproto protocol --info --init-host-cache --issuer-cert-cache --long-output --match --maximum-validity --nmap-bin --no-perf --no-proxy --no-proxy-curl --no-proxy-s_client --no-ssl2 --no-ssl3 --no-tls1 --no-tls1_1 --no-tls1_2 --no-tls1_3 --not-issued-by --not-valid-longer-than --ocsp-critical --ocsp-warning --openssl --password --path --precision --prometheus --proxy --require-client-cert --require-dnssec --require-http-header --require-no-http-header --require-no-ssl2 --require-no-ssl3 --require-no-tls1 --require-no-tls1_1 --require-no-tls1_2 --require-ocsp-stapling --require-purpose --require-purpose-critical --resolve --resolve-over-http --rootcert-dir --rootcert-file --rsa --serial --security-level --skip-element --sni --ssl2 --ssl3 --temp --terse --tls1 --tls1_1 --tls1_2 --tls1_3 --xmpphost -4 -6 --clientkey --protocol --version --debug --email --help --issuer --cn --org --port port --rootcert --quic --quiet --selfsigned --timeout --url --verbose --warning --python-bin" |
| 18 |
|
| 19 |
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]]; then |
| 20 |
# shellcheck disable=2207 |
| 21 |
COMPREPLY=($(compgen -W "${opts}" -- "${cur}")) |
| 22 |
return 0 |
| 23 |
fi |
| 24 |
|
| 25 |
# |
| 26 |
# options with arguments: if the option requires an argument we try to autocomplete it if possible |
| 27 |
# |
| 28 |
case "${prev}" in |
| 29 |
|
| 30 |
# options with files or directories as argument |
| 31 |
-f | --file | -C | --clientcert | --configuration | --curl-bin | --date | --debug-file | --dig-bin | --file-bin | --grep-bin | --issuer-cert-cache | --nmap-bin | --openssl | --rootcert-dir | --rootcert-file | --temp | -K | --clientkey | -r | --rootcert | --python-bin) |
| 32 |
_filedir |
| 33 |
;; |
| 34 |
|
| 35 |
# options with hosts as argument |
| 36 |
-H | --host | --resolve) |
| 37 |
_known_hosts_real "${cur}" |
| 38 |
if [[ -r ~/.check_ssl_cert-cache ]]; then |
| 39 |
# concatenate the array with the cached hosts: https://stackoverflow.com/questions/31143874/how-to-concatenate-arrays-in-bash |
| 40 |
# shellcheck disable=2207 |
| 41 |
COMPREPLY+=($(compgen -W "$(tr <~/.check_ssl_cert-cache "\n" ' ')" -- "${cur}")) |
| 42 |
fi |
| 43 |
;; |
| 44 |
|
| 45 |
# grades |
| 46 |
--check-ciphers | --check-ssl-labs-warn | --check-ssl-labs) |
| 47 |
# shellcheck disable=2207 |
| 48 |
COMPREPLY=($(compgen -W "A B C D E F" -- "${cur}")) |
| 49 |
;; |
| 50 |
|
| 51 |
--dane) |
| 52 |
# shellcheck disable=2207 |
| 53 |
COMPREPLY=($(compgen -W "211 301 302 311 312" -- "${cur}")) |
| 54 |
;; |
| 55 |
|
| 56 |
--maximum-validity) |
| 57 |
# shellcheck disable=2207 |
| 58 |
COMPREPLY=($(compgen -W "397" -- "${cur}")) |
| 59 |
;; |
| 60 |
|
| 61 |
--require-purpose) |
| 62 |
|
| 63 |
# the argument have spaces: see https://stackoverflow.com/questions/1146098/properly-handling-spaces-and-quotes-in-bash-completion |
| 64 |
|
| 65 |
# Get the currently completing word |
| 66 |
local CWORD=${COMP_WORDS[COMP_CWORD]} |
| 67 |
|
| 68 |
# This is our word list (in a bash array for convenience) |
| 69 |
local WORD_LIST=('Digital Signature' 'Key Encipherment' 'Key Agreement' 'Certificate Sign' 'Certificate Revocation List (CRL) Sign' 'CRL Sign') |
| 70 |
|
| 71 |
# Commands below depend on this IFS |
| 72 |
local IFS=$'\n' |
| 73 |
|
| 74 |
# Filter our candidates |
| 75 |
# shellcheck disable=2207 |
| 76 |
CANDIDATES=($(compgen -W "${WORD_LIST[*]}" -- "$CWORD")) |
| 77 |
|
| 78 |
# Correctly set our candidates to COMPREPLY |
| 79 |
if [[ ${#CANDIDATES[*]} -eq 0 ]]; then |
| 80 |
COMPREPLY=() |
| 81 |
else |
| 82 |
# shellcheck disable=2207 |
| 83 |
COMPREPLY=($(printf '%q\n' "${CANDIDATES[@]}")) |
| 84 |
fi |
| 85 |
;; |
| 86 |
|
| 87 |
--require-http-header) |
| 88 |
|
| 89 |
# shellcheck disable=2207 |
| 90 |
COMPREPLY=($(compgen -W "strict-transport-security X-Frame-Options Content-Security-Policy X-Content-Type-Options Referrer-Policy Permissions-Policy X-Permitted-Cross-Domain-Policies" -- "${cur}")) |
| 91 |
;; |
| 92 |
|
| 93 |
--require-no-http-header) |
| 94 |
|
| 95 |
# shellcheck disable=2207 |
| 96 |
COMPREPLY=($(compgen -W "X-Powered-By X-Aspnet-Version X-XSS-Protection Server X-AspNetMvc-Version" -- "${cur}")) |
| 97 |
;; |
| 98 |
|
| 99 |
--security-level) |
| 100 |
|
| 101 |
# shellcheck disable=2207 |
| 102 |
COMPREPLY=($(compgen -W "0 1 2 3 4 5" -- "${cur}")) |
| 103 |
;; |
| 104 |
|
| 105 |
--port | -p) |
| 106 |
# shellcheck disable=2207 |
| 107 |
COMPREPLY=($(compgen -W "21 22 80 443 143 993 194 994 389 587 636 3306 3391 110 995 5432 4190 25 465 5061 5222 5269" -- "${cur}")) |
| 108 |
;; |
| 109 |
|
| 110 |
--protocol | -P) |
| 111 |
# shellcheck disable=2207 |
| 112 |
COMPREPLY=($(compgen -W "dns ftp ftps http https h2 imap imaps irc ircs ldap ldaps mqtts mysql pop3 pop3s postgres sieve sips smtp smtps xmpp xmpp-server tds" -- "${cur}")) |
| 113 |
;; |
| 114 |
|
| 115 |
*) ;; |
| 116 |
|
| 117 |
esac |
| 118 |
|
| 119 |
} |
| 120 |
|
| 121 |
complete -F _check_ssl_cert check_ssl_cert |