]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: ssl: adds sample converter base64 for binary type.
authorEmeric Brun <ebrun@exceliance.fr>
Wed, 30 Apr 2014 16:21:37 +0000 (18:21 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 30 Apr 2014 20:31:11 +0000 (22:31 +0200)
The new converter encode binary type sample to base64 string.

i.e. : ssl_c_serial,base64

doc/configuration.txt
src/sample.c

index 8c2c0b035c5fcd7cc3278de19b89a86e96904e62..3d4aee7029d3c0c4577a66a3a7b77d5bd8652769 100644 (file)
@@ -9535,6 +9535,11 @@ support some arguments (eg: a netmask) which must be passed in parenthesis.
 
 The currently available list of transformation keywords include :
 
+base64
+  Converts a binary input sample to a base64 string. It is used to log or
+  transfer binary content in a way that can be reliably transferred (eg:
+  an SSL ID can be copied in a header).
+
 lower
   Convert a string sample to lower case. This can only be placed after a string
   sample fetch function or after a transformation keyword returning a string
index 7001f36ab1d5fa69bda84dc8894cc8311307b841..a1e80124f8b3646295bd04cd6cf7f30300cd209c 100644 (file)
@@ -20,6 +20,7 @@
 #include <common/chunk.h>
 #include <common/standard.h>
 #include <common/uri_auth.h>
+#include <common/base64.h>
 
 #include <proto/arg.h>
 #include <proto/auth.h>
@@ -1172,6 +1173,23 @@ struct sample *sample_fetch_string(struct proxy *px, struct session *l4, void *l
 /*    These functions set the data type on return.               */
 /*****************************************************************/
 
+static int sample_conv_bin2base64(const struct arg *arg_p, struct sample *smp)
+{
+       struct chunk *trash = get_trash_chunk();
+       int b64_len;
+
+       trash->len = 0;
+       b64_len = a2base64(smp->data.str.str, smp->data.str.len, trash->str, trash->size);
+       if (b64_len < 0)
+               return 0;
+
+       trash->len = b64_len;
+       smp->data.str = *trash;
+       smp->type = SMP_T_STR;
+       smp->flags &= ~SMP_F_CONST;
+       return 1;
+}
+
 static int sample_conv_bin2hex(const struct arg *arg_p, struct sample *smp)
 {
        struct chunk *trash = get_trash_chunk();
@@ -1329,6 +1347,7 @@ static struct sample_fetch_kw_list smp_kws = {ILH, {
 
 /* Note: must not be declared <const> as its list will be overwritten */
 static struct sample_conv_kw_list sample_conv_kws = {ILH, {
+       { "base64", sample_conv_bin2base64,0,            NULL, SMP_T_BIN,  SMP_T_STR  },
        { "upper",  sample_conv_str2upper, 0,            NULL, SMP_T_STR,  SMP_T_STR  },
        { "lower",  sample_conv_str2lower, 0,            NULL, SMP_T_STR,  SMP_T_STR  },
        { "hex",    sample_conv_bin2hex,   0,            NULL, SMP_T_BIN,  SMP_T_STR  },