picoquic/tls_api.c
int picoquic_tlscontext_create(picoquic_quic_t* quic, picoquic_cnx_t* cnx, uint64_t current_time)
{
    int ret = 0;
    /* allocate a context structure */
    picoquic_tls_ctx_t* ctx = (picoquic_tls_ctx_t*)malloc(sizeof(picoquic_tls_ctx_t));

    /* Create the TLS context */
    if (ctx == NULL) {
        ret = -1;
    } else {
        memset(ctx, 0, sizeof(picoquic_tls_ctx_t));

        ctx->cnx = cnx;

        ctx->handshake_properties.collect_extension = picoquic_tls_collect_extensions_cb;
        ctx->handshake_properties.collected_extensions = picoquic_tls_collected_extensions_cb;
        ctx->client_mode = cnx->client_mode;

        ctx->tls = ptls_new((ptls_context_t*)quic->tls_master_ctx,
            (ctx->client_mode) ? 0 : 1);
        *ptls_get_data_ptr(ctx->tls) = cnx;

        if (ctx->tls == NULL) {
            free(ctx);
            ctx = NULL;
            ret = -1;
        } else if (!ctx->client_mode) {
            /* A server side connection, but no cert/key where given for the master context */
            if (((ptls_context_t*)quic->tls_master_ctx)->encrypt_ticket == NULL) {
                ret = PICOQUIC_ERROR_TLS_SERVER_CON_WITHOUT_CERT;
                picoquic_tlscontext_free(ctx);
                ctx = NULL;
            }

            if (ctx != NULL) {
                /* The server should never attempt a stateless retry */
                ctx->handshake_properties.server.enforce_retry = 0;
                ctx->handshake_properties.server.retry_uses_cookie = 0;
                ctx->handshake_properties.server.cookie.key = NULL;
                ctx->handshake_properties.server.cookie.additional_data.base = NULL;
                ctx->handshake_properties.server.cookie.additional_data.len = 0;
            }
        }
    }
    
    if (cnx->tls_ctx != NULL) {
        picoquic_tlscontext_free(cnx->tls_ctx);
    }

    cnx->tls_ctx = (void*)ctx;

    return ret;
}
/*
 * Creation of a TLS context.
 * This includes setting the handshake properties that will later be
 * used during the TLS handshake.
 */
Creation of a TLS context.
This includes setting the handshake properties that will later be
used during the TLS handshake.
Creation of a TLS context . This includes setting the handshake properties that will later be used during the TLS handshake .
int picoquic_tlscontext_create(picoquic_quic_t* quic, picoquic_cnx_t* cnx, uint64_t current_time)
{
    int ret = 0;
    picoquic_tls_ctx_t* ctx = (picoquic_tls_ctx_t*)malloc(sizeof(picoquic_tls_ctx_t));
    if (ctx == NULL) {
        ret = -1;
    } else {
        memset(ctx, 0, sizeof(picoquic_tls_ctx_t));
        ctx->cnx = cnx;
        ctx->handshake_properties.collect_extension = picoquic_tls_collect_extensions_cb;
        ctx->handshake_properties.collected_extensions = picoquic_tls_collected_extensions_cb;
        ctx->client_mode = cnx->client_mode;
        ctx->tls = ptls_new((ptls_context_t*)quic->tls_master_ctx,
            (ctx->client_mode) ? 0 : 1);
        *ptls_get_data_ptr(ctx->tls) = cnx;
        if (ctx->tls == NULL) {
            free(ctx);
            ctx = NULL;
            ret = -1;
        } else if (!ctx->client_mode) {
            if (((ptls_context_t*)quic->tls_master_ctx)->encrypt_ticket == NULL) {
                ret = PICOQUIC_ERROR_TLS_SERVER_CON_WITHOUT_CERT;
                picoquic_tlscontext_free(ctx);
                ctx = NULL;
            }
            if (ctx != NULL) {
                ctx->handshake_properties.server.enforce_retry = 0;
                ctx->handshake_properties.server.retry_uses_cookie = 0;
                ctx->handshake_properties.server.cookie.key = NULL;
                ctx->handshake_properties.server.cookie.additional_data.base = NULL;
                ctx->handshake_properties.server.cookie.additional_data.len = 0;
            }
        }
    }
    if (cnx->tls_ctx != NULL) {
        picoquic_tlscontext_free(cnx->tls_ctx);
    }
    cnx->tls_ctx = (void*)ctx;
    return ret;
}
int picoquic_tlscontext_create ( picoquic_quic_t * quic , picoquic_cnx_t * cnx , uint64_t current_time ) { int ret = 0 ; picoquic_tls_ctx_t * ctx = ( picoquic_tls_ctx_t * ) malloc ( sizeof ( picoquic_tls_ctx_t ) ) ; if ( ctx == NULL ) { ret = -1 ; } else { memset ( ctx , 0 , sizeof ( picoquic_tls_ctx_t ) ) ; ctx -> cnx = cnx ; ctx -> handshake_properties . collect_extension = picoquic_tls_collect_extensions_cb ; ctx -> handshake_properties . collected_extensions = picoquic_tls_collected_extensions_cb ; ctx -> client_mode = cnx -> client_mode ; ctx -> tls = ptls_new ( ( ptls_context_t * ) quic -> tls_master_ctx , ( ctx -> client_mode ) ? 0 : 1 ) ; * ptls_get_data_ptr ( ctx -> tls ) = cnx ; if ( ctx -> tls == NULL ) { free ( ctx ) ; ctx = NULL ; ret = -1 ; } else if ( ! ctx -> client_mode ) { if ( ( ( ptls_context_t * ) quic -> tls_master_ctx ) -> encrypt_ticket == NULL ) { ret = PICOQUIC_ERROR_TLS_SERVER_CON_WITHOUT_CERT ; picoquic_tlscontext_free ( ctx ) ; ctx = NULL ; } if ( ctx != NULL ) { ctx -> handshake_properties . server . enforce_retry = 0 ; ctx -> handshake_properties . server . retry_uses_cookie = 0 ; ctx -> handshake_properties . server . cookie . key = NULL ; ctx -> handshake_properties . server . cookie . additional_data . base = NULL ; ctx -> handshake_properties . server . cookie . additional_data . len = 0 ; } } } if ( cnx -> tls_ctx != NULL ) { picoquic_tlscontext_free ( cnx -> tls_ctx ) ; } cnx -> tls_ctx = ( void * ) ctx ; return ret ; }
Creation of a TLS context.
Creation of a TLS context .
/* allocate a context structure */ /* Create the TLS context */ /* A server side connection, but no cert/key where given for the master context */ /* The server should never attempt a stateless retry */