The build system of this package automagically enables HMAC support
based on SSL functionality being enabled in the installed NGINX.

In order to enable this support independently, via a USE flag, a "hack"
is applied: only if GENTOO_USE_HMAC environmental variable and
preprocessor definition are defined, HMAC support is enabled.

Signed-off-by: Zurab Kvachadze <zurabid2...@gmail.com>
---
 www-nginx/ngx-set-misc/Manifest               |  1 +
 .../ngx-set-misc-0.33-hmac-configurable.patch | 71 +++++++++++++++++++
 www-nginx/ngx-set-misc/metadata.xml           | 25 +++++++
 .../ngx-set-misc/ngx-set-misc-0.33.ebuild     | 43 +++++++++++
 4 files changed, 140 insertions(+)
 create mode 100644 www-nginx/ngx-set-misc/Manifest
 create mode 100644 
www-nginx/ngx-set-misc/files/ngx-set-misc-0.33-hmac-configurable.patch
 create mode 100644 www-nginx/ngx-set-misc/metadata.xml
 create mode 100644 www-nginx/ngx-set-misc/ngx-set-misc-0.33.ebuild

diff --git a/www-nginx/ngx-set-misc/Manifest b/www-nginx/ngx-set-misc/Manifest
new file mode 100644
index 000000000000..34be9e483747
--- /dev/null
+++ b/www-nginx/ngx-set-misc/Manifest
@@ -0,0 +1 @@
+DIST ngx-set-misc-0.33.tar.gz 30084 BLAKE2B 
1aabf47e86946054d128a10290c36829152d427cf415378f5042e00e428baaf94a91e1d8ee1037b8a40197637c721492b01a82c800064decb9471149ad47bcff
 SHA512 
1ff4c947538a5bd5f9d6adcd87b37f2702f5cc90e3342bc08359cbe8f290b705a3a2daa3dedfb1df3ce4bc19478c8fcac07081c4a53a804fc2862d50078278dc
diff --git 
a/www-nginx/ngx-set-misc/files/ngx-set-misc-0.33-hmac-configurable.patch 
b/www-nginx/ngx-set-misc/files/ngx-set-misc-0.33-hmac-configurable.patch
new file mode 100644
index 000000000000..49302624efa3
--- /dev/null
+++ b/www-nginx/ngx-set-misc/files/ngx-set-misc-0.33-hmac-configurable.patch
@@ -0,0 +1,71 @@
+From 01292430b8eb0972670a3221c4809fc6a9bd98f2 Mon Sep 17 00:00:00 2001
+From: Zurab Kvachadze <zurabid2...@gmail.com>
+Date: Mon, 23 Dec 2024 00:32:18 +0100
+Subject: [PATCH] Make HMAC support easily toggleable
+
+set-misc-nginx-module tries to automagically detect the presence of the
+crypto library by checking USE_OPENSSL and MAIL_SSL shell variables.
+These variables are set by NGINX build system (see 'auto/modules') if
+OpenSSL and mail_ssl modules are being used respectively. Since set-misc
+does not actually depend on any of the NGINX's SSL modules, but rather
+on OpenSSL itself, we change the guard variable to GENTOO_USE_HMAC and
+set from within ebuild based on a USE flag.
+
+This also makes a similar change to ngx_http_set_misc_module.c file.
+
+Signed-off-by: Zurab Kvachadze <zurabid2...@gmail.com>
+---
+ config                         | 3 ++-
+ src/ngx_http_set_misc_module.c | 6 +++---
+ 2 files changed, 5 insertions(+), 4 deletions(-)
+
+diff --git a/config b/config
+index 7bb00af..58bffd4 100755
+--- a/config
++++ b/config
+@@ -54,9 +54,10 @@ SET_MISC_DEPS="                                             
                \
+             $ngx_addon_dir/src/ngx_http_set_misc_module.h                   \
+             "
+ 
+-if [ $USE_OPENSSL = YES -o $MAIL_SSL = YES ]; then
++if [ $GENTOO_USE_HMAC = YES ]; then
+     SET_MISC_DEPS="$SET_MISC_DEPS $ngx_addon_dir/src/ngx_http_set_hmac.h"
+     SET_MISC_SRCS="$SET_MISC_SRCS $ngx_addon_dir/src/ngx_http_set_hmac.c"
++    CFLAGS="$CFLAGS -DGENTOO_USE_HMAC=1"
+ fi
+ 
+ CFLAGS="$CFLAGS -DNDK_SET_VAR -DNDK_UPSTREAM_LIST"
+diff --git a/src/ngx_http_set_misc_module.c b/src/ngx_http_set_misc_module.c
+index 3b12b0e..6d4df68 100644
+--- a/src/ngx_http_set_misc_module.c
++++ b/src/ngx_http_set_misc_module.c
+@@ -18,7 +18,7 @@
+ #include "ngx_http_set_hex.h"
+ #include "ngx_http_set_base64.h"
+ #include "ngx_http_set_base64url.h"
+-#if NGX_OPENSSL
++#if GENTOO_USE_HMAC
+ #include "ngx_http_set_hmac.h"
+ #endif
+ #include "ngx_http_set_random.h"
+@@ -90,7 +90,7 @@ static ndk_set_var_t  
ngx_http_set_misc_set_encode_hex_filter = {
+ };
+ 
+ 
+-#if NGX_OPENSSL
++#if GENTOO_USE_HMAC
+ static ndk_set_var_t  ngx_http_set_misc_set_hmac_sha1_filter = {
+     NDK_SET_VAR_MULTI_VALUE,
+     (void *) ngx_http_set_misc_set_hmac_sha1,
+@@ -281,7 +281,7 @@ static ngx_command_t  ngx_http_set_misc_commands[] = {
+         0,
+         &ngx_http_set_misc_set_encode_hex_filter
+     },
+-#if NGX_OPENSSL
++#if GENTOO_USE_HMAC
+     {   ngx_string ("set_hmac_sha1"),
+         NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF
+             |NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_TAKE3,
+-- 
+2.45.3
+
diff --git a/www-nginx/ngx-set-misc/metadata.xml 
b/www-nginx/ngx-set-misc/metadata.xml
new file mode 100644
index 000000000000..327c79a8fbb6
--- /dev/null
+++ b/www-nginx/ngx-set-misc/metadata.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "https://www.gentoo.org/dtd/metadata.dtd";>
+<pkgmetadata>
+       <maintainer type="person" proxied="yes">
+               <email>zurabid2...@gmail.com</email>
+               <name>Zurab Kvachadze</name>
+       </maintainer>
+       <maintainer type="project" proxied="proxy">
+               <email>proxy-ma...@gentoo.org</email>
+               <name>Proxy Maintainers</name>
+       </maintainer>
+       <longdescription>
+               The ngx-set-mist module extends the standard NGINX 
HttpRewriteModule's directive set to
+               provide more functionalities like URI escaping and unescaping, 
JSON quoting,
+               Hexadecimal/MD5/SHA1/Base32/Base64 digest encoding and 
decoding, random number generator,
+               and more.
+       </longdescription>
+       <use>
+               <flag name="hmac">Enable support for generating HMAC digests 
using <pkg>dev-libs/openssl</pkg></flag>
+       </use>
+       <upstream>
+               
<bugs-to>https://github.com/openresty/set-misc-nginx-module/issues</bugs-to>
+               <remote-id 
type="github">openresty/set-misc-nginx-module</remote-id>
+       </upstream>
+</pkgmetadata>
diff --git a/www-nginx/ngx-set-misc/ngx-set-misc-0.33.ebuild 
b/www-nginx/ngx-set-misc/ngx-set-misc-0.33.ebuild
new file mode 100644
index 000000000000..c71366126ffe
--- /dev/null
+++ b/www-nginx/ngx-set-misc/ngx-set-misc-0.33.ebuild
@@ -0,0 +1,43 @@
+# Copyright 1999-2025 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+MY_PN="set-misc-nginx-module"
+NGINX_MOD_S="${WORKDIR}/${MY_PN}-${PV}"
+
+NGINX_MOD_LINK_MODULES=( www-nginx/ngx_devel_kit )
+
+inherit toolchain-funcs nginx-module
+
+DESCRIPTION="An NGINX module that adds various set_xxx directives to NGINX's 
rewrite module"
+HOMEPAGE="https://github.com/openresty/set-misc-nginx-module";
+SRC_URI="
+       
https://github.com/openresty/set-misc-nginx-module/archive/refs/tags/v${PV}.tar.gz
 -> ${P}.tar.gz
+"
+
+LICENSE="BSD-2"
+SLOT="0"
+
+IUSE="+hmac"
+
+RESTRICT="test"
+
+BDEPEND="virtual/pkgconfig"
+DEPEND="hmac? ( dev-libs/openssl:= )"
+RDEPEND="${DEPEND}"
+
+PATCHES=(
+       "${FILESDIR}/${PN}-0.33-hmac-configurable.patch"
+)
+
+src_configure() {
+       # These are variables patched into the build system to be able to 
control
+       # HMAC support. For more details, see the "hmac-configurable" patch 
above.
+       local -x GENTOO_USE_HMAC=NO
+       if use hmac; then
+               GENTOO_USE_HMAC=YES
+               ngx_mod_append_libs "$("$(tc-getPKG_CONFIG)" --libs libcrypto)"
+       fi
+       nginx-module_src_configure
+}
-- 
2.45.3


Reply via email to