/src/mod_auth_openidc/src/proto/profile.c
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 | | * All rights reserved. |
23 | | * |
24 | | * DISCLAIMER OF WARRANTIES: |
25 | | * |
26 | | * THE SOFTWARE PROVIDED HEREUNDER IS PROVIDED ON AN "AS IS" BASIS, WITHOUT |
27 | | * ANY WARRANTIES OR REPRESENTATIONS EXPRESS, IMPLIED OR STATUTORY; INCLUDING, |
28 | | * WITHOUT LIMITATION, WARRANTIES OF QUALITY, PERFORMANCE, NONINFRINGEMENT, |
29 | | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. NOR ARE THERE ANY |
30 | | * WARRANTIES CREATED BY A COURSE OR DEALING, COURSE OF PERFORMANCE OR TRADE |
31 | | * USAGE. FURTHERMORE, THERE ARE NO WARRANTIES THAT THE SOFTWARE WILL MEET |
32 | | * YOUR NEEDS OR BE FREE FROM ERRORS, OR THAT THE OPERATION OF THE SOFTWARE |
33 | | * WILL BE UNINTERRUPTED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR |
34 | | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
35 | | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES HOWEVER CAUSED AND ON ANY THEORY OF |
36 | | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
37 | | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
38 | | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
39 | | * |
40 | | * @Author: Hans Zandbelt - hans.zandbelt@openidc.com |
41 | | */ |
42 | | |
43 | | #include "proto/proto.h" |
44 | | |
45 | | /* |
46 | | * per-profile overrides of provider settings: each callback returns the effective value of a |
47 | | * setting under its profile; the plain OIDC 1.0 entries pass the provider configuration |
48 | | * through, the FAPI 2.0 entries enforce the FAPI 2.0 Security Profile requirements; adding a |
49 | | * profile means adding one ops instance here rather than a branch in every getter |
50 | | */ |
51 | | typedef struct oidc_proto_profile_ops_t { |
52 | | const char *(*token_endpoint_auth_aud)(const oidc_provider_t *provider); |
53 | | const char *(*revocation_endpoint_auth_aud)(const oidc_provider_t *provider, const char *val); |
54 | | oidc_auth_request_method_t (*auth_request_method)(const oidc_provider_t *provider); |
55 | | const apr_array_header_t *(*id_token_aud_values)(apr_pool_t *pool, const oidc_provider_t *provider); |
56 | | const oidc_proto_pkce_t *(*pkce)(const oidc_provider_t *provider); |
57 | | oidc_dpop_mode_t (*dpop_mode)(const oidc_provider_t *provider); |
58 | | oidc_cert_bound_tokens_t (*cert_bound_tokens)(const oidc_provider_t *provider); |
59 | | int (*response_require_iss)(const oidc_provider_t *provider); |
60 | | const char *(*request_uri_scope)(const oidc_provider_t *provider); |
61 | | oidc_proto_endpoint_auth_policy_t (*token_endpoint_auth_policy)(apr_byte_t b_secret, apr_byte_t b_cert, |
62 | | apr_byte_t b_key); |
63 | | const char *(*token_endpoint_auth)(const oidc_cfg_t *cfg, const oidc_provider_t *provider); |
64 | | const char *(*token_endpoint_auth_alg)(const oidc_cfg_t *cfg, const oidc_provider_t *provider); |
65 | | /* the JWS algorithms the profile permits for the JWTs the client creates; NULL permits every algorithm */ |
66 | | oidc_valid_function_t jws_alg_permitted; |
67 | | } oidc_proto_profile_ops_t; |
68 | | |
69 | | /* |
70 | | * plain OpenID Connect 1.0: the configured provider settings apply as-is |
71 | | */ |
72 | | |
73 | 258 | static const char *oidc_profile_oidc10_token_endpoint_auth_aud(const oidc_provider_t *provider) { |
74 | 258 | if (oidc_cfg_provider_token_endpoint_auth_aud_get(provider) == OIDC_ENDPOINT_AUTH_AUD_ISSUER) |
75 | 0 | return oidc_cfg_provider_issuer_get(provider); |
76 | | // "legacy" and "token" both use the token endpoint URL for the token and PAR endpoints |
77 | 258 | return oidc_cfg_provider_token_endpoint_url_get(provider); |
78 | 258 | } |
79 | | |
80 | 0 | static const char *oidc_profile_oidc10_revocation_endpoint_auth_aud(const oidc_provider_t *provider, const char *val) { |
81 | | // a per-request value set in the environment takes precedence over the configured one |
82 | 0 | if (val != NULL) |
83 | 0 | return (_oidc_strcmp(val, "token") == 0) ? oidc_cfg_provider_token_endpoint_url_get(provider) : val; |
84 | 0 | switch (oidc_cfg_provider_token_endpoint_auth_aud_get(provider)) { |
85 | 0 | case OIDC_ENDPOINT_AUTH_AUD_ISSUER: |
86 | 0 | return oidc_cfg_provider_issuer_get(provider); |
87 | 0 | case OIDC_ENDPOINT_AUTH_AUD_TOKEN: |
88 | 0 | return oidc_cfg_provider_token_endpoint_url_get(provider); |
89 | 0 | case OIDC_ENDPOINT_AUTH_AUD_LEGACY: |
90 | 0 | default: |
91 | 0 | return oidc_cfg_provider_revocation_endpoint_url_get(provider); |
92 | 0 | } |
93 | 0 | } |
94 | | |
95 | 3.92k | static oidc_auth_request_method_t oidc_profile_oidc10_auth_request_method(const oidc_provider_t *provider) { |
96 | 3.92k | return oidc_cfg_provider_auth_request_method_get(provider); |
97 | 3.92k | } |
98 | | |
99 | | static const apr_array_header_t *oidc_profile_oidc10_id_token_aud_values(apr_pool_t *pool, |
100 | 3.58k | const oidc_provider_t *provider) { |
101 | 3.58k | return oidc_cfg_provider_id_token_aud_values_get(provider); |
102 | 3.58k | } |
103 | | |
104 | 12.5k | static const oidc_proto_pkce_t *oidc_profile_oidc10_pkce(const oidc_provider_t *provider) { |
105 | 12.5k | return oidc_cfg_provider_pkce_get(provider); |
106 | 12.5k | } |
107 | | |
108 | 2.89k | static oidc_dpop_mode_t oidc_profile_oidc10_dpop_mode(const oidc_provider_t *provider) { |
109 | 2.89k | return oidc_cfg_provider_dpop_mode_get(provider); |
110 | 2.89k | } |
111 | | |
112 | 2.59k | static oidc_cert_bound_tokens_t oidc_profile_oidc10_cert_bound_tokens(const oidc_provider_t *provider) { |
113 | 2.59k | return oidc_cfg_provider_cert_bound_tokens_get(provider); |
114 | 2.59k | } |
115 | | |
116 | 6.02k | static int oidc_profile_oidc10_response_require_iss(const oidc_provider_t *provider) { |
117 | 6.02k | return oidc_cfg_provider_response_require_iss_get(provider); |
118 | 6.02k | } |
119 | | |
120 | 0 | static const char *oidc_profile_oidc10_request_uri_scope(const oidc_provider_t *provider) { |
121 | | // OpenID Connect Core 1.0 incorporating errata set 2 section 6.2: even if a scope parameter is present in |
122 | | // the referenced Request Object, a scope parameter MUST always be passed using the OAuth 2.0 request |
123 | | // syntax containing the openid scope value |
124 | 0 | return OIDC_PROTO_SCOPE_OPENID; |
125 | 0 | } |
126 | | |
127 | | static oidc_proto_endpoint_auth_policy_t |
128 | 2.66k | oidc_profile_oidc10_token_endpoint_auth_policy(apr_byte_t b_secret, apr_byte_t b_cert, apr_byte_t b_key) { |
129 | | // RFC 8705 mutual-TLS client authentication is selected only when a certificate is configured without a |
130 | | // client secret: with a secret, the certificate may be there for (section 3) token binding only |
131 | 2.66k | oidc_proto_endpoint_auth_policy_t policy = {FALSE, NULL, OIDC_ENDPOINT_AUTH_CLIENT_SECRET_BASIC}; |
132 | 2.66k | if ((b_secret == FALSE) && (b_cert == TRUE)) { |
133 | 0 | policy.allow_mtls = TRUE; |
134 | 0 | policy.preference = OIDC_ENDPOINT_AUTH_TLS_CLIENT_AUTH; |
135 | 0 | } |
136 | 2.66k | return policy; |
137 | 2.66k | } |
138 | | |
139 | 258 | static const char *oidc_profile_oidc10_token_endpoint_auth(const oidc_cfg_t *cfg, const oidc_provider_t *provider) { |
140 | | // NULL makes oidc_proto_token_endpoint_auth use client_secret_basic when a client secret is configured, |
141 | | // or no client authentication at all (a public client) when it is not |
142 | 258 | return oidc_cfg_provider_token_endpoint_auth_get(provider); |
143 | 258 | } |
144 | | |
145 | 258 | static const char *oidc_profile_oidc10_token_endpoint_auth_alg(const oidc_cfg_t *cfg, const oidc_provider_t *provider) { |
146 | | // NULL makes oidc_proto_token_endpoint_auth derive the algorithm from the signing key, i.e. RS256 for an |
147 | | // RSA key (see oidc_jwk_default_jws_alg) |
148 | 258 | return oidc_cfg_provider_token_endpoint_auth_alg_get(provider); |
149 | 258 | } |
150 | | |
151 | | static const oidc_proto_profile_ops_t _oidc_profile_oidc10_ops = { |
152 | | oidc_profile_oidc10_token_endpoint_auth_aud, |
153 | | oidc_profile_oidc10_revocation_endpoint_auth_aud, |
154 | | oidc_profile_oidc10_auth_request_method, |
155 | | oidc_profile_oidc10_id_token_aud_values, |
156 | | oidc_profile_oidc10_pkce, |
157 | | oidc_profile_oidc10_dpop_mode, |
158 | | oidc_profile_oidc10_cert_bound_tokens, |
159 | | oidc_profile_oidc10_response_require_iss, |
160 | | oidc_profile_oidc10_request_uri_scope, |
161 | | oidc_profile_oidc10_token_endpoint_auth_policy, |
162 | | oidc_profile_oidc10_token_endpoint_auth, |
163 | | oidc_profile_oidc10_token_endpoint_auth_alg, |
164 | | NULL, |
165 | | }; |
166 | | |
167 | | /* |
168 | | * FAPI 2.0 Security Profile: harden the settings the profile mandates |
169 | | */ |
170 | | |
171 | 0 | static const char *oidc_profile_fapi20_token_endpoint_auth_aud(const oidc_provider_t *provider) { |
172 | 0 | return oidc_cfg_provider_issuer_get(provider); |
173 | 0 | } |
174 | | |
175 | 0 | static const char *oidc_profile_fapi20_revocation_endpoint_auth_aud(const oidc_provider_t *provider, const char *val) { |
176 | 0 | return oidc_cfg_provider_issuer_get(provider); |
177 | 0 | } |
178 | | |
179 | 2 | static oidc_auth_request_method_t oidc_profile_fapi20_auth_request_method(const oidc_provider_t *provider) { |
180 | 2 | return OIDC_AUTH_REQUEST_METHOD_PAR; |
181 | 2 | } |
182 | | |
183 | | static const apr_array_header_t *oidc_profile_fapi20_id_token_aud_values(apr_pool_t *pool, |
184 | 0 | const oidc_provider_t *provider) { |
185 | | // NB: the acceptable "aud" values may be overridden; when they are, the client_id is assumed (but not |
186 | | // enforced, even for FAPI20) to be among them |
187 | 0 | const apr_array_header_t *values = oidc_cfg_provider_id_token_aud_values_get(provider); |
188 | 0 | if (values == NULL) { |
189 | 0 | apr_array_header_t *list = NULL; |
190 | 0 | oidc_cfg_string_list_add(pool, &list, oidc_cfg_provider_client_id_get(provider)); |
191 | 0 | return list; |
192 | 0 | } |
193 | 0 | return values; |
194 | 0 | } |
195 | | |
196 | 2 | static const oidc_proto_pkce_t *oidc_profile_fapi20_pkce(const oidc_provider_t *provider) { |
197 | 2 | return &oidc_pkce_s256; |
198 | 2 | } |
199 | | |
200 | 2 | static oidc_dpop_mode_t oidc_profile_fapi20_dpop_mode(const oidc_provider_t *provider) { |
201 | | // FAPI 2.0 Security Profile section 5.3.2.1: access tokens shall be sender-constrained using |
202 | | // *either* RFC 8705 mutual-TLS certificate binding *or* RFC 9449 DPoP. Mandating DPoP regardless |
203 | | // breaks the mutual-TLS variant of the profile against an OP that does not support DPoP at all, |
204 | | // so stand down when the access tokens are certificate-bound (as resolved into the provider |
205 | | // struct by oidc_metadata_provider_parse) and the OP does not advertise DPoP support; the |
206 | | // configured mode then applies, so DPoP can still be asked for explicitly |
207 | 2 | oidc_cert_bound_tokens_t mode = oidc_cfg_provider_cert_bound_tokens_get(provider); |
208 | | |
209 | | // still "auto" means oidc_metadata_provider_parse never ran for this provider, i.e. an OP whose |
210 | | // endpoints are all configured by hand, with no provider metadata to resolve it against. Take the |
211 | | // same decision the profile hands that function in oidc_profile_fapi20_cert_bound_tokens: under |
212 | | // FAPI 2.0 a configured TLS client certificate is there for RFC 8705 binding |
213 | 2 | if (mode == OIDC_CERT_BOUND_TOKENS_AUTO) { |
214 | 1 | if (oidc_cfg_provider_token_endpoint_tls_client_cert_get(provider) != NULL) |
215 | 0 | mode = OIDC_CERT_BOUND_TOKENS_ON; |
216 | 1 | else |
217 | 1 | mode = OIDC_CERT_BOUND_TOKENS_OFF; |
218 | 1 | } |
219 | | |
220 | 2 | if ((mode == OIDC_CERT_BOUND_TOKENS_ON) && (oidc_cfg_provider_dpop_supported_get(provider) == FALSE)) |
221 | 0 | return oidc_cfg_provider_dpop_mode_get(provider); |
222 | 2 | return OIDC_DPOP_MODE_REQUIRED; |
223 | 2 | } |
224 | | |
225 | 0 | static oidc_cert_bound_tokens_t oidc_profile_fapi20_cert_bound_tokens(const oidc_provider_t *provider) { |
226 | | // FAPI 2.0 Security Profile section 5.3.2.1: access tokens are sender-constrained through either |
227 | | // mutual-TLS or DPoP, so a TLS client certificate configured against a FAPI 2.0 OP is there for |
228 | | // RFC 8705 binding; use the mutual-TLS endpoints without requiring the OP to advertise support |
229 | 0 | return OIDC_CERT_BOUND_TOKENS_ON; |
230 | 0 | } |
231 | | |
232 | 2 | static int oidc_profile_fapi20_response_require_iss(const oidc_provider_t *provider) { |
233 | 2 | return 1; |
234 | 2 | } |
235 | | |
236 | 0 | static const char *oidc_profile_fapi20_request_uri_scope(const oidc_provider_t *provider) { |
237 | | // FAPI 2.0 Security Profile section 5.3.3.2: the client shall only send the client_id and request_uri |
238 | | // request parameters to the authorization endpoint, all other parameters (scope included) are sent in |
239 | | // the pushed authorization request |
240 | 0 | return NULL; |
241 | 0 | } |
242 | | |
243 | | /* |
244 | | * FAPI 2.0 Security Profile section 5.3.3.1 item 2: the client authenticates with RFC 8705 mutual-TLS or with |
245 | | * private_key_jwt, i.e. never with a client secret and never as a public client |
246 | | */ |
247 | 0 | static const char *oidc_profile_fapi20_valid_token_endpoint_auth(apr_pool_t *pool, const char *arg) { |
248 | 0 | static const char *options[] = {OIDC_ENDPOINT_AUTH_PRIVATE_KEY_JWT, OIDC_ENDPOINT_AUTH_TLS_CLIENT_AUTH, |
249 | 0 | OIDC_ENDPOINT_AUTH_SELF_SIGNED_TLS_CLIENT_AUTH, NULL}; |
250 | 0 | return oidc_cfg_parse_is_valid_option(pool, arg, options); |
251 | 0 | } |
252 | | |
253 | | /* |
254 | | * the FAPI 2.0 client authentication method that the configured credentials can perform: a certificate |
255 | | * configured without a client secret keeps meaning mutual-TLS, as it does for OIDC10, so that it is only the |
256 | | * selections that FAPI 2.0 does not permit that change; otherwise a signing key means private_key_jwt and a |
257 | | * certificate next to a (useless under FAPI 2.0) client secret still means mutual-TLS |
258 | | */ |
259 | | static const char *oidc_profile_fapi20_token_endpoint_auth_preference(apr_byte_t b_secret, apr_byte_t b_cert, |
260 | 0 | apr_byte_t b_key) { |
261 | 0 | if ((b_cert == TRUE) && (b_secret == FALSE)) |
262 | 0 | return OIDC_ENDPOINT_AUTH_TLS_CLIENT_AUTH; |
263 | 0 | if (b_key == TRUE) |
264 | 0 | return OIDC_ENDPOINT_AUTH_PRIVATE_KEY_JWT; |
265 | 0 | if (b_cert == TRUE) |
266 | 0 | return OIDC_ENDPOINT_AUTH_TLS_CLIENT_AUTH; |
267 | 0 | return NULL; |
268 | 0 | } |
269 | | |
270 | | static oidc_proto_endpoint_auth_policy_t |
271 | 0 | oidc_profile_fapi20_token_endpoint_auth_policy(apr_byte_t b_secret, apr_byte_t b_cert, apr_byte_t b_key) { |
272 | | // a client secret cannot be used for authentication here, so it does not stop a configured certificate from |
273 | | // making the mutual-TLS methods candidates |
274 | 0 | oidc_proto_endpoint_auth_policy_t policy = { |
275 | 0 | b_cert, oidc_profile_fapi20_valid_token_endpoint_auth, |
276 | 0 | oidc_profile_fapi20_token_endpoint_auth_preference(b_secret, b_cert, b_key)}; |
277 | 0 | return policy; |
278 | 0 | } |
279 | | |
280 | 0 | static const char *oidc_profile_fapi20_token_endpoint_auth(const oidc_cfg_t *cfg, const oidc_provider_t *provider) { |
281 | | // a configured (or, from Provider metadata, selected) method applies as-is: unlike the other settings it |
282 | | // cannot be overridden, since it depends on credentials and on a client registration at the Provider |
283 | 0 | const char *auth = oidc_cfg_provider_token_endpoint_auth_get(provider); |
284 | 0 | if (auth != NULL) |
285 | 0 | return auth; |
286 | | // none is set when the Provider's endpoints are all configured by hand, i.e. when there is no |
287 | | // "token_endpoint_auth_methods_supported" to select from; decide on the configured credentials alone |
288 | 0 | return oidc_profile_fapi20_token_endpoint_auth_preference( |
289 | 0 | oidc_cfg_provider_client_secret_get(provider) != NULL, |
290 | 0 | oidc_cfg_provider_token_endpoint_tls_client_cert_get(provider) != NULL, |
291 | 0 | oidc_cfg_private_keys_get(cfg) != NULL); |
292 | 0 | } |
293 | | |
294 | | /* |
295 | | * FAPI 2.0 Security Profile section 5.4.1 item 1.2: JWTs are created and processed with PS256, ES256 or EdDSA |
296 | | * (the Ed25519 variant) only |
297 | | */ |
298 | 0 | static const char *oidc_profile_fapi20_valid_jws_alg(apr_pool_t *pool, const char *arg) { |
299 | 0 | static const char *options[] = {OIDC_JOSE_HDR_ALG_PS256, OIDC_JOSE_HDR_ALG_ES256, OIDC_JOSE_HDR_ALG_EDDSA, |
300 | 0 | NULL}; |
301 | 0 | return oidc_cfg_parse_is_valid_option(pool, arg, options); |
302 | 0 | } |
303 | | |
304 | 0 | static const char *oidc_profile_fapi20_token_endpoint_auth_alg(const oidc_cfg_t *cfg, const oidc_provider_t *provider) { |
305 | | // a configured algorithm applies as-is, as a configured method does (see |
306 | | // oidc_profile_fapi20_token_endpoint_auth); a startup warning reports one that FAPI 2.0 does not permit |
307 | 0 | const char *alg = oidc_cfg_provider_token_endpoint_auth_alg_get(provider); |
308 | 0 | if (alg != NULL) |
309 | 0 | return alg; |
310 | | // section 5.4.1 item 1.2 rules out the RS256 that is the default for an RSA key, so use PS256 as the DPoP |
311 | | // proofs do; an Elliptic Curve key keeps the algorithm for its curve, which is ES256 on P-256, the only curve |
312 | | // that a permitted algorithm can be used with |
313 | 0 | const char *x5t = NULL; |
314 | 0 | return oidc_proto_jwt_alg_for_key( |
315 | 0 | oidc_proto_endpoint_auth_pick_signing_key(cfg, oidc_cfg_provider_client_keys_get(provider), &x5t), TRUE); |
316 | 0 | } |
317 | | |
318 | | static const oidc_proto_profile_ops_t _oidc_profile_fapi20_ops = { |
319 | | oidc_profile_fapi20_token_endpoint_auth_aud, |
320 | | oidc_profile_fapi20_revocation_endpoint_auth_aud, |
321 | | oidc_profile_fapi20_auth_request_method, |
322 | | oidc_profile_fapi20_id_token_aud_values, |
323 | | oidc_profile_fapi20_pkce, |
324 | | oidc_profile_fapi20_dpop_mode, |
325 | | oidc_profile_fapi20_cert_bound_tokens, |
326 | | oidc_profile_fapi20_response_require_iss, |
327 | | oidc_profile_fapi20_request_uri_scope, |
328 | | oidc_profile_fapi20_token_endpoint_auth_policy, |
329 | | oidc_profile_fapi20_token_endpoint_auth, |
330 | | oidc_profile_fapi20_token_endpoint_auth_alg, |
331 | | oidc_profile_fapi20_valid_jws_alg, |
332 | | }; |
333 | | |
334 | | /* |
335 | | * return the ops for the provider's configured profile |
336 | | */ |
337 | 35.0k | static const oidc_proto_profile_ops_t *oidc_proto_profile_ops(const oidc_provider_t *provider) { |
338 | 35.0k | switch (oidc_cfg_provider_profile_get(provider)) { |
339 | 8 | case OIDC_PROFILE_FAPI20: |
340 | 8 | return &_oidc_profile_fapi20_ops; |
341 | 35.0k | case OIDC_PROFILE_OIDC10: |
342 | 35.0k | default: |
343 | 35.0k | return &_oidc_profile_oidc10_ops; |
344 | 35.0k | } |
345 | 35.0k | } |
346 | | |
347 | | /* |
348 | | * wrap a client assertion "aud" value, recording whether it is the provider's issuer identifier (RFC 10070) |
349 | | */ |
350 | | static oidc_proto_endpoint_auth_aud_t oidc_proto_profile_endpoint_auth_aud(const oidc_provider_t *provider, |
351 | 258 | const char *value) { |
352 | 258 | const char *issuer = oidc_cfg_provider_issuer_get(provider); |
353 | 258 | oidc_proto_endpoint_auth_aud_t aud = {value, FALSE}; |
354 | 258 | aud.is_issuer = (value != NULL) && (issuer != NULL) && (_oidc_strcmp(value, issuer) == 0); |
355 | 258 | return aud; |
356 | 258 | } |
357 | | |
358 | | /* |
359 | | * returns the "aud" claim to insert into the JWT used for client authentication towards the token and |
360 | | * pushed authorization request endpoints using private_key_jwt/client_secret_jwt |
361 | | */ |
362 | 258 | oidc_proto_endpoint_auth_aud_t oidc_proto_profile_token_endpoint_auth_aud(const oidc_provider_t *provider) { |
363 | 258 | return oidc_proto_profile_endpoint_auth_aud( |
364 | 258 | provider, oidc_proto_profile_ops(provider)->token_endpoint_auth_aud(provider)); |
365 | 258 | } |
366 | | |
367 | | /* |
368 | | * returns the "aud" claim to insert into the JWT used for client |
369 | | * authentication towards the revocation endpoint using private_key_jwt/client_secret_jwt |
370 | | */ |
371 | | oidc_proto_endpoint_auth_aud_t oidc_proto_profile_revocation_endpoint_auth_aud(const oidc_provider_t *provider, |
372 | 0 | const char *val) { |
373 | 0 | return oidc_proto_profile_endpoint_auth_aud( |
374 | 0 | provider, oidc_proto_profile_ops(provider)->revocation_endpoint_auth_aud(provider, val)); |
375 | 0 | } |
376 | | |
377 | | /* |
378 | | * returns the method to be used when sending the authorization request to the Provider |
379 | | */ |
380 | 3.92k | oidc_auth_request_method_t oidc_proto_profile_auth_request_method_get(const oidc_provider_t *provider) { |
381 | 3.92k | return oidc_proto_profile_ops(provider)->auth_request_method(provider); |
382 | 3.92k | } |
383 | | |
384 | | /* |
385 | | * returns the acceptable "aud" values in the ID token |
386 | | */ |
387 | | const apr_array_header_t *oidc_proto_profile_id_token_aud_values_get(apr_pool_t *pool, |
388 | 3.58k | const oidc_provider_t *provider) { |
389 | 3.58k | return oidc_proto_profile_ops(provider)->id_token_aud_values(pool, provider); |
390 | 3.58k | } |
391 | | |
392 | | /* |
393 | | * returns the PKCE mode |
394 | | */ |
395 | 12.5k | const oidc_proto_pkce_t *oidc_proto_profile_pkce_get(const oidc_provider_t *provider) { |
396 | 12.5k | return oidc_proto_profile_ops(provider)->pkce(provider); |
397 | 12.5k | } |
398 | | |
399 | | /* |
400 | | * returns the DPoP mode |
401 | | */ |
402 | 2.89k | oidc_dpop_mode_t oidc_proto_profile_dpop_mode_get(const oidc_provider_t *provider) { |
403 | 2.89k | return oidc_proto_profile_ops(provider)->dpop_mode(provider); |
404 | 2.89k | } |
405 | | |
406 | | /* |
407 | | * returns whether to obtain RFC 8705 certificate-bound access tokens with a configured TLS client |
408 | | * certificate that is not (also) used for mutual-TLS client authentication |
409 | | */ |
410 | 2.59k | oidc_cert_bound_tokens_t oidc_proto_profile_cert_bound_tokens_get(const oidc_provider_t *provider) { |
411 | 2.59k | return oidc_proto_profile_ops(provider)->cert_bound_tokens(provider); |
412 | 2.59k | } |
413 | | |
414 | | /* |
415 | | * returns whether the Provider is required to pass back an "iss" parameter |
416 | | * together with the authorization response sent to the Redirect URI |
417 | | */ |
418 | 6.02k | int oidc_proto_profile_response_require_iss_get(const oidc_provider_t *provider) { |
419 | 6.02k | return oidc_proto_profile_ops(provider)->response_require_iss(provider); |
420 | 6.02k | } |
421 | | |
422 | | /* |
423 | | * returns the value of the "scope" parameter to add to an authorization request that |
424 | | * references its parameters through a "request_uri", or NULL when it must be omitted |
425 | | */ |
426 | 0 | const char *oidc_proto_profile_request_uri_scope_get(const oidc_provider_t *provider) { |
427 | 0 | return oidc_proto_profile_ops(provider)->request_uri_scope(provider); |
428 | 0 | } |
429 | | |
430 | | /* |
431 | | * returns how to select the token endpoint authentication method from the methods advertised by the Provider, |
432 | | * given whether a client secret and a TLS client certificate are configured for it; a NULL provider (the OAuth 2.0 |
433 | | * Resource Server role) applies the plain OpenID Connect 1.0 selection |
434 | | */ |
435 | | oidc_proto_endpoint_auth_policy_t oidc_proto_profile_token_endpoint_auth_policy(const oidc_cfg_t *cfg, |
436 | | const oidc_provider_t *provider, |
437 | | apr_byte_t b_secret, |
438 | 2.66k | apr_byte_t b_cert) { |
439 | 2.66k | const oidc_proto_profile_ops_t *ops = |
440 | 2.66k | (provider != NULL) ? oidc_proto_profile_ops(provider) : &_oidc_profile_oidc10_ops; |
441 | 2.66k | return ops->token_endpoint_auth_policy(b_secret, b_cert, oidc_cfg_private_keys_get(cfg) != NULL); |
442 | 2.66k | } |
443 | | |
444 | | /* |
445 | | * returns the token endpoint authentication method to use towards the token, pushed authorization request and |
446 | | * revocation endpoints; NULL means client_secret_basic with a client secret and a public client without one |
447 | | */ |
448 | 258 | const char *oidc_proto_profile_token_endpoint_auth_get(const oidc_cfg_t *cfg, const oidc_provider_t *provider) { |
449 | 258 | return oidc_proto_profile_ops(provider)->token_endpoint_auth(cfg, provider); |
450 | 258 | } |
451 | | |
452 | | /* |
453 | | * returns whether the profile permits a token endpoint authentication method; NULL stands for the default |
454 | | * of oidc_proto_token_endpoint_auth (client_secret_basic, or a public client) |
455 | | */ |
456 | | apr_byte_t oidc_proto_profile_token_endpoint_auth_permitted(apr_pool_t *pool, const oidc_provider_t *provider, |
457 | 0 | const char *method) { |
458 | 0 | oidc_valid_function_t permitted = |
459 | 0 | oidc_proto_profile_ops(provider)->token_endpoint_auth_policy(FALSE, FALSE, FALSE).permitted; |
460 | 0 | if (permitted == NULL) |
461 | 0 | return TRUE; |
462 | 0 | return ((method != NULL) && (permitted(pool, method) == NULL)) ? TRUE : FALSE; |
463 | 0 | } |
464 | | |
465 | | /* |
466 | | * returns the JWS algorithm to sign the private_key_jwt client assertion with towards the token, pushed |
467 | | * authorization request and revocation endpoints; NULL derives it from the signing key |
468 | | */ |
469 | 258 | const char *oidc_proto_profile_token_endpoint_auth_alg_get(const oidc_cfg_t *cfg, const oidc_provider_t *provider) { |
470 | 258 | return oidc_proto_profile_ops(provider)->token_endpoint_auth_alg(cfg, provider); |
471 | 258 | } |
472 | | |
473 | | /* |
474 | | * returns whether the profile permits a JWS algorithm for a JWT that the client creates |
475 | | */ |
476 | 0 | apr_byte_t oidc_proto_profile_jws_alg_permitted(apr_pool_t *pool, const oidc_provider_t *provider, const char *alg) { |
477 | 0 | oidc_valid_function_t permitted = oidc_proto_profile_ops(provider)->jws_alg_permitted; |
478 | 0 | if (permitted == NULL) |
479 | 0 | return TRUE; |
480 | 0 | return ((alg != NULL) && (permitted(pool, alg) == NULL)) ? TRUE : FALSE; |
481 | 0 | } |