Browse Source

[mod_redirect,mod_rewrite] base64url encoding opt

Provide means to encode redirect and rewrite backreference substitutions

  %{encb64u:...} encode to base64url characters (no-padding)
  %{decb64u:...} decode from base64url characters
personal/stbuehler/fix-fdevent
Glenn Strauss 4 years ago
parent
commit
f832b71180
  1. 2
      src/Makefile.am
  2. 8
      src/burl.c
  3. 2
      src/burl.h
  4. 10
      src/keyvalue.c

2
src/Makefile.am

@ -524,7 +524,7 @@ t_test_buffer_LDADD = $(LIBUNWIND_LIBS)
t_test_base64_SOURCES = t/test_base64.c base64.c buffer.c
t_test_base64_LDADD = $(LIBUNWIND_LIBS)
t_test_burl_SOURCES = t/test_burl.c burl.c buffer.c
t_test_burl_SOURCES = t/test_burl.c burl.c buffer.c base64.c
t_test_burl_LDADD = $(LIBUNWIND_LIBS)
t_test_configfile_SOURCES = t/test_configfile.c buffer.c array.c data_config.c data_string.c http_kv.c vector.c log.c sock_addr.c

8
src/burl.c

@ -4,6 +4,7 @@
#include <string.h>
#include "buffer.h"
#include "base64.h"
static const char hex_chars_uc[] = "0123456789ABCDEF";
@ -493,6 +494,13 @@ void burl_append (buffer * const b, const char * const str, const size_t len, co
else if (flags & BURL_ENCODE_PSNDE) {
burl_append_encode_psnde(b, str, len);
}
else if (flags & BURL_ENCODE_B64U) {
const unsigned char *s = (const unsigned char *)str;
buffer_append_base64_encode_no_padding(b, s, len, BASE64_URL);
}
else if (flags & BURL_DECODE_B64U) {
buffer_append_base64_decode(b, str, len, BASE64_URL);
}
/* note: not normalizing str, which could come from arbitrary header,
* so it is possible that alpha chars are percent-encoded upper/lowercase */

2
src/burl.h

@ -37,6 +37,8 @@ enum burl_recoding_e {
,BURL_ENCODE_ALL = 0x0008
,BURL_ENCODE_NDE = 0x0010 /* encode delims, but no-double-encode (NDE) */
,BURL_ENCODE_PSNDE = 0x0020 /* similar to NDE, but preserve literal slash */
,BURL_ENCODE_B64U = 0x0040
,BURL_DECODE_B64U = 0x0080
};
void burl_append (buffer * const b, const char * const str, const size_t len, const int flags);

10
src/keyvalue.c

@ -234,6 +234,16 @@ static int pcre_keyvalue_buffer_subst_ext(buffer *b, const char *pattern, const
p+=3;
break;
}
else if (p[0] == 'e' && p[1] == 'n' && p[2] == 'c'
&& 0 == strncmp((const char *)p+3, "b64u:", 5)) {
flags |= BURL_ENCODE_B64U;
p+=8;
}
else if (p[0] == 'd' && p[1] == 'e' && p[2] == 'c'
&& 0 == strncmp((const char *)p+3, "b64u:", 5)) {
flags |= BURL_DECODE_B64U;
p+=8;
}
else ++p; /* skip unrecognized char */
}
if (*p == '\0') return -1;

Loading…
Cancel
Save