1/*
2 * Copyright 2000-2025 The OpenSSL Project Authors. All Rights Reserved.
3 * Copyright Siemens AG 2018-2020
4 *
5 * Licensed under the Apache License 2.0 (the "License"). You may not use
6 * this file except in compliance with the License. You can obtain a copy
7 * in the file LICENSE in the source distribution or at
8 * https://www.openssl.org/source/license.html
9 */
10
11#ifndef OPENSSL_HTTP_H
12#define OPENSSL_HTTP_H
13#pragma once
14
15#include <openssl/opensslconf.h>
16
17#include <openssl/bio.h>
18#include <openssl/asn1.h>
19#include <openssl/conf.h>
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25#define OSSL_HTTP_NAME "http"
26#define OSSL_HTTPS_NAME "https"
27#define OSSL_HTTP_PREFIX OSSL_HTTP_NAME "://"
28#define OSSL_HTTPS_PREFIX OSSL_HTTPS_NAME "://"
29#define OSSL_HTTP_PORT "80"
30#define OSSL_HTTPS_PORT "443"
31#define OPENSSL_NO_PROXY "NO_PROXY"
32#define OPENSSL_HTTP_PROXY "HTTP_PROXY"
33#define OPENSSL_HTTPS_PROXY "HTTPS_PROXY"
34
35/* We want to have this even in case of OPENSSL_NO_HTTP */
36int OSSL_parse_url(const char *url, char **pscheme, char **puser, char **phost,
37 char **pport, int *pport_num,
38 char **ppath, char **pquery, char **pfrag);
39
40#ifndef OPENSSL_NO_HTTP
41
42#define OSSL_HTTP_DEFAULT_MAX_LINE_LEN (4 * 1024)
43#define OSSL_HTTP_DEFAULT_MAX_RESP_LEN (100 * 1024)
44#define OSSL_HTTP_DEFAULT_MAX_CRL_LEN (32 * 1024 * 1024)
45#define OSSL_HTTP_DEFAULT_MAX_RESP_HDR_LINES 256
46
47/* Low-level HTTP API */
48OSSL_HTTP_REQ_CTX *OSSL_HTTP_REQ_CTX_new(BIO *wbio, BIO *rbio, int buf_size);
49void OSSL_HTTP_REQ_CTX_free(OSSL_HTTP_REQ_CTX *rctx);
50int OSSL_HTTP_REQ_CTX_set_request_line(OSSL_HTTP_REQ_CTX *rctx, int method_POST,
51 const char *server, const char *port,
52 const char *path);
53int OSSL_HTTP_REQ_CTX_add1_header(OSSL_HTTP_REQ_CTX *rctx,
54 const char *name, const char *value);
55int OSSL_HTTP_REQ_CTX_set_expected(OSSL_HTTP_REQ_CTX *rctx,
56 const char *content_type, int asn1,
57 int timeout, int keep_alive);
58int OSSL_HTTP_REQ_CTX_set1_req(OSSL_HTTP_REQ_CTX *rctx, const char *content_type,
59 const ASN1_ITEM *it, const ASN1_VALUE *req);
60int OSSL_HTTP_REQ_CTX_nbio(OSSL_HTTP_REQ_CTX *rctx);
61int OSSL_HTTP_REQ_CTX_nbio_d2i(OSSL_HTTP_REQ_CTX *rctx,
62 ASN1_VALUE **pval, const ASN1_ITEM *it);
63BIO *OSSL_HTTP_REQ_CTX_exchange(OSSL_HTTP_REQ_CTX *rctx);
64BIO *OSSL_HTTP_REQ_CTX_get0_mem_bio(const OSSL_HTTP_REQ_CTX *rctx);
65size_t OSSL_HTTP_REQ_CTX_get_resp_len(const OSSL_HTTP_REQ_CTX *rctx);
66void OSSL_HTTP_REQ_CTX_set_max_response_length(OSSL_HTTP_REQ_CTX *rctx,
67 unsigned long len);
68void OSSL_HTTP_REQ_CTX_set_max_response_hdr_lines(OSSL_HTTP_REQ_CTX *rctx,
69 size_t count);
70int OSSL_HTTP_is_alive(const OSSL_HTTP_REQ_CTX *rctx);
71
72/* High-level HTTP API */
73typedef BIO *(*OSSL_HTTP_bio_cb_t)(BIO *bio, void *arg, int connect, int detail);
74OSSL_HTTP_REQ_CTX *OSSL_HTTP_open(const char *server, const char *port,
75 const char *proxy, const char *no_proxy,
76 int use_ssl, BIO *bio, BIO *rbio,
77 OSSL_HTTP_bio_cb_t bio_update_fn, void *arg,
78 int buf_size, int overall_timeout);
79int OSSL_HTTP_proxy_connect(BIO *bio, const char *server, const char *port,
80 const char *proxyuser, const char *proxypass,
81 int timeout, BIO *bio_err, const char *prog);
82int OSSL_HTTP_set1_request(OSSL_HTTP_REQ_CTX *rctx, const char *path,
83 const STACK_OF(CONF_VALUE) *headers,
84 const char *content_type, BIO *req,
85 const char *expected_content_type, int expect_asn1,
86 size_t max_resp_len, int timeout, int keep_alive);
87BIO *OSSL_HTTP_exchange(OSSL_HTTP_REQ_CTX *rctx, char **redirection_url);
88BIO *OSSL_HTTP_get(const char *url, const char *proxy, const char *no_proxy,
89 BIO *bio, BIO *rbio,
90 OSSL_HTTP_bio_cb_t bio_update_fn, void *arg,
91 int buf_size, const STACK_OF(CONF_VALUE) *headers,
92 const char *expected_content_type, int expect_asn1,
93 size_t max_resp_len, int timeout);
94BIO *OSSL_HTTP_transfer(OSSL_HTTP_REQ_CTX **prctx,
95 const char *server, const char *port,
96 const char *path, int use_ssl,
97 const char *proxy, const char *no_proxy,
98 BIO *bio, BIO *rbio,
99 OSSL_HTTP_bio_cb_t bio_update_fn, void *arg,
100 int buf_size, const STACK_OF(CONF_VALUE) *headers,
101 const char *content_type, BIO *req,
102 const char *expected_content_type, int expect_asn1,
103 size_t max_resp_len, int timeout, int keep_alive);
104int OSSL_HTTP_close(OSSL_HTTP_REQ_CTX *rctx, int ok);
105
106/* Auxiliary functions */
107int OSSL_HTTP_parse_url(const char *url, int *pssl, char **puser, char **phost,
108 char **pport, int *pport_num,
109 char **ppath, char **pquery, char **pfrag);
110const char *OSSL_HTTP_adapt_proxy(const char *proxy, const char *no_proxy,
111 const char *server, int use_ssl);
112
113#endif /* !defined(OPENSSL_NO_HTTP) */
114#ifdef __cplusplus
115}
116#endif
117#endif /* !defined(OPENSSL_HTTP_H) */
118