|
10 | 10 | #include <stdio.h>
|
11 | 11 | #include <limits.h>
|
12 | 12 | #include <errno.h>
|
| 13 | +#include <assert.h> |
13 | 14 | #include "../ssl_locl.h"
|
14 | 15 | #include <openssl/evp.h>
|
15 | 16 | #include <openssl/buffer.h>
|
@@ -347,6 +348,22 @@ int ssl3_write_bytes(SSL *s, int type, const void *buf_, size_t len,
|
347 | 348 | int i;
|
348 | 349 | size_t tmpwrit;
|
349 | 350 |
|
| 351 | + if (s->mode & SSL_MODE_QUIC_HACK) { |
| 352 | + /* If we have an alert to send, lets send it */ |
| 353 | + if (s->s3->alert_dispatch) { |
| 354 | + i = s->method->ssl_dispatch_alert(s); |
| 355 | + if (i <= 0) { |
| 356 | + /* SSLfatal() already called if appropriate */ |
| 357 | + return i; |
| 358 | + } |
| 359 | + } |
| 360 | + |
| 361 | + s->rwstate = SSL_WRITING; |
| 362 | + *written = len; |
| 363 | + |
| 364 | + return 1; |
| 365 | + } |
| 366 | + |
350 | 367 | s->rwstate = SSL_NOTHING;
|
351 | 368 | tot = s->rlayer.wnum;
|
352 | 369 | /*
|
@@ -667,6 +684,10 @@ int do_ssl3_write(SSL *s, int type, const unsigned char *buf,
|
667 | 684 | size_t totlen = 0, len, wpinited = 0;
|
668 | 685 | size_t j;
|
669 | 686 |
|
| 687 | + if (s->mode & SSL_MODE_QUIC_HACK) { |
| 688 | + assert(0); |
| 689 | + } |
| 690 | + |
670 | 691 | for (j = 0; j < numpipes; j++)
|
671 | 692 | totlen += pipelens[j];
|
672 | 693 | /*
|
@@ -1131,6 +1152,10 @@ int ssl3_write_pending(SSL *s, int type, const unsigned char *buf, size_t len,
|
1131 | 1152 | size_t currbuf = 0;
|
1132 | 1153 | size_t tmpwrit = 0;
|
1133 | 1154 |
|
| 1155 | + if (s->mode & SSL_MODE_QUIC_HACK) { |
| 1156 | + assert(0); |
| 1157 | + } |
| 1158 | + |
1134 | 1159 | if ((s->rlayer.wpend_tot > len)
|
1135 | 1160 | || (!(s->mode & SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER)
|
1136 | 1161 | && (s->rlayer.wpend_buf != buf))
|
@@ -1234,6 +1259,117 @@ int ssl3_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
|
1234 | 1259 | }
|
1235 | 1260 | }
|
1236 | 1261 |
|
| 1262 | + if (s->mode & SSL_MODE_QUIC_HACK) { |
| 1263 | + /* In QUIC, we only expect handshake protocol. Alerts are |
| 1264 | + notified by decicated API function. */ |
| 1265 | + if (!ossl_statem_get_in_handshake(s)) { |
| 1266 | + /* We found handshake data, so we're going back into init */ |
| 1267 | + ossl_statem_set_in_init(s, 1); |
| 1268 | + |
| 1269 | + i = s->handshake_func(s); |
| 1270 | + /* SSLfatal() already called if appropriate */ |
| 1271 | + if (i < 0) |
| 1272 | + return i; |
| 1273 | + if (i == 0) { |
| 1274 | + return -1; |
| 1275 | + } |
| 1276 | + *readbytes = 0; |
| 1277 | + return 1; |
| 1278 | + } |
| 1279 | + |
| 1280 | + if (s->rlayer.packet_length == 0) { |
| 1281 | + if (rbuf->left < 4) { |
| 1282 | + if (rbuf->len - rbuf->offset < 4 - rbuf->left) { |
| 1283 | + memmove(rbuf->buf, rbuf->buf + rbuf->offset - rbuf->left, |
| 1284 | + rbuf->left); |
| 1285 | + rbuf->offset = rbuf->left; |
| 1286 | + } |
| 1287 | + s->rwstate = SSL_READING; |
| 1288 | + /* TODO(size_t): Convert this function */ |
| 1289 | + ret = BIO_read(s->rbio, rbuf->buf + rbuf->offset, |
| 1290 | + rbuf->len - rbuf->offset); |
| 1291 | + if (ret < 0) { |
| 1292 | + return -1; |
| 1293 | + } |
| 1294 | + /* TODO Check this is really ok */ |
| 1295 | + if (ret == 0) { |
| 1296 | + *readbytes = 0; |
| 1297 | + return 1; |
| 1298 | + } |
| 1299 | + |
| 1300 | + rbuf->left += ret; |
| 1301 | + rbuf->offset += ret; |
| 1302 | + |
| 1303 | + if (rbuf->left < 4) { |
| 1304 | + *readbytes = 0; |
| 1305 | + return 1; |
| 1306 | + } |
| 1307 | + rbuf->offset -= rbuf->left; |
| 1308 | + } |
| 1309 | + |
| 1310 | + switch (rbuf->buf[rbuf->offset]) { |
| 1311 | + case SSL3_MT_CLIENT_HELLO: |
| 1312 | + case SSL3_MT_SERVER_HELLO: |
| 1313 | + case SSL3_MT_NEWSESSION_TICKET: |
| 1314 | + case SSL3_MT_END_OF_EARLY_DATA: |
| 1315 | + case SSL3_MT_ENCRYPTED_EXTENSIONS: |
| 1316 | + case SSL3_MT_CERTIFICATE: |
| 1317 | + case SSL3_MT_CERTIFICATE_REQUEST: |
| 1318 | + case SSL3_MT_CERTIFICATE_VERIFY: |
| 1319 | + case SSL3_MT_FINISHED: |
| 1320 | + case SSL3_MT_KEY_UPDATE: |
| 1321 | + case SSL3_MT_MESSAGE_HASH: |
| 1322 | + break; |
| 1323 | + default: |
| 1324 | + SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL3_READ_BYTES, |
| 1325 | + ERR_R_INTERNAL_ERROR); |
| 1326 | + return -1; |
| 1327 | + } |
| 1328 | + |
| 1329 | + s->rlayer.packet_length = (rbuf->buf[rbuf->offset + 1] << 16) |
| 1330 | + + (rbuf->buf[rbuf->offset + 2] << 8) |
| 1331 | + + rbuf->buf[rbuf->offset + 3] + 4; |
| 1332 | + } |
| 1333 | + |
| 1334 | + if (s->rlayer.packet_length) { |
| 1335 | + size_t n; |
| 1336 | + |
| 1337 | + n = len < s->rlayer.packet_length ? len : s->rlayer.packet_length; |
| 1338 | + if (rbuf->left == 0) { |
| 1339 | + s->rwstate = SSL_READING; |
| 1340 | + ret = BIO_read(s->rbio, buf, n); |
| 1341 | + if (ret >= 0) { |
| 1342 | + s->rlayer.packet_length -= ret; |
| 1343 | + *readbytes = ret; |
| 1344 | + if (recvd_type) { |
| 1345 | + *recvd_type = SSL3_RT_HANDSHAKE; |
| 1346 | + } |
| 1347 | + return 1; |
| 1348 | + } |
| 1349 | + return -1; |
| 1350 | + } |
| 1351 | + |
| 1352 | + n = n < rbuf->left ? n : rbuf->left; |
| 1353 | + |
| 1354 | + memcpy(buf, rbuf->buf + rbuf->offset, n); |
| 1355 | + rbuf->offset += n; |
| 1356 | + rbuf->left -= n; |
| 1357 | + s->rlayer.packet_length -= n; |
| 1358 | + if (rbuf->left == 0) { |
| 1359 | + rbuf->offset = 0; |
| 1360 | + } |
| 1361 | + *readbytes = n; |
| 1362 | + if (recvd_type) { |
| 1363 | + *recvd_type = SSL3_RT_HANDSHAKE; |
| 1364 | + } |
| 1365 | + return 1; |
| 1366 | + } |
| 1367 | + |
| 1368 | + SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL3_READ_BYTES, |
| 1369 | + ERR_R_INTERNAL_ERROR); |
| 1370 | + return -1; |
| 1371 | + } |
| 1372 | + |
1237 | 1373 | if ((type && (type != SSL3_RT_APPLICATION_DATA)
|
1238 | 1374 | && (type != SSL3_RT_HANDSHAKE)) || (peek
|
1239 | 1375 | && (type !=
|
|
0 commit comments