mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-26 02:05:39 +01:00
- Added Secure Renegotiation (RFC 5746)
This commit is contained in:
parent
b5b20f19e7
commit
48916f9b67
@ -13,7 +13,7 @@ Features
|
|||||||
* Added key_app_writer example application
|
* Added key_app_writer example application
|
||||||
* Added cert_req example application
|
* Added cert_req example application
|
||||||
* Added base Galois Counter Mode (GCM) for AES
|
* Added base Galois Counter Mode (GCM) for AES
|
||||||
* Added TLS 1.2 support
|
* Added TLS 1.2 support (RFC 5246)
|
||||||
* Added GCM suites to TLS 1.2 (RFC 5288)
|
* Added GCM suites to TLS 1.2 (RFC 5288)
|
||||||
* Added commandline error code convertor (util/strerror)
|
* Added commandline error code convertor (util/strerror)
|
||||||
* Added support for Hardware Acceleration hooking in SSL/TLS
|
* Added support for Hardware Acceleration hooking in SSL/TLS
|
||||||
@ -24,6 +24,7 @@ Features
|
|||||||
* Added DEFLATE compression support as per RFC3749 (requires zlib)
|
* Added DEFLATE compression support as per RFC3749 (requires zlib)
|
||||||
* Added blowfish algorithm (Generic and cipher layer)
|
* Added blowfish algorithm (Generic and cipher layer)
|
||||||
* Added PKCS#5 PBKDF2 key derivation function
|
* Added PKCS#5 PBKDF2 key derivation function
|
||||||
|
* Added Secure Renegotiation (RFC 5746)
|
||||||
|
|
||||||
Changes
|
Changes
|
||||||
* Removed redundant POLARSSL_DEBUG_MSG define
|
* Removed redundant POLARSSL_DEBUG_MSG define
|
||||||
|
@ -30,7 +30,6 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
#include "dhm.h"
|
|
||||||
#include "rsa.h"
|
#include "rsa.h"
|
||||||
#include "md5.h"
|
#include "md5.h"
|
||||||
#include "sha1.h"
|
#include "sha1.h"
|
||||||
@ -39,6 +38,10 @@
|
|||||||
#include "x509.h"
|
#include "x509.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#if defined(POLARSSL_DHM_C)
|
||||||
|
#include "dhm.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(POLARSSL_PKCS11_C)
|
#if defined(POLARSSL_PKCS11_C)
|
||||||
#include "pkcs11.h"
|
#include "pkcs11.h"
|
||||||
#endif
|
#endif
|
||||||
@ -110,6 +113,18 @@
|
|||||||
#define SSL_VERIFY_OPTIONAL 1
|
#define SSL_VERIFY_OPTIONAL 1
|
||||||
#define SSL_VERIFY_REQUIRED 2
|
#define SSL_VERIFY_REQUIRED 2
|
||||||
|
|
||||||
|
#define SSL_INITIAL_HANDSHAKE 0
|
||||||
|
#define SSL_RENEGOTIATION 1
|
||||||
|
|
||||||
|
#define SSL_LEGACY_RENEGOTIATION 0
|
||||||
|
#define SSL_SECURE_RENEGOTIATION 1
|
||||||
|
|
||||||
|
#define SSL_RENEGOTIATION_ENABLED 0
|
||||||
|
#define SSL_RENEGOTIATION_DISABLED 1
|
||||||
|
|
||||||
|
#define SSL_NO_LEGACY_RENEGOTIATION 0
|
||||||
|
#define SSL_ALLOW_LEGACY_RENEGOTIATION 1
|
||||||
|
|
||||||
#define SSL_MAX_CONTENT_LEN 16384
|
#define SSL_MAX_CONTENT_LEN 16384
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -164,6 +179,8 @@
|
|||||||
#define SSL_EDH_RSA_AES_128_GCM_SHA256 0x9E
|
#define SSL_EDH_RSA_AES_128_GCM_SHA256 0x9E
|
||||||
#define SSL_EDH_RSA_AES_256_GCM_SHA384 0x9F
|
#define SSL_EDH_RSA_AES_256_GCM_SHA384 0x9F
|
||||||
|
|
||||||
|
#define SSL_EMPTY_RENEGOTIATION_INFO 0xFF /**< renegotiation info ext */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Supported Signature and Hash algorithms (For TLS 1.2)
|
* Supported Signature and Hash algorithms (For TLS 1.2)
|
||||||
*/
|
*/
|
||||||
@ -233,6 +250,8 @@
|
|||||||
|
|
||||||
#define TLS_EXT_SIG_ALG 13
|
#define TLS_EXT_SIG_ALG 13
|
||||||
|
|
||||||
|
#define TLS_EXT_RENEGOTIATION_INFO 0xFF01
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* SSL state machine
|
* SSL state machine
|
||||||
*/
|
*/
|
||||||
@ -253,12 +272,15 @@ typedef enum
|
|||||||
SSL_SERVER_CHANGE_CIPHER_SPEC,
|
SSL_SERVER_CHANGE_CIPHER_SPEC,
|
||||||
SSL_SERVER_FINISHED,
|
SSL_SERVER_FINISHED,
|
||||||
SSL_FLUSH_BUFFERS,
|
SSL_FLUSH_BUFFERS,
|
||||||
|
SSL_HANDSHAKE_WRAPUP,
|
||||||
SSL_HANDSHAKE_OVER
|
SSL_HANDSHAKE_OVER
|
||||||
}
|
}
|
||||||
ssl_states;
|
ssl_states;
|
||||||
|
|
||||||
typedef struct _ssl_session ssl_session;
|
typedef struct _ssl_session ssl_session;
|
||||||
typedef struct _ssl_context ssl_context;
|
typedef struct _ssl_context ssl_context;
|
||||||
|
typedef struct _ssl_transform ssl_transform;
|
||||||
|
typedef struct _ssl_handshake_params ssl_handshake_params;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This structure is used for session resuming.
|
* This structure is used for session resuming.
|
||||||
@ -271,15 +293,83 @@ struct _ssl_session
|
|||||||
size_t length; /*!< session id length */
|
size_t length; /*!< session id length */
|
||||||
unsigned char id[32]; /*!< session identifier */
|
unsigned char id[32]; /*!< session identifier */
|
||||||
unsigned char master[48]; /*!< the master secret */
|
unsigned char master[48]; /*!< the master secret */
|
||||||
|
x509_cert *peer_cert; /*!< peer X.509 cert chain */
|
||||||
ssl_session *next; /*!< next session entry */
|
ssl_session *next; /*!< next session entry */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This structure contains a full set of runtime transform parameters
|
||||||
|
* either in negotiation or active.
|
||||||
|
*/
|
||||||
|
struct _ssl_transform
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Session specific crypto layer
|
||||||
|
*/
|
||||||
|
unsigned int keylen; /*!< symmetric key length */
|
||||||
|
size_t minlen; /*!< min. ciphertext length */
|
||||||
|
size_t ivlen; /*!< IV length */
|
||||||
|
size_t fixed_ivlen; /*!< Fixed part of IV (AEAD) */
|
||||||
|
size_t maclen; /*!< MAC length */
|
||||||
|
|
||||||
|
unsigned char iv_enc[16]; /*!< IV (encryption) */
|
||||||
|
unsigned char iv_dec[16]; /*!< IV (decryption) */
|
||||||
|
|
||||||
|
unsigned char mac_enc[32]; /*!< MAC (encryption) */
|
||||||
|
unsigned char mac_dec[32]; /*!< MAC (decryption) */
|
||||||
|
|
||||||
|
unsigned long ctx_enc[134]; /*!< encryption context */
|
||||||
|
unsigned long ctx_dec[134]; /*!< decryption context */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Session specific compression layer
|
||||||
|
*/
|
||||||
|
#if defined(POLARSSL_ZLIB_SUPPORT)
|
||||||
|
z_stream ctx_deflate; /*!< compression context */
|
||||||
|
z_stream ctx_inflate; /*!< decompression context */
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This structure contains the parameters only needed during handshake.
|
||||||
|
*/
|
||||||
|
struct _ssl_handshake_params
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Handshake specific crypto variables
|
||||||
|
*/
|
||||||
|
#if defined(POLARSSL_DHM_C)
|
||||||
|
dhm_context dhm_ctx; /*!< DHM key exchange */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Checksum contexts
|
||||||
|
*/
|
||||||
|
md5_context fin_md5;
|
||||||
|
sha1_context fin_sha1;
|
||||||
|
sha2_context fin_sha2;
|
||||||
|
sha4_context fin_sha4;
|
||||||
|
|
||||||
|
void (*update_checksum)(ssl_context *, unsigned char *, size_t);
|
||||||
|
void (*calc_verify)(ssl_context *, unsigned char *);
|
||||||
|
void (*calc_finished)(ssl_context *, unsigned char *, int);
|
||||||
|
int (*tls_prf)(unsigned char *, size_t, char *,
|
||||||
|
unsigned char *, size_t,
|
||||||
|
unsigned char *, size_t);
|
||||||
|
|
||||||
|
size_t pmslen; /*!< premaster length */
|
||||||
|
|
||||||
|
unsigned char randbytes[64]; /*!< random bytes */
|
||||||
|
unsigned char premaster[256]; /*!< premaster secret */
|
||||||
|
};
|
||||||
|
|
||||||
struct _ssl_context
|
struct _ssl_context
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Miscellaneous
|
* Miscellaneous
|
||||||
*/
|
*/
|
||||||
int state; /*!< SSL handshake: current state */
|
int state; /*!< SSL handshake: current state */
|
||||||
|
int renegotiation; /*!< Initial or renegotiation */
|
||||||
|
|
||||||
int major_ver; /*!< equal to SSL_MAJOR_VERSION_3 */
|
int major_ver; /*!< equal to SSL_MAJOR_VERSION_3 */
|
||||||
int minor_ver; /*!< either 0 (SSL3) or 1 (TLS1.0) */
|
int minor_ver; /*!< either 0 (SSL3) or 1 (TLS1.0) */
|
||||||
@ -307,10 +397,24 @@ struct _ssl_context
|
|||||||
*/
|
*/
|
||||||
int resume; /*!< session resuming flag */
|
int resume; /*!< session resuming flag */
|
||||||
int timeout; /*!< sess. expiration time */
|
int timeout; /*!< sess. expiration time */
|
||||||
ssl_session *session; /*!< current session data */
|
ssl_session *session_in; /*!< current session data (in) */
|
||||||
|
ssl_session *session_out; /*!< current session data (out) */
|
||||||
|
ssl_session *session; /*!< negotiated session data */
|
||||||
|
ssl_session *session_negotiate; /*!< session data in negotiation */
|
||||||
int (*s_get)(ssl_context *); /*!< (server) get callback */
|
int (*s_get)(ssl_context *); /*!< (server) get callback */
|
||||||
int (*s_set)(ssl_context *); /*!< (server) set callback */
|
int (*s_set)(ssl_context *); /*!< (server) set callback */
|
||||||
|
|
||||||
|
ssl_handshake_params *handshake; /*!< params required only during
|
||||||
|
the handshake process */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Record layer transformations
|
||||||
|
*/
|
||||||
|
ssl_transform *transform_in; /*!< current transform params (in) */
|
||||||
|
ssl_transform *transform_out; /*!< current transform params (in) */
|
||||||
|
ssl_transform *transform; /*!< negotiated transform params */
|
||||||
|
ssl_transform *transform_negotiate; /*!< transform params in negotiation */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Record layer (incoming data)
|
* Record layer (incoming data)
|
||||||
*/
|
*/
|
||||||
@ -347,51 +451,22 @@ struct _ssl_context
|
|||||||
x509_cert *own_cert; /*!< own X.509 certificate */
|
x509_cert *own_cert; /*!< own X.509 certificate */
|
||||||
x509_cert *ca_chain; /*!< own trusted CA chain */
|
x509_cert *ca_chain; /*!< own trusted CA chain */
|
||||||
x509_crl *ca_crl; /*!< trusted CA CRLs */
|
x509_crl *ca_crl; /*!< trusted CA CRLs */
|
||||||
x509_cert *peer_cert; /*!< peer X.509 cert chain */
|
|
||||||
const char *peer_cn; /*!< expected peer CN */
|
const char *peer_cn; /*!< expected peer CN */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* User settings
|
||||||
|
*/
|
||||||
int endpoint; /*!< 0: client, 1: server */
|
int endpoint; /*!< 0: client, 1: server */
|
||||||
int authmode; /*!< verification mode */
|
int authmode; /*!< verification mode */
|
||||||
int client_auth; /*!< flag for client auth. */
|
int client_auth; /*!< flag for client auth. */
|
||||||
int verify_result; /*!< verification result */
|
int verify_result; /*!< verification result */
|
||||||
|
int disable_renegotiation; /*!< enable/disable renegotiation */
|
||||||
/*
|
int allow_legacy_renegotiation; /*!< allow legacy renegotiation */
|
||||||
* Crypto layer
|
|
||||||
*/
|
|
||||||
dhm_context dhm_ctx; /*!< DHM key exchange */
|
|
||||||
unsigned char ctx_checksum[500]; /*!< Checksum context(s) */
|
|
||||||
|
|
||||||
void (*update_checksum)(ssl_context *, unsigned char *, size_t);
|
|
||||||
void (*calc_verify)(ssl_context *, unsigned char *);
|
|
||||||
void (*calc_finished)(ssl_context *, unsigned char *, int);
|
|
||||||
int (*tls_prf)(unsigned char *, size_t, char *,
|
|
||||||
unsigned char *, size_t,
|
|
||||||
unsigned char *, size_t);
|
|
||||||
|
|
||||||
int do_crypt; /*!< en(de)cryption flag */
|
|
||||||
const int *ciphersuites; /*!< allowed ciphersuites */
|
const int *ciphersuites; /*!< allowed ciphersuites */
|
||||||
size_t pmslen; /*!< premaster length */
|
|
||||||
unsigned int keylen; /*!< symmetric key length */
|
|
||||||
size_t minlen; /*!< min. ciphertext length */
|
|
||||||
size_t ivlen; /*!< IV length */
|
|
||||||
size_t fixed_ivlen; /*!< Fixed part of IV (AEAD) */
|
|
||||||
size_t maclen; /*!< MAC length */
|
|
||||||
|
|
||||||
unsigned char randbytes[64]; /*!< random bytes */
|
#if defined(POLARSSL_DHM_C)
|
||||||
unsigned char premaster[256]; /*!< premaster secret */
|
mpi dhm_P; /*!< prime modulus for DHM */
|
||||||
|
mpi dhm_G; /*!< generator for DHM */
|
||||||
unsigned char iv_enc[16]; /*!< IV (encryption) */
|
|
||||||
unsigned char iv_dec[16]; /*!< IV (decryption) */
|
|
||||||
|
|
||||||
unsigned char mac_enc[32]; /*!< MAC (encryption) */
|
|
||||||
unsigned char mac_dec[32]; /*!< MAC (decryption) */
|
|
||||||
|
|
||||||
unsigned long ctx_enc[134]; /*!< encryption context */
|
|
||||||
unsigned long ctx_dec[134]; /*!< decryption context */
|
|
||||||
|
|
||||||
#if defined(POLARSSL_ZLIB_SUPPORT)
|
|
||||||
z_stream ctx_deflate; /*!< compression context */
|
|
||||||
z_stream ctx_inflate; /*!< decompression context */
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -399,6 +474,15 @@ struct _ssl_context
|
|||||||
*/
|
*/
|
||||||
unsigned char *hostname;
|
unsigned char *hostname;
|
||||||
size_t hostname_len;
|
size_t hostname_len;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Secure renegotiation
|
||||||
|
*/
|
||||||
|
int secure_renegotiation; /*!< does peer support legacy or
|
||||||
|
secure renegotiation */
|
||||||
|
size_t verify_data_len; /*!< length of verify data stored */
|
||||||
|
char own_verify_data[36]; /*!< previous handshake verify data */
|
||||||
|
char peer_verify_data[36]; /*!< previous handshake verify data */
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@ -465,7 +549,8 @@ int ssl_init( ssl_context *ssl );
|
|||||||
* pointers and data.
|
* pointers and data.
|
||||||
*
|
*
|
||||||
* \param ssl SSL context
|
* \param ssl SSL context
|
||||||
* \return 0 if successful, or POLARSSL_ERR_SSL_HW_ACCEL_FAILED or
|
* \return 0 if successful, or POLASSL_ERR_SSL_MALLOC_FAILED,
|
||||||
|
POLARSSL_ERR_SSL_HW_ACCEL_FAILED or
|
||||||
* POLARSSL_ERR_SSL_COMPRESSION_FAILED
|
* POLARSSL_ERR_SSL_COMPRESSION_FAILED
|
||||||
*/
|
*/
|
||||||
int ssl_session_reset( ssl_context *ssl );
|
int ssl_session_reset( ssl_context *ssl );
|
||||||
@ -614,6 +699,7 @@ void ssl_set_own_cert_pkcs11( ssl_context *ssl, x509_cert *own_cert,
|
|||||||
pkcs11_context *pkcs11_key );
|
pkcs11_context *pkcs11_key );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(POLARSSL_DHM_C)
|
||||||
/**
|
/**
|
||||||
* \brief Set the Diffie-Hellman public P and G values,
|
* \brief Set the Diffie-Hellman public P and G values,
|
||||||
* read as hexadecimal strings (server-side only)
|
* read as hexadecimal strings (server-side only)
|
||||||
@ -636,6 +722,7 @@ int ssl_set_dh_param( ssl_context *ssl, const char *dhm_P, const char *dhm_G );
|
|||||||
* \return 0 if successful
|
* \return 0 if successful
|
||||||
*/
|
*/
|
||||||
int ssl_set_dh_param_ctx( ssl_context *ssl, dhm_context *dhm_ctx );
|
int ssl_set_dh_param_ctx( ssl_context *ssl, dhm_context *dhm_ctx );
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Set hostname for ServerName TLS Extension
|
* \brief Set hostname for ServerName TLS Extension
|
||||||
@ -659,6 +746,29 @@ int ssl_set_hostname( ssl_context *ssl, const char *hostname );
|
|||||||
*/
|
*/
|
||||||
void ssl_set_max_version( ssl_context *ssl, int major, int minor );
|
void ssl_set_max_version( ssl_context *ssl, int major, int minor );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Enable / Disable renegotiation support for connection
|
||||||
|
* (Default: SSL_RENEGOTIATION_ENABLED)
|
||||||
|
*
|
||||||
|
* \param ssl SSL context
|
||||||
|
* \param renegotiation Enable or disable (SSL_RENEGOTIATION_ENABLED or
|
||||||
|
* SSL_RENEGOTIATION_DISABLED)
|
||||||
|
*/
|
||||||
|
void ssl_set_renegotiation( ssl_context *ssl, int renegotiation );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Prevent or allow legacy renegotiation.
|
||||||
|
* (Default: SSL_NO_LEGACY_RENEGOTIATION)
|
||||||
|
* Allowing legacy renegotiation makes the connection
|
||||||
|
* vulnerable to specific man in the middle attacks.
|
||||||
|
* (See RFC 5746)
|
||||||
|
*
|
||||||
|
* \param ssl SSL context
|
||||||
|
* \param allow_legacy Prevent or allow (SSL_NO_LEGACY_RENEGOTIATION or
|
||||||
|
* SSL_ALLOW_LEGACY_RENEGOTIATION)
|
||||||
|
*/
|
||||||
|
void ssl_legacy_renegotiation( ssl_context *ssl, int allow_legacy );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Return the number of data bytes available to read
|
* \brief Return the number of data bytes available to read
|
||||||
*
|
*
|
||||||
@ -709,6 +819,15 @@ const char *ssl_get_version( const ssl_context *ssl );
|
|||||||
*/
|
*/
|
||||||
int ssl_handshake( ssl_context *ssl );
|
int ssl_handshake( ssl_context *ssl );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Perform an SSL renegotiation on the running connection
|
||||||
|
*
|
||||||
|
* \param ssl SSL context
|
||||||
|
*
|
||||||
|
* \return 0 if succesful, or any ssl_handshake() return value.
|
||||||
|
*/
|
||||||
|
int ssl_renegotiate( ssl_context *ssl );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Read at most 'len' application data bytes
|
* \brief Read at most 'len' application data bytes
|
||||||
*
|
*
|
||||||
@ -758,17 +877,42 @@ int ssl_send_alert_message( ssl_context *ssl,
|
|||||||
int ssl_close_notify( ssl_context *ssl );
|
int ssl_close_notify( ssl_context *ssl );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Free an SSL context
|
* \brief Free referenced items in an SSL context and clear memory
|
||||||
*
|
*
|
||||||
* \param ssl SSL context
|
* \param ssl SSL context
|
||||||
*/
|
*/
|
||||||
void ssl_free( ssl_context *ssl );
|
void ssl_free( ssl_context *ssl );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Free referenced items in an SSL session and free all
|
||||||
|
* sessions in the chain. Memory is cleared
|
||||||
|
*
|
||||||
|
* \param session SSL session
|
||||||
|
*/
|
||||||
|
void ssl_session_free( ssl_session *session );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Free referenced items in an SSL transform context and clear
|
||||||
|
* memory
|
||||||
|
*
|
||||||
|
* \param transform SSL transform context
|
||||||
|
*/
|
||||||
|
void ssl_transform_free( ssl_transform *transform );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Free referenced items in an SSL handshake context and clear
|
||||||
|
* memory
|
||||||
|
*
|
||||||
|
* \param handshake SSL handshake context
|
||||||
|
*/
|
||||||
|
void ssl_handshake_free( ssl_handshake_params *handshake );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Internal functions (do not call directly)
|
* Internal functions (do not call directly)
|
||||||
*/
|
*/
|
||||||
int ssl_handshake_client( ssl_context *ssl );
|
int ssl_handshake_client( ssl_context *ssl );
|
||||||
int ssl_handshake_server( ssl_context *ssl );
|
int ssl_handshake_server( ssl_context *ssl );
|
||||||
|
void ssl_handshake_wrapup( ssl_context *ssl );
|
||||||
|
|
||||||
int ssl_derive_keys( ssl_context *ssl );
|
int ssl_derive_keys( ssl_context *ssl );
|
||||||
|
|
||||||
@ -791,8 +935,7 @@ int ssl_write_change_cipher_spec( ssl_context *ssl );
|
|||||||
int ssl_parse_finished( ssl_context *ssl );
|
int ssl_parse_finished( ssl_context *ssl );
|
||||||
int ssl_write_finished( ssl_context *ssl );
|
int ssl_write_finished( ssl_context *ssl );
|
||||||
|
|
||||||
void ssl_kickstart_checksum( ssl_context *ssl, int ciphersuite,
|
void ssl_optimize_checksum( ssl_context *ssl, int ciphersuite );
|
||||||
unsigned char *input_buf, size_t len );
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -54,8 +54,11 @@ static int ssl_write_client_hello( ssl_context *ssl )
|
|||||||
|
|
||||||
SSL_DEBUG_MSG( 2, ( "=> write client hello" ) );
|
SSL_DEBUG_MSG( 2, ( "=> write client hello" ) );
|
||||||
|
|
||||||
ssl->major_ver = SSL_MAJOR_VERSION_3;
|
if( ssl->renegotiation == SSL_INITIAL_HANDSHAKE )
|
||||||
ssl->minor_ver = SSL_MINOR_VERSION_0;
|
{
|
||||||
|
ssl->major_ver = SSL_MAJOR_VERSION_3;
|
||||||
|
ssl->minor_ver = SSL_MINOR_VERSION_0;
|
||||||
|
}
|
||||||
|
|
||||||
if( ssl->max_major_ver == 0 && ssl->max_minor_ver == 0 )
|
if( ssl->max_major_ver == 0 && ssl->max_minor_ver == 0 )
|
||||||
{
|
{
|
||||||
@ -92,7 +95,7 @@ static int ssl_write_client_hello( ssl_context *ssl )
|
|||||||
|
|
||||||
p += 28;
|
p += 28;
|
||||||
|
|
||||||
memcpy( ssl->randbytes, buf + 6, 32 );
|
memcpy( ssl->handshake->randbytes, buf + 6, 32 );
|
||||||
|
|
||||||
SSL_DEBUG_BUF( 3, "client hello, random bytes", buf + 6, 32 );
|
SSL_DEBUG_BUF( 3, "client hello, random bytes", buf + 6, 32 );
|
||||||
|
|
||||||
@ -106,24 +109,36 @@ static int ssl_write_client_hello( ssl_context *ssl )
|
|||||||
* .. . .. extensions length
|
* .. . .. extensions length
|
||||||
* .. . .. extensions
|
* .. . .. extensions
|
||||||
*/
|
*/
|
||||||
n = ssl->session->length;
|
n = ssl->session_negotiate->length;
|
||||||
|
|
||||||
if( n < 16 || n > 32 || ssl->resume == 0 ||
|
if( n < 16 || n > 32 || ssl->resume == 0 ||
|
||||||
( ssl->timeout != 0 && t - ssl->session->start > ssl->timeout ) )
|
( ssl->timeout != 0 &&
|
||||||
|
t - ssl->session_negotiate->start > ssl->timeout ) )
|
||||||
n = 0;
|
n = 0;
|
||||||
|
|
||||||
*p++ = (unsigned char) n;
|
*p++ = (unsigned char) n;
|
||||||
|
|
||||||
for( i = 0; i < n; i++ )
|
for( i = 0; i < n; i++ )
|
||||||
*p++ = ssl->session->id[i];
|
*p++ = ssl->session_negotiate->id[i];
|
||||||
|
|
||||||
SSL_DEBUG_MSG( 3, ( "client hello, session id len.: %d", n ) );
|
SSL_DEBUG_MSG( 3, ( "client hello, session id len.: %d", n ) );
|
||||||
SSL_DEBUG_BUF( 3, "client hello, session id", buf + 39, n );
|
SSL_DEBUG_BUF( 3, "client hello, session id", buf + 39, n );
|
||||||
|
|
||||||
for( n = 0; ssl->ciphersuites[n] != 0; n++ );
|
for( n = 0; ssl->ciphersuites[n] != 0; n++ );
|
||||||
|
if( ssl->renegotiation == SSL_INITIAL_HANDSHAKE ) n++;
|
||||||
*p++ = (unsigned char)( n >> 7 );
|
*p++ = (unsigned char)( n >> 7 );
|
||||||
*p++ = (unsigned char)( n << 1 );
|
*p++ = (unsigned char)( n << 1 );
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add TLS_EMPTY_RENEGOTIATION_INFO_SCSV
|
||||||
|
*/
|
||||||
|
if( ssl->renegotiation == SSL_INITIAL_HANDSHAKE )
|
||||||
|
{
|
||||||
|
*p++ = (unsigned char)( SSL_EMPTY_RENEGOTIATION_INFO >> 8 );
|
||||||
|
*p++ = (unsigned char)( SSL_EMPTY_RENEGOTIATION_INFO );
|
||||||
|
n--;
|
||||||
|
}
|
||||||
|
|
||||||
SSL_DEBUG_MSG( 3, ( "client hello, got %d ciphersuites", n ) );
|
SSL_DEBUG_MSG( 3, ( "client hello, got %d ciphersuites", n ) );
|
||||||
|
|
||||||
for( i = 0; i < n; i++ )
|
for( i = 0; i < n; i++ )
|
||||||
@ -138,11 +153,11 @@ static int ssl_write_client_hello( ssl_context *ssl )
|
|||||||
#if defined(POLARSSL_ZLIB_SUPPORT)
|
#if defined(POLARSSL_ZLIB_SUPPORT)
|
||||||
SSL_DEBUG_MSG( 3, ( "client hello, compress len.: %d", 2 ) );
|
SSL_DEBUG_MSG( 3, ( "client hello, compress len.: %d", 2 ) );
|
||||||
SSL_DEBUG_MSG( 3, ( "client hello, compress alg.: %d %d",
|
SSL_DEBUG_MSG( 3, ( "client hello, compress alg.: %d %d",
|
||||||
SSL_COMPRESS_NULL, SSL_COMPRESS_DEFLATE ) );
|
SSL_COMPRESS_DEFLATE, SSL_COMPRESS_NULL ) );
|
||||||
|
|
||||||
*p++ = 2;
|
*p++ = 2;
|
||||||
*p++ = SSL_COMPRESS_NULL;
|
|
||||||
*p++ = SSL_COMPRESS_DEFLATE;
|
*p++ = SSL_COMPRESS_DEFLATE;
|
||||||
|
*p++ = SSL_COMPRESS_NULL;
|
||||||
#else
|
#else
|
||||||
SSL_DEBUG_MSG( 3, ( "client hello, compress len.: %d", 1 ) );
|
SSL_DEBUG_MSG( 3, ( "client hello, compress len.: %d", 1 ) );
|
||||||
SSL_DEBUG_MSG( 3, ( "client hello, compress alg.: %d", SSL_COMPRESS_NULL ) );
|
SSL_DEBUG_MSG( 3, ( "client hello, compress alg.: %d", SSL_COMPRESS_NULL ) );
|
||||||
@ -159,6 +174,12 @@ static int ssl_write_client_hello( ssl_context *ssl )
|
|||||||
ext_len += ssl->hostname_len + 9;
|
ext_len += ssl->hostname_len + 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( ssl->renegotiation == SSL_RENEGOTIATION )
|
||||||
|
{
|
||||||
|
SSL_DEBUG_MSG( 3, ( "client hello, prepping for renegotiation extension" ) );
|
||||||
|
ext_len += 5 + ssl->verify_data_len;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Prepare signature_algorithms extension (TLS 1.2)
|
* Prepare signature_algorithms extension (TLS 1.2)
|
||||||
*/
|
*/
|
||||||
@ -184,7 +205,7 @@ static int ssl_write_client_hello( ssl_context *ssl )
|
|||||||
sig_alg_list[sig_alg_len++] = SSL_HASH_MD5;
|
sig_alg_list[sig_alg_len++] = SSL_HASH_MD5;
|
||||||
sig_alg_list[sig_alg_len++] = SSL_SIG_RSA;
|
sig_alg_list[sig_alg_len++] = SSL_SIG_RSA;
|
||||||
#endif
|
#endif
|
||||||
ext_len = 6 + sig_alg_len;
|
ext_len += 6 + sig_alg_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSL_DEBUG_MSG( 3, ( "client hello, total extension length: %d",
|
SSL_DEBUG_MSG( 3, ( "client hello, total extension length: %d",
|
||||||
@ -230,10 +251,27 @@ static int ssl_write_client_hello( ssl_context *ssl )
|
|||||||
*p++ = (unsigned char)( ( ssl->hostname_len ) & 0xFF );
|
*p++ = (unsigned char)( ( ssl->hostname_len ) & 0xFF );
|
||||||
|
|
||||||
memcpy( p, ssl->hostname, ssl->hostname_len );
|
memcpy( p, ssl->hostname, ssl->hostname_len );
|
||||||
|
|
||||||
p += ssl->hostname_len;
|
p += ssl->hostname_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( ssl->renegotiation == SSL_RENEGOTIATION )
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Secure renegotiation
|
||||||
|
*/
|
||||||
|
SSL_DEBUG_MSG( 3, ( "client hello, renegotiation info extension" ) );
|
||||||
|
|
||||||
|
*p++ = (unsigned char)( ( TLS_EXT_RENEGOTIATION_INFO >> 8 ) & 0xFF );
|
||||||
|
*p++ = (unsigned char)( ( TLS_EXT_RENEGOTIATION_INFO ) & 0xFF );
|
||||||
|
|
||||||
|
*p++ = 0x00;
|
||||||
|
*p++ = ( ssl->verify_data_len + 1 ) & 0xFF;
|
||||||
|
*p++ = ssl->verify_data_len & 0xFF;
|
||||||
|
|
||||||
|
memcpy( p, ssl->own_verify_data, ssl->verify_data_len );
|
||||||
|
p += ssl->verify_data_len;
|
||||||
|
}
|
||||||
|
|
||||||
if( ssl->max_minor_ver == SSL_MINOR_VERSION_3 )
|
if( ssl->max_minor_ver == SSL_MINOR_VERSION_3 )
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@ -286,6 +324,38 @@ static int ssl_write_client_hello( ssl_context *ssl )
|
|||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int ssl_parse_renegotiation_info( ssl_context *ssl,
|
||||||
|
unsigned char *buf,
|
||||||
|
size_t len )
|
||||||
|
{
|
||||||
|
if( ssl->renegotiation == SSL_INITIAL_HANDSHAKE )
|
||||||
|
{
|
||||||
|
if( len != 1 || buf[0] != 0x0 )
|
||||||
|
{
|
||||||
|
SSL_DEBUG_MSG( 1, ( "non-zero length renegotiated connection field" ) );
|
||||||
|
/* TODO: Send handshake failure alert */
|
||||||
|
return( POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO );
|
||||||
|
}
|
||||||
|
|
||||||
|
ssl->secure_renegotiation = SSL_SECURE_RENEGOTIATION;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if( len != 1 + ssl->verify_data_len * 2 ||
|
||||||
|
buf[0] != ssl->verify_data_len * 2 ||
|
||||||
|
memcmp( buf + 1, ssl->own_verify_data, ssl->verify_data_len ) != 0 ||
|
||||||
|
memcmp( buf + 1 + ssl->verify_data_len,
|
||||||
|
ssl->peer_verify_data, ssl->verify_data_len ) != 0 )
|
||||||
|
{
|
||||||
|
SSL_DEBUG_MSG( 1, ( "non-matching renegotiated connection field" ) );
|
||||||
|
/* TODO: Send handshake failure alert */
|
||||||
|
return( POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
static int ssl_parse_server_hello( ssl_context *ssl )
|
static int ssl_parse_server_hello( ssl_context *ssl )
|
||||||
{
|
{
|
||||||
#if defined(POLARSSL_DEBUG_C)
|
#if defined(POLARSSL_DEBUG_C)
|
||||||
@ -293,8 +363,9 @@ static int ssl_parse_server_hello( ssl_context *ssl )
|
|||||||
#endif
|
#endif
|
||||||
int ret, i, comp;
|
int ret, i, comp;
|
||||||
size_t n;
|
size_t n;
|
||||||
int ext_len;
|
size_t ext_len = 0;
|
||||||
unsigned char *buf;
|
unsigned char *buf, *ext;
|
||||||
|
int renegotiation_info_seen = 0;
|
||||||
|
|
||||||
SSL_DEBUG_MSG( 2, ( "=> parse server hello" ) );
|
SSL_DEBUG_MSG( 2, ( "=> parse server hello" ) );
|
||||||
|
|
||||||
@ -345,13 +416,19 @@ static int ssl_parse_server_hello( ssl_context *ssl )
|
|||||||
| ( (time_t) buf[9] );
|
| ( (time_t) buf[9] );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
memcpy( ssl->randbytes + 32, buf + 6, 32 );
|
memcpy( ssl->handshake->randbytes + 32, buf + 6, 32 );
|
||||||
|
|
||||||
n = buf[38];
|
n = buf[38];
|
||||||
|
|
||||||
SSL_DEBUG_MSG( 3, ( "server hello, current time: %lu", t ) );
|
SSL_DEBUG_MSG( 3, ( "server hello, current time: %lu", t ) );
|
||||||
SSL_DEBUG_BUF( 3, "server hello, random bytes", buf + 6, 32 );
|
SSL_DEBUG_BUF( 3, "server hello, random bytes", buf + 6, 32 );
|
||||||
|
|
||||||
|
if( n > 32 )
|
||||||
|
{
|
||||||
|
SSL_DEBUG_MSG( 1, ( "bad server hello message" ) );
|
||||||
|
return( POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO );
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 38 . 38 session id length
|
* 38 . 38 session id length
|
||||||
* 39 . 38+n session id
|
* 39 . 38+n session id
|
||||||
@ -360,20 +437,17 @@ static int ssl_parse_server_hello( ssl_context *ssl )
|
|||||||
* 42+n . 43+n extensions length
|
* 42+n . 43+n extensions length
|
||||||
* 44+n . 44+n+m extensions
|
* 44+n . 44+n+m extensions
|
||||||
*/
|
*/
|
||||||
if( n > 32 || ssl->in_hslen > 42 + n )
|
if( ssl->in_hslen > 42 + n )
|
||||||
{
|
{
|
||||||
ext_len = ( ( buf[42 + n] << 8 )
|
ext_len = ( ( buf[42 + n] << 8 )
|
||||||
| ( buf[43 + n] ) ) + 2;
|
| ( buf[43 + n] ) );
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ext_len = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( n > 32 || ssl->in_hslen != 42 + n + ext_len )
|
if( ( ext_len > 0 && ext_len < 4 ) ||
|
||||||
{
|
ssl->in_hslen != 44 + n + ext_len )
|
||||||
SSL_DEBUG_MSG( 1, ( "bad server hello message" ) );
|
{
|
||||||
return( POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO );
|
SSL_DEBUG_MSG( 1, ( "bad server hello message" ) );
|
||||||
|
return( POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
i = ( buf[39 + n] << 8 ) | buf[40 + n];
|
i = ( buf[39 + n] << 8 ) | buf[40 + n];
|
||||||
@ -382,7 +456,7 @@ static int ssl_parse_server_hello( ssl_context *ssl )
|
|||||||
/*
|
/*
|
||||||
* Initialize update checksum functions
|
* Initialize update checksum functions
|
||||||
*/
|
*/
|
||||||
ssl_kickstart_checksum( ssl, i, buf, ssl->in_hslen );
|
ssl_optimize_checksum( ssl, i );
|
||||||
|
|
||||||
SSL_DEBUG_MSG( 3, ( "server hello, session id len.: %d", n ) );
|
SSL_DEBUG_MSG( 3, ( "server hello, session id len.: %d", n ) );
|
||||||
SSL_DEBUG_BUF( 3, "server hello, session id", buf + 39, n );
|
SSL_DEBUG_BUF( 3, "server hello, session id", buf + 39, n );
|
||||||
@ -391,18 +465,18 @@ static int ssl_parse_server_hello( ssl_context *ssl )
|
|||||||
* Check if the session can be resumed
|
* Check if the session can be resumed
|
||||||
*/
|
*/
|
||||||
if( ssl->resume == 0 || n == 0 ||
|
if( ssl->resume == 0 || n == 0 ||
|
||||||
ssl->session->ciphersuite != i ||
|
ssl->session_negotiate->ciphersuite != i ||
|
||||||
ssl->session->compression != comp ||
|
ssl->session_negotiate->compression != comp ||
|
||||||
ssl->session->length != n ||
|
ssl->session_negotiate->length != n ||
|
||||||
memcmp( ssl->session->id, buf + 39, n ) != 0 )
|
memcmp( ssl->session_negotiate->id, buf + 39, n ) != 0 )
|
||||||
{
|
{
|
||||||
ssl->state++;
|
ssl->state++;
|
||||||
ssl->resume = 0;
|
ssl->resume = 0;
|
||||||
ssl->session->start = time( NULL );
|
ssl->session_negotiate->start = time( NULL );
|
||||||
ssl->session->ciphersuite = i;
|
ssl->session_negotiate->ciphersuite = i;
|
||||||
ssl->session->compression = comp;
|
ssl->session_negotiate->compression = comp;
|
||||||
ssl->session->length = n;
|
ssl->session_negotiate->length = n;
|
||||||
memcpy( ssl->session->id, buf + 39, n );
|
memcpy( ssl->session_negotiate->id, buf + 39, n );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -430,7 +504,7 @@ static int ssl_parse_server_hello( ssl_context *ssl )
|
|||||||
return( POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO );
|
return( POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ssl->ciphersuites[i++] == ssl->session->ciphersuite )
|
if( ssl->ciphersuites[i++] == ssl->session_negotiate->ciphersuite )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -443,9 +517,66 @@ static int ssl_parse_server_hello( ssl_context *ssl )
|
|||||||
SSL_DEBUG_MSG( 1, ( "bad server hello message" ) );
|
SSL_DEBUG_MSG( 1, ( "bad server hello message" ) );
|
||||||
return( POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO );
|
return( POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO );
|
||||||
}
|
}
|
||||||
ssl->session->compression = comp;
|
ssl->session_negotiate->compression = comp;
|
||||||
|
|
||||||
/* TODO: Process extensions */
|
ext = buf + 44 + n;
|
||||||
|
|
||||||
|
while( ext_len )
|
||||||
|
{
|
||||||
|
unsigned int ext_id = ( ( ext[0] << 8 )
|
||||||
|
| ( ext[1] ) );
|
||||||
|
unsigned int ext_size = ( ( ext[2] << 8 )
|
||||||
|
| ( ext[3] ) );
|
||||||
|
|
||||||
|
if( ext_size + 4 > ext_len )
|
||||||
|
{
|
||||||
|
SSL_DEBUG_MSG( 1, ( "bad server hello message" ) );
|
||||||
|
return( POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO );
|
||||||
|
}
|
||||||
|
|
||||||
|
switch( ext_id )
|
||||||
|
{
|
||||||
|
case TLS_EXT_RENEGOTIATION_INFO:
|
||||||
|
SSL_DEBUG_MSG( 3, ( "found renegotiation extension" ) );
|
||||||
|
renegotiation_info_seen = 1;
|
||||||
|
|
||||||
|
if( ( ret = ssl_parse_renegotiation_info( ssl, ext + 4, ext_size ) ) != 0 )
|
||||||
|
return( ret );
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
SSL_DEBUG_MSG( 3, ( "unknown extension found: %d (ignoring)",
|
||||||
|
ext_id ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
ext_len -= 4 + ext_size;
|
||||||
|
ext += 4 + ext_size;
|
||||||
|
|
||||||
|
if( ext_len > 0 && ext_len < 4 )
|
||||||
|
{
|
||||||
|
SSL_DEBUG_MSG( 1, ( "bad server hello message" ) );
|
||||||
|
return( POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Renegotiation security checks
|
||||||
|
*/
|
||||||
|
if( ssl->renegotiation == SSL_RENEGOTIATION &&
|
||||||
|
ssl->secure_renegotiation == SSL_SECURE_RENEGOTIATION &&
|
||||||
|
renegotiation_info_seen == 0 )
|
||||||
|
{
|
||||||
|
SSL_DEBUG_MSG( 1, ( "renegotiation_info extension missing" ) );
|
||||||
|
return( POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( !ssl->allow_legacy_renegotiation &&
|
||||||
|
ssl->secure_renegotiation == SSL_LEGACY_RENEGOTIATION )
|
||||||
|
{
|
||||||
|
SSL_DEBUG_MSG( 1, ( "legacy renegotiation not allowed" ) );
|
||||||
|
return( POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO );
|
||||||
|
}
|
||||||
|
|
||||||
SSL_DEBUG_MSG( 2, ( "<= parse server hello" ) );
|
SSL_DEBUG_MSG( 2, ( "<= parse server hello" ) );
|
||||||
|
|
||||||
@ -467,18 +598,18 @@ static int ssl_parse_server_key_exchange( ssl_context *ssl )
|
|||||||
|
|
||||||
SSL_DEBUG_MSG( 2, ( "=> parse server key exchange" ) );
|
SSL_DEBUG_MSG( 2, ( "=> parse server key exchange" ) );
|
||||||
|
|
||||||
if( ssl->session->ciphersuite != SSL_EDH_RSA_DES_SHA &&
|
if( ssl->session_negotiate->ciphersuite != SSL_EDH_RSA_DES_SHA &&
|
||||||
ssl->session->ciphersuite != SSL_EDH_RSA_DES_168_SHA &&
|
ssl->session_negotiate->ciphersuite != SSL_EDH_RSA_DES_168_SHA &&
|
||||||
ssl->session->ciphersuite != SSL_EDH_RSA_AES_128_SHA &&
|
ssl->session_negotiate->ciphersuite != SSL_EDH_RSA_AES_128_SHA &&
|
||||||
ssl->session->ciphersuite != SSL_EDH_RSA_AES_256_SHA &&
|
ssl->session_negotiate->ciphersuite != SSL_EDH_RSA_AES_256_SHA &&
|
||||||
ssl->session->ciphersuite != SSL_EDH_RSA_AES_128_SHA256 &&
|
ssl->session_negotiate->ciphersuite != SSL_EDH_RSA_AES_128_SHA256 &&
|
||||||
ssl->session->ciphersuite != SSL_EDH_RSA_AES_256_SHA256 &&
|
ssl->session_negotiate->ciphersuite != SSL_EDH_RSA_AES_256_SHA256 &&
|
||||||
ssl->session->ciphersuite != SSL_EDH_RSA_CAMELLIA_128_SHA &&
|
ssl->session_negotiate->ciphersuite != SSL_EDH_RSA_CAMELLIA_128_SHA &&
|
||||||
ssl->session->ciphersuite != SSL_EDH_RSA_CAMELLIA_256_SHA &&
|
ssl->session_negotiate->ciphersuite != SSL_EDH_RSA_CAMELLIA_256_SHA &&
|
||||||
ssl->session->ciphersuite != SSL_EDH_RSA_CAMELLIA_128_SHA256 &&
|
ssl->session_negotiate->ciphersuite != SSL_EDH_RSA_CAMELLIA_128_SHA256 &&
|
||||||
ssl->session->ciphersuite != SSL_EDH_RSA_CAMELLIA_256_SHA256 &&
|
ssl->session_negotiate->ciphersuite != SSL_EDH_RSA_CAMELLIA_256_SHA256 &&
|
||||||
ssl->session->ciphersuite != SSL_EDH_RSA_AES_128_GCM_SHA256 &&
|
ssl->session_negotiate->ciphersuite != SSL_EDH_RSA_AES_128_GCM_SHA256 &&
|
||||||
ssl->session->ciphersuite != SSL_EDH_RSA_AES_256_GCM_SHA384 )
|
ssl->session_negotiate->ciphersuite != SSL_EDH_RSA_AES_256_GCM_SHA384 )
|
||||||
{
|
{
|
||||||
SSL_DEBUG_MSG( 2, ( "<= skip parse server key exchange" ) );
|
SSL_DEBUG_MSG( 2, ( "<= skip parse server key exchange" ) );
|
||||||
ssl->state++;
|
ssl->state++;
|
||||||
@ -521,7 +652,7 @@ static int ssl_parse_server_key_exchange( ssl_context *ssl )
|
|||||||
p = ssl->in_msg + 4;
|
p = ssl->in_msg + 4;
|
||||||
end = ssl->in_msg + ssl->in_hslen;
|
end = ssl->in_msg + ssl->in_hslen;
|
||||||
|
|
||||||
if( ( ret = dhm_read_params( &ssl->dhm_ctx, &p, end ) ) != 0 )
|
if( ( ret = dhm_read_params( &ssl->handshake->dhm_ctx, &p, end ) ) != 0 )
|
||||||
{
|
{
|
||||||
SSL_DEBUG_MSG( 2, ( "DHM Read Params returned -0x%x", -ret ) );
|
SSL_DEBUG_MSG( 2, ( "DHM Read Params returned -0x%x", -ret ) );
|
||||||
SSL_DEBUG_MSG( 1, ( "bad server key exchange message" ) );
|
SSL_DEBUG_MSG( 1, ( "bad server key exchange message" ) );
|
||||||
@ -585,21 +716,22 @@ static int ssl_parse_server_key_exchange( ssl_context *ssl )
|
|||||||
return( POLARSSL_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE );
|
return( POLARSSL_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( (unsigned int)( end - p ) != ssl->peer_cert->rsa.len )
|
if( (unsigned int)( end - p ) !=
|
||||||
|
ssl->session_negotiate->peer_cert->rsa.len )
|
||||||
{
|
{
|
||||||
SSL_DEBUG_MSG( 1, ( "bad server key exchange message" ) );
|
SSL_DEBUG_MSG( 1, ( "bad server key exchange message" ) );
|
||||||
return( POLARSSL_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE );
|
return( POLARSSL_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ssl->dhm_ctx.len < 64 || ssl->dhm_ctx.len > 512 )
|
if( ssl->handshake->dhm_ctx.len < 64 || ssl->handshake->dhm_ctx.len > 512 )
|
||||||
{
|
{
|
||||||
SSL_DEBUG_MSG( 1, ( "bad server key exchange message" ) );
|
SSL_DEBUG_MSG( 1, ( "bad server key exchange message" ) );
|
||||||
return( POLARSSL_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE );
|
return( POLARSSL_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE );
|
||||||
}
|
}
|
||||||
|
|
||||||
SSL_DEBUG_MPI( 3, "DHM: P ", &ssl->dhm_ctx.P );
|
SSL_DEBUG_MPI( 3, "DHM: P ", &ssl->handshake->dhm_ctx.P );
|
||||||
SSL_DEBUG_MPI( 3, "DHM: G ", &ssl->dhm_ctx.G );
|
SSL_DEBUG_MPI( 3, "DHM: G ", &ssl->handshake->dhm_ctx.G );
|
||||||
SSL_DEBUG_MPI( 3, "DHM: GY", &ssl->dhm_ctx.GY );
|
SSL_DEBUG_MPI( 3, "DHM: GY", &ssl->handshake->dhm_ctx.GY );
|
||||||
|
|
||||||
if( ssl->minor_ver != SSL_MINOR_VERSION_3 )
|
if( ssl->minor_ver != SSL_MINOR_VERSION_3 )
|
||||||
{
|
{
|
||||||
@ -619,12 +751,12 @@ static int ssl_parse_server_key_exchange( ssl_context *ssl )
|
|||||||
n = ssl->in_hslen - ( end - p ) - 6;
|
n = ssl->in_hslen - ( end - p ) - 6;
|
||||||
|
|
||||||
md5_starts( &md5 );
|
md5_starts( &md5 );
|
||||||
md5_update( &md5, ssl->randbytes, 64 );
|
md5_update( &md5, ssl->handshake->randbytes, 64 );
|
||||||
md5_update( &md5, ssl->in_msg + 4, n );
|
md5_update( &md5, ssl->in_msg + 4, n );
|
||||||
md5_finish( &md5, hash );
|
md5_finish( &md5, hash );
|
||||||
|
|
||||||
sha1_starts( &sha1 );
|
sha1_starts( &sha1 );
|
||||||
sha1_update( &sha1, ssl->randbytes, 64 );
|
sha1_update( &sha1, ssl->handshake->randbytes, 64 );
|
||||||
sha1_update( &sha1, ssl->in_msg + 4, n );
|
sha1_update( &sha1, ssl->in_msg + 4, n );
|
||||||
sha1_finish( &sha1, hash + 16 );
|
sha1_finish( &sha1, hash + 16 );
|
||||||
|
|
||||||
@ -650,7 +782,7 @@ static int ssl_parse_server_key_exchange( ssl_context *ssl )
|
|||||||
#if defined(POLARSSL_MD5_C)
|
#if defined(POLARSSL_MD5_C)
|
||||||
case SIG_RSA_MD5:
|
case SIG_RSA_MD5:
|
||||||
md5_starts( &md5 );
|
md5_starts( &md5 );
|
||||||
md5_update( &md5, ssl->randbytes, 64 );
|
md5_update( &md5, ssl->handshake->randbytes, 64 );
|
||||||
md5_update( &md5, ssl->in_msg + 4, n );
|
md5_update( &md5, ssl->in_msg + 4, n );
|
||||||
md5_finish( &md5, hash );
|
md5_finish( &md5, hash );
|
||||||
hashlen = 16;
|
hashlen = 16;
|
||||||
@ -659,7 +791,7 @@ static int ssl_parse_server_key_exchange( ssl_context *ssl )
|
|||||||
#if defined(POLARSSL_SHA1_C)
|
#if defined(POLARSSL_SHA1_C)
|
||||||
case SIG_RSA_SHA1:
|
case SIG_RSA_SHA1:
|
||||||
sha1_starts( &sha1 );
|
sha1_starts( &sha1 );
|
||||||
sha1_update( &sha1, ssl->randbytes, 64 );
|
sha1_update( &sha1, ssl->handshake->randbytes, 64 );
|
||||||
sha1_update( &sha1, ssl->in_msg + 4, n );
|
sha1_update( &sha1, ssl->in_msg + 4, n );
|
||||||
sha1_finish( &sha1, hash );
|
sha1_finish( &sha1, hash );
|
||||||
hashlen = 20;
|
hashlen = 20;
|
||||||
@ -668,14 +800,14 @@ static int ssl_parse_server_key_exchange( ssl_context *ssl )
|
|||||||
#if defined(POLARSSL_SHA2_C)
|
#if defined(POLARSSL_SHA2_C)
|
||||||
case SIG_RSA_SHA224:
|
case SIG_RSA_SHA224:
|
||||||
sha2_starts( &sha2, 1 );
|
sha2_starts( &sha2, 1 );
|
||||||
sha2_update( &sha2, ssl->randbytes, 64 );
|
sha2_update( &sha2, ssl->handshake->randbytes, 64 );
|
||||||
sha2_update( &sha2, ssl->in_msg + 4, n );
|
sha2_update( &sha2, ssl->in_msg + 4, n );
|
||||||
sha2_finish( &sha2, hash );
|
sha2_finish( &sha2, hash );
|
||||||
hashlen = 28;
|
hashlen = 28;
|
||||||
break;
|
break;
|
||||||
case SIG_RSA_SHA256:
|
case SIG_RSA_SHA256:
|
||||||
sha2_starts( &sha2, 0 );
|
sha2_starts( &sha2, 0 );
|
||||||
sha2_update( &sha2, ssl->randbytes, 64 );
|
sha2_update( &sha2, ssl->handshake->randbytes, 64 );
|
||||||
sha2_update( &sha2, ssl->in_msg + 4, n );
|
sha2_update( &sha2, ssl->in_msg + 4, n );
|
||||||
sha2_finish( &sha2, hash );
|
sha2_finish( &sha2, hash );
|
||||||
hashlen = 32;
|
hashlen = 32;
|
||||||
@ -684,14 +816,14 @@ static int ssl_parse_server_key_exchange( ssl_context *ssl )
|
|||||||
#if defined(POLARSSL_SHA4_C)
|
#if defined(POLARSSL_SHA4_C)
|
||||||
case SIG_RSA_SHA384:
|
case SIG_RSA_SHA384:
|
||||||
sha4_starts( &sha4, 1 );
|
sha4_starts( &sha4, 1 );
|
||||||
sha4_update( &sha4, ssl->randbytes, 64 );
|
sha4_update( &sha4, ssl->handshake->randbytes, 64 );
|
||||||
sha4_update( &sha4, ssl->in_msg + 4, n );
|
sha4_update( &sha4, ssl->in_msg + 4, n );
|
||||||
sha4_finish( &sha4, hash );
|
sha4_finish( &sha4, hash );
|
||||||
hashlen = 48;
|
hashlen = 48;
|
||||||
break;
|
break;
|
||||||
case SIG_RSA_SHA512:
|
case SIG_RSA_SHA512:
|
||||||
sha4_starts( &sha4, 0 );
|
sha4_starts( &sha4, 0 );
|
||||||
sha4_update( &sha4, ssl->randbytes, 64 );
|
sha4_update( &sha4, ssl->handshake->randbytes, 64 );
|
||||||
sha4_update( &sha4, ssl->in_msg + 4, n );
|
sha4_update( &sha4, ssl->in_msg + 4, n );
|
||||||
sha4_finish( &sha4, hash );
|
sha4_finish( &sha4, hash );
|
||||||
hashlen = 64;
|
hashlen = 64;
|
||||||
@ -702,7 +834,8 @@ static int ssl_parse_server_key_exchange( ssl_context *ssl )
|
|||||||
|
|
||||||
SSL_DEBUG_BUF( 3, "parameters hash", hash, hashlen );
|
SSL_DEBUG_BUF( 3, "parameters hash", hash, hashlen );
|
||||||
|
|
||||||
if( ( ret = rsa_pkcs1_verify( &ssl->peer_cert->rsa, RSA_PUBLIC,
|
if( ( ret = rsa_pkcs1_verify( &ssl->session_negotiate->peer_cert->rsa,
|
||||||
|
RSA_PUBLIC,
|
||||||
hash_id, hashlen, hash, p ) ) != 0 )
|
hash_id, hashlen, hash, p ) ) != 0 )
|
||||||
{
|
{
|
||||||
SSL_DEBUG_RET( 1, "rsa_pkcs1_verify", ret );
|
SSL_DEBUG_RET( 1, "rsa_pkcs1_verify", ret );
|
||||||
@ -802,18 +935,18 @@ static int ssl_write_client_key_exchange( ssl_context *ssl )
|
|||||||
|
|
||||||
SSL_DEBUG_MSG( 2, ( "=> write client key exchange" ) );
|
SSL_DEBUG_MSG( 2, ( "=> write client key exchange" ) );
|
||||||
|
|
||||||
if( ssl->session->ciphersuite == SSL_EDH_RSA_DES_SHA ||
|
if( ssl->session_negotiate->ciphersuite == SSL_EDH_RSA_DES_SHA ||
|
||||||
ssl->session->ciphersuite == SSL_EDH_RSA_DES_168_SHA ||
|
ssl->session_negotiate->ciphersuite == SSL_EDH_RSA_DES_168_SHA ||
|
||||||
ssl->session->ciphersuite == SSL_EDH_RSA_AES_128_SHA ||
|
ssl->session_negotiate->ciphersuite == SSL_EDH_RSA_AES_128_SHA ||
|
||||||
ssl->session->ciphersuite == SSL_EDH_RSA_AES_256_SHA ||
|
ssl->session_negotiate->ciphersuite == SSL_EDH_RSA_AES_256_SHA ||
|
||||||
ssl->session->ciphersuite == SSL_EDH_RSA_AES_128_SHA256 ||
|
ssl->session_negotiate->ciphersuite == SSL_EDH_RSA_AES_128_SHA256 ||
|
||||||
ssl->session->ciphersuite == SSL_EDH_RSA_AES_256_SHA256 ||
|
ssl->session_negotiate->ciphersuite == SSL_EDH_RSA_AES_256_SHA256 ||
|
||||||
ssl->session->ciphersuite == SSL_EDH_RSA_CAMELLIA_128_SHA ||
|
ssl->session_negotiate->ciphersuite == SSL_EDH_RSA_CAMELLIA_128_SHA ||
|
||||||
ssl->session->ciphersuite == SSL_EDH_RSA_CAMELLIA_256_SHA ||
|
ssl->session_negotiate->ciphersuite == SSL_EDH_RSA_CAMELLIA_256_SHA ||
|
||||||
ssl->session->ciphersuite == SSL_EDH_RSA_CAMELLIA_128_SHA256 ||
|
ssl->session_negotiate->ciphersuite == SSL_EDH_RSA_CAMELLIA_128_SHA256 ||
|
||||||
ssl->session->ciphersuite == SSL_EDH_RSA_CAMELLIA_256_SHA256 ||
|
ssl->session_negotiate->ciphersuite == SSL_EDH_RSA_CAMELLIA_256_SHA256 ||
|
||||||
ssl->session->ciphersuite == SSL_EDH_RSA_AES_128_GCM_SHA256 ||
|
ssl->session_negotiate->ciphersuite == SSL_EDH_RSA_AES_128_GCM_SHA256 ||
|
||||||
ssl->session->ciphersuite == SSL_EDH_RSA_AES_256_GCM_SHA384 )
|
ssl->session_negotiate->ciphersuite == SSL_EDH_RSA_AES_256_GCM_SHA384 )
|
||||||
{
|
{
|
||||||
#if !defined(POLARSSL_DHM_C)
|
#if !defined(POLARSSL_DHM_C)
|
||||||
SSL_DEBUG_MSG( 1, ( "support for dhm in not available" ) );
|
SSL_DEBUG_MSG( 1, ( "support for dhm in not available" ) );
|
||||||
@ -822,13 +955,13 @@ static int ssl_write_client_key_exchange( ssl_context *ssl )
|
|||||||
/*
|
/*
|
||||||
* DHM key exchange -- send G^X mod P
|
* DHM key exchange -- send G^X mod P
|
||||||
*/
|
*/
|
||||||
n = ssl->dhm_ctx.len;
|
n = ssl->handshake->dhm_ctx.len;
|
||||||
|
|
||||||
ssl->out_msg[4] = (unsigned char)( n >> 8 );
|
ssl->out_msg[4] = (unsigned char)( n >> 8 );
|
||||||
ssl->out_msg[5] = (unsigned char)( n );
|
ssl->out_msg[5] = (unsigned char)( n );
|
||||||
i = 6;
|
i = 6;
|
||||||
|
|
||||||
ret = dhm_make_public( &ssl->dhm_ctx, 256,
|
ret = dhm_make_public( &ssl->handshake->dhm_ctx, 256,
|
||||||
&ssl->out_msg[i], n,
|
&ssl->out_msg[i], n,
|
||||||
ssl->f_rng, ssl->p_rng );
|
ssl->f_rng, ssl->p_rng );
|
||||||
if( ret != 0 )
|
if( ret != 0 )
|
||||||
@ -837,20 +970,20 @@ static int ssl_write_client_key_exchange( ssl_context *ssl )
|
|||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
|
|
||||||
SSL_DEBUG_MPI( 3, "DHM: X ", &ssl->dhm_ctx.X );
|
SSL_DEBUG_MPI( 3, "DHM: X ", &ssl->handshake->dhm_ctx.X );
|
||||||
SSL_DEBUG_MPI( 3, "DHM: GX", &ssl->dhm_ctx.GX );
|
SSL_DEBUG_MPI( 3, "DHM: GX", &ssl->handshake->dhm_ctx.GX );
|
||||||
|
|
||||||
ssl->pmslen = ssl->dhm_ctx.len;
|
ssl->handshake->pmslen = ssl->handshake->dhm_ctx.len;
|
||||||
|
|
||||||
if( ( ret = dhm_calc_secret( &ssl->dhm_ctx,
|
if( ( ret = dhm_calc_secret( &ssl->handshake->dhm_ctx,
|
||||||
ssl->premaster,
|
ssl->handshake->premaster,
|
||||||
&ssl->pmslen ) ) != 0 )
|
&ssl->handshake->pmslen ) ) != 0 )
|
||||||
{
|
{
|
||||||
SSL_DEBUG_RET( 1, "dhm_calc_secret", ret );
|
SSL_DEBUG_RET( 1, "dhm_calc_secret", ret );
|
||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
|
|
||||||
SSL_DEBUG_MPI( 3, "DHM: K ", &ssl->dhm_ctx.K );
|
SSL_DEBUG_MPI( 3, "DHM: K ", &ssl->handshake->dhm_ctx.K );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -858,16 +991,17 @@ static int ssl_write_client_key_exchange( ssl_context *ssl )
|
|||||||
/*
|
/*
|
||||||
* RSA key exchange -- send rsa_public(pkcs1 v1.5(premaster))
|
* RSA key exchange -- send rsa_public(pkcs1 v1.5(premaster))
|
||||||
*/
|
*/
|
||||||
ssl->premaster[0] = (unsigned char) ssl->max_major_ver;
|
ssl->handshake->premaster[0] = (unsigned char) ssl->max_major_ver;
|
||||||
ssl->premaster[1] = (unsigned char) ssl->max_minor_ver;
|
ssl->handshake->premaster[1] = (unsigned char) ssl->max_minor_ver;
|
||||||
ssl->pmslen = 48;
|
ssl->handshake->pmslen = 48;
|
||||||
|
|
||||||
ret = ssl->f_rng( ssl->p_rng, ssl->premaster + 2, ssl->pmslen - 2 );
|
ret = ssl->f_rng( ssl->p_rng, ssl->handshake->premaster + 2,
|
||||||
|
ssl->handshake->pmslen - 2 );
|
||||||
if( ret != 0 )
|
if( ret != 0 )
|
||||||
return( ret );
|
return( ret );
|
||||||
|
|
||||||
i = 4;
|
i = 4;
|
||||||
n = ssl->peer_cert->rsa.len;
|
n = ssl->session_negotiate->peer_cert->rsa.len;
|
||||||
|
|
||||||
if( ssl->minor_ver != SSL_MINOR_VERSION_0 )
|
if( ssl->minor_ver != SSL_MINOR_VERSION_0 )
|
||||||
{
|
{
|
||||||
@ -876,10 +1010,11 @@ static int ssl_write_client_key_exchange( ssl_context *ssl )
|
|||||||
ssl->out_msg[5] = (unsigned char)( n );
|
ssl->out_msg[5] = (unsigned char)( n );
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = rsa_pkcs1_encrypt( &ssl->peer_cert->rsa,
|
ret = rsa_pkcs1_encrypt( &ssl->session_negotiate->peer_cert->rsa,
|
||||||
ssl->f_rng, ssl->p_rng,
|
ssl->f_rng, ssl->p_rng,
|
||||||
RSA_PUBLIC,
|
RSA_PUBLIC,
|
||||||
ssl->pmslen, ssl->premaster,
|
ssl->handshake->pmslen,
|
||||||
|
ssl->handshake->premaster,
|
||||||
ssl->out_msg + i );
|
ssl->out_msg + i );
|
||||||
if( ret != 0 )
|
if( ret != 0 )
|
||||||
{
|
{
|
||||||
@ -934,8 +1069,8 @@ static int ssl_write_certificate_verify( ssl_context *ssl )
|
|||||||
// Certificate Request according to RFC 5246. But OpenSSL only allows
|
// Certificate Request according to RFC 5246. But OpenSSL only allows
|
||||||
// SHA256 and SHA384. Find out why OpenSSL does this.
|
// SHA256 and SHA384. Find out why OpenSSL does this.
|
||||||
//
|
//
|
||||||
if( ssl->session->ciphersuite == SSL_RSA_AES_256_GCM_SHA384 ||
|
if( ssl->session_negotiate->ciphersuite == SSL_RSA_AES_256_GCM_SHA384 ||
|
||||||
ssl->session->ciphersuite == SSL_EDH_RSA_AES_256_GCM_SHA384 )
|
ssl->session_negotiate->ciphersuite == SSL_EDH_RSA_AES_256_GCM_SHA384 )
|
||||||
{
|
{
|
||||||
hash_id = SIG_RSA_SHA384;
|
hash_id = SIG_RSA_SHA384;
|
||||||
hashlen = 48;
|
hashlen = 48;
|
||||||
@ -963,7 +1098,7 @@ static int ssl_write_certificate_verify( ssl_context *ssl )
|
|||||||
/*
|
/*
|
||||||
* Make an RSA signature of the handshake digests
|
* Make an RSA signature of the handshake digests
|
||||||
*/
|
*/
|
||||||
ssl->calc_verify( ssl, hash );
|
ssl->handshake->calc_verify( ssl, hash );
|
||||||
|
|
||||||
if ( ssl->rsa_key )
|
if ( ssl->rsa_key )
|
||||||
n = ssl->rsa_key->len;
|
n = ssl->rsa_key->len;
|
||||||
@ -978,8 +1113,8 @@ static int ssl_write_certificate_verify( ssl_context *ssl )
|
|||||||
// Certificate Request according to RFC 5246. But OpenSSL only allows
|
// Certificate Request according to RFC 5246. But OpenSSL only allows
|
||||||
// SHA256 and SHA384. Find out why OpenSSL does this.
|
// SHA256 and SHA384. Find out why OpenSSL does this.
|
||||||
//
|
//
|
||||||
if( ssl->session->ciphersuite == SSL_RSA_AES_256_GCM_SHA384 ||
|
if( ssl->session_negotiate->ciphersuite == SSL_RSA_AES_256_GCM_SHA384 ||
|
||||||
ssl->session->ciphersuite == SSL_EDH_RSA_AES_256_GCM_SHA384 )
|
ssl->session_negotiate->ciphersuite == SSL_EDH_RSA_AES_256_GCM_SHA384 )
|
||||||
{
|
{
|
||||||
ssl->out_msg[4] = SSL_HASH_SHA384;
|
ssl->out_msg[4] = SSL_HASH_SHA384;
|
||||||
ssl->out_msg[5] = SSL_SIG_RSA;
|
ssl->out_msg[5] = SSL_SIG_RSA;
|
||||||
@ -999,12 +1134,12 @@ static int ssl_write_certificate_verify( ssl_context *ssl )
|
|||||||
if( ssl->rsa_key )
|
if( ssl->rsa_key )
|
||||||
{
|
{
|
||||||
ret = rsa_pkcs1_sign( ssl->rsa_key, ssl->f_rng, ssl->p_rng,
|
ret = rsa_pkcs1_sign( ssl->rsa_key, ssl->f_rng, ssl->p_rng,
|
||||||
RSA_PRIVATE, hash_id,
|
RSA_PRIVATE, hash_id,
|
||||||
hashlen, hash, ssl->out_msg + 6 + offset );
|
hashlen, hash, ssl->out_msg + 6 + offset );
|
||||||
} else {
|
} else {
|
||||||
#if defined(POLARSSL_PKCS11_C)
|
#if defined(POLARSSL_PKCS11_C)
|
||||||
ret = pkcs11_sign( ssl->pkcs11_key, RSA_PRIVATE, hash_id,
|
ret = pkcs11_sign( ssl->pkcs11_key, RSA_PRIVATE, hash_id,
|
||||||
hashlen, hash, ssl->out_msg + 6 + offset );
|
hashlen, hash, ssl->out_msg + 6 + offset );
|
||||||
#endif /* defined(POLARSSL_PKCS11_C) */
|
#endif /* defined(POLARSSL_PKCS11_C) */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1128,7 +1263,11 @@ int ssl_handshake_client( ssl_context *ssl )
|
|||||||
|
|
||||||
case SSL_FLUSH_BUFFERS:
|
case SSL_FLUSH_BUFFERS:
|
||||||
SSL_DEBUG_MSG( 2, ( "handshake: done" ) );
|
SSL_DEBUG_MSG( 2, ( "handshake: done" ) );
|
||||||
ssl->state = SSL_HANDSHAKE_OVER;
|
ssl->state = SSL_HANDSHAKE_WRAPUP;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SSL_HANDSHAKE_WRAPUP:
|
||||||
|
ssl_handshake_wrapup( ssl );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -38,6 +38,36 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
static int ssl_parse_renegotiation_info( ssl_context *ssl,
|
||||||
|
unsigned char *buf,
|
||||||
|
size_t len )
|
||||||
|
{
|
||||||
|
if( ssl->renegotiation == SSL_INITIAL_HANDSHAKE )
|
||||||
|
{
|
||||||
|
if( len != 1 || buf[0] != 0x0 )
|
||||||
|
{
|
||||||
|
SSL_DEBUG_MSG( 1, ( "non-zero length renegotiated connection field" ) );
|
||||||
|
/* TODO: Send handshake failure alert */
|
||||||
|
return( POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO );
|
||||||
|
}
|
||||||
|
|
||||||
|
ssl->secure_renegotiation = SSL_SECURE_RENEGOTIATION;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if( len != 1 + ssl->verify_data_len ||
|
||||||
|
buf[0] != ssl->verify_data_len ||
|
||||||
|
memcmp( buf + 1, ssl->peer_verify_data, ssl->verify_data_len ) != 0 )
|
||||||
|
{
|
||||||
|
SSL_DEBUG_MSG( 1, ( "non-matching renegotiated connection field" ) );
|
||||||
|
/* TODO: Send handshake failure alert */
|
||||||
|
return( POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
static int ssl_parse_client_hello( ssl_context *ssl )
|
static int ssl_parse_client_hello( ssl_context *ssl )
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
@ -45,11 +75,14 @@ static int ssl_parse_client_hello( ssl_context *ssl )
|
|||||||
size_t n;
|
size_t n;
|
||||||
unsigned int ciph_len, sess_len;
|
unsigned int ciph_len, sess_len;
|
||||||
unsigned int comp_len;
|
unsigned int comp_len;
|
||||||
unsigned char *buf, *p;
|
unsigned int ext_len = 0;
|
||||||
|
unsigned char *buf, *p, *ext;
|
||||||
|
int renegotiation_info_seen;
|
||||||
|
|
||||||
SSL_DEBUG_MSG( 2, ( "=> parse client hello" ) );
|
SSL_DEBUG_MSG( 2, ( "=> parse client hello" ) );
|
||||||
|
|
||||||
if( ( ret = ssl_fetch_input( ssl, 5 ) ) != 0 )
|
if( ssl->renegotiation == SSL_INITIAL_HANDSHAKE &&
|
||||||
|
( ret = ssl_fetch_input( ssl, 5 ) ) != 0 )
|
||||||
{
|
{
|
||||||
SSL_DEBUG_RET( 1, "ssl_fetch_input", ret );
|
SSL_DEBUG_RET( 1, "ssl_fetch_input", ret );
|
||||||
return( ret );
|
return( ret );
|
||||||
@ -89,16 +122,20 @@ static int ssl_parse_client_hello( ssl_context *ssl )
|
|||||||
return( POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO );
|
return( POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ( ret = ssl_fetch_input( ssl, 5 + n ) ) != 0 )
|
if( ssl->renegotiation == SSL_INITIAL_HANDSHAKE &&
|
||||||
|
( ret = ssl_fetch_input( ssl, 5 + n ) ) != 0 )
|
||||||
{
|
{
|
||||||
SSL_DEBUG_RET( 1, "ssl_fetch_input", ret );
|
SSL_DEBUG_RET( 1, "ssl_fetch_input", ret );
|
||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
|
|
||||||
buf = ssl->in_msg;
|
buf = ssl->in_msg;
|
||||||
n = ssl->in_left - 5;
|
if( !ssl->renegotiation )
|
||||||
|
n = ssl->in_left - 5;
|
||||||
|
else
|
||||||
|
n = ssl->in_msglen;
|
||||||
|
|
||||||
ssl->update_checksum( ssl, buf, n );
|
ssl->handshake->update_checksum( ssl, buf, n );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* SSL layer:
|
* SSL layer:
|
||||||
@ -140,7 +177,7 @@ static int ssl_parse_client_hello( ssl_context *ssl )
|
|||||||
ssl->max_major_ver = buf[4];
|
ssl->max_major_ver = buf[4];
|
||||||
ssl->max_minor_ver = buf[5];
|
ssl->max_minor_ver = buf[5];
|
||||||
|
|
||||||
memcpy( ssl->randbytes, buf + 6, 32 );
|
memcpy( ssl->handshake->randbytes, buf + 6, 32 );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check the handshake message length
|
* Check the handshake message length
|
||||||
@ -162,9 +199,11 @@ static int ssl_parse_client_hello( ssl_context *ssl )
|
|||||||
return( POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO );
|
return( POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO );
|
||||||
}
|
}
|
||||||
|
|
||||||
ssl->session->length = sess_len;
|
ssl->session_negotiate->length = sess_len;
|
||||||
memset( ssl->session->id, 0, sizeof( ssl->session->id ) );
|
memset( ssl->session_negotiate->id, 0,
|
||||||
memcpy( ssl->session->id, buf + 39 , ssl->session->length );
|
sizeof( ssl->session_negotiate->id ) );
|
||||||
|
memcpy( ssl->session_negotiate->id, buf + 39,
|
||||||
|
ssl->session_negotiate->length );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check the ciphersuitelist length
|
* Check the ciphersuitelist length
|
||||||
@ -189,13 +228,30 @@ static int ssl_parse_client_hello( ssl_context *ssl )
|
|||||||
return( POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO );
|
return( POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO );
|
||||||
}
|
}
|
||||||
|
|
||||||
ssl->session->compression = SSL_COMPRESS_NULL;
|
/*
|
||||||
|
* Check the extension length
|
||||||
|
*/
|
||||||
|
if( n > 42 + sess_len + ciph_len + comp_len )
|
||||||
|
{
|
||||||
|
ext_len = ( buf[42 + sess_len + ciph_len + comp_len] << 8 )
|
||||||
|
| ( buf[43 + sess_len + ciph_len + comp_len] );
|
||||||
|
|
||||||
|
if( ( ext_len > 0 && ext_len < 4 ) ||
|
||||||
|
n != 44 + sess_len + ciph_len + comp_len + ext_len )
|
||||||
|
{
|
||||||
|
SSL_DEBUG_MSG( 1, ( "bad client hello message" ) );
|
||||||
|
SSL_DEBUG_BUF( 3, "Ext", buf + 44 + sess_len + ciph_len + comp_len, ext_len);
|
||||||
|
return( POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ssl->session_negotiate->compression = SSL_COMPRESS_NULL;
|
||||||
#if defined(POLARSSL_ZLIB_SUPPORT)
|
#if defined(POLARSSL_ZLIB_SUPPORT)
|
||||||
for( i = 0; i < comp_len; ++i )
|
for( i = 0; i < comp_len; ++i )
|
||||||
{
|
{
|
||||||
if( buf[41 + sess_len + ciph_len + i] == SSL_COMPRESS_DEFLATE )
|
if( buf[42 + sess_len + ciph_len + i] == SSL_COMPRESS_DEFLATE )
|
||||||
{
|
{
|
||||||
ssl->session->compression = SSL_COMPRESS_DEFLATE;
|
ssl->session_negotiate->compression = SSL_COMPRESS_DEFLATE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -210,6 +266,24 @@ static int ssl_parse_client_hello( ssl_context *ssl )
|
|||||||
SSL_DEBUG_BUF( 3, "client hello, compression",
|
SSL_DEBUG_BUF( 3, "client hello, compression",
|
||||||
buf + 42 + sess_len + ciph_len, comp_len );
|
buf + 42 + sess_len + ciph_len, comp_len );
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check for TLS_EMPTY_RENEGOTIATION_INFO_SCSV
|
||||||
|
*/
|
||||||
|
for( i = 0, p = buf + 41 + sess_len; i < ciph_len; i += 2, p += 2 )
|
||||||
|
{
|
||||||
|
if( p[0] == 0 && p[1] == SSL_EMPTY_RENEGOTIATION_INFO )
|
||||||
|
{
|
||||||
|
SSL_DEBUG_MSG( 3, ( "received TLS_EMPTY_RENEGOTIATION_INFO " ) );
|
||||||
|
if( ssl->renegotiation == SSL_RENEGOTIATION )
|
||||||
|
{
|
||||||
|
SSL_DEBUG_MSG( 1, ( "received RENEGOTIATION SCSV during renegotiation" ) );
|
||||||
|
return( POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO );
|
||||||
|
}
|
||||||
|
ssl->secure_renegotiation = SSL_SECURE_RENEGOTIATION;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Search for a matching ciphersuite
|
* Search for a matching ciphersuite
|
||||||
*/
|
*/
|
||||||
@ -228,9 +302,75 @@ static int ssl_parse_client_hello( ssl_context *ssl )
|
|||||||
return( POLARSSL_ERR_SSL_NO_CIPHER_CHOSEN );
|
return( POLARSSL_ERR_SSL_NO_CIPHER_CHOSEN );
|
||||||
|
|
||||||
have_ciphersuite:
|
have_ciphersuite:
|
||||||
|
ssl->session_negotiate->ciphersuite = ssl->ciphersuites[i];
|
||||||
|
ssl_optimize_checksum( ssl, ssl->session_negotiate->ciphersuite );
|
||||||
|
|
||||||
ssl->session->ciphersuite = ssl->ciphersuites[i];
|
ext = buf + 44 + sess_len + ciph_len + comp_len;
|
||||||
ssl_kickstart_checksum( ssl, ssl->session->ciphersuite, buf, n );
|
renegotiation_info_seen = 0;
|
||||||
|
|
||||||
|
while( ext_len )
|
||||||
|
{
|
||||||
|
unsigned int ext_id = ( ( ext[0] << 8 )
|
||||||
|
| ( ext[1] ) );
|
||||||
|
unsigned int ext_size = ( ( ext[2] << 8 )
|
||||||
|
| ( ext[3] ) );
|
||||||
|
|
||||||
|
if( ext_size + 4 > ext_len )
|
||||||
|
{
|
||||||
|
SSL_DEBUG_MSG( 1, ( "bad client hello message" ) );
|
||||||
|
return( POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO );
|
||||||
|
}
|
||||||
|
switch( ext_id )
|
||||||
|
{
|
||||||
|
case TLS_EXT_RENEGOTIATION_INFO:
|
||||||
|
SSL_DEBUG_MSG( 3, ( "found renegotiation extension" ) );
|
||||||
|
renegotiation_info_seen = 1;
|
||||||
|
|
||||||
|
if( ( ret = ssl_parse_renegotiation_info( ssl, ext + 4, ext_size ) ) != 0 )
|
||||||
|
return( ret );
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
SSL_DEBUG_MSG( 3, ( "unknown extension found: %d (ignoring)",
|
||||||
|
ext_id ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
ext_len -= 4 + ext_size;
|
||||||
|
ext += 4 + ext_size;
|
||||||
|
|
||||||
|
if( ext_len > 0 && ext_len < 4 )
|
||||||
|
{
|
||||||
|
SSL_DEBUG_MSG( 1, ( "bad client hello message" ) );
|
||||||
|
return( POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Renegotiation security checks
|
||||||
|
*/
|
||||||
|
if( ssl->renegotiation == SSL_RENEGOTIATION &&
|
||||||
|
ssl->secure_renegotiation == SSL_SECURE_RENEGOTIATION &&
|
||||||
|
renegotiation_info_seen == 0 )
|
||||||
|
{
|
||||||
|
SSL_DEBUG_MSG( 1, ( "renegotiation_info extension missing (secure)" ) );
|
||||||
|
return( POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( ssl->renegotiation == SSL_RENEGOTIATION &&
|
||||||
|
ssl->secure_renegotiation == SSL_LEGACY_RENEGOTIATION &&
|
||||||
|
renegotiation_info_seen == 1 )
|
||||||
|
{
|
||||||
|
SSL_DEBUG_MSG( 1, ( "renegotiation_info extension present (legacy)" ) );
|
||||||
|
return( POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( !ssl->allow_legacy_renegotiation &&
|
||||||
|
ssl->secure_renegotiation == SSL_LEGACY_RENEGOTIATION )
|
||||||
|
{
|
||||||
|
SSL_DEBUG_MSG( 1, ( "legacy renegotiation not allowed" ) );
|
||||||
|
return( POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO );
|
||||||
|
}
|
||||||
|
|
||||||
ssl->in_left = 0;
|
ssl->in_left = 0;
|
||||||
ssl->state++;
|
ssl->state++;
|
||||||
@ -244,6 +384,7 @@ static int ssl_write_server_hello( ssl_context *ssl )
|
|||||||
{
|
{
|
||||||
time_t t;
|
time_t t;
|
||||||
int ret, n;
|
int ret, n;
|
||||||
|
size_t ext_len = 0;
|
||||||
unsigned char *buf, *p;
|
unsigned char *buf, *p;
|
||||||
|
|
||||||
SSL_DEBUG_MSG( 2, ( "=> write server hello" ) );
|
SSL_DEBUG_MSG( 2, ( "=> write server hello" ) );
|
||||||
@ -277,7 +418,7 @@ static int ssl_write_server_hello( ssl_context *ssl )
|
|||||||
|
|
||||||
p += 28;
|
p += 28;
|
||||||
|
|
||||||
memcpy( ssl->randbytes + 32, buf + 6, 32 );
|
memcpy( ssl->handshake->randbytes + 32, buf + 6, 32 );
|
||||||
|
|
||||||
SSL_DEBUG_BUF( 3, "server hello, random bytes", buf + 6, 32 );
|
SSL_DEBUG_BUF( 3, "server hello, random bytes", buf + 6, 32 );
|
||||||
|
|
||||||
@ -287,8 +428,8 @@ static int ssl_write_server_hello( ssl_context *ssl )
|
|||||||
* 39+n . 40+n chosen ciphersuite
|
* 39+n . 40+n chosen ciphersuite
|
||||||
* 41+n . 41+n chosen compression alg.
|
* 41+n . 41+n chosen compression alg.
|
||||||
*/
|
*/
|
||||||
ssl->session->length = n = 32;
|
ssl->session_negotiate->length = n = 32;
|
||||||
*p++ = (unsigned char) ssl->session->length;
|
*p++ = (unsigned char) ssl->session_negotiate->length;
|
||||||
|
|
||||||
if( ssl->s_get == NULL ||
|
if( ssl->s_get == NULL ||
|
||||||
ssl->s_get( ssl ) != 0 )
|
ssl->s_get( ssl ) != 0 )
|
||||||
@ -299,13 +440,14 @@ static int ssl_write_server_hello( ssl_context *ssl )
|
|||||||
ssl->resume = 0;
|
ssl->resume = 0;
|
||||||
ssl->state++;
|
ssl->state++;
|
||||||
|
|
||||||
if( ssl->session == NULL )
|
if( ssl->session_negotiate == NULL )
|
||||||
{
|
{
|
||||||
SSL_DEBUG_MSG( 1, ( "No session struct set" ) );
|
SSL_DEBUG_MSG( 1, ( "No session struct set" ) );
|
||||||
return( POLARSSL_ERR_SSL_BAD_INPUT_DATA );
|
return( POLARSSL_ERR_SSL_BAD_INPUT_DATA );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ( ret = ssl->f_rng( ssl->p_rng, ssl->session->id, n ) ) != 0 )
|
if( ( ret = ssl->f_rng( ssl->p_rng, ssl->session_negotiate->id,
|
||||||
|
n ) ) != 0 )
|
||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -323,22 +465,48 @@ static int ssl_write_server_hello( ssl_context *ssl )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy( p, ssl->session->id, ssl->session->length );
|
memcpy( p, ssl->session_negotiate->id, ssl->session_negotiate->length );
|
||||||
p += ssl->session->length;
|
p += ssl->session_negotiate->length;
|
||||||
|
|
||||||
SSL_DEBUG_MSG( 3, ( "server hello, session id len.: %d", n ) );
|
SSL_DEBUG_MSG( 3, ( "server hello, session id len.: %d", n ) );
|
||||||
SSL_DEBUG_BUF( 3, "server hello, session id", buf + 39, n );
|
SSL_DEBUG_BUF( 3, "server hello, session id", buf + 39, n );
|
||||||
SSL_DEBUG_MSG( 3, ( "%s session has been resumed",
|
SSL_DEBUG_MSG( 3, ( "%s session has been resumed",
|
||||||
ssl->resume ? "a" : "no" ) );
|
ssl->resume ? "a" : "no" ) );
|
||||||
|
|
||||||
*p++ = (unsigned char)( ssl->session->ciphersuite >> 8 );
|
*p++ = (unsigned char)( ssl->session_negotiate->ciphersuite >> 8 );
|
||||||
*p++ = (unsigned char)( ssl->session->ciphersuite );
|
*p++ = (unsigned char)( ssl->session_negotiate->ciphersuite );
|
||||||
*p++ = (unsigned char)( ssl->session->compression );
|
*p++ = (unsigned char)( ssl->session_negotiate->compression );
|
||||||
|
|
||||||
SSL_DEBUG_MSG( 3, ( "server hello, chosen ciphersuite: %d",
|
SSL_DEBUG_MSG( 3, ( "server hello, chosen ciphersuite: %d",
|
||||||
ssl->session->ciphersuite ) );
|
ssl->session_negotiate->ciphersuite ) );
|
||||||
SSL_DEBUG_MSG( 3, ( "server hello, compress alg.: %d",
|
SSL_DEBUG_MSG( 3, ( "server hello, compress alg.: %d",
|
||||||
ssl->session->compression ) );
|
ssl->session_negotiate->compression ) );
|
||||||
|
|
||||||
|
SSL_DEBUG_MSG( 3, ( "server hello, prepping for secure renegotiation extension" ) );
|
||||||
|
ext_len += 5 + ssl->verify_data_len * 2;
|
||||||
|
|
||||||
|
SSL_DEBUG_MSG( 3, ( "server hello, total extension length: %d",
|
||||||
|
ext_len ) );
|
||||||
|
|
||||||
|
*p++ = (unsigned char)( ( ext_len >> 8 ) & 0xFF );
|
||||||
|
*p++ = (unsigned char)( ( ext_len ) & 0xFF );
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Secure renegotiation
|
||||||
|
*/
|
||||||
|
SSL_DEBUG_MSG( 3, ( "client hello, secure renegotiation extension" ) );
|
||||||
|
|
||||||
|
*p++ = (unsigned char)( ( TLS_EXT_RENEGOTIATION_INFO >> 8 ) & 0xFF );
|
||||||
|
*p++ = (unsigned char)( ( TLS_EXT_RENEGOTIATION_INFO ) & 0xFF );
|
||||||
|
|
||||||
|
*p++ = 0x00;
|
||||||
|
*p++ = ( ssl->verify_data_len * 2 + 1 ) & 0xFF;
|
||||||
|
*p++ = ssl->verify_data_len * 2 & 0xFF;
|
||||||
|
|
||||||
|
memcpy( p, ssl->peer_verify_data, ssl->verify_data_len );
|
||||||
|
p += ssl->verify_data_len;
|
||||||
|
memcpy( p, ssl->own_verify_data, ssl->verify_data_len );
|
||||||
|
p += ssl->verify_data_len;
|
||||||
|
|
||||||
ssl->out_msglen = p - buf;
|
ssl->out_msglen = p - buf;
|
||||||
ssl->out_msgtype = SSL_MSG_HANDSHAKE;
|
ssl->out_msgtype = SSL_MSG_HANDSHAKE;
|
||||||
@ -431,18 +599,18 @@ static int ssl_write_server_key_exchange( ssl_context *ssl )
|
|||||||
|
|
||||||
SSL_DEBUG_MSG( 2, ( "=> write server key exchange" ) );
|
SSL_DEBUG_MSG( 2, ( "=> write server key exchange" ) );
|
||||||
|
|
||||||
if( ssl->session->ciphersuite != SSL_EDH_RSA_DES_SHA &&
|
if( ssl->session_negotiate->ciphersuite != SSL_EDH_RSA_DES_SHA &&
|
||||||
ssl->session->ciphersuite != SSL_EDH_RSA_DES_168_SHA &&
|
ssl->session_negotiate->ciphersuite != SSL_EDH_RSA_DES_168_SHA &&
|
||||||
ssl->session->ciphersuite != SSL_EDH_RSA_AES_128_SHA &&
|
ssl->session_negotiate->ciphersuite != SSL_EDH_RSA_AES_128_SHA &&
|
||||||
ssl->session->ciphersuite != SSL_EDH_RSA_AES_256_SHA &&
|
ssl->session_negotiate->ciphersuite != SSL_EDH_RSA_AES_256_SHA &&
|
||||||
ssl->session->ciphersuite != SSL_EDH_RSA_AES_128_SHA256 &&
|
ssl->session_negotiate->ciphersuite != SSL_EDH_RSA_AES_128_SHA256 &&
|
||||||
ssl->session->ciphersuite != SSL_EDH_RSA_AES_256_SHA256 &&
|
ssl->session_negotiate->ciphersuite != SSL_EDH_RSA_AES_256_SHA256 &&
|
||||||
ssl->session->ciphersuite != SSL_EDH_RSA_CAMELLIA_128_SHA &&
|
ssl->session_negotiate->ciphersuite != SSL_EDH_RSA_CAMELLIA_128_SHA &&
|
||||||
ssl->session->ciphersuite != SSL_EDH_RSA_CAMELLIA_256_SHA &&
|
ssl->session_negotiate->ciphersuite != SSL_EDH_RSA_CAMELLIA_256_SHA &&
|
||||||
ssl->session->ciphersuite != SSL_EDH_RSA_CAMELLIA_128_SHA256 &&
|
ssl->session_negotiate->ciphersuite != SSL_EDH_RSA_CAMELLIA_128_SHA256 &&
|
||||||
ssl->session->ciphersuite != SSL_EDH_RSA_CAMELLIA_256_SHA256 &&
|
ssl->session_negotiate->ciphersuite != SSL_EDH_RSA_CAMELLIA_256_SHA256 &&
|
||||||
ssl->session->ciphersuite != SSL_EDH_RSA_AES_128_GCM_SHA256 &&
|
ssl->session_negotiate->ciphersuite != SSL_EDH_RSA_AES_128_GCM_SHA256 &&
|
||||||
ssl->session->ciphersuite != SSL_EDH_RSA_AES_256_GCM_SHA384 )
|
ssl->session_negotiate->ciphersuite != SSL_EDH_RSA_AES_256_GCM_SHA384 )
|
||||||
{
|
{
|
||||||
SSL_DEBUG_MSG( 2, ( "<= skip write server key exchange" ) );
|
SSL_DEBUG_MSG( 2, ( "<= skip write server key exchange" ) );
|
||||||
ssl->state++;
|
ssl->state++;
|
||||||
@ -476,17 +644,24 @@ static int ssl_write_server_key_exchange( ssl_context *ssl )
|
|||||||
* opaque dh_Ys<1..2^16-1>;
|
* opaque dh_Ys<1..2^16-1>;
|
||||||
* } ServerDHParams;
|
* } ServerDHParams;
|
||||||
*/
|
*/
|
||||||
if( ( ret = dhm_make_params( &ssl->dhm_ctx, 256, ssl->out_msg + 4,
|
if( ( ret = mpi_copy( &ssl->handshake->dhm_ctx.P, &ssl->dhm_P ) ) != 0 ||
|
||||||
&n, ssl->f_rng, ssl->p_rng ) ) != 0 )
|
( ret = mpi_copy( &ssl->handshake->dhm_ctx.G, &ssl->dhm_G ) ) != 0 )
|
||||||
|
{
|
||||||
|
SSL_DEBUG_RET( 1, "mpi_copy", ret );
|
||||||
|
return( ret );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( ( ret = dhm_make_params( &ssl->handshake->dhm_ctx, 256, ssl->out_msg + 4,
|
||||||
|
&n, ssl->f_rng, ssl->p_rng ) ) != 0 )
|
||||||
{
|
{
|
||||||
SSL_DEBUG_RET( 1, "dhm_make_params", ret );
|
SSL_DEBUG_RET( 1, "dhm_make_params", ret );
|
||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
|
|
||||||
SSL_DEBUG_MPI( 3, "DHM: X ", &ssl->dhm_ctx.X );
|
SSL_DEBUG_MPI( 3, "DHM: X ", &ssl->handshake->dhm_ctx.X );
|
||||||
SSL_DEBUG_MPI( 3, "DHM: P ", &ssl->dhm_ctx.P );
|
SSL_DEBUG_MPI( 3, "DHM: P ", &ssl->handshake->dhm_ctx.P );
|
||||||
SSL_DEBUG_MPI( 3, "DHM: G ", &ssl->dhm_ctx.G );
|
SSL_DEBUG_MPI( 3, "DHM: G ", &ssl->handshake->dhm_ctx.G );
|
||||||
SSL_DEBUG_MPI( 3, "DHM: GX", &ssl->dhm_ctx.GX );
|
SSL_DEBUG_MPI( 3, "DHM: GX", &ssl->handshake->dhm_ctx.GX );
|
||||||
|
|
||||||
if( ssl->minor_ver != SSL_MINOR_VERSION_3 )
|
if( ssl->minor_ver != SSL_MINOR_VERSION_3 )
|
||||||
{
|
{
|
||||||
@ -504,12 +679,12 @@ static int ssl_write_server_key_exchange( ssl_context *ssl )
|
|||||||
* + ServerParams);
|
* + ServerParams);
|
||||||
*/
|
*/
|
||||||
md5_starts( &md5 );
|
md5_starts( &md5 );
|
||||||
md5_update( &md5, ssl->randbytes, 64 );
|
md5_update( &md5, ssl->handshake->randbytes, 64 );
|
||||||
md5_update( &md5, ssl->out_msg + 4, n );
|
md5_update( &md5, ssl->out_msg + 4, n );
|
||||||
md5_finish( &md5, hash );
|
md5_finish( &md5, hash );
|
||||||
|
|
||||||
sha1_starts( &sha1 );
|
sha1_starts( &sha1 );
|
||||||
sha1_update( &sha1, ssl->randbytes, 64 );
|
sha1_update( &sha1, ssl->handshake->randbytes, 64 );
|
||||||
sha1_update( &sha1, ssl->out_msg + 4, n );
|
sha1_update( &sha1, ssl->out_msg + 4, n );
|
||||||
sha1_finish( &sha1, hash + 16 );
|
sha1_finish( &sha1, hash + 16 );
|
||||||
|
|
||||||
@ -530,7 +705,7 @@ static int ssl_write_server_key_exchange( ssl_context *ssl )
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
sha1_starts( &sha1 );
|
sha1_starts( &sha1 );
|
||||||
sha1_update( &sha1, ssl->randbytes, 64 );
|
sha1_update( &sha1, ssl->handshake->randbytes, 64 );
|
||||||
sha1_update( &sha1, ssl->out_msg + 4, n );
|
sha1_update( &sha1, ssl->out_msg + 4, n );
|
||||||
sha1_finish( &sha1, hash );
|
sha1_finish( &sha1, hash );
|
||||||
|
|
||||||
@ -646,18 +821,18 @@ static int ssl_parse_client_key_exchange( ssl_context *ssl )
|
|||||||
return( POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE );
|
return( POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ssl->session->ciphersuite == SSL_EDH_RSA_DES_SHA ||
|
if( ssl->session_negotiate->ciphersuite == SSL_EDH_RSA_DES_SHA ||
|
||||||
ssl->session->ciphersuite == SSL_EDH_RSA_DES_168_SHA ||
|
ssl->session_negotiate->ciphersuite == SSL_EDH_RSA_DES_168_SHA ||
|
||||||
ssl->session->ciphersuite == SSL_EDH_RSA_AES_128_SHA ||
|
ssl->session_negotiate->ciphersuite == SSL_EDH_RSA_AES_128_SHA ||
|
||||||
ssl->session->ciphersuite == SSL_EDH_RSA_AES_256_SHA ||
|
ssl->session_negotiate->ciphersuite == SSL_EDH_RSA_AES_256_SHA ||
|
||||||
ssl->session->ciphersuite == SSL_EDH_RSA_AES_128_SHA256 ||
|
ssl->session_negotiate->ciphersuite == SSL_EDH_RSA_AES_128_SHA256 ||
|
||||||
ssl->session->ciphersuite == SSL_EDH_RSA_AES_256_SHA256 ||
|
ssl->session_negotiate->ciphersuite == SSL_EDH_RSA_AES_256_SHA256 ||
|
||||||
ssl->session->ciphersuite == SSL_EDH_RSA_CAMELLIA_128_SHA ||
|
ssl->session_negotiate->ciphersuite == SSL_EDH_RSA_CAMELLIA_128_SHA ||
|
||||||
ssl->session->ciphersuite == SSL_EDH_RSA_CAMELLIA_256_SHA ||
|
ssl->session_negotiate->ciphersuite == SSL_EDH_RSA_CAMELLIA_256_SHA ||
|
||||||
ssl->session->ciphersuite == SSL_EDH_RSA_CAMELLIA_128_SHA256 ||
|
ssl->session_negotiate->ciphersuite == SSL_EDH_RSA_CAMELLIA_128_SHA256 ||
|
||||||
ssl->session->ciphersuite == SSL_EDH_RSA_CAMELLIA_256_SHA256 ||
|
ssl->session_negotiate->ciphersuite == SSL_EDH_RSA_CAMELLIA_256_SHA256 ||
|
||||||
ssl->session->ciphersuite == SSL_EDH_RSA_AES_128_GCM_SHA256 ||
|
ssl->session_negotiate->ciphersuite == SSL_EDH_RSA_AES_128_GCM_SHA256 ||
|
||||||
ssl->session->ciphersuite == SSL_EDH_RSA_AES_256_GCM_SHA384 )
|
ssl->session_negotiate->ciphersuite == SSL_EDH_RSA_AES_256_GCM_SHA384 )
|
||||||
{
|
{
|
||||||
#if !defined(POLARSSL_DHM_C)
|
#if !defined(POLARSSL_DHM_C)
|
||||||
SSL_DEBUG_MSG( 1, ( "support for dhm is not available" ) );
|
SSL_DEBUG_MSG( 1, ( "support for dhm is not available" ) );
|
||||||
@ -668,32 +843,33 @@ static int ssl_parse_client_key_exchange( ssl_context *ssl )
|
|||||||
*/
|
*/
|
||||||
n = ( ssl->in_msg[4] << 8 ) | ssl->in_msg[5];
|
n = ( ssl->in_msg[4] << 8 ) | ssl->in_msg[5];
|
||||||
|
|
||||||
if( n < 1 || n > ssl->dhm_ctx.len ||
|
if( n < 1 || n > ssl->handshake->dhm_ctx.len ||
|
||||||
n + 6 != ssl->in_hslen )
|
n + 6 != ssl->in_hslen )
|
||||||
{
|
{
|
||||||
SSL_DEBUG_MSG( 1, ( "bad client key exchange message" ) );
|
SSL_DEBUG_MSG( 1, ( "bad client key exchange message" ) );
|
||||||
return( POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE );
|
return( POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ( ret = dhm_read_public( &ssl->dhm_ctx,
|
if( ( ret = dhm_read_public( &ssl->handshake->dhm_ctx,
|
||||||
ssl->in_msg + 6, n ) ) != 0 )
|
ssl->in_msg + 6, n ) ) != 0 )
|
||||||
{
|
{
|
||||||
SSL_DEBUG_RET( 1, "dhm_read_public", ret );
|
SSL_DEBUG_RET( 1, "dhm_read_public", ret );
|
||||||
return( POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_DHM_RP );
|
return( POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_DHM_RP );
|
||||||
}
|
}
|
||||||
|
|
||||||
SSL_DEBUG_MPI( 3, "DHM: GY", &ssl->dhm_ctx.GY );
|
SSL_DEBUG_MPI( 3, "DHM: GY", &ssl->handshake->dhm_ctx.GY );
|
||||||
|
|
||||||
ssl->pmslen = ssl->dhm_ctx.len;
|
ssl->handshake->pmslen = ssl->handshake->dhm_ctx.len;
|
||||||
|
|
||||||
if( ( ret = dhm_calc_secret( &ssl->dhm_ctx,
|
if( ( ret = dhm_calc_secret( &ssl->handshake->dhm_ctx,
|
||||||
ssl->premaster, &ssl->pmslen ) ) != 0 )
|
ssl->handshake->premaster,
|
||||||
|
&ssl->handshake->pmslen ) ) != 0 )
|
||||||
{
|
{
|
||||||
SSL_DEBUG_RET( 1, "dhm_calc_secret", ret );
|
SSL_DEBUG_RET( 1, "dhm_calc_secret", ret );
|
||||||
return( POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_DHM_CS );
|
return( POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_DHM_CS );
|
||||||
}
|
}
|
||||||
|
|
||||||
SSL_DEBUG_MPI( 3, "DHM: K ", &ssl->dhm_ctx.K );
|
SSL_DEBUG_MPI( 3, "DHM: K ", &ssl->handshake->dhm_ctx.K );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -721,7 +897,7 @@ static int ssl_parse_client_key_exchange( ssl_context *ssl )
|
|||||||
else
|
else
|
||||||
n = ssl->pkcs11_key->len;
|
n = ssl->pkcs11_key->len;
|
||||||
#endif
|
#endif
|
||||||
ssl->pmslen = 48;
|
ssl->handshake->pmslen = 48;
|
||||||
|
|
||||||
if( ssl->minor_ver != SSL_MINOR_VERSION_0 )
|
if( ssl->minor_ver != SSL_MINOR_VERSION_0 )
|
||||||
{
|
{
|
||||||
@ -741,21 +917,25 @@ static int ssl_parse_client_key_exchange( ssl_context *ssl )
|
|||||||
}
|
}
|
||||||
|
|
||||||
if( ssl->rsa_key ) {
|
if( ssl->rsa_key ) {
|
||||||
ret = rsa_pkcs1_decrypt( ssl->rsa_key, RSA_PRIVATE, &ssl->pmslen,
|
ret = rsa_pkcs1_decrypt( ssl->rsa_key, RSA_PRIVATE,
|
||||||
ssl->in_msg + i, ssl->premaster,
|
&ssl->handshake->pmslen,
|
||||||
sizeof(ssl->premaster) );
|
ssl->in_msg + i,
|
||||||
|
ssl->handshake->premaster,
|
||||||
|
sizeof(ssl->handshake->premaster) );
|
||||||
}
|
}
|
||||||
#if defined(POLARSSL_PKCS11_C)
|
#if defined(POLARSSL_PKCS11_C)
|
||||||
else {
|
else {
|
||||||
ret = pkcs11_decrypt( ssl->pkcs11_key, RSA_PRIVATE, &ssl->pmslen,
|
ret = pkcs11_decrypt( ssl->pkcs11_key, RSA_PRIVATE,
|
||||||
ssl->in_msg + i, ssl->premaster,
|
&ssl->handshake->pmslen,
|
||||||
sizeof(ssl->premaster) );
|
ssl->in_msg + i,
|
||||||
|
ssl->handshake->premaster,
|
||||||
|
sizeof(ssl->handshake->premaster) );
|
||||||
}
|
}
|
||||||
#endif /* defined(POLARSSL_PKCS11_C) */
|
#endif /* defined(POLARSSL_PKCS11_C) */
|
||||||
|
|
||||||
if( ret != 0 || ssl->pmslen != 48 ||
|
if( ret != 0 || ssl->handshake->pmslen != 48 ||
|
||||||
ssl->premaster[0] != ssl->max_major_ver ||
|
ssl->handshake->premaster[0] != ssl->max_major_ver ||
|
||||||
ssl->premaster[1] != ssl->max_minor_ver )
|
ssl->handshake->premaster[1] != ssl->max_minor_ver )
|
||||||
{
|
{
|
||||||
SSL_DEBUG_MSG( 1, ( "bad client key exchange message" ) );
|
SSL_DEBUG_MSG( 1, ( "bad client key exchange message" ) );
|
||||||
|
|
||||||
@ -765,9 +945,10 @@ static int ssl_parse_client_key_exchange( ssl_context *ssl )
|
|||||||
* the connection to end immediately; instead,
|
* the connection to end immediately; instead,
|
||||||
* send a bad_record_mac later in the handshake.
|
* send a bad_record_mac later in the handshake.
|
||||||
*/
|
*/
|
||||||
ssl->pmslen = 48;
|
ssl->handshake->pmslen = 48;
|
||||||
|
|
||||||
ret = ssl->f_rng( ssl->p_rng, ssl->premaster, ssl->pmslen );
|
ret = ssl->f_rng( ssl->p_rng, ssl->handshake->premaster,
|
||||||
|
ssl->handshake->pmslen );
|
||||||
if( ret != 0 )
|
if( ret != 0 )
|
||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
@ -797,14 +978,14 @@ static int ssl_parse_certificate_verify( ssl_context *ssl )
|
|||||||
|
|
||||||
SSL_DEBUG_MSG( 2, ( "=> parse certificate verify" ) );
|
SSL_DEBUG_MSG( 2, ( "=> parse certificate verify" ) );
|
||||||
|
|
||||||
if( ssl->peer_cert == NULL )
|
if( ssl->session_negotiate->peer_cert == NULL )
|
||||||
{
|
{
|
||||||
SSL_DEBUG_MSG( 2, ( "<= skip parse certificate verify" ) );
|
SSL_DEBUG_MSG( 2, ( "<= skip parse certificate verify" ) );
|
||||||
ssl->state++;
|
ssl->state++;
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
ssl->calc_verify( ssl, hash );
|
ssl->handshake->calc_verify( ssl, hash );
|
||||||
|
|
||||||
if( ( ret = ssl_read_record( ssl ) ) != 0 )
|
if( ( ret = ssl_read_record( ssl ) ) != 0 )
|
||||||
{
|
{
|
||||||
@ -826,7 +1007,7 @@ static int ssl_parse_certificate_verify( ssl_context *ssl )
|
|||||||
return( POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY );
|
return( POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY );
|
||||||
}
|
}
|
||||||
|
|
||||||
n1 = ssl->peer_cert->rsa.len;
|
n1 = ssl->session_negotiate->peer_cert->rsa.len;
|
||||||
n2 = ( ssl->in_msg[4] << 8 ) | ssl->in_msg[5];
|
n2 = ( ssl->in_msg[4] << 8 ) | ssl->in_msg[5];
|
||||||
|
|
||||||
if( n1 + 6 != ssl->in_hslen || n1 != n2 )
|
if( n1 + 6 != ssl->in_hslen || n1 != n2 )
|
||||||
@ -835,7 +1016,7 @@ static int ssl_parse_certificate_verify( ssl_context *ssl )
|
|||||||
return( POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY );
|
return( POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY );
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = rsa_pkcs1_verify( &ssl->peer_cert->rsa, RSA_PUBLIC,
|
ret = rsa_pkcs1_verify( &ssl->session_negotiate->peer_cert->rsa, RSA_PUBLIC,
|
||||||
SIG_RSA_RAW, 36, hash, ssl->in_msg + 6 );
|
SIG_RSA_RAW, 36, hash, ssl->in_msg + 6 );
|
||||||
if( ret != 0 )
|
if( ret != 0 )
|
||||||
{
|
{
|
||||||
@ -945,7 +1126,11 @@ int ssl_handshake_server( ssl_context *ssl )
|
|||||||
|
|
||||||
case SSL_FLUSH_BUFFERS:
|
case SSL_FLUSH_BUFFERS:
|
||||||
SSL_DEBUG_MSG( 2, ( "handshake: done" ) );
|
SSL_DEBUG_MSG( 2, ( "handshake: done" ) );
|
||||||
ssl->state = SSL_HANDSHAKE_OVER;
|
ssl->state = SSL_HANDSHAKE_WRAPUP;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SSL_HANDSHAKE_WRAPUP:
|
||||||
|
ssl_handshake_wrapup( ssl );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
1088
library/ssl_tls.c
1088
library/ssl_tls.c
File diff suppressed because it is too large
Load Diff
@ -50,6 +50,8 @@
|
|||||||
#define DFL_CRT_FILE ""
|
#define DFL_CRT_FILE ""
|
||||||
#define DFL_KEY_FILE ""
|
#define DFL_KEY_FILE ""
|
||||||
#define DFL_FORCE_CIPHER 0
|
#define DFL_FORCE_CIPHER 0
|
||||||
|
#define DFL_RENEGOTIATION SSL_RENEGOTIATION_ENABLED
|
||||||
|
#define DFL_ALLOW_LEGACY SSL_NO_LEGACY_RENEGOTIATION
|
||||||
|
|
||||||
#define GET_REQUEST "GET %s HTTP/1.0\r\n\r\n"
|
#define GET_REQUEST "GET %s HTTP/1.0\r\n\r\n"
|
||||||
|
|
||||||
@ -67,6 +69,8 @@ struct options
|
|||||||
char *crt_file; /* the file with the client certificate */
|
char *crt_file; /* the file with the client certificate */
|
||||||
char *key_file; /* the file with the client key */
|
char *key_file; /* the file with the client key */
|
||||||
int force_ciphersuite[2]; /* protocol/ciphersuite to use, or all */
|
int force_ciphersuite[2]; /* protocol/ciphersuite to use, or all */
|
||||||
|
int renegotiation; /* enable / disable renegotiation */
|
||||||
|
int allow_legacy; /* allow legacy renegotiation */
|
||||||
} opt;
|
} opt;
|
||||||
|
|
||||||
void my_debug( void *ctx, int level, const char *str )
|
void my_debug( void *ctx, int level, const char *str )
|
||||||
@ -97,6 +101,8 @@ void my_debug( void *ctx, int level, const char *str )
|
|||||||
" debug_level=%%d default: 0 (disabled)\n" \
|
" debug_level=%%d default: 0 (disabled)\n" \
|
||||||
USAGE_IO \
|
USAGE_IO \
|
||||||
" request_page=%%s default: \".\"\n" \
|
" request_page=%%s default: \".\"\n" \
|
||||||
|
" renegotiation=%%d default: 1 (enabled)\n" \
|
||||||
|
" allow_legacy=%%d default: 0 (disabled)\n" \
|
||||||
" force_ciphersuite=<name> default: all enabled\n"\
|
" force_ciphersuite=<name> default: all enabled\n"\
|
||||||
" acceptable ciphersuite names:\n"
|
" acceptable ciphersuite names:\n"
|
||||||
|
|
||||||
@ -171,6 +177,8 @@ int main( int argc, char *argv[] )
|
|||||||
opt.crt_file = DFL_CRT_FILE;
|
opt.crt_file = DFL_CRT_FILE;
|
||||||
opt.key_file = DFL_KEY_FILE;
|
opt.key_file = DFL_KEY_FILE;
|
||||||
opt.force_ciphersuite[0]= DFL_FORCE_CIPHER;
|
opt.force_ciphersuite[0]= DFL_FORCE_CIPHER;
|
||||||
|
opt.renegotiation = DFL_RENEGOTIATION;
|
||||||
|
opt.allow_legacy = DFL_ALLOW_LEGACY;
|
||||||
|
|
||||||
for( i = 1; i < argc; i++ )
|
for( i = 1; i < argc; i++ )
|
||||||
{
|
{
|
||||||
@ -224,6 +232,17 @@ int main( int argc, char *argv[] )
|
|||||||
}
|
}
|
||||||
opt.force_ciphersuite[1] = 0;
|
opt.force_ciphersuite[1] = 0;
|
||||||
}
|
}
|
||||||
|
else if( strcmp( p, "renegotiation" ) == 0 )
|
||||||
|
{
|
||||||
|
opt.renegotiation = (atoi( q )) ? SSL_RENEGOTIATION_ENABLED :
|
||||||
|
SSL_RENEGOTIATION_DISABLED;
|
||||||
|
}
|
||||||
|
else if( strcmp( p, "allow_legacy" ) == 0 )
|
||||||
|
{
|
||||||
|
opt.allow_legacy = atoi( q );
|
||||||
|
if( opt.allow_legacy < 0 || opt.allow_legacy > 1 )
|
||||||
|
goto usage;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
goto usage;
|
goto usage;
|
||||||
}
|
}
|
||||||
@ -367,6 +386,9 @@ int main( int argc, char *argv[] )
|
|||||||
else
|
else
|
||||||
ssl_set_ciphersuites( &ssl, opt.force_ciphersuite );
|
ssl_set_ciphersuites( &ssl, opt.force_ciphersuite );
|
||||||
|
|
||||||
|
ssl_set_renegotiation( &ssl, opt.renegotiation );
|
||||||
|
ssl_legacy_renegotiation( &ssl, opt.allow_legacy );
|
||||||
|
|
||||||
ssl_set_session( &ssl, 1, 600, &ssn );
|
ssl_set_session( &ssl, 1, 600, &ssn );
|
||||||
|
|
||||||
ssl_set_ca_chain( &ssl, &cacert, NULL, opt.server_name );
|
ssl_set_ca_chain( &ssl, &cacert, NULL, opt.server_name );
|
||||||
@ -419,7 +441,8 @@ int main( int argc, char *argv[] )
|
|||||||
printf( " ok\n" );
|
printf( " ok\n" );
|
||||||
|
|
||||||
printf( " . Peer certificate information ...\n" );
|
printf( " . Peer certificate information ...\n" );
|
||||||
x509parse_cert_info( (char *) buf, sizeof( buf ) - 1, " ", ssl.peer_cert );
|
x509parse_cert_info( (char *) buf, sizeof( buf ) - 1, " ",
|
||||||
|
ssl.session->peer_cert );
|
||||||
printf( "%s\n", buf );
|
printf( "%s\n", buf );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -495,6 +518,7 @@ exit:
|
|||||||
x509_free( &clicert );
|
x509_free( &clicert );
|
||||||
x509_free( &cacert );
|
x509_free( &cacert );
|
||||||
rsa_free( &rsa );
|
rsa_free( &rsa );
|
||||||
|
ssl_session_free( &ssn );
|
||||||
ssl_free( &ssl );
|
ssl_free( &ssl );
|
||||||
|
|
||||||
memset( &ssl, 0, sizeof( ssl ) );
|
memset( &ssl, 0, sizeof( ssl ) );
|
||||||
|
@ -379,7 +379,9 @@ int main( int argc, char *argv[] )
|
|||||||
|
|
||||||
ssl_set_ca_chain( &ssl, srvcert.next, NULL, NULL );
|
ssl_set_ca_chain( &ssl, srvcert.next, NULL, NULL );
|
||||||
ssl_set_own_cert( &ssl, &srvcert, &rsa );
|
ssl_set_own_cert( &ssl, &srvcert, &rsa );
|
||||||
|
#if defined(POLARSSL_DHM_C)
|
||||||
ssl_set_dh_param( &ssl, my_dhm_P, my_dhm_G );
|
ssl_set_dh_param( &ssl, my_dhm_P, my_dhm_G );
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 5. Handshake
|
* 5. Handshake
|
||||||
|
@ -171,7 +171,8 @@ int do_handshake( ssl_context *ssl, struct options *opt )
|
|||||||
printf( " ok\n" );
|
printf( " ok\n" );
|
||||||
|
|
||||||
printf( " . Peer certificate information ...\n" );
|
printf( " . Peer certificate information ...\n" );
|
||||||
x509parse_cert_info( (char *) buf, sizeof( buf ) - 1, " ", ssl->peer_cert );
|
x509parse_cert_info( (char *) buf, sizeof( buf ) - 1, " ",
|
||||||
|
ssl->session->peer_cert );
|
||||||
printf( "%s\n", buf );
|
printf( "%s\n", buf );
|
||||||
|
|
||||||
return( 0 );
|
return( 0 );
|
||||||
@ -803,6 +804,7 @@ exit:
|
|||||||
x509_free( &clicert );
|
x509_free( &clicert );
|
||||||
x509_free( &cacert );
|
x509_free( &cacert );
|
||||||
rsa_free( &rsa );
|
rsa_free( &rsa );
|
||||||
|
ssl_session_free( &ssn );
|
||||||
ssl_free( &ssl );
|
ssl_free( &ssl );
|
||||||
|
|
||||||
memset( &ssl, 0, sizeof( ssl ) );
|
memset( &ssl, 0, sizeof( ssl ) );
|
||||||
|
@ -370,7 +370,9 @@ int main( int argc, char *argv[] )
|
|||||||
|
|
||||||
ssl_set_ca_chain( &ssl, srvcert.next, NULL, NULL );
|
ssl_set_ca_chain( &ssl, srvcert.next, NULL, NULL );
|
||||||
ssl_set_own_cert( &ssl, &srvcert, &rsa );
|
ssl_set_own_cert( &ssl, &srvcert, &rsa );
|
||||||
|
#if defined(POLARSSL_DHM_C)
|
||||||
ssl_set_dh_param( &ssl, my_dhm_P, my_dhm_G );
|
ssl_set_dh_param( &ssl, my_dhm_P, my_dhm_G );
|
||||||
|
#endif
|
||||||
|
|
||||||
printf( " ok\n" );
|
printf( " ok\n" );
|
||||||
|
|
||||||
@ -484,8 +486,11 @@ reset:
|
|||||||
|
|
||||||
len = ret;
|
len = ret;
|
||||||
printf( " %d bytes read\n\n%s", len, (char *) buf );
|
printf( " %d bytes read\n\n%s", len, (char *) buf );
|
||||||
|
|
||||||
|
if( ret > 0 )
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
while( 0 );
|
while( 1 );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 7. Write the 200 Response
|
* 7. Write the 200 Response
|
||||||
@ -531,19 +536,10 @@ exit:
|
|||||||
net_close( client_fd );
|
net_close( client_fd );
|
||||||
x509_free( &srvcert );
|
x509_free( &srvcert );
|
||||||
rsa_free( &rsa );
|
rsa_free( &rsa );
|
||||||
|
ssl_session_free( &ssn );
|
||||||
|
ssl_session_free( s_list_1st );
|
||||||
ssl_free( &ssl );
|
ssl_free( &ssl );
|
||||||
|
|
||||||
cur = s_list_1st;
|
|
||||||
while( cur != NULL )
|
|
||||||
{
|
|
||||||
prv = cur;
|
|
||||||
cur = cur->next;
|
|
||||||
memset( prv, 0, sizeof( ssl_session ) );
|
|
||||||
free( prv );
|
|
||||||
}
|
|
||||||
|
|
||||||
memset( &ssl, 0, sizeof( ssl_context ) );
|
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
printf( " Press Enter to exit this program.\n" );
|
printf( " Press Enter to exit this program.\n" );
|
||||||
fflush( stdout ); getchar();
|
fflush( stdout ); getchar();
|
||||||
|
@ -312,7 +312,8 @@ int main( int argc, char *argv[] )
|
|||||||
* 5. Print the certificate
|
* 5. Print the certificate
|
||||||
*/
|
*/
|
||||||
printf( " . Peer certificate information ...\n" );
|
printf( " . Peer certificate information ...\n" );
|
||||||
ret = x509parse_cert_info( (char *) buf, sizeof( buf ) - 1, " ", ssl.peer_cert );
|
ret = x509parse_cert_info( (char *) buf, sizeof( buf ) - 1, " ",
|
||||||
|
ssl.session->peer_cert );
|
||||||
if( ret == -1 )
|
if( ret == -1 )
|
||||||
{
|
{
|
||||||
printf( " failed\n ! x509parse_cert_info returned %d\n\n", ret );
|
printf( " failed\n ! x509parse_cert_info returned %d\n\n", ret );
|
||||||
@ -332,10 +333,9 @@ exit:
|
|||||||
net_close( server_fd );
|
net_close( server_fd );
|
||||||
x509_free( &clicert );
|
x509_free( &clicert );
|
||||||
rsa_free( &rsa );
|
rsa_free( &rsa );
|
||||||
|
ssl_session_free( &ssn );
|
||||||
ssl_free( &ssl );
|
ssl_free( &ssl );
|
||||||
|
|
||||||
memset( &ssl, 0, sizeof( ssl ) );
|
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
printf( " + Press Enter to exit this program.\n" );
|
printf( " + Press Enter to exit this program.\n" );
|
||||||
fflush( stdout ); getchar();
|
fflush( stdout ); getchar();
|
||||||
|
Loading…
Reference in New Issue
Block a user