picoquic/tls_api.c
int picoquic_esni_client_from_file(picoquic_cnx_t * cnx, char const * esni_rr_file_name)
{
    int ret = 0;
    picoquic_tls_ctx_t* ctx = (picoquic_tls_ctx_t*)cnx->tls_ctx;
    uint8_t* esnikeys = malloc(picoquic_esnikeys_max_rr);
    size_t esnikeys_len;

    if (esnikeys != NULL) {
        /* read esnikeys */
        ret = picoquic_esni_load_rr(esni_rr_file_name, esnikeys, picoquic_esnikeys_max_rr, &esnikeys_len);

        if (ret == 0 && esnikeys_len > 0 && esnikeys_len <= picoquic_esnikeys_max_rr){
            ctx->handshake_properties.client.esni_keys.base = (uint8_t*)malloc(esnikeys_len);
            if (ctx->handshake_properties.client.esni_keys.base == NULL) {
                ctx->handshake_properties.client.esni_keys.len = 0;
                DBG_PRINTF("%s", "no memory for SNI allocation.\n");
                ret = PICOQUIC_ERROR_MEMORY;
            }
            else {
                ctx->handshake_properties.client.esni_keys.len = esnikeys_len;
                memcpy(ctx->handshake_properties.client.esni_keys.base, esnikeys, esnikeys_len);
            }
        }
        else {
            ctx->handshake_properties.client.esni_keys.len = 0;
            ctx->handshake_properties.client.esni_keys.base = NULL;
            if (ret != 0) {
                ret = PICOQUIC_ERROR_INVALID_FILE;
            }
        }
        free(esnikeys);
    }
    else {
        DBG_PRINTF("failed to allocate memory(%zu) for parsing esni record\n", picoquic_esnikeys_max_rr);
        ret = PICOQUIC_ERROR_MEMORY;
    }

    return ret;
}
/* Setup the client side ESNI record, prior to using ESNI in a connection attempt. 
 */
Setup the client side ESNI record, prior to using ESNI in a connection attempt.
Setup the client side ESNI record prior to using ESNI in a connection attempt .
int picoquic_esni_client_from_file(picoquic_cnx_t * cnx, char const * esni_rr_file_name)
{
    int ret = 0;
    picoquic_tls_ctx_t* ctx = (picoquic_tls_ctx_t*)cnx->tls_ctx;
    uint8_t* esnikeys = malloc(picoquic_esnikeys_max_rr);
    size_t esnikeys_len;
    if (esnikeys != NULL) {
        ret = picoquic_esni_load_rr(esni_rr_file_name, esnikeys, picoquic_esnikeys_max_rr, &esnikeys_len);
        if (ret == 0 && esnikeys_len > 0 && esnikeys_len <= picoquic_esnikeys_max_rr){
            ctx->handshake_properties.client.esni_keys.base = (uint8_t*)malloc(esnikeys_len);
            if (ctx->handshake_properties.client.esni_keys.base == NULL) {
                ctx->handshake_properties.client.esni_keys.len = 0;
                DBG_PRINTF("%s", "no memory for SNI allocation.\n");
                ret = PICOQUIC_ERROR_MEMORY;
            }
            else {
                ctx->handshake_properties.client.esni_keys.len = esnikeys_len;
                memcpy(ctx->handshake_properties.client.esni_keys.base, esnikeys, esnikeys_len);
            }
        }
        else {
            ctx->handshake_properties.client.esni_keys.len = 0;
            ctx->handshake_properties.client.esni_keys.base = NULL;
            if (ret != 0) {
                ret = PICOQUIC_ERROR_INVALID_FILE;
            }
        }
        free(esnikeys);
    }
    else {
        DBG_PRINTF("failed to allocate memory(%zu) for parsing esni record\n", picoquic_esnikeys_max_rr);
        ret = PICOQUIC_ERROR_MEMORY;
    }
    return ret;
}
int picoquic_esni_client_from_file ( picoquic_cnx_t * cnx , char const * esni_rr_file_name ) { int ret = 0 ; picoquic_tls_ctx_t * ctx = ( picoquic_tls_ctx_t * ) cnx -> tls_ctx ; uint8_t * esnikeys = malloc ( picoquic_esnikeys_max_rr ) ; size_t esnikeys_len ; if ( esnikeys != NULL ) { ret = picoquic_esni_load_rr ( esni_rr_file_name , esnikeys , picoquic_esnikeys_max_rr , & esnikeys_len ) ; if ( ret == 0 && esnikeys_len > 0 && esnikeys_len <= picoquic_esnikeys_max_rr ) { ctx -> handshake_properties . client . esni_keys . base = ( uint8_t * ) malloc ( esnikeys_len ) ; if ( ctx -> handshake_properties . client . esni_keys . base == NULL ) { ctx -> handshake_properties . client . esni_keys . len = 0 ; DBG_PRINTF ( " " , " \n " ) ; ret = PICOQUIC_ERROR_MEMORY ; } else { ctx -> handshake_properties . client . esni_keys . len = esnikeys_len ; memcpy ( ctx -> handshake_properties . client . esni_keys . base , esnikeys , esnikeys_len ) ; } } else { ctx -> handshake_properties . client . esni_keys . len = 0 ; ctx -> handshake_properties . client . esni_keys . base = NULL ; if ( ret != 0 ) { ret = PICOQUIC_ERROR_INVALID_FILE ; } } free ( esnikeys ) ; } else { DBG_PRINTF ( " \n " , picoquic_esnikeys_max_rr ) ; ret = PICOQUIC_ERROR_MEMORY ; } return ret ; }
Setup the client side ESNI record, prior to using ESNI in a connection attempt.
Setup the client side ESNI record prior to using ESNI in a connection attempt .
/* read esnikeys */