summaryrefslogtreecommitdiffstats
path: root/crypto/ocsp/ocsp_http.c
blob: c0456c753c8598dc8685bed386dabce50d597af6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
 * Copyright 2001-2021 The OpenSSL Project Authors. All Rights Reserved.
 *
 * Licensed under the Apache License 2.0 (the "License").  You may not use
 * this file except in compliance with the License.  You can obtain a copy
 * in the file LICENSE in the source distribution or at
 * https://www.openssl.org/source/license.html
 */

#include <openssl/ocsp.h>
#include <openssl/http.h>
#include "../http/http_local.h"

#ifndef OPENSSL_NO_OCSP

OSSL_HTTP_REQ_CTX *OCSP_sendreq_new(BIO *io, const char *path,
                                    const OCSP_REQUEST *req, int buf_size)
{
    OSSL_HTTP_REQ_CTX *rctx = OSSL_HTTP_REQ_CTX_new(io, io, buf_size);

    if (rctx == NULL)
        return NULL;

    if (!OSSL_HTTP_REQ_CTX_set_request_line(rctx, 1 /* POST */, NULL, NULL, path))
        goto err;

    if (!OSSL_HTTP_REQ_CTX_set_expected(rctx,
                                        NULL /* content_type */, 1 /* asn1 */,
                                        0 /* timeout */, 0 /* keep_alive */))
        goto err;
    if (req != NULL
        && !OSSL_HTTP_REQ_CTX_set1_req(rctx, "application/ocsp-request",
                                       ASN1_ITEM_rptr(OCSP_REQUEST),
                                       (ASN1_VALUE *)req))
        goto err;

    return rctx;

 err:
    OSSL_HTTP_REQ_CTX_free(rctx);
    return NULL;
}

OCSP_RESPONSE *OCSP_sendreq_bio(BIO *b, const char *path, OCSP_REQUEST *req)
{
    OCSP_RESPONSE *resp = NULL;
    OSSL_HTTP_REQ_CTX *ctx;
    BIO *mem;

    ctx = OCSP_sendreq_new(b, path, req, -1 /* default max resp line length */);
    if (ctx == NULL)
        return NULL;
    mem = OSSL_HTTP_REQ_CTX_exchange(ctx);
    resp = (OCSP_RESPONSE *)
        ASN1_item_d2i_bio(ASN1_ITEM_rptr(OCSP_RESPONSE), mem, NULL);
    BIO_free(mem);

    /* this indirectly calls ERR_clear_error(): */
    OSSL_HTTP_REQ_CTX_free(ctx);

    return resp;
}
#endif /* !defined(OPENSSL_NO_OCSP) */