Skip to content

Commit d94ccb9

Browse files
authored
Merge pull request esp8266#24 from slaff/master
Re-added the SNI extension.
2 parents 144994c + fac976c commit d94ccb9

File tree

3 files changed

+43
-5
lines changed

3 files changed

+43
-5
lines changed

ssl/tls1.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ extern "C" {
8383
#define NUM_PROTOCOLS 4
8484

8585
#define MAX_SIG_ALGORITHMS 4
86-
#define SIG_ALG_EXTENSION 0x0d
8786
#define SIG_ALG_SHA1 2
8887
#define SIG_ALG_SHA256 4
8988
#define SIG_ALG_SHA384 5
@@ -117,6 +116,13 @@ enum
117116
HS_FINISHED = 20
118117
};
119118

119+
/* SSL extension types */
120+
enum
121+
{
122+
SSL_EXT_SERVER_NAME = 0,
123+
SSL_EXT_SIG_ALG = 0x0d,
124+
};
125+
120126
typedef struct
121127
{
122128
uint8_t cipher;

ssl/tls1_clnt.c

+35-3
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@
3939

4040
/* support sha512/384/256/1 RSA */
4141
static const uint8_t g_sig_alg[] = {
42-
0x00, 0x0e,
43-
0x00, SIG_ALG_EXTENSION,
42+
0x00, SSL_EXT_SIG_ALG,
4443
0x00, 0x0a, 0x00, 0x08,
4544
SIG_ALG_SHA512, SIG_ALG_RSA,
4645
SIG_ALG_SHA384, SIG_ALG_RSA,
@@ -197,7 +196,10 @@ static int send_client_hello(SSL *ssl)
197196
uint8_t *buf = ssl->bm_data;
198197
time_t tm = time(NULL);
199198
uint8_t *tm_ptr = &buf[6]; /* time will go here */
200-
int i, offset;
199+
int i, offset, ext_offset;
200+
uint16_t ext_len; /* extensions total length */
201+
202+
ext_len = 0;
201203

202204
buf[0] = HS_CLIENT_HELLO;
203205
buf[1] = 0;
@@ -244,11 +246,41 @@ static int send_client_hello(SSL *ssl)
244246
buf[offset++] = 1; /* no compression */
245247
buf[offset++] = 0;
246248

249+
ext_offset = offset;
250+
251+
buf[offset++] = 0; /* total length of extensions */
252+
buf[offset++] = 0;
253+
247254
/* send the signature algorithm extension for TLS 1.2+ */
248255
if (ssl->version >= SSL_PROTOCOL_VERSION_TLS1_2)
249256
{
250257
memcpy(&buf[offset], g_sig_alg, sizeof(g_sig_alg));
251258
offset += sizeof(g_sig_alg);
259+
ext_len += sizeof(g_sig_alg);
260+
}
261+
262+
/* send the host name if specified */
263+
if (ssl->host_name != NULL) {
264+
unsigned int host_len = strlen(ssl->host_name);
265+
266+
buf[offset++] = 0;
267+
buf[offset++] = SSL_EXT_SERVER_NAME; /* server_name(0) (65535) */
268+
buf[offset++] = 0;
269+
buf[offset++] = host_len+5; /* server_name length */
270+
buf[offset++] = 0;
271+
buf[offset++] = host_len+3; /* server_list length */
272+
buf[offset++] = 0; /* host_name(0) (255) */
273+
buf[offset++] = 0;
274+
buf[offset++] = host_len; /* host_name length */
275+
strncpy((char*) &buf[offset], ssl->host_name, host_len);
276+
offset += host_len;
277+
ext_len += host_len + 9;
278+
}
279+
280+
if(ext_len > 0) {
281+
// update the extensions length value
282+
buf[ext_offset] = (uint8_t) ((ext_len >> 8) & 0xff);
283+
buf[ext_offset + 1] = (uint8_t) (ext_len & 0xff);
252284
}
253285

254286
buf[3] = offset - 4; /* handshake size */

ssl/tls1_svr.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ static int process_client_hello(SSL *ssl)
206206
ext_len += buf[offset++];
207207
PARANOIA_CHECK(pkt_size, offset + ext_len);
208208

209-
if (ext == SIG_ALG_EXTENSION)
209+
if (ext == SSL_EXT_SIG_ALG)
210210
{
211211
while (ext_len > 0)
212212
{

0 commit comments

Comments
 (0)