comparison tests/testcnx.c @ 729:5d8ac5da7092

Fixed timeout handling + minor fixes
author Sebastien Decugis <sdecugis@nict.go.jp>
date Thu, 24 Feb 2011 17:19:14 +0900
parents 8c3dc8584dab
children 4a9f08d6b6ba
comparison
equal deleted inserted replaced
728:6169b4c5b256 729:5d8ac5da7092
463 "T1BLiwJoiWXmLTJ/EP0V9Irov2uMtm5cE6DhrJqlduksz8r1gu7RZ3tMsVLg5Iy+\n" 463 "T1BLiwJoiWXmLTJ/EP0V9Irov2uMtm5cE6DhrJqlduksz8r1gu7RZ3tMsVLg5Iy+\n"
464 "dcCQJOffNa54caQUTZ8CQQDTs/70Nr6F6ktrtmtU/S7lIitpQJCu9u/SPyBYPmFZ\n" 464 "dcCQJOffNa54caQUTZ8CQQDTs/70Nr6F6ktrtmtU/S7lIitpQJCu9u/SPyBYPmFZ\n"
465 "9Axy6Ee66Php+eWDNP4Ln4axrapD0732wD8DcmGDVHij\n" 465 "9Axy6Ee66Php+eWDNP4Ln4axrapD0732wD8DcmGDVHij\n"
466 "-----END RSA PRIVATE KEY-----\n"; 466 "-----END RSA PRIVATE KEY-----\n";
467 467
468 468 /* Diffie-Hellman parameters, generated with GNUTLS certtool:
469 struct fd_list eps = FD_LIST_INITIALIZER(eps); 469 certtool --generate-dh-params
470 470 Generator: 06
471
472 Prime: ea:c3:75:0b:32:cf:d9:17:98:5c:da:d1
473 e0:1d:b9:7c:be:29:60:b0:6f:68:a9:f6
474 8d:75:05:59:69:04:ae:39:7c:2b:74:04
475 3c:e2:da:28:8a:9b:93:aa:67:05:a7:3e
476 06:3e:0d:31:63:88:55:ad:5a:bd:41:22
477 b7:58:a7:45:b3:d5:03:ad:de:3c:8d:69
478 42:bf:84:3d:c1:90:e7:39:6a:4b:87:01
479 19:e5:f3:a4:e5:8e:e2:45:d5:0c:6b:17
480 22:2b:2e:50:83:91:0c:5b:82:fc:72:27
481 49:3b:9f:29:11:53:c7:90:b8:8d:87:73
482 1a:7b:05:ab:cb:30:59:16:71:30:60:1b
483 4c:80:15:3a:a2:d3:47:b7:4a:61:de:64
484 7e:79:de:88:53:b7:7a:c6:a2:9a:bb:55
485 40:2d:7a:71:c7:41:b5:29:df:d7:5c:fb
486 42:e4:d8:5e:0b:99:d3:3c:93:0f:33:51
487 8b:f4:60:e4:c5:b5:58:21:c0:51:c4:43
488 25:7c:37:fe:5c:d3:62:6c:2a:af:a7:2a
489 82:d5:d3:e2:bb:5d:ad:84:15:f6:78:d9
490 d5:a8:f7:f0:48:5c:8d:e0:3d:04:ac:cf
491 aa:34:3f:5d:f2:0d:3d:ee:ec:b8:d8:e8
492 ad:dc:d3:40:59:a0:fd:45:62:47:63:c0
493 bd:f5:df:8b
494 */
495 static char dh_params_data[] = "-----BEGIN DH PARAMETERS-----\n"
496 "MIIBCAKCAQEA6sN1CzLP2ReYXNrR4B25fL4pYLBvaKn2jXUFWWkErjl8K3QEPOLa\n"
497 "KIqbk6pnBac+Bj4NMWOIVa1avUEit1inRbPVA63ePI1pQr+EPcGQ5zlqS4cBGeXz\n"
498 "pOWO4kXVDGsXIisuUIORDFuC/HInSTufKRFTx5C4jYdzGnsFq8swWRZxMGAbTIAV\n"
499 "OqLTR7dKYd5kfnneiFO3esaimrtVQC16ccdBtSnf11z7QuTYXguZ0zyTDzNRi/Rg\n"
500 "5MW1WCHAUcRDJXw3/lzTYmwqr6cqgtXT4rtdrYQV9njZ1aj38EhcjeA9BKzPqjQ/\n"
501 "XfINPe7suNjordzTQFmg/UViR2PAvfXfiwIBBg==\n"
502 "-----END DH PARAMETERS-----\n";
503
504
505 /* List server endpoints */
506 static struct fd_list eps = FD_LIST_INITIALIZER(eps);
507
508 /* Pass parameters to the connect thread */
471 struct connect_flags { 509 struct connect_flags {
472 int proto; 510 int proto;
473 int expect_failure; /* 0 or 1 */ 511 int expect_failure; /* 0 or 1 */
474 }; 512 };
475 513
476 void * connect_thr(void * arg) 514 /* Client's side of the connection established from a separate thread */
515 static void * connect_thr(void * arg)
477 { 516 {
478 struct connect_flags * cf = arg; 517 struct connect_flags * cf = arg;
479 struct cnxctx * cnx = NULL; 518 struct cnxctx * cnx = NULL;
480 519
481 fd_log_threadname ( "testcnx:connect" ); 520 fd_log_threadname ( "testcnx:connect" );
503 542
504 /* exit */ 543 /* exit */
505 return cnx; 544 return cnx;
506 } 545 }
507 546
547 /* Parameters to the handshake thread */
508 struct handshake_flags { 548 struct handshake_flags {
509 struct cnxctx * cnx; 549 struct cnxctx * cnx;
510 gnutls_certificate_credentials_t creds; 550 gnutls_certificate_credentials_t creds;
511 int ret; 551 int ret;
512 }; 552 };
513 553
514 void * handshake_thr(void * arg) 554 /* Handshake the client's side */
555 static void * handshake_thr(void * arg)
515 { 556 {
516 struct handshake_flags * hf = arg; 557 struct handshake_flags * hf = arg;
517 fd_log_threadname ( "testcnx:handshake" ); 558 fd_log_threadname ( "testcnx:handshake" );
518 hf->ret = fd_cnx_handshake(hf->cnx, GNUTLS_CLIENT, NULL, hf->creds); 559 hf->ret = fd_cnx_handshake(hf->cnx, GNUTLS_CLIENT, NULL, hf->creds);
519 return NULL; 560 return NULL;
520 } 561 }
521 562
522 void * destroy_thr(void * arg) 563 /* Terminate the client's connection side */
564 static void * destroy_thr(void * arg)
523 { 565 {
524 struct cnxctx * cnx = arg; 566 struct cnxctx * cnx = arg;
525 fd_log_threadname ( "testcnx:destroy" ); 567 fd_log_threadname ( "testcnx:destroy" );
526 fd_cnx_destroy(cnx); 568 fd_cnx_destroy(cnx);
527 return NULL; 569 return NULL;
538 gnutls_datum_t expired_cert = { (uint8_t *)expired_cert_data, sizeof(expired_cert_data) }; 580 gnutls_datum_t expired_cert = { (uint8_t *)expired_cert_data, sizeof(expired_cert_data) };
539 gnutls_datum_t expired_priv = { (uint8_t *)expired_priv_data, sizeof(expired_priv_data) }; 581 gnutls_datum_t expired_priv = { (uint8_t *)expired_priv_data, sizeof(expired_priv_data) };
540 gnutls_datum_t notrust_ca = { (uint8_t *)notrust_ca_data, sizeof(notrust_ca_data) }; 582 gnutls_datum_t notrust_ca = { (uint8_t *)notrust_ca_data, sizeof(notrust_ca_data) };
541 gnutls_datum_t notrust_cert = { (uint8_t *)notrust_cert_data, sizeof(notrust_cert_data) }; 583 gnutls_datum_t notrust_cert = { (uint8_t *)notrust_cert_data, sizeof(notrust_cert_data) };
542 gnutls_datum_t notrust_priv = { (uint8_t *)notrust_priv_data, sizeof(notrust_priv_data) }; 584 gnutls_datum_t notrust_priv = { (uint8_t *)notrust_priv_data, sizeof(notrust_priv_data) };
543 585 gnutls_datum_t dh_params = { (uint8_t *)dh_params_data, sizeof(dh_params_data) };
586
587 /* Listening socket, server side */
544 struct cnxctx * listener; 588 struct cnxctx * listener;
545 #ifndef DISABLE_SCTP 589 #ifndef DISABLE_SCTP
546 struct cnxctx * listener_sctp; 590 struct cnxctx * listener_sctp;
547 #endif /* DISABLE_SCTP */ 591 #endif /* DISABLE_SCTP */
592
593 /* Server & client connected sockets */
548 struct cnxctx * server_side; 594 struct cnxctx * server_side;
549 struct cnxctx * client_side; 595 struct cnxctx * client_side;
596
550 pthread_t thr; 597 pthread_t thr;
551 int ret, i; 598 int ret, i;
552 uint8_t * cer_buf; 599 uint8_t * cer_buf;
553 size_t cer_sz; 600 size_t cer_sz;
554 uint8_t * rcv_buf; 601 uint8_t * rcv_buf;
576 /* Set the default priority */ 623 /* Set the default priority */
577 CHECK_GNUTLS_DO( ret = gnutls_priority_init( &fd_g_config->cnf_sec_data.prio_cache, GNUTLS_DEFAULT_PRIORITY, NULL), ); 624 CHECK_GNUTLS_DO( ret = gnutls_priority_init( &fd_g_config->cnf_sec_data.prio_cache, GNUTLS_DEFAULT_PRIORITY, NULL), );
578 CHECK( GNUTLS_E_SUCCESS, ret ); 625 CHECK( GNUTLS_E_SUCCESS, ret );
579 626
580 /* Set default DH params */ 627 /* Set default DH params */
581 CHECK_GNUTLS_DO( ret = gnutls_dh_params_generate2( fd_g_config->cnf_sec_data.dh_cache, GNUTLS_DEFAULT_DHBITS), ); 628 CHECK_GNUTLS_DO( ret = gnutls_dh_params_import_pkcs3( fd_g_config->cnf_sec_data.dh_cache, &dh_params, GNUTLS_X509_FMT_PEM), );
582 CHECK( GNUTLS_E_SUCCESS, ret ); 629 CHECK( GNUTLS_E_SUCCESS, ret );
583 630
584 /* Initialize the server addresses */ 631
632 /* Initialize the server address (this should give a safe loopback address + port, even on non-standard configs) */
585 { 633 {
586 struct addrinfo hints, *ai, *aip; 634 struct addrinfo hints, *ai, *aip;
587 memset(&hints, 0, sizeof(hints)); 635 memset(&hints, 0, sizeof(hints));
588 hints.ai_flags = AI_NUMERICSERV; 636 hints.ai_flags = AI_NUMERICSERV;
589 hints.ai_family = AF_INET; 637 hints.ai_family = AF_INET;
592 while (aip) { 640 while (aip) {
593 CHECK( 0, fd_ep_add_merge( &eps, aip->ai_addr, aip->ai_addrlen, EP_FL_DISC | EP_ACCEPTALL )); 641 CHECK( 0, fd_ep_add_merge( &eps, aip->ai_addr, aip->ai_addrlen, EP_FL_DISC | EP_ACCEPTALL ));
594 aip = aip->ai_next; 642 aip = aip->ai_next;
595 }; 643 };
596 freeaddrinfo(ai); 644 freeaddrinfo(ai);
645
646 CHECK( 0, FD_IS_LIST_EMPTY(&eps) ? 1 : 0 );
597 } 647 }
598 648
599 /* Start the server(s) */ 649 /* Start the server(s) */
600 { 650 {
601 /* TCP server */ 651 /* TCP server */
644 #if 0 694 #if 0
645 /* For debug: dump the object */ 695 /* For debug: dump the object */
646 fd_log_debug("Dumping CER\n"); 696 fd_log_debug("Dumping CER\n");
647 fd_msg_dump_walk(0, cer); 697 fd_msg_dump_walk(0, cer);
648 #endif 698 #endif
649 699
650 CHECK( 0, fd_msg_bufferize( cer, &cer_buf, &cer_sz ) ); 700 CHECK( 0, fd_msg_bufferize( cer, &cer_buf, &cer_sz ) );
651 CHECK( 0, fd_msg_free(cer) ); 701 CHECK( 0, fd_msg_free(cer) );
652 } 702 }
653 703
654 /* Simple TCP client / server test (no TLS) */ 704 /* Simple TCP client / server test (no TLS) */
657 707
658 memset(&cf, 0, sizeof(cf)); 708 memset(&cf, 0, sizeof(cf));
659 cf.proto = IPPROTO_TCP; 709 cf.proto = IPPROTO_TCP;
660 710
661 /* Start the client thread */ 711 /* Start the client thread */
662 CHECK( 0, pthread_create(&thr, 0, connect_thr, &cf) ); 712 CHECK( 0, pthread_create(&thr, NULL, connect_thr, &cf) );
663 713
664 /* Accept the connection of the client */ 714 /* Accept the connection of the client */
665 server_side = fd_cnx_serv_accept(listener); 715 server_side = fd_cnx_serv_accept(listener);
666 CHECK( 1, server_side ? 1 : 0 ); 716 CHECK( 1, server_side ? 1 : 0 );
667 CHECK( 0, fd_cnx_start_clear(server_side, 0) ); 717 CHECK( 0, fd_cnx_start_clear(server_side, 0) );
683 CHECK( 0, fd_cnx_receive(server_side, NULL, &rcv_buf, &rcv_sz)); 733 CHECK( 0, fd_cnx_receive(server_side, NULL, &rcv_buf, &rcv_sz));
684 CHECK( cer_sz, rcv_sz ); 734 CHECK( cer_sz, rcv_sz );
685 CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) ); 735 CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) );
686 free(rcv_buf); 736 free(rcv_buf);
687 737
688 /* Now close the connection */ 738 /* Now close the connections */
689 fd_cnx_destroy(client_side); 739 fd_cnx_destroy(client_side);
690 fd_cnx_destroy(server_side); 740 fd_cnx_destroy(server_side);
691 } 741 }
692 742
693 #ifndef DISABLE_SCTP 743 #ifndef DISABLE_SCTP
697 747
698 memset(&cf, 0, sizeof(cf)); 748 memset(&cf, 0, sizeof(cf));
699 cf.proto = IPPROTO_SCTP; 749 cf.proto = IPPROTO_SCTP;
700 750
701 /* Start the client thread */ 751 /* Start the client thread */
702 CHECK( 0, pthread_create(&thr, 0, connect_thr, &cf) ); 752 CHECK( 0, pthread_create(&thr, NULL, connect_thr, &cf) );
703 753
704 /* Accept the connection of the client */ 754 /* Accept the connection of the client */
705 server_side = fd_cnx_serv_accept(listener_sctp); 755 server_side = fd_cnx_serv_accept(listener_sctp);
706 CHECK( 1, server_side ? 1 : 0 ); 756 CHECK( 1, server_side ? 1 : 0 );
707 757
759 /* Set the key */ 809 /* Set the key */
760 CHECK_GNUTLS_DO( ret = gnutls_certificate_set_x509_key_mem( hf.creds, &client_cert, &client_priv, GNUTLS_X509_FMT_PEM), ); 810 CHECK_GNUTLS_DO( ret = gnutls_certificate_set_x509_key_mem( hf.creds, &client_cert, &client_priv, GNUTLS_X509_FMT_PEM), );
761 CHECK( GNUTLS_E_SUCCESS, ret ); 811 CHECK( GNUTLS_E_SUCCESS, ret );
762 812
763 /* Start the client thread */ 813 /* Start the client thread */
764 CHECK( 0, pthread_create(&thr, 0, connect_thr, &cf) ); 814 CHECK( 0, pthread_create(&thr, NULL, connect_thr, &cf) );
765 815
766 /* Accept the connection of the client */ 816 /* Accept the connection of the client */
767 server_side = fd_cnx_serv_accept(listener); 817 server_side = fd_cnx_serv_accept(listener);
768 CHECK( 1, server_side ? 1 : 0 ); 818 CHECK( 1, server_side ? 1 : 0 );
769 819
790 CHECK( cer_sz, rcv_sz ); 840 CHECK( cer_sz, rcv_sz );
791 CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) ); 841 CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) );
792 free(rcv_buf); 842 free(rcv_buf);
793 843
794 /* At this point in legacy Diameter we start the handshake */ 844 /* At this point in legacy Diameter we start the handshake */
795 CHECK( 0, pthread_create(&thr, 0, handshake_thr, &hf) ); 845 CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) );
796 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) ); 846 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) );
797 CHECK( 0, pthread_join(thr, NULL) ); 847 CHECK( 0, pthread_join(thr, NULL) );
798 CHECK( 0, hf.ret ); 848 CHECK( 0, hf.ret );
799 849
800 /* Send a few TLS protected message, and replies */ 850 /* Send a few TLS protected message, and replies */
812 free(rcv_buf); 862 free(rcv_buf);
813 } 863 }
814 864
815 865
816 /* Now close the connection */ 866 /* Now close the connection */
817 CHECK( 0, pthread_create(&thr, 0, destroy_thr, client_side) ); 867 CHECK( 0, pthread_create(&thr, NULL, destroy_thr, client_side) );
818 fd_cnx_destroy(server_side); 868 fd_cnx_destroy(server_side);
819 CHECK( 0, pthread_join(thr, NULL) ); 869 CHECK( 0, pthread_join(thr, NULL) );
820 870
821 /* Free the credentials */ 871 /* Free the credentials */
822 gnutls_certificate_free_keys(hf.creds); 872 gnutls_certificate_free_keys(hf.creds);
844 /* Set the key */ 894 /* Set the key */
845 CHECK_GNUTLS_DO( ret = gnutls_certificate_set_x509_key_mem( hf.creds, &client_cert, &client_priv, GNUTLS_X509_FMT_PEM), ); 895 CHECK_GNUTLS_DO( ret = gnutls_certificate_set_x509_key_mem( hf.creds, &client_cert, &client_priv, GNUTLS_X509_FMT_PEM), );
846 CHECK( GNUTLS_E_SUCCESS, ret ); 896 CHECK( GNUTLS_E_SUCCESS, ret );
847 897
848 /* Start the client thread */ 898 /* Start the client thread */
849 CHECK( 0, pthread_create(&thr, 0, connect_thr, &cf) ); 899 CHECK( 0, pthread_create(&thr, NULL, connect_thr, &cf) );
850 900
851 /* Accept the connection of the client */ 901 /* Accept the connection of the client */
852 server_side = fd_cnx_serv_accept(listener_sctp); 902 server_side = fd_cnx_serv_accept(listener_sctp);
853 CHECK( 1, server_side ? 1 : 0 ); 903 CHECK( 1, server_side ? 1 : 0 );
854 904
875 CHECK( cer_sz, rcv_sz ); 925 CHECK( cer_sz, rcv_sz );
876 CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) ); 926 CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) );
877 free(rcv_buf); 927 free(rcv_buf);
878 928
879 /* At this point in legacy Diameter we start the handshake */ 929 /* At this point in legacy Diameter we start the handshake */
880 CHECK( 0, pthread_create(&thr, 0, handshake_thr, &hf) ); 930 CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) );
881 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) ); 931 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) );
882 CHECK( 0, pthread_join(thr, NULL) ); 932 CHECK( 0, pthread_join(thr, NULL) );
883 CHECK( 0, hf.ret ); 933 CHECK( 0, hf.ret );
884 934
885 /* Send a few TLS protected message, and replies */ 935 /* Send a few TLS protected message, and replies */
897 free(rcv_buf); 947 free(rcv_buf);
898 } 948 }
899 949
900 950
901 /* Now close the connection */ 951 /* Now close the connection */
902 CHECK( 0, pthread_create(&thr, 0, destroy_thr, client_side) ); 952 CHECK( 0, pthread_create(&thr, NULL, destroy_thr, client_side) );
903 fd_cnx_destroy(server_side); 953 fd_cnx_destroy(server_side);
904 CHECK( 0, pthread_join(thr, NULL) ); 954 CHECK( 0, pthread_join(thr, NULL) );
905 955
906 /* Free the credentials */ 956 /* Free the credentials */
907 gnutls_certificate_free_keys(hf.creds); 957 gnutls_certificate_free_keys(hf.creds);
929 /* Set the key */ 979 /* Set the key */
930 CHECK_GNUTLS_DO( ret = gnutls_certificate_set_x509_key_mem( hf.creds, &client_cert, &client_priv, GNUTLS_X509_FMT_PEM), ); 980 CHECK_GNUTLS_DO( ret = gnutls_certificate_set_x509_key_mem( hf.creds, &client_cert, &client_priv, GNUTLS_X509_FMT_PEM), );
931 CHECK( GNUTLS_E_SUCCESS, ret ); 981 CHECK( GNUTLS_E_SUCCESS, ret );
932 982
933 /* Start the client thread */ 983 /* Start the client thread */
934 CHECK( 0, pthread_create(&thr, 0, connect_thr, &cf) ); 984 CHECK( 0, pthread_create(&thr, NULL, connect_thr, &cf) );
935 985
936 /* Accept the connection of the client */ 986 /* Accept the connection of the client */
937 server_side = fd_cnx_serv_accept(listener); 987 server_side = fd_cnx_serv_accept(listener);
938 CHECK( 1, server_side ? 1 : 0 ); 988 CHECK( 1, server_side ? 1 : 0 );
939 989
941 CHECK( 0, pthread_join( thr, (void *)&client_side ) ); 991 CHECK( 0, pthread_join( thr, (void *)&client_side ) );
942 CHECK( 1, client_side ? 1 : 0 ); 992 CHECK( 1, client_side ? 1 : 0 );
943 hf.cnx = client_side; 993 hf.cnx = client_side;
944 994
945 /* Start the handshake directly */ 995 /* Start the handshake directly */
946 CHECK( 0, pthread_create(&thr, 0, handshake_thr, &hf) ); 996 CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) );
947 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) ); 997 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) );
948 CHECK( 0, pthread_join(thr, NULL) ); 998 CHECK( 0, pthread_join(thr, NULL) );
949 CHECK( 0, hf.ret ); 999 CHECK( 0, hf.ret );
950 1000
951 /* Send a few TLS protected message, and replies */ 1001 /* Send a few TLS protected message, and replies */
962 CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) ); 1012 CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) );
963 free(rcv_buf); 1013 free(rcv_buf);
964 } 1014 }
965 1015
966 /* Now close the connection */ 1016 /* Now close the connection */
967 CHECK( 0, pthread_create(&thr, 0, destroy_thr, client_side) ); 1017 CHECK( 0, pthread_create(&thr, NULL, destroy_thr, client_side) );
968 fd_cnx_destroy(server_side); 1018 fd_cnx_destroy(server_side);
969 CHECK( 0, pthread_join(thr, NULL) ); 1019 CHECK( 0, pthread_join(thr, NULL) );
970 1020
971 /* Free the credentials */ 1021 /* Free the credentials */
972 gnutls_certificate_free_keys(hf.creds); 1022 gnutls_certificate_free_keys(hf.creds);
994 /* Set the key */ 1044 /* Set the key */
995 CHECK_GNUTLS_DO( ret = gnutls_certificate_set_x509_key_mem( hf.creds, &client_cert, &client_priv, GNUTLS_X509_FMT_PEM), ); 1045 CHECK_GNUTLS_DO( ret = gnutls_certificate_set_x509_key_mem( hf.creds, &client_cert, &client_priv, GNUTLS_X509_FMT_PEM), );
996 CHECK( GNUTLS_E_SUCCESS, ret ); 1046 CHECK( GNUTLS_E_SUCCESS, ret );
997 1047
998 /* Start the client thread */ 1048 /* Start the client thread */
999 CHECK( 0, pthread_create(&thr, 0, connect_thr, &cf) ); 1049 CHECK( 0, pthread_create(&thr, NULL, connect_thr, &cf) );
1000 1050
1001 /* Accept the connection of the client */ 1051 /* Accept the connection of the client */
1002 server_side = fd_cnx_serv_accept(listener_sctp); 1052 server_side = fd_cnx_serv_accept(listener_sctp);
1003 CHECK( 1, server_side ? 1 : 0 ); 1053 CHECK( 1, server_side ? 1 : 0 );
1004 1054
1006 CHECK( 0, pthread_join( thr, (void *)&client_side ) ); 1056 CHECK( 0, pthread_join( thr, (void *)&client_side ) );
1007 CHECK( 1, client_side ? 1 : 0 ); 1057 CHECK( 1, client_side ? 1 : 0 );
1008 hf.cnx = client_side; 1058 hf.cnx = client_side;
1009 1059
1010 /* Start the handshake directly */ 1060 /* Start the handshake directly */
1011 CHECK( 0, pthread_create(&thr, 0, handshake_thr, &hf) ); 1061 CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) );
1062 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) );
1063 CHECK( 0, pthread_join(thr, NULL) );
1064 CHECK( 0, hf.ret );
1065
1066 /* Send a few TLS protected messages, and replies */
1067 for (i = 0; i < 2 * NB_STREAMS; i++) {
1068 CHECK( 0, fd_cnx_send(server_side, cer_buf, cer_sz, 0));
1069 CHECK( 0, fd_cnx_receive(client_side, NULL, &rcv_buf, &rcv_sz));
1070 CHECK( cer_sz, rcv_sz );
1071 CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) );
1072 free(rcv_buf);
1073
1074 CHECK( 0, fd_cnx_send(client_side, cer_buf, cer_sz, 0));
1075 CHECK( 0, fd_cnx_receive(server_side, NULL, &rcv_buf, &rcv_sz));
1076 CHECK( cer_sz, rcv_sz );
1077 CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) );
1078 free(rcv_buf);
1079 }
1080
1081
1082 /* Now close the connection */
1083 CHECK( 0, pthread_create(&thr, NULL, destroy_thr, client_side) );
1084 fd_cnx_destroy(server_side);
1085 CHECK( 0, pthread_join(thr, NULL) );
1086
1087 /* Free the credentials */
1088 gnutls_certificate_free_keys(hf.creds);
1089 gnutls_certificate_free_cas(hf.creds);
1090 gnutls_certificate_free_credentials(hf.creds);
1091 }
1092 #endif /* DISABLE_SCTP */
1093
1094 /* Test with different number of streams between server and client */
1095 #ifndef DISABLE_SCTP
1096 {
1097 struct connect_flags cf;
1098 struct handshake_flags hf;
1099
1100 memset(&cf, 0, sizeof(cf));
1101 cf.proto = IPPROTO_SCTP;
1102
1103 memset(&hf, 0, sizeof(hf));
1104
1105 /* Initialize remote certificate */
1106 CHECK_GNUTLS_DO( ret = gnutls_certificate_allocate_credentials (&hf.creds), );
1107 CHECK( GNUTLS_E_SUCCESS, ret );
1108 /* Set the CA */
1109 CHECK_GNUTLS_DO( ret = gnutls_certificate_set_x509_trust_mem( hf.creds, &ca, GNUTLS_X509_FMT_PEM), );
1110 CHECK( 1, ret );
1111 /* Set the key */
1112 CHECK_GNUTLS_DO( ret = gnutls_certificate_set_x509_key_mem( hf.creds, &client_cert, &client_priv, GNUTLS_X509_FMT_PEM), );
1113 CHECK( GNUTLS_E_SUCCESS, ret );
1114
1115 /* Start the client thread with more streams than the server */
1116 fd_g_config->cnf_sctp_str = 2 * NB_STREAMS;
1117 CHECK( 0, pthread_create(&thr, NULL, connect_thr, &cf) );
1118
1119 /* Accept the connection of the client */
1120 server_side = fd_cnx_serv_accept(listener_sctp);
1121 CHECK( 1, server_side ? 1 : 0 );
1122
1123 /* Retrieve the client connection object */
1124 CHECK( 0, pthread_join( thr, (void *)&client_side ) );
1125 CHECK( 1, client_side ? 1 : 0 );
1126 hf.cnx = client_side;
1127
1128 /* Start the handshake directly */
1129 CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) );
1130 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) );
1131 CHECK( 0, pthread_join(thr, NULL) );
1132 CHECK( 0, hf.ret );
1133
1134 /* Send a few TLS protected message, and replies */
1135 for (i = 0; i < 4 * NB_STREAMS; i++) {
1136 CHECK( 0, fd_cnx_send(server_side, cer_buf, cer_sz, 0));
1137 CHECK( 0, fd_cnx_receive(client_side, NULL, &rcv_buf, &rcv_sz));
1138 CHECK( cer_sz, rcv_sz );
1139 CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) );
1140 free(rcv_buf);
1141
1142 CHECK( 0, fd_cnx_send(client_side, cer_buf, cer_sz, 0));
1143 CHECK( 0, fd_cnx_receive(server_side, NULL, &rcv_buf, &rcv_sz));
1144 CHECK( cer_sz, rcv_sz );
1145 CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) );
1146 free(rcv_buf);
1147 }
1148
1149 /* Now close the connection */
1150 CHECK( 0, pthread_create(&thr, NULL, destroy_thr, client_side) );
1151 fd_cnx_destroy(server_side);
1152 CHECK( 0, pthread_join(thr, NULL) );
1153
1154 /* Do the same test but with more streams on the server this time */
1155 fd_g_config->cnf_sctp_str = NB_STREAMS / 2;
1156 CHECK( 0, pthread_create(&thr, NULL, connect_thr, &cf) );
1157
1158 /* Accept the connection of the client */
1159 server_side = fd_cnx_serv_accept(listener_sctp);
1160 CHECK( 1, server_side ? 1 : 0 );
1161
1162 /* Retrieve the client connection object */
1163 CHECK( 0, pthread_join( thr, (void *)&client_side ) );
1164 CHECK( 1, client_side ? 1 : 0 );
1165 hf.cnx = client_side;
1166
1167 /* Start the handshake directly */
1168 CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) );
1012 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) ); 1169 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) );
1013 CHECK( 0, pthread_join(thr, NULL) ); 1170 CHECK( 0, pthread_join(thr, NULL) );
1014 CHECK( 0, hf.ret ); 1171 CHECK( 0, hf.ret );
1015 1172
1016 /* Send a few TLS protected message, and replies */ 1173 /* Send a few TLS protected message, and replies */
1026 CHECK( cer_sz, rcv_sz ); 1183 CHECK( cer_sz, rcv_sz );
1027 CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) ); 1184 CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) );
1028 free(rcv_buf); 1185 free(rcv_buf);
1029 } 1186 }
1030 1187
1031
1032 /* Now close the connection */ 1188 /* Now close the connection */
1033 CHECK( 0, pthread_create(&thr, 0, destroy_thr, client_side) ); 1189 CHECK( 0, pthread_create(&thr, NULL, destroy_thr, client_side) );
1034 fd_cnx_destroy(server_side);
1035 CHECK( 0, pthread_join(thr, NULL) );
1036
1037 /* Free the credentials */
1038 gnutls_certificate_free_keys(hf.creds);
1039 gnutls_certificate_free_cas(hf.creds);
1040 gnutls_certificate_free_credentials(hf.creds);
1041 }
1042 #endif /* DISABLE_SCTP */
1043
1044 /* Test with different number of streams between server and client */
1045 #ifndef DISABLE_SCTP
1046 {
1047 struct connect_flags cf;
1048 struct handshake_flags hf;
1049
1050 memset(&cf, 0, sizeof(cf));
1051 cf.proto = IPPROTO_SCTP;
1052
1053 memset(&hf, 0, sizeof(hf));
1054
1055 /* Initialize remote certificate */
1056 CHECK_GNUTLS_DO( ret = gnutls_certificate_allocate_credentials (&hf.creds), );
1057 CHECK( GNUTLS_E_SUCCESS, ret );
1058 /* Set the CA */
1059 CHECK_GNUTLS_DO( ret = gnutls_certificate_set_x509_trust_mem( hf.creds, &ca, GNUTLS_X509_FMT_PEM), );
1060 CHECK( 1, ret );
1061 /* Set the key */
1062 CHECK_GNUTLS_DO( ret = gnutls_certificate_set_x509_key_mem( hf.creds, &client_cert, &client_priv, GNUTLS_X509_FMT_PEM), );
1063 CHECK( GNUTLS_E_SUCCESS, ret );
1064
1065 /* Start the client thread with more streams than the server */
1066 fd_g_config->cnf_sctp_str = 2 * NB_STREAMS;
1067 CHECK( 0, pthread_create(&thr, 0, connect_thr, &cf) );
1068
1069 /* Accept the connection of the client */
1070 server_side = fd_cnx_serv_accept(listener_sctp);
1071 CHECK( 1, server_side ? 1 : 0 );
1072
1073 /* Retrieve the client connection object */
1074 CHECK( 0, pthread_join( thr, (void *)&client_side ) );
1075 CHECK( 1, client_side ? 1 : 0 );
1076 hf.cnx = client_side;
1077
1078 /* Start the handshake directly */
1079 CHECK( 0, pthread_create(&thr, 0, handshake_thr, &hf) );
1080 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) );
1081 CHECK( 0, pthread_join(thr, NULL) );
1082 CHECK( 0, hf.ret );
1083
1084 /* Send a few TLS protected message, and replies */
1085 for (i = 0; i < 4 * NB_STREAMS; i++) {
1086 CHECK( 0, fd_cnx_send(server_side, cer_buf, cer_sz, 0));
1087 CHECK( 0, fd_cnx_receive(client_side, NULL, &rcv_buf, &rcv_sz));
1088 CHECK( cer_sz, rcv_sz );
1089 CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) );
1090 free(rcv_buf);
1091
1092 CHECK( 0, fd_cnx_send(client_side, cer_buf, cer_sz, 0));
1093 CHECK( 0, fd_cnx_receive(server_side, NULL, &rcv_buf, &rcv_sz));
1094 CHECK( cer_sz, rcv_sz );
1095 CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) );
1096 free(rcv_buf);
1097 }
1098
1099 /* Now close the connection */
1100 CHECK( 0, pthread_create(&thr, 0, destroy_thr, client_side) );
1101 fd_cnx_destroy(server_side);
1102 CHECK( 0, pthread_join(thr, NULL) );
1103
1104 /* Do the same test but with more streams on the server this time */
1105 fd_g_config->cnf_sctp_str = NB_STREAMS / 2;
1106 CHECK( 0, pthread_create(&thr, 0, connect_thr, &cf) );
1107
1108 /* Accept the connection of the client */
1109 server_side = fd_cnx_serv_accept(listener_sctp);
1110 CHECK( 1, server_side ? 1 : 0 );
1111
1112 /* Retrieve the client connection object */
1113 CHECK( 0, pthread_join( thr, (void *)&client_side ) );
1114 CHECK( 1, client_side ? 1 : 0 );
1115 hf.cnx = client_side;
1116
1117 /* Start the handshake directly */
1118 CHECK( 0, pthread_create(&thr, 0, handshake_thr, &hf) );
1119 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) );
1120 CHECK( 0, pthread_join(thr, NULL) );
1121 CHECK( 0, hf.ret );
1122
1123 /* Send a few TLS protected message, and replies */
1124 for (i = 0; i < 2 * NB_STREAMS; i++) {
1125 CHECK( 0, fd_cnx_send(server_side, cer_buf, cer_sz, 0));
1126 CHECK( 0, fd_cnx_receive(client_side, NULL, &rcv_buf, &rcv_sz));
1127 CHECK( cer_sz, rcv_sz );
1128 CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) );
1129 free(rcv_buf);
1130
1131 CHECK( 0, fd_cnx_send(client_side, cer_buf, cer_sz, 0));
1132 CHECK( 0, fd_cnx_receive(server_side, NULL, &rcv_buf, &rcv_sz));
1133 CHECK( cer_sz, rcv_sz );
1134 CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) );
1135 free(rcv_buf);
1136 }
1137
1138 /* Now close the connection */
1139 CHECK( 0, pthread_create(&thr, 0, destroy_thr, client_side) );
1140 fd_cnx_destroy(server_side); 1190 fd_cnx_destroy(server_side);
1141 CHECK( 0, pthread_join(thr, NULL) ); 1191 CHECK( 0, pthread_join(thr, NULL) );
1142 1192
1143 1193
1144 /* Free the credentials */ 1194 /* Free the credentials */
1171 /* Set the key */ 1221 /* Set the key */
1172 CHECK_GNUTLS_DO( ret = gnutls_certificate_set_x509_key_mem( hf.creds, &notrust_cert, &notrust_priv, GNUTLS_X509_FMT_PEM), ); 1222 CHECK_GNUTLS_DO( ret = gnutls_certificate_set_x509_key_mem( hf.creds, &notrust_cert, &notrust_priv, GNUTLS_X509_FMT_PEM), );
1173 CHECK( GNUTLS_E_SUCCESS, ret ); 1223 CHECK( GNUTLS_E_SUCCESS, ret );
1174 1224
1175 /* Start the client thread */ 1225 /* Start the client thread */
1176 CHECK( 0, pthread_create(&thr, 0, connect_thr, &cf) ); 1226 CHECK( 0, pthread_create(&thr, NULL, connect_thr, &cf) );
1177 1227
1178 /* Accept the connection of the client */ 1228 /* Accept the connection of the client */
1179 server_side = fd_cnx_serv_accept(listener); 1229 server_side = fd_cnx_serv_accept(listener);
1180 CHECK( 1, server_side ? 1 : 0 ); 1230 CHECK( 1, server_side ? 1 : 0 );
1181 1231
1183 CHECK( 0, pthread_join( thr, (void *)&client_side ) ); 1233 CHECK( 0, pthread_join( thr, (void *)&client_side ) );
1184 CHECK( 1, client_side ? 1 : 0 ); 1234 CHECK( 1, client_side ? 1 : 0 );
1185 hf.cnx = client_side; 1235 hf.cnx = client_side;
1186 1236
1187 /* Start the handshake directly */ 1237 /* Start the handshake directly */
1188 CHECK( 0, pthread_create(&thr, 0, handshake_thr, &hf) ); 1238 CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) );
1189 CHECK( EINVAL, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) ); 1239 CHECK( EINVAL, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) );
1190 CHECK( 0, pthread_join(thr, NULL) ); 1240 CHECK( 0, pthread_join(thr, NULL) );
1191 1241
1192 /* Now close the connection */ 1242 /* Now close the connection */
1193 CHECK( 0, pthread_create(&thr, 0, destroy_thr, client_side) ); 1243 CHECK( 0, pthread_create(&thr, NULL, destroy_thr, client_side) );
1194 fd_cnx_destroy(server_side); 1244 fd_cnx_destroy(server_side);
1195 CHECK( 0, pthread_join(thr, NULL) ); 1245 CHECK( 0, pthread_join(thr, NULL) );
1196 1246
1197 /* Free the credentials */ 1247 /* Free the credentials */
1198 gnutls_certificate_free_keys(hf.creds); 1248 gnutls_certificate_free_keys(hf.creds);
1221 /* Set the key */ 1271 /* Set the key */
1222 CHECK_GNUTLS_DO( ret = gnutls_certificate_set_x509_key_mem( hf.creds, &notrust_cert, &notrust_priv, GNUTLS_X509_FMT_PEM), ); 1272 CHECK_GNUTLS_DO( ret = gnutls_certificate_set_x509_key_mem( hf.creds, &notrust_cert, &notrust_priv, GNUTLS_X509_FMT_PEM), );
1223 CHECK( GNUTLS_E_SUCCESS, ret ); 1273 CHECK( GNUTLS_E_SUCCESS, ret );
1224 1274
1225 /* Start the client thread */ 1275 /* Start the client thread */
1226 CHECK( 0, pthread_create(&thr, 0, connect_thr, &cf) ); 1276 CHECK( 0, pthread_create(&thr, NULL, connect_thr, &cf) );
1227 1277
1228 /* Accept the connection of the client */ 1278 /* Accept the connection of the client */
1229 server_side = fd_cnx_serv_accept(listener_sctp); 1279 server_side = fd_cnx_serv_accept(listener_sctp);
1230 CHECK( 1, server_side ? 1 : 0 ); 1280 CHECK( 1, server_side ? 1 : 0 );
1231 1281
1233 CHECK( 0, pthread_join( thr, (void *)&client_side ) ); 1283 CHECK( 0, pthread_join( thr, (void *)&client_side ) );
1234 CHECK( 1, client_side ? 1 : 0 ); 1284 CHECK( 1, client_side ? 1 : 0 );
1235 hf.cnx = client_side; 1285 hf.cnx = client_side;
1236 1286
1237 /* Start the handshake directly */ 1287 /* Start the handshake directly */
1238 CHECK( 0, pthread_create(&thr, 0, handshake_thr, &hf) ); 1288 CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) );
1239 CHECK( EINVAL, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) ); 1289 CHECK( EINVAL, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) );
1240 CHECK( 0, pthread_join(thr, NULL) ); 1290 CHECK( 0, pthread_join(thr, NULL) );
1241 1291
1242 /* Now close the connection */ 1292 /* Now close the connection */
1243 CHECK( 0, pthread_create(&thr, 0, destroy_thr, client_side) ); 1293 CHECK( 0, pthread_create(&thr, NULL, destroy_thr, client_side) );
1244 fd_cnx_destroy(server_side); 1294 fd_cnx_destroy(server_side);
1245 CHECK( 0, pthread_join(thr, NULL) ); 1295 CHECK( 0, pthread_join(thr, NULL) );
1246 1296
1247 /* Free the credentials */ 1297 /* Free the credentials */
1248 gnutls_certificate_free_keys(hf.creds); 1298 gnutls_certificate_free_keys(hf.creds);
1270 /* Set the key */ 1320 /* Set the key */
1271 CHECK_GNUTLS_DO( ret = gnutls_certificate_set_x509_key_mem( hf.creds, &expired_cert, &expired_priv, GNUTLS_X509_FMT_PEM), ); 1321 CHECK_GNUTLS_DO( ret = gnutls_certificate_set_x509_key_mem( hf.creds, &expired_cert, &expired_priv, GNUTLS_X509_FMT_PEM), );
1272 CHECK( GNUTLS_E_SUCCESS, ret ); 1322 CHECK( GNUTLS_E_SUCCESS, ret );
1273 1323
1274 /* Start the client thread */ 1324 /* Start the client thread */
1275 CHECK( 0, pthread_create(&thr, 0, connect_thr, &cf) ); 1325 CHECK( 0, pthread_create(&thr, NULL, connect_thr, &cf) );
1276 1326
1277 /* Accept the connection of the client */ 1327 /* Accept the connection of the client */
1278 server_side = fd_cnx_serv_accept(listener); 1328 server_side = fd_cnx_serv_accept(listener);
1279 CHECK( 1, server_side ? 1 : 0 ); 1329 CHECK( 1, server_side ? 1 : 0 );
1280 1330
1282 CHECK( 0, pthread_join( thr, (void *)&client_side ) ); 1332 CHECK( 0, pthread_join( thr, (void *)&client_side ) );
1283 CHECK( 1, client_side ? 1 : 0 ); 1333 CHECK( 1, client_side ? 1 : 0 );
1284 hf.cnx = client_side; 1334 hf.cnx = client_side;
1285 1335
1286 /* Start the handshake directly */ 1336 /* Start the handshake directly */
1287 CHECK( 0, pthread_create(&thr, 0, handshake_thr, &hf) ); 1337 CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) );
1288 CHECK( EINVAL, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) ); 1338 CHECK( EINVAL, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) );
1289 CHECK( 0, pthread_join(thr, NULL) ); 1339 CHECK( 0, pthread_join(thr, NULL) );
1290 1340
1291 /* Now close the connection */ 1341 /* Now close the connection */
1292 CHECK( 0, pthread_create(&thr, 0, destroy_thr, client_side) ); 1342 CHECK( 0, pthread_create(&thr, NULL, destroy_thr, client_side) );
1293 fd_cnx_destroy(server_side); 1343 fd_cnx_destroy(server_side);
1294 CHECK( 0, pthread_join(thr, NULL) ); 1344 CHECK( 0, pthread_join(thr, NULL) );
1295 1345
1296 /* Free the credentials */ 1346 /* Free the credentials */
1297 gnutls_certificate_free_keys(hf.creds); 1347 gnutls_certificate_free_keys(hf.creds);
1319 /* Set the key */ 1369 /* Set the key */
1320 CHECK_GNUTLS_DO( ret = gnutls_certificate_set_x509_key_mem( hf.creds, &client_cert, &client_priv, GNUTLS_X509_FMT_PEM), ); 1370 CHECK_GNUTLS_DO( ret = gnutls_certificate_set_x509_key_mem( hf.creds, &client_cert, &client_priv, GNUTLS_X509_FMT_PEM), );
1321 CHECK( GNUTLS_E_SUCCESS, ret ); 1371 CHECK( GNUTLS_E_SUCCESS, ret );
1322 1372
1323 /* Start the client thread */ 1373 /* Start the client thread */
1324 CHECK( 0, pthread_create(&thr, 0, connect_thr, &cf) ); 1374 CHECK( 0, pthread_create(&thr, NULL, connect_thr, &cf) );
1325 1375
1326 /* Accept the connection of the client */ 1376 /* Accept the connection of the client */
1327 server_side = fd_cnx_serv_accept(listener); 1377 server_side = fd_cnx_serv_accept(listener);
1328 CHECK( 1, server_side ? 1 : 0 ); 1378 CHECK( 1, server_side ? 1 : 0 );
1329 1379
1334 1384
1335 /* Set the correct hostname we expect from the client (in the server) */ 1385 /* Set the correct hostname we expect from the client (in the server) */
1336 fd_cnx_sethostname(server_side, "client.test"); 1386 fd_cnx_sethostname(server_side, "client.test");
1337 1387
1338 /* Start the handshake, check it is successful */ 1388 /* Start the handshake, check it is successful */
1339 CHECK( 0, pthread_create(&thr, 0, handshake_thr, &hf) ); 1389 CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) );
1340 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) ); 1390 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) );
1341 CHECK( 0, pthread_join(thr, NULL) ); 1391 CHECK( 0, pthread_join(thr, NULL) );
1342 CHECK( 0, hf.ret ); 1392 CHECK( 0, hf.ret );
1343 1393
1344 /* Now close the connection */ 1394 /* Now close the connection */
1345 CHECK( 0, pthread_create(&thr, 0, destroy_thr, client_side) ); 1395 CHECK( 0, pthread_create(&thr, NULL, destroy_thr, client_side) );
1346 fd_cnx_destroy(server_side); 1396 fd_cnx_destroy(server_side);
1347 CHECK( 0, pthread_join(thr, NULL) ); 1397 CHECK( 0, pthread_join(thr, NULL) );
1348 1398
1349 /* Do it again with an invalid hostname */ 1399 /* Do it again with an invalid hostname */
1350 CHECK( 0, pthread_create(&thr, 0, connect_thr, &cf) ); 1400 CHECK( 0, pthread_create(&thr, NULL, connect_thr, &cf) );
1351 1401
1352 /* Accept the connection of the client */ 1402 /* Accept the connection of the client */
1353 server_side = fd_cnx_serv_accept(listener); 1403 server_side = fd_cnx_serv_accept(listener);
1354 CHECK( 1, server_side ? 1 : 0 ); 1404 CHECK( 1, server_side ? 1 : 0 );
1355 1405
1360 1410
1361 /* Set the correct hostname we expect from the client (in the server) */ 1411 /* Set the correct hostname we expect from the client (in the server) */
1362 fd_cnx_sethostname(server_side, "nomatch.test"); 1412 fd_cnx_sethostname(server_side, "nomatch.test");
1363 1413
1364 /* Start the handshake, check it is successful */ 1414 /* Start the handshake, check it is successful */
1365 CHECK( 0, pthread_create(&thr, 0, handshake_thr, &hf) ); 1415 CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) );
1366 CHECK( EINVAL, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) ); 1416 CHECK( EINVAL, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) );
1367 CHECK( 0, pthread_join(thr, NULL) ); 1417 CHECK( 0, pthread_join(thr, NULL) );
1368 1418
1369 /* Now close the connection */ 1419 /* Now close the connection */
1370 CHECK( 0, pthread_create(&thr, 0, destroy_thr, client_side) ); 1420 CHECK( 0, pthread_create(&thr, NULL, destroy_thr, client_side) );
1371 fd_cnx_destroy(server_side); 1421 fd_cnx_destroy(server_side);
1372 CHECK( 0, pthread_join(thr, NULL) ); 1422 CHECK( 0, pthread_join(thr, NULL) );
1373 1423
1374 /* Free the credentials */ 1424 /* Free the credentials */
1375 gnutls_certificate_free_keys(hf.creds); 1425 gnutls_certificate_free_keys(hf.creds);
1402 /* Set the key */ 1452 /* Set the key */
1403 CHECK_GNUTLS_DO( ret = gnutls_certificate_set_x509_key_mem( hf.creds, &client_cert, &client_priv, GNUTLS_X509_FMT_PEM), ); 1453 CHECK_GNUTLS_DO( ret = gnutls_certificate_set_x509_key_mem( hf.creds, &client_cert, &client_priv, GNUTLS_X509_FMT_PEM), );
1404 CHECK( GNUTLS_E_SUCCESS, ret ); 1454 CHECK( GNUTLS_E_SUCCESS, ret );
1405 1455
1406 /* Start the client thread */ 1456 /* Start the client thread */
1407 CHECK( 0, pthread_create(&thr, 0, connect_thr, &cf) ); 1457 CHECK( 0, pthread_create(&thr, NULL, connect_thr, &cf) );
1408 1458
1409 /* Accept the connection of the client */ 1459 /* Accept the connection of the client */
1410 server_side = fd_cnx_serv_accept(listener); 1460 server_side = fd_cnx_serv_accept(listener);
1411 CHECK( 1, server_side ? 1 : 0 ); 1461 CHECK( 1, server_side ? 1 : 0 );
1412 1462
1414 CHECK( 0, pthread_join( thr, (void *)&client_side ) ); 1464 CHECK( 0, pthread_join( thr, (void *)&client_side ) );
1415 CHECK( 1, client_side ? 1 : 0 ); 1465 CHECK( 1, client_side ? 1 : 0 );
1416 hf.cnx = client_side; 1466 hf.cnx = client_side;
1417 1467
1418 /* Start the handshake */ 1468 /* Start the handshake */
1419 CHECK( 0, pthread_create(&thr, 0, handshake_thr, &hf) ); 1469 CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) );
1420 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) ); 1470 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) );
1421 CHECK( 0, pthread_join(thr, NULL) ); 1471 CHECK( 0, pthread_join(thr, NULL) );
1422 CHECK( 0, hf.ret ); 1472 CHECK( 0, hf.ret );
1423 1473
1424 /* Test some simple functions */ 1474 /* Test some simple functions */
1456 free(rcv_buf); 1506 free(rcv_buf);
1457 } while (ev_code != FDEVP_CNX_MSG_RECV); 1507 } while (ev_code != FDEVP_CNX_MSG_RECV);
1458 fd_event_destroy(&myfifo, free); 1508 fd_event_destroy(&myfifo, free);
1459 1509
1460 /* Now close the connection */ 1510 /* Now close the connection */
1461 CHECK( 0, pthread_create(&thr, 0, destroy_thr, client_side) ); 1511 CHECK( 0, pthread_create(&thr, NULL, destroy_thr, client_side) );
1462 fd_cnx_destroy(server_side); 1512 fd_cnx_destroy(server_side);
1463 CHECK( 0, pthread_join(thr, NULL) ); 1513 CHECK( 0, pthread_join(thr, NULL) );
1464 1514
1465 /* Free the credentials */ 1515 /* Free the credentials */
1466 gnutls_certificate_free_keys(hf.creds); 1516 gnutls_certificate_free_keys(hf.creds);
1494 /* Set the key */ 1544 /* Set the key */
1495 CHECK_GNUTLS_DO( ret = gnutls_certificate_set_x509_key_mem( hf.creds, &client_cert, &client_priv, GNUTLS_X509_FMT_PEM), ); 1545 CHECK_GNUTLS_DO( ret = gnutls_certificate_set_x509_key_mem( hf.creds, &client_cert, &client_priv, GNUTLS_X509_FMT_PEM), );
1496 CHECK( GNUTLS_E_SUCCESS, ret ); 1546 CHECK( GNUTLS_E_SUCCESS, ret );
1497 1547
1498 /* Start the client thread */ 1548 /* Start the client thread */
1499 CHECK( 0, pthread_create(&thr, 0, connect_thr, &cf) ); 1549 CHECK( 0, pthread_create(&thr, NULL, connect_thr, &cf) );
1500 1550
1501 /* Accept the connection of the client */ 1551 /* Accept the connection of the client */
1502 server_side = fd_cnx_serv_accept(listener_sctp); 1552 server_side = fd_cnx_serv_accept(listener_sctp);
1503 CHECK( 1, server_side ? 1 : 0 ); 1553 CHECK( 1, server_side ? 1 : 0 );
1504 1554
1506 CHECK( 0, pthread_join( thr, (void *)&client_side ) ); 1556 CHECK( 0, pthread_join( thr, (void *)&client_side ) );
1507 CHECK( 1, client_side ? 1 : 0 ); 1557 CHECK( 1, client_side ? 1 : 0 );
1508 hf.cnx = client_side; 1558 hf.cnx = client_side;
1509 1559
1510 /* Start the handshake */ 1560 /* Start the handshake */
1511 CHECK( 0, pthread_create(&thr, 0, handshake_thr, &hf) ); 1561 CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) );
1512 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) ); 1562 CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) );
1513 CHECK( 0, pthread_join(thr, NULL) ); 1563 CHECK( 0, pthread_join(thr, NULL) );
1514 CHECK( 0, hf.ret ); 1564 CHECK( 0, hf.ret );
1515 1565
1516 /* Test some simple functions */ 1566 /* Test some simple functions */
1547 CHECK( 0, fd_event_timedget(myfifo, &now, ETIMEDOUT, &ev_code, NULL, (void *)&rcv_buf) ); 1597 CHECK( 0, fd_event_timedget(myfifo, &now, ETIMEDOUT, &ev_code, NULL, (void *)&rcv_buf) );
1548 free(rcv_buf); 1598 free(rcv_buf);
1549 } while (ev_code != FDEVP_CNX_MSG_RECV); 1599 } while (ev_code != FDEVP_CNX_MSG_RECV);
1550 1600
1551 /* Now close the connection */ 1601 /* Now close the connection */
1552 CHECK( 0, pthread_create(&thr, 0, destroy_thr, client_side) ); 1602 CHECK( 0, pthread_create(&thr, NULL, destroy_thr, client_side) );
1553 fd_cnx_destroy(server_side); 1603 fd_cnx_destroy(server_side);
1554 CHECK( 0, pthread_join(thr, NULL) ); 1604 CHECK( 0, pthread_join(thr, NULL) );
1555 1605
1556 fd_event_destroy(&myfifo, free); 1606 fd_event_destroy(&myfifo, free);
1557 1607
1578 memset(&cf, 0, sizeof(cf)); 1628 memset(&cf, 0, sizeof(cf));
1579 cf.proto = IPPROTO_TCP; 1629 cf.proto = IPPROTO_TCP;
1580 cf.expect_failure = 1; 1630 cf.expect_failure = 1;
1581 1631
1582 /* Start the client thread, that should fail */ 1632 /* Start the client thread, that should fail */
1583 CHECK( 0, pthread_create(&thr, 0, connect_thr, &cf) ); 1633 CHECK( 0, pthread_create(&thr, NULL, connect_thr, &cf) );
1584 CHECK( 0, pthread_join( thr, (void *)&client_side ) ); 1634 CHECK( 0, pthread_join( thr, (void *)&client_side ) );
1585 CHECK( 0, client_side ? 1 : 0 ); 1635 CHECK( 0, client_side ? 1 : 0 );
1586 } 1636 }
1587 1637
1588 #ifndef DISABLE_SCTP 1638 #ifndef DISABLE_SCTP
1592 memset(&cf, 0, sizeof(cf)); 1642 memset(&cf, 0, sizeof(cf));
1593 cf.proto = IPPROTO_SCTP; 1643 cf.proto = IPPROTO_SCTP;
1594 cf.expect_failure = 1; 1644 cf.expect_failure = 1;
1595 1645
1596 /* Start the client thread, that should fail */ 1646 /* Start the client thread, that should fail */
1597 CHECK( 0, pthread_create(&thr, 0, connect_thr, &cf) ); 1647 CHECK( 0, pthread_create(&thr, NULL, connect_thr, &cf) );
1598 CHECK( 0, pthread_join( thr, (void *)&client_side ) ); 1648 CHECK( 0, pthread_join( thr, (void *)&client_side ) );
1599 CHECK( 0, client_side ? 1 : 0 ); 1649 CHECK( 0, client_side ? 1 : 0 );
1600 } 1650 }
1601 #endif /* DISABLE_SCTP */ 1651 #endif /* DISABLE_SCTP */
1602 1652
"Welcome to our mercurial repository"