Changeset 1181:22de21feec64 in freeDiameter for tests/testcnx.c
- Timestamp:
- Jun 5, 2013, 8:22:26 PM (11 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/testcnx.c
r1127 r1181 549 549 struct cnxctx * cnx; 550 550 gnutls_certificate_credentials_t creds; 551 int algo; 551 552 int ret; 552 553 }; … … 557 558 struct handshake_flags * hf = arg; 558 559 fd_log_threadname ( "testcnx:handshake" ); 559 hf->ret = fd_cnx_handshake(hf->cnx, GNUTLS_CLIENT, NULL, hf->creds);560 hf->ret = fd_cnx_handshake(hf->cnx, GNUTLS_CLIENT, hf->algo, NULL, hf->creds); 560 561 return NULL; 561 562 } … … 864 865 /* At this point in legacy Diameter we start the handshake */ 865 866 CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) ); 866 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) );867 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, ALGO_HANDSHAKE_DEFAULT /* No impact on TCP */, NULL, NULL) ); 867 868 CHECK( 0, pthread_join(thr, NULL) ); 868 869 CHECK( 0, hf.ret ); … … 905 906 906 907 memset(&hf, 0, sizeof(hf)); 908 hf.algo = ALGO_HANDSHAKE_3436; /* this is mandatory for old TLS mechanism */ 907 909 908 910 /* Initialize remote certificate */ … … 949 951 /* At this point in legacy Diameter we start the handshake */ 950 952 CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) ); 951 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) );953 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, ALGO_HANDSHAKE_3436, NULL, NULL) ); 952 954 CHECK( 0, pthread_join(thr, NULL) ); 953 955 CHECK( 0, hf.ret ); … … 1015 1017 /* Start the handshake directly */ 1016 1018 CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) ); 1017 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) );1019 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, ALGO_HANDSHAKE_DEFAULT, NULL, NULL) ); 1018 1020 CHECK( 0, pthread_join(thr, NULL) ); 1019 1021 CHECK( 0, hf.ret ); … … 1046 1048 1047 1049 #ifndef DISABLE_SCTP 1048 /* SCTP Client / server emulating new Diameter behavior (handshake at connection directly) */ 1050 1051 1052 /* SCTP Client / server emulating new Diameter behavior (DTLS handshake at connection directly) */ 1053 TODO("Enabled after DTLS implementation"); 1054 if (0) 1049 1055 { 1050 1056 struct connect_flags cf; … … 1080 1086 /* Start the handshake directly */ 1081 1087 CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) ); 1082 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) );1088 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, ALGO_HANDSHAKE_DEFAULT, NULL, NULL) ); 1083 1089 CHECK( 0, pthread_join(thr, NULL) ); 1084 1090 CHECK( 0, hf.ret ); … … 1110 1116 gnutls_certificate_free_credentials(hf.creds); 1111 1117 } 1112 #endif /* DISABLE_SCTP */ 1113 1114 /* Test with different number of streams between server and client */ 1115 #ifndef DISABLE_SCTP 1118 1119 /* SCTP Client / server emulating old intermediary Diameter behavior (TLS handshake at connection directly) */ 1116 1120 { 1117 1121 struct connect_flags cf; … … 1122 1126 1123 1127 memset(&hf, 0, sizeof(hf)); 1128 hf.algo = ALGO_HANDSHAKE_3436; /* this is mandatory for old TLS mechanism */ 1124 1129 1125 1130 /* Initialize remote certificate */ … … 1133 1138 CHECK( GNUTLS_E_SUCCESS, ret ); 1134 1139 1135 /* Start the client thread with more streams than the server */ 1136 fd_g_config->cnf_sctp_str = 2 * NB_STREAMS; 1140 /* Start the client thread */ 1137 1141 CHECK( 0, pthread_create(&thr, NULL, connect_thr, &cf) ); 1138 1142 … … 1148 1152 /* Start the handshake directly */ 1149 1153 CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) ); 1150 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) ); 1154 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, ALGO_HANDSHAKE_3436, NULL, NULL) ); 1155 CHECK( 0, pthread_join(thr, NULL) ); 1156 CHECK( 0, hf.ret ); 1157 1158 /* Send a few TLS protected messages, and replies */ 1159 for (i = 0; i < 2 * NB_STREAMS; i++) { 1160 CHECK( 0, fd_cnx_send(server_side, cer_buf, cer_sz, 0)); 1161 CHECK( 0, fd_cnx_receive(client_side, NULL, &rcv_buf, &rcv_sz)); 1162 CHECK( cer_sz, rcv_sz ); 1163 CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) ); 1164 free(rcv_buf); 1165 1166 CHECK( 0, fd_cnx_send(client_side, cer_buf, cer_sz, 0)); 1167 CHECK( 0, fd_cnx_receive(server_side, NULL, &rcv_buf, &rcv_sz)); 1168 CHECK( cer_sz, rcv_sz ); 1169 CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) ); 1170 free(rcv_buf); 1171 } 1172 1173 1174 /* Now close the connection */ 1175 CHECK( 0, pthread_create(&thr, NULL, destroy_thr, client_side) ); 1176 fd_cnx_destroy(server_side); 1177 CHECK( 0, pthread_join(thr, NULL) ); 1178 1179 /* Free the credentials */ 1180 gnutls_certificate_free_keys(hf.creds); 1181 gnutls_certificate_free_cas(hf.creds); 1182 gnutls_certificate_free_credentials(hf.creds); 1183 } 1184 #endif /* DISABLE_SCTP */ 1185 1186 /* Test with different number of streams between server and client */ 1187 #ifndef DISABLE_SCTP 1188 /* DTLS / SCTP style */ 1189 TODO("Enabled after DTLS implementation"); 1190 if (0) 1191 { 1192 struct connect_flags cf; 1193 struct handshake_flags hf; 1194 1195 memset(&cf, 0, sizeof(cf)); 1196 cf.proto = IPPROTO_SCTP; 1197 1198 memset(&hf, 0, sizeof(hf)); 1199 1200 /* Initialize remote certificate */ 1201 CHECK_GNUTLS_DO( ret = gnutls_certificate_allocate_credentials (&hf.creds), ); 1202 CHECK( GNUTLS_E_SUCCESS, ret ); 1203 /* Set the CA */ 1204 CHECK_GNUTLS_DO( ret = gnutls_certificate_set_x509_trust_mem( hf.creds, &ca, GNUTLS_X509_FMT_PEM), ); 1205 CHECK( 1, ret ); 1206 /* Set the key */ 1207 CHECK_GNUTLS_DO( ret = gnutls_certificate_set_x509_key_mem( hf.creds, &client_cert, &client_priv, GNUTLS_X509_FMT_PEM), ); 1208 CHECK( GNUTLS_E_SUCCESS, ret ); 1209 1210 /* Start the client thread with more streams than the server */ 1211 fd_g_config->cnf_sctp_str = 2 * NB_STREAMS; 1212 CHECK( 0, pthread_create(&thr, NULL, connect_thr, &cf) ); 1213 1214 /* Accept the connection of the client */ 1215 server_side = fd_cnx_serv_accept(listener_sctp); 1216 CHECK( 1, server_side ? 1 : 0 ); 1217 1218 /* Retrieve the client connection object */ 1219 CHECK( 0, pthread_join( thr, (void *)&client_side ) ); 1220 CHECK( 1, client_side ? 1 : 0 ); 1221 hf.cnx = client_side; 1222 1223 /* Start the handshake directly */ 1224 CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) ); 1225 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, ALGO_HANDSHAKE_DEFAULT, NULL, NULL) ); 1151 1226 CHECK( 0, pthread_join(thr, NULL) ); 1152 1227 CHECK( 0, hf.ret ); … … 1187 1262 /* Start the handshake directly */ 1188 1263 CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) ); 1189 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) );1264 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, ALGO_HANDSHAKE_DEFAULT, NULL, NULL) ); 1190 1265 CHECK( 0, pthread_join(thr, NULL) ); 1191 1266 CHECK( 0, hf.ret ); … … 1217 1292 gnutls_certificate_free_credentials(hf.creds); 1218 1293 } 1294 1295 /* TLS / SCTP style */ 1296 { 1297 struct connect_flags cf; 1298 struct handshake_flags hf; 1299 1300 memset(&cf, 0, sizeof(cf)); 1301 cf.proto = IPPROTO_SCTP; 1302 1303 memset(&hf, 0, sizeof(hf)); 1304 hf.algo = ALGO_HANDSHAKE_3436; 1305 1306 /* Initialize remote certificate */ 1307 CHECK_GNUTLS_DO( ret = gnutls_certificate_allocate_credentials (&hf.creds), ); 1308 CHECK( GNUTLS_E_SUCCESS, ret ); 1309 /* Set the CA */ 1310 CHECK_GNUTLS_DO( ret = gnutls_certificate_set_x509_trust_mem( hf.creds, &ca, GNUTLS_X509_FMT_PEM), ); 1311 CHECK( 1, ret ); 1312 /* Set the key */ 1313 CHECK_GNUTLS_DO( ret = gnutls_certificate_set_x509_key_mem( hf.creds, &client_cert, &client_priv, GNUTLS_X509_FMT_PEM), ); 1314 CHECK( GNUTLS_E_SUCCESS, ret ); 1315 1316 /* Start the client thread with more streams than the server */ 1317 fd_g_config->cnf_sctp_str = 2 * NB_STREAMS; 1318 CHECK( 0, pthread_create(&thr, NULL, connect_thr, &cf) ); 1319 1320 /* Accept the connection of the client */ 1321 server_side = fd_cnx_serv_accept(listener_sctp); 1322 CHECK( 1, server_side ? 1 : 0 ); 1323 1324 /* Retrieve the client connection object */ 1325 CHECK( 0, pthread_join( thr, (void *)&client_side ) ); 1326 CHECK( 1, client_side ? 1 : 0 ); 1327 hf.cnx = client_side; 1328 1329 /* Start the handshake directly */ 1330 CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) ); 1331 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, ALGO_HANDSHAKE_3436, NULL, NULL) ); 1332 CHECK( 0, pthread_join(thr, NULL) ); 1333 CHECK( 0, hf.ret ); 1334 1335 /* Send a few TLS protected message, and replies */ 1336 for (i = 0; i < 4 * NB_STREAMS; i++) { 1337 CHECK( 0, fd_cnx_send(server_side, cer_buf, cer_sz, 0)); 1338 CHECK( 0, fd_cnx_receive(client_side, NULL, &rcv_buf, &rcv_sz)); 1339 CHECK( cer_sz, rcv_sz ); 1340 CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) ); 1341 free(rcv_buf); 1342 1343 CHECK( 0, fd_cnx_send(client_side, cer_buf, cer_sz, 0)); 1344 CHECK( 0, fd_cnx_receive(server_side, NULL, &rcv_buf, &rcv_sz)); 1345 CHECK( cer_sz, rcv_sz ); 1346 CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) ); 1347 free(rcv_buf); 1348 } 1349 1350 /* Now close the connection */ 1351 CHECK( 0, pthread_create(&thr, NULL, destroy_thr, client_side) ); 1352 fd_cnx_destroy(server_side); 1353 CHECK( 0, pthread_join(thr, NULL) ); 1354 1355 /* Do the same test but with more streams on the server this time */ 1356 fd_g_config->cnf_sctp_str = NB_STREAMS / 2; 1357 CHECK( 0, pthread_create(&thr, NULL, connect_thr, &cf) ); 1358 1359 /* Accept the connection of the client */ 1360 server_side = fd_cnx_serv_accept(listener_sctp); 1361 CHECK( 1, server_side ? 1 : 0 ); 1362 1363 /* Retrieve the client connection object */ 1364 CHECK( 0, pthread_join( thr, (void *)&client_side ) ); 1365 CHECK( 1, client_side ? 1 : 0 ); 1366 hf.cnx = client_side; 1367 1368 /* Start the handshake directly */ 1369 CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) ); 1370 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, ALGO_HANDSHAKE_3436, NULL, NULL) ); 1371 CHECK( 0, pthread_join(thr, NULL) ); 1372 CHECK( 0, hf.ret ); 1373 1374 /* Send a few TLS protected message, and replies */ 1375 for (i = 0; i < 2 * NB_STREAMS; i++) { 1376 CHECK( 0, fd_cnx_send(server_side, cer_buf, cer_sz, 0)); 1377 CHECK( 0, fd_cnx_receive(client_side, NULL, &rcv_buf, &rcv_sz)); 1378 CHECK( cer_sz, rcv_sz ); 1379 CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) ); 1380 free(rcv_buf); 1381 1382 CHECK( 0, fd_cnx_send(client_side, cer_buf, cer_sz, 0)); 1383 CHECK( 0, fd_cnx_receive(server_side, NULL, &rcv_buf, &rcv_sz)); 1384 CHECK( cer_sz, rcv_sz ); 1385 CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) ); 1386 free(rcv_buf); 1387 } 1388 1389 /* Now close the connection */ 1390 CHECK( 0, pthread_create(&thr, NULL, destroy_thr, client_side) ); 1391 fd_cnx_destroy(server_side); 1392 CHECK( 0, pthread_join(thr, NULL) ); 1393 1394 1395 /* Free the credentials */ 1396 gnutls_certificate_free_keys(hf.creds); 1397 gnutls_certificate_free_cas(hf.creds); 1398 gnutls_certificate_free_credentials(hf.creds); 1399 } 1400 1219 1401 #endif /* DISABLE_SCTP */ 1220 1402 … … 1257 1439 /* Start the handshake directly */ 1258 1440 CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) ); 1259 CHECK( EINVAL, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) );1441 CHECK( EINVAL, fd_cnx_handshake(server_side, GNUTLS_SERVER, ALGO_HANDSHAKE_DEFAULT, NULL, NULL) ); 1260 1442 fd_cnx_destroy(server_side); 1261 1443 … … 1274 1456 /* Same in SCTP */ 1275 1457 #ifndef DISABLE_SCTP 1458 /* DTLS */ 1459 TODO("Enabled after DTLS implementation"); 1460 if (0) 1276 1461 { 1277 1462 struct connect_flags cf; … … 1308 1493 /* Start the handshake directly */ 1309 1494 CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) ); 1310 CHECK( EINVAL, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) ); 1495 CHECK( EINVAL, fd_cnx_handshake(server_side, GNUTLS_SERVER, ALGO_HANDSHAKE_DEFAULT, NULL, NULL) ); 1496 fd_cnx_destroy(server_side); 1497 CHECK( 0, pthread_join(thr, NULL) ); 1498 1499 /* Now close the connection */ 1500 CHECK( 0, pthread_create(&thr, NULL, destroy_thr, client_side) ); 1501 CHECK( 0, pthread_join(thr, NULL) ); 1502 1503 /* Free the credentials */ 1504 gnutls_certificate_free_keys(hf.creds); 1505 gnutls_certificate_free_cas(hf.creds); 1506 gnutls_certificate_free_credentials(hf.creds); 1507 } 1508 1509 /* TLS */ 1510 { 1511 struct connect_flags cf; 1512 struct handshake_flags hf; 1513 1514 memset(&cf, 0, sizeof(cf)); 1515 cf.proto = IPPROTO_SCTP; 1516 1517 memset(&hf, 0, sizeof(hf)); 1518 hf.algo = ALGO_HANDSHAKE_3436; 1519 1520 /* Initialize remote certificate */ 1521 CHECK_GNUTLS_DO( ret = gnutls_certificate_allocate_credentials (&hf.creds), ); 1522 CHECK( GNUTLS_E_SUCCESS, ret ); 1523 /* Set the CA */ 1524 CHECK_GNUTLS_DO( ret = gnutls_certificate_set_x509_trust_mem( hf.creds, ¬rust_ca, GNUTLS_X509_FMT_PEM), ); 1525 CHECK_GNUTLS_DO( ret = gnutls_certificate_set_x509_trust_mem( hf.creds, &ca, GNUTLS_X509_FMT_PEM), ); 1526 CHECK( 1, ret ); 1527 /* Set the key */ 1528 CHECK_GNUTLS_DO( ret = gnutls_certificate_set_x509_key_mem( hf.creds, ¬rust_cert, ¬rust_priv, GNUTLS_X509_FMT_PEM), ); 1529 CHECK( GNUTLS_E_SUCCESS, ret ); 1530 1531 /* Start the client thread */ 1532 CHECK( 0, pthread_create(&thr, NULL, connect_thr, &cf) ); 1533 1534 /* Accept the connection of the client */ 1535 server_side = fd_cnx_serv_accept(listener_sctp); 1536 CHECK( 1, server_side ? 1 : 0 ); 1537 1538 /* Retrieve the client connection object */ 1539 CHECK( 0, pthread_join( thr, (void *)&client_side ) ); 1540 CHECK( 1, client_side ? 1 : 0 ); 1541 hf.cnx = client_side; 1542 1543 /* Start the handshake directly */ 1544 CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) ); 1545 CHECK( EINVAL, fd_cnx_handshake(server_side, GNUTLS_SERVER, ALGO_HANDSHAKE_3436, NULL, NULL) ); 1311 1546 fd_cnx_destroy(server_side); 1312 1547 CHECK( 0, pthread_join(thr, NULL) ); … … 1357 1592 /* Start the handshake directly */ 1358 1593 CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) ); 1359 CHECK( EINVAL, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) );1594 CHECK( EINVAL, fd_cnx_handshake(server_side, GNUTLS_SERVER, ALGO_HANDSHAKE_DEFAULT, NULL, NULL) ); 1360 1595 fd_cnx_destroy(server_side); 1361 1596 CHECK( 0, pthread_join(thr, NULL) ); … … 1409 1644 /* Start the handshake, check it is successful */ 1410 1645 CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) ); 1411 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) );1646 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, ALGO_HANDSHAKE_DEFAULT, NULL, NULL) ); 1412 1647 CHECK( 0, pthread_join(thr, NULL) ); 1413 1648 CHECK( 0, hf.ret ); … … 1435 1670 /* Start the handshake, check it is successful */ 1436 1671 CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) ); 1437 CHECK( EINVAL, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) );1672 CHECK( EINVAL, fd_cnx_handshake(server_side, GNUTLS_SERVER, ALGO_HANDSHAKE_DEFAULT, NULL, NULL) ); 1438 1673 fd_cnx_destroy(server_side); 1439 1674 CHECK( 0, pthread_join(thr, NULL) ); … … 1489 1724 /* Start the handshake */ 1490 1725 CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) ); 1491 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) );1726 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, ALGO_HANDSHAKE_DEFAULT, NULL, NULL) ); 1492 1727 CHECK( 0, pthread_join(thr, NULL) ); 1493 1728 CHECK( 0, hf.ret ); … … 1543 1778 #ifndef DISABLE_SCTP 1544 1779 /* And re-test with a SCTP connection */ 1780 TODO("Enabled after DTLS implementation"); 1781 if (0) 1545 1782 { 1546 1783 struct connect_flags cf; … … 1582 1819 /* Start the handshake */ 1583 1820 CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) ); 1584 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) );1821 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, ALGO_HANDSHAKE_DEFAULT, NULL, NULL) ); 1585 1822 CHECK( 0, pthread_join(thr, NULL) ); 1586 1823 CHECK( 0, hf.ret ); … … 1633 1870 gnutls_certificate_free_credentials(hf.creds); 1634 1871 } 1872 1873 /* TLS */ 1874 { 1875 struct connect_flags cf; 1876 struct handshake_flags hf; 1877 char * str; 1878 const gnutls_datum_t *cert_list; 1879 unsigned int cert_list_size; 1880 struct fifo * myfifo = NULL; 1881 struct timespec now; 1882 int ev_code; 1883 1884 memset(&cf, 0, sizeof(cf)); 1885 cf.proto = IPPROTO_SCTP; 1886 1887 memset(&hf, 0, sizeof(hf)); 1888 hf.algo = ALGO_HANDSHAKE_3436; 1889 1890 /* Initialize remote certificate */ 1891 CHECK_GNUTLS_DO( ret = gnutls_certificate_allocate_credentials (&hf.creds), ); 1892 CHECK( GNUTLS_E_SUCCESS, ret ); 1893 /* Set the CA */ 1894 CHECK_GNUTLS_DO( ret = gnutls_certificate_set_x509_trust_mem( hf.creds, &ca, GNUTLS_X509_FMT_PEM), ); 1895 CHECK( 1, ret ); 1896 /* Set the key */ 1897 CHECK_GNUTLS_DO( ret = gnutls_certificate_set_x509_key_mem( hf.creds, &client_cert, &client_priv, GNUTLS_X509_FMT_PEM), ); 1898 CHECK( GNUTLS_E_SUCCESS, ret ); 1899 1900 /* Start the client thread */ 1901 CHECK( 0, pthread_create(&thr, NULL, connect_thr, &cf) ); 1902 1903 /* Accept the connection of the client */ 1904 server_side = fd_cnx_serv_accept(listener_sctp); 1905 CHECK( 1, server_side ? 1 : 0 ); 1906 1907 /* Retrieve the client connection object */ 1908 CHECK( 0, pthread_join( thr, (void *)&client_side ) ); 1909 CHECK( 1, client_side ? 1 : 0 ); 1910 hf.cnx = client_side; 1911 1912 /* Start the handshake */ 1913 CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) ); 1914 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, ALGO_HANDSHAKE_3436, NULL, NULL) ); 1915 CHECK( 0, pthread_join(thr, NULL) ); 1916 CHECK( 0, hf.ret ); 1917 1918 /* Test some simple functions */ 1919 1920 /* fd_cnx_getid */ 1921 str = fd_cnx_getid(server_side); 1922 CHECK( 1, str ? 1 : 0 ); 1923 CHECK( 1, (str[0] != '\0') ? 1 : 0 ); 1924 1925 /* fd_cnx_getproto */ 1926 i = fd_cnx_getproto(server_side); 1927 CHECK( IPPROTO_SCTP, i); 1928 1929 /* fd_cnx_getTLS */ 1930 i = fd_cnx_getTLS(server_side); 1931 CHECK( 1, i ? 1 : 0 ); 1932 1933 /* fd_cnx_getcred */ 1934 CHECK( 0, fd_cnx_getcred(server_side, &cert_list, &cert_list_size) ); 1935 CHECK( 1, (cert_list_size > 0) ? 1 : 0 ); 1936 /* We could also verify that the cert_list really contains the client_cert and ca certificates */ 1937 1938 /* fd_cnx_getremoteid */ 1939 str = fd_cnx_getremoteid(server_side); 1940 CHECK( 1, str ? 1 : 0 ); 1941 CHECK( 1, (str[0] != '\0') ? 1 : 0 ); 1942 1943 /* fd_cnx_recv_setaltfifo */ 1944 CHECK( 0, fd_cnx_send(client_side, cer_buf, cer_sz, 0)); 1945 CHECK( 0, fd_fifo_new(&myfifo, 0) ); 1946 CHECK( 0, fd_cnx_recv_setaltfifo(server_side, myfifo) ); 1947 CHECK( 0, clock_gettime(CLOCK_REALTIME, &now) ); 1948 do { 1949 CHECK( 0, fd_event_timedget(myfifo, &now, ETIMEDOUT, &ev_code, NULL, (void *)&rcv_buf) ); 1950 free(rcv_buf); 1951 } while (ev_code != FDEVP_CNX_MSG_RECV); 1952 1953 /* Now close the connection */ 1954 CHECK( 0, pthread_create(&thr, NULL, destroy_thr, client_side) ); 1955 fd_cnx_destroy(server_side); 1956 CHECK( 0, pthread_join(thr, NULL) ); 1957 1958 fd_event_destroy(&myfifo, free); 1959 1960 /* Free the credentials */ 1961 gnutls_certificate_free_keys(hf.creds); 1962 gnutls_certificate_free_cas(hf.creds); 1963 gnutls_certificate_free_credentials(hf.creds); 1964 } 1635 1965 #endif /* DISABLE_SCTP */ 1636 1966
Note: See TracChangeset
for help on using the changeset viewer.