mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-20 08:39:05 +00:00
wpa_supplicant: sync eap code with upstream
This commit is contained in:
@@ -1,33 +1,32 @@
|
||||
/*
|
||||
* TLSv1 server - write handshake message
|
||||
* Copyright (c) 2006-2011, Jouni Malinen <j@w1.fi>
|
||||
* Copyright (c) 2006-2014, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This software may be distributed under the terms of the BSD license.
|
||||
* See README for more details.
|
||||
*/
|
||||
|
||||
#include "utils/includes.h"
|
||||
#include "includes.h"
|
||||
|
||||
#include "utils/common.h"
|
||||
#include "common.h"
|
||||
#include "crypto/md5.h"
|
||||
#include "crypto/sha1.h"
|
||||
#include "crypto/sha256.h"
|
||||
#include "crypto/tls.h"
|
||||
#include "crypto/random.h"
|
||||
#include "tls/tls.h"
|
||||
#include "tls/x509v3.h"
|
||||
#include "tls/tlsv1_common.h"
|
||||
#include "tls/tlsv1_record.h"
|
||||
#include "tls/tlsv1_server.h"
|
||||
#include "tls/tlsv1_server_i.h"
|
||||
#include "x509v3.h"
|
||||
#include "tlsv1_common.h"
|
||||
#include "tlsv1_record.h"
|
||||
#include "tlsv1_server.h"
|
||||
#include "tlsv1_server_i.h"
|
||||
|
||||
#include "eap_peer/eap_i.h"
|
||||
|
||||
static size_t tls_server_cert_chain_der_len(struct tlsv1_server *conn)
|
||||
{
|
||||
size_t len = 0;
|
||||
struct x509_certificate *cert;
|
||||
|
||||
cert = conn->cred->cert;
|
||||
cert = conn->cred ? conn->cred->cert : NULL;
|
||||
while (cert) {
|
||||
len += 3 + cert->cert_len;
|
||||
if (x509_certificate_self_signed(cert))
|
||||
@@ -43,17 +42,20 @@ static size_t tls_server_cert_chain_der_len(struct tlsv1_server *conn)
|
||||
static int tls_write_server_hello(struct tlsv1_server *conn,
|
||||
u8 **msgpos, u8 *end)
|
||||
{
|
||||
u8 *pos, *rhdr, *hs_start, *hs_length;
|
||||
u8 *pos, *rhdr, *hs_start, *hs_length, *ext_start;
|
||||
struct os_time now;
|
||||
size_t rlen;
|
||||
|
||||
pos = *msgpos;
|
||||
|
||||
wpa_printf(MSG_DEBUG, "TLSv1: Send ServerHello");
|
||||
tlsv1_server_log(conn, "Send ServerHello");
|
||||
rhdr = pos;
|
||||
pos += TLS_RECORD_HEADER_LEN;
|
||||
|
||||
os_get_time(&now);
|
||||
#ifdef TEST_FUZZ
|
||||
now.sec = 0xfffefdfc;
|
||||
#endif /* TEST_FUZZ */
|
||||
WPA_PUT_BE32(conn->server_random, now.sec);
|
||||
if (random_get_bytes(conn->server_random + 4, TLS_RANDOM_LEN - 4)) {
|
||||
wpa_printf(MSG_ERROR, "TLSv1: Could not generate "
|
||||
@@ -98,6 +100,32 @@ static int tls_write_server_hello(struct tlsv1_server *conn,
|
||||
/* CompressionMethod compression_method */
|
||||
*pos++ = TLS_COMPRESSION_NULL;
|
||||
|
||||
/* Extension */
|
||||
ext_start = pos;
|
||||
pos += 2;
|
||||
|
||||
if (conn->status_request) {
|
||||
/* Add a status_request extension with empty extension_data */
|
||||
/* ExtensionsType extension_type = status_request(5) */
|
||||
WPA_PUT_BE16(pos, TLS_EXT_STATUS_REQUEST);
|
||||
pos += 2;
|
||||
/* opaque extension_data<0..2^16-1> length */
|
||||
WPA_PUT_BE16(pos, 0);
|
||||
pos += 2;
|
||||
}
|
||||
|
||||
if (conn->status_request_v2) {
|
||||
/*
|
||||
Add a status_request_v2 extension with empty extension_data
|
||||
*/
|
||||
/* ExtensionsType extension_type = status_request_v2(17) */
|
||||
WPA_PUT_BE16(pos, TLS_EXT_STATUS_REQUEST_V2);
|
||||
pos += 2;
|
||||
/* opaque extension_data<0..2^16-1> length */
|
||||
WPA_PUT_BE16(pos, 0);
|
||||
pos += 2;
|
||||
}
|
||||
|
||||
if (conn->session_ticket && conn->session_ticket_cb) {
|
||||
int res = conn->session_ticket_cb(
|
||||
conn->session_ticket_cb_ctx,
|
||||
@@ -105,8 +133,7 @@ static int tls_write_server_hello(struct tlsv1_server *conn,
|
||||
conn->client_random, conn->server_random,
|
||||
conn->master_secret);
|
||||
if (res < 0) {
|
||||
wpa_printf(MSG_DEBUG, "TLSv1: SessionTicket callback "
|
||||
"indicated failure");
|
||||
tlsv1_server_log(conn, "SessionTicket callback indicated failure");
|
||||
tlsv1_server_alert(conn, TLS_ALERT_LEVEL_FATAL,
|
||||
TLS_ALERT_HANDSHAKE_FAILURE);
|
||||
return -1;
|
||||
@@ -135,6 +162,11 @@ static int tls_write_server_hello(struct tlsv1_server *conn,
|
||||
*/
|
||||
}
|
||||
|
||||
if (pos == ext_start + 2)
|
||||
pos -= 2; /* no extensions */
|
||||
else
|
||||
WPA_PUT_BE16(ext_start, pos - ext_start - 2);
|
||||
|
||||
WPA_PUT_BE24(hs_length, pos - hs_length - 3);
|
||||
tls_verify_hash_add(&conn->verify, hs_start, pos - hs_start);
|
||||
|
||||
@@ -170,8 +202,13 @@ static int tls_write_server_certificate(struct tlsv1_server *conn,
|
||||
}
|
||||
|
||||
pos = *msgpos;
|
||||
if (TLS_RECORD_HEADER_LEN + 1 + 3 + 3 > end - pos) {
|
||||
tlsv1_server_alert(conn, TLS_ALERT_LEVEL_FATAL,
|
||||
TLS_ALERT_INTERNAL_ERROR);
|
||||
return -1;
|
||||
}
|
||||
|
||||
wpa_printf(MSG_DEBUG, "TLSv1: Send Certificate");
|
||||
tlsv1_server_log(conn, "Send Certificate");
|
||||
rhdr = pos;
|
||||
pos += TLS_RECORD_HEADER_LEN;
|
||||
|
||||
@@ -190,7 +227,7 @@ static int tls_write_server_certificate(struct tlsv1_server *conn,
|
||||
pos += 3;
|
||||
cert = conn->cred->cert;
|
||||
while (cert) {
|
||||
if (pos + 3 + cert->cert_len > end) {
|
||||
if (3 + cert->cert_len > (size_t) (end - pos)) {
|
||||
wpa_printf(MSG_DEBUG, "TLSv1: Not enough buffer space "
|
||||
"for Certificate (cert_len=%lu left=%lu)",
|
||||
(unsigned long) cert->cert_len,
|
||||
@@ -241,15 +278,104 @@ static int tls_write_server_certificate(struct tlsv1_server *conn,
|
||||
}
|
||||
|
||||
|
||||
static int tls_write_server_certificate_status(struct tlsv1_server *conn,
|
||||
u8 **msgpos, u8 *end,
|
||||
int ocsp_multi,
|
||||
char *ocsp_resp,
|
||||
size_t ocsp_resp_len)
|
||||
{
|
||||
u8 *pos, *rhdr, *hs_start, *hs_length;
|
||||
size_t rlen;
|
||||
|
||||
if (!ocsp_resp) {
|
||||
/*
|
||||
* Client did not request certificate status or there is no
|
||||
* matching response cached.
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
pos = *msgpos;
|
||||
if (TLS_RECORD_HEADER_LEN + 1 + 3 + 1 + 3 + ocsp_resp_len >
|
||||
(unsigned int) (end - pos)) {
|
||||
tlsv1_server_alert(conn, TLS_ALERT_LEVEL_FATAL,
|
||||
TLS_ALERT_INTERNAL_ERROR);
|
||||
return -1;
|
||||
}
|
||||
|
||||
tlsv1_server_log(conn, "Send CertificateStatus (multi=%d)", ocsp_multi);
|
||||
rhdr = pos;
|
||||
pos += TLS_RECORD_HEADER_LEN;
|
||||
|
||||
/* opaque fragment[TLSPlaintext.length] */
|
||||
|
||||
/* Handshake */
|
||||
hs_start = pos;
|
||||
/* HandshakeType msg_type */
|
||||
*pos++ = TLS_HANDSHAKE_TYPE_CERTIFICATE_STATUS;
|
||||
/* uint24 length (to be filled) */
|
||||
hs_length = pos;
|
||||
pos += 3;
|
||||
|
||||
/* body - CertificateStatus
|
||||
*
|
||||
* struct {
|
||||
* CertificateStatusType status_type;
|
||||
* select (status_type) {
|
||||
* case ocsp: OCSPResponse;
|
||||
* case ocsp_multi: OCSPResponseList;
|
||||
* } response;
|
||||
* } CertificateStatus;
|
||||
*
|
||||
* opaque OCSPResponse<1..2^24-1>;
|
||||
*
|
||||
* struct {
|
||||
* OCSPResponse ocsp_response_list<1..2^24-1>;
|
||||
* } OCSPResponseList;
|
||||
*/
|
||||
|
||||
/* CertificateStatusType status_type */
|
||||
if (ocsp_multi)
|
||||
*pos++ = 2; /* ocsp_multi(2) */
|
||||
else
|
||||
*pos++ = 1; /* ocsp(1) */
|
||||
/* uint24 length of OCSPResponse */
|
||||
WPA_PUT_BE24(pos, ocsp_resp_len);
|
||||
pos += 3;
|
||||
os_memcpy(pos, ocsp_resp, ocsp_resp_len);
|
||||
pos += ocsp_resp_len;
|
||||
|
||||
WPA_PUT_BE24(hs_length, pos - hs_length - 3);
|
||||
|
||||
if (tlsv1_record_send(&conn->rl, TLS_CONTENT_TYPE_HANDSHAKE,
|
||||
rhdr, end - rhdr, hs_start, pos - hs_start,
|
||||
&rlen) < 0) {
|
||||
wpa_printf(MSG_DEBUG, "TLSv1: Failed to generate a record");
|
||||
tlsv1_server_alert(conn, TLS_ALERT_LEVEL_FATAL,
|
||||
TLS_ALERT_INTERNAL_ERROR);
|
||||
return -1;
|
||||
}
|
||||
pos = rhdr + rlen;
|
||||
|
||||
tls_verify_hash_add(&conn->verify, hs_start, pos - hs_start);
|
||||
|
||||
*msgpos = pos;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int tls_write_server_key_exchange(struct tlsv1_server *conn,
|
||||
u8 **msgpos, u8 *end)
|
||||
{
|
||||
tls_key_exchange keyx;
|
||||
const struct tls_cipher_suite *suite;
|
||||
u8 *pos, *rhdr, *hs_start, *hs_length;
|
||||
u8 *pos, *rhdr, *hs_start, *hs_length, *server_params;
|
||||
size_t rlen;
|
||||
u8 *dh_ys;
|
||||
size_t dh_ys_len;
|
||||
const u8 *dh_p;
|
||||
size_t dh_p_len;
|
||||
|
||||
suite = tls_get_cipher_suite(conn->rl.cipher_suite);
|
||||
if (suite == NULL)
|
||||
@@ -262,8 +388,7 @@ static int tls_write_server_key_exchange(struct tlsv1_server *conn,
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (keyx != TLS_KEY_X_DH_anon) {
|
||||
/* TODO? */
|
||||
if (keyx != TLS_KEY_X_DH_anon && keyx != TLS_KEY_X_DHE_RSA) {
|
||||
wpa_printf(MSG_DEBUG, "TLSv1: ServerKeyExchange not yet "
|
||||
"supported with key exchange type %d", keyx);
|
||||
return -1;
|
||||
@@ -276,8 +401,10 @@ static int tls_write_server_key_exchange(struct tlsv1_server *conn,
|
||||
return -1;
|
||||
}
|
||||
|
||||
tlsv1_server_get_dh_p(conn, &dh_p, &dh_p_len);
|
||||
|
||||
os_free(conn->dh_secret);
|
||||
conn->dh_secret_len = conn->cred->dh_p_len;
|
||||
conn->dh_secret_len = dh_p_len;
|
||||
conn->dh_secret = os_malloc(conn->dh_secret_len);
|
||||
if (conn->dh_secret == NULL) {
|
||||
wpa_printf(MSG_DEBUG, "TLSv1: Failed to allocate "
|
||||
@@ -296,8 +423,7 @@ static int tls_write_server_key_exchange(struct tlsv1_server *conn,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (os_memcmp(conn->dh_secret, conn->cred->dh_p, conn->dh_secret_len) >
|
||||
0)
|
||||
if (os_memcmp(conn->dh_secret, dh_p, conn->dh_secret_len) > 0)
|
||||
conn->dh_secret[0] = 0; /* make sure secret < p */
|
||||
|
||||
pos = conn->dh_secret;
|
||||
@@ -312,7 +438,7 @@ static int tls_write_server_key_exchange(struct tlsv1_server *conn,
|
||||
conn->dh_secret, conn->dh_secret_len);
|
||||
|
||||
/* Ys = g^secret mod p */
|
||||
dh_ys_len = conn->cred->dh_p_len;
|
||||
dh_ys_len = dh_p_len;
|
||||
dh_ys = os_malloc(dh_ys_len);
|
||||
if (dh_ys == NULL) {
|
||||
wpa_printf(MSG_DEBUG, "TLSv1: Failed to allocate memory for "
|
||||
@@ -322,16 +448,14 @@ static int tls_write_server_key_exchange(struct tlsv1_server *conn,
|
||||
return -1;
|
||||
}
|
||||
if (crypto_mod_exp(conn->cred->dh_g, conn->cred->dh_g_len,
|
||||
conn->dh_secret, conn->dh_secret_len,
|
||||
conn->cred->dh_p, conn->cred->dh_p_len,
|
||||
dh_ys, &dh_ys_len)) {
|
||||
conn->dh_secret, conn->dh_secret_len,
|
||||
dh_p, dh_p_len, dh_ys, &dh_ys_len)) {
|
||||
tlsv1_server_alert(conn, TLS_ALERT_LEVEL_FATAL,
|
||||
TLS_ALERT_INTERNAL_ERROR);
|
||||
TLS_ALERT_INTERNAL_ERROR);
|
||||
os_free(dh_ys);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
wpa_hexdump(MSG_DEBUG, "TLSv1: DH Ys (server's public value)",
|
||||
dh_ys, dh_ys_len);
|
||||
|
||||
@@ -356,7 +480,7 @@ static int tls_write_server_key_exchange(struct tlsv1_server *conn,
|
||||
|
||||
pos = *msgpos;
|
||||
|
||||
wpa_printf(MSG_DEBUG, "TLSv1: Send ServerKeyExchange");
|
||||
tlsv1_server_log(conn, "Send ServerKeyExchange");
|
||||
rhdr = pos;
|
||||
pos += TLS_RECORD_HEADER_LEN;
|
||||
|
||||
@@ -371,8 +495,9 @@ static int tls_write_server_key_exchange(struct tlsv1_server *conn,
|
||||
pos += 3;
|
||||
|
||||
/* body - ServerDHParams */
|
||||
server_params = pos;
|
||||
/* dh_p */
|
||||
if (pos + 2 + conn->cred->dh_p_len > end) {
|
||||
if (2 + dh_p_len > (size_t) (end - pos)) {
|
||||
wpa_printf(MSG_DEBUG, "TLSv1: Not enough buffer space for "
|
||||
"dh_p");
|
||||
tlsv1_server_alert(conn, TLS_ALERT_LEVEL_FATAL,
|
||||
@@ -380,13 +505,13 @@ static int tls_write_server_key_exchange(struct tlsv1_server *conn,
|
||||
os_free(dh_ys);
|
||||
return -1;
|
||||
}
|
||||
WPA_PUT_BE16(pos, conn->cred->dh_p_len);
|
||||
WPA_PUT_BE16(pos, dh_p_len);
|
||||
pos += 2;
|
||||
os_memcpy(pos, conn->cred->dh_p, conn->cred->dh_p_len);
|
||||
pos += conn->cred->dh_p_len;
|
||||
os_memcpy(pos, dh_p, dh_p_len);
|
||||
pos += dh_p_len;
|
||||
|
||||
/* dh_g */
|
||||
if (pos + 2 + conn->cred->dh_g_len > end) {
|
||||
if (2 + conn->cred->dh_g_len > (size_t) (end - pos)) {
|
||||
wpa_printf(MSG_DEBUG, "TLSv1: Not enough buffer space for "
|
||||
"dh_g");
|
||||
tlsv1_server_alert(conn, TLS_ALERT_LEVEL_FATAL,
|
||||
@@ -400,7 +525,7 @@ static int tls_write_server_key_exchange(struct tlsv1_server *conn,
|
||||
pos += conn->cred->dh_g_len;
|
||||
|
||||
/* dh_Ys */
|
||||
if (pos + 2 + dh_ys_len > end) {
|
||||
if (2 + dh_ys_len > (size_t) (end - pos)) {
|
||||
wpa_printf(MSG_DEBUG, "TLSv1: Not enough buffer space for "
|
||||
"dh_Ys");
|
||||
tlsv1_server_alert(conn, TLS_ALERT_LEVEL_FATAL,
|
||||
@@ -414,6 +539,139 @@ static int tls_write_server_key_exchange(struct tlsv1_server *conn,
|
||||
pos += dh_ys_len;
|
||||
os_free(dh_ys);
|
||||
|
||||
/*
|
||||
* select (SignatureAlgorithm)
|
||||
* { case anonymous: struct { };
|
||||
* case rsa:
|
||||
* digitally-signed struct {
|
||||
* opaque md5_hash[16];
|
||||
* opaque sha_hash[20];
|
||||
* };
|
||||
* case dsa:
|
||||
* digitally-signed struct {
|
||||
* opaque sha_hash[20];
|
||||
* };
|
||||
* } Signature;
|
||||
*
|
||||
* md5_hash
|
||||
* MD5(ClientHello.random + ServerHello.random + ServerParams);
|
||||
*
|
||||
* sha_hash
|
||||
* SHA(ClientHello.random + ServerHello.random + ServerParams);
|
||||
*/
|
||||
|
||||
if (keyx == TLS_KEY_X_DHE_RSA) {
|
||||
u8 hash[100];
|
||||
u8 *signed_start;
|
||||
size_t clen;
|
||||
int hlen;
|
||||
|
||||
if (conn->rl.tls_version >= TLS_VERSION_1_2) {
|
||||
#ifdef CONFIG_TLSV12
|
||||
hlen = tlsv12_key_x_server_params_hash(
|
||||
conn->rl.tls_version, TLS_HASH_ALG_SHA256,
|
||||
conn->client_random,
|
||||
conn->server_random, server_params,
|
||||
pos - server_params, hash + 19);
|
||||
|
||||
/*
|
||||
* RFC 5246, 4.7:
|
||||
* TLS v1.2 adds explicit indication of the used
|
||||
* signature and hash algorithms.
|
||||
*
|
||||
* struct {
|
||||
* HashAlgorithm hash;
|
||||
* SignatureAlgorithm signature;
|
||||
* } SignatureAndHashAlgorithm;
|
||||
*/
|
||||
if (hlen < 0 || end - pos < 2) {
|
||||
tlsv1_server_alert(conn, TLS_ALERT_LEVEL_FATAL,
|
||||
TLS_ALERT_INTERNAL_ERROR);
|
||||
return -1;
|
||||
}
|
||||
*pos++ = TLS_HASH_ALG_SHA256;
|
||||
*pos++ = TLS_SIGN_ALG_RSA;
|
||||
|
||||
/*
|
||||
* RFC 3447, A.2.4 RSASSA-PKCS1-v1_5
|
||||
*
|
||||
* DigestInfo ::= SEQUENCE {
|
||||
* digestAlgorithm DigestAlgorithm,
|
||||
* digest OCTET STRING
|
||||
* }
|
||||
*
|
||||
* SHA-256 OID: sha256WithRSAEncryption ::= {pkcs-1 11}
|
||||
*
|
||||
* DER encoded DigestInfo for SHA256 per RFC 3447:
|
||||
* 30 31 30 0d 06 09 60 86 48 01 65 03 04 02 01 05 00
|
||||
* 04 20 || H
|
||||
*/
|
||||
hlen += 19;
|
||||
os_memcpy(hash,
|
||||
"\x30\x31\x30\x0d\x06\x09\x60\x86\x48\x01\x65"
|
||||
"\x03\x04\x02\x01\x05\x00\x04\x20", 19);
|
||||
|
||||
#else /* CONFIG_TLSV12 */
|
||||
tlsv1_server_alert(conn, TLS_ALERT_LEVEL_FATAL,
|
||||
TLS_ALERT_INTERNAL_ERROR);
|
||||
return -1;
|
||||
#endif /* CONFIG_TLSV12 */
|
||||
} else {
|
||||
hlen = tls_key_x_server_params_hash(
|
||||
conn->rl.tls_version, conn->client_random,
|
||||
conn->server_random, server_params,
|
||||
pos - server_params, hash);
|
||||
}
|
||||
|
||||
if (hlen < 0) {
|
||||
tlsv1_server_alert(conn, TLS_ALERT_LEVEL_FATAL,
|
||||
TLS_ALERT_INTERNAL_ERROR);
|
||||
return -1;
|
||||
}
|
||||
|
||||
wpa_hexdump(MSG_MSGDUMP, "TLS: ServerKeyExchange signed_params hash",
|
||||
hash, hlen);
|
||||
#ifdef CONFIG_TESTING_OPTIONS
|
||||
if (conn->test_flags & TLS_BREAK_SRV_KEY_X_HASH) {
|
||||
tlsv1_server_log(conn, "TESTING: Break ServerKeyExchange signed params hash");
|
||||
hash[hlen - 1] ^= 0x80;
|
||||
}
|
||||
#endif /* CONFIG_TESTING_OPTIONS */
|
||||
|
||||
/*
|
||||
* RFC 2246, 4.7:
|
||||
* In digital signing, one-way hash functions are used as input
|
||||
* for a signing algorithm. A digitally-signed element is
|
||||
* encoded as an opaque vector <0..2^16-1>, where the length is
|
||||
* specified by the signing algorithm and key.
|
||||
*
|
||||
* In RSA signing, a 36-byte structure of two hashes (one SHA
|
||||
* and one MD5) is signed (encrypted with the private key). It
|
||||
* is encoded with PKCS #1 block type 0 or type 1 as described
|
||||
* in [PKCS1].
|
||||
*/
|
||||
signed_start = pos; /* length to be filled */
|
||||
pos += 2;
|
||||
clen = end - pos;
|
||||
if (conn->cred == NULL ||
|
||||
crypto_private_key_sign_pkcs1(conn->cred->key, hash, hlen,
|
||||
pos, &clen) < 0) {
|
||||
wpa_printf(MSG_DEBUG, "TLSv1: Failed to sign hash (PKCS #1)");
|
||||
tlsv1_server_alert(conn, TLS_ALERT_LEVEL_FATAL,
|
||||
TLS_ALERT_INTERNAL_ERROR);
|
||||
return -1;
|
||||
}
|
||||
WPA_PUT_BE16(signed_start, clen);
|
||||
#ifdef CONFIG_TESTING_OPTIONS
|
||||
if (conn->test_flags & TLS_BREAK_SRV_KEY_X_SIGNATURE) {
|
||||
tlsv1_server_log(conn, "TESTING: Break ServerKeyExchange signed params signature");
|
||||
pos[clen - 1] ^= 0x80;
|
||||
}
|
||||
#endif /* CONFIG_TESTING_OPTIONS */
|
||||
|
||||
pos += clen;
|
||||
}
|
||||
|
||||
WPA_PUT_BE24(hs_length, pos - hs_length - 3);
|
||||
|
||||
if (tlsv1_record_send(&conn->rl, TLS_CONTENT_TYPE_HANDSHAKE,
|
||||
@@ -447,7 +705,7 @@ static int tls_write_server_certificate_request(struct tlsv1_server *conn,
|
||||
|
||||
pos = *msgpos;
|
||||
|
||||
wpa_printf(MSG_DEBUG, "TLSv1: Send CertificateRequest");
|
||||
tlsv1_server_log(conn, "Send CertificateRequest");
|
||||
rhdr = pos;
|
||||
pos += TLS_RECORD_HEADER_LEN;
|
||||
|
||||
@@ -507,7 +765,7 @@ static int tls_write_server_hello_done(struct tlsv1_server *conn,
|
||||
size_t rlen;
|
||||
u8 payload[4];
|
||||
|
||||
wpa_printf(MSG_DEBUG, "TLSv1: Send ServerHelloDone");
|
||||
tlsv1_server_log(conn, "Send ServerHelloDone");
|
||||
|
||||
/* opaque fragment[TLSPlaintext.length] */
|
||||
|
||||
@@ -543,7 +801,7 @@ static int tls_write_server_change_cipher_spec(struct tlsv1_server *conn,
|
||||
size_t rlen;
|
||||
u8 payload[1];
|
||||
|
||||
wpa_printf(MSG_DEBUG, "TLSv1: Send ChangeCipherSpec");
|
||||
tlsv1_server_log(conn, "Send ChangeCipherSpec");
|
||||
|
||||
payload[0] = TLS_CHANGE_CIPHER_SPEC;
|
||||
|
||||
@@ -580,7 +838,7 @@ static int tls_write_server_finished(struct tlsv1_server *conn,
|
||||
|
||||
pos = *msgpos;
|
||||
|
||||
wpa_printf(MSG_DEBUG, "TLSv1: Send Finished");
|
||||
tlsv1_server_log(conn, "Send Finished");
|
||||
|
||||
/* Encrypted Handshake Message: Finished */
|
||||
|
||||
@@ -588,11 +846,11 @@ static int tls_write_server_finished(struct tlsv1_server *conn,
|
||||
if (conn->rl.tls_version >= TLS_VERSION_1_2) {
|
||||
hlen = SHA256_MAC_LEN;
|
||||
if (conn->verify.sha256_server == NULL ||
|
||||
crypto_hash_finish(conn->verify.sha256_server, hash, &hlen)
|
||||
< 0) {
|
||||
crypto_hash_finish(conn->verify.sha256_server, hash, &hlen)
|
||||
< 0) {
|
||||
conn->verify.sha256_server = NULL;
|
||||
tlsv1_server_alert(conn, TLS_ALERT_LEVEL_FATAL,
|
||||
TLS_ALERT_INTERNAL_ERROR);
|
||||
TLS_ALERT_INTERNAL_ERROR);
|
||||
return -1;
|
||||
}
|
||||
conn->verify.sha256_server = NULL;
|
||||
@@ -637,6 +895,12 @@ static int tls_write_server_finished(struct tlsv1_server *conn,
|
||||
}
|
||||
wpa_hexdump_key(MSG_DEBUG, "TLSv1: verify_data (server)",
|
||||
verify_data + 1 + 3, TLS_VERIFY_DATA_LEN);
|
||||
#ifdef CONFIG_TESTING_OPTIONS
|
||||
if (conn->test_flags & TLS_BREAK_VERIFY_DATA) {
|
||||
tlsv1_server_log(conn, "TESTING: Break verify_data (server)");
|
||||
verify_data[1 + 3 + 1] ^= 0x80;
|
||||
}
|
||||
#endif /* CONFIG_TESTING_OPTIONS */
|
||||
|
||||
/* Handshake */
|
||||
pos = hs_start = verify_data;
|
||||
@@ -667,24 +931,46 @@ static u8 * tls_send_server_hello(struct tlsv1_server *conn, size_t *out_len)
|
||||
{
|
||||
u8 *msg, *end, *pos;
|
||||
size_t msglen;
|
||||
int ocsp_multi = 0;
|
||||
char *ocsp_resp = NULL;
|
||||
size_t ocsp_resp_len = 0;
|
||||
|
||||
*out_len = 0;
|
||||
|
||||
msglen = 1000 + tls_server_cert_chain_der_len(conn);
|
||||
if (conn->status_request_multi &&
|
||||
conn->cred->ocsp_stapling_response_multi) {
|
||||
ocsp_resp = os_readfile(
|
||||
conn->cred->ocsp_stapling_response_multi,
|
||||
&ocsp_resp_len);
|
||||
ocsp_multi = 1;
|
||||
} else if ((conn->status_request || conn->status_request_v2) &&
|
||||
conn->cred->ocsp_stapling_response) {
|
||||
ocsp_resp = os_readfile(conn->cred->ocsp_stapling_response,
|
||||
&ocsp_resp_len);
|
||||
}
|
||||
if (!ocsp_resp)
|
||||
ocsp_resp_len = 0;
|
||||
|
||||
msglen = 1000 + tls_server_cert_chain_der_len(conn) + ocsp_resp_len;
|
||||
|
||||
msg = os_malloc(msglen);
|
||||
if (msg == NULL)
|
||||
if (msg == NULL) {
|
||||
os_free(ocsp_resp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pos = msg;
|
||||
end = msg + msglen;
|
||||
|
||||
if (tls_write_server_hello(conn, &pos, end) < 0) {
|
||||
os_free(msg);
|
||||
os_free(ocsp_resp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (conn->use_session_ticket) {
|
||||
os_free(ocsp_resp);
|
||||
|
||||
/* Abbreviated handshake using session ticket; RFC 4507 */
|
||||
if (tls_write_server_change_cipher_spec(conn, &pos, end) < 0 ||
|
||||
tls_write_server_finished(conn, &pos, end) < 0) {
|
||||
@@ -701,12 +987,16 @@ static u8 * tls_send_server_hello(struct tlsv1_server *conn, size_t *out_len)
|
||||
|
||||
/* Full handshake */
|
||||
if (tls_write_server_certificate(conn, &pos, end) < 0 ||
|
||||
tls_write_server_certificate_status(conn, &pos, end, ocsp_multi,
|
||||
ocsp_resp, ocsp_resp_len) < 0 ||
|
||||
tls_write_server_key_exchange(conn, &pos, end) < 0 ||
|
||||
tls_write_server_certificate_request(conn, &pos, end) < 0 ||
|
||||
tls_write_server_hello_done(conn, &pos, end) < 0) {
|
||||
os_free(msg);
|
||||
os_free(ocsp_resp);
|
||||
return NULL;
|
||||
}
|
||||
os_free(ocsp_resp);
|
||||
|
||||
*out_len = pos - msg;
|
||||
|
||||
@@ -738,7 +1028,7 @@ static u8 * tls_send_change_cipher_spec(struct tlsv1_server *conn,
|
||||
|
||||
*out_len = pos - msg;
|
||||
|
||||
wpa_printf(MSG_DEBUG, "TLSv1: Handshake completed successfully");
|
||||
tlsv1_server_log(conn, "Handshake completed successfully");
|
||||
conn->state = ESTABLISHED;
|
||||
|
||||
return msg;
|
||||
@@ -757,8 +1047,8 @@ u8 * tlsv1_server_handshake_write(struct tlsv1_server *conn, size_t *out_len)
|
||||
/* Abbreviated handshake was already completed. */
|
||||
return NULL;
|
||||
}
|
||||
wpa_printf(MSG_DEBUG, "TLSv1: Unexpected state %d while "
|
||||
"generating reply", conn->state);
|
||||
tlsv1_server_log(conn, "Unexpected state %d while generating reply",
|
||||
conn->state);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@@ -769,7 +1059,7 @@ u8 * tlsv1_server_send_alert(struct tlsv1_server *conn, u8 level,
|
||||
{
|
||||
u8 *alert, *pos, *length;
|
||||
|
||||
wpa_printf(MSG_DEBUG, "TLSv1: Send Alert(%d:%d)", level, description);
|
||||
tlsv1_server_log(conn, "Send Alert(%d:%d)", level, description);
|
||||
*out_len = 0;
|
||||
|
||||
alert = os_malloc(10);
|
||||
|
Reference in New Issue
Block a user