e9f7d832142bc907aecfbeaf0079f13ee9591f2a
[strongswan.git] / src / libtls / tests / suites / test_socket.c
1 /*
2 * Copyright (C) 2020 Pascal Knecht
3 * HSR Hochschule fuer Technik Rapperswil
4 *
5 * Copyright (C) 2014 Martin Willi
6 * Copyright (C) 2014 revosec AG
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 * for more details.
17 */
18
19 #include <test_suite.h>
20
21 #include <unistd.h>
22 #include <errno.h>
23
24 #include <processing/jobs/callback_job.h>
25 #include <credentials/sets/mem_cred.h>
26
27 #include "tls_socket.h"
28
29 /**
30 * Credentials for authentication
31 */
32 static mem_cred_t *creds;
33
34 /**
35 * RSA private key, 2048 bit
36 */
37 static char rsa[] = {
38 0x30,0x82,0x04,0xa4,0x02,0x01,0x00,0x02,0x82,0x01,0x01,0x00,0xee,0xa3,0x28,0xcc,
39 0x48,0xca,0x37,0xfc,0xb6,0xfa,0xfc,0x18,0x0d,0xa2,0x28,0x44,0xb4,0x16,0x56,0xf7,
40 0x97,0x5f,0x38,0x83,0xfc,0xd4,0x30,0xea,0xf7,0x5e,0xaa,0xd4,0x21,0x0e,0x71,0x49,
41 0x13,0x39,0xaf,0x89,0xa1,0x1d,0x1b,0x9a,0x08,0x44,0xff,0x0b,0xeb,0x4b,0xad,0x8e,
42 0xc4,0x6d,0x1e,0x0c,0x02,0xbb,0x17,0x59,0xc7,0x66,0xc7,0xff,0x4c,0x3c,0x11,0x40,
43 0x1a,0xe3,0xca,0x34,0xf8,0x41,0xe0,0x39,0x3e,0xce,0x72,0x9f,0x56,0x9e,0x69,0xad,
44 0x98,0x43,0x5f,0x35,0xc2,0xd0,0xd9,0xbc,0x8b,0xed,0xc6,0xc7,0x74,0x73,0x74,0x30,
45 0x92,0x86,0x39,0x26,0x3d,0xf1,0xd5,0x16,0x45,0x7d,0xcc,0x90,0x54,0xff,0x44,0x74,
46 0xf3,0xba,0x41,0x5c,0x58,0xa4,0x66,0xe6,0x9d,0x58,0xbe,0x7e,0x89,0xe1,0x7c,0xf7,
47 0x28,0xb0,0xde,0xe2,0x01,0x0a,0x89,0xc7,0x63,0x3f,0xef,0x2b,0xcb,0xef,0x65,0x89,
48 0x82,0x23,0x32,0xa7,0xa3,0x1c,0x0d,0xc6,0x8f,0x76,0x59,0x8b,0x55,0x65,0x9c,0x91,
49 0xd4,0x93,0x89,0xad,0x37,0x47,0x23,0x25,0xb3,0x53,0xea,0xef,0x73,0xeb,0x97,0xd3,
50 0xd7,0x74,0x38,0x73,0x8d,0x16,0x0d,0x6f,0xae,0x59,0x33,0x4e,0x24,0xe9,0x52,0xf6,
51 0x6f,0x8c,0x5c,0x13,0xcf,0x1d,0x0a,0xcc,0xb7,0x6a,0x88,0xce,0x91,0xe2,0xe0,0xcb,
52 0xc6,0xd2,0xfb,0x81,0xf6,0xd2,0x9f,0x0a,0x82,0x70,0x80,0xbf,0x93,0x70,0xc0,0x57,
53 0x23,0x6e,0x97,0x1c,0x9d,0x7d,0xf0,0xa3,0x54,0x86,0xec,0x40,0xae,0x09,0x20,0xed,
54 0x02,0x43,0xa3,0xf8,0x7e,0x0e,0x5b,0xd0,0x22,0x7b,0x74,0x39,0x02,0x03,0x01,0x00,
55 0x01,0x02,0x82,0x01,0x01,0x00,0xd9,0x5b,0x99,0x74,0x80,0xb4,0x57,0xcc,0x82,0x2a,
56 0x17,0x66,0x1d,0x3c,0xde,0xea,0xbd,0x11,0x40,0x03,0x62,0x47,0xe3,0xe5,0x2c,0x6b,
57 0x65,0x67,0x0f,0x0b,0x96,0x13,0x83,0x4c,0x71,0x58,0xfa,0xfe,0xe6,0xe9,0x37,0xeb,
58 0x98,0x51,0x73,0x48,0xcc,0xf9,0xe1,0x46,0x5b,0xfe,0x16,0xe1,0xc0,0xa5,0x75,0xf3,
59 0x4d,0x30,0x84,0x14,0x15,0x04,0x6f,0x3e,0xa3,0x03,0xbd,0xba,0x4f,0x5a,0x71,0xe9,
60 0x26,0xbf,0x5d,0x7a,0x93,0x22,0x98,0xb5,0xcf,0x51,0xc3,0xc7,0x51,0xb8,0x59,0x0a,
61 0xfb,0xd7,0xe5,0xa8,0x1d,0x0f,0x5c,0xfd,0x30,0x0e,0x71,0xd7,0x79,0xc4,0x60,0x55,
62 0x9e,0x1e,0x1c,0x0b,0x9a,0x40,0xb8,0x7a,0x8d,0xb2,0xec,0xb0,0x70,0x8a,0x19,0x5f,
63 0x1d,0x2e,0xde,0x90,0x8f,0x68,0x56,0x08,0xce,0x0c,0x08,0xde,0xc7,0xf8,0x13,0xef,
64 0xd2,0xbc,0x92,0xb6,0xfb,0xec,0xb6,0x04,0xf6,0x8f,0x7d,0x95,0xe9,0xeb,0xc7,0xfb,
65 0xcc,0x4f,0xad,0x41,0xf1,0x4c,0x79,0x07,0xdd,0x4b,0x40,0xb4,0x74,0x44,0x9a,0x06,
66 0x0a,0x0f,0xb2,0xda,0x12,0x46,0xe5,0xee,0x01,0x64,0xe5,0xf0,0x82,0x69,0xf9,0xf1,
67 0xe9,0x41,0x13,0x5a,0xee,0xc0,0x37,0x9a,0xbe,0x9a,0x9a,0x06,0x4b,0x52,0xd6,0xf3,
68 0x1b,0x30,0x64,0x93,0x3a,0x97,0xe1,0xdc,0x50,0x1f,0x46,0xc4,0x81,0x6a,0x17,0x52,
69 0x49,0x85,0xc6,0x85,0xb7,0x60,0xd4,0xf0,0xd1,0x6a,0xeb,0x50,0x8c,0xb7,0xeb,0x1f,
70 0x17,0x0e,0xf0,0xfd,0x67,0x03,0x7c,0x74,0x1a,0xac,0x66,0x81,0x00,0x45,0x5e,0xf3,
71 0xd9,0x9d,0x22,0x99,0xc4,0x11,0x02,0x81,0x81,0x00,0xfa,0x44,0x32,0x14,0xb2,0x82,
72 0x28,0x02,0x46,0x05,0xdd,0x8d,0xb1,0x9f,0x9e,0x6f,0x61,0xf2,0x01,0xa0,0x2b,0x76,
73 0xee,0x46,0xaa,0x2d,0x2d,0x5b,0xd2,0x67,0x90,0x36,0xbb,0xa0,0x07,0xdf,0x9b,0xad,
74 0x18,0x1e,0xa7,0xe6,0x36,0xc6,0x49,0xda,0xc5,0x0d,0x52,0x29,0x5a,0x40,0xcf,0xdf,
75 0x8d,0xd0,0xa3,0xc2,0x34,0x17,0x9f,0xb5,0xf1,0x67,0xac,0x29,0x10,0xc2,0x5c,0x62,
76 0xe3,0xe2,0x5c,0x9f,0x93,0xcc,0xb5,0xeb,0x16,0x64,0x44,0x9f,0x6b,0x5a,0xac,0x19,
77 0x09,0xff,0x4b,0x78,0x7f,0xec,0x5a,0xbd,0xe9,0xcb,0x74,0xbb,0x30,0x13,0xc5,0x25,
78 0x8b,0xac,0x8d,0xf9,0xa9,0x99,0x25,0xf5,0xce,0x07,0xb6,0x2b,0x1b,0x42,0xed,0x3a,
79 0x30,0x4a,0xfc,0x5f,0xf0,0xe2,0x26,0xa6,0x60,0x5d,0x02,0x81,0x81,0x00,0xf4,0x1a,
80 0xc2,0x7e,0xa0,0xa0,0xad,0x20,0x65,0x04,0xe8,0xf7,0xb0,0xb1,0x76,0x79,0x08,0x18,
81 0x58,0x93,0x21,0xf1,0x56,0x58,0x58,0x18,0x4a,0x5c,0x59,0x08,0x27,0x64,0x09,0xcb,
82 0x0b,0x0b,0x4e,0x26,0xc8,0x0b,0x87,0x67,0x40,0xc1,0xab,0x31,0x60,0xa6,0x78,0xdd,
83 0x78,0xc8,0x86,0x38,0xbd,0x19,0xde,0x0b,0x70,0x72,0xec,0x36,0x88,0x39,0x69,0x70,
84 0xda,0xa6,0x2e,0xf9,0x5c,0xd8,0x17,0xc5,0xfa,0xf8,0xa5,0xc9,0x9b,0xf0,0xfe,0x03,
85 0x71,0x57,0xfa,0x58,0x0f,0x33,0xc3,0xab,0xce,0xb0,0x5d,0xd0,0x40,0x07,0x9a,0x0b,
86 0xff,0xb9,0xaa,0x9d,0xc5,0x33,0x7f,0x5f,0x48,0x7e,0x54,0x82,0xd1,0xdf,0x75,0x69,
87 0xee,0xe5,0xf5,0x80,0x44,0xce,0x52,0x72,0x14,0x2c,0xe6,0xa7,0xd5,0x8d,0x02,0x81,
88 0x81,0x00,0xb8,0xf7,0x70,0x20,0x35,0xf2,0xd6,0x89,0x1f,0xa1,0xb4,0x26,0xc6,0x51,
89 0xd7,0xb2,0x30,0xac,0xc1,0xa0,0xd4,0x9e,0xf8,0xea,0x87,0x5a,0x0e,0x7d,0x1f,0xdb,
90 0xe5,0x0d,0x5e,0xcc,0x9f,0x25,0x18,0x14,0xed,0x8f,0xb2,0xbe,0x06,0x5b,0xb5,0x38,
91 0x18,0x8d,0x88,0xdd,0x01,0x54,0x87,0x8e,0x8d,0x6c,0xd7,0xab,0x6f,0xfe,0xc9,0xce,
92 0x9a,0x15,0xea,0x7b,0x0b,0x64,0xeb,0x0d,0x37,0xaa,0x14,0x94,0xe8,0x92,0xd3,0x1d,
93 0x66,0x16,0x43,0x55,0xa3,0xed,0x86,0xe6,0x96,0xa9,0xf5,0xe8,0xa0,0x7b,0x5a,0x71,
94 0xa4,0x7a,0xf7,0xd2,0x65,0x6d,0x27,0x37,0x61,0xac,0xed,0xdd,0xc9,0x08,0x64,0xb2,
95 0xf0,0x4c,0x68,0xca,0x21,0x42,0xec,0xbc,0x25,0xf7,0x35,0xe1,0xde,0xd1,0xf6,0x88,
96 0xdf,0x0d,0x02,0x81,0x80,0x44,0xb0,0xcb,0x0e,0x6b,0x11,0x0b,0xe6,0xd3,0xc6,0x7f,
97 0xf0,0x43,0x6e,0x8c,0xd2,0x1e,0x2f,0x0b,0xad,0xcb,0x9d,0x68,0x18,0xd0,0x21,0x75,
98 0xbb,0x6a,0xea,0x5a,0x7b,0x52,0x2e,0x2a,0xdb,0x71,0x90,0x84,0x36,0x8a,0x51,0xc9,
99 0xed,0x35,0xc9,0x5d,0x53,0x3b,0x2b,0xc7,0x73,0x56,0x21,0xdd,0x44,0xcc,0x31,0x17,
100 0xe1,0x9f,0x0a,0xf1,0x66,0x86,0x7f,0x55,0x67,0xf2,0x4c,0x05,0x8e,0x61,0x92,0x3a,
101 0xbf,0x81,0x97,0xac,0x24,0x32,0xb6,0xb1,0x4c,0x7a,0x8c,0x11,0x2b,0x15,0xe2,0xe0,
102 0xf4,0xcc,0x51,0x6f,0xd3,0x33,0xcc,0x30,0x98,0x04,0xa5,0x04,0xfb,0x2a,0xda,0x9b,
103 0x41,0xc1,0x72,0x56,0xb0,0xb5,0x0f,0xac,0x44,0x55,0xc3,0x54,0x99,0x62,0xa5,0xeb,
104 0x7b,0x7f,0x24,0xb7,0x79,0x02,0x81,0x80,0x0a,0x3b,0x9b,0x91,0x1d,0x9b,0x04,0x4e,
105 0xdf,0xd9,0xe6,0x47,0xf3,0x79,0xb7,0x17,0xcf,0x42,0xa5,0xde,0x94,0xf0,0xfe,0xed,
106 0x46,0xf6,0xaf,0x3e,0x6c,0x91,0x01,0x89,0x79,0x81,0xea,0x2b,0x82,0x68,0x0e,0xd8,
107 0x25,0xaf,0x79,0x8b,0x14,0xfd,0xf2,0x29,0x20,0x34,0x2d,0x0b,0x08,0x8c,0x3b,0x2b,
108 0xfc,0x75,0xe9,0x4e,0x21,0xa6,0xb2,0x35,0x67,0x8d,0x4c,0x90,0x94,0x02,0xd5,0x32,
109 0x23,0xc6,0xa0,0x92,0x2e,0xfa,0x97,0x48,0x5b,0x95,0xc3,0xf1,0xbc,0x6b,0xe8,0x4c,
110 0x92,0x6f,0x5e,0x3d,0xf9,0xbd,0x2c,0xf0,0x83,0x1c,0xe6,0xb3,0x45,0x68,0x32,0x8d,
111 0x85,0x20,0xcb,0x9d,0xd2,0x30,0x5a,0x57,0xa4,0x6e,0x27,0xb5,0x29,0x14,0xdb,0xf1,
112 0x4b,0x9a,0xc3,0xc1,0xc5,0x37,0x6d,0x1b,
113 };
114
115 /**
116 * ECDSA private key
117 */
118 static char ecdsa[] = {
119 0x30,0x81,0xa4,0x02,0x01,0x01,0x04,0x30,0xc0,0x1f,0xfd,0x65,0xc6,0xc4,0x4c,0xb8,
120 0xff,0x56,0x08,0xb5,0xbd,0xb8,0xf5,0x93,0xf7,0x51,0x0e,0x92,0x1f,0x06,0xbf,0xa6,
121 0xd9,0x1d,0xae,0xa3,0x16,0x0d,0x0f,0xc9,0xd5,0x97,0x90,0x46,0xf1,0x98,0xa8,0x18,
122 0x07,0xba,0xcf,0x91,0x8e,0x07,0xed,0x88,0xa0,0x07,0x06,0x05,0x2b,0x81,0x04,0x00,
123 0x22,0xa1,0x64,0x03,0x62,0x00,0x04,0xd6,0xba,0xe1,0xf0,0x09,0x22,0x21,0x12,0x69,
124 0xed,0x0e,0xd5,0x02,0x8c,0xb8,0x52,0xbb,0x57,0x68,0x0e,0xf3,0xdb,0xb9,0xb1,0xee,
125 0x9c,0x67,0xa0,0xb8,0xdc,0x13,0x1e,0x5b,0x44,0x71,0x04,0xef,0x4e,0xe3,0xdd,0xf4,
126 0xa6,0xc3,0xba,0x77,0x53,0xb8,0x28,0x5f,0xd2,0x97,0x05,0xa3,0x5b,0xe6,0xde,0x0a,
127 0xce,0x11,0xa8,0xaf,0x02,0xbd,0xfa,0x17,0xf9,0xa7,0x38,0x3e,0x5b,0x57,0xb0,0x01,
128 0xb3,0xc6,0x09,0x29,0x65,0xae,0xfb,0x87,0x92,0xa3,0xd7,0x3d,0x9a,0x1c,0x52,0x09,
129 0xb1,0x47,0xc8,0xf6,0x18,0xbb,0x97,
130 };
131
132 /**
133 * Ed25519 private key
134 * pki --gen --type ed25519
135 */
136 static char ed25519[] = {
137 0x30,0x2e,0x02,0x01,0x00,0x30,0x05,0x06,0x03,0x2b,0x65,0x70,0x04,0x22,0x04,0x20,
138 0x70,0x4b,0xca,0x70,0x1c,0xb1,0x75,0xf1,0xed,0xde,0xf1,0x99,0x8e,0x11,0x32,0x2d,
139 0x76,0x41,0x01,0x6c,0xd7,0xbc,0x79,0xa2,0x06,0x15,0x7e,0x44,0x28,0xf2,0x49,0x61,
140 };
141
142 /**
143 * Ed448 private key
144 * pki --gen --type ed448
145 */
146 static char ed448[] = {
147 0x30,0x47,0x02,0x01,0x00,0x30,0x05,0x06,0x03,0x2b,0x65,0x71,0x04,0x3b,0x04,0x39,
148 0xcf,0xb9,0xbe,0x75,0xdf,0x76,0x8b,0x9a,0xdf,0x56,0x52,0x5d,0x37,0x7d,0xb0,0xa8,
149 0x1f,0x19,0x44,0x30,0xbd,0x9d,0x0e,0xff,0x5f,0xc8,0xc3,0xec,0x60,0xd5,0xf6,0xa4,
150 0x3d,0x1f,0x0e,0xb5,0x65,0x6e,0xe6,0x62,0x4d,0xb7,0xe7,0x5c,0x88,0x7b,0xe8,0xdd,
151 0x02,0xd9,0x0f,0xaa,0xe7,0xfb,0x05,0x14,0x41,
152 };
153
154 /**
155 * TLS certificate for RSA key
156 * pki --self --in rsa.key --dn "C=CH, O=strongSwan, CN=tls-rsa" --san 127.0.0.1
157 */
158 static char rsa_crt[] = {
159 0x30,0x82,0x02,0xfd,0x30,0x82,0x01,0xe5,0xa0,0x03,0x02,0x01,0x02,0x02,0x08,0x78,
160 0x90,0x39,0xe2,0x1c,0x03,0x1f,0x05,0x30,0x0d,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,
161 0x0d,0x01,0x01,0x0b,0x05,0x00,0x30,0x34,0x31,0x0b,0x30,0x09,0x06,0x03,0x55,0x04,
162 0x06,0x13,0x02,0x43,0x48,0x31,0x13,0x30,0x11,0x06,0x03,0x55,0x04,0x0a,0x13,0x0a,
163 0x73,0x74,0x72,0x6f,0x6e,0x67,0x53,0x77,0x61,0x6e,0x31,0x10,0x30,0x0e,0x06,0x03,
164 0x55,0x04,0x03,0x13,0x07,0x74,0x6c,0x73,0x2d,0x72,0x73,0x61,0x30,0x1e,0x17,0x0d,
165 0x32,0x30,0x30,0x33,0x32,0x35,0x31,0x34,0x32,0x39,0x32,0x37,0x5a,0x17,0x0d,0x32,
166 0x33,0x30,0x33,0x32,0x35,0x31,0x34,0x32,0x39,0x32,0x37,0x5a,0x30,0x34,0x31,0x0b,
167 0x30,0x09,0x06,0x03,0x55,0x04,0x06,0x13,0x02,0x43,0x48,0x31,0x13,0x30,0x11,0x06,
168 0x03,0x55,0x04,0x0a,0x13,0x0a,0x73,0x74,0x72,0x6f,0x6e,0x67,0x53,0x77,0x61,0x6e,
169 0x31,0x10,0x30,0x0e,0x06,0x03,0x55,0x04,0x03,0x13,0x07,0x74,0x6c,0x73,0x2d,0x72,
170 0x73,0x61,0x30,0x82,0x01,0x22,0x30,0x0d,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,
171 0x01,0x01,0x01,0x05,0x00,0x03,0x82,0x01,0x0f,0x00,0x30,0x82,0x01,0x0a,0x02,0x82,
172 0x01,0x01,0x00,0xee,0xa3,0x28,0xcc,0x48,0xca,0x37,0xfc,0xb6,0xfa,0xfc,0x18,0x0d,
173 0xa2,0x28,0x44,0xb4,0x16,0x56,0xf7,0x97,0x5f,0x38,0x83,0xfc,0xd4,0x30,0xea,0xf7,
174 0x5e,0xaa,0xd4,0x21,0x0e,0x71,0x49,0x13,0x39,0xaf,0x89,0xa1,0x1d,0x1b,0x9a,0x08,
175 0x44,0xff,0x0b,0xeb,0x4b,0xad,0x8e,0xc4,0x6d,0x1e,0x0c,0x02,0xbb,0x17,0x59,0xc7,
176 0x66,0xc7,0xff,0x4c,0x3c,0x11,0x40,0x1a,0xe3,0xca,0x34,0xf8,0x41,0xe0,0x39,0x3e,
177 0xce,0x72,0x9f,0x56,0x9e,0x69,0xad,0x98,0x43,0x5f,0x35,0xc2,0xd0,0xd9,0xbc,0x8b,
178 0xed,0xc6,0xc7,0x74,0x73,0x74,0x30,0x92,0x86,0x39,0x26,0x3d,0xf1,0xd5,0x16,0x45,
179 0x7d,0xcc,0x90,0x54,0xff,0x44,0x74,0xf3,0xba,0x41,0x5c,0x58,0xa4,0x66,0xe6,0x9d,
180 0x58,0xbe,0x7e,0x89,0xe1,0x7c,0xf7,0x28,0xb0,0xde,0xe2,0x01,0x0a,0x89,0xc7,0x63,
181 0x3f,0xef,0x2b,0xcb,0xef,0x65,0x89,0x82,0x23,0x32,0xa7,0xa3,0x1c,0x0d,0xc6,0x8f,
182 0x76,0x59,0x8b,0x55,0x65,0x9c,0x91,0xd4,0x93,0x89,0xad,0x37,0x47,0x23,0x25,0xb3,
183 0x53,0xea,0xef,0x73,0xeb,0x97,0xd3,0xd7,0x74,0x38,0x73,0x8d,0x16,0x0d,0x6f,0xae,
184 0x59,0x33,0x4e,0x24,0xe9,0x52,0xf6,0x6f,0x8c,0x5c,0x13,0xcf,0x1d,0x0a,0xcc,0xb7,
185 0x6a,0x88,0xce,0x91,0xe2,0xe0,0xcb,0xc6,0xd2,0xfb,0x81,0xf6,0xd2,0x9f,0x0a,0x82,
186 0x70,0x80,0xbf,0x93,0x70,0xc0,0x57,0x23,0x6e,0x97,0x1c,0x9d,0x7d,0xf0,0xa3,0x54,
187 0x86,0xec,0x40,0xae,0x09,0x20,0xed,0x02,0x43,0xa3,0xf8,0x7e,0x0e,0x5b,0xd0,0x22,
188 0x7b,0x74,0x39,0x02,0x03,0x01,0x00,0x01,0xa3,0x13,0x30,0x11,0x30,0x0f,0x06,0x03,
189 0x55,0x1d,0x11,0x04,0x08,0x30,0x06,0x87,0x04,0x7f,0x00,0x00,0x01,0x30,0x0d,0x06,
190 0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x0b,0x05,0x00,0x03,0x82,0x01,0x01,
191 0x00,0x97,0xfb,0x1e,0xd8,0x78,0x65,0x65,0x23,0x15,0xf9,0x8a,0xcc,0x98,0x37,0x30,
192 0x05,0x34,0x76,0x6a,0x23,0x11,0x40,0x89,0x9f,0x26,0x33,0xd5,0x00,0xa9,0xf2,0x78,
193 0x42,0x99,0xa7,0xbd,0xda,0x31,0xa1,0xcd,0x56,0x46,0xfe,0xd1,0xa3,0x9c,0x86,0xfa,
194 0x0b,0x76,0xb2,0x13,0x8f,0x83,0x96,0x00,0x5a,0xa0,0xc5,0x63,0x72,0xd5,0xf8,0xbe,
195 0x61,0x57,0x3e,0xd4,0xaa,0x8c,0x87,0xdf,0x27,0xf3,0x6f,0xbe,0xbe,0x3c,0x50,0xa1,
196 0x7a,0x00,0xbd,0x0e,0x16,0x1a,0x1f,0xde,0xd9,0xf7,0x76,0xdd,0xc9,0xa9,0xff,0x82,
197 0xf7,0x59,0x03,0x2b,0x6e,0x19,0x7c,0xac,0x6d,0x29,0xe6,0xc8,0x83,0x35,0x91,0x04,
198 0xf2,0x6a,0x9b,0x3c,0x54,0xda,0x83,0x72,0x80,0x07,0xc3,0x8e,0x4c,0x1c,0x09,0xbf,
199 0x41,0x34,0xec,0xa1,0xac,0xc3,0xac,0x71,0x5d,0x64,0x1e,0x60,0x4b,0x98,0xaa,0x1f,
200 0x0c,0x7f,0x6d,0xf2,0xe1,0x56,0x28,0x48,0xf0,0xfd,0xe4,0xb0,0xb6,0xad,0xf3,0x49,
201 0x76,0x6b,0x23,0x35,0x73,0x38,0xd6,0x1c,0x6d,0x73,0xd4,0x0c,0x8e,0x1a,0x15,0x75,
202 0x90,0x76,0xee,0xe1,0x2d,0x90,0xf6,0x1a,0x49,0xb4,0x19,0xda,0xcd,0x89,0xd6,0x8d,
203 0x27,0xb0,0xeb,0x79,0x4e,0x9f,0xec,0xda,0xbf,0x27,0x84,0xf0,0xd5,0x5b,0xef,0x0b,
204 0xea,0xec,0x35,0x99,0x9b,0x39,0xe7,0x43,0x24,0xc6,0x71,0x4c,0xf8,0x6f,0x7a,0xc9,
205 0x4a,0x2e,0xbb,0x96,0x77,0x05,0xe3,0xb3,0xcf,0x1f,0x80,0xbe,0xd1,0xed,0xde,0x85,
206 0xaf,0xb4,0xe3,0x63,0x63,0xdc,0x70,0x4e,0x1e,0x0e,0x9a,0x10,0x2d,0xe5,0x86,0x6e,
207 0xbd,
208 };
209
210 /**
211 * TLS certificate for ECDSA key
212 * pki --self --in ecdsa.key --dn "C=CH, O=strongSwan, CN=tls-ecdsa" --san 127.0.0.1
213 */
214 static char ecdsa_crt[] = {
215 0x30,0x82,0x01,0xb1,0x30,0x82,0x01,0x38,0xa0,0x03,0x02,0x01,0x02,0x02,0x08,0x77,
216 0x8f,0x61,0x26,0xa2,0xae,0xe8,0x6c,0x30,0x0a,0x06,0x08,0x2a,0x86,0x48,0xce,0x3d,
217 0x04,0x03,0x03,0x30,0x36,0x31,0x0b,0x30,0x09,0x06,0x03,0x55,0x04,0x06,0x13,0x02,
218 0x43,0x48,0x31,0x13,0x30,0x11,0x06,0x03,0x55,0x04,0x0a,0x13,0x0a,0x73,0x74,0x72,
219 0x6f,0x6e,0x67,0x53,0x77,0x61,0x6e,0x31,0x12,0x30,0x10,0x06,0x03,0x55,0x04,0x03,
220 0x13,0x09,0x74,0x6c,0x73,0x2d,0x65,0x63,0x64,0x73,0x61,0x30,0x1e,0x17,0x0d,0x32,
221 0x30,0x30,0x33,0x32,0x35,0x31,0x34,0x33,0x30,0x32,0x34,0x5a,0x17,0x0d,0x32,0x33,
222 0x30,0x33,0x32,0x35,0x31,0x34,0x33,0x30,0x32,0x34,0x5a,0x30,0x36,0x31,0x0b,0x30,
223 0x09,0x06,0x03,0x55,0x04,0x06,0x13,0x02,0x43,0x48,0x31,0x13,0x30,0x11,0x06,0x03,
224 0x55,0x04,0x0a,0x13,0x0a,0x73,0x74,0x72,0x6f,0x6e,0x67,0x53,0x77,0x61,0x6e,0x31,
225 0x12,0x30,0x10,0x06,0x03,0x55,0x04,0x03,0x13,0x09,0x74,0x6c,0x73,0x2d,0x65,0x63,
226 0x64,0x73,0x61,0x30,0x76,0x30,0x10,0x06,0x07,0x2a,0x86,0x48,0xce,0x3d,0x02,0x01,
227 0x06,0x05,0x2b,0x81,0x04,0x00,0x22,0x03,0x62,0x00,0x04,0xd6,0xba,0xe1,0xf0,0x09,
228 0x22,0x21,0x12,0x69,0xed,0x0e,0xd5,0x02,0x8c,0xb8,0x52,0xbb,0x57,0x68,0x0e,0xf3,
229 0xdb,0xb9,0xb1,0xee,0x9c,0x67,0xa0,0xb8,0xdc,0x13,0x1e,0x5b,0x44,0x71,0x04,0xef,
230 0x4e,0xe3,0xdd,0xf4,0xa6,0xc3,0xba,0x77,0x53,0xb8,0x28,0x5f,0xd2,0x97,0x05,0xa3,
231 0x5b,0xe6,0xde,0x0a,0xce,0x11,0xa8,0xaf,0x02,0xbd,0xfa,0x17,0xf9,0xa7,0x38,0x3e,
232 0x5b,0x57,0xb0,0x01,0xb3,0xc6,0x09,0x29,0x65,0xae,0xfb,0x87,0x92,0xa3,0xd7,0x3d,
233 0x9a,0x1c,0x52,0x09,0xb1,0x47,0xc8,0xf6,0x18,0xbb,0x97,0xa3,0x13,0x30,0x11,0x30,
234 0x0f,0x06,0x03,0x55,0x1d,0x11,0x04,0x08,0x30,0x06,0x87,0x04,0x7f,0x00,0x00,0x01,
235 0x30,0x0a,0x06,0x08,0x2a,0x86,0x48,0xce,0x3d,0x04,0x03,0x03,0x03,0x67,0x00,0x30,
236 0x64,0x02,0x30,0x68,0x6e,0x8e,0x65,0x7c,0x84,0x33,0x82,0x2c,0x2e,0xca,0x17,0xe5,
237 0x68,0xf7,0xbd,0x4b,0x6a,0xa2,0xa6,0xc3,0x40,0x21,0x4c,0xf0,0x00,0xd5,0xf7,0xfe,
238 0x87,0x54,0xe3,0x2a,0x6f,0xce,0x46,0xf0,0x2e,0x9e,0x22,0xc3,0x73,0x47,0xf4,0xce,
239 0x9b,0x03,0x0b,0x02,0x30,0x01,0x62,0x4c,0x6f,0x90,0x62,0x50,0x3b,0xe5,0x3f,0xdf,
240 0x70,0x70,0xf6,0x81,0xad,0x25,0x2f,0x99,0x2e,0x69,0x8a,0x47,0xcf,0x14,0x31,0x27,
241 0x1b,0x52,0xf4,0x91,0x78,0x0f,0x29,0x5b,0x33,0xca,0xb2,0x0c,0x45,0xee,0xc2,0x83,
242 0xac,0x36,0x08,0x14,0x29,
243 };
244
245 /**
246 * TLS certificate for Ed25519 key
247 * pki --self --in ed25519.key --dn "C=CH, O=strongSwan, CN=tls-ed25519" \
248 * --san 127.0.0.1
249 */
250 static char ed25519_crt[] = {
251 0x30,0x82,0x01,0x38,0x30,0x81,0xeb,0xa0,0x03,0x02,0x01,0x02,0x02,0x08,0x46,0x41,
252 0x12,0x0d,0xa4,0xbd,0x00,0x11,0x30,0x05,0x06,0x03,0x2b,0x65,0x70,0x30,0x38,0x31,
253 0x0b,0x30,0x09,0x06,0x03,0x55,0x04,0x06,0x13,0x02,0x43,0x48,0x31,0x13,0x30,0x11,
254 0x06,0x03,0x55,0x04,0x0a,0x13,0x0a,0x73,0x74,0x72,0x6f,0x6e,0x67,0x53,0x77,0x61,
255 0x6e,0x31,0x14,0x30,0x12,0x06,0x03,0x55,0x04,0x03,0x13,0x0b,0x74,0x6c,0x73,0x2d,
256 0x65,0x64,0x32,0x35,0x35,0x31,0x39,0x30,0x1e,0x17,0x0d,0x32,0x30,0x31,0x30,0x32,
257 0x32,0x31,0x34,0x30,0x31,0x30,0x30,0x5a,0x17,0x0d,0x32,0x33,0x31,0x30,0x32,0x32,
258 0x31,0x34,0x30,0x31,0x30,0x30,0x5a,0x30,0x38,0x31,0x0b,0x30,0x09,0x06,0x03,0x55,
259 0x04,0x06,0x13,0x02,0x43,0x48,0x31,0x13,0x30,0x11,0x06,0x03,0x55,0x04,0x0a,0x13,
260 0x0a,0x73,0x74,0x72,0x6f,0x6e,0x67,0x53,0x77,0x61,0x6e,0x31,0x14,0x30,0x12,0x06,
261 0x03,0x55,0x04,0x03,0x13,0x0b,0x74,0x6c,0x73,0x2d,0x65,0x64,0x32,0x35,0x35,0x31,
262 0x39,0x30,0x2a,0x30,0x05,0x06,0x03,0x2b,0x65,0x70,0x03,0x21,0x00,0xbd,0xbd,0xd2,
263 0x9d,0x90,0x2c,0x4f,0xb0,0x0d,0x88,0xe9,0x92,0xba,0x59,0x91,0x6c,0x0a,0x30,0xc3,
264 0x8e,0x7d,0x0d,0x55,0x67,0xf7,0xb0,0x37,0x39,0xfa,0x05,0x61,0xc3,0xa3,0x13,0x30,
265 0x11,0x30,0x0f,0x06,0x03,0x55,0x1d,0x11,0x04,0x08,0x30,0x06,0x87,0x04,0x7f,0x00,
266 0x00,0x01,0x30,0x05,0x06,0x03,0x2b,0x65,0x70,0x03,0x41,0x00,0x04,0xc6,0x12,0x57,
267 0xfa,0x69,0x74,0xd2,0x3a,0x7d,0x1b,0x23,0xde,0x64,0x08,0xa8,0x05,0x75,0xd3,0x15,
268 0xfb,0xd4,0x46,0xe0,0x4a,0x59,0x48,0x8e,0xee,0x4e,0x4d,0x72,0xbf,0xbc,0xdb,0x36,
269 0xda,0x39,0x23,0x9a,0x06,0x88,0xee,0x63,0xe5,0xb4,0x23,0xf9,0xa9,0x80,0x41,0x99,
270 0x3d,0x3f,0xb5,0x39,0x72,0x4b,0x62,0x86,0x4e,0x85,0x61,0x0b,
271 };
272
273 /**
274 * TLS certificate for Ed448 key
275 * pki --self --in ed448.key --dn "C=CH, O=strongSwan, CN=tls-ed448" \
276 * --san 127.0.0.1
277 */
278 static char ed448_crt[] = {
279 0x30,0x82,0x01,0x80,0x30,0x82,0x01,0x00,0xa0,0x03,0x02,0x01,0x02,0x02,0x08,0x71,
280 0xa9,0xa0,0xdd,0x5b,0xee,0xa0,0x5c,0x30,0x05,0x06,0x03,0x2b,0x65,0x71,0x30,0x36,
281 0x31,0x0b,0x30,0x09,0x06,0x03,0x55,0x04,0x06,0x13,0x02,0x43,0x48,0x31,0x13,0x30,
282 0x11,0x06,0x03,0x55,0x04,0x0a,0x13,0x0a,0x73,0x74,0x72,0x6f,0x6e,0x67,0x53,0x77,
283 0x61,0x6e,0x31,0x12,0x30,0x10,0x06,0x03,0x55,0x04,0x03,0x13,0x09,0x74,0x6c,0x73,
284 0x2d,0x65,0x64,0x34,0x34,0x38,0x30,0x1e,0x17,0x0d,0x32,0x30,0x31,0x30,0x32,0x33,
285 0x32,0x30,0x34,0x34,0x30,0x35,0x5a,0x17,0x0d,0x32,0x33,0x31,0x30,0x32,0x33,0x32,
286 0x30,0x34,0x34,0x30,0x35,0x5a,0x30,0x36,0x31,0x0b,0x30,0x09,0x06,0x03,0x55,0x04,
287 0x06,0x13,0x02,0x43,0x48,0x31,0x13,0x30,0x11,0x06,0x03,0x55,0x04,0x0a,0x13,0x0a,
288 0x73,0x74,0x72,0x6f,0x6e,0x67,0x53,0x77,0x61,0x6e,0x31,0x12,0x30,0x10,0x06,0x03,
289 0x55,0x04,0x03,0x13,0x09,0x74,0x6c,0x73,0x2d,0x65,0x64,0x34,0x34,0x38,0x30,0x43,
290 0x30,0x05,0x06,0x03,0x2b,0x65,0x71,0x03,0x3a,0x00,0xdd,0x5e,0x19,0xc8,0x67,0xa9,
291 0x93,0x53,0x5f,0x26,0xca,0x6f,0x2f,0xdf,0x9e,0x0f,0x48,0xb6,0x60,0x3e,0x56,0xa5,
292 0xaf,0xe8,0xf9,0x3f,0xe5,0x1c,0xeb,0xf2,0xf4,0x84,0xd1,0x48,0xa9,0xb1,0x92,0x6b,
293 0xa1,0x4d,0x47,0x86,0x8e,0xf9,0xcc,0xd2,0x58,0xd4,0x6f,0x8c,0x76,0x59,0xf4,0x77,
294 0x59,0xc8,0x00,0xa3,0x13,0x30,0x11,0x30,0x0f,0x06,0x03,0x55,0x1d,0x11,0x04,0x08,
295 0x30,0x06,0x87,0x04,0x7f,0x00,0x00,0x01,0x30,0x05,0x06,0x03,0x2b,0x65,0x71,0x03,
296 0x73,0x00,0xc6,0xf0,0x4e,0xf2,0x41,0xe0,0xb4,0xa0,0x0a,0x9f,0x73,0x67,0xcb,0x89,
297 0x97,0xf0,0x3a,0xfe,0x53,0xb2,0x1b,0x6c,0x37,0x24,0xbe,0x9e,0x2b,0x50,0x0c,0x98,
298 0xb3,0x15,0x65,0x79,0x37,0xd6,0xc2,0x92,0x89,0x96,0xf3,0x5f,0x2d,0x70,0xa5,0x49,
299 0xdd,0x7d,0x12,0x3d,0x17,0x28,0xd2,0x56,0x25,0xab,0x80,0x89,0x4d,0x6a,0xfa,0x32,
300 0x6a,0x16,0x7f,0xd2,0x12,0xb3,0x73,0xf5,0xe7,0x1f,0x89,0x0b,0x5e,0x05,0xbe,0x69,
301 0xb8,0x11,0x59,0xf9,0xdc,0x9c,0xca,0x68,0xe3,0x1f,0x7a,0x43,0x1a,0x72,0xfa,0x1f,
302 0x07,0xe0,0x58,0xc2,0x3a,0x18,0xb3,0x01,0x68,0x90,0x40,0x05,0x7d,0x35,0x1a,0x3f,
303 0xdc,0xc8,0x00,0x00
304 };
305
306 static void setup_credentials(chunk_t key_data, chunk_t cert_data)
307 {
308 private_key_t *key;
309 certificate_t *cert;
310
311 creds = mem_cred_create();
312
313 key = lib->creds->create(lib->creds, CRED_PRIVATE_KEY, KEY_RSA,
314 BUILD_BLOB, chunk_from_thing(rsa), BUILD_END);
315 if (key)
316 {
317 creds->add_key(creds, key);
318 }
319 key = lib->creds->create(lib->creds, CRED_PRIVATE_KEY, KEY_ANY,
320 BUILD_BLOB, key_data, BUILD_END);
321 if (key)
322 {
323 creds->add_key(creds, key);
324 }
325 cert = lib->creds->create(lib->creds, CRED_CERTIFICATE, CERT_X509,
326 BUILD_BLOB, chunk_from_thing(rsa_crt), BUILD_END);
327 if (cert)
328 {
329 creds->add_cert(creds, TRUE, cert);
330 }
331 cert = lib->creds->create(lib->creds, CRED_CERTIFICATE, CERT_X509,
332 BUILD_BLOB, cert_data, BUILD_END);
333 if (cert)
334 {
335 creds->add_cert(creds, TRUE, cert);
336 }
337
338 lib->credmgr->add_set(lib->credmgr, &creds->set);
339 }
340
341 START_SETUP(setup_creds)
342 {
343 setup_credentials(chunk_from_thing(ecdsa), chunk_from_thing(ecdsa_crt));
344 }
345 END_SETUP
346
347 START_SETUP(setup_ed25519_creds)
348 {
349 setup_credentials(chunk_from_thing(ed25519), chunk_from_thing(ed25519_crt));
350 }
351 END_SETUP
352
353 START_SETUP(setup_ed448_creds)
354 {
355 setup_credentials(chunk_from_thing(ed448), chunk_from_thing(ed448_crt));
356 }
357 END_SETUP
358
359 START_TEARDOWN(teardown_creds)
360 {
361 lib->credmgr->remove_set(lib->credmgr, &creds->set);
362 creds->destroy(creds);
363 }
364 END_TEARDOWN
365
366 /**
367 * Configuration for an echo server
368 */
369 typedef struct {
370 tls_version_t version;
371 uint16_t port;
372 char *addr;
373 chunk_t data;
374 int fd;
375 bool cauth;
376 } echo_server_config_t;
377
378 /**
379 * Run an echo server
380 */
381 static job_requeue_t serve_echo(echo_server_config_t *config)
382 {
383 tls_socket_t *tls;
384 int sfd, cfd;
385 identification_t *server, *client = NULL;
386 ssize_t len, total, done;
387 char buf[128];
388
389 server = identification_create_from_string(config->addr);
390 if (config->cauth)
391 {
392 client = server;
393 }
394 sfd = config->fd;
395 while (TRUE)
396 {
397 cfd = accept(sfd, NULL, NULL);
398 if (cfd < 0)
399 {
400 break;
401 }
402
403 tls = tls_socket_create(TRUE, server, client, cfd, NULL,
404 TLS_SUPPORTED_MIN, config->version, TRUE);
405 ck_assert(tls != NULL);
406
407 while (TRUE)
408 {
409 len = tls->read(tls, buf, sizeof(buf), TRUE);
410 if (len <= 0)
411 {
412 break;
413 }
414 total = 0;
415 while (total < len)
416 {
417 done = tls->write(tls, buf + total, len - total);
418 ck_assert_msg(done > 0, "%s", strerror(errno));
419 total += done;
420 }
421 }
422
423 tls->destroy(tls);
424 close(cfd);
425 }
426 server->destroy(server);
427
428 return JOB_REQUEUE_NONE;
429 }
430
431 /**
432 * Start a echo server using config
433 */
434 static void start_echo_server(echo_server_config_t *config)
435 {
436 host_t *host;
437 int on = 1;
438
439 host = host_create_from_string(config->addr, config->port);
440
441 config->fd = socket(AF_INET, SOCK_STREAM, 0);
442 ck_assert(config->fd != -1);
443 ck_assert(setsockopt(config->fd, SOL_SOCKET, SO_REUSEADDR,
444 (void*)&on, sizeof(on)) != -1);
445 ck_assert_msg(bind(config->fd, host->get_sockaddr(host),
446 *host->get_sockaddr_len(host)) != -1, "%s", strerror(errno));
447 host->destroy(host);
448 ck_assert(listen(config->fd, 1) != -1);
449
450 lib->processor->set_threads(lib->processor, 8);
451
452 lib->processor->queue_job(lib->processor, (job_t*)
453 callback_job_create((void*)serve_echo, config, NULL, NULL));
454 }
455
456 /**
457 * Run client to perform echo test
458 */
459 static void run_echo_client(echo_server_config_t *config)
460 {
461 tls_socket_t *tls;
462 ssize_t len, rd, wr;
463 int fd;
464 host_t *host;
465 identification_t *server, *client = NULL;
466 char buf[128];
467
468 host = host_create_from_string(config->addr, config->port);
469 server = identification_create_from_string(config->addr);
470 if (config->cauth)
471 {
472 client = server;
473 }
474
475 fd = socket(AF_INET, SOCK_STREAM, 0);
476 ck_assert(fd != -1);
477 ck_assert(connect(fd, host->get_sockaddr(host),
478 *host->get_sockaddr_len(host)) != -1);
479 tls = tls_socket_create(FALSE, server, client, fd, NULL,
480 TLS_SUPPORTED_MIN, config->version, TRUE);
481 ck_assert(tls != NULL);
482
483 wr = rd = 0;
484 while (rd < config->data.len)
485 {
486 len = tls->write(tls, config->data.ptr + wr, config->data.len - wr);
487 ck_assert(len >= 0);
488 wr += len;
489
490 len = tls->read(tls, buf, sizeof(buf), FALSE);
491 if (len == -1 && errno == EWOULDBLOCK)
492 {
493 continue;
494 }
495 if (len == 0)
496 {
497 ck_assert_int_eq(rd, config->data.len);
498 break;
499 }
500 ck_assert(len > 0);
501 ck_assert(rd + len <= config->data.len);
502 ck_assert(memeq(buf, config->data.ptr + rd, len));
503 rd += len;
504 }
505
506 tls->destroy(tls);
507 close(fd);
508 host->destroy(host);
509 server->destroy(server);
510 }
511
512 /**
513 * Create server/peer configuration
514 */
515 static echo_server_config_t *create_config(tls_version_t version, uint16_t port,
516 bool cauth)
517 {
518 echo_server_config_t *config;
519
520 INIT(config,
521 .version = version,
522 .addr = "127.0.0.1",
523 .port = port,
524 .cauth = cauth,
525 .data = chunk_from_chars(0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08),
526 );
527 return config;
528 }
529
530 /**
531 * Common test wrapper function for different test variants
532 */
533 static void test_tls(tls_version_t version, uint16_t port, bool cauth, u_int i)
534 {
535 echo_server_config_t *config;
536 tls_cipher_suite_t *suites;
537 char suite[128];
538 int count;
539
540 config = create_config(version, port, cauth);
541
542 start_echo_server(config);
543
544 count = tls_crypto_get_supported_suites(TRUE, version, &suites);
545 ck_assert(i < count);
546 snprintf(suite, sizeof(suite), "%N", tls_cipher_suite_names, suites[i]);
547 lib->settings->set_str(lib->settings, "%s.tls.suites", suite, lib->ns);
548
549 run_echo_client(config);
550
551 free(suites);
552
553 shutdown(config->fd, SHUT_RDWR);
554 close(config->fd);
555
556 free(config);
557 }
558
559 /**
560 * TLS curve test wrapper function
561 */
562 static void test_tls_curves(tls_version_t version, uint16_t port, bool cauth,
563 u_int i)
564 {
565 echo_server_config_t *config;
566 diffie_hellman_group_t *groups;
567 char curve[128];
568 int count;
569
570 config = create_config(version, port, cauth);
571
572 start_echo_server(config);
573
574 count = tls_crypto_get_supported_groups(&groups);
575 ck_assert(i < count);
576 snprintf(curve, sizeof(curve), "%N", diffie_hellman_group_names_short,
577 groups[i]);
578 lib->settings->set_str(lib->settings, "%s.tls.curve", curve, lib->ns);
579
580 run_echo_client(config);
581
582 free(groups);
583
584 shutdown(config->fd, SHUT_RDWR);
585 close(config->fd);
586
587 free(config);
588 }
589
590 /**
591 * TLS server version test wrapper function
592 */
593 static void test_tls_server(tls_version_t version, uint16_t port, bool cauth,
594 u_int i)
595 {
596 echo_server_config_t *client, *server;
597
598 client = create_config(i, port, cauth);
599 server = create_config(version, port, cauth);
600
601 start_echo_server(server);
602
603 run_echo_client(client);
604
605 shutdown(client->fd, SHUT_RDWR);
606 close(client->fd);
607 shutdown(server->fd, SHUT_RDWR);
608 close(server->fd);
609
610 free(client);
611 free(server);
612 }
613
614 /**
615 * TLS client version test wrapper function
616 */
617 static void test_tls_client(tls_version_t version, uint16_t port, bool cauth,
618 u_int i)
619 {
620 echo_server_config_t *client, *server;
621
622 client = create_config(version, port, cauth);
623 server = create_config(i, port, cauth);
624
625 start_echo_server(server);
626
627 run_echo_client(client);
628
629 shutdown(client->fd, SHUT_RDWR);
630 close(client->fd);
631 shutdown(server->fd, SHUT_RDWR);
632 close(server->fd);
633
634 free(client);
635 free(server);
636 }
637
638 START_TEST(test_tls_12_server)
639 {
640 test_tls_server(TLS_1_2, 5665, FALSE, _i);
641 }
642 END_TEST
643
644 START_TEST(test_tls_13_server)
645 {
646 test_tls_server(TLS_1_3, 5666, FALSE, _i);
647 }
648 END_TEST
649
650 START_TEST(test_tls_13_client)
651 {
652 test_tls_client(TLS_1_3, 5667, FALSE, _i);
653 }
654 END_TEST
655
656 START_TEST(test_tls13_curves)
657 {
658 test_tls_curves(TLS_1_3, 5668, FALSE, _i);
659 }
660 END_TEST
661
662 START_TEST(test_tls13)
663 {
664 test_tls(TLS_1_3, 5669, FALSE, _i);
665 }
666 END_TEST
667
668 START_TEST(test_tls13_mutual)
669 {
670 test_tls(TLS_1_3, 5670, TRUE, _i);
671 }
672 END_TEST
673
674 START_TEST(test_tls12)
675 {
676 test_tls(TLS_1_2, 5671, FALSE, _i);
677 }
678 END_TEST
679
680 START_TEST(test_tls12_mutual)
681 {
682 test_tls(TLS_1_2, 5672, TRUE, _i);
683 }
684 END_TEST
685
686 START_TEST(test_tls11)
687 {
688 test_tls(TLS_1_1, 5673, FALSE, _i);
689 }
690 END_TEST
691
692 START_TEST(test_tls11_mutual)
693 {
694 test_tls(TLS_1_1, 5674, TRUE, _i);
695 }
696 END_TEST
697
698 START_TEST(test_tls10)
699 {
700 test_tls(TLS_1_0, 5675, FALSE, _i);
701 }
702 END_TEST
703
704 START_TEST(test_tls10_mutual)
705 {
706 test_tls(TLS_1_0, 5676, TRUE, _i);
707 }
708 END_TEST
709
710 #define add_tls_test(func, version) \
711 tcase_add_loop_test(tc, func, 0, \
712 tls_crypto_get_supported_suites(TRUE, version, NULL));
713
714 #define add_tls_versions_test(func, from, to) \
715 tcase_add_loop_test(tc, func, from, to+1);
716
717 Suite *socket_suite_create()
718 {
719 Suite *s;
720 TCase *tc;
721
722 s = suite_create("socket");
723
724 tc = tcase_create("TLS [1.0..1.3] client to TLS 1.3 server");
725 tcase_add_checked_fixture(tc, setup_creds, teardown_creds);
726 add_tls_versions_test(test_tls_13_server, TLS_1_0, TLS_1_3);
727 suite_add_tcase(s, tc);
728
729 tc = tcase_create("TLS 1.3 client to TLS [1.0..1.3] server");
730 tcase_add_checked_fixture(tc, setup_creds, teardown_creds);
731 add_tls_versions_test(test_tls_13_client, TLS_1_0, TLS_1_3);
732 suite_add_tcase(s, tc);
733
734 tc = tcase_create("TLS [1.0..1.3] client to TLS 1.2 server");
735 tcase_add_checked_fixture(tc, setup_creds, teardown_creds);
736 add_tls_versions_test(test_tls_12_server, TLS_1_0, TLS_1_3);
737 suite_add_tcase(s, tc);
738
739 tc = tcase_create("TLS 1.3/curves");
740 tcase_add_checked_fixture(tc, setup_creds, teardown_creds);
741 tcase_add_loop_test(tc, test_tls13_curves, 0,
742 tls_crypto_get_supported_groups(NULL));
743 suite_add_tcase(s, tc);
744
745 tc = tcase_create("TLS 1.3/anon");
746 tcase_add_checked_fixture(tc, setup_creds, teardown_creds);
747 add_tls_test(test_tls13, TLS_1_3);
748 suite_add_tcase(s, tc);
749
750 tc = tcase_create("TLS 1.3/mutl");
751 tcase_add_checked_fixture(tc, setup_creds, teardown_creds);
752 add_tls_test(test_tls13_mutual, TLS_1_3);
753 suite_add_tcase(s, tc);
754
755 tc = tcase_create("TLS 1.2/anon");
756 tcase_add_checked_fixture(tc, setup_creds, teardown_creds);
757 add_tls_test(test_tls12, TLS_1_2);
758 suite_add_tcase(s, tc);
759
760 tc = tcase_create("TLS 1.2/mutl");
761 tcase_add_checked_fixture(tc, setup_creds, teardown_creds);
762 add_tls_test(test_tls12_mutual, TLS_1_2);
763 suite_add_tcase(s, tc);
764
765 tc = tcase_create("TLS 1.1/anon");
766 tcase_add_checked_fixture(tc, setup_creds, teardown_creds);
767 add_tls_test(test_tls11, TLS_1_1);
768 suite_add_tcase(s, tc);
769
770 tc = tcase_create("TLS 1.1/mutl");
771 tcase_add_checked_fixture(tc, setup_creds, teardown_creds);
772 add_tls_test(test_tls11_mutual, TLS_1_1);
773 suite_add_tcase(s, tc);
774
775 tc = tcase_create("TLS 1.0/anon");
776 tcase_add_checked_fixture(tc, setup_creds, teardown_creds);
777 add_tls_test(test_tls10, TLS_1_0);
778 suite_add_tcase(s, tc);
779
780 tc = tcase_create("TLS 1.0/mutl");
781 tcase_add_checked_fixture(tc, setup_creds, teardown_creds);
782 add_tls_test(test_tls10_mutual, TLS_1_0);
783 suite_add_tcase(s, tc);
784
785 return s;
786 }
787
788 Suite *socket_suite_ed25519_create()
789 {
790 Suite *s;
791 TCase *tc;
792
793 s = suite_create("socket ed25519");
794
795 tc = tcase_create("TLS 1.3/ed25519");
796 tcase_add_checked_fixture(tc, setup_ed25519_creds, teardown_creds);
797 add_tls_test(test_tls13, TLS_1_3);
798 suite_add_tcase(s, tc);
799
800 tc = tcase_create("TLS 1.2/ed25519");
801 tcase_add_checked_fixture(tc, setup_ed25519_creds, teardown_creds);
802 add_tls_test(test_tls12, TLS_1_2);
803 suite_add_tcase(s, tc);
804
805 tc = tcase_create("TLS 1.1/ed25519");
806 tcase_add_checked_fixture(tc, setup_ed25519_creds, teardown_creds);
807 add_tls_test(test_tls11, TLS_1_1);
808 suite_add_tcase(s, tc);
809
810 tc = tcase_create("TLS 1.0/ed25519");
811 tcase_add_checked_fixture(tc, setup_ed25519_creds, teardown_creds);
812 add_tls_test(test_tls10, TLS_1_0);
813 suite_add_tcase(s, tc);
814
815 return s;
816 }
817
818 Suite *socket_suite_ed448_create()
819 {
820 Suite *s;
821 TCase *tc;
822
823 s = suite_create("socket ed448");
824
825 tc = tcase_create("TLS 1.3/ed448");
826 tcase_add_checked_fixture(tc, setup_ed448_creds, teardown_creds);
827 add_tls_test(test_tls13, TLS_1_3);
828 suite_add_tcase(s, tc);
829
830 tc = tcase_create("TLS 1.2/ed448");
831 tcase_add_checked_fixture(tc, setup_ed448_creds, teardown_creds);
832 add_tls_test(test_tls12, TLS_1_2);
833 suite_add_tcase(s, tc);
834
835 tc = tcase_create("TLS 1.1/ed448");
836 tcase_add_checked_fixture(tc, setup_ed448_creds, teardown_creds);
837 add_tls_test(test_tls11, TLS_1_1);
838 suite_add_tcase(s, tc);
839
840 tc = tcase_create("TLS 1.0/ed448");
841 tcase_add_checked_fixture(tc, setup_ed448_creds, teardown_creds);
842 add_tls_test(test_tls10, TLS_1_0);
843 suite_add_tcase(s, tc);
844
845 return s;
846 }