Line data Source code
1 : /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
2 : * Copyright (C) 2025 Frediano Ziglio
3 : *
4 : * This library is free software; you can redistribute it and/or
5 : * modify it under the terms of the GNU Library General Public
6 : * License as published by the Free Software Foundation; either
7 : * version 2 of the License, or (at your option) any later version.
8 : *
9 : * This library is distributed in the hope that it will be useful,
10 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 : * Library General Public License for more details.
13 : *
14 : * You should have received a copy of the GNU Library General Public
15 : * License along with this library; if not, write to the
16 : * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 : * Boston, MA 02111-1307, USA.
18 : */
19 :
20 : /*
21 : * Purpose: test channel binding code
22 : */
23 : #undef NDEBUG
24 : #include "../challenge.c"
25 :
26 : #include "common.h"
27 :
28 : static char *
29 : bin2ascii(char *dest, const void *data, size_t len)
30 : {
31 20 : char *s = dest;
32 20 : const unsigned char *src = (const unsigned char *) data;
33 :
34 320 : for (; len > 0; --len, s += 2)
35 320 : sprintf(s, "%02x", *src++);
36 20 : *s = 0;
37 : return dest;
38 : }
39 :
40 : static void
41 20 : calc_cbt_test(const char *app_data, const char *cbt)
42 : {
43 : unsigned char cbt_buf[16];
44 : char cbt_str[33];
45 :
46 20 : tds_calc_cbt(app_data, strlen(app_data), cbt_buf);
47 :
48 : /* convert to hex string and compare */
49 20 : bin2ascii(cbt_str, cbt_buf, 16);
50 20 : if (strcasecmp(cbt_str, cbt) != 0) {
51 0 : fprintf(stderr, "Wrong tds_calc_cbt(%s) -> %s expected %s\n", app_data, cbt_str, cbt);
52 0 : exit(1);
53 : }
54 20 : }
55 :
56 10 : TEST_MAIN()
57 : {
58 10 : calc_cbt_test("tls-unique:0123456789abcdef", "1eb7620a5e38cb1f50478b1690621a03");
59 10 : calc_cbt_test("tls-server-end-point:0123456789abcdef0123456789abcdef", "5eda5394c965f26697e73da2828a7ad0");
60 10 : return 0;
61 : }
|