@@ -19,7 +19,7 @@ use crate::error::ErrorStack;
19
19
use crate :: hash:: MessageDigest ;
20
20
#[ cfg( not( boringssl) ) ]
21
21
use crate :: ocsp:: { OcspResponse , OcspResponseStatus } ;
22
- use crate :: pkey:: PKey ;
22
+ use crate :: pkey:: { Id , PKey } ;
23
23
use crate :: srtp:: SrtpProfileId ;
24
24
use crate :: ssl:: test:: server:: Server ;
25
25
#[ cfg( any( ossl110, ossl111, libressl261) ) ]
@@ -322,6 +322,56 @@ fn state() {
322
322
) ;
323
323
}
324
324
325
+ // when a connection uses ECDHE P-384 key exchange, then the temp key APIs
326
+ // return P-384 keys, and the peer and local keys are different.
327
+ #[ test]
328
+ #[ cfg( ossl300) ]
329
+ fn peer_tmp_key_p384 ( ) {
330
+ let mut server = Server :: builder ( ) ;
331
+ server. ctx ( ) . set_groups_list ( "P-384" ) . unwrap ( ) ;
332
+ let server = server. build ( ) ;
333
+ let s = server. client ( ) . connect ( ) ;
334
+ let peer_temp = s. ssl ( ) . peer_tmp_key ( ) . unwrap ( ) ;
335
+ assert_eq ! ( peer_temp. id( ) , Id :: EC ) ;
336
+ assert_eq ! ( peer_temp. bits( ) , 384 ) ;
337
+
338
+ let local_temp = s. ssl ( ) . tmp_key ( ) . unwrap ( ) ;
339
+ assert_eq ! ( local_temp. id( ) , Id :: EC ) ;
340
+ assert_eq ! ( local_temp. bits( ) , 384 ) ;
341
+
342
+ assert_ne ! (
343
+ peer_temp. ec_key( ) . unwrap( ) . public_key_to_der( ) . unwrap( ) ,
344
+ local_temp. ec_key( ) . unwrap( ) . public_key_to_der( ) . unwrap( ) ,
345
+ ) ;
346
+ }
347
+
348
+ // when a connection uses RSA key exchange, then the peer (server) temp key is
349
+ // an Error because there is no temp key, and the local (client) temp key is the
350
+ // temp key sent in the initial key share.
351
+ #[ test]
352
+ #[ cfg( ossl300) ]
353
+ fn peer_tmp_key_rsa ( ) {
354
+ let mut server = Server :: builder ( ) ;
355
+ server. ctx ( ) . set_cipher_list ( "RSA" ) . unwrap ( ) ;
356
+ // RSA key exchange is not allowed in TLS 1.3, so force the connection
357
+ // to negotiate TLS 1.2
358
+ server
359
+ . ctx ( )
360
+ . set_max_proto_version ( Some ( SslVersion :: TLS1_2 ) )
361
+ . unwrap ( ) ;
362
+ let server = server. build ( ) ;
363
+ let mut client = server. client ( ) ;
364
+ client. ctx ( ) . set_groups_list ( "P-521" ) . unwrap ( ) ;
365
+ let s = client. connect ( ) ;
366
+ let peer_temp = s. ssl ( ) . peer_tmp_key ( ) ;
367
+ assert ! ( peer_temp. is_err( ) ) ;
368
+
369
+ // this is the temp key that the client sent in the initial key share
370
+ let local_temp = s. ssl ( ) . tmp_key ( ) . unwrap ( ) ;
371
+ assert_eq ! ( local_temp. id( ) , Id :: EC ) ;
372
+ assert_eq ! ( local_temp. bits( ) , 521 ) ;
373
+ }
374
+
325
375
/// Tests that when both the client as well as the server use SRTP and their
326
376
/// lists of supported protocols have an overlap -- with only ONE protocol
327
377
/// being valid for both.
0 commit comments