2025-01-02 16:02:21 +00:00
|
|
|
// RFC 9001 Appendix A.
|
|
|
|
static const char quic_testing_payload[] = "\xc0\x00\x00\x00\x01\x08\x83\x94\xc8\xf0\x3e\x51\x57\x08\x00\x00\x44\x9e\x7b\x9a\xec\x34\xd1\xb1\xc9\x8d\xd7\x68\x9f\xb8\xec\x11\xd2\x42\xb1\x23\xdc\x9b\xd8\xba\xb9\x36\xb4\x7d\x92\xec\x35\x6c\x0b\xab\x7d\xf5\x97\x6d\x27\xcd\x44\x9f\x63\x30\x00\x99\xf3\x99\x1c\x26\x0e\xc4\xc6\x0d\x17\xb3\x1f\x84\x29\x15\x7b\xb3\x5a\x12\x82\xa6\x43\xa8\xd2\x26\x2c\xad\x67\x50\x0c\xad\xb8\xe7\x37\x8c\x8e\xb7\x53\x9e\xc4\xd4\x90\x5f\xed\x1b\xee\x1f\xc8\xaa\xfb\xa1\x7c\x75\x0e\x2c\x7a\xce\x01\xe6\x00\x5f\x80\xfc\xb7\xdf\x62\x12\x30\xc8\x37\x11\xb3\x93\x43\xfa\x02\x8c\xea\x7f\x7f\xb5\xff\x89\xea\xc2\x30\x82\x49\xa0\x22\x52\x15\x5e\x23\x47\xb6\x3d\x58\xc5\x45\x7a\xfd\x84\xd0\x5d\xff\xfd\xb2\x03\x92\x84\x4a\xe8\x12\x15\x46\x82\xe9\xcf\x01\x2f\x90\x21\xa6\xf0\xbe\x17\xdd\xd0\xc2\x08\x4d\xce\x25\xff\x9b\x06\xcd\xe5\x35\xd0\xf9\x20\xa2\xdb\x1b\xf3\x62\xc2\x3e\x59\x6d\x11\xa4\xf5\xa6\xcf\x39\x48\x83\x8a\x3a\xec\x4e\x15\xda\xf8\x50\x0a\x6e\xf6\x9e\xc4\xe3\xfe\xb6\xb1\xd9\x8e\x61\x0a\xc8\xb7\xec\x3f\xaf\x6a\xd7\x60\xb7\xba\xd1\xdb\x4b\xa3\x48\x5e\x8a\x94\xdc\x25\x0a\xe3\xfd\xb4\x1e\xd1\x5f\xb6\xa8\xe5\xeb\xa0\xfc\x3d\xd6\x0b\xc8\xe3\x0c\x5c\x42\x87\xe5\x38\x05\xdb\x05\x9a\xe0\x64\x8d\xb2\xf6\x42\x64\xed\x5e\x39\xbe\x2e\x20\xd8\x2d\xf5\x66\xda\x8d\xd5\x99\x8c\xca\xbd\xae\x05\x30\x60\xae\x6c\x7b\x43\x78\xe8\x46\xd2\x9f\x37\xed\x7b\x4e\xa9\xec\x5d\x82\xe7\x96\x1b\x7f\x25\xa9\x32\x38\x51\xf6\x81\xd5\x82\x36\x3a\xa5\xf8\x99\x37\xf5\xa6\x72\x58\xbf\x63\xad\x6f\x1a\x0b\x1d\x96\xdb\xd4\xfa\xdd\xfc\xef\xc5\x26\x6b\xa6\x61\x17\x22\x39\x5c\x90\x65\x56\xbe\x52\xaf\xe3\xf5\x65\x63\x6a\xd1\xb1\x7d\x50\x8b\x73\xd8\x74\x3e\xeb\x52\x4b\xe2\x2b\x3d\xcb\xc2\xc7\x46\x8d\x54\x11\x9c\x74\x68\x44\x9a\x13\xd8\xe3\xb9\x58\x11\xa1\x98\xf3\x49\x1d\xe3\xe7\xfe\x94\x2b\x33\x04\x07\xab\xf8\x2a\x4e\xd7\xc1\xb3\x11\x66\x3a\xc6\x98\x90\xf4\x15\x70\x15\x85\x3d\x91\xe9\x23\x03\x7c\x22\x7a\x33\xcd\xd5\xec\x28\x1c\xa3\xf7\x9c\x44\x54\x6b\x9d\x90\xca\x00\xf0\x64\xc9\x9e\x3d\xd9\x79\x11\xd3\x9f\xe9\xc5\xd0\xb2\x3a\x22\x9a\x23\x4c\xb3\x61\x86\xc4\x81\x9e\x8b\x9c\x59\x27\x72\x66\x32\x29\x1d\x6a\x41\x82\x11\xcc\x29\x62\xe2\x0f\xe4\x7f\xeb\x3e\xdf\x33\x0f\x2c\x60\x3a\x9d\x48\xc0\xfc\xb5\x69\x9d\xbf\xe5\x89\x64\x25\xc5\xba\xc4\xae\xe8\x2e\x57\xa8\x5a\xaf\x4e\x25\x13\xe4\xf0\x57\x96\xb0\x7b\xa2\xee\x47\xd8\x05\x06\xf8\xd2\xc2\x5e\x50\xfd\x14\xde\x71\xe6\xc4\x18\x55\x93\x02\xf9\x39\xb0\xe1\xab\xd5\x76\xf2\x79\xc4\xb2\xe0\xfe\xb8\x5c\x1f\x28\xff\x18\xf5\x88\x91\xff\xef\x13\x2e\xef\x2f\xa0\x93\x46\xae\xe3\x3c\x28\xeb\x13\x0f\xf2\x8f\x5b\x76\x69\x53\x33\x41\x13\x21\x19\x96\xd2\x00\x11\xa1\x98\xe3\xfc\x43\x3f\x9f\x25\x41\x01\x0a\xe1\x7c\x1b\xf2\x02\x58\x0f\x60\x47\x47\x2f\xb3\x68\x57\xfe\x84\x3b\x19\xf5\x98\x40\x09\xdd\xc3\x24\x04\x4e\x84\x7a\x4f\x4a\x0a\xb3\x4f\x71\x95\x95\xde\x37\x25\x2d\x62\x35\x36\x5e\x9b\x84\x39\x2b\x06\x10\x85\x34\x9d\x73\x20\x3a\x4a\x13\xe9\x6f\x54\x32\xec\x0f\xd4\xa1\xee\x65\xac\xcd\xd5\xe3\x90\x4d\xf5\x4c\x1d\xa5\x10\xb0\xff\x20\xdc\xc0\xc7\x7f\xcb\x2c\x0e\x0e\xb6\x05\xcb\x05\x04\xdb\x87\x63\x2c\xf3\xd8\xb4\xda\xe6\xe7\x05\x76\x9d\x1d\xe3\x54\x27\x01\x23\xcb\x11\x45\x0e\xfc\x60\xac\x47\x68\x3d\x7b\x8d\x0f\x81\x13\x65\x56\x5f\xd9\x8c\x4c\x8e\xb9\x36\xbc\xab\x8d\x06\x9f\xc3\x3b\xd8\x01\xb0\x3a\xde\xa2\xe1\xfb\xc5\xaa\x46\x3d\x08\xca\x19\x89\x6d\x2b\xf5\x9a\x07\x1b\x85\x1e\x6c\x23\x90\x52\x17\x2f\x29\x6b\xfb\x5e\x72\x40\x47\x90\xa2\x18\x10\x14\xf3\xb9\x4a\x4e\x97\xd1\x17\xb4\x38\x13\x03\x68\xcc\x39\xdb\xb2\xd1\x98\x06\x5a\xe3\x98\x65\x47\x92\x6c\xd2\x16\x2f\x40\xa2\x9f\x0c\x3c\x87\x45\xc0\xf5\x0f\xba\x38\x52\xe5\x66\xd4\x45\x75\xc2\x9d\x39\xa0\x3f\x0c\xda\x72\x19\x84\xb6\xf4\x40\x59\x1f\x35\x5e\x12\xd4\x39\xff\x15\x0a\xab\x76\x13\x49\x9d\xbd\x49\xad\xab\xc8\x67\x6e\xef\x02\x3b\x15\xb6\x5b\xfc\x5c\xa0\x69\x48\x10\x9f\x23\xf3\x50\xdb\x82\x12\x35\x35\xeb\x8a\x74\x33\xbd\xab\xcb\x90\x92\x71\xa6\xec\xbc\xb5\x8b\x93\x6a\x88\xcd\x4e\x8f\x2e\x6f\xf5\x80\x01\x75\xf1\x13\x25\x3d\x8f\xa9\xca\x88\x85\xc2\xf5\x52\xe6\x57\xdc\x60\x3f\x25\x2e\x1a\x8e\x30\x8f\x76\xf0\xbe\x79\xe2\xfb\x8f\x5d\x5f\xbb\xe2\xe3\x0e\xca\xdd\x22\x07\x23\xc8\xc0\xae\xa8\x0
|
|
|
|
static const char quic_decrypted_header[] = "\xc3\x00\x00\x00\x01\x08\x83\x94\xc8\xf0\x3e\x51\x57\x08\x00\x00\x44\x9e\x00\x00\x00\x02";
|
|
|
|
static const char quic_decrypted_crypto[] = "\x06\x00\x40\xf1\x01\x00\x00\xed\x03\x03\xeb\xf8\xfa\x56\xf1\x29\x39\xb9\x58\x4a\x38\x96\x47\x2e\xc4\x0b\xb8\x63\xcf\xd3\xe8\x68\x04\xfe\x3a\x47\xf0\x6a\x2b\x69\x48\x4c\x00\x00\x04\x13\x01\x13\x02\x01\x00\x00\xc0\x00\x00\x00\x10\x00\x0e\x00\x00\x0b\x65\x78\x61\x6d\x70\x6c\x65\x2e\x63\x6f\x6d\xff\x01\x00\x01\x00\x00\x0a\x00\x08\x00\x06\x00\x1d\x00\x17\x00\x18\x00\x10\x00\x07\x00\x05\x04\x61\x6c\x70\x6e\x00\x05\x00\x05\x01\x00\x00\x00\x00\x00\x33\x00\x26\x00\x24\x00\x1d\x00\x20\x93\x70\xb2\xc9\xca\xa4\x7f\xba\xba\xf4\x55\x9f\xed\xba\x75\x3d\xe1\x71\xfa\x71\xf5\x0f\x1c\xe1\x5d\x43\xe9\x94\xec\x74\xd7\x48\x00\x2b\x00\x03\x02\x03\x04\x00\x0d\x00\x10\x00\x0e\x04\x03\x05\x03\x06\x03\x02\x03\x08\x04\x08\x05\x08\x06\x00\x2d\x00\x02\x01\x01\x00\x1c\x00\x02\x40\x01\x00\x39\x00\x32\x04\x08\xff\xff\xff\xff\xff\xff\xff\xff\x05\x04\x80\x00\xff\xff\x07\x04\x80\x00\xff\xff\x08\x01\x10\x01\x04\x80\x00\x75\x30\x09\x01\x10\x0f\x08\x83\x94\xc8\xf0\x3e\x51\x57\x08\x06\x04\x80\x00\xff\xff";
|
|
|
|
static const int quic_padding_len = 917;
|
|
|
|
|
2025-01-03 22:02:13 +00:00
|
|
|
// Just a QUIC payload but with sparse frames (like ping, padding, ping, crypto 0, padding, ping, ping, padding, ping, crypto 425, padding)
|
|
|
|
static const char quic_sparse_payload[] = "\306\000\000\000\001\bB\302\246\317\237]S\226\000\000D\320\372/\3503Ac\222\312\360\355\030\223\231\340\360\022\222e\177$@\270\312\006\205-\267\304\207\036Zq?\246\2072zza\272\337\365'\335_\246\255\2502\347\245r\217>\2556\t\033\347\234w*Q4\003\330\270\037\271\004\346\254B(G\022\356\232\221P\357\305>\301T\331J xv.<\224\344Q\267\v\017b\254\260f\313\232\2213D:F\371\214\177\342C\234\022\301\316\277\342/\027\337X\317\250\200N< 6y\313\r\224\310i\263-\212\372\030\264Z\003#D4\234\315\205H\373\227\026yx\245d\375\211U\223\235\204\236\"T\255i\001\3308)ca%\243\376.mMc\225\b&\276\245n\233V\300\334\261\261\247\266(\334kA\314\250\261\271\353\nC\034\273\276\324\361J\341\017\361N\212\3128\261\233z\267|\344\260d\376\344\342\357\336\255X\366w\313\225C\022\022s\256\202\3568k!\177\025\375K~\224y\216\022\341\376\230\024\346\212l\025\253\300\256\031\360O\200|\331\342\315=I\306dS\030\306\320\212\177\356\350\207\360D7\177\agQ\"\031o6\202\352k\206]\210\370k5k\252\221\254\245\364\333\247\310\207\024\202Q#\314\214\264\341R?UL\340\271\313\213nj\217;\rU\304C\274\361[\327\002\321\372\212LO\325\324\237<\336\361<\205\331w\177`\210\\\276\304\314\220\235\3437\206g\323\275\036\a\033A!\254\217\341\277y6\211\304\031`-d\207wj\037\334MjY'!\327\245\002\255;\b\251\215\tY\310/\366N\224\206\027\037*\311\235\302\236=\377C\264\343o\255\264f\235%\036\026y\353\271(\3160\343*\300>\214&}\177-\363jj\336\204'\266\310\210\312\347\211h)\351\031\325\231\332\177\332#\3552bC\2775)\336\353\271gY\305\315`\212\342\325\376\250\2235y\a\315b\200R\361S\022\333\f\023\r\313\370\267\n\205\314\374\257\376\211\304Y?}.u\244b\315\221\264\211\371\256\224\332C\333@\025\027nb)G\360S\326_\277\362\201\365]\2745\376\253#\251\240\224=\316Y_\233\260\302\260\227.}\260\226\244\241r\320\347_\2273V\237\0262\375^\374F\266!\036k\346\352\204\222\300VuN\027\216\"\2531j\330\222\335\354Uz\367,\376\201\272O\177\376\026\220:?\n\202S\220\373\343\333'+%*rW\n\177Y{\347\211\357+\364(\270\034\207\371\221>\200Ua\026\034\235e\246D\036\352X\202\350\036\303\231\210\351j+\227e\352il\362\273`\360\361\304e\356\206\321\2232\327]\246\325\273\361\233G\336n\212.\335\250\t\177\233$\243\334<\304%\332\000\346\2777\343c\026`|\222\3666\207\021\034\001~\206\221I\f\316\f\006\000\036~\313kH\243L\343B\261Yg\031\362\324\370-\260B\330?e>fd\r\3544\\\312E\231\000\210oZ\033s\207\220\36379f=\017\032\256~\222\377!q\270w\305!\312o\343\035_\003U\313P\356\363^\016o\203,Yf \354\321\0038:\363I\300\215+h\316\305\257\305\002\t\232c\333'~\341\352\3170\362\244A\211\360\272\371\321\371Q\b\237\3076s.\032\322k\202,\345\374\266\233b OS\035\b*\242J\265\215\357\317\325\356\322\031g\2610G]\272i\265\\,\226\237\323\355\351\237\345\032b\364\347\250\227\217\323\353Y\002q[\335\365\034\363$*\312\231\317\302}\2600~\261O\336\265(d\240\323\214zr\371=\027\203\376\330\032w\002,90~{\3677\230\363\250b\320\202I\221\213?\272\227\ncc\343\031Ow\0347s\313\356\037\312t\206\002\006\336\270\203\277\020j\210g\372MU\2758\333\326:\312\262\r\022\210\275[}\314\377\035\241\267s\326\211\300\236;\217\001/\354k\365+?n\230e\350\002z\\K\035\227j\331\031\rj\230<z\272\220\311\036\000\264\017\020\255S\343\001\246\311\021\301\t\006\337\245\3565\2657D{9\b\271s=\a\202\254\326\365T+e\370)7AE\241\217z\276\331xe\n<\320\206\246-\313\330\035\"&\347\201\275\234r\355>\306\306\236\367\021p#\001\203\262\206+kg\313u\205a\004\t2>\322\224\327\001.c\t\225\244=\243M\006\311\347z\262\021Hl\027\202\271\033\345~\334\214\034\202\024m@\372\361Kk@~\374\340Z\260D\245\272'M\232\001$\242wJ:\r\r-\244\363\217\t\261WgS7\272\213\357\314\240\371\374\313\233r\235\017\235\031\230%}Z\345\"";
|
|
|
|
|
2025-01-02 16:02:21 +00:00
|
|
|
|
2025-01-02 13:44:12 +00:00
|
|
|
#include "unity.h"
|
|
|
|
#include "unity_fixture.h"
|
|
|
|
|
2025-01-02 16:02:21 +00:00
|
|
|
#include "quic.h"
|
|
|
|
#include "types.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "tls.h"
|
|
|
|
#include "config.h"
|
2025-01-03 22:02:13 +00:00
|
|
|
#include "logging.h"
|
2025-01-02 16:02:21 +00:00
|
|
|
|
|
|
|
static struct section_config_t sconf = default_section_config;
|
|
|
|
|
2025-01-02 13:44:12 +00:00
|
|
|
TEST_GROUP(QuicTest);
|
|
|
|
|
|
|
|
TEST_SETUP(QuicTest)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_TEAR_DOWN(QuicTest)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2025-01-02 16:02:21 +00:00
|
|
|
TEST(QuicTest, Test_decrypts)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
uint8_t *decrypted_payload;
|
|
|
|
uint32_t decrypted_payload_len;
|
|
|
|
const uint8_t *decrypted_message;
|
|
|
|
uint32_t decrypted_message_len;
|
|
|
|
|
|
|
|
ret = quic_parse_initial_message(
|
|
|
|
(const uint8_t *)quic_testing_payload, sizeof(quic_testing_payload) - 1,
|
|
|
|
&decrypted_payload, &decrypted_payload_len,
|
|
|
|
&decrypted_message, &decrypted_message_len
|
|
|
|
);
|
|
|
|
|
|
|
|
TEST_ASSERT_EQUAL(ret, 0);
|
|
|
|
|
|
|
|
TEST_ASSERT_EQUAL(sizeof(quic_testing_payload) - 1, decrypted_payload_len);
|
|
|
|
TEST_ASSERT_EQUAL_MEMORY(quic_decrypted_header, decrypted_payload, sizeof(quic_decrypted_header) - 1);
|
|
|
|
TEST_ASSERT_EQUAL(decrypted_message, decrypted_payload + sizeof(quic_decrypted_header) - 1);
|
|
|
|
TEST_ASSERT_EQUAL_MEMORY(quic_decrypted_crypto, decrypted_message, sizeof(quic_decrypted_crypto) - 1);
|
|
|
|
|
|
|
|
const uint8_t *curptr = decrypted_message + (sizeof(quic_decrypted_crypto) - 1);
|
|
|
|
ssize_t curptr_len = decrypted_message_len - (sizeof(quic_decrypted_crypto) - 1);
|
|
|
|
TEST_ASSERT_EQUAL(quic_padding_len, curptr_len);
|
|
|
|
|
|
|
|
while (curptr_len-- > 0) {
|
|
|
|
TEST_ASSERT_EQUAL(0x00, *curptr++);
|
|
|
|
}
|
|
|
|
TEST_ASSERT_EQUAL(decrypted_message + decrypted_message_len, curptr);
|
|
|
|
|
|
|
|
// tag is left
|
|
|
|
TEST_ASSERT_EQUAL(16, decrypted_payload + decrypted_payload_len - curptr);
|
2025-01-02 17:37:34 +00:00
|
|
|
|
|
|
|
#undef free
|
|
|
|
free(decrypted_payload);
|
|
|
|
#define free unity_free
|
2025-01-02 16:02:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(QuicTest, Test_crypto_parser_valid)
|
|
|
|
{
|
|
|
|
ssize_t fret;
|
|
|
|
struct quic_frame_crypto fr_cr;
|
|
|
|
|
|
|
|
fret = quic_parse_crypto(&fr_cr, (const uint8_t *)quic_decrypted_crypto, sizeof(quic_decrypted_crypto));
|
|
|
|
TEST_ASSERT_EQUAL(sizeof(quic_decrypted_crypto) - 1, fret);
|
|
|
|
TEST_ASSERT_EQUAL(0, fr_cr.offset);
|
|
|
|
TEST_ASSERT_EQUAL(241, fr_cr.payload_length);
|
|
|
|
// one for type, one for offset, two for length
|
|
|
|
TEST_ASSERT_EQUAL(quic_decrypted_crypto + 4, fr_cr.payload);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(QuicTest, Test_crypto_parser_tls)
|
|
|
|
{
|
|
|
|
ssize_t fret;
|
|
|
|
int ret;
|
|
|
|
struct quic_frame_crypto fr_cr;
|
|
|
|
struct tls_verdict tlsv;
|
|
|
|
|
|
|
|
fret = quic_parse_crypto(&fr_cr, (const uint8_t *)quic_decrypted_crypto, sizeof(quic_decrypted_crypto));
|
2025-01-02 17:37:34 +00:00
|
|
|
TEST_ASSERT_GREATER_OR_EQUAL(0, fret);
|
2025-01-02 16:02:21 +00:00
|
|
|
ret = analyze_tls_message(&sconf, fr_cr.payload, fr_cr.payload_length, &tlsv);
|
2025-01-02 17:37:34 +00:00
|
|
|
TEST_ASSERT_GREATER_OR_EQUAL(0, ret);
|
2025-01-02 16:02:21 +00:00
|
|
|
TEST_ASSERT_EQUAL_STRING_LEN("example.com", tlsv.sni_ptr, 11);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(QuicTest, Test_crypto_parser_invalid)
|
|
|
|
{
|
|
|
|
ssize_t fret;
|
|
|
|
struct quic_frame_crypto fr_cr;
|
|
|
|
|
|
|
|
fret = quic_parse_crypto(&fr_cr, NULL, 0);
|
|
|
|
TEST_ASSERT_EQUAL(-EINVAL, fret);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(QuicTest, Test_varlength_parser)
|
|
|
|
{
|
|
|
|
uint8_t varlv[4];
|
|
|
|
uint64_t mlen, var;
|
|
|
|
|
|
|
|
varlv[0] = 0x00;
|
|
|
|
varlv[1] = 0x00;
|
|
|
|
varlv[2] = 0x00;
|
|
|
|
varlv[3] = 0x00;
|
|
|
|
mlen = 4;
|
|
|
|
var = quic_parse_varlength(varlv, &mlen);
|
|
|
|
TEST_ASSERT_EQUAL(0, var);
|
|
|
|
TEST_ASSERT_EQUAL(1, mlen);
|
|
|
|
|
|
|
|
varlv[0] = 0x40;
|
|
|
|
varlv[1] = 0xf1;
|
|
|
|
varlv[2] = 0x00;
|
|
|
|
varlv[3] = 0x00;
|
|
|
|
mlen = 4;
|
|
|
|
var = quic_parse_varlength(varlv, &mlen);
|
|
|
|
TEST_ASSERT_EQUAL(241, var);
|
|
|
|
TEST_ASSERT_EQUAL(2, mlen);
|
|
|
|
|
|
|
|
mlen = 2;
|
|
|
|
var = quic_parse_varlength(varlv, &mlen);
|
|
|
|
TEST_ASSERT_EQUAL(241, var);
|
|
|
|
TEST_ASSERT_EQUAL(2, mlen);
|
|
|
|
|
|
|
|
// overflow
|
|
|
|
mlen = 1;
|
|
|
|
var = quic_parse_varlength(varlv, &mlen);
|
|
|
|
TEST_ASSERT_EQUAL(0, var);
|
|
|
|
TEST_ASSERT_EQUAL(0, mlen);
|
|
|
|
}
|
2025-01-02 13:44:12 +00:00
|
|
|
|
2025-01-02 17:37:34 +00:00
|
|
|
TEST(QuicTest, Test_parse_quic_decrypted)
|
|
|
|
{
|
2025-01-06 16:04:44 +00:00
|
|
|
#undef free
|
|
|
|
|
2025-01-02 17:37:34 +00:00
|
|
|
int ret;
|
|
|
|
uint8_t *decrypted_payload;
|
|
|
|
uint32_t decrypted_payload_len;
|
|
|
|
const uint8_t *decrypted_message;
|
|
|
|
uint32_t decrypted_message_len;
|
2025-01-06 16:04:44 +00:00
|
|
|
uint8_t *crypto_message;
|
|
|
|
uint32_t crypto_message_len;
|
2025-01-02 17:37:34 +00:00
|
|
|
struct tls_verdict tlsv = {0};
|
|
|
|
|
|
|
|
ret = quic_parse_initial_message(
|
|
|
|
(const uint8_t *)quic_testing_payload, sizeof(quic_testing_payload) - 1,
|
|
|
|
&decrypted_payload, &decrypted_payload_len,
|
|
|
|
&decrypted_message, &decrypted_message_len
|
|
|
|
);
|
2025-01-06 16:04:44 +00:00
|
|
|
TEST_ASSERT_EQUAL(0, ret);
|
2025-01-02 17:37:34 +00:00
|
|
|
|
2025-01-06 16:04:44 +00:00
|
|
|
ret = parse_quic_decrypted(
|
|
|
|
&sconf, decrypted_message, decrypted_message_len,
|
|
|
|
&crypto_message, &crypto_message_len);
|
|
|
|
TEST_ASSERT_EQUAL(0, ret);
|
2025-01-02 17:37:34 +00:00
|
|
|
free(decrypted_payload);
|
2025-01-06 16:04:44 +00:00
|
|
|
decrypted_payload = NULL;
|
|
|
|
|
|
|
|
ret = analyze_tls_message(
|
|
|
|
&sconf, crypto_message, crypto_message_len, &tlsv
|
|
|
|
);
|
|
|
|
TEST_ASSERT_EQUAL_STRING_LEN("example.com", tlsv.sni_ptr, 11);
|
|
|
|
free(crypto_message);
|
|
|
|
|
2025-01-02 17:37:34 +00:00
|
|
|
#define free unity_free
|
|
|
|
}
|
|
|
|
|
2025-01-03 22:02:13 +00:00
|
|
|
TEST(QuicTest, Test_parse_quic_decrypted_on_sparse)
|
|
|
|
{
|
2025-01-06 16:04:44 +00:00
|
|
|
#undef free
|
|
|
|
|
2025-01-03 22:02:13 +00:00
|
|
|
int ret;
|
|
|
|
uint8_t *decrypted_payload;
|
|
|
|
uint32_t decrypted_payload_len;
|
|
|
|
const uint8_t *decrypted_message;
|
|
|
|
uint32_t decrypted_message_len;
|
2025-01-06 16:04:44 +00:00
|
|
|
uint8_t *crypto_message;
|
|
|
|
uint32_t crypto_message_len;
|
2025-01-03 22:02:13 +00:00
|
|
|
struct tls_verdict tlsv = {0};
|
|
|
|
|
|
|
|
ret = quic_parse_initial_message(
|
|
|
|
(const uint8_t *)quic_sparse_payload, sizeof(quic_sparse_payload) - 1,
|
|
|
|
&decrypted_payload, &decrypted_payload_len,
|
|
|
|
&decrypted_message, &decrypted_message_len
|
|
|
|
);
|
2025-01-06 16:04:44 +00:00
|
|
|
TEST_ASSERT_EQUAL(0, ret);
|
|
|
|
|
|
|
|
ret = parse_quic_decrypted(
|
|
|
|
&sconf, decrypted_message, decrypted_message_len,
|
|
|
|
&crypto_message, &crypto_message_len);
|
|
|
|
TEST_ASSERT_EQUAL(0, ret);
|
|
|
|
free(decrypted_payload);
|
|
|
|
decrypted_payload = NULL;
|
2025-01-03 22:02:13 +00:00
|
|
|
|
2025-01-06 16:04:44 +00:00
|
|
|
ret = analyze_tls_message(
|
|
|
|
&sconf, crypto_message, crypto_message_len, &tlsv
|
|
|
|
);
|
2025-01-03 22:02:13 +00:00
|
|
|
TEST_ASSERT_EQUAL(19, tlsv.sni_len);
|
|
|
|
TEST_ASSERT_EQUAL_STRING_LEN("ipm.adblockplus.dev", tlsv.sni_ptr, 19);
|
2025-01-06 16:04:44 +00:00
|
|
|
free(crypto_message);
|
|
|
|
|
2025-01-03 22:02:13 +00:00
|
|
|
#define free unity_free
|
|
|
|
}
|
|
|
|
|
2025-01-02 13:44:12 +00:00
|
|
|
TEST_GROUP_RUNNER(QuicTest)
|
|
|
|
{
|
2025-01-02 16:02:21 +00:00
|
|
|
RUN_TEST_CASE(QuicTest, Test_decrypts);
|
|
|
|
RUN_TEST_CASE(QuicTest, Test_crypto_parser_valid);
|
|
|
|
RUN_TEST_CASE(QuicTest, Test_crypto_parser_tls);
|
|
|
|
RUN_TEST_CASE(QuicTest, Test_crypto_parser_invalid);
|
|
|
|
RUN_TEST_CASE(QuicTest, Test_varlength_parser);
|
2025-01-02 17:37:34 +00:00
|
|
|
RUN_TEST_CASE(QuicTest, Test_parse_quic_decrypted)
|
2025-01-03 22:02:13 +00:00
|
|
|
RUN_TEST_CASE(QuicTest, Test_parse_quic_decrypted_on_sparse)
|
2025-01-02 13:44:12 +00:00
|
|
|
}
|