PageRenderTime 44ms CodeModel.GetById 33ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

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