Changeset e376ed8 in mod_gnutls for src/gnutls_cache.c


Ignore:
Timestamp:
Nov 29, 2019, 4:30:08 PM (15 months ago)
Author:
Fiona Klute <fiona.klute@…>
Branches:
asyncio, master, proxy-ticket
Children:
618ee14
Parents:
d4c9331 (diff), 556783e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'subca'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/gnutls_cache.c

    rd4c9331 re376ed8  
    5252/** Maximum length of the hex string representation of a GnuTLS
    5353 * session ID: two characters per byte, plus one more for `\0` */
    54 #if GNUTLS_VERSION_NUMBER >= 0x030400
    5554#define GNUTLS_SESSION_ID_STRING_LEN ((GNUTLS_MAX_SESSION_ID_SIZE * 2) + 1)
    56 #else
    57 #define GNUTLS_SESSION_ID_STRING_LEN ((GNUTLS_MAX_SESSION_ID * 2) + 1)
    58 #endif
    5955
    6056#ifdef APLOG_USE_MODULE
     
    179175#define SOCACHE_FETCH_BUF_SIZE (8 * 1024)
    180176
    181 gnutls_datum_t mgs_cache_fetch(mgs_cache_t cache, server_rec *server,
    182                                gnutls_datum_t key, apr_pool_t *pool)
    183 {
    184     gnutls_datum_t data = {NULL, 0};
    185     data.data = gnutls_malloc(SOCACHE_FETCH_BUF_SIZE);
    186     if (data.data == NULL)
    187         return data;
    188     data.size = SOCACHE_FETCH_BUF_SIZE;
    189 
     177apr_status_t mgs_cache_fetch(mgs_cache_t cache, server_rec *server,
     178                             gnutls_datum_t key, gnutls_datum_t *output,
     179                             apr_pool_t *pool)
     180{
    190181    apr_pool_t *spool;
    191182    apr_pool_create(&spool, pool);
     
    195186    apr_status_t rv = cache->prov->retrieve(cache->socache, server,
    196187                                            key.data, key.size,
    197                                             data.data, &data.size,
     188                                            output->data, &output->size,
    198189                                            spool);
    199190    if (cache->prov->flags & AP_SOCACHE_FLAG_NOTMPSAFE)
     
    211202                         "error fetching from cache '%s:%s'",
    212203                         cache->prov->name, cache->config);
     204    }
     205    else
     206    {
     207        ap_log_error(APLOG_MARK, APLOG_TRACE1, rv, server,
     208                     "fetched %u bytes from cache '%s:%s'",
     209                     output->size, cache->prov->name, cache->config);
     210    }
     211    apr_pool_destroy(spool);
     212
     213    return rv;
     214}
     215
     216
     217
     218/**
     219 * Fetch function for the GnuTLS session cache, see
     220 * gnutls_db_set_retrieve_function().
     221 *
     222 * *Warning*: The `data` element of the returned `gnutls_datum_t` is
     223 * allocated using `gnutls_malloc()` for compatibility with the GnuTLS
     224 * session caching API, and must be released using `gnutls_free()`.
     225 *
     226 * @param baton mgs_handle_t for the connection, as set via
     227 * gnutls_db_set_ptr()
     228 *
     229 * @param key object key to fetch
     230 *
     231 * @return the requested cache entry, or `{NULL, 0}`
     232 */
     233static gnutls_datum_t socache_fetch_session(void *baton, gnutls_datum_t key)
     234{
     235    gnutls_datum_t data = {NULL, 0};
     236    gnutls_datum_t dbmkey;
     237    mgs_handle_t *ctxt = baton;
     238
     239    if (mgs_session_id2dbm(ctxt->c, key.data, key.size, &dbmkey) < 0)
     240        return data;
     241
     242    data.data = gnutls_malloc(SOCACHE_FETCH_BUF_SIZE);
     243    if (data.data == NULL)
     244        return data;
     245    data.size = SOCACHE_FETCH_BUF_SIZE;
     246
     247    apr_status_t rv = mgs_cache_fetch(ctxt->sc->cache, ctxt->c->base_server,
     248                                      dbmkey, &data, ctxt->c->pool);
     249
     250    if (rv != APR_SUCCESS)
     251    {
    213252        /* free unused buffer */
    214253        gnutls_free(data.data);
     
    218257    else
    219258    {
    220         ap_log_error(APLOG_MARK, APLOG_TRACE1, rv, server,
    221                      "fetched %u bytes from cache '%s:%s'",
    222                      data.size, cache->prov->name, cache->config);
    223 
    224259        /* Realloc buffer to data.size. Data size must be less than or
    225260         * equal to the initial buffer size, so this REALLY should not
     
    228263        if (__builtin_expect(data.data == NULL, 0))
    229264        {
    230             ap_log_error(APLOG_MARK, APLOG_CRIT, APR_ENOMEM, server,
     265            ap_log_cerror(APLOG_MARK, APLOG_CRIT, APR_ENOMEM, ctxt->c,
    231266                         "%s: Could not realloc fetch buffer to data size!",
    232267                         __func__);
     
    234269        }
    235270    }
    236     apr_pool_destroy(spool);
    237271
    238272    return data;
    239 }
    240 
    241 
    242 
    243 /**
    244  * Fetch function for the GnuTLS session cache, see
    245  * gnutls_db_set_retrieve_function().
    246  *
    247  * *Warning*: The `data` element of the returned `gnutls_datum_t` is
    248  * allocated using `gnutls_malloc()` for compatibility with the GnuTLS
    249  * session caching API, and must be released using `gnutls_free()`.
    250  *
    251  * @param baton mgs_handle_t for the connection, as set via
    252  * gnutls_db_set_ptr()
    253  *
    254  * @param key object key to fetch
    255  *
    256  * @return the requested cache entry, or `{NULL, 0}`
    257  */
    258 static gnutls_datum_t socache_fetch_session(void *baton, gnutls_datum_t key)
    259 {
    260     gnutls_datum_t data = {NULL, 0};
    261     gnutls_datum_t dbmkey;
    262     mgs_handle_t *ctxt = baton;
    263 
    264     if (mgs_session_id2dbm(ctxt->c, key.data, key.size, &dbmkey) < 0)
    265         return data;
    266 
    267     return mgs_cache_fetch(ctxt->sc->cache, ctxt->c->base_server,
    268                            dbmkey, ctxt->c->pool);
    269273}
    270274
Note: See TracChangeset for help on using the changeset viewer.