Changeset 894efd0 in mod_gnutls for src/gnutls_ocsp.c


Ignore:
Timestamp:
Jun 14, 2016, 4:57:36 PM (7 years ago)
Author:
Thomas Klute <thomas2.klute@…>
Branches:
asyncio, debian/master, debian/stretch-backports, main, master, proxy-ticket, upstream
Children:
317b569
Parents:
82745d1
Message:

Check OCSP response nonce

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/gnutls_ocsp.c

    r82745d1 r894efd0  
    186186 * contained in the response, or zero if the response does not contain
    187187 * a nextUpdate field.
     188 *
     189 * If nonce is not NULL, the response must contain a matching nonce.
    188190 */
    189191int check_ocsp_response(server_rec *s, const gnutls_datum_t *ocsp_response,
    190                         apr_time_t* expiry)
     192                        apr_time_t* expiry, const gnutls_datum_t *nonce)
     193    __attribute__((nonnull(1, 2)));
     194int check_ocsp_response(server_rec *s, const gnutls_datum_t *ocsp_response,
     195                        apr_time_t* expiry, const gnutls_datum_t *nonce)
    191196{
    192197    mgs_srvconf_rec *sc = (mgs_srvconf_rec *)
     
    248253        else
    249254            ap_log_error(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, s,
    250                          "OCSP response is valid.");
     255                         "OCSP response signature is valid.");
     256    }
     257
     258    if (nonce != NULL)
     259    {
     260        gnutls_datum_t resp_nonce;
     261        ret = gnutls_ocsp_resp_get_nonce(resp, 0, &resp_nonce);
     262        if (ret != GNUTLS_E_SUCCESS)
     263        {
     264            ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, s,
     265                         "Could not get OCSP response nonce: %s (%d)",
     266                         gnutls_strerror(ret), ret);
     267            goto resp_cleanup;
     268        }
     269        if (resp_nonce.size != nonce->size
     270            || memcmp(resp_nonce.data, nonce->data, nonce->size))
     271        {
     272            ret = GNUTLS_E_OCSP_RESPONSE_ERROR;
     273            ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, s,
     274                         "OCSP response invalid: nonce mismatch");
     275            gnutls_free(resp_nonce.data);
     276            goto resp_cleanup;
     277        }
     278        ap_log_error(APLOG_MARK, APLOG_TRACE2, APR_SUCCESS, s,
     279                     "OCSP response: nonce match");
     280        gnutls_free(resp_nonce.data);
    251281    }
    252282
     
    534564
    535565    gnutls_datum_t req;
    536     int ret = mgs_create_ocsp_request(s, &req, NULL);
     566    gnutls_datum_t nonce;
     567    int ret = mgs_create_ocsp_request(s, &req, &nonce);
    537568    if (ret == GNUTLS_E_SUCCESS)
    538569    {
     
    545576    {
    546577        gnutls_free(req.data);
     578        gnutls_free(nonce.data);
    547579        apr_pool_destroy(tmp);
    548580        return APR_EGENERAL;
     
    555587    {
    556588        /* do_ocsp_request() does its own error logging. */
     589        gnutls_free(nonce.data);
    557590        apr_pool_destroy(tmp);
    558591        return rv;
    559592    }
    560     /* TODO: check nonce */
    561 
    562     /* TODO: separate option to enable/disable OCSP stapling, restore
    563      * reading response from file for debugging/expert use. */
     593
     594    /* TODO: separate option to enable/disable OCSP stapling, same for
     595     * nonce, restore reading response from file for debugging/expert
     596     * use. */
    564597
    565598    apr_time_t expiry;
    566     if (check_ocsp_response(s, &resp, &expiry) != GNUTLS_E_SUCCESS)
     599    if (check_ocsp_response(s, &resp, &expiry, &nonce) != GNUTLS_E_SUCCESS)
    567600    {
    568601        ap_log_error(APLOG_MARK, APLOG_DEBUG, APR_EGENERAL, s,
     
    570603                     "update cache.");
    571604        apr_pool_destroy(tmp);
     605        gnutls_free(nonce.data);
    572606        return APR_EGENERAL;
    573607    }
     608    gnutls_free(nonce.data);
     609
    574610    /* If expiry is zero, the response does not contain a nextUpdate
    575611     * field. Use the default cache timeout. */
Note: See TracChangeset for help on using the changeset viewer.