Navigation


Changeset 393:6d9ee5ab79e5 in freeDiameter


Ignore:
Timestamp:
Jul 7, 2010, 2:17:04 PM (14 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Added test case for ticket #6

File:
1 edited

Legend:

Unmodified
Added
Removed
  • freeDiameter/tests/testcnx.c

    r258 r393  
    10421042#endif /* DISABLE_SCTP */
    10431043       
     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);
     1141                CHECK( 0, pthread_join(thr, NULL) );
     1142               
     1143               
     1144                /* Free the credentials */
     1145                gnutls_certificate_free_keys(hf.creds);
     1146                gnutls_certificate_free_cas(hf.creds);
     1147                gnutls_certificate_free_credentials(hf.creds);
     1148        }
     1149#endif /* DISABLE_SCTP */
     1150       
     1151       
    10441152        /* Basic operation tested successfully, now test we detect error conditions */
    10451153       
     
    15061614#endif /* DISABLE_SCTP */
    15071615       
     1616
    15081617        /* Destroy the servers */
    15091618        {
Note: See TracChangeset for help on using the changeset viewer.