Navigation


Changeset 1181:22de21feec64 in freeDiameter for tests


Ignore:
Timestamp:
Jun 5, 2013, 8:22:26 PM (11 years ago)
Author:
Sebastien Decugis <sdecugis@freediameter.net>
Branch:
default
Phase:
public
Message:

Preparing for DTLS support

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/testcnx.c

    r1127 r1181  
    549549        struct cnxctx * cnx;
    550550        gnutls_certificate_credentials_t        creds;
     551        int algo;
    551552        int ret;
    552553};
     
    557558        struct handshake_flags * hf = arg;
    558559        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);
    560561        return NULL;
    561562}
     
    864865                /* At this point in legacy Diameter we start the handshake */
    865866                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) );
    867868                CHECK( 0, pthread_join(thr, NULL) );
    868869                CHECK( 0, hf.ret );
     
    905906               
    906907                memset(&hf, 0, sizeof(hf));
     908                hf.algo = ALGO_HANDSHAKE_3436; /* this is mandatory for old TLS mechanism */
    907909               
    908910                /* Initialize remote certificate */
     
    949951                /* At this point in legacy Diameter we start the handshake */
    950952                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) );
    952954                CHECK( 0, pthread_join(thr, NULL) );
    953955                CHECK( 0, hf.ret );
     
    10151017                /* Start the handshake directly */
    10161018                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) );
    10181020                CHECK( 0, pthread_join(thr, NULL) );
    10191021                CHECK( 0, hf.ret );
     
    10461048       
    10471049#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)
    10491055        {
    10501056                struct connect_flags cf;
     
    10801086                /* Start the handshake directly */
    10811087                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) );
    10831089                CHECK( 0, pthread_join(thr, NULL) );
    10841090                CHECK( 0, hf.ret );
     
    11101116                gnutls_certificate_free_credentials(hf.creds);
    11111117        }
    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) */
    11161120        {
    11171121                struct connect_flags cf;
     
    11221126               
    11231127                memset(&hf, 0, sizeof(hf));
     1128                hf.algo = ALGO_HANDSHAKE_3436; /* this is mandatory for old TLS mechanism */
    11241129               
    11251130                /* Initialize remote certificate */
     
    11331138                CHECK( GNUTLS_E_SUCCESS, ret );
    11341139               
    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 */
    11371141                CHECK( 0, pthread_create(&thr, NULL, connect_thr, &cf) );
    11381142
     
    11481152                /* Start the handshake directly */
    11491153                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) );
    11511226                CHECK( 0, pthread_join(thr, NULL) );
    11521227                CHECK( 0, hf.ret );
     
    11871262                /* Start the handshake directly */
    11881263                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) );
    11901265                CHECK( 0, pthread_join(thr, NULL) );
    11911266                CHECK( 0, hf.ret );
     
    12171292                gnutls_certificate_free_credentials(hf.creds);
    12181293        }
     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       
    12191401#endif /* DISABLE_SCTP */
    12201402       
     
    12571439                /* Start the handshake directly */
    12581440                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) );
    12601442                fd_cnx_destroy(server_side);
    12611443               
     
    12741456        /* Same in SCTP */
    12751457#ifndef DISABLE_SCTP
     1458        /* DTLS */
     1459        TODO("Enabled after DTLS implementation");
     1460        if (0)
    12761461        {
    12771462                struct connect_flags cf;
     
    13081493                /* Start the handshake directly */
    13091494                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, &notrust_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, &notrust_cert, &notrust_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) );
    13111546                fd_cnx_destroy(server_side);
    13121547                CHECK( 0, pthread_join(thr, NULL) );
     
    13571592                /* Start the handshake directly */
    13581593                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) );
    13601595                fd_cnx_destroy(server_side);
    13611596                CHECK( 0, pthread_join(thr, NULL) );
     
    14091644                /* Start the handshake, check it is successful */
    14101645                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) );
    14121647                CHECK( 0, pthread_join(thr, NULL) );
    14131648                CHECK( 0, hf.ret );
     
    14351670                /* Start the handshake, check it is successful */
    14361671                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) );
    14381673                fd_cnx_destroy(server_side);
    14391674                CHECK( 0, pthread_join(thr, NULL) );
     
    14891724                /* Start the handshake */
    14901725                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) );
    14921727                CHECK( 0, pthread_join(thr, NULL) );
    14931728                CHECK( 0, hf.ret );
     
    15431778#ifndef DISABLE_SCTP
    15441779        /* And re-test with a SCTP connection */
     1780        TODO("Enabled after DTLS implementation");
     1781        if (0)
    15451782        {
    15461783                struct connect_flags cf;
     
    15821819                /* Start the handshake */
    15831820                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) );
    15851822                CHECK( 0, pthread_join(thr, NULL) );
    15861823                CHECK( 0, hf.ret );
     
    16331870                gnutls_certificate_free_credentials(hf.creds);
    16341871        }
     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        }
    16351965#endif /* DISABLE_SCTP */
    16361966       
Note: See TracChangeset for help on using the changeset viewer.