altarch-user / rpms / httpd

Forked from rpms/httpd 2 years ago
Clone

Blame SOURCES/httpd-2.4.6-r1861793+.patch

008793
# ./pullrev.sh 1861793 1862611 1862612
008793
http://svn.apache.org/viewvc?view=revision&revision=1861793
008793
http://svn.apache.org/viewvc?view=revision&revision=1862611
008793
http://svn.apache.org/viewvc?view=revision&revision=1862612
008793
http://svn.apache.org/viewvc?view=revision&revision=1862724
008793
008793
--- httpd-2.4.6/configure.in.r1861793+
008793
+++ httpd-2.4.6/configure.in
008793
@@ -464,6 +464,28 @@
008793
 AC_SEARCH_LIBS(crypt, crypt)
008793
 CRYPT_LIBS="$LIBS"
008793
 APACHE_SUBST(CRYPT_LIBS)
008793
+
008793
+if test "$ac_cv_search_crypt" != "no"; then
008793
+   # Test crypt() with the SHA-512 test vector from https://akkadia.org/drepper/SHA-crypt.txt
008793
+   AC_CACHE_CHECK([whether crypt() supports SHA-2], [ap_cv_crypt_sha2], [
008793
+    AC_RUN_IFELSE([AC_LANG_PROGRAM([[
008793
+#include <crypt.h>
008793
+#include <stdlib.h>
008793
+#include <string.h>
008793
+
008793
+#define PASSWD_0 "Hello world!"
008793
+#define SALT_0 "\$6\$saltstring"
008793
+#define EXPECT_0 "\$6\$saltstring\$svn8UoSVapNtMuq1ukKS4tPQd8iKwSMHWjl/O817G3uBnIFNjnQJu" \
008793
+               "esI68u4OTLiBFdcbYEdFCoEOfaS35inz1"
008793
+]], [char *result = crypt(PASSWD_0, SALT_0);
008793
+     if (!result) return 1;
008793
+     if (strcmp(result, EXPECT_0)) return 2;
008793
+])], [ap_cv_crypt_sha2=yes], [ap_cv_crypt_sha2=no])])
008793
+   if test "$ap_cv_crypt_sha2" = yes; then
008793
+     AC_DEFINE([HAVE_CRYPT_SHA2], 1, [Define if crypt() supports SHA-2 hashes])
008793
+   fi
008793
+fi
008793
+
008793
 LIBS="$saved_LIBS"
008793
 
008793
 dnl See Comment #Spoon
008793
--- httpd-2.4.6/docs/man/htpasswd.1.r1861793+
008793
+++ httpd-2.4.6/docs/man/htpasswd.1
008793
@@ -27,16 +27,16 @@
008793
 .SH "SYNOPSIS"
008793
  
008793
 .PP
008793
-\fBhtpasswd\fR [ -\fBc\fR ] [ -\fBi\fR ] [ -\fBm\fR | -\fBB\fR | -\fBd\fR | -\fBs\fR | -\fBp\fR ] [ -\fBC\fR \fIcost\fR ] [ -\fBD\fR ] [ -\fBv\fR ] \fIpasswdfile\fR \fIusername\fR
008793
+\fBhtpasswd\fR [ -\fBc\fR ] [ -\fBi\fR ] [ -\fBm\fR | -\fBB\fR | -\fBd\fR | -\fBs\fR | -\fBp\fR ] [ -\fBr\fR \fIrounds\fR ] [ -\fBC\fR \fIcost\fR ] [ -\fBD\fR ] [ -\fBv\fR ] \fIpasswdfile\fR \fIusername\fR
008793
  
008793
 .PP
008793
-\fBhtpasswd\fR -\fBb\fR [ -\fBc\fR ] [ -\fBm\fR | -\fBB\fR | -\fBd\fR | -\fBs\fR | -\fBp\fR ] [ -\fBC\fR \fIcost\fR ] [ -\fBD\fR ] [ -\fBv\fR ] \fIpasswdfile\fR \fIusername\fR \fIpassword\fR
008793
+\fBhtpasswd\fR -\fBb\fR [ -\fBc\fR ] [ -\fBm\fR | -\fBB\fR | -\fBd\fR | -\fBs\fR | -\fBp\fR ] [ -\fBr\fR \fIrounds\fR ] [ -\fBC\fR \fIcost\fR ] [ -\fBD\fR ] [ -\fBv\fR ] \fIpasswdfile\fR \fIusername\fR \fIpassword\fR
008793
  
008793
 .PP
008793
-\fBhtpasswd\fR -\fBn\fR [ -\fBi\fR ] [ -\fBm\fR | -\fBB\fR | -\fBd\fR | -\fBs\fR | -\fBp\fR ] [ -\fBC\fR \fIcost\fR ] \fIusername\fR
008793
+\fBhtpasswd\fR -\fBn\fR [ -\fBi\fR ] [ -\fBm\fR | -\fBB\fR | -\fBd\fR | -\fBs\fR | -\fBp\fR ] [ -\fBr\fR \fIrounds\fR ] [ -\fBC\fR \fIcost\fR ] \fIusername\fR
008793
  
008793
 .PP
008793
-\fBhtpasswd\fR -\fBnb\fR [ -\fBm\fR | -\fBB\fR | -\fBd\fR | -\fBs\fR | -\fBp\fR ] [ -\fBC\fR \fIcost\fR ] \fIusername\fR \fIpassword\fR
008793
+\fBhtpasswd\fR -\fBnb\fR [ -\fBm\fR | -\fBB\fR | -\fBd\fR | -\fBs\fR | -\fBp\fR ] [ -\fBr\fR \fIrounds\fR ] [ -\fBC\fR \fIcost\fR ] \fIusername\fR \fIpassword\fR
008793
  
008793
 
008793
 .SH "SUMMARY"
008793
@@ -48,7 +48,7 @@
008793
 Resources available from the Apache HTTP server can be restricted to just the users listed in the files created by htpasswd\&. This program can only manage usernames and passwords stored in a flat-file\&. It can encrypt and display password information for use in other types of data stores, though\&. To use a DBM database see dbmmanage or htdbm\&.
008793
  
008793
 .PP
008793
-htpasswd encrypts passwords using either bcrypt, a version of MD5 modified for Apache, SHA1, or the system's crypt() routine\&. Files managed by htpasswd may contain a mixture of different encoding types of passwords; some user records may have bcrypt or MD5-encrypted passwords while others in the same file may have passwords encrypted with crypt()\&.
008793
++\fBhtpasswd\fR encrypts passwords using either bcrypt, a version of MD5 modified for Apache, SHA-1, or the system's \fBcrypt()\fR routine\&. SHA-2-based hashes (SHA-256 and SHA-512) are supported for \fBcrypt()\fR\&. Files managed by \fBhtpasswd\fR may contain a mixture of different encoding types of passwords; some user records may have bcrypt or MD5-encrypted passwords while others in the same file may have passwords encrypted with \fBcrypt()\fR\&.
008793
  
008793
 .PP
008793
 This manual page only lists the command line arguments\&. For details of the directives necessary to configure user authentication in httpd see the Apache manual, which is part of the Apache distribution or can be found at http://httpd\&.apache\&.org/\&.
008793
@@ -73,17 +73,26 @@
008793
 -m
008793
 Use MD5 encryption for passwords\&. This is the default (since version 2\&.2\&.18)\&.  
008793
 .TP
008793
+-2
008793
+Use SHA-256 \fBcrypt()\fR based hashes for passwords\&. This is supported on most Unix platforms\&.  
008793
+.TP
008793
+-5
008793
+Use SHA-512 \fBcrypt()\fR based hashes for passwords\&. This is supported on most Unix platforms\&.  
008793
+.TP
008793
 -B
008793
 Use bcrypt encryption for passwords\&. This is currently considered to be very secure\&.  
008793
 .TP
008793
 -C
008793
 This flag is only allowed in combination with -B (bcrypt encryption)\&. It sets the computing time used for the bcrypt algorithm (higher is more secure but slower, default: 5, valid: 4 to 31)\&.  
008793
 .TP
008793
+-r
008793
+This flag is only allowed in combination with \fB-2\fR or \fB-5\fR\&. It sets the number of hash rounds used for the SHA-2 algorithms (higher is more secure but slower; the default is 5,000)\&.  
008793
+.TP
008793
 -d
008793
 Use crypt() encryption for passwords\&. This is not supported by the httpd server on Windows and Netware\&. This algorithm limits the password length to 8 characters\&. This algorithm is \fBinsecure\fR by today's standards\&. It used to be the default algorithm until version 2\&.2\&.17\&.  
008793
 .TP
008793
 -s
008793
-Use SHA encryption for passwords\&. Facilitates migration from/to Netscape servers using the LDAP Directory Interchange Format (ldif)\&. This algorithm is \fBinsecure\fR by today's standards\&.  
008793
+Use SHA-1 encryption for passwords\&. Facilitates migration from/to Netscape servers using the LDAP Directory Interchange Format (ldif)\&. This algorithm is \fBinsecure\fR by today's standards\&.  
008793
 .TP
008793
 -p
008793
 Use plaintext passwords\&. Though htpasswd will support creation on all platforms, the httpd daemon will only accept plain text passwords on Windows and Netware\&.  
008793
@@ -152,11 +161,14 @@
008793
 When using the crypt() algorithm, note that only the first 8 characters of the password are used to form the password\&. If the supplied password is longer, the extra characters will be silently discarded\&.
008793
  
008793
 .PP
008793
-The SHA encryption format does not use salting: for a given password, there is only one encrypted representation\&. The crypt() and MD5 formats permute the representation by prepending a random salt string, to make dictionary attacks against the passwords more difficult\&.
008793
+The SHA-1 encryption format does not use salting: for a given password, there is only one encrypted representation\&. The crypt() and MD5 formats permute the representation by prepending a random salt string, to make dictionary attacks against the passwords more difficult\&.
008793
  
008793
 .PP
008793
-The SHA and crypt() formats are insecure by today's standards\&.
008793
- 
008793
+The SHA-1 and crypt() formats are insecure by today's standards\&.
008793
+
008793
+.PP
008793
+The SHA-2-based \fBcrypt()\fR formats (SHA-256 and SHA-512) are supported on most modern Unix systems, and follow the specification at https://www\&.akkadia\&.org/drepper/SHA-crypt\&.txt\&
008793
+
008793
 .SH "RESTRICTIONS"
008793
  
008793
 .PP
008793
--- httpd-2.4.6/support/htpasswd.c.r1861793+
008793
+++ httpd-2.4.6/support/htpasswd.c
008793
@@ -93,28 +93,32 @@
008793
 static void usage(void)
008793
 {
008793
     apr_file_printf(errfile, "Usage:" NL
008793
-        "\thtpasswd [-cimBdpsDv] [-C cost] passwordfile username" NL
008793
-        "\thtpasswd -b[cmBdpsDv] [-C cost] passwordfile username password" NL
008793
+        "\thtpasswd [-cimB25dpsDv] [-C cost] [-r rounds] passwordfile username" NL
008793
+        "\thtpasswd -b[cmB25dpsDv] [-C cost] [-r rounds] passwordfile username password" NL
008793
         NL
008793
-        "\thtpasswd -n[imBdps] [-C cost] username" NL
008793
-        "\thtpasswd -nb[mBdps] [-C cost] username password" NL
008793
+        "\thtpasswd -n[imB25dps] [-C cost] [-r rounds] username" NL
008793
+        "\thtpasswd -nb[mB25dps] [-C cost] [-r rounds] username password" NL
008793
         " -c  Create a new file." NL
008793
         " -n  Don't update file; display results on stdout." NL
008793
         " -b  Use the password from the command line rather than prompting "
008793
             "for it." NL
008793
         " -i  Read password from stdin without verification (for script usage)." NL
008793
         " -m  Force MD5 encryption of the password (default)." NL
008793
-        " -B  Force bcrypt encryption of the password (very secure)." NL
008793
+        " -2  Force SHA-256 crypt() hash of the password (secure)." NL
008793
+        " -5  Force SHA-512 crypt() hash of the password (secure)." NL
008793
+        " -B  Force bcrypt aencryption of the password (very secure)." NL
008793
         " -C  Set the computing time used for the bcrypt algorithm" NL
008793
         "     (higher is more secure but slower, default: %d, valid: 4 to 31)." NL
008793
+        " -r  Set the number of rounds used for the SHA-256, SHA-512 algorithms" NL
008793
+        "     (higher is more secure but slower, default: 5000)." NL
008793
         " -d  Force CRYPT encryption of the password (8 chars max, insecure)." NL
008793
-        " -s  Force SHA encryption of the password (insecure)." NL
008793
+        " -s  Force SHA-1 encryption of the password (insecure)." NL
008793
         " -p  Do not encrypt the password (plaintext, insecure)." NL
008793
         " -D  Delete the specified user." NL
008793
         " -v  Verify password for the specified user." NL
008793
         "On other systems than Windows and NetWare the '-p' flag will "
008793
             "probably not work." NL
008793
-        "The SHA algorithm does not use a salt and is less secure than the "
008793
+        "The SHA-1 algorithm does not use a salt and is less secure than the "
008793
             "MD5 algorithm." NL,
008793
         BCRYPT_DEFAULT_COST
008793
     );
008793
@@ -173,7 +177,7 @@
008793
     if (rv != APR_SUCCESS)
008793
         exit(ERR_SYNTAX);
008793
 
008793
-    while ((rv = apr_getopt(state, "cnmspdBbDiC:v", &opt, &opt_arg)) == APR_SUCCESS) {
008793
+    while ((rv = apr_getopt(state, "cnmspdBbDi25C:r:v", &opt, &opt_arg)) == APR_SUCCESS) {
008793
         switch (opt) {
008793
         case 'c':
008793
             *mask |= APHTP_NEWFILE;
008793
--- httpd-2.4.6/support/passwd_common.c.r1861793+
008793
+++ httpd-2.4.6/support/passwd_common.c
008793
@@ -185,10 +185,15 @@
008793
 #if CRYPT_ALGO_SUPPORTED
008793
     char *cbuf;
008793
 #endif
008793
+#ifdef HAVE_CRYPT_SHA2
008793
+    const char *setting;
008793
+    char method;
008793
+#endif
008793
 
008793
-    if (ctx->cost != 0 && ctx->alg != ALG_BCRYPT) {
008793
+    if (ctx->cost != 0 && ctx->alg != ALG_BCRYPT
008793
+        && ctx->alg != ALG_CRYPT_SHA256 && ctx->alg != ALG_CRYPT_SHA512 ) {
008793
         apr_file_printf(errfile,
008793
-                        "Warning: Ignoring -C argument for this algorithm." NL);
008793
+                        "Warning: Ignoring -C/-r argument for this algorithm." NL);
008793
     }
008793
 
008793
     if (ctx->passwd == NULL) {
008793
@@ -246,6 +251,34 @@
008793
         break;
008793
 #endif /* CRYPT_ALGO_SUPPORTED */
008793
 
008793
+#ifdef HAVE_CRYPT_SHA2
008793
+    case ALG_CRYPT_SHA256:
008793
+    case ALG_CRYPT_SHA512:
008793
+        ret = generate_salt(salt, 16, &ctx->errstr, ctx->pool);
008793
+        if (ret != 0)
008793
+            break;
008793
+
008793
+        method = ctx->alg == ALG_CRYPT_SHA256 ? '5': '6';
008793
+
008793
+        if (ctx->cost) 
008793
+            setting = apr_psprintf(ctx->pool, "$%c$rounds=%d$%s",
008793
+                                   method, ctx->cost, salt);
008793
+        else
008793
+            setting = apr_psprintf(ctx->pool, "$%c$%s",
008793
+                                   method, salt);
008793
+
008793
+        cbuf = crypt(pw, setting);
008793
+        if (cbuf == NULL) {
008793
+            rv = APR_FROM_OS_ERROR(errno);
008793
+            ctx->errstr = apr_psprintf(ctx->pool, "crypt() failed: %pm", &rv;;
008793
+            ret = ERR_PWMISMATCH;
008793
+            break;
008793
+        }
008793
+
008793
+        apr_cpystrn(ctx->out, cbuf, ctx->out_len - 1);
008793
+        break;
008793
+#endif /* HAVE_CRYPT_SHA2 */
008793
+
008793
 #if BCRYPT_ALGO_SUPPORTED
008793
     case ALG_BCRYPT:
008793
         rv = apr_generate_random_bytes((unsigned char*)salt, 16);
008793
@@ -294,6 +327,19 @@
008793
     case 's':
008793
         ctx->alg = ALG_APSHA;
008793
         break;
008793
+#ifdef HAVE_CRYPT_SHA2
008793
+    case '2':
008793
+        ctx->alg = ALG_CRYPT_SHA256;
008793
+        break;
008793
+    case '5':
008793
+        ctx->alg = ALG_CRYPT_SHA512;
008793
+        break;
008793
+#else
008793
+    case '2':
008793
+    case '5':
008793
+        ctx->errstr = "SHA-2 crypt() algorithms are not supported on this platform.";
008793
+        return ERR_ALG_NOT_SUPP;
008793
+#endif
008793
     case 'p':
008793
         ctx->alg = ALG_PLAIN;
008793
 #if !PLAIN_ALGO_SUPPORTED
008793
@@ -324,11 +370,12 @@
008793
         return ERR_ALG_NOT_SUPP;
008793
 #endif
008793
         break;
008793
-    case 'C': {
008793
+    case 'C':
008793
+    case 'r': {
008793
             char *endptr;
008793
             long num = strtol(opt_arg, &endptr, 10);
008793
             if (*endptr != '\0' || num <= 0) {
008793
-                ctx->errstr = "argument to -C must be a positive integer";
008793
+                ctx->errstr = "argument to -C/-r must be a positive integer";
008793
                 return ERR_SYNTAX;
008793
             }
008793
             ctx->cost = num;
008793
--- httpd-2.4.6/support/passwd_common.h.r1861793+
008793
+++ httpd-2.4.6/support/passwd_common.h
008793
@@ -28,6 +28,8 @@
008793
 #include "apu_version.h"
008793
 #endif
008793
 
008793
+#include "ap_config_auto.h"
008793
+
008793
 #define MAX_STRING_LEN 256
008793
 
008793
 #define ALG_PLAIN 0
008793
@@ -35,6 +37,8 @@
008793
 #define ALG_APMD5 2
008793
 #define ALG_APSHA 3
008793
 #define ALG_BCRYPT 4
008793
+#define ALG_CRYPT_SHA256 5
008793
+#define ALG_CRYPT_SHA512 6
008793
 
008793
 #define BCRYPT_DEFAULT_COST 5
008793
 
008793
@@ -79,7 +83,7 @@
008793
     apr_size_t      out_len;
008793
     char            *passwd;
008793
     int             alg;
008793
-    int             cost;
008793
+    int             cost; /* cost for bcrypt, rounds for SHA-2 */
008793
     enum {
008793
         PW_PROMPT = 0,
008793
         PW_ARG,