Blame SOURCES/cups-fips-compliance.patch

a3fe81
diff --git a/cups/cups.h b/cups/cups.h
a3fe81
index 8f5c818..9d8c3a3 100644
a3fe81
--- a/cups/cups.h
a3fe81
+++ b/cups/cups.h
a3fe81
@@ -606,6 +606,9 @@ extern ssize_t		cupsHashData(const char *algorithm, const void *data, size_t dat
a3fe81
 extern int		cupsAddIntegerOption(const char *name, int value, int num_options, cups_option_t **options) _CUPS_API_2_2_4;
a3fe81
 extern int		cupsGetIntegerOption(const char *name, int num_options, cups_option_t *options) _CUPS_API_2_2_4;
a3fe81
 
a3fe81
+/* New in CUPS 2.3 */
a3fe81
+extern const char	*cupsHashString(const unsigned char *hash, size_t hashsize, char *buffer, size_t bufsize);
a3fe81
+
a3fe81
 #  ifdef __cplusplus
a3fe81
 }
a3fe81
 #  endif /* __cplusplus */
a3fe81
diff --git a/cups/hash.c b/cups/hash.c
a3fe81
index ede5461..8ebe20b 100644
a3fe81
--- a/cups/hash.c
a3fe81
+++ b/cups/hash.c
a3fe81
@@ -21,6 +21,8 @@
a3fe81
 #  include <CommonCrypto/CommonDigest.h>
a3fe81
 #elif defined(HAVE_GNUTLS)
a3fe81
 #  include <gnutls/crypto.h>
a3fe81
+#else
a3fe81
+#  include "md5-private.h"
a3fe81
 #endif /* __APPLE__ */
a3fe81
 
a3fe81
 
a3fe81
@@ -171,7 +173,9 @@ cupsHashData(const char    *algorithm,	/* I - Algorithm name */
a3fe81
   unsigned char	temp[64];		/* Temporary hash buffer */
a3fe81
   size_t	tempsize = 0;		/* Truncate to this size? */
a3fe81
 
a3fe81
-  if (!strcmp(algorithm, "sha"))
a3fe81
+  if (!strcmp(algorithm, "md5"))
a3fe81
+    alg = GNUTLS_DIG_MD5;
a3fe81
+  else if (!strcmp(algorithm, "sha"))
a3fe81
     alg = GNUTLS_DIG_SHA1;
a3fe81
   else if (!strcmp(algorithm, "sha2-224"))
a3fe81
     alg = GNUTLS_DIG_SHA224;
a3fe81
@@ -219,10 +223,20 @@ cupsHashData(const char    *algorithm,	/* I - Algorithm name */
a3fe81
 
a3fe81
 #else
a3fe81
  /*
a3fe81
-  * No hash support without CommonCrypto or GNU TLS...
a3fe81
+  * No hash support beyond MD5 without CommonCrypto or GNU TLS...
a3fe81
   */
a3fe81
 
a3fe81
-  if (hashsize < 64)
a3fe81
+  if (!strcmp(algorithm, "md5"))
a3fe81
+  {
a3fe81
+    _cups_md5_state_t	state;		/* MD5 state info */
a3fe81
+
a3fe81
+    _cupsMD5Init(&state);
a3fe81
+    _cupsMD5Append(&state, data, datalen);
a3fe81
+    _cupsMD5Finish(&state, hash);
a3fe81
+
a3fe81
+    return (16);
a3fe81
+  }
a3fe81
+  else if (hashsize < 64)
a3fe81
     goto too_small;
a3fe81
 #endif /* __APPLE__ */
a3fe81
 
a3fe81
@@ -243,3 +257,51 @@ cupsHashData(const char    *algorithm,	/* I - Algorithm name */
a3fe81
   _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Hash buffer too small."), 1);
a3fe81
   return (-1);
a3fe81
 }
a3fe81
+
a3fe81
+
a3fe81
+/*
a3fe81
+ * 'cupsHashString()' - Format a hash value as a hexadecimal string.
a3fe81
+ *
a3fe81
+ * The passed buffer must be at least 2 * hashsize + 1 characters in length.
a3fe81
+ */
a3fe81
+
a3fe81
+const char *				/* O - Formatted string */
a3fe81
+cupsHashString(
a3fe81
+    const unsigned char *hash,		/* I - Hash */
a3fe81
+    size_t              hashsize,	/* I - Size of hash */
a3fe81
+    char                *buffer,	/* I - String buffer */
a3fe81
+    size_t		bufsize)	/* I - Size of string buffer */
a3fe81
+{
a3fe81
+  char		*bufptr = buffer;	/* Pointer into buffer */
a3fe81
+  static const char *hex = "0123456789abcdef";
a3fe81
+					/* Hex characters (lowercase!) */
a3fe81
+
a3fe81
+
a3fe81
+ /*
a3fe81
+  * Range check input...
a3fe81
+  */
a3fe81
+
a3fe81
+  if (!hash || hashsize < 1 || !buffer || bufsize < (2 * hashsize + 1))
a3fe81
+  {
a3fe81
+    if (buffer)
a3fe81
+      *buffer = '\0';
a3fe81
+    return (NULL);
a3fe81
+  }
a3fe81
+
a3fe81
+ /*
a3fe81
+  * Loop until we've converted the whole hash...
a3fe81
+  */
a3fe81
+
a3fe81
+  while (hashsize > 0)
a3fe81
+  {
a3fe81
+    *bufptr++ = hex[*hash >> 4];
a3fe81
+    *bufptr++ = hex[*hash & 15];
a3fe81
+
a3fe81
+    hash ++;
a3fe81
+    hashsize --;
a3fe81
+  }
a3fe81
+
a3fe81
+  *bufptr = '\0';
a3fe81
+
a3fe81
+  return (buffer);
a3fe81
+}
a3fe81
diff --git a/cups/md5passwd.c b/cups/md5passwd.c
a3fe81
index a9817aa..c9ffe04 100644
a3fe81
--- a/cups/md5passwd.c
a3fe81
+++ b/cups/md5passwd.c
a3fe81
@@ -17,6 +17,7 @@
a3fe81
  * Include necessary headers...
a3fe81
  */
a3fe81
 
a3fe81
+#include <cups/cups.h>
a3fe81
 #include "http-private.h"
a3fe81
 #include "string-private.h"
a3fe81
 
a3fe81
@@ -31,7 +32,6 @@ httpMD5(const char *username,		/* I - User name */
a3fe81
         const char *passwd,		/* I - Password string */
a3fe81
 	char       md5[33])		/* O - MD5 string */
a3fe81
 {
a3fe81
-  _cups_md5_state_t	state;		/* MD5 state info */
a3fe81
   unsigned char		sum[16];	/* Sum data */
a3fe81
   char			line[256];	/* Line to sum */
a3fe81
 
a3fe81
@@ -41,15 +41,13 @@ httpMD5(const char *username,		/* I - User name */
a3fe81
   */
a3fe81
 
a3fe81
   snprintf(line, sizeof(line), "%s:%s:%s", username, realm, passwd);
a3fe81
-  _cupsMD5Init(&state);
a3fe81
-  _cupsMD5Append(&state, (unsigned char *)line, (int)strlen(line));
a3fe81
-  _cupsMD5Finish(&state, sum);
a3fe81
+  cupsHashData("md5", (unsigned char *)line, strlen(line), sum, sizeof(sum));
a3fe81
 
a3fe81
  /*
a3fe81
   * Return the sum...
a3fe81
   */
a3fe81
 
a3fe81
-  return (httpMD5String(sum, md5));
a3fe81
+  return ((char *)cupsHashString(sum, sizeof(sum), md5, 33));
a3fe81
 }
a3fe81
 
a3fe81
 
a3fe81
@@ -65,7 +63,6 @@ httpMD5Final(const char *nonce,		/* I - Server nonce value */
a3fe81
 	     const char *resource,	/* I - Resource path */
a3fe81
              char       md5[33])	/* IO - MD5 sum */
a3fe81
 {
a3fe81
-  _cups_md5_state_t	state;		/* MD5 state info */
a3fe81
   unsigned char		sum[16];	/* Sum data */
a3fe81
   char			line[1024];	/* Line of data */
a3fe81
   char			a2[33];		/* Hash of method and resource */
a3fe81
@@ -76,9 +73,7 @@ httpMD5Final(const char *nonce,		/* I - Server nonce value */
a3fe81
   */
a3fe81
 
a3fe81
   snprintf(line, sizeof(line), "%s:%s", method, resource);
a3fe81
-  _cupsMD5Init(&state);
a3fe81
-  _cupsMD5Append(&state, (unsigned char *)line, (int)strlen(line));
a3fe81
-  _cupsMD5Finish(&state, sum);
a3fe81
+  cupsHashData("md5", (unsigned char *)line, strlen(line), sum, sizeof(sum));
a3fe81
   httpMD5String(sum, a2);
a3fe81
 
a3fe81
  /*
a3fe81
@@ -88,12 +83,9 @@ httpMD5Final(const char *nonce,		/* I - Server nonce value */
a3fe81
   */
a3fe81
 
a3fe81
   snprintf(line, sizeof(line), "%s:%s:%s", md5, nonce, a2);
a3fe81
+  cupsHashData("md5", (unsigned char *)line, strlen(line), sum, sizeof(sum));
a3fe81
 
a3fe81
-  _cupsMD5Init(&state);
a3fe81
-  _cupsMD5Append(&state, (unsigned char *)line, (int)strlen(line));
a3fe81
-  _cupsMD5Finish(&state, sum);
a3fe81
-
a3fe81
-  return (httpMD5String(sum, md5));
a3fe81
+  return ((char *)cupsHashString(sum, sizeof(sum), md5, 33));
a3fe81
 }
a3fe81
 
a3fe81
 
a3fe81
@@ -106,23 +98,5 @@ httpMD5String(const unsigned char *sum,	/* I - MD5 sum data */
a3fe81
               char                md5[33])
a3fe81
 					/* O - MD5 sum in hex */
a3fe81
 {
a3fe81
-  int		i;			/* Looping var */
a3fe81
-  char		*md5ptr;		/* Pointer into MD5 string */
a3fe81
-  static const char hex[] = "0123456789abcdef";
a3fe81
-					/* Hex digits */
a3fe81
-
a3fe81
-
a3fe81
- /*
a3fe81
-  * Convert the MD5 sum to hexadecimal...
a3fe81
-  */
a3fe81
-
a3fe81
-  for (i = 16, md5ptr = md5; i > 0; i --, sum ++)
a3fe81
-  {
a3fe81
-    *md5ptr++ = hex[*sum >> 4];
a3fe81
-    *md5ptr++ = hex[*sum & 15];
a3fe81
-  }
a3fe81
-
a3fe81
-  *md5ptr = '\0';
a3fe81
-
a3fe81
-  return (md5);
a3fe81
+  return ((char *)cupsHashString(sum, 16, md5, 33));
a3fe81
 }
a3fe81
diff --git a/scheduler/auth.c b/scheduler/auth.c
a3fe81
index 71df9dc..e7d0006 100644
a3fe81
--- a/scheduler/auth.c
a3fe81
+++ b/scheduler/auth.c
a3fe81
@@ -72,9 +72,6 @@ static int		check_authref(cupsd_client_t *con, const char *right);
a3fe81
 static int		compare_locations(cupsd_location_t *a,
a3fe81
 			                  cupsd_location_t *b);
a3fe81
 static cupsd_authmask_t	*copy_authmask(cupsd_authmask_t *am, void *data);
a3fe81
-#if !HAVE_LIBPAM
a3fe81
-static char		*cups_crypt(const char *pw, const char *salt);
a3fe81
-#endif /* !HAVE_LIBPAM */
a3fe81
 static void		free_authmask(cupsd_authmask_t *am, void *data);
a3fe81
 #if HAVE_LIBPAM
a3fe81
 static int		pam_func(int, const struct pam_message **,
a3fe81
@@ -695,14 +692,14 @@ cupsdAuthorize(cupsd_client_t *con)	/* I - Client connection */
a3fe81
 	    * client...
a3fe81
 	    */
a3fe81
 
a3fe81
-	    pass = cups_crypt(password, pw->pw_passwd);
a3fe81
+	    pass = crypt(password, pw->pw_passwd);
a3fe81
 
a3fe81
 	    if (!pass || strcmp(pw->pw_passwd, pass))
a3fe81
 	    {
a3fe81
 #  ifdef HAVE_SHADOW_H
a3fe81
 	      if (spw)
a3fe81
 	      {
a3fe81
-		pass = cups_crypt(password, spw->sp_pwdp);
a3fe81
+		pass = crypt(password, spw->sp_pwdp);
a3fe81
 
a3fe81
 		if (pass == NULL || strcmp(spw->sp_pwdp, pass))
a3fe81
 		{
a3fe81
@@ -1988,129 +1985,6 @@ copy_authmask(cupsd_authmask_t *mask,	/* I - Existing auth mask */
a3fe81
 }
a3fe81
 
a3fe81
 
a3fe81
-#if !HAVE_LIBPAM
a3fe81
-/*
a3fe81
- * 'cups_crypt()' - Encrypt the password using the DES or MD5 algorithms,
a3fe81
- *                  as needed.
a3fe81
- */
a3fe81
-
a3fe81
-static char *				/* O - Encrypted password */
a3fe81
-cups_crypt(const char *pw,		/* I - Password string */
a3fe81
-           const char *salt)		/* I - Salt (key) string */
a3fe81
-{
a3fe81
-  if (!strncmp(salt, "$1$", 3))
a3fe81
-  {
a3fe81
-   /*
a3fe81
-    * Use MD5 passwords without the benefit of PAM; this is for
a3fe81
-    * Slackware Linux, and the algorithm was taken from the
a3fe81
-    * old shadow-19990827/lib/md5crypt.c source code... :(
a3fe81
-    */
a3fe81
-
a3fe81
-    int			i;		/* Looping var */
a3fe81
-    unsigned long	n;		/* Output number */
a3fe81
-    int			pwlen;		/* Length of password string */
a3fe81
-    const char		*salt_end;	/* End of "salt" data for MD5 */
a3fe81
-    char		*ptr;		/* Pointer into result string */
a3fe81
-    _cups_md5_state_t	state;		/* Primary MD5 state info */
a3fe81
-    _cups_md5_state_t	state2;		/* Secondary MD5 state info */
a3fe81
-    unsigned char	digest[16];	/* MD5 digest result */
a3fe81
-    static char		result[120];	/* Final password string */
a3fe81
-
a3fe81
-
a3fe81
-   /*
a3fe81
-    * Get the salt data between dollar signs, e.g. $1$saltdata$md5.
a3fe81
-    * Get a maximum of 8 characters of salt data after $1$...
a3fe81
-    */
a3fe81
-
a3fe81
-    for (salt_end = salt + 3; *salt_end && (salt_end - salt) < 11; salt_end ++)
a3fe81
-      if (*salt_end == '$')
a3fe81
-        break;
a3fe81
-
a3fe81
-   /*
a3fe81
-    * Compute the MD5 sum we need...
a3fe81
-    */
a3fe81
-
a3fe81
-    pwlen = strlen(pw);
a3fe81
-
a3fe81
-    _cupsMD5Init(&state);
a3fe81
-    _cupsMD5Append(&state, (unsigned char *)pw, pwlen);
a3fe81
-    _cupsMD5Append(&state, (unsigned char *)salt, salt_end - salt);
a3fe81
-
a3fe81
-    _cupsMD5Init(&state2);
a3fe81
-    _cupsMD5Append(&state2, (unsigned char *)pw, pwlen);
a3fe81
-    _cupsMD5Append(&state2, (unsigned char *)salt + 3, salt_end - salt - 3);
a3fe81
-    _cupsMD5Append(&state2, (unsigned char *)pw, pwlen);
a3fe81
-    _cupsMD5Finish(&state2, digest);
a3fe81
-
a3fe81
-    for (i = pwlen; i > 0; i -= 16)
a3fe81
-      _cupsMD5Append(&state, digest, i > 16 ? 16 : i);
a3fe81
-
a3fe81
-    for (i = pwlen; i > 0; i >>= 1)
a3fe81
-      _cupsMD5Append(&state, (unsigned char *)((i & 1) ? "" : pw), 1);
a3fe81
-
a3fe81
-    _cupsMD5Finish(&state, digest);
a3fe81
-
a3fe81
-    for (i = 0; i < 1000; i ++)
a3fe81
-    {
a3fe81
-      _cupsMD5Init(&state);
a3fe81
-
a3fe81
-      if (i & 1)
a3fe81
-        _cupsMD5Append(&state, (unsigned char *)pw, pwlen);
a3fe81
-      else
a3fe81
-        _cupsMD5Append(&state, digest, 16);
a3fe81
-
a3fe81
-      if (i % 3)
a3fe81
-        _cupsMD5Append(&state, (unsigned char *)salt + 3, salt_end - salt - 3);
a3fe81
-
a3fe81
-      if (i % 7)
a3fe81
-        _cupsMD5Append(&state, (unsigned char *)pw, pwlen);
a3fe81
-
a3fe81
-      if (i & 1)
a3fe81
-        _cupsMD5Append(&state, digest, 16);
a3fe81
-      else
a3fe81
-        _cupsMD5Append(&state, (unsigned char *)pw, pwlen);
a3fe81
-
a3fe81
-      _cupsMD5Finish(&state, digest);
a3fe81
-    }
a3fe81
-
a3fe81
-   /*
a3fe81
-    * Copy the final sum to the result string and return...
a3fe81
-    */
a3fe81
-
a3fe81
-    memcpy(result, salt, (size_t)(salt_end - salt));
a3fe81
-    ptr = result + (salt_end - salt);
a3fe81
-    *ptr++ = '$';
a3fe81
-
a3fe81
-    for (i = 0; i < 5; i ++, ptr += 4)
a3fe81
-    {
a3fe81
-      n = ((((unsigned)digest[i] << 8) | (unsigned)digest[i + 6]) << 8);
a3fe81
-
a3fe81
-      if (i < 4)
a3fe81
-        n |= (unsigned)digest[i + 12];
a3fe81
-      else
a3fe81
-        n |= (unsigned)digest[5];
a3fe81
-
a3fe81
-      to64(ptr, n, 4);
a3fe81
-    }
a3fe81
-
a3fe81
-    to64(ptr, (unsigned)digest[11], 2);
a3fe81
-    ptr += 2;
a3fe81
-    *ptr = '\0';
a3fe81
-
a3fe81
-    return (result);
a3fe81
-  }
a3fe81
-  else
a3fe81
-  {
a3fe81
-   /*
a3fe81
-    * Use the standard crypt() function...
a3fe81
-    */
a3fe81
-
a3fe81
-    return (crypt(pw, salt));
a3fe81
-  }
a3fe81
-}
a3fe81
-#endif /* !HAVE_LIBPAM */
a3fe81
-
a3fe81
-
a3fe81
 /*
a3fe81
  * 'free_authmask()' - Free function for auth masks.
a3fe81
  */