mirror of
				https://github.com/cuberite/polarssl.git
				synced 2025-10-30 19:20:40 -04:00 
			
		
		
		
	More *-PSK refactoring
This commit is contained in:
		
							parent
							
								
									bd1ae24449
								
							
						
					
					
						commit
						72fb62daa2
					
				| @ -1802,15 +1802,17 @@ static int ssl_write_client_key_exchange( ssl_context *ssl ) | |||||||
|     else |     else | ||||||
| #endif /* POLARSSL_KEY_EXCHANGE_ECDHE_RSA_ENABLED || | #endif /* POLARSSL_KEY_EXCHANGE_ECDHE_RSA_ENABLED || | ||||||
|           POLARSSL_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED */ |           POLARSSL_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED */ | ||||||
| #if defined(POLARSSL_KEY_EXCHANGE_PSK_ENABLED) | #if defined(POLARSSL_KEY_EXCHANGE_PSK_ENABLED) ||                           \ | ||||||
|     if( ciphersuite_info->key_exchange == POLARSSL_KEY_EXCHANGE_PSK ) |     defined(POLARSSL_KEY_EXCHANGE_DHE_PSK_ENABLED) ||                       \ | ||||||
|  |     defined(POLARSSL_KEY_EXCHANGE_ECDHE_PSK_ENABLED) | ||||||
|  |     if( ciphersuite_info->key_exchange == POLARSSL_KEY_EXCHANGE_PSK || | ||||||
|  |         ciphersuite_info->key_exchange == POLARSSL_KEY_EXCHANGE_DHE_PSK || | ||||||
|  |         ciphersuite_info->key_exchange == POLARSSL_KEY_EXCHANGE_ECDHE_PSK ) | ||||||
|     { |     { | ||||||
|         /*
 |         /*
 | ||||||
|          * PSK key exchange |  | ||||||
|          * |  | ||||||
|          * opaque psk_identity<0..2^16-1>; |          * opaque psk_identity<0..2^16-1>; | ||||||
|          */ |          */ | ||||||
|         if( ssl->psk == NULL ) |         if( ssl->psk == NULL || ssl->psk_identity == NULL ) | ||||||
|             return( POLARSSL_ERR_SSL_PRIVATE_KEY_REQUIRED ); |             return( POLARSSL_ERR_SSL_PRIVATE_KEY_REQUIRED ); | ||||||
| 
 | 
 | ||||||
|         i = 4; |         i = 4; | ||||||
| @ -1821,35 +1823,19 @@ static int ssl_write_client_key_exchange( ssl_context *ssl ) | |||||||
|         memcpy( ssl->out_msg + i, ssl->psk_identity, ssl->psk_identity_len ); |         memcpy( ssl->out_msg + i, ssl->psk_identity, ssl->psk_identity_len ); | ||||||
|         i += ssl->psk_identity_len; |         i += ssl->psk_identity_len; | ||||||
| 
 | 
 | ||||||
|         if( ( ret = ssl_psk_derive_premaster( ssl, | #if defined(POLARSSL_KEY_EXCHANGE_PSK_ENABLED) | ||||||
|                         ciphersuite_info->key_exchange ) ) != 0 ) |         if( ciphersuite_info->key_exchange == POLARSSL_KEY_EXCHANGE_PSK ) | ||||||
|         { |         { | ||||||
|             SSL_DEBUG_RET( 1, "ssl_psk_derive_premaster", ret ); |             n = 0; | ||||||
|             return( ret ); |  | ||||||
|         } |  | ||||||
|         } |         } | ||||||
|         else |         else | ||||||
| #endif /* POLARSSL_KEY_EXCHANGE_PSK_ENABLED */ | #endif | ||||||
| #if defined(POLARSSL_KEY_EXCHANGE_DHE_PSK_ENABLED) | #if defined(POLARSSL_KEY_EXCHANGE_DHE_PSK_ENABLED) | ||||||
|         if( ciphersuite_info->key_exchange == POLARSSL_KEY_EXCHANGE_DHE_PSK ) |         if( ciphersuite_info->key_exchange == POLARSSL_KEY_EXCHANGE_DHE_PSK ) | ||||||
|         { |         { | ||||||
|             /*
 |             /*
 | ||||||
|          * DHE_PSK key exchange |  | ||||||
|          * |  | ||||||
|          * opaque psk_identity<0..2^16-1>; |  | ||||||
|              * ClientDiffieHellmanPublic public (DHM send G^X mod P) |              * ClientDiffieHellmanPublic public (DHM send G^X mod P) | ||||||
|              */ |              */ | ||||||
|         if( ssl->psk == NULL ) |  | ||||||
|             return( POLARSSL_ERR_SSL_PRIVATE_KEY_REQUIRED ); |  | ||||||
| 
 |  | ||||||
|         i = 4; |  | ||||||
|         n = ssl->psk_identity_len; |  | ||||||
|         ssl->out_msg[i++] = (unsigned char)( n >> 8 ); |  | ||||||
|         ssl->out_msg[i++] = (unsigned char)( n      ); |  | ||||||
| 
 |  | ||||||
|         memcpy( ssl->out_msg + i, ssl->psk_identity, ssl->psk_identity_len ); |  | ||||||
|         i += ssl->psk_identity_len; |  | ||||||
| 
 |  | ||||||
|             n = ssl->handshake->dhm_ctx.len; |             n = ssl->handshake->dhm_ctx.len; | ||||||
|             ssl->out_msg[i++] = (unsigned char)( n >> 8 ); |             ssl->out_msg[i++] = (unsigned char)( n >> 8 ); | ||||||
|             ssl->out_msg[i++] = (unsigned char)( n      ); |             ssl->out_msg[i++] = (unsigned char)( n      ); | ||||||
| @ -1863,13 +1849,6 @@ static int ssl_write_client_key_exchange( ssl_context *ssl ) | |||||||
|                 SSL_DEBUG_RET( 1, "dhm_make_public", ret ); |                 SSL_DEBUG_RET( 1, "dhm_make_public", ret ); | ||||||
|                 return( ret ); |                 return( ret ); | ||||||
|             } |             } | ||||||
| 
 |  | ||||||
|         if( ( ret = ssl_psk_derive_premaster( ssl, |  | ||||||
|                         ciphersuite_info->key_exchange ) ) != 0 ) |  | ||||||
|         { |  | ||||||
|             SSL_DEBUG_RET( 1, "ssl_psk_derive_premaster", ret ); |  | ||||||
|             return( ret ); |  | ||||||
|         } |  | ||||||
|         } |         } | ||||||
|         else |         else | ||||||
| #endif /* POLARSSL_KEY_EXCHANGE_DHE_PSK_ENABLED */ | #endif /* POLARSSL_KEY_EXCHANGE_DHE_PSK_ENABLED */ | ||||||
| @ -1877,21 +1856,8 @@ static int ssl_write_client_key_exchange( ssl_context *ssl ) | |||||||
|         if( ciphersuite_info->key_exchange == POLARSSL_KEY_EXCHANGE_ECDHE_PSK ) |         if( ciphersuite_info->key_exchange == POLARSSL_KEY_EXCHANGE_ECDHE_PSK ) | ||||||
|         { |         { | ||||||
|             /*
 |             /*
 | ||||||
|          * ECDHE_PSK key exchange: RFC 5489, section 2 |  | ||||||
|          * |  | ||||||
|          * opaque psk_identity<0..2^16-1>; |  | ||||||
|              * ClientECDiffieHellmanPublic public; |              * ClientECDiffieHellmanPublic public; | ||||||
|              */ |              */ | ||||||
|         if( ssl->psk == NULL ) |  | ||||||
|             return( POLARSSL_ERR_SSL_PRIVATE_KEY_REQUIRED ); |  | ||||||
| 
 |  | ||||||
|         i = 4; |  | ||||||
|         ssl->out_msg[i++] = (unsigned char)( ssl->psk_identity_len >> 8 ); |  | ||||||
|         ssl->out_msg[i++] = (unsigned char)( ssl->psk_identity_len      ); |  | ||||||
| 
 |  | ||||||
|         memcpy( ssl->out_msg + i, ssl->psk_identity, ssl->psk_identity_len ); |  | ||||||
|         i += ssl->psk_identity_len; |  | ||||||
| 
 |  | ||||||
|             ret = ecdh_make_public( &ssl->handshake->ecdh_ctx, &n, |             ret = ecdh_make_public( &ssl->handshake->ecdh_ctx, &n, | ||||||
|                     &ssl->out_msg[i], SSL_MAX_CONTENT_LEN - i, |                     &ssl->out_msg[i], SSL_MAX_CONTENT_LEN - i, | ||||||
|                     ssl->f_rng, ssl->p_rng ); |                     ssl->f_rng, ssl->p_rng ); | ||||||
| @ -1902,6 +1868,13 @@ static int ssl_write_client_key_exchange( ssl_context *ssl ) | |||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             SSL_DEBUG_ECP( 3, "ECDH: Q", &ssl->handshake->ecdh_ctx.Q ); |             SSL_DEBUG_ECP( 3, "ECDH: Q", &ssl->handshake->ecdh_ctx.Q ); | ||||||
|  |         } | ||||||
|  |         else | ||||||
|  | #endif /* POLARSSL_KEY_EXCHANGE_ECDHE_PSK_ENABLED */ | ||||||
|  |         { | ||||||
|  |             SSL_DEBUG_MSG( 1, ( "should never happen" ) ); | ||||||
|  |             return( POLARSSL_ERR_SSL_FEATURE_UNAVAILABLE ); | ||||||
|  |         } | ||||||
| 
 | 
 | ||||||
|         if( ( ret = ssl_psk_derive_premaster( ssl, |         if( ( ret = ssl_psk_derive_premaster( ssl, | ||||||
|                         ciphersuite_info->key_exchange ) ) != 0 ) |                         ciphersuite_info->key_exchange ) ) != 0 ) | ||||||
| @ -1911,7 +1884,9 @@ static int ssl_write_client_key_exchange( ssl_context *ssl ) | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|     else |     else | ||||||
| #endif /* POLARSSL_KEY_EXCHANGE_ECDHE_PSK_ENABLED */ | #endif /* POLARSSL_KEY_EXCHANGE_PSK_ENABLED || | ||||||
|  |           POLARSSL_KEY_EXCHANGE_DHE_PSK_ENABLED || | ||||||
|  |           POLARSSL_KEY_EXCHANGE_ECDHE_PSK_ENABLED */ | ||||||
| #if defined(POLARSSL_KEY_EXCHANGE_RSA_ENABLED) | #if defined(POLARSSL_KEY_EXCHANGE_RSA_ENABLED) | ||||||
|     if( ciphersuite_info->key_exchange == POLARSSL_KEY_EXCHANGE_RSA ) |     if( ciphersuite_info->key_exchange == POLARSSL_KEY_EXCHANGE_RSA ) | ||||||
|     { |     { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Manuel Pégourié-Gonnard
						Manuel Pégourié-Gonnard