/src/mod_auth_openidc/src/http.h
Line | Count | Source |
1 | | /* |
2 | | * Licensed to the Apache Software Foundation (ASF) under one |
3 | | * or more contributor license agreements. See the NOTICE file |
4 | | * distributed with this work for additional information |
5 | | * regarding copyright ownership. The ASF licenses this file |
6 | | * to you under the Apache License, Version 2.0 (the |
7 | | * "License"); you may not use this file except in compliance |
8 | | * with the License. You may obtain a copy of the License at |
9 | | * |
10 | | * http://www.apache.org/licenses/LICENSE-2.0 |
11 | | * |
12 | | * Unless required by applicable law or agreed to in writing, |
13 | | * software distributed under the License is distributed on an |
14 | | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
15 | | * KIND, either express or implied. See the License for the |
16 | | * specific language governing permissions and limitations |
17 | | * under the License. |
18 | | */ |
19 | | |
20 | | /*************************************************************************** |
21 | | * Copyright (C) 2017-2026 ZmartZone Holding BV |
22 | | * Copyright (C) 2013-2017 Ping Identity Corporation |
23 | | * All rights reserved. |
24 | | * |
25 | | * DISCLAIMER OF WARRANTIES: |
26 | | * |
27 | | * THE SOFTWARE PROVIDED HEREUNDER IS PROVIDED ON AN "AS IS" BASIS, WITHOUT |
28 | | * ANY WARRANTIES OR REPRESENTATIONS EXPRESS, IMPLIED OR STATUTORY; INCLUDING, |
29 | | * WITHOUT LIMITATION, WARRANTIES OF QUALITY, PERFORMANCE, NONINFRINGEMENT, |
30 | | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. NOR ARE THERE ANY |
31 | | * WARRANTIES CREATED BY A COURSE OR DEALING, COURSE OF PERFORMANCE OR TRADE |
32 | | * USAGE. FURTHERMORE, THERE ARE NO WARRANTIES THAT THE SOFTWARE WILL MEET |
33 | | * YOUR NEEDS OR BE FREE FROM ERRORS, OR THAT THE OPERATION OF THE SOFTWARE |
34 | | * WILL BE UNINTERRUPTED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR |
35 | | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
36 | | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES HOWEVER CAUSED AND ON ANY THEORY OF |
37 | | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
38 | | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
39 | | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
40 | | * |
41 | | * @Author: Hans Zandbelt - hans.zandbelt@openidc.com |
42 | | */ |
43 | | |
44 | | #ifndef _MOD_AUTH_OPENIDC_HTTP_H_ |
45 | | #define _MOD_AUTH_OPENIDC_HTTP_H_ |
46 | | |
47 | | #include <apr.h> |
48 | | #include <apr_hash.h> |
49 | | #include <apr_time.h> |
50 | | // clang-format off |
51 | | #include <httpd.h> |
52 | | #include <http_log.h> |
53 | | #include <http_request.h> |
54 | | // clang-format on |
55 | | #include "json.h" |
56 | | |
57 | 0 | #define OIDC_HTTP_CONTENT_TYPE_JSON "application/json" |
58 | 0 | #define OIDC_HTTP_CONTENT_TYPE_JWT "application/jwt" |
59 | 0 | #define OIDC_HTTP_CONTENT_TYPE_FORM_ENCODED "application/x-www-form-urlencoded" |
60 | 0 | #define OIDC_HTTP_CONTENT_TYPE_IMAGE_PNG "image/png" |
61 | 0 | #define OIDC_HTTP_CONTENT_TYPE_TEXT_HTML "text/html" |
62 | 0 | #define OIDC_HTTP_CONTENT_TYPE_APP_XHTML_XML "application/xhtml+xml" |
63 | 0 | #define OIDC_HTTP_CONTENT_TYPE_ANY "*/*" |
64 | | |
65 | | /* HTTP header constants */ |
66 | 11.2k | #define OIDC_HTTP_HDR_COOKIE "Cookie" |
67 | 36.8k | #define OIDC_HTTP_HDR_SET_COOKIE "Set-Cookie" |
68 | 0 | #define OIDC_HTTP_HDR_USER_AGENT "User-Agent" |
69 | 0 | #define OIDC_HTTP_HDR_X_FORWARDED_FOR "X-Forwarded-For" |
70 | 0 | #define OIDC_HTTP_HDR_CONTENT_TYPE "Content-Type" |
71 | 0 | #define OIDC_HTTP_HDR_CONTENT_LENGTH "Content-Length" |
72 | 0 | #define OIDC_HTTP_HDR_X_REQUESTED_WITH "X-Requested-With" |
73 | 0 | #define OIDC_HTTP_HDR_SEC_FETCH_MODE "Sec-Fetch-Mode" |
74 | 0 | #define OIDC_HTTP_HDR_SEC_FETCH_DEST "Sec-Fetch-Dest" |
75 | 0 | #define OIDC_HTTP_HDR_ACCEPT "Accept" |
76 | 0 | #define OIDC_HTTP_HDR_AUTHORIZATION "Authorization" |
77 | 0 | #define OIDC_HTTP_HDR_X_FORWARDED_PROTO "X-Forwarded-Proto" |
78 | 0 | #define OIDC_HTTP_HDR_X_FORWARDED_PORT "X-Forwarded-Port" |
79 | 0 | #define OIDC_HTTP_HDR_X_FORWARDED_HOST "X-Forwarded-Host" |
80 | 0 | #define OIDC_HTTP_HDR_FORWARDED "Forwarded" |
81 | 0 | #define OIDC_HTTP_HDR_HOST "Host" |
82 | 0 | #define OIDC_HTTP_HDR_LOCATION "Location" |
83 | 0 | #define OIDC_HTTP_HDR_CACHE_CONTROL "Cache-Control" |
84 | 0 | #define OIDC_HTTP_HDR_PRAGMA "Pragma" |
85 | 0 | #define OIDC_HTTP_HDR_P3P "P3P" |
86 | 0 | #define OIDC_HTTP_HDR_EXPIRES "Expires" |
87 | 0 | #define OIDC_HTTP_HDR_X_FRAME_OPTIONS "X-Frame-Options" |
88 | 0 | #define OIDC_HTTP_HDR_WWW_AUTHENTICATE "WWW-Authenticate" |
89 | 0 | #define OIDC_HTTP_HDR_TRACE_PARENT "traceparent" |
90 | 0 | #define OIDC_HTTP_HDR_DPOP "DPoP" |
91 | 0 | #define OIDC_HTTP_HDR_DPOP_NONCE "DPoP-Nonce" |
92 | | |
93 | 0 | #define OIDC_HTTP_HDR_VAL_XML_HTTP_REQUEST "XMLHttpRequest" |
94 | 0 | #define OIDC_HTTP_HDR_VAL_NAVIGATE "navigate" |
95 | 0 | #define OIDC_HTTP_HDR_VAL_DOCUMENT "document" |
96 | | |
97 | 0 | #define OIDC_HTTP_COOKIE_SAMESITE_LAX "SameSite=Lax" |
98 | 0 | #define OIDC_HTTP_COOKIE_SAMESITE_STRICT "SameSite=Strict" |
99 | 36.8k | #define OIDC_HTTP_COOKIE_SAMESITE_NONE(c, r) oidc_util_url_cur_is_secure(r, c) ? "SameSite=None" : NULL |
100 | | |
101 | | typedef struct oidc_http_timeout_t { |
102 | | int request_timeout; // in seconds |
103 | | int connect_timeout; // in seconds |
104 | | int retries; |
105 | | int retry_interval; // in milliseconds |
106 | | } oidc_http_timeout_t; |
107 | | |
108 | 0 | #define OIDC_HTTP_PROXY_AUTH_BASIC "basic" |
109 | 0 | #define OIDC_HTTP_PROXY_AUTH_DIGEST "digest" |
110 | 0 | #define OIDC_HTTP_PROXY_AUTH_NTLM "ntlm" |
111 | 0 | #define OIDC_HTTP_PROXY_AUTH_ANY "any" |
112 | 0 | #define OIDC_HTTP_PROXY_AUTH_NEGOTIATE "negotiate" |
113 | | |
114 | | typedef struct oidc_http_outgoing_proxy_t { |
115 | | const char *host_port; |
116 | | const char *username_password; |
117 | | unsigned long auth_type; |
118 | | } oidc_http_outgoing_proxy_t; |
119 | | |
120 | | char *oidc_http_url_encode(const request_rec *r, const char *str); |
121 | | char *oidc_http_url_decode(const request_rec *r, const char *str); |
122 | | /* TRUE when a protocol parameter of this name carries a secret or token and its value |
123 | | * must be redacted before it is written to the debug log */ |
124 | | apr_byte_t oidc_http_param_is_sensitive(const char *key); |
125 | | |
126 | | void oidc_http_hdr_err_out_add(const request_rec *r, const char *name, const char *value); |
127 | | void oidc_http_set_no_cache_headers(const request_rec *r); |
128 | | void oidc_http_hdr_in_set(const request_rec *r, const char *name, const char *value); |
129 | | void oidc_http_hdr_table_add(const request_rec *r, apr_table_t *table, const char *name, const char *value); |
130 | | const char *oidc_http_hdr_in_cookie_get(const request_rec *r); |
131 | | void oidc_http_hdr_in_cookie_set(const request_rec *r, const char *value); |
132 | | const char *oidc_http_hdr_in_user_agent_get(const request_rec *r); |
133 | | const char *oidc_http_hdr_in_x_forwarded_for_get(const request_rec *r); |
134 | | const char *oidc_http_hdr_in_content_type_get(const request_rec *r); |
135 | | const char *oidc_http_hdr_in_content_length_get(const request_rec *r); |
136 | | const char *oidc_http_hdr_in_x_requested_with_get(const request_rec *r); |
137 | | const char *oidc_http_hdr_in_sec_fetch_mode_get(const request_rec *r); |
138 | | const char *oidc_http_hdr_in_sec_fetch_dest_get(const request_rec *r); |
139 | | const char *oidc_http_hdr_in_accept_get(const request_rec *r); |
140 | | apr_byte_t oidc_http_hdr_in_accept_contains(const request_rec *r, const char *needle); |
141 | | const char *oidc_http_hdr_in_authorization_get(const request_rec *r); |
142 | | const char *oidc_http_hdr_in_x_forwarded_proto_get(const request_rec *r); |
143 | | const char *oidc_http_hdr_in_x_forwarded_port_get(const request_rec *r); |
144 | | const char *oidc_http_hdr_in_x_forwarded_host_get(const request_rec *r); |
145 | | const char *oidc_http_hdr_in_forwarded_get(const request_rec *r); |
146 | | const char *oidc_http_hdr_in_host_get(const request_rec *r); |
147 | | const char *oidc_http_hdr_in_traceparent_get(const request_rec *r); |
148 | | void oidc_http_hdr_out_location_set(const request_rec *r, const char *value); |
149 | | const char *oidc_http_hdr_out_location_get(const request_rec *r); |
150 | | const char *oidc_http_hdr_forwarded_get(const request_rec *r, const char *elem); |
151 | | |
152 | | char *oidc_http_hdr_normalize_name(const request_rec *r, const char *str); |
153 | | apr_byte_t oidc_http_get(request_rec *r, const char *url, const apr_table_t *params, const char *basic_auth, |
154 | | const char *access_token, const char *dpop, int ssl_validate_server, char **response, |
155 | | long *response_code, apr_hash_t *response_hdrs, const oidc_http_timeout_t *http_timeout, |
156 | | const oidc_http_outgoing_proxy_t *outgoing_proxy, const apr_array_header_t *pass_cookies, |
157 | | const char *ssl_cert, const char *ssl_key, const char *ssl_key_pwd); |
158 | | apr_byte_t oidc_http_post_form(request_rec *r, const char *url, const apr_table_t *params, const char *basic_auth, |
159 | | const char *access_token, const char *dpop, int ssl_validate_server, char **response, |
160 | | long *response_code, apr_hash_t *response_hdrs, const oidc_http_timeout_t *http_timeout, |
161 | | const oidc_http_outgoing_proxy_t *outgoing_proxy, const apr_array_header_t *pass_cookies, |
162 | | const char *ssl_cert, const char *ssl_key, const char *ssl_key_pwd); |
163 | | apr_byte_t oidc_http_post_json(request_rec *r, const char *url, const oidc_json_t *data, const char *basic_auth, |
164 | | const char *access_token, const char *dpop, int ssl_validate_server, char **response, |
165 | | long *response_code, apr_hash_t *response_hdrs, const oidc_http_timeout_t *http_timeout, |
166 | | const oidc_http_outgoing_proxy_t *outgoing_proxy, const apr_array_header_t *pass_cookies, |
167 | | const char *ssl_cert, const char *ssl_key, const char *ssl_key_pwd); |
168 | | apr_byte_t oidc_util_url_has_parameter(request_rec *r, const char *param); |
169 | | apr_byte_t oidc_util_url_parameter_get(request_rec *r, char *name, char **value); |
170 | | int oidc_util_http_send(request_rec *r, const char *data, size_t data_len, const char *content_type, |
171 | | int success_rvalue); |
172 | | int oidc_util_http_content_prep(request_rec *r, const char *data, size_t data_len, const char *content_type); |
173 | | int oidc_util_http_content_send(request_rec *r); |
174 | | apr_byte_t oidc_util_read_form_encoded_params(request_rec *r, apr_table_t *table, const char *data); |
175 | | apr_byte_t oidc_util_read_form_encoded_params_reject_dup(request_rec *r, apr_table_t *table, const char *data, |
176 | | const char *const *no_repeat); |
177 | | apr_byte_t oidc_util_read_post_params(request_rec *r, apr_table_t *table, apr_byte_t propagate, |
178 | | const char *strip_param_name); |
179 | | apr_byte_t oidc_util_read_post_params_reject_dup(request_rec *r, apr_table_t *table, apr_byte_t propagate, |
180 | | const char *strip_param_name, const char *const *no_repeat); |
181 | | char *oidc_http_query_encoded_url(request_rec *r, const char *url, const apr_table_t *params); |
182 | | char *oidc_http_form_encoded_data(request_rec *r, const apr_table_t *params); |
183 | | |
184 | | char *oidc_http_get_cookie(request_rec *r, const char *cookieName); |
185 | | void oidc_http_set_cookie(request_rec *r, const char *cookieName, const char *cookieValue, apr_time_t expires, |
186 | | const char *ext); |
187 | | char *oidc_http_get_chunked_cookie(request_rec *r, const char *cookieName, int chunkSize); |
188 | | apr_byte_t oidc_http_set_chunked_cookie(request_rec *r, const char *cookieName, const char *cookieValue, |
189 | | apr_time_t expires, int chunkSize, const char *ext); |
190 | | |
191 | | const char **oidc_http_proxy_auth_options(void); |
192 | | unsigned long oidc_http_proxy_s2auth(const char *arg); |
193 | | |
194 | | void oidc_http_init(void); |
195 | | void oidc_http_cleanup(void); |
196 | | void oidc_http_curl_pool_init(apr_pool_t *pool); |
197 | | void oidc_http_curl_pool_child_init(void); |
198 | | |
199 | | #endif /* _MOD_AUTH_OPENIDC_HTTP_H_ */ |