]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Nettle v3.4 support (#103)
authorAmos Jeffries <yadij@users.noreply.github.com>
Thu, 14 Dec 2017 08:04:04 +0000 (21:04 +1300)
committerGitHub <noreply@github.com>
Thu, 14 Dec 2017 08:04:04 +0000 (21:04 +1300)
Nettle crypto library v3.4 changes the Base64 coder API to require less casting between uint8_t and char types.

17 files changed:
configure.ac
include/base64.h
lib/base64.c
src/HttpHeader.cc
src/adaptation/icap/ModXact.cc
src/auth/digest/Config.cc
src/auth/negotiate/kerberos/negotiate_kerberos_auth.cc
src/auth/negotiate/kerberos/negotiate_kerberos_auth_test.cc
src/auth/negotiate/kerberos/negotiate_kerberos_pac.cc
src/auth/negotiate/wrapper/negotiate_wrapper.cc
src/auth/ntlm/fake/ntlm_fake_auth.cc
src/http.cc
src/peer_proxy_negotiate_auth.cc
test-suite/buildtests/layer-01-minimal.opts
tools/cachemgr.cc
tools/squidclient/gssapi_support.cc
tools/squidclient/squidclient.cc

index 30686ee5f0dbae59e53c71acabdb37c50a9e6662..6d41870db4d1442fa29146666a81fcad795e2abc 100644 (file)
@@ -1166,16 +1166,16 @@ if test "x$with_nettle" != "xno" ; then
     AC_CHECK_HEADERS(nettle/md5.h)
   ],[with_nettle=no])
   if test "x$with_nettle" != "xno" ; then
-    # Base64 uses the nettle 3.0 API
+    # Base64 uses the nettle 3.4 API
     # which matters on 64-bit systems
     AC_CHECK_HEADERS(nettle/base64.h)
-    AC_MSG_CHECKING([for Nettle 3.0 API compatibility])
+    AC_MSG_CHECKING([for Nettle 3.4 API compatibility])
     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
 #     include <cstddef>
 #     include <cstdint>
 #     include <nettle/base64.h>
     ]],[[
-      uint8_t inData[10]; inData[0] = '\0';
+      char inData[10]; inData[0] = '\0';
       size_t srcLen = 0;
       struct base64_decode_ctx ctx;
       base64_decode_init(&ctx);
@@ -1186,7 +1186,7 @@ if test "x$with_nettle" != "xno" ; then
           return 1;
       }
     ]])],[AC_MSG_RESULT(yes)
-      AC_DEFINE(HAVE_NETTLE30_BASE64,1,[set to 1 if Nettle 3.0 API will link])
+      AC_DEFINE(HAVE_NETTLE34_BASE64,1,[set to 1 if Nettle 3.4 API will link])
     ],[AC_MSG_RESULT(no)])
   fi
 fi
index 1e0afdc352e224d7f7e9fe9a74e933534cfe250c..5bc89fd5c0e7c0a57d65b852124a49eaeb47eb2c 100644 (file)
 #ifndef _SQUID_BASE64_H
 #define _SQUID_BASE64_H
 
-#if HAVE_NETTLE_BASE64_H && HAVE_NETTLE30_BASE64
+#if HAVE_NETTLE_BASE64_H && HAVE_NETTLE34_BASE64
 #include <nettle/base64.h>
 
-#else /* Base64 functions copied from Nettle 3.0 under GPLv2, with adjustments */
+#else /* Base64 functions copied from Nettle 3.4 under GPLv2, with adjustments */
 
-#ifdef __cplusplus
-extern "C" {
-#endif
+/* base64.h
 
-// Decoding functions
+   Base-64 encoding and decoding.
 
-/// Maximum length of output for base64_decode_update.
-/// We have at most 6 buffered bits, and a total of (length + 1) * 6 bits.
-#   define BASE64_DECODE_LENGTH(length) ((((length) + 1) * 6) / 8)
+   Copyright (C) 2002 Niels Möller, Dan Egnor
 
-struct base64_decode_ctx
-{
-    unsigned word;   /* Leftover bits */
-    unsigned bits;   /* Number buffered bits */
+   This file is part of GNU Nettle.
 
-    /* Number of padding characters encountered */
-    unsigned padding;
-};
+   GNU Nettle is free software: you can redistribute it and/or
+   modify it under the terms of either:
 
-void base64_decode_init(struct base64_decode_ctx *ctx);
+     * the GNU Lesser General Public License as published by the Free
+       Software Foundation; either version 3 of the License, or (at your
+       option) any later version.
 
-/* Returns 1 on success, 0 on error. DST should point to an area of
- * size at least BASE64_DECODE_LENGTH(length). The amount of data
- * generated is returned in *DST_LENGTH.
- */
-int base64_decode_update(struct base64_decode_ctx *ctx,
-                         size_t *dst_length,
-                         uint8_t *dst,
-                         size_t src_length,
-                         const uint8_t *src);
+   or
 
-/* Returns 1 on success. */
-int base64_decode_final(struct base64_decode_ctx *ctx);
+     * the GNU General Public License as published by the Free
+       Software Foundation; either version 2 of the License, or (at your
+       option) any later version.
+
+   or both in parallel, as here.
+
+   GNU Nettle is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received copies of the GNU General Public License and
+   the GNU Lesser General Public License along with this program.  If
+   not, see http://www.gnu.org/licenses/.
+*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
 
-// Encoding functions
+/* Base64 encoding */
 
 /* Maximum length of output for base64_encode_update. NOTE: Doesn't
  * include any padding that base64_encode_final may add. */
 /* We have at most 4 buffered bits, and a total of (4 + length * 8) bits. */
-#   define BASE64_ENCODE_LENGTH(length) (((length) * 8 + 4)/6)
+#define BASE64_ENCODE_LENGTH(length) (((length) * 8 + 4)/6)
 
 /* Maximum length of output generated by base64_encode_final. */
-#   define BASE64_ENCODE_FINAL_LENGTH 3
+#define BASE64_ENCODE_FINAL_LENGTH 3
 
 /* Exact length of output generated by base64_encode_raw, including
- * padding.
- */
-#   define BASE64_ENCODE_RAW_LENGTH(length) ((((length) + 2)/3)*4)
+ * padding. */
+#define BASE64_ENCODE_RAW_LENGTH(length) ((((length) + 2)/3)*4)
 
 struct base64_encode_ctx
 {
-    unsigned word;   /* Leftover bits */
-    unsigned bits;  /* Number of bits, always 0, 2, or 4. */
+    const char *alphabet;    /* Alphabet to use for encoding */
+    unsigned short word;     /* Leftover bits */
+    unsigned char bits;      /* Number of bits, always 0, 2, or 4. */
 };
 
-void base64_encode_init(struct base64_encode_ctx *ctx);
+/* Initialize encoding context for base-64 */
+void
+base64_encode_init(struct base64_encode_ctx *ctx);
+
+/* Initialize encoding context for URL safe alphabet, RFC 4648. */
+void
+base64url_encode_init(struct base64_encode_ctx *ctx);
 
-/// Encodes a single byte. Returns amount of output (always 1 or 2).
-size_t base64_encode_single(struct base64_encode_ctx *ctx, uint8_t *dst, uint8_t src);
+/* Encodes a single byte. Returns amount of output (always 1 or 2). */
+size_t
+base64_encode_single(struct base64_encode_ctx *ctx,
+                     char *dst,
+                     uint8_t src);
 
 /* Returns the number of output characters. DST should point to an
- * area of size at least BASE64_ENCODE_LENGTH(length).
- */
-size_t base64_encode_update(struct base64_encode_ctx *ctx, uint8_t *dst, size_t length, const uint8_t *src);
+ * area of size at least BASE64_ENCODE_LENGTH(length). */
+size_t
+base64_encode_update(struct base64_encode_ctx *ctx,
+                     char *dst,
+                     size_t length,
+                     const uint8_t *src);
+
+/* DST should point to an area of size at least
+ * BASE64_ENCODE_FINAL_LENGTH */
+size_t
+base64_encode_final(struct base64_encode_ctx *ctx,
+                    char *dst);
+
+/* Lower level functions */
+
+/* Encodes a string in one go, including any padding at the end.
+ * Generates exactly BASE64_ENCODE_RAW_LENGTH(length) bytes of output.
+ * Supports overlapped operation, if src <= dst. FIXME: Use of overlap
+ * is deprecated, if needed there should be a separate public fucntion
+ * to do that.*/
+void
+base64_encode_raw(char *dst, size_t length, const uint8_t *src);
+
+void
+base64_encode_group(char *dst, uint32_t group);
+
+/* Base64 decoding */
+
+/* Maximum length of output for base64_decode_update. */
+/* We have at most 6 buffered bits, and a total of (length + 1) * 6 bits. */
+#define BASE64_DECODE_LENGTH(length) ((((length) + 1) * 6) / 8)
+
+struct base64_decode_ctx
+{
+    const signed char *table; /* Decoding table */
+    unsigned short word;      /* Leftover bits */
+    unsigned char bits;       /* Number buffered bits */
+
+    /* Number of padding characters encountered */
+    unsigned char padding;
+};
 
-/// DST should point to an area of size at least BASE64_ENCODE_FINAL_LENGTH
-size_t base64_encode_final(struct base64_encode_ctx *ctx, uint8_t *dst);
+/* Initialize decoding context for base-64 */
+void
+base64_decode_init(struct base64_decode_ctx *ctx);
+
+/* Initialize encoding context for URL safe alphabet, RFC 4648. */
+void
+base64url_decode_init(struct base64_decode_ctx *ctx);
+
+/* Decodes a single byte. Returns amount of output (0 or 1), or -1 on
+ * errors. */
+int
+base64_decode_single(struct base64_decode_ctx *ctx,
+                     uint8_t *dst,
+                     char src);
+
+/* Returns 1 on success, 0 on error. DST should point to an area of
+ * size at least BASE64_DECODE_LENGTH(length). The amount of data
+ * generated is returned in *DST_LENGTH. */
+int
+base64_decode_update(struct base64_decode_ctx *ctx,
+                     size_t *dst_length,
+                     uint8_t *dst,
+                     size_t src_length,
+                     const char *src);
+
+/* Returns 1 on success. */
+int
+base64_decode_final(struct base64_decode_ctx *ctx);
 
 #ifdef __cplusplus
 }
 #endif
 
-#endif /* HAVE_NETTLE_BASE64_H */
+#endif /* HAVE_NETTLE_BASE64_H && HAVE_NETTLE34_BASE64 */
 
 /// Calculate the buffer size required to hold the encoded form of
 /// a string of length 'decodedLen' including all terminator bytes.
 #   define base64_encode_len(length) (BASE64_ENCODE_LENGTH(length)+BASE64_ENCODE_FINAL_LENGTH+1)
 
 #endif /* _SQUID_BASE64_H */
-
index 484c058f1b77c84afff9bfd8b815a8641621fb8c..ff75d5607adbadb279709e123f6c9231c958cc32 100644 (file)
@@ -7,65 +7,86 @@
  */
 
 /*
-* Copied from Nettle 3.0 under GPLv2, with adjustments
+ * Copied from Nettle 3.4 under GPLv2, with adjustments
  */
 
 #include "squid.h"
 #include "base64.h"
 
-#if !HAVE_NETTLE_BASE64_H || !HAVE_NETTLE30_BASE64
+#if !HAVE_NETTLE_BASE64_H || !HAVE_NETTLE34_BASE64
 
-#if HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
+/* base64-encode.c
 
-static const uint8_t encode_table[64] =
-    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
-    "abcdefghijklmnopqrstuvwxyz"
-    "0123456789+/";
+   Copyright (C) 2002 Niels Möller
 
-#define ENCODE(x) (encode_table[0x3F & (x)])
+   This file is part of GNU Nettle.
 
-static const signed char decode_table[0x100] =
-{
-    /* White space is HT, VT, FF, CR, LF and SPC */
-    -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, -2, -2, -2, -2, -1, -1,
-    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-    -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
-    52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -3, -1, -1,
-    -1,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14,
-    15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
-    -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
-    41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1,
-    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-};
+   GNU Nettle is free software: you can redistribute it and/or
+   modify it under the terms of either:
+
+     * the GNU Lesser General Public License as published by the Free
+       Software Foundation; either version 3 of the License, or (at your
+       option) any later version.
+
+   or
+
+     * the GNU General Public License as published by the Free
+       Software Foundation; either version 2 of the License, or (at your
+       option) any later version.
+
+   or both in parallel, as here.
+
+   GNU Nettle is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received copies of the GNU General Public License and
+   the GNU Lesser General Public License along with this program.  If
+   not, see http://www.gnu.org/licenses/.
+*/
 
 #define TABLE_INVALID -1
 #define TABLE_SPACE -2
 #define TABLE_END -3
 
-#define BASE64_VALUE_SZ 256
-int base64_value[BASE64_VALUE_SZ];
-
 void
 base64_decode_init(struct base64_decode_ctx *ctx)
 {
+    static const signed char base64_decode_table[0x100] =
+    {
+        /* White space is HT, VT, FF, CR, LF and SPC */
+        -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, -2, -2, -2, -2, -1, -1,
+        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+        -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
+        52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -3, -1, -1,
+        -1,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14,
+        15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
+        -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
+        41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1,
+        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+    };
+
     ctx->word = ctx->bits = ctx->padding = 0;
+    ctx->table = base64_decode_table;
 }
 
-static int
-base64_decode_single(struct base64_decode_ctx *ctx, uint8_t *dst, uint8_t src)
+int
+base64_decode_single(struct base64_decode_ctx *ctx,
+                     uint8_t *dst,
+                     char src)
 {
-    int data = decode_table[src];
+    int data = ctx->table[(uint8_t) src];
 
-    switch(data) {
+    switch(data)
+    {
     default:
         assert(data >= 0 && data < 0x40);
 
@@ -75,12 +96,13 @@ base64_decode_single(struct base64_decode_ctx *ctx, uint8_t *dst, uint8_t src)
         ctx->word = ctx->word << 6 | data;
         ctx->bits += 6;
 
-        if (ctx->bits >= 8) {
+        if (ctx->bits >= 8)
+        {
             ctx->bits -= 8;
             dst[0] = ctx->word >> ctx->bits;
             return 1;
-        } else
-            return 0;
+        }
+        else return 0;
 
     case TABLE_INVALID:
         return -1;
@@ -108,13 +130,14 @@ base64_decode_update(struct base64_decode_ctx *ctx,
                      size_t *dst_length,
                      uint8_t *dst,
                      size_t src_length,
-                     const uint8_t *src)
+                     const char *src)
 {
     size_t done;
     size_t i;
 
-    for (i = 0, done = 0; i < src_length; i++) {
-        switch(base64_decode_single(ctx, dst + done, src[i])) {
+    for (i = 0, done = 0; i<src_length; i++)
+        switch(base64_decode_single(ctx, dst + done, src[i]))
+        {
         case -1:
             return 0;
         case 1:
@@ -125,7 +148,6 @@ base64_decode_update(struct base64_decode_ctx *ctx,
         default:
             abort();
         }
-    }
 
     assert(done <= BASE64_DECODE_LENGTH(src_length));
 
@@ -139,64 +161,94 @@ base64_decode_final(struct base64_decode_ctx *ctx)
     return ctx->bits == 0;
 }
 
+/* base64-encode.c */
+
+#define ENCODE(alphabet,x) ((alphabet)[0x3F & (x)])
+
 static void
-base64_encode_raw(uint8_t *dst, size_t length, const uint8_t *src)
+encode_raw(const char *alphabet,
+           char *dst, size_t length, const uint8_t *src)
 {
     const uint8_t *in = src + length;
-    uint8_t *out = dst + BASE64_ENCODE_RAW_LENGTH(length);
+    char *out = dst + BASE64_ENCODE_RAW_LENGTH(length);
 
     unsigned left_over = length % 3;
 
-    if (left_over) {
+    if (left_over)
+    {
         in -= left_over;
         *--out = '=';
-        switch(left_over) {
+        switch(left_over)
+        {
         case 1:
             *--out = '=';
-            *--out = ENCODE(in[0] << 4);
+            *--out = ENCODE(alphabet, (in[0] << 4));
             break;
 
         case 2:
-            *--out = ENCODE( in[1] << 2);
-            *--out = ENCODE((in[0] << 4) | (in[1] >> 4));
+            *--out = ENCODE(alphabet, (in[1] << 2));
+            *--out = ENCODE(alphabet, ((in[0] << 4) | (in[1] >> 4)));
             break;
 
         default:
             abort();
         }
-        *--out = ENCODE(in[0] >> 2);
+        *--out = ENCODE(alphabet, (in[0] >> 2));
     }
 
-    while (in > src) {
+    while (in > src)
+    {
         in -= 3;
-        *--out = ENCODE( in[2]);
-        *--out = ENCODE((in[1] << 2) | (in[2] >> 6));
-        *--out = ENCODE((in[0] << 4) | (in[1] >> 4));
-        *--out = ENCODE( in[0] >> 2);
+        *--out = ENCODE(alphabet, (in[2]));
+        *--out = ENCODE(alphabet, ((in[1] << 2) | (in[2] >> 6)));
+        *--out = ENCODE(alphabet, ((in[0] << 4) | (in[1] >> 4)));
+        *--out = ENCODE(alphabet, (in[0] >> 2));
     }
     assert(in == src);
     assert(out == dst);
 }
 
+static const char base64_encode_table[64] =
+    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+    "abcdefghijklmnopqrstuvwxyz"
+    "0123456789+/";
+
+void
+base64_encode_raw(char *dst, size_t length, const uint8_t *src)
+{
+    encode_raw(base64_encode_table, dst, length, src);
+}
+
+void
+base64_encode_group(char *dst, uint32_t group)
+{
+    *dst++ = ENCODE(base64_encode_table, (group >> 18));
+    *dst++ = ENCODE(base64_encode_table, (group >> 12));
+    *dst++ = ENCODE(base64_encode_table, (group >> 6));
+    *dst++ = ENCODE(base64_encode_table, group);
+}
+
 void
 base64_encode_init(struct base64_encode_ctx *ctx)
 {
     ctx->word = ctx->bits = 0;
+    ctx->alphabet = base64_encode_table;
 }
 
 /* Encodes a single byte. */
 size_t
 base64_encode_single(struct base64_encode_ctx *ctx,
-                     uint8_t *dst,
+                     char *dst,
                      uint8_t src)
 {
     unsigned done = 0;
     unsigned word = ctx->word << 8 | src;
     unsigned bits = ctx->bits + 8;
 
-    while (bits >= 6) {
+    while (bits >= 6)
+    {
         bits -= 6;
-        dst[done++] = ENCODE(word >> bits);
+        dst[done++] = ENCODE(ctx->alphabet, (word >> bits));
     }
 
     ctx->bits = bits;
@@ -211,7 +263,7 @@ base64_encode_single(struct base64_encode_ctx *ctx,
  * area of size at least BASE64_ENCODE_LENGTH(length). */
 size_t
 base64_encode_update(struct base64_encode_ctx *ctx,
-                     uint8_t *dst,
+                     char *dst,
                      size_t length,
                      const uint8_t *src)
 {
@@ -220,7 +272,8 @@ base64_encode_update(struct base64_encode_ctx *ctx,
     unsigned left_over;
     size_t bulk;
 
-    while (ctx->bits && left) {
+    while (ctx->bits && left)
+    {
         left--;
         done += base64_encode_single(ctx, dst + done, *src++);
     }
@@ -228,16 +281,18 @@ base64_encode_update(struct base64_encode_ctx *ctx,
     left_over = left % 3;
     bulk = left - left_over;
 
-    if (bulk) {
+    if (bulk)
+    {
         assert(!(bulk % 3));
 
-        base64_encode_raw(dst + done, bulk, src);
+        encode_raw(ctx->alphabet, dst + done, bulk, src);
         done += BASE64_ENCODE_RAW_LENGTH(bulk);
         src += bulk;
         left = left_over;
     }
 
-    while (left) {
+    while (left)
+    {
         left--;
         done += base64_encode_single(ctx, dst + done, *src++);
     }
@@ -251,13 +306,14 @@ base64_encode_update(struct base64_encode_ctx *ctx,
  * BASE64_ENCODE_FINAL_SIZE */
 size_t
 base64_encode_final(struct base64_encode_ctx *ctx,
-                    uint8_t *dst)
+                    char *dst)
 {
     unsigned done = 0;
     unsigned bits = ctx->bits;
 
-    if (bits) {
-        dst[done++] = ENCODE(ctx->word << (6 - ctx->bits));
+    if (bits)
+    {
+        dst[done++] = ENCODE(ctx->alphabet, (ctx->word << (6 - ctx->bits)));
         for (; bits < 6; bits += 2)
             dst[done++] = '=';
 
@@ -268,5 +324,4 @@ base64_encode_final(struct base64_encode_ctx *ctx,
     return done;
 }
 
-#endif /* !HAVE_NETTLE_BASE64_H || !HAVE_NETTLE30_BASE64 */
-
+#endif /* !HAVE_NETTLE_BASE64_H || !HAVE_NETTLE34_BASE64 */
index d40146221fea17af75e5e61a2130191c72680ee5..3e98a739be8bf1bfde46ffac1f37cd5cb002bef8 100644 (file)
@@ -1345,7 +1345,7 @@ HttpHeader::getAuth(Http::HdrType id, const char *auth_scheme) const
     struct base64_decode_ctx ctx;
     base64_decode_init(&ctx);
     size_t decodedLen = 0;
-    if (!base64_decode_update(&ctx, &decodedLen, reinterpret_cast<uint8_t*>(decodedAuthToken), strlen(field), reinterpret_cast<const uint8_t*>(field)) ||
+    if (!base64_decode_update(&ctx, &decodedLen, reinterpret_cast<uint8_t*>(decodedAuthToken), strlen(field), field) ||
             !base64_decode_final(&ctx)) {
         return NULL;
     }
index 54e25cd946f0341952ece03803d351b9c90603ee..e53583cc7423cb288a975b19f2c6827f829d12b4 100644 (file)
@@ -1413,7 +1413,7 @@ void Adaptation::Icap::ModXact::makeRequestHeaders(MemBuf &buf)
     } else if (request->extacl_user.size() > 0 && request->extacl_passwd.size() > 0) {
         struct base64_encode_ctx ctx;
         base64_encode_init(&ctx);
-        uint8_t base64buf[base64_encode_len(MAX_LOGIN_SZ)];
+        char base64buf[base64_encode_len(MAX_LOGIN_SZ)];
         size_t resultLen = base64_encode_update(&ctx, base64buf, request->extacl_user.size(), reinterpret_cast<const uint8_t*>(request->extacl_user.rawBuf()));
         resultLen += base64_encode_update(&ctx, base64buf+resultLen, 1, reinterpret_cast<const uint8_t*>(":"));
         resultLen += base64_encode_update(&ctx, base64buf+resultLen, request->extacl_passwd.size(), reinterpret_cast<const uint8_t*>(request->extacl_passwd.rawBuf()));
@@ -1575,7 +1575,7 @@ void Adaptation::Icap::ModXact::makeUsernameHeader(const HttpRequest *request, M
 
     if (value) {
         if (TheConfig.client_username_encode) {
-            uint8_t base64buf[base64_encode_len(MAX_LOGIN_SZ)];
+            char base64buf[base64_encode_len(MAX_LOGIN_SZ)];
             size_t resultLen = base64_encode_update(&ctx, base64buf, strlen(value), reinterpret_cast<const uint8_t*>(value));
             resultLen += base64_encode_final(&ctx, base64buf+resultLen);
             buf.appendf("%s: %.*s\r\n", TheConfig.client_username_header, (int)resultLen, base64buf);
index 3e9a07edc91407091bc2ca92fd9be87551b8e16b..8209edd63a8702149e36d95a5b937724a47a175c 100644 (file)
@@ -111,8 +111,8 @@ authDigestNonceEncode(digest_nonce_h * nonce)
     nonce->key = xcalloc(base64_encode_len(sizeof(digest_nonce_data)), 1);
     struct base64_encode_ctx ctx;
     base64_encode_init(&ctx);
-    size_t blen = base64_encode_update(&ctx, reinterpret_cast<uint8_t*>(nonce->key), sizeof(digest_nonce_data), reinterpret_cast<const uint8_t*>(&(nonce->noncedata)));
-    blen += base64_encode_final(&ctx, reinterpret_cast<uint8_t*>(nonce->key)+blen);
+    size_t blen = base64_encode_update(&ctx, reinterpret_cast<char*>(nonce->key), sizeof(digest_nonce_data), reinterpret_cast<const uint8_t*>(&(nonce->noncedata)));
+    blen += base64_encode_final(&ctx, reinterpret_cast<char*>(nonce->key)+blen);
 }
 
 digest_nonce_h *
index 7195689514dd7d1205059f11129568750afeac70..d08e364a62383823db1866328b145e8c73f02b60 100644 (file)
@@ -658,7 +658,7 @@ main(int argc, char *const argv[])
             fprintf(stdout, "BH Invalid negotiate request\n");
             continue;
         }
-        const uint8_t *b64Token = reinterpret_cast<const uint8_t*>(buf+3);
+        const char *b64Token = buf+3;
         const size_t srcLen = strlen(buf+3);
         input_token.length = BASE64_DECODE_LENGTH(srcLen);
         debug((char *) "%s| %s: DEBUG: Decode '%s' (decoded length estimate: %d).\n",
@@ -729,8 +729,8 @@ main(int argc, char *const argv[])
             }
             struct base64_encode_ctx tokCtx;
             base64_encode_init(&tokCtx);
-            size_t blen = base64_encode_update(&tokCtx, reinterpret_cast<uint8_t*>(token), spnegoTokenLength, reinterpret_cast<const uint8_t*>(spnegoToken));
-            blen += base64_encode_final(&tokCtx, reinterpret_cast<uint8_t*>(token)+blen);
+            size_t blen = base64_encode_update(&tokCtx, token, spnegoTokenLength, reinterpret_cast<const uint8_t*>(spnegoToken));
+            blen += base64_encode_final(&tokCtx, token+blen);
             token[blen] = '\0';
 
             if (check_gss_err(major_status, minor_status, "gss_accept_sec_context()", log, 1))
index afe0737896697b879ea753b66dcf133e38552420..41cbb59def2c1dbcb558d04a1d8b16b4ca09c1b7 100644 (file)
@@ -203,8 +203,8 @@ squid_kerb_proxy_auth(char *proxy)
             token = (char *) xcalloc(base64_encode_len(output_token.length), 1);
             struct base64_encode_ctx ctx;
             base64_encode_init(&ctx);
-            size_t blen = base64_encode_update(&ctx, reinterpret_cast<uint8_t*>(token), output_token.length, reinterpret_cast<const uint8_t*>(output_token.value));
-            blen += base64_encode_final(&ctx, reinterpret_cast<uint8_t*>(token)+blen);
+            size_t blen = base64_encode_update(&ctx, token, output_token.length, reinterpret_cast<const uint8_t*>(output_token.value));
+            blen += base64_encode_final(&ctx, token+blen);
         }
     }
 
index bd791138b94a772fc907b376b77fb421146d8842..d79835bb7ddfe753e5c113cfe3aec4af52dc7eab 100644 (file)
@@ -244,11 +244,11 @@ getdomaingids(char *ad_groups, uint32_t DomainLogonId, char **Rids, uint32_t Gro
             struct base64_encode_ctx ctx;
             base64_encode_init(&ctx);
             const uint32_t expectedSz = base64_encode_len(length+4) +1 /* terminator */;
-            uint8_t *b64buf = (uint8_t *)xcalloc(expectedSz, 1);
+            char *b64buf = static_cast<char *>(xcalloc(expectedSz, 1));
             size_t blen = base64_encode_update(&ctx, b64buf, length+4, reinterpret_cast<uint8_t*>(ag));
             blen += base64_encode_final(&ctx, b64buf+blen);
             b64buf[expectedSz-1] = '\0';
-            if (!pstrcat(ad_groups, reinterpret_cast<char*>(b64buf))) {
+            if (!pstrcat(ad_groups, b64buf)) {
                 debug((char *) "%s| %s: WARN: Too many groups ! size > %d : %s\n",
                       LogTime(), PROGRAM, MAX_PAC_GROUP_SIZE, ad_groups);
             }
@@ -333,7 +333,7 @@ getextrasids(char *ad_groups, uint32_t ExtraSids, uint32_t SidCount)
                 struct base64_encode_ctx ctx;
                 base64_encode_init(&ctx);
                 const uint32_t expectedSz = base64_encode_len(length) +1 /* terminator */;
-                uint8_t *b64buf = (uint8_t *)xcalloc(expectedSz, 1);
+                char *b64buf = static_cast<char *>(xcalloc(expectedSz, 1));
                 size_t blen = base64_encode_update(&ctx, b64buf, length, reinterpret_cast<uint8_t*>(ag));
                 blen += base64_encode_final(&ctx, b64buf+blen);
                 b64buf[expectedSz-1] = '\0';
index 9943a99b86f0c3c09d5c798d9a4568671997c56e..1671d3e1441595ceb3c898449bf2a092ad1a6abb 100644 (file)
@@ -193,7 +193,7 @@ processingLoop(FILE *FDKIN, FILE *FDKOUT, FILE *FDNIN, FILE *FDNOUT)
         struct base64_decode_ctx ctx;
         base64_decode_init(&ctx);
         size_t dstLen = 0;
-        if (!base64_decode_update(&ctx, &dstLen, token, strlen(buf+3), reinterpret_cast<const uint8_t*>(buf+3)) ||
+        if (!base64_decode_update(&ctx, &dstLen, token, strlen(buf+3), buf+3) ||
                 !base64_decode_final(&ctx)) {
             if (debug_enabled)
                 fprintf(stderr, "%s| %s: Invalid base64 token [%s]\n", LogTime(), PROGRAM, buf+3);
index ac9fb281d7f07bbcb23f8d294bc9e45e3a18d2d3..f79199c682be9ffda645fe2f778630fbb5dded61 100644 (file)
@@ -155,7 +155,7 @@ main(int argc, char *argv[])
         base64_decode_init(&ctx);
         size_t dstLen = 0;
         if (buflen > 3 &&
-                base64_decode_update(&ctx, &dstLen, decodedBuf, buflen-3, reinterpret_cast<const uint8_t*>(buf+3)) &&
+                base64_decode_update(&ctx, &dstLen, decodedBuf, buflen-3, buf+3) &&
                 base64_decode_final(&ctx)) {
             decodedLen = dstLen;
             packet = (ntlmhdr*)decodedBuf;
@@ -189,8 +189,8 @@ main(int argc, char *argv[])
 
             struct base64_encode_ctx eCtx;
             base64_encode_init(&eCtx);
-            uint8_t *data = (uint8_t*)xcalloc(base64_encode_len(len), 1);
-            size_t blen = base64_encode_update(&eCtx, data, len, reinterpret_cast<uint8_t*>(&chal));
+            char *data = static_cast<char *>(xcalloc(base64_encode_len(len), 1));
+            size_t blen = base64_encode_update(&eCtx, data, len, reinterpret_cast<const uint8_t *>(&chal));
             blen += base64_encode_final(&eCtx, data+blen);
             if (NTLM_packet_debug_enabled) {
                 printf("TT %.*s\n", (int)blen, data);
index 3b2e079d38f60ad1f6402c5c75eed4005df5fcd3..ea09b6c4178ce6ab1aa26542de728c7c6f33ab1e 100644 (file)
@@ -1672,7 +1672,7 @@ httpFixupAuthentication(HttpRequest * request, const HttpHeader * hdr_in, HttpHe
         }
     }
 
-    uint8_t loginbuf[base64_encode_len(MAX_LOGIN_SZ)];
+    char loginbuf[base64_encode_len(MAX_LOGIN_SZ)];
     size_t blen;
     struct base64_encode_ctx ctx;
     base64_encode_init(&ctx);
@@ -1857,7 +1857,7 @@ HttpStateData::httpBuildRequestHeader(HttpRequest * request,
     /* append Authorization if known in URL, not in header and going direct */
     if (!hdr_out->has(Http::HdrType::AUTHORIZATION)) {
         if (!request->flags.proxying && !request->url.userInfo().isEmpty()) {
-            static uint8_t result[base64_encode_len(MAX_URL*2)]; // should be big enough for a single URI segment
+            static char result[base64_encode_len(MAX_URL*2)]; // should be big enough for a single URI segment
             struct base64_encode_ctx ctx;
             base64_encode_init(&ctx);
             size_t blen = base64_encode_update(&ctx, result, request->url.userInfo().length(), reinterpret_cast<const uint8_t*>(request->url.userInfo().rawContent()));
index 221f308d8773eef02608e79f80130760b5baf776..d3ffc875f3988bb037a25f8bfa5a4c1203a9a8a7 100644 (file)
@@ -559,7 +559,7 @@ char *peer_proxy_negotiate_auth(char *principal_name, char *proxy, int flags) {
 
     debugs(11, 5, HERE << "Got token with length " << output_token.length);
     if (output_token.length) {
-        static uint8_t b64buf[8192]; // XXX: 8KB only because base64_encode_bin() used to.
+        static char b64buf[8192]; // XXX: 8KB only because base64_encode_bin() used to.
         struct base64_encode_ctx ctx;
         base64_encode_init(&ctx);
         size_t blen = base64_encode_update(&ctx, b64buf, output_token.length, reinterpret_cast<const uint8_t*>(output_token.value));
index da8f2db739ae0511f37e4213790f0a7c8fb3c1e0..251f73b8ab958e3dc10e9fd69244e7e65f823644 100644 (file)
@@ -99,6 +99,7 @@ DISTCHECK_CONFIGURE_FLAGS=" \
        --without-aio \
        --without-dl \
        --without-large-files \
+       --without-nettle \
        --without-valgrind-debug \
        --without-ipv6-split-stack \
        --without-dns-cname \
index ec7cdabdbb8e6cdcbc3508dfc97e176b704d05e4..178a8673349c975158bea881a52e5b00947d8cfa 100644 (file)
@@ -1081,8 +1081,8 @@ make_pub_auth(cachemgr_request * req)
     req->pub_auth = (char *) xmalloc(encodedLen);
     struct base64_encode_ctx ctx;
     base64_encode_init(&ctx);
-    size_t blen = base64_encode_update(&ctx, reinterpret_cast<uint8_t*>(req->pub_auth), bufLen, reinterpret_cast<uint8_t*>(buf));
-    blen += base64_encode_final(&ctx, reinterpret_cast<uint8_t*>(req->pub_auth)+blen);
+    size_t blen = base64_encode_update(&ctx, req->pub_auth, bufLen, reinterpret_cast<uint8_t*>(buf));
+    blen += base64_encode_final(&ctx, req->pub_auth + blen);
     req->pub_auth[blen] = '\0';
     debug("cmgr: encoded: '%s'\n", req->pub_auth);
 }
@@ -1106,7 +1106,7 @@ decode_pub_auth(cachemgr_request * req)
     buf = (char*)xmalloc(decodedLen);
     struct base64_decode_ctx ctx;
     base64_decode_init(&ctx);
-    if (!base64_decode_update(&ctx, &decodedLen, reinterpret_cast<uint8_t*>(buf), strlen(req->pub_auth), reinterpret_cast<const uint8_t*>(req->pub_auth)) ||
+    if (!base64_decode_update(&ctx, &decodedLen, reinterpret_cast<uint8_t*>(buf), strlen(req->pub_auth), req->pub_auth) ||
             !base64_decode_final(&ctx)) {
         debug("cmgr: base64 decode failure. Incomplete auth token string.\n");
         xfree(buf);
@@ -1191,7 +1191,7 @@ make_auth_header(const cachemgr_request * req)
     if (encodedLen <= 0)
         return "";
 
-    uint8_t *str64 = static_cast<uint8_t*>(xmalloc(encodedLen));
+    char *str64 = static_cast<char *>(xmalloc(encodedLen));
     struct base64_encode_ctx ctx;
     base64_encode_init(&ctx);
     size_t blen = base64_encode_update(&ctx, str64, bufLen, reinterpret_cast<uint8_t*>(buf));
index 578459c1cc17c08bee975bbd4c2e3c26dc16e19c..14de023a50793429ea5e4f1de46981bba27b4c06 100644 (file)
@@ -131,14 +131,12 @@ GSSAPI_token(const char *server)
                                             NULL);
 
         if (!check_gss_err(major_status, minor_status, "gss_init_sec_context()") && output_token.length) {
-            uint8_t *b64buf = new uint8_t[base64_encode_len(output_token.length)];
+            token = new char[base64_encode_len(output_token.length)];
             struct base64_encode_ctx ctx;
             base64_encode_init(&ctx);
-            size_t blen = base64_encode_update(&ctx, b64buf, output_token.length, reinterpret_cast<const uint8_t*>(output_token.value));
-            blen += base64_encode_final(&ctx, b64buf+blen);
-            b64buf[blen] = '\0';
-
-            token = reinterpret_cast<char*>(b64buf);
+            size_t blen = base64_encode_update(&ctx, token, output_token.length, reinterpret_cast<const uint8_t*>(output_token.value));
+            blen += base64_encode_final(&ctx, token+blen);
+            token[blen] = '\0';
         }
     }
 
index 71976125a95ee17ec8eeee9e6df5c7ffa8f9d9d4..12255ffb98d38db2923fae6833f7fa1c0aa69d57 100644 (file)
@@ -481,12 +481,12 @@ main(int argc, char *argv[])
                 std::cerr << "ERROR: Proxy password missing" << std::endl;
                 exit(EXIT_FAILURE);
             }
-            uint8_t *pwdBuf = new uint8_t[base64_encode_len(strlen(user)+1+strlen(password))];
+            char *pwdBuf = new char[base64_encode_len(strlen(user)+1+strlen(password))];
             blen = base64_encode_update(&ctx, pwdBuf, strlen(user), reinterpret_cast<const uint8_t*>(user));
             blen += base64_encode_update(&ctx, pwdBuf+blen, 1, reinterpret_cast<const uint8_t*>(":"));
             blen += base64_encode_update(&ctx, pwdBuf+blen, strlen(password), reinterpret_cast<const uint8_t*>(password));
             blen += base64_encode_final(&ctx, pwdBuf+blen);
-            snprintf(buf, BUFSIZ, "Proxy-Authorization: Basic %.*s\r\n", (int)blen, reinterpret_cast<char*>(pwdBuf));
+            snprintf(buf, BUFSIZ, "Proxy-Authorization: Basic %.*s\r\n", static_cast<int>(blen), pwdBuf);
             strcat(msg, buf);
             delete[] pwdBuf;
         }
@@ -501,12 +501,12 @@ main(int argc, char *argv[])
                 std::cerr << "ERROR: WWW password missing" << std::endl;
                 exit(EXIT_FAILURE);
             }
-            uint8_t *pwdBuf = new uint8_t[base64_encode_len(strlen(user)+1+strlen(password))];
+            char *pwdBuf = new char[base64_encode_len(strlen(user)+1+strlen(password))];
             blen = base64_encode_update(&ctx, pwdBuf, strlen(user), reinterpret_cast<const uint8_t*>(user));
             blen += base64_encode_update(&ctx, pwdBuf+blen, 1, reinterpret_cast<const uint8_t*>(":"));
             blen += base64_encode_update(&ctx, pwdBuf+blen, strlen(password), reinterpret_cast<const uint8_t*>(password));
             blen += base64_encode_final(&ctx, pwdBuf+blen);
-            snprintf(buf, BUFSIZ, "Authorization: Basic %.*s\r\n", (int)blen, reinterpret_cast<char*>(pwdBuf));
+            snprintf(buf, BUFSIZ, "Authorization: Basic %.*s\r\n", static_cast<int>(blen), pwdBuf);
             strcat(msg, buf);
             delete[] pwdBuf;
         }