]> git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/ocsp/ocsp_http.c
PROV: add RSA signature implementation
[thirdparty/openssl.git] / crypto / ocsp / ocsp_http.c
1 /*
2 * Copyright 2001-2019 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
9
10 #include <openssl/ocsp.h>
11 #include <openssl/http.h>
12 #include "../http/http_local.h"
13
14 #ifndef OPENSSL_NO_OCSP
15
16 int OCSP_REQ_CTX_set1_req(OCSP_REQ_CTX *rctx, const OCSP_REQUEST *req)
17 {
18 return OCSP_REQ_CTX_i2d(rctx, "application/ocsp-request",
19 ASN1_ITEM_rptr(OCSP_REQUEST), (ASN1_VALUE *)req);
20 }
21
22 OCSP_REQ_CTX *OCSP_sendreq_new(BIO *io, const char *path, OCSP_REQUEST *req,
23 int maxline)
24 {
25 BIO *req_mem = HTTP_asn1_item2bio(ASN1_ITEM_rptr(OCSP_REQUEST),
26 (ASN1_VALUE *)req);
27 OCSP_REQ_CTX *res =
28 HTTP_REQ_CTX_new(io, io, 0 /* no HTTP proxy used */, NULL, NULL, path,
29 NULL /* headers */, "application/ocsp-request",
30 req_mem /* may be NULL */,
31 maxline, 0 /* default max_resp_len */,
32 0 /* no timeout, blocking indefinite */, NULL,
33 1 /* expect_asn1 */);
34 BIO_free(req_mem);
35 return res;
36 }
37
38 int OCSP_sendreq_nbio(OCSP_RESPONSE **presp, OCSP_REQ_CTX *rctx)
39 {
40 *presp = (OCSP_RESPONSE *)
41 OCSP_REQ_CTX_nbio_d2i(rctx, ASN1_ITEM_rptr(OCSP_RESPONSE));
42 return *presp != NULL;
43 }
44
45 OCSP_RESPONSE *OCSP_sendreq_bio(BIO *b, const char *path, OCSP_REQUEST *req)
46 {
47 OCSP_RESPONSE *resp = NULL;
48 OCSP_REQ_CTX *ctx;
49 int rv;
50
51 ctx = OCSP_sendreq_new(b, path, req, -1 /* default max resp line length */);
52 if (ctx == NULL)
53 return NULL;
54
55 rv = OCSP_sendreq_nbio(&resp, ctx);
56
57 /* this indirectly calls ERR_clear_error(): */
58 OCSP_REQ_CTX_free(ctx);
59
60 return rv == 1 ? resp : NULL;
61 }
62 #endif /* !defined(OPENSSL_NO_OCSP) */