~ubuntu-branches/ubuntu/vivid/bash-completion/vivid-proposed

« back to all changes in this revision

Viewing changes to completions/openssl

  • Committer: Package Import Robot
  • Author(s): Angel Abad
  • Date: 2011-02-08 09:39:13 UTC
  • mfrom: (5.1.8 sid)
  • Revision ID: package-import@ubuntu.com-20110208093913-89h9hx9eq5j7vjpw
Tags: 1:1.3-1ubuntu1
* Merge from debian unstable. (LP: #715057) Remaining changes:
  - debian/patches/disable-avahi-browse.diff: Disable avahi-browse since
    it scales poorly in the current form:
    + Refresh patch
  - debian/patches/apt-get-changelog.patch:
    + Re-work patch because contrib dir no longer exists in upstream
      distribution.
* Dropped chages, applied upstream:
  - Fix p4 completion
  - Fix typo in openssl completion
  - Fix error while loading service(8) completions

Show diffs side-by-side

added added

removed removed

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