|
Packit Service |
4684c1 |
/*
|
|
Packit Service |
4684c1 |
* Copyright (C) 2016, 2017 Red Hat, Inc.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* Author: Nikos Mavrogiannopoulos
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* This file is part of GnuTLS.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* GnuTLS is free software; you can redistribute it and/or modify it
|
|
Packit Service |
4684c1 |
* under the terms of the GNU General Public License as published by
|
|
Packit Service |
4684c1 |
* the Free Software Foundation; either version 3 of the License, or
|
|
Packit Service |
4684c1 |
* (at your option) any later version.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* GnuTLS is distributed in the hope that it will be useful, but
|
|
Packit Service |
4684c1 |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
4684c1 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
4684c1 |
* General Public License for more details.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* You should have received a copy of the GNU Lesser General Public License
|
|
Packit Service |
4684c1 |
* along with this program. If not, see <https://www.gnu.org/licenses/>
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#ifdef HAVE_CONFIG_H
|
|
Packit Service |
4684c1 |
#include <config.h>
|
|
Packit Service |
4684c1 |
#endif
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#include <stdio.h>
|
|
Packit Service |
4684c1 |
#include <stdlib.h>
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#include <string.h>
|
|
Packit Service |
4684c1 |
#include <gnutls/gnutls.h>
|
|
Packit Service |
4684c1 |
#include <stdint.h>
|
|
Packit Service |
4684c1 |
#include "../lib/tls13/psk_ext_parser.h"
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#include "utils.h"
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* Tests the PSK-extension decoding part */
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static void decode(const char *test_name, const gnutls_datum_t *raw, const gnutls_datum_t *id,
|
|
Packit Service |
4684c1 |
const gnutls_datum_t *b, unsigned idx, int res)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
int ret;
|
|
Packit Service |
4684c1 |
psk_ext_parser_st p;
|
|
Packit Service |
4684c1 |
psk_ext_iter_st iter;
|
|
Packit Service |
4684c1 |
struct psk_st psk;
|
|
Packit Service |
4684c1 |
gnutls_datum_t binder;
|
|
Packit Service |
4684c1 |
unsigned found = 0;
|
|
Packit Service |
4684c1 |
unsigned i, j;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
ret = _gnutls13_psk_ext_parser_init(&p, raw->data, raw->size);
|
|
Packit Service |
4684c1 |
if (ret < 0) {
|
|
Packit Service |
4684c1 |
if (res == ret) /* expected */
|
|
Packit Service |
4684c1 |
return;
|
|
Packit Service |
4684c1 |
fail("%s: _gnutls13_psk_ext_parser_init: %d/%s\n", test_name, ret, gnutls_strerror(ret));
|
|
Packit Service |
4684c1 |
exit(1);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
_gnutls13_psk_ext_iter_init(&iter, &p);
|
|
Packit Service |
4684c1 |
for (i = 0; ; i++) {
|
|
Packit Service |
4684c1 |
ret = _gnutls13_psk_ext_iter_next_identity(&iter, &psk;;
|
|
Packit Service |
4684c1 |
if (ret < 0) {
|
|
Packit Service |
4684c1 |
if (ret == GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE)
|
|
Packit Service |
4684c1 |
break;
|
|
Packit Service |
4684c1 |
if (res == ret) /* expected */
|
|
Packit Service |
4684c1 |
return;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
if (i == idx) {
|
|
Packit Service |
4684c1 |
if (psk.identity.size == id->size && memcmp(psk.identity.data, id->data, id->size) == 0) {
|
|
Packit Service |
4684c1 |
if (debug)
|
|
Packit Service |
4684c1 |
success("%s: found id\n", test_name);
|
|
Packit Service |
4684c1 |
found = 1;
|
|
Packit Service |
4684c1 |
break;
|
|
Packit Service |
4684c1 |
} else {
|
|
Packit Service |
4684c1 |
fail("%s: did not found identity on index %d\n", test_name, idx);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (found == 0)
|
|
Packit Service |
4684c1 |
fail("%s: did not found identity!\n", test_name);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
_gnutls13_psk_ext_iter_init(&iter, &p);
|
|
Packit Service |
4684c1 |
for (j = 0; j <= i; j++) {
|
|
Packit Service |
4684c1 |
ret = _gnutls13_psk_ext_iter_next_binder(&iter, &binder);
|
|
Packit Service |
4684c1 |
if (ret < 0) {
|
|
Packit Service |
4684c1 |
if (res == ret) /* expected */
|
|
Packit Service |
4684c1 |
return;
|
|
Packit Service |
4684c1 |
fail("%s: could not extract binder: %s\n",
|
|
Packit Service |
4684c1 |
test_name, gnutls_strerror(ret));
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (debug)
|
|
Packit Service |
4684c1 |
success("%s: found binder\n", test_name);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (binder.size != b->size || memcmp(binder.data, b->data, b->size) != 0) {
|
|
Packit Service |
4684c1 |
hexprint(binder.data, binder.size);
|
|
Packit Service |
4684c1 |
fail("%s: did not match binder on index %d\n", test_name, idx);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
return;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
struct decode_tests_st {
|
|
Packit Service |
4684c1 |
const char *name;
|
|
Packit Service |
4684c1 |
gnutls_datum_t psk;
|
|
Packit Service |
4684c1 |
unsigned idx; /* the ID index */
|
|
Packit Service |
4684c1 |
gnutls_datum_t id;
|
|
Packit Service |
4684c1 |
gnutls_datum_t binder;
|
|
Packit Service |
4684c1 |
int res;
|
|
Packit Service |
4684c1 |
};
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
struct decode_tests_st decode_tests[] = {
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
.name = "single PSK",
|
|
Packit Service |
4684c1 |
.psk = { (unsigned char*)"\x00\x0a\x00\x04\x6e\x6d\x61\x76\x00\x00\x00\x00\x00\x21\x20\xc4\xda\xe5\x7e\x05\x59\xf7\xae\x9b\xba\x90\xd2\x6e\x12\x68\xf6\xc1\xc7\xb9\x7e\xdc\xed\x9e\x67\x4e\xa5\x91\x2d\x7c\xb4\xf0\xab", 47},
|
|
Packit Service |
4684c1 |
.id = { (unsigned char*)"nmav", 4 },
|
|
Packit Service |
4684c1 |
.binder = { (unsigned char*)"\xc4\xda\xe5\x7e\x05\x59\xf7\xae\x9b\xba\x90\xd2\x6e\x12\x68\xf6\xc1\xc7\xb9\x7e\xdc\xed\x9e\x67\x4e\xa5\x91\x2d\x7c\xb4\xf0\xab", 32 },
|
|
Packit Service |
4684c1 |
.idx = 0,
|
|
Packit Service |
4684c1 |
.res = 0
|
|
Packit Service |
4684c1 |
},
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
.name = "multiple psks id0",
|
|
Packit Service |
4684c1 |
.psk = { (unsigned char*)"\x00\x20\x00\x04\x70\x73\x6b\x31\x00\x00\x00\x00"
|
|
Packit Service |
4684c1 |
"\x00\x06\x70\x73\x6b\x69\x64\x00\x00\x00\x00\x00"
|
|
Packit Service |
4684c1 |
"\x00\x04\x74\x65\x73\x74\x00\x00\x00\x00\x00\x63"
|
|
Packit Service |
4684c1 |
"\x20\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
Packit Service |
4684c1 |
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
Packit Service |
4684c1 |
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x01\x00"
|
|
Packit Service |
4684c1 |
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
Packit Service |
4684c1 |
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
Packit Service |
4684c1 |
"\x00\x00\x00\x00\x00\x00\x20\x71\x83\x89\x3d\xcc"
|
|
Packit Service |
4684c1 |
"\x46\xad\x83\x18\x98\x59\x46\x0b\xb2\x51\x24\x53"
|
|
Packit Service |
4684c1 |
"\x41\xb4\x35\x04\x22\x90\x02\xac\x5e\xc1\xe7\xbc"
|
|
Packit Service |
4684c1 |
"\xca\x52\x16", 135},
|
|
Packit Service |
4684c1 |
.id = { (unsigned char*)"psk1", 4 },
|
|
Packit Service |
4684c1 |
.binder = { (unsigned char*)"\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 32},
|
|
Packit Service |
4684c1 |
.idx = 0,
|
|
Packit Service |
4684c1 |
.res = 0
|
|
Packit Service |
4684c1 |
},
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
.name = "multiple psks id1",
|
|
Packit Service |
4684c1 |
.psk = { (unsigned char*)"\x00\x20\x00\x04\x70\x73\x6b\x31\x00\x00\x00\x00"
|
|
Packit Service |
4684c1 |
"\x00\x06\x70\x73\x6b\x69\x64\x00\x00\x00\x00\x00"
|
|
Packit Service |
4684c1 |
"\x00\x04\x74\x65\x73\x74\x00\x00\x00\x00\x00\x63"
|
|
Packit Service |
4684c1 |
"\x20\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
Packit Service |
4684c1 |
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
Packit Service |
4684c1 |
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x01\x00"
|
|
Packit Service |
4684c1 |
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
Packit Service |
4684c1 |
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
Packit Service |
4684c1 |
"\x00\x00\x00\x00\x00\x00\x20\x71\x83\x89\x3d\xcc"
|
|
Packit Service |
4684c1 |
"\x46\xad\x83\x18\x98\x59\x46\x0b\xb2\x51\x24\x53"
|
|
Packit Service |
4684c1 |
"\x41\xb4\x35\x04\x22\x90\x02\xac\x5e\xc1\xe7\xbc"
|
|
Packit Service |
4684c1 |
"\xca\x52\x16", 135},
|
|
Packit Service |
4684c1 |
.id = { (unsigned char*)"pskid", 6 },
|
|
Packit Service |
4684c1 |
.binder = { (unsigned char*)"\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 32},
|
|
Packit Service |
4684c1 |
.idx = 1,
|
|
Packit Service |
4684c1 |
.res = 0
|
|
Packit Service |
4684c1 |
},
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
.name = "multiple psks id2",
|
|
Packit Service |
4684c1 |
.psk = { (unsigned char*)"\x00\x20\x00\x04\x70\x73\x6b\x31\x00\x00\x00\x00"
|
|
Packit Service |
4684c1 |
"\x00\x06\x70\x73\x6b\x69\x64\x00\x00\x00\x00\x00"
|
|
Packit Service |
4684c1 |
"\x00\x04\x74\x65\x73\x74\x00\x00\x00\x00\x00\x63"
|
|
Packit Service |
4684c1 |
"\x20\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
Packit Service |
4684c1 |
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
Packit Service |
4684c1 |
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x01\x00"
|
|
Packit Service |
4684c1 |
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
Packit Service |
4684c1 |
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
Packit Service |
4684c1 |
"\x00\x00\x00\x00\x00\x00\x20\x71\x83\x89\x3d\xcc"
|
|
Packit Service |
4684c1 |
"\x46\xad\x83\x18\x98\x59\x46\x0b\xb2\x51\x24\x53"
|
|
Packit Service |
4684c1 |
"\x41\xb4\x35\x04\x22\x90\x02\xac\x5e\xc1\xe7\xbc"
|
|
Packit Service |
4684c1 |
"\xca\x52\x16", 135},
|
|
Packit Service |
4684c1 |
.id = { (unsigned char*)"test", 4 },
|
|
Packit Service |
4684c1 |
.binder = { (unsigned char*)"\x71\x83\x89\x3d\xcc\x46\xad\x83\x18\x98\x59\x46\x0b\xb2\x51\x24\x53\x41\xb4\x35\x04\x22\x90\x02\xac\x5e\xc1\xe7\xbc\xca\x52\x16", 32},
|
|
Packit Service |
4684c1 |
.idx = 2,
|
|
Packit Service |
4684c1 |
.res = 0
|
|
Packit Service |
4684c1 |
},
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
.name = "multiple psks id3",
|
|
Packit Service |
4684c1 |
.psk = { (unsigned char*)"\x00\x20\x00\x04\x70\x73\x6b\x31\x00\x00\x00\x00"
|
|
Packit Service |
4684c1 |
"\x00\x06\x70\x73\x6b\x69\x64\x00\x00\x00\x00\x00"
|
|
Packit Service |
4684c1 |
"\x00\x04\x74\x65\x73\x74\x00\x00\x00\x00\x00\x42"
|
|
Packit Service |
4684c1 |
"\x20\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
Packit Service |
4684c1 |
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
Packit Service |
4684c1 |
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x01\x00"
|
|
Packit Service |
4684c1 |
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
Packit Service |
4684c1 |
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
Packit Service |
4684c1 |
"\x00\x00\x00\x00\x00\x00", 102},
|
|
Packit Service |
4684c1 |
.id = { (unsigned char*)"test", 4 },
|
|
Packit Service |
4684c1 |
.binder = { NULL, 0 },
|
|
Packit Service |
4684c1 |
.idx = 2,
|
|
Packit Service |
4684c1 |
.res = GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
};
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
void doit(void)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
unsigned i;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
for (i=0;i
|
|
Packit Service |
4684c1 |
decode(decode_tests[i].name, &decode_tests[i].psk, &decode_tests[i].id,
|
|
Packit Service |
4684c1 |
&decode_tests[i].binder, decode_tests[i].idx, decode_tests[i].res);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|