Changeset 32:a5b507479a09 in freeDiameter
- Timestamp:
- Oct 29, 2009, 10:23:12 AM (15 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
freeDiameter/tests/testcnx.c
r31 r32 676 676 CHECK( cer_sz, rcv_sz ); 677 677 CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) ); 678 free(rcv_buf); 678 679 679 680 /* Do it in the other direction */ … … 682 683 CHECK( cer_sz, rcv_sz ); 683 684 CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) ); 685 free(rcv_buf); 684 686 685 687 /* Now close the connection */ … … 716 718 CHECK( cer_sz, rcv_sz ); 717 719 CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) ); 720 free(rcv_buf); 718 721 719 722 /* Do it in the other direction */ … … 722 725 CHECK( cer_sz, rcv_sz ); 723 726 CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) ); 727 free(rcv_buf); 724 728 725 729 /* Do it one more time to use another stream */ … … 728 732 CHECK( cer_sz, rcv_sz ); 729 733 CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) ); 734 free(rcv_buf); 730 735 731 736 /* Now close the connection */ … … 777 782 CHECK( cer_sz, rcv_sz ); 778 783 CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) ); 784 free(rcv_buf); 779 785 780 786 /* And the supposed reply */ … … 783 789 CHECK( cer_sz, rcv_sz ); 784 790 CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) ); 791 free(rcv_buf); 785 792 786 793 /* At this point in legacy Diameter we start the handshake */ … … 796 803 CHECK( cer_sz, rcv_sz ); 797 804 CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) ); 805 free(rcv_buf); 798 806 799 807 CHECK( 0, fd_cnx_send(client_side, cer_buf, cer_sz)); … … 801 809 CHECK( cer_sz, rcv_sz ); 802 810 CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) ); 811 free(rcv_buf); 803 812 } 804 813 … … 858 867 CHECK( cer_sz, rcv_sz ); 859 868 CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) ); 869 free(rcv_buf); 860 870 861 871 /* And the supposed reply */ … … 864 874 CHECK( cer_sz, rcv_sz ); 865 875 CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) ); 876 free(rcv_buf); 866 877 867 878 /* At this point in legacy Diameter we start the handshake */ … … 877 888 CHECK( cer_sz, rcv_sz ); 878 889 CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) ); 890 free(rcv_buf); 879 891 880 892 CHECK( 0, fd_cnx_send(client_side, cer_buf, cer_sz)); … … 882 894 CHECK( cer_sz, rcv_sz ); 883 895 CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) ); 896 free(rcv_buf); 884 897 } 885 898 … … 941 954 CHECK( cer_sz, rcv_sz ); 942 955 CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) ); 956 free(rcv_buf); 943 957 944 958 CHECK( 0, fd_cnx_send(client_side, cer_buf, cer_sz)); … … 946 960 CHECK( cer_sz, rcv_sz ); 947 961 CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) ); 962 free(rcv_buf); 948 963 } 949 964 … … 1004 1019 CHECK( cer_sz, rcv_sz ); 1005 1020 CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) ); 1021 free(rcv_buf); 1006 1022 1007 1023 CHECK( 0, fd_cnx_send(client_side, cer_buf, cer_sz)); … … 1009 1025 CHECK( cer_sz, rcv_sz ); 1010 1026 CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) ); 1027 free(rcv_buf); 1011 1028 } 1012 1029 … … 1252 1269 } 1253 1270 1271 /* Test the other functions of the module */ 1272 { 1273 struct connect_flags cf; 1274 struct handshake_flags hf; 1275 char * str; 1276 const gnutls_datum_t *cert_list; 1277 unsigned int cert_list_size; 1278 struct fd_list local, remote; 1279 struct fifo * myfifo = NULL; 1280 struct timespec now; 1281 int ev_code; 1282 1283 memset(&cf, 0, sizeof(cf)); 1284 cf.proto = IPPROTO_TCP; 1285 1286 memset(&hf, 0, sizeof(hf)); 1287 1288 /* Initialize remote certificate */ 1289 CHECK_GNUTLS_DO( ret = gnutls_certificate_allocate_credentials (&hf.creds), ); 1290 CHECK( GNUTLS_E_SUCCESS, ret ); 1291 /* Set the CA */ 1292 CHECK_GNUTLS_DO( ret = gnutls_certificate_set_x509_trust_mem( hf.creds, &ca, GNUTLS_X509_FMT_PEM), ); 1293 CHECK( 1, ret ); 1294 /* Set the key */ 1295 CHECK_GNUTLS_DO( ret = gnutls_certificate_set_x509_key_mem( hf.creds, &client_cert, &client_priv, GNUTLS_X509_FMT_PEM), ); 1296 CHECK( GNUTLS_E_SUCCESS, ret ); 1297 1298 /* Start the client thread */ 1299 CHECK( 0, pthread_create(&thr, 0, connect_thr, &cf) ); 1300 1301 /* Accept the connection of the client */ 1302 server_side = fd_cnx_serv_accept(listener); 1303 CHECK( 1, server_side ? 1 : 0 ); 1304 1305 /* Retrieve the client connection object */ 1306 CHECK( 0, pthread_join( thr, (void *)&client_side ) ); 1307 CHECK( 1, client_side ? 1 : 0 ); 1308 hf.cnx = client_side; 1309 1310 /* Start the handshake */ 1311 CHECK( 0, pthread_create(&thr, 0, handshake_thr, &hf) ); 1312 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) ); 1313 CHECK( 0, pthread_join(thr, NULL) ); 1314 CHECK( 0, hf.ret ); 1315 1316 /* Test some simple functions */ 1317 1318 /* fd_cnx_getid */ 1319 str = fd_cnx_getid(server_side); 1320 CHECK( 1, str ? 1 : 0 ); 1321 CHECK( 1, (str[0] != '\0') ? 1 : 0 ); 1322 1323 /* fd_cnx_getproto */ 1324 i = fd_cnx_getproto(server_side); 1325 CHECK( IPPROTO_TCP, i); 1326 1327 /* fd_cnx_getTLS */ 1328 i = fd_cnx_getTLS(server_side); 1329 CHECK( 1, i ? 1 : 0 ); 1330 1331 /* fd_cnx_getcred */ 1332 CHECK( 0, fd_cnx_getcred(server_side, &cert_list, &cert_list_size) ); 1333 CHECK( 1, (cert_list_size > 0) ? 1 : 0 ); 1334 /* We could also verify that the cert_list really contains the client_cert and ca certificates */ 1335 1336 1337 /* fd_cnx_getendpoints */ 1338 fd_list_init(&local, NULL); 1339 fd_list_init(&remote, NULL); 1340 1341 /* Check the function provides the LL endpoint(s) */ 1342 CHECK( 0, fd_cnx_getendpoints(server_side, &local, &remote) ); 1343 CHECK( 0, fd_ep_filter( &local, EP_FL_LL ) ); 1344 CHECK( 0, fd_ep_filter( &remote, EP_FL_LL ) ); 1345 CHECK( 0, FD_IS_LIST_EMPTY(&local) ? 1 : 0 ); 1346 CHECK( 0, FD_IS_LIST_EMPTY(&remote) ? 1 : 0 ); 1347 CHECK( 0, fd_ep_filter( &local, 0 ) ); 1348 CHECK( 0, fd_ep_filter( &remote, 0 ) ); 1349 1350 /* Check the function provides 1 primary endpoint */ 1351 CHECK( 0, fd_cnx_getendpoints(server_side, &local, &remote) ); 1352 CHECK( 0, fd_ep_filter( &local, EP_FL_PRIMARY ) ); 1353 CHECK( 0, fd_ep_filter( &remote, EP_FL_PRIMARY ) ); 1354 CHECK( 0, FD_IS_LIST_EMPTY(&local) ? 1 : 0 ); 1355 CHECK( 0, FD_IS_LIST_EMPTY(&remote) ? 1 : 0 ); 1356 CHECK( &local, local.next->next ); 1357 CHECK( &remote, remote.next->next ); 1358 1359 /* fd_cnx_getremoteid */ 1360 str = fd_cnx_getremoteid(server_side); 1361 CHECK( 1, str ? 1 : 0 ); 1362 CHECK( 1, (str[0] != '\0') ? 1 : 0 ); 1363 1364 /* fd_cnx_recv_setaltfifo */ 1365 CHECK( 0, fd_cnx_send(client_side, cer_buf, cer_sz)); 1366 CHECK( 0, fd_fifo_new(&myfifo) ); 1367 CHECK( 0, fd_cnx_recv_setaltfifo(server_side, myfifo) ); 1368 CHECK( 0, clock_gettime(CLOCK_REALTIME, &now) ); 1369 do { 1370 CHECK( 0, fd_event_timedget(myfifo, &now, ETIMEDOUT, &ev_code, NULL, (void *)&rcv_buf) ); 1371 free(rcv_buf); 1372 } while (ev_code != FDEVP_CNX_MSG_RECV); 1373 fd_event_destroy(&myfifo, free); 1374 1375 /* Now close the connection */ 1376 CHECK( 0, pthread_create(&thr, 0, destroy_thr, client_side) ); 1377 fd_cnx_destroy(server_side); 1378 CHECK( 0, pthread_join(thr, NULL) ); 1379 1380 /* Free the credentials */ 1381 gnutls_certificate_free_keys(hf.creds); 1382 gnutls_certificate_free_cas(hf.creds); 1383 gnutls_certificate_free_credentials(hf.creds); 1384 } 1385 1386 #ifndef DISABLE_SCTP 1387 /* And re-test with a SCTP connection */ 1388 { 1389 struct connect_flags cf; 1390 struct handshake_flags hf; 1391 char * str; 1392 const gnutls_datum_t *cert_list; 1393 unsigned int cert_list_size; 1394 struct fd_list local, remote; 1395 struct fifo * myfifo = NULL; 1396 struct timespec now; 1397 int ev_code; 1398 1399 memset(&cf, 0, sizeof(cf)); 1400 cf.proto = IPPROTO_SCTP; 1401 1402 memset(&hf, 0, sizeof(hf)); 1403 1404 /* Initialize remote certificate */ 1405 CHECK_GNUTLS_DO( ret = gnutls_certificate_allocate_credentials (&hf.creds), ); 1406 CHECK( GNUTLS_E_SUCCESS, ret ); 1407 /* Set the CA */ 1408 CHECK_GNUTLS_DO( ret = gnutls_certificate_set_x509_trust_mem( hf.creds, &ca, GNUTLS_X509_FMT_PEM), ); 1409 CHECK( 1, ret ); 1410 /* Set the key */ 1411 CHECK_GNUTLS_DO( ret = gnutls_certificate_set_x509_key_mem( hf.creds, &client_cert, &client_priv, GNUTLS_X509_FMT_PEM), ); 1412 CHECK( GNUTLS_E_SUCCESS, ret ); 1413 1414 /* Start the client thread */ 1415 CHECK( 0, pthread_create(&thr, 0, connect_thr, &cf) ); 1416 1417 /* Accept the connection of the client */ 1418 server_side = fd_cnx_serv_accept(listener_sctp); 1419 CHECK( 1, server_side ? 1 : 0 ); 1420 1421 /* Retrieve the client connection object */ 1422 CHECK( 0, pthread_join( thr, (void *)&client_side ) ); 1423 CHECK( 1, client_side ? 1 : 0 ); 1424 hf.cnx = client_side; 1425 1426 /* Start the handshake */ 1427 CHECK( 0, pthread_create(&thr, 0, handshake_thr, &hf) ); 1428 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) ); 1429 CHECK( 0, pthread_join(thr, NULL) ); 1430 CHECK( 0, hf.ret ); 1431 1432 /* Test some simple functions */ 1433 1434 /* fd_cnx_getid */ 1435 str = fd_cnx_getid(server_side); 1436 CHECK( 1, str ? 1 : 0 ); 1437 CHECK( 1, (str[0] != '\0') ? 1 : 0 ); 1438 1439 /* fd_cnx_getproto */ 1440 i = fd_cnx_getproto(server_side); 1441 CHECK( IPPROTO_SCTP, i); 1442 1443 /* fd_cnx_getTLS */ 1444 i = fd_cnx_getTLS(server_side); 1445 CHECK( 1, i ? 1 : 0 ); 1446 1447 /* fd_cnx_getcred */ 1448 CHECK( 0, fd_cnx_getcred(server_side, &cert_list, &cert_list_size) ); 1449 CHECK( 1, (cert_list_size > 0) ? 1 : 0 ); 1450 /* We could also verify that the cert_list really contains the client_cert and ca certificates */ 1451 1452 1453 /* fd_cnx_getendpoints */ 1454 fd_list_init(&local, NULL); 1455 fd_list_init(&remote, NULL); 1456 1457 /* Check the function provides the LL endpoint(s) */ 1458 CHECK( 0, fd_cnx_getendpoints(server_side, &local, &remote) ); 1459 CHECK( 0, fd_ep_filter( &local, EP_FL_LL ) ); 1460 CHECK( 0, fd_ep_filter( &remote, EP_FL_LL ) ); 1461 CHECK( 0, FD_IS_LIST_EMPTY(&local) ? 1 : 0 ); 1462 CHECK( 0, FD_IS_LIST_EMPTY(&remote) ? 1 : 0 ); 1463 CHECK( 0, fd_ep_filter( &local, 0 ) ); 1464 CHECK( 0, fd_ep_filter( &remote, 0 ) ); 1465 1466 /* Check the function provides 1 primary endpoint */ 1467 CHECK( 0, fd_cnx_getendpoints(server_side, &local, &remote) ); 1468 CHECK( 0, fd_ep_filter( &local, EP_FL_PRIMARY ) ); 1469 CHECK( 0, fd_ep_filter( &remote, EP_FL_PRIMARY ) ); 1470 CHECK( 0, FD_IS_LIST_EMPTY(&local) ? 1 : 0 ); 1471 CHECK( 0, FD_IS_LIST_EMPTY(&remote) ? 1 : 0 ); 1472 CHECK( &local, local.next->next ); 1473 CHECK( &remote, remote.next->next ); 1474 1475 /* fd_cnx_getremoteid */ 1476 str = fd_cnx_getremoteid(server_side); 1477 CHECK( 1, str ? 1 : 0 ); 1478 CHECK( 1, (str[0] != '\0') ? 1 : 0 ); 1479 1480 /* fd_cnx_recv_setaltfifo */ 1481 CHECK( 0, fd_cnx_send(client_side, cer_buf, cer_sz)); 1482 CHECK( 0, fd_fifo_new(&myfifo) ); 1483 CHECK( 0, fd_cnx_recv_setaltfifo(server_side, myfifo) ); 1484 CHECK( 0, clock_gettime(CLOCK_REALTIME, &now) ); 1485 do { 1486 CHECK( 0, fd_event_timedget(myfifo, &now, ETIMEDOUT, &ev_code, NULL, (void *)&rcv_buf) ); 1487 free(rcv_buf); 1488 } while (ev_code != FDEVP_CNX_MSG_RECV); 1489 1490 /* Now close the connection */ 1491 CHECK( 0, pthread_create(&thr, 0, destroy_thr, client_side) ); 1492 fd_cnx_destroy(server_side); 1493 CHECK( 0, pthread_join(thr, NULL) ); 1494 1495 fd_event_destroy(&myfifo, free); 1496 1497 /* Free the credentials */ 1498 gnutls_certificate_free_keys(hf.creds); 1499 gnutls_certificate_free_cas(hf.creds); 1500 gnutls_certificate_free_credentials(hf.creds); 1501 } 1502 #endif /* DISABLE_SCTP */ 1503 1504 /* Destroy the servers */ 1505 { 1506 fd_cnx_destroy(listener); 1507 #ifndef DISABLE_SCTP 1508 fd_cnx_destroy(listener_sctp); 1509 #endif /* DISABLE_SCTP */ 1510 } 1511 1254 1512 /* That's all for the tests yet */ 1255 1513 PASSTEST();
Note: See TracChangeset
for help on using the changeset viewer.