Skip to content

Commit c8005bc

Browse files
committed
add (optional) JQ support with caching in oauth2_jq_filter
- add "json_payload_claim" claim option to oauth2_cfg_target_pass_t - make oauth2_jwt_create public in jose.h - nginx: fix memory leak in _oauth2_nginx_ssl_cert_set - bump to 2.1.0dev Signed-off-by: Hans Zandbelt <[email protected]>
1 parent 4af820f commit c8005bc

23 files changed

+402
-24
lines changed

.cproject

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</extensions>
1919
</storageModule>
2020
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
21-
<configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.linuxtools.cdt.autotools.core.buildArtefactType.autotools" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.linuxtools.cdt.autotools.core.buildArtefactType.autotools,org.eclipse.cdt.build.core.buildType=org.eclipse.linuxtools.cdt.autotools.core.buildType.default" cleanCommand="rm -rf" description="" errorParsers="org.eclipse.cdt.core.CWDLocator;org.eclipse.cdt.core.GmakeErrorParser;org.eclipse.cdt.core.GCCErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.GASErrorParser" id="org.eclipse.linuxtools.cdt.autotools.core.configuration.build.1562680719" name="Build (GNU)" optionalBuildProperties="org.eclipse.cdt.docker.launcher.containerbuild.property.volumes=,org.eclipse.cdt.docker.launcher.containerbuild.property.connection=unix:///var/run/docker.sock,org.eclipse.cdt.docker.launcher.containerbuild.property.selectedvolumes=" parent="org.eclipse.linuxtools.cdt.autotools.core.configuration.build">
21+
<configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.linuxtools.cdt.autotools.core.buildArtefactType.autotools" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.linuxtools.cdt.autotools.core.buildArtefactType.autotools,org.eclipse.cdt.build.core.buildType=org.eclipse.linuxtools.cdt.autotools.core.buildType.default" cleanCommand="rm -rf" description="" errorParsers="org.eclipse.cdt.core.CWDLocator;org.eclipse.cdt.core.GmakeErrorParser;org.eclipse.cdt.core.GCCErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.GASErrorParser" id="org.eclipse.linuxtools.cdt.autotools.core.configuration.build.1562680719" name="Build (GNU)" optionalBuildProperties="org.eclipse.cdt.docker.launcher.containerbuild.property.selectedvolumes=,org.eclipse.cdt.docker.launcher.containerbuild.property.volumes=,org.eclipse.cdt.docker.launcher.containerbuild.property.connection=unix:///var/run/docker.sock" parent="org.eclipse.linuxtools.cdt.autotools.core.configuration.build">
2222
<folderInfo id="org.eclipse.linuxtools.cdt.autotools.core.configuration.build.1562680719." name="/" resourcePath="">
2323
<toolChain id="org.eclipse.linuxtools.cdt.autotools.core.toolChain.617277945" name="GNU Autotools Toolchain" superClass="org.eclipse.linuxtools.cdt.autotools.core.toolChain">
2424
<targetPlatform id="org.eclipse.linuxtools.cdt.autotools.core.toolchain.targetPlatform.359991688" isAbstract="false" name="GNU Autotools Target Platform" superClass="org.eclipse.linuxtools.cdt.autotools.core.toolchain.targetPlatform"/>
@@ -52,6 +52,7 @@
5252
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.c.compiler.option.preprocessor.def.symbols.2047978831" name="Defined symbols (-D)" superClass="gnu.c.compiler.option.preprocessor.def.symbols" useByScannerDiscovery="false" valueType="definedSymbols">
5353
<listOptionValue builtIn="false" value="HAVE_LIBHIREDIS=1"/>
5454
<listOptionValue builtIn="false" value="HAVE_LIBMEMCACHE=1"/>
55+
<listOptionValue builtIn="false" value="HAVE_LIBJQ=1"/>
5556
</option>
5657
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1754841162" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
5758
</tool>
@@ -86,7 +87,7 @@
8687
</extensions>
8788
</storageModule>
8889
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
89-
<configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.linuxtools.cdt.autotools.core.buildArtefactType.autotools" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.linuxtools.cdt.autotools.core.buildArtefactType.autotools,org.eclipse.cdt.build.core.buildType=org.eclipse.linuxtools.cdt.autotools.core.buildType.debug" cleanCommand="rm -rf" description="" errorParsers="org.eclipse.cdt.core.CWDLocator;org.eclipse.cdt.core.GmakeErrorParser;org.eclipse.cdt.core.GCCErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.GASErrorParser" id="org.eclipse.linuxtools.cdt.autotools.core.configuration.build.debug.1551656597" name="Debug (GNU)" optionalBuildProperties="org.eclipse.cdt.docker.launcher.containerbuild.property.volumes=,org.eclipse.cdt.docker.launcher.containerbuild.property.connection=unix:///var/run/docker.sock,org.eclipse.cdt.docker.launcher.containerbuild.property.selectedvolumes=" parent="org.eclipse.linuxtools.cdt.autotools.core.configuration.build.debug">
90+
<configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.linuxtools.cdt.autotools.core.buildArtefactType.autotools" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.linuxtools.cdt.autotools.core.buildArtefactType.autotools,org.eclipse.cdt.build.core.buildType=org.eclipse.linuxtools.cdt.autotools.core.buildType.debug" cleanCommand="rm -rf" description="" errorParsers="org.eclipse.cdt.core.CWDLocator;org.eclipse.cdt.core.GmakeErrorParser;org.eclipse.cdt.core.GCCErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.GASErrorParser" id="org.eclipse.linuxtools.cdt.autotools.core.configuration.build.debug.1551656597" name="Debug (GNU)" optionalBuildProperties="org.eclipse.cdt.docker.launcher.containerbuild.property.selectedvolumes=,org.eclipse.cdt.docker.launcher.containerbuild.property.volumes=,org.eclipse.cdt.docker.launcher.containerbuild.property.connection=unix:///var/run/docker.sock" parent="org.eclipse.linuxtools.cdt.autotools.core.configuration.build.debug">
9091
<folderInfo id="org.eclipse.linuxtools.cdt.autotools.core.configuration.build.debug.1551656597." name="/" resourcePath="">
9192
<toolChain id="org.eclipse.linuxtools.cdt.autotools.core.toolChain.debug.1772566252" name="GNU Autotools Toolchain" superClass="org.eclipse.linuxtools.cdt.autotools.core.toolChain.debug">
9293
<targetPlatform id="org.eclipse.linuxtools.cdt.autotools.core.toolchain.targetPlatform.debug.1422301246" isAbstract="false" name="GNU Autotools Target Platform" superClass="org.eclipse.linuxtools.cdt.autotools.core.toolchain.targetPlatform.debug"/>
@@ -118,6 +119,7 @@
118119
<listOptionValue builtIn="false" value="HAVE_LIBHIREDIS=1"/>
119120
<listOptionValue builtIn="false" value="HAVE_LIBMEMCACHE=1"/>
120121
<listOptionValue builtIn="false" value="HAVE_MEMCACHE=1"/>
122+
<listOptionValue builtIn="false" value="HAVE_LIBJQ=1"/>
121123
</option>
122124
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.814681391" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
123125
</tool>

ChangeLog

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
09/11/2024
2+
- add (optional) JQ support with caching in oauth2_jq_filter
3+
- add "json_payload_claim" claim option to oauth2_cfg_target_pass_t
4+
- make oauth2_jwt_create public in jose.h and add a json_payload parameter
5+
- nginx: fix memory leak in _oauth2_nginx_ssl_cert_set
6+
- bump to 2.1.0dev
7+
18
08/22/2024
29
- change LICENSE to Apache 2.0
310
- release 2.0.0
@@ -21,7 +28,7 @@
2128
see OpenIDC/ngx_oauth2_module#7; thanks @smanolache and @pladen
2229
- allow NGINX primitives in an if block within a location block in the http block
2330
- bump to 1.6.3dev
24-
.
31+
2532
06/05/2024
2633
- release 1.6.2
2734

Makefile.am

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ includesub_HEADERS = \
3434
include/oauth2/util.h \
3535
include/oauth2/version.h
3636

37+
if HAVE_LIBJQ
38+
includesub_HEADERS += \
39+
include/oauth2/jq.h
40+
endif
41+
3742
#
3843
# liboauth
3944
#
@@ -81,6 +86,13 @@ liboauth2_la_SOURCES = \
8186
src/openidc/state.c \
8287
src/openidc/openidc.c
8388

89+
if HAVE_LIBJQ
90+
AM_CPPFLAGS += -DHAVE_LIBJQ
91+
liboauth2_la_CFLAGS += @JQ_CFLAGS@
92+
liboauth2_la_LIBADD += @JQ_LIBS@
93+
liboauth2_la_SOURCES += src/jq.c
94+
endif
95+
8496
#
8597
# cache
8698
#
@@ -161,7 +173,7 @@ TESTS = check_liboauth2
161173
check_PROGRAMS = $(TESTS)
162174

163175
check_liboauth2_CPPFLAGS = $(liboauth2_cache_la_CPPFLAGS)
164-
check_liboauth2_CFLAGS = @OPENSSL_CFLAGS@ @CURL_CFLAGS@ @CJOSE_CFLAGS@ @PCRE2_CFLAGS@ @CHECK_CFLAGS@
176+
check_liboauth2_CFLAGS = @OPENSSL_CFLAGS@ @CURL_CFLAGS@ @CJOSE_CFLAGS@ @PCRE2_CFLAGS@ @JQ_CFLAGS@ @CHECK_CFLAGS@
165177
check_liboauth2_LDADD = liboauth2.la
166178
if HAVE_APACHE
167179
check_liboauth2_CPPFLAGS += $(liboauth2_apache_la_CPPFLAGS)
@@ -193,6 +205,11 @@ check_liboauth2_SOURCES = \
193205
test/server_stubs.c \
194206
test/provider.json \
195207
test/client.json
208+
209+
if HAVE_LIBJQ
210+
check_liboauth2_SOURCES += \
211+
test/check_jq.c
212+
endif
196213
if HAVE_APACHE
197214
check_liboauth2_SOURCES += \
198215
test/check_apache.c
@@ -216,7 +233,7 @@ test: check
216233
TAG=liboauth2/test
217234

218235
docker: clean
219-
docker build -f test/Dockerfile . -t $(TAG)
236+
docker build --progress plain -f test/Dockerfile . -t $(TAG)
220237

221238
docker-check: docker
222239
docker run -it --rm $(TAG):latest /bin/bash -c "./start.sh && make check"

configure.ac

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
AC_INIT([liboauth2],[2.0.0],[[email protected]])
1+
AC_INIT([liboauth2],[2.1.0dev],[[email protected]])
22

33
AM_INIT_AUTOMAKE([foreign no-define subdir-objects])
44
AC_CONFIG_MACRO_DIR([m4])
@@ -41,7 +41,6 @@ if test x"$have_memcache" = "xyes"; then
4141
fi
4242
AC_SUBST(MEMCACHE_PC)
4343

44-
4544
AC_ARG_WITH([redis], AS_HELP_STRING([--with-redis], [build with Redis cache support [default=autodetect]]),)
4645
if test "x$with_redis" != "xno"; then
4746
PKG_CHECK_MODULES([HIREDIS], [hiredis], [have_redis="yes"], [have_redis="no"])
@@ -54,6 +53,44 @@ if test x"$have_redis" = "xyes"; then
5453
fi
5554
AC_SUBST(HIREDIS_PC)
5655

56+
have_jq=no
57+
AC_ARG_WITH([jq],
58+
AS_HELP_STRING([--with-jq=PATH], [location of your libjq installation])])
59+
if test -n "$with_jq" ; then
60+
if test "x$with_jq" != "xno"; then
61+
if test "x$with_jq" = "xyes"; then
62+
PKG_CHECK_MODULES([JQ], [libjq >= 1.6], [have_jq="yes"], [have_jq="no"])
63+
else
64+
if test "$JQ_CFLAGS" = ""; then
65+
JQ_CFLAGS="-I$with_jq/include"
66+
fi
67+
if test "$JQ_LIBS" = ""; then
68+
JQ_LIBS="-L$with_jq/lib -ljq"
69+
fi
70+
CPPFLAGS="$JQ_CFLAGS $CPPFLAGS"
71+
AC_CHECK_HEADER([jq.h], [have_jq=yes], [have_jq=no])
72+
73+
LDFLAGS="$JQ_LIBS $LDFLAGS"
74+
AC_CHECK_LIB([jq], [jq_init], [have_jq=yes], [have_jq=no])
75+
if test "x$have_jq" = "xno" ; then
76+
AC_MSG_WARN("cannot find library for -ljq.")
77+
JQ_CFLAGS=
78+
JQ_LIBS=
79+
fi
80+
fi
81+
fi
82+
fi
83+
AM_CONDITIONAL(HAVE_LIBJQ, [test x"$have_jq" = "xyes"])
84+
AC_SUBST(JQ_CFLAGS)
85+
AC_SUBST(JQ_LIBS)
86+
if test x"$have_jq" = "xyes"; then
87+
# note the leading comma and space(s)
88+
JQ_LIBS_PC=', libjq >= 1.6'
89+
JQ_CFLAGS_PC=' -DOAUTH2_WITH_JQ'
90+
fi
91+
AC_SUBST(JQ_LIBS_PC)
92+
AC_SUBST(JQ_CFLAGS_PC)
93+
5794
AC_ARG_WITH([apache], AS_HELP_STRING([--with-apache], [build with Apache support [default=autodetect]]),)
5895
AC_ARG_WITH([apxs],
5996
[AS_HELP_STRING([--with-apxs=PATH/NAME],[path to the apxs binary for Apache [[apxs]]])],

include/oauth2/cfg.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ const char *
261261
oauth2_cfg_target_pass_get_authn_header(oauth2_cfg_target_pass_t *cfg);
262262
const char *
263263
oauth2_cfg_target_get_remote_user_claim(oauth2_cfg_target_pass_t *cfg);
264+
const char *
265+
oauth2_cfg_target_get_json_payload_claim(oauth2_cfg_target_pass_t *cfg);
264266

265267
/*
266268
* resource owner password credentials

include/oauth2/jose.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,9 @@ bool oauth2_jose_jwk_thumbprint(oauth2_log_t *log, const cjose_jwk_t *jwk,
7878
unsigned char **hash_bytes,
7979
unsigned int *hash_bytes_len);
8080

81+
char *oauth2_jwt_create(oauth2_log_t *log, cjose_jwk_t *jwk, const char *alg,
82+
const char *iss, const char *sub, const char *client_id,
83+
const char *aud, oauth2_uint_t exp, bool include_iat,
84+
bool include_jti, const json_t *json_payload);
85+
8186
#endif /* _OAUTH2_JOSE_H_ */

include/oauth2/jq.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#ifndef _OAUTH2_JQ_H
2+
#define _OAUTH2_JQ_H
3+
4+
/***************************************************************************
5+
*
6+
* Copyright (C) 2018-2024 - ZmartZone Holding BV
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*
20+
* @Author: Hans Zandbelt - [email protected]
21+
*
22+
**************************************************************************/
23+
24+
#include "oauth2/cache.h"
25+
#include "oauth2/log.h"
26+
27+
bool oauth2_jq_filter(oauth2_log_t *log, oauth2_cache_t *cache,
28+
const char *input, const char *filter, char **result);
29+
30+
#endif /* _OAUTH2_JQ_H */

liboauth2.pc.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ Name: liboauth2
1111
URL: https://github.com/OpenIDC/liboauth2
1212
Description: OAuth 2.0 / OpenID Connect implementation for C
1313
Version: @VERSION@
14-
Requires: cjose >= 0.5.1, jansson >= 2.3, libcurl, libpcre2-8, libssl, libcrypto >= 1.0.1@MEMCACHE_PC@@HIREDIS_PC@
15-
Cflags: -I${includedir}
14+
Requires: cjose >= 0.5.1, jansson >= 2.3, libcurl, libpcre2-8, libssl, libcrypto >= 1.0.1@MEMCACHE_PC@@HIREDIS_PC@@JQ_LIBS_PC@
15+
Cflags: -I${includedir}@JQ_CFLAGS_PC@
1616
Libs: -L${libdir} -loauth2

src/cfg/auth.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ static char *oauth2_cfg_endpoint_auth_private_key_jwt_options_set(
316316
auth->private_key_jwt.jwk = cjose_jwk_import(jwk, strlen(jwk), &err);
317317
if (auth->private_key_jwt.jwk == NULL) {
318318
rv = oauth2_stradd(NULL, "parsing JWK failed: ",
319-
"cjose_jws_import error: ", err.message);
319+
"cjose_jwk_import error: ", err.message);
320320
goto end;
321321
}
322322

src/cfg/target.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@
2727
#define OAUTH2_CFG_PASS_TARGET_PREFIX_DEFAULT "OAUTH2_CLAIM_"
2828
#define OAUTH2_CFG_PASS_TARGET_AUTHN_HEADER_DEFAULT NULL
2929
#define OAUTH2_CFG_PASS_TARGET_REMOTE_USER_CLAIM_DEFAULT "sub"
30+
#define OAUTH2_CFG_PASS_TARGET_JSON_PAYLOAD_CLAIM_DEFAULT NULL
3031

3132
typedef struct oauth2_cfg_target_pass_t {
3233
oauth2_flag_t as_envvars;
3334
oauth2_flag_t as_headers;
3435
char *authn_header;
3536
char *prefix;
3637
char *remote_user_claim;
38+
char *json_payload_claim;
3739
} oauth2_cfg_target_pass_t;
3840

3941
oauth2_cfg_target_pass_t *oauth2_cfg_target_pass_init(oauth2_log_t *log)
@@ -50,6 +52,7 @@ oauth2_cfg_target_pass_t *oauth2_cfg_target_pass_init(oauth2_log_t *log)
5052
pass->authn_header = NULL;
5153
pass->prefix = NULL;
5254
pass->remote_user_claim = NULL;
55+
pass->json_payload_claim = NULL;
5356

5457
end:
5558

@@ -68,6 +71,8 @@ void oauth2_cfg_target_pass_free(oauth2_log_t *log,
6871
oauth2_mem_free(pass->prefix);
6972
if (pass->remote_user_claim)
7073
oauth2_mem_free(pass->remote_user_claim);
74+
if (pass->json_payload_claim)
75+
oauth2_mem_free(pass->json_payload_claim);
7176
oauth2_mem_free(pass);
7277

7378
end:
@@ -96,6 +101,9 @@ void oauth2_cfg_target_pass_merge(oauth2_log_t *log,
96101
cfg->remote_user_claim = oauth2_strdup(add->remote_user_claim != NULL
97102
? add->remote_user_claim
98103
: base->remote_user_claim);
104+
cfg->json_payload_claim = oauth2_strdup(add->json_payload_claim != NULL
105+
? add->json_payload_claim
106+
: base->json_payload_claim);
99107

100108
end:
101109

@@ -162,6 +170,15 @@ char *oauth2_cfg_set_target_pass_options(oauth2_log_t *log,
162170
goto end;
163171
}
164172

173+
value = oauth2_nv_list_get(log, params, "json_payload_claim");
174+
if (value) {
175+
rv = oauth2_strdup(oauth2_cfg_set_str_slot(
176+
cfg, offsetof(oauth2_cfg_target_pass_t, json_payload_claim),
177+
value));
178+
if (rv)
179+
goto end;
180+
}
181+
165182
end:
166183

167184
if (params)
@@ -210,3 +227,11 @@ oauth2_cfg_target_get_remote_user_claim(oauth2_cfg_target_pass_t *cfg)
210227
return OAUTH2_CFG_PASS_TARGET_REMOTE_USER_CLAIM_DEFAULT;
211228
return cfg->remote_user_claim;
212229
}
230+
231+
const char *
232+
oauth2_cfg_target_get_json_payload_claim(oauth2_cfg_target_pass_t *cfg)
233+
{
234+
if (cfg->json_payload_claim == NULL)
235+
return OAUTH2_CFG_PASS_TARGET_JSON_PAYLOAD_CLAIM_DEFAULT;
236+
return cfg->json_payload_claim;
237+
}

0 commit comments

Comments
 (0)