|
39 | 39 |
|
40 | 40 | /* support sha512/384/256/1 RSA */
|
41 | 41 | static const uint8_t g_sig_alg[] = {
|
42 |
| - 0x00, 0x0e, |
43 |
| - 0x00, SIG_ALG_EXTENSION, |
| 42 | + 0x00, SSL_EXT_SIG_ALG, |
44 | 43 | 0x00, 0x0a, 0x00, 0x08,
|
45 | 44 | SIG_ALG_SHA512, SIG_ALG_RSA,
|
46 | 45 | SIG_ALG_SHA384, SIG_ALG_RSA,
|
@@ -197,7 +196,10 @@ static int send_client_hello(SSL *ssl)
|
197 | 196 | uint8_t *buf = ssl->bm_data;
|
198 | 197 | time_t tm = time(NULL);
|
199 | 198 | 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; |
201 | 203 |
|
202 | 204 | buf[0] = HS_CLIENT_HELLO;
|
203 | 205 | buf[1] = 0;
|
@@ -244,11 +246,41 @@ static int send_client_hello(SSL *ssl)
|
244 | 246 | buf[offset++] = 1; /* no compression */
|
245 | 247 | buf[offset++] = 0;
|
246 | 248 |
|
| 249 | + ext_offset = offset; |
| 250 | + |
| 251 | + buf[offset++] = 0; /* total length of extensions */ |
| 252 | + buf[offset++] = 0; |
| 253 | + |
247 | 254 | /* send the signature algorithm extension for TLS 1.2+ */
|
248 | 255 | if (ssl->version >= SSL_PROTOCOL_VERSION_TLS1_2)
|
249 | 256 | {
|
250 | 257 | memcpy(&buf[offset], g_sig_alg, sizeof(g_sig_alg));
|
251 | 258 | 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); |
252 | 284 | }
|
253 | 285 |
|
254 | 286 | buf[3] = offset - 4; /* handshake size */
|
|
0 commit comments