Skip to content

Commit 7882d73

Browse files
committed
fix OIDCOAuthVerifyCertFiles #989; add OIDCProviderVerifyCertFiles #990
- add OIDCProviderVerifyCertFiles option to statically configure ID token validation keys; see #989; thanks @madsfreek - fix bug in OIDCOAuthVerifyCertFiles where cert(s) would be cast to apr_hash_t instead of apr_array_header_t; see #990; thanks @bommo1 - bump to 2.4.12.3rc0 Signed-off-by: Hans Zandbelt <[email protected]>
1 parent 37b1917 commit 7882d73

File tree

9 files changed

+37
-11
lines changed

9 files changed

+37
-11
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,4 @@ reporting bugs, providing fixes, suggesting useful features or other:
8787
Nikhil Chaudhari <https://github.com/nvchaudhari1991>
8888
Quentin Gillet <[email protected]>
8989
Brent van Laere <[email protected]>
90+
Mads Freek Petersen <https://github.com/madsfreek>

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
01/20/2023
2+
- add OIDCProviderVerifyCertFiles option to statically configure ID token validation keys; see #989; thanks @madsfreek
3+
- fix bug in OIDCOAuthVerifyCertFiles where cert(s) would be cast to apr_hash_t instead of apr_array_header_t; see #990; thanks @bommo1
4+
- bump to 2.4.12.3rc0
5+
16
12/28/2022
27
- update sample/test Dockerfile to Ubuntu Jammy
38

auth_openidc.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@
6565
# Used when OIDCProviderMetadataURL is not defined or the metadata obtained from that URL does not set it.
6666
#OIDCProviderJwksUri <jwks_url>
6767

68+
# The fully qualified names of the files that contain the X.509 certificates with the RSA public
69+
# keys that can be used for ID Token verification.
70+
# NB: this is one or more key tuples where a key tuple consists of:
71+
# [<key-identifier>#]<path-to-cert>
72+
# and the key identifier part is required when the ID Token contains a "kid" in its header.
73+
# When not defined, ID Token validation key material has to be obtained through OIDCProviderJwksUri or OIDCProviderMetadataURL
74+
#OIDCProviderVerifyCertFiles ([<kid>#]<filename>)+
75+
6876
# OpenID Connect Provider Token Endpoint URL (e.g. https://localhost:9031/as/token.oauth2)
6977
# Used when OIDCProviderMetadataURL is not defined or the metadata obtained from that URL does not set it.
7078
#OIDCProviderTokenEndpoint <token_endpoint>

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
AC_INIT([mod_auth_openidc],[2.4.12.2],[[email protected]])
1+
AC_INIT([mod_auth_openidc],[2.4.12.3rc0],[[email protected]])
22

33
AC_SUBST(NAMEVER, AC_PACKAGE_TARNAME()-AC_PACKAGE_VERSION())
44

src/config.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@
173173
#define OIDCProviderEndSessionEndpoint "OIDCProviderEndSessionEndpoint"
174174
#define OIDCProviderBackChannelLogoutSupported "OIDCProviderBackChannelLogoutSupported"
175175
#define OIDCProviderJwksUri "OIDCProviderJwksUri"
176+
#define OIDCProviderVerifyCertFiles "OIDCProviderVerifyCertFiles"
176177
#define OIDCResponseType "OIDCResponseType"
177178
#define OIDCResponseMode "OIDCResponseMode"
178179
#define OIDCPublicKeyFiles "OIDCPublicKeyFiles"
@@ -1417,6 +1418,7 @@ void oidc_cfg_provider_init(oidc_provider_t *provider) {
14171418
provider->check_session_iframe = NULL;
14181419
provider->end_session_endpoint = NULL;
14191420
provider->jwks_uri = NULL;
1421+
provider->verify_public_keys = NULL;
14201422
provider->backchannel_logout_supported = OIDC_CONFIG_POS_INT_UNSET;
14211423

14221424
provider->ssl_validate_server = OIDC_DEFAULT_SSL_VALIDATE_SERVER;
@@ -1633,6 +1635,10 @@ void* oidc_merge_server_config(apr_pool_t *pool, void *BASE, void *ADD) {
16331635
c->provider.jwks_uri =
16341636
add->provider.jwks_uri != NULL ?
16351637
add->provider.jwks_uri : base->provider.jwks_uri;
1638+
c->provider.verify_public_keys =
1639+
add->provider.verify_public_keys != NULL ?
1640+
add->provider.verify_public_keys :
1641+
base->provider.verify_public_keys;
16361642
c->provider.client_id =
16371643
add->provider.client_id != NULL ?
16381644
add->provider.client_id : base->provider.client_id;
@@ -2677,7 +2683,9 @@ static apr_status_t oidc_cleanup_child(void *data) {
26772683

26782684
// can do this even though we haven't got a deep copy
26792685
// since references within the object will be set to NULL
2680-
oidc_jwk_list_destroy_hash(sp->process->pool,
2686+
oidc_jwk_list_destroy(sp->process->pool,
2687+
cfg->provider.verify_public_keys);
2688+
oidc_jwk_list_destroy(sp->process->pool,
26812689
cfg->oauth.verify_public_keys);
26822690
oidc_jwk_list_destroy_hash(sp->process->pool,
26832691
cfg->oauth.verify_shared_keys);
@@ -3058,6 +3066,11 @@ const command_rec oidc_config_cmds[] = {
30583066
(void *)APR_OFFSETOF(oidc_cfg, provider.jwks_uri),
30593067
RSRC_CONF,
30603068
"Define the OpenID OP JWKS URL (e.g.: https://localhost:9031/pf/JWKS)"),
3069+
AP_INIT_ITERATE(OIDCProviderVerifyCertFiles,
3070+
oidc_set_public_key_files,
3071+
(void*)APR_OFFSETOF(oidc_cfg, provider.verify_public_keys),
3072+
RSRC_CONF,
3073+
"The fully qualified names of the files that contain the X.509 certificates that contains the RSA public keys that can be used for ID token validation."),
30613074
AP_INIT_TAKE1(OIDCResponseType,
30623075
oidc_set_response_type,
30633076
(void *)APR_OFFSETOF(oidc_cfg, provider.response_type),

src/mod_auth_openidc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3024,7 +3024,7 @@ static int oidc_handle_logout_backchannel(request_rec *r, oidc_cfg *cfg) {
30243024
oidc_jwks_uri_t jwks_uri = { provider->jwks_uri,
30253025
provider->jwks_refresh_interval, provider->ssl_validate_server };
30263026
if (oidc_proto_jwt_verify(r, cfg, jwt, &jwks_uri,
3027-
oidc_util_merge_symmetric_key(r->pool, NULL, jwk),
3027+
oidc_util_merge_symmetric_key(r->pool, provider->verify_public_keys, jwk),
30283028
provider->id_token_signed_response_alg) == FALSE) {
30293029

30303030
oidc_error(r, "id_token signature could not be validated, aborting");

src/mod_auth_openidc.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ typedef struct oidc_provider_t {
296296
char *check_session_iframe;
297297
char *end_session_endpoint;
298298
char *jwks_uri;
299+
apr_array_header_t *verify_public_keys;
299300
char *client_id;
300301
char *client_secret;
301302
char *token_endpoint_tls_client_key;
@@ -364,7 +365,7 @@ typedef struct oidc_oauth_t {
364365
oidc_remote_user_claim_t remote_user_claim;
365366
apr_hash_t *verify_shared_keys;
366367
char *verify_jwks_uri;
367-
apr_hash_t *verify_public_keys;
368+
apr_array_header_t *verify_public_keys;
368369
int access_token_binding_policy;
369370
} oidc_oauth_t;
370371

src/oauth.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -612,19 +612,17 @@ static apr_byte_t oidc_oauth_validate_jwt_access_token(request_rec *r,
612612
oidc_debug(r,
613613
"verify JWT against %d statically configured public keys and %d shared keys, with JWKs URI set to %s",
614614
c->oauth.verify_public_keys ?
615-
apr_hash_count(c->oauth.verify_public_keys) : 0,
615+
c->oauth.verify_public_keys->nelts : 0,
616616
c->oauth.verify_shared_keys ?
617617
apr_hash_count(c->oauth.verify_shared_keys) : 0,
618618
c->oauth.verify_jwks_uri);
619619

620620
// TODO: we're re-using the OIDC provider JWKs refresh interval here...
621621
oidc_jwks_uri_t jwks_uri = { c->oauth.verify_jwks_uri,
622622
c->provider.jwks_refresh_interval, c->oauth.ssl_validate_server };
623-
if (oidc_proto_jwt_verify(r, c, jwt, &jwks_uri,
624-
oidc_util_merge_key_sets_hash(r->pool, c->oauth.verify_public_keys,
625-
c->oauth.verify_shared_keys), NULL) == FALSE) {
626-
oidc_error(r,
627-
"JWT access token signature could not be validated, aborting");
623+
if (oidc_proto_jwt_verify(r, c, jwt, &jwks_uri, oidc_util_merge_key_sets(r->pool, c->oauth.verify_shared_keys, c->oauth.verify_public_keys), NULL)
624+
== FALSE) {
625+
oidc_error(r, "JWT access token signature could not be validated, aborting");
628626
oidc_jwt_destroy(jwt);
629627
return FALSE;
630628
}

src/proto.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1668,7 +1668,7 @@ apr_byte_t oidc_proto_parse_idtoken(request_rec *r, oidc_cfg *cfg,
16681668
oidc_jwks_uri_t jwks_uri = { provider->jwks_uri,
16691669
provider->jwks_refresh_interval, provider->ssl_validate_server };
16701670
if (oidc_proto_jwt_verify(r, cfg, *jwt, &jwks_uri,
1671-
oidc_util_merge_symmetric_key(r->pool, NULL, jwk),
1671+
oidc_util_merge_symmetric_key(r->pool, provider->verify_public_keys, jwk),
16721672
provider->id_token_signed_response_alg) == FALSE) {
16731673

16741674
oidc_error(r,

0 commit comments

Comments
 (0)