Scripts for testing ECC ciphersuites.
[openssl.git] / demos / ssltest-ecc / ssltest.sh
1 #! /bin/sh
2 # Tests ECC cipher suites using ssltest. Requires one argument which could
3 # be aecdh or ecdh-ecdsa or ecdhe-ecdsa or ecdh-rsa or ecdhe-rsa.
4 # A second optional argument can be one of ssl2 ssl3 or tls1
5
6 if [ "$1" = "" ]; then
7   (echo "Usage: $0 test [ protocol ]"
8    echo "   where test is one of aecdh, ecdh-ecdsa, ecdhe-ecdsa, ecdh-rsa, ecdhe-rsa"
9    echo "   and protocol (optional) is one of ssl2, ssl3, tls1"
10    echo "Run RSAcertgen.sh, ECC-RSAcertgen.sh, ECCcertgen.sh first."
11   ) >&2
12   exit 1
13 fi
14
15
16 OPENSSL_DIR=../..
17 CERTS_DIR=./Certs
18 SSLTEST=$OPENSSL_DIR/test/ssltest
19 # SSL protocol version to test (one of ssl2 ssl3 or tls1)"
20 SSLVERSION=
21
22 # These don't really require any certificates
23 AECDH_CIPHER_LIST="EXP-AECDH-RC4-40-SHA EXP-AECDH-DES-40-CBC-SHA AECDH-DES-CBC3-SHA AECDH-DES-CBC-SHA AECDH-RC4-SHA AECDH-NULL-SHA"
24
25 # These require ECC certificates signed with ECDSA
26 # The EC public key must be authorized for key agreement.
27 ECDH_ECDSA_CIPHER_LIST="EXP-ECDH-ECDSA-RC4-56-SHA EXP-ECDH-ECDSA-RC4-40-SHA ECDH-ECDSA-AES256-SHA ECDH-ECDSA-AES128-SHA ECDH-ECDSA-DES-CBC3-SHA ECDH-ECDSA-DES-CBC-SHA ECDH-ECDSA-RC4-SHA ECDH-ECDSA-NULL-SHA"
28
29 # These require ECC certificates.
30 # The EC public key must be authorized for digital signature.
31 ECDHE_ECDSA_CIPHER_LIST="ECDHE-ECDSA-AES128-SHA"
32
33 # These require ECC certificates signed with RSA.
34 # The EC public key must be authorized for key agreement.
35 ECDH_RSA_CIPHER_LIST="EXP-ECDH-RSA-RC4-56-SHA EXP-ECDH-RSA-RC4-40-SHA ECDH-RSA-AES256-SHA ECDH-RSA-AES128-SHA ECDH-RSA-DES-CBC3-SHA ECDH-RSA-DES-CBC-SHA ECDH-RSA-RC4-SHA ECDH-RSA-NULL-SHA"
36
37 # These require RSA certificates.
38 # The RSA public key must be authorized for digital signature.
39 ECDHE_RSA_CIPHER_LIST="ECDHE-RSA-AES128-SHA"
40
41 # List of Elliptic curves over which we wish to test generation of
42 # ephemeral ECDH keys when using AECDH or ECDHE ciphers
43 # NOTE: secp192r1 = prime192v1 and secp256r1 = prime256v1
44 #ELLIPTIC_CURVE_LIST="secp112r1 sect113r2 secp128r1 sect131r1 secp160k1 sect163r2 wap-wsg-idm-ecid-wtls7 c2pnb163v3 c2pnb176v3 c2tnb191v3 secp192r1 prime192v3 sect193r2 secp224r1 wap-wsg-idm-ecid-wtls10 sect239k1 prime239v2 secp256r1 prime256v1 sect283k1 secp384r1 sect409r1 secp521r1 sect571r1"
45 ELLIPTIC_CURVE_LIST="sect163k1 sect163r1 sect163r2 sect193r1 sect193r2 sect233k1 sect233r1 sect239k1 sect283k1 sect283r1 sect409k1 sect409r1 sect571k1 sect571r1 secp160k1 secp160r1 secp160r2 secp192k1 prime192v1 secp224k1 secp224r1 secp256k1 prime256v1 secp384r1 secp521r1"
46
47 DEFAULT_CURVE="sect163r2"
48
49 if [ "$2" = "" ]; then
50     if [ "$SSL_VERSION" = "" ]; then
51         SSL_VERSION=""
52     else
53         SSL_VERSION="-$SSL_VERSION"
54     fi
55 else
56     SSL_VERSION="-$2"
57 fi
58
59 #==============================================================
60 # Anonymous cipher suites do not require key or certificate files
61 # but ssltest expects a cert file and complains if it can't
62 # open the default one.
63 SERVER_PEM=$OPENSSL_DIR/apps/server.pem
64
65 if [ "$1" = "aecdh" ]; then
66 for cipher in $AECDH_CIPHER_LIST
67 do
68     echo "Testing $cipher"
69     $SSLTEST $SSL_VERSION -cert $SERVER_PEM -cipher $cipher 
70 done
71 #--------------------------------------------------------------
72 for curve in $ELLIPTIC_CURVE_LIST
73 do
74     echo "Testing AECDH-NULL-SHA (with $curve)"
75     $SSLTEST $SSL_VERSION -cert $SERVER_PEM \
76         -named_curve $curve -cipher AECDH-NULL-SHA
77 done
78
79 for curve in $ELLIPTIC_CURVE_LIST
80 do
81     echo "Testing EXP-AECDH-RC4-40-SHA (with $curve)"
82     $SSLTEST $SSL_VERSION -cert $SERVER_PEM \
83         -named_curve $curve -cipher EXP-AECDH-RC4-40-SHA
84 done
85 fi
86
87 #==============================================================
88 # Both ECDH-ECDSA and ECDHE-ECDSA cipher suites require 
89 # the server to have an ECC certificate signed with ECDSA.
90 CA_PEM=$CERTS_DIR/secp160r1TestCA.pem
91 SERVER_PEM=$CERTS_DIR/secp160r2TestServer.pem
92 CLIENT_PEM=$CERTS_DIR/secp160r2TestClient.pem
93
94 if [ "$1" = "ecdh-ecdsa" ]; then
95 for cipher in $ECDH_ECDSA_CIPHER_LIST
96 do
97     echo "Testing $cipher (with server authentication)"
98     $SSLTEST $SSL_VERSION -CAfile $CA_PEM \
99         -cert $SERVER_PEM -server_auth \
100         -cipher $cipher
101
102     echo "Testing $cipher (with server and client authentication)"
103     $SSLTEST $SSL_VERSION -CAfile $CA_PEM \
104         -cert $SERVER_PEM -server_auth \
105         -c_cert $CLIENT_PEM -client_auth \
106         -cipher $cipher
107 done
108 fi
109
110 #==============================================================
111 if [ "$1" = "ecdhe-ecdsa" ]; then
112 for cipher in $ECDHE_ECDSA_CIPHER_LIST
113 do
114     echo "Testing $cipher (with server authentication)"
115     $SSLTEST $SSL_VERSION -CAfile $CA_PEM \
116         -cert $SERVER_PEM -server_auth \
117         -cipher $cipher -named_curve $DEFAULT_CURVE
118
119     echo "Testing $cipher (with server and client authentication)"
120     $SSLTEST $SSL_VERSION -CAfile $CA_PEM \
121         -cert $SERVER_PEM -server_auth \
122         -c_cert $CLIENT_PEM -client_auth \
123         -cipher $cipher -named_curve $DEFAULT_CURVE
124 done
125
126 #--------------------------------------------------------------
127 for curve in $ELLIPTIC_CURVE_LIST
128 do
129     echo "Testing ECDHE-ECDSA-AES128-SHA (2-way auth with $curve)"
130     $SSLTEST $SSL_VERSION -CAfile $CA_PEM \
131         -cert $SERVER_PEM -server_auth \
132         -c_cert $CLIENT_PEM -client_auth \
133         -cipher ECDHE-ECDSA-AES128-SHA -named_curve $curve 
134 done
135 fi
136
137 #==============================================================
138 # ECDH-RSA cipher suites require the server to have an ECC
139 # certificate signed with RSA.
140 CA_PEM=$CERTS_DIR/rsa1024TestCA.pem
141 SERVER_PEM=$CERTS_DIR/sect163r1-rsaTestServer.pem
142 CLIENT_PEM=$CERTS_DIR/sect163r1-rsaTestClient.pem
143
144 if [ "$1" = "ecdh-rsa" ]; then
145 for cipher in $ECDH_RSA_CIPHER_LIST
146 do
147     echo "Testing $cipher (with server authentication)"
148     $SSLTEST $SSL_VERSION -CAfile $CA_PEM \
149         -cert $SERVER_PEM -server_auth \
150         -cipher $cipher
151
152     echo "Testing $cipher (with server and client authentication)"
153     $SSLTEST $SSL_VERSION -CAfile $CA_PEM \
154         -cert $SERVER_PEM -server_auth \
155         -c_cert $CLIENT_PEM -client_auth \
156         -cipher $cipher
157 done
158 fi
159
160 #==============================================================
161 # ECDHE-RSA cipher suites require the server to have an RSA cert.
162 CA_PEM=$CERTS_DIR/rsa1024TestCA.pem
163 SERVER_PEM=$CERTS_DIR/rsa1024TestServer.pem
164 CLIENT_PEM=$CERTS_DIR/rsa1024TestClient.pem
165
166 if [ "$1" = "ecdhe-rsa" ]; then
167 for cipher in $ECDHE_RSA_CIPHER_LIST
168 do
169     echo "Testing $cipher (with server authentication)"
170     $SSLTEST $SSL_VERSION -CAfile $CA_PEM \
171         -cert $SERVER_PEM -server_auth \
172         -cipher $cipher -named_curve $DEFAULT_CURVE
173
174     echo "Testing $cipher (with server and client authentication)"
175     $SSLTEST $SSL_VERSION -CAfile $CA_PEM \
176         -cert $SERVER_PEM -server_auth \
177         -c_cert $CLIENT_PEM -client_auth \
178         -cipher $cipher -named_curve $DEFAULT_CURVE
179 done
180 fi
181 #==============================================================
182
183
184
185