@@ -105,6 +105,29 @@ fn test_handshake_client_authentication_with_no_rsa_client_key() {
105
105
client. connect ( addr) ;
106
106
}
107
107
108
+ #[ should_panic]
109
+ #[ test]
110
+ fn test_handshake_client_authentication_with_no_ecdsa_client_key ( ) {
111
+ let listener = TcpListener :: bind ( "127.0.0.1:0" ) . unwrap ( ) ;
112
+ let addr = listener. local_addr ( ) . unwrap ( ) ;
113
+
114
+ let server = Server :: new (
115
+ Some ( String :: from ( "../../tests/tls/server/server_cert.pem" ) ) ,
116
+ Some ( String :: from ( "../../tests/tls/server/server_priv_key.pem" ) ) ,
117
+ Some ( String :: from ( "../../tests/tls/ca/ca_cert.pem" ) ) ,
118
+ SslVerifyMode :: PEER | SslVerifyMode :: FAIL_IF_NO_PEER_CERT ,
119
+ ) ;
120
+ server. accept ( listener) ;
121
+
122
+ let client = Client :: new (
123
+ Some ( String :: from ( "../../tests/tls/client/parsec_ecdsa.pem" ) ) ,
124
+ None ,
125
+ Some ( String :: from ( "../../tests/tls/ca/ca_cert.pem" ) ) ,
126
+ SslVerifyMode :: PEER ,
127
+ ) ;
128
+ client. connect ( addr) ;
129
+ }
130
+
108
131
#[ test]
109
132
fn test_handshake_client_authentication_rsa ( ) {
110
133
let socket = TcpListener :: bind ( "127.0.0.1:0" ) . unwrap ( ) ;
@@ -127,6 +150,28 @@ fn test_handshake_client_authentication_rsa() {
127
150
client. connect ( addr) ;
128
151
}
129
152
153
+ #[ test]
154
+ fn test_handshake_client_authentication_ecdsa ( ) {
155
+ let socket = TcpListener :: bind ( "127.0.0.1:0" ) . unwrap ( ) ;
156
+ let addr = socket. local_addr ( ) . unwrap ( ) ;
157
+
158
+ let server = Server :: new (
159
+ Some ( String :: from ( "../../tests/tls/server/server_cert.pem" ) ) ,
160
+ Some ( String :: from ( "../../tests/tls/server/server_priv_key.pem" ) ) ,
161
+ Some ( String :: from ( "../../tests/tls/ca/ca_cert.pem" ) ) ,
162
+ SslVerifyMode :: FAIL_IF_NO_PEER_CERT | SslVerifyMode :: PEER ,
163
+ ) ;
164
+ server. accept ( socket) ;
165
+
166
+ let client = Client :: new (
167
+ Some ( String :: from ( "../../tests/tls/client/parsec_ecdsa.pem" ) ) ,
168
+ Some ( String :: from ( "PARSEC_TEST_ECDSA_KEY" ) ) ,
169
+ Some ( String :: from ( "../../tests/tls/ca/ca_cert.pem" ) ) ,
170
+ SslVerifyMode :: PEER ,
171
+ ) ;
172
+ client. connect ( addr) ;
173
+ }
174
+
130
175
#[ should_panic]
131
176
#[ test]
132
177
fn test_handshake_client_authentication_with_fake_ca ( ) {
@@ -168,3 +213,22 @@ fn test_client_with_mismatched_rsa_key_and_certificate() {
168
213
. set_private_key_file ( String :: from ( "PARSEC_TEST_RSA_KEY" ) , SslFiletype :: PEM )
169
214
. unwrap_err ( ) ;
170
215
}
216
+
217
+ // This is a negative test case. When a client is configured with a wrong certificate for a private
218
+ // key, the key management match function should report an error about the mismatched private key and
219
+ // public key from the x509 certificate.
220
+ #[ test]
221
+ fn test_client_with_mismatched_ecdsa_key_and_certificate ( ) {
222
+ let mut ctx_builder = SslContext :: builder ( SslMethod :: tls_client ( ) ) . unwrap ( ) ;
223
+
224
+ ctx_builder
225
+ . set_certificate_file (
226
+ String :: from ( "../../tests/tls/fake_client/parsec_ecdsa.pem" ) ,
227
+ SslFiletype :: PEM ,
228
+ )
229
+ . unwrap ( ) ;
230
+
231
+ ctx_builder
232
+ . set_private_key_file ( String :: from ( "PARSEC_TEST_ECDSA_KEY" ) , SslFiletype :: PEM )
233
+ . unwrap_err ( ) ;
234
+ }
0 commit comments