Navigation


Changeset 807:09f8f0c4f4a4 in freeDiameter for libfdcore/sctps.c


Ignore:
Timestamp:
Aug 24, 2012, 7:15:48 AM (12 years ago)
Author:
Sebastien Decugis <sdecugis@freediameter.net>
Branch:
default
Phase:
public
Message:

Several changes to support GnuTLS 3.x in a more efficient way

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libfdcore/sctps.c

    r803 r807  
    105105                       
    106106                        case FDEVP_CNX_ERROR:
    107                                 fd_cnx_markerror(conn);
    108107                                goto out;
    109108                               
     
    121120        /* Signal termination of the connection to all decipher threads */
    122121        for (strid = 0; strid < conn->cc_sctp_para.pairs; strid++) {
    123                 if (conn->cc_sctps_data.array[strid].raw_recv)
     122                if (conn->cc_sctps_data.array[strid].raw_recv) {
    124123                        CHECK_FCT_DO(fd_event_send(conn->cc_sctps_data.array[strid].raw_recv, FDEVP_CNX_ERROR, 0, NULL), goto fatal );
    125         }
     124                }
     125        }
     126        fd_cnx_markerror(conn);
    126127        TRACE_DEBUG(FULL, "Thread terminated");
    127128        return NULL;
     
    171172        CHECK_PARAMS_DO( tr && data, { errno = EINVAL; return -1; } );
    172173       
    173         CHECK_FCT_DO( fd_sctp_sendstr(ctx->parent, ctx->strid, (uint8_t *)data, len), /* errno is already set */ return -1 );
     174        CHECK_FCT_DO( fd_sctp_sendstr(ctx->parent, ctx->strid, (uint8_t *)data, len), return -1 );
    174175       
    175176        return len;
     
    184185       
    185186        TRACE_ENTRY("%p %p %zd", tr, buf, len);
    186         CHECK_PARAMS_DO( tr && buf, { errno = EINVAL; return -1; } );
     187        CHECK_PARAMS_DO( tr && buf, { errno = EINVAL; goto error; } );
    187188       
    188189        /* If we don't have data available now, pull new message from the fifo -- this is blocking (until the queue is destroyed) */
    189190        if (!ctx->partial.buf) {
    190191                int ev;
    191                 CHECK_FCT_DO( errno = fd_event_get(ctx->raw_recv, &ev, &ctx->partial.bufsz, (void *)&ctx->partial.buf), return -1 );
    192                 if (ev == FDEVP_CNX_ERROR)
    193                         return 0; /* connection closed */
     192                CHECK_FCT_DO( errno = fd_event_get(ctx->raw_recv, &ev, &ctx->partial.bufsz, (void *)&ctx->partial.buf), goto error );
     193                if (ev == FDEVP_CNX_ERROR) {
     194                        /* Documentations says to return 0 on connection closed, but it does hang within gnutls_handshake */
     195                        return -1;
     196                }
    194197        }
    195198               
     
    216219        /* We are done */
    217220        return pulled;
     221       
     222error:
     223        gnutls_transport_set_errno (ctx->session, errno);
     224        return -1;
    218225}
    219226
     
    463470       
    464471        TRACE_DEBUG(FULL, "Starting TLS resumed handshake on stream %hu", ctx->strid);
    465 #ifdef GNUTLS_VERSION_310
    466         GNUTLS_TRACE( gnutls_handshake_set_timeout( ctx->session, GNUTLS_DEFAULT_HANDSHAKE_TIMEOUT));
    467 #endif /* GNUTLS_VERSION_310 */
     472
    468473        CHECK_GNUTLS_DO( gnutls_handshake( ctx->session ), return NULL);
    469474                       
    470475        GNUTLS_TRACE( resumed = gnutls_session_is_resumed(ctx->session) );
     476        #ifndef GNUTLS_VERSION_300
    471477        if (!resumed) {
    472478                /* Check the credentials here also */
    473479                CHECK_FCT_DO( fd_tls_verify_credentials(ctx->session, ctx->parent, 0), return NULL );
    474480        }
     481        #endif /* GNUTLS_VERSION_300 */
    475482        if (TRACE_BOOL(FULL)) {
    476483                if (resumed) {
    477484                        fd_log_debug("Session was resumed successfully on stream %hu (conn: '%s')\n", ctx->strid, fd_cnx_getid(ctx->parent));
    478485                } else {
    479                         fd_log_debug("Session was NOT resumed on stream %hu  (full handshake + verif) (conn: '%s')\n", ctx->strid, fd_cnx_getid(ctx->parent));
     486                        fd_log_debug("Session was NOT resumed on stream %hu  (full handshake) (conn: '%s')\n", ctx->strid, fd_cnx_getid(ctx->parent));
    480487                }
    481488        }
     
    555562                CHECK_FCT( fd_tls_prepare(&conn->cc_sctps_data.array[i].session, conn->cc_tls_para.mode, priority, alt_creds) );
    556563               
     564                /* additional initialization for gnutls 3.x */
     565                #ifdef GNUTLS_VERSION_300
     566                        /* the verify function has already been set in the global initialization in config.c */
     567
     568                /* fd_tls_verify_credentials_2 uses the connection */
     569                gnutls_session_set_ptr (conn->cc_sctps_data.array[i].session, (void *) conn);
     570
     571                if ((conn->cc_tls_para.cn != NULL) && (conn->cc_tls_para.mode == GNUTLS_CLIENT)) {
     572                        /* this might allow virtual hosting on the remote peer */
     573                        CHECK_GNUTLS_DO( gnutls_server_name_set (conn->cc_sctps_data.array[i].session, GNUTLS_NAME_DNS, conn->cc_tls_para.cn, strlen(conn->cc_tls_para.cn)), /* ignore failure */);
     574                }
     575
     576                #endif /* GNUTLS_VERSION_300 */
     577
     578                #ifdef GNUTLS_VERSION_310
     579                GNUTLS_TRACE( gnutls_handshake_set_timeout( conn->cc_sctps_data.array[i].session, GNUTLS_DEFAULT_HANDSHAKE_TIMEOUT));
     580                #endif /* GNUTLS_VERSION_310 */
     581
    557582                /* For the client, copy data from master session; for the server, set session resuming pointers */
    558583                if (conn->cc_tls_para.mode == GNUTLS_CLIENT) {
Note: See TracChangeset for help on using the changeset viewer.