@@ -707,17 +707,15 @@ void oauth2_jose_jwk_list_free(oauth2_log_t *log, oauth2_jose_jwk_list_t *keys)
707
707
708
708
static oauth2_jose_jwk_list_t *
709
709
oauth2_jose_jwks_list_resolve (oauth2_log_t * , oauth2_jose_jwks_provider_t * ,
710
- bool * , const cjose_header_t * );
710
+ bool * , cjose_header_t * );
711
711
static oauth2_jose_jwk_list_t *
712
712
oauth2_jose_jwks_uri_resolve (oauth2_log_t * , oauth2_jose_jwks_provider_t * ,
713
- bool * , const cjose_header_t * );
714
- static oauth2_jose_jwk_list_t *
715
- oauth2_jose_jwks_eckey_url_resolve (oauth2_log_t * ,
716
- oauth2_jose_jwks_provider_t * , bool * ,
717
- const cjose_header_t * );
713
+ bool * , cjose_header_t * );
714
+ static oauth2_jose_jwk_list_t * oauth2_jose_jwks_eckey_url_resolve (
715
+ oauth2_log_t * , oauth2_jose_jwks_provider_t * , bool * , cjose_header_t * );
718
716
static oauth2_jose_jwk_list_t *
719
717
oauth2_jose_jwks_aws_alb_resolve (oauth2_log_t * , oauth2_jose_jwks_provider_t * ,
720
- bool * , const cjose_header_t * );
718
+ bool * , cjose_header_t * );
721
719
722
720
static oauth2_jose_jwks_provider_t *
723
721
_oauth2_jose_jwks_provider_init (oauth2_log_t * log ,
@@ -1892,7 +1890,7 @@ _OAUTH_CFG_CTX_CALLBACK(oauth2_jose_verify_options_jwk_set_aws_alb)
1892
1890
static oauth2_jose_jwk_list_t *
1893
1891
oauth2_jose_jwks_list_resolve (oauth2_log_t * log ,
1894
1892
oauth2_jose_jwks_provider_t * provider ,
1895
- bool * refresh , const cjose_header_t * hdr )
1893
+ bool * refresh , cjose_header_t * hdr )
1896
1894
{
1897
1895
* refresh = false;
1898
1896
return oauth2_jose_jwk_list_clone (log , provider -> jwks );
@@ -2219,7 +2217,7 @@ static oauth2_jose_jwk_list_t *_oauth2_jose_jwks_resolve_from_uri(
2219
2217
static oauth2_jose_jwk_list_t *
2220
2218
oauth2_jose_jwks_uri_resolve (oauth2_log_t * log ,
2221
2219
oauth2_jose_jwks_provider_t * provider ,
2222
- bool * refresh , const cjose_header_t * hdr )
2220
+ bool * refresh , cjose_header_t * hdr )
2223
2221
{
2224
2222
return _oauth2_jose_jwks_resolve_from_uri (
2225
2223
log , provider , refresh ,
@@ -2229,85 +2227,91 @@ oauth2_jose_jwks_uri_resolve(oauth2_log_t *log,
2229
2227
static oauth2_jose_jwk_list_t *
2230
2228
oauth2_jose_jwks_eckey_url_resolve (oauth2_log_t * log ,
2231
2229
oauth2_jose_jwks_provider_t * provider ,
2232
- bool * refresh , const cjose_header_t * hdr )
2230
+ bool * refresh , cjose_header_t * hdr )
2233
2231
{
2234
2232
return _oauth2_jose_jwks_resolve_from_uri (
2235
2233
log , provider , refresh ,
2236
2234
_oauth2_jose_jwks_eckey_url_resolve_response_callback );
2237
2235
}
2238
2236
2239
- static const char * _oauth2_jose_jwks_aws_alb_region (const char * arn ) {
2240
- if (!arn ) return NULL ;
2237
+ static const char * _oauth2_jose_jwks_aws_alb_region (const char * arn )
2238
+ {
2239
+ if (!arn )
2240
+ return NULL ;
2241
2241
2242
- char * arn_copy = oauth2_strdup (arn );
2243
- if (!arn_copy ) return NULL ;
2242
+ char * arn_copy = oauth2_strdup (arn );
2243
+ if (!arn_copy )
2244
+ return NULL ;
2244
2245
2245
- char * token = strtok (arn_copy , ":" );
2246
- int count = 0 ;
2247
- const char * region = NULL ;
2246
+ char * token = strtok (arn_copy , ":" );
2247
+ int count = 0 ;
2248
+ const char * region = NULL ;
2248
2249
2249
- while (token ) {
2250
- if (count == 3 ) {
2251
- region = oauth2_strdup (token );
2252
- break ;
2253
- }
2254
- token = strtok (NULL , ":" );
2255
- count ++ ;
2256
- }
2250
+ while (token ) {
2251
+ if (count == 3 ) {
2252
+ region = oauth2_strdup (token );
2253
+ break ;
2254
+ }
2255
+ token = strtok (NULL , ":" );
2256
+ count ++ ;
2257
+ }
2257
2258
2258
- oauth2_mem_free (arn_copy );
2259
- return region ;
2259
+ oauth2_mem_free (arn_copy );
2260
+ return region ;
2260
2261
}
2261
2262
2262
2263
static oauth2_jose_jwk_list_t *
2263
2264
oauth2_jose_jwks_aws_alb_resolve (oauth2_log_t * log ,
2264
2265
oauth2_jose_jwks_provider_t * provider ,
2265
- bool * refresh , const cjose_header_t * hdr )
2266
+ bool * refresh , cjose_header_t * hdr )
2266
2267
{
2267
- cjose_err err ;
2268
-
2269
- // TODO - error here, issue with const cjose_header_t *hdr
2270
- const char * signer = cjose_header_get (hdr , "signer" , & err );
2271
- const char * kid = cjose_header_get (hdr , "kid" , & err );
2272
-
2273
- if (!signer || !kid ) {
2274
- oauth2_error (log , "missing 'signer' or 'kid' in JWT header: signer=%s, kid=%s" , signer , kid );
2275
- return NULL ;
2276
- }
2277
-
2278
- // TODO - determine if theres a better place for this?
2279
- // TODO - maybe needed? timing safe compare?
2280
- if (strcmp (signer , provider -> alb_arn ) != 0 ) {
2281
- oauth2_error (log , "signer does not match configured ARN: signer=%s, arn=%s" , signer , provider -> alb_arn );
2282
- return NULL ;
2283
- }
2284
-
2285
- const char * region = _oauth2_jose_jwks_aws_alb_region (provider -> alb_arn );
2286
- if (!region ) {
2287
- oauth2_error (log , "failed to extract region from ARN: arn=%s" , provider -> alb_arn );
2288
- return NULL ;
2289
- }
2290
-
2291
- size_t url_len = strlen ("https://public-keys.auth.elb." ) + strlen (region ) + strlen (".amazonaws.com/" ) + strlen (kid ) + 1 ;
2292
- char * url = oauth2_mem_alloc (url_len );
2293
- if (!url ) {
2294
- oauth2_error (log , "oauth2_mem_alloc failed for JWKS URL" );
2295
- return NULL ;
2296
- }
2297
-
2298
- oauth2_snprintf (url , url_len , "https://public-keys.auth.elb.%s.amazonaws.com/%s" , region , kid );
2299
- oauth2_debug (log , "constructed JWKS URL: %s" , url );
2300
-
2301
- // TODO - should probably be a copy of provider?
2302
- oauth2_cfg_endpoint_set_url (provider -> jwks_uri -> endpoint , url );
2303
-
2304
- oauth2_jose_jwk_list_t * result = _oauth2_jose_jwks_resolve_from_uri (
2305
- log , provider , refresh , oauth2_jose_jwks_eckey_url_resolve_response_callback
2306
- );
2307
-
2308
- oauth2_mem_free (url );
2309
-
2310
- return result ;
2268
+ cjose_err err ;
2269
+
2270
+ const char * signer = cjose_header_get (hdr , "signer" , & err );
2271
+ const char * kid = cjose_header_get (hdr , "kid" , & err );
2272
+
2273
+ if (!signer || !kid ) {
2274
+ oauth2_error (log ,
2275
+ "missing 'signer' or 'kid' in JWT header: "
2276
+ "signer=%s, kid=%s" ,
2277
+ signer , kid );
2278
+ return NULL ;
2279
+ }
2280
+
2281
+ // TODO - maybe needed? timing safe compare?
2282
+ if (strcmp (signer , provider -> alb_arn ) != 0 ) {
2283
+ oauth2_error (
2284
+ log ,
2285
+ "signer does not match configured ARN: signer=%s, arn=%s" ,
2286
+ signer , provider -> alb_arn );
2287
+ return NULL ;
2288
+ }
2289
+
2290
+ const char * region =
2291
+ _oauth2_jose_jwks_aws_alb_region (provider -> alb_arn );
2292
+ if (!region ) {
2293
+ oauth2_error (log , "failed to extract region from ARN: arn=%s" ,
2294
+ provider -> alb_arn );
2295
+ return NULL ;
2296
+ }
2297
+
2298
+ // TODO: make the base URL configurable
2299
+ char * url = _oauth2_stradd4 (NULL , "https://public-keys.auth.elb." ,
2300
+ region , ".amazonaws.com/" , kid );
2301
+ oauth2_debug (log , "constructed ALB JWKs URL: %s" , url );
2302
+
2303
+ provider -> jwks_uri = oauth2_uri_ctx_init (log );
2304
+ oauth2_jose_options_uri_ctx (log , url , NULL , provider -> jwks_uri , NULL );
2305
+
2306
+ oauth2_jose_jwk_list_t * result = _oauth2_jose_jwks_resolve_from_uri (
2307
+ log , provider , refresh ,
2308
+ _oauth2_jose_jwks_eckey_url_resolve_response_callback );
2309
+
2310
+ oauth2_uri_ctx_free (log , provider -> jwks_uri );
2311
+ provider -> jwks_uri = NULL ;
2312
+ oauth2_mem_free (url );
2313
+
2314
+ return result ;
2311
2315
}
2312
2316
2313
2317
/*
0 commit comments