41a6c3
# ./pullrev.sh 1861793 1862611 1862612
41a6c3
http://svn.apache.org/viewvc?view=revision&revision=1861793
41a6c3
http://svn.apache.org/viewvc?view=revision&revision=1862611
41a6c3
http://svn.apache.org/viewvc?view=revision&revision=1862612
41a6c3
http://svn.apache.org/viewvc?view=revision&revision=1862724
41a6c3
41a6c3
--- httpd-2.4.6/configure.in.r1861793+
41a6c3
+++ httpd-2.4.6/configure.in
41a6c3
@@ -464,6 +464,28 @@
41a6c3
 AC_SEARCH_LIBS(crypt, crypt)
41a6c3
 CRYPT_LIBS="$LIBS"
41a6c3
 APACHE_SUBST(CRYPT_LIBS)
41a6c3
+
41a6c3
+if test "$ac_cv_search_crypt" != "no"; then
41a6c3
+   # Test crypt() with the SHA-512 test vector from https://akkadia.org/drepper/SHA-crypt.txt
41a6c3
+   AC_CACHE_CHECK([whether crypt() supports SHA-2], [ap_cv_crypt_sha2], [
41a6c3
+    AC_RUN_IFELSE([AC_LANG_PROGRAM([[
41a6c3
+#include <crypt.h>
41a6c3
+#include <stdlib.h>
41a6c3
+#include <string.h>
41a6c3
+
41a6c3
+#define PASSWD_0 "Hello world!"
41a6c3
+#define SALT_0 "\$6\$saltstring"
41a6c3
+#define EXPECT_0 "\$6\$saltstring\$svn8UoSVapNtMuq1ukKS4tPQd8iKwSMHWjl/O817G3uBnIFNjnQJu" \
41a6c3
+               "esI68u4OTLiBFdcbYEdFCoEOfaS35inz1"
41a6c3
+]], [char *result = crypt(PASSWD_0, SALT_0);
41a6c3
+     if (!result) return 1;
41a6c3
+     if (strcmp(result, EXPECT_0)) return 2;
41a6c3
+])], [ap_cv_crypt_sha2=yes], [ap_cv_crypt_sha2=no])])
41a6c3
+   if test "$ap_cv_crypt_sha2" = yes; then
41a6c3
+     AC_DEFINE([HAVE_CRYPT_SHA2], 1, [Define if crypt() supports SHA-2 hashes])
41a6c3
+   fi
41a6c3
+fi
41a6c3
+
41a6c3
 LIBS="$saved_LIBS"
41a6c3
 
41a6c3
 dnl See Comment #Spoon
41a6c3
--- httpd-2.4.6/docs/man/htpasswd.1.r1861793+
41a6c3
+++ httpd-2.4.6/docs/man/htpasswd.1
41a6c3
@@ -27,16 +27,16 @@
41a6c3
 .SH "SYNOPSIS"
41a6c3
  
41a6c3
 .PP
41a6c3
-\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
41a6c3
+\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
41a6c3
  
41a6c3
 .PP
41a6c3
-\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
41a6c3
+\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
41a6c3
  
41a6c3
 .PP
41a6c3
-\fBhtpasswd\fR -\fBn\fR [ -\fBi\fR ] [ -\fBm\fR | -\fBB\fR | -\fBd\fR | -\fBs\fR | -\fBp\fR ] [ -\fBC\fR \fIcost\fR ] \fIusername\fR
41a6c3
+\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
41a6c3
  
41a6c3
 .PP
41a6c3
-\fBhtpasswd\fR -\fBnb\fR [ -\fBm\fR | -\fBB\fR | -\fBd\fR | -\fBs\fR | -\fBp\fR ] [ -\fBC\fR \fIcost\fR ] \fIusername\fR \fIpassword\fR
41a6c3
+\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
41a6c3
  
41a6c3
 
41a6c3
 .SH "SUMMARY"
41a6c3
@@ -48,7 +48,7 @@
41a6c3
 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\&.
41a6c3
  
41a6c3
 .PP
41a6c3
-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()\&.
41a6c3
++\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\&.
41a6c3
  
41a6c3
 .PP
41a6c3
 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/\&.
41a6c3
@@ -73,17 +73,26 @@
41a6c3
 -m
41a6c3
 Use MD5 encryption for passwords\&. This is the default (since version 2\&.2\&.18)\&.  
41a6c3
 .TP
41a6c3
+-2
41a6c3
+Use SHA-256 \fBcrypt()\fR based hashes for passwords\&. This is supported on most Unix platforms\&.  
41a6c3
+.TP
41a6c3
+-5
41a6c3
+Use SHA-512 \fBcrypt()\fR based hashes for passwords\&. This is supported on most Unix platforms\&.  
41a6c3
+.TP
41a6c3
 -B
41a6c3
 Use bcrypt encryption for passwords\&. This is currently considered to be very secure\&.  
41a6c3
 .TP
41a6c3
 -C
41a6c3
 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)\&.  
41a6c3
 .TP
41a6c3
+-r
41a6c3
+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)\&.  
41a6c3
+.TP
41a6c3
 -d
41a6c3
 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\&.  
41a6c3
 .TP
41a6c3
 -s
41a6c3
-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\&.  
41a6c3
+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\&.  
41a6c3
 .TP
41a6c3
 -p
41a6c3
 Use plaintext passwords\&. Though htpasswd will support creation on all platforms, the httpd daemon will only accept plain text passwords on Windows and Netware\&.  
41a6c3
@@ -152,11 +161,14 @@
41a6c3
 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\&.
41a6c3
  
41a6c3
 .PP
41a6c3
-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\&.
41a6c3
+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\&.
41a6c3
  
41a6c3
 .PP
41a6c3
-The SHA and crypt() formats are insecure by today's standards\&.
41a6c3
- 
41a6c3
+The SHA-1 and crypt() formats are insecure by today's standards\&.
41a6c3
+
41a6c3
+.PP
41a6c3
+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\&
41a6c3
+
41a6c3
 .SH "RESTRICTIONS"
41a6c3
  
41a6c3
 .PP
41a6c3
--- httpd-2.4.6/support/htpasswd.c.r1861793+
41a6c3
+++ httpd-2.4.6/support/htpasswd.c
41a6c3
@@ -93,28 +93,32 @@
41a6c3
 static void usage(void)
41a6c3
 {
41a6c3
     apr_file_printf(errfile, "Usage:" NL
41a6c3
-        "\thtpasswd [-cimBdpsDv] [-C cost] passwordfile username" NL
41a6c3
-        "\thtpasswd -b[cmBdpsDv] [-C cost] passwordfile username password" NL
41a6c3
+        "\thtpasswd [-cimB25dpsDv] [-C cost] [-r rounds] passwordfile username" NL
41a6c3
+        "\thtpasswd -b[cmB25dpsDv] [-C cost] [-r rounds] passwordfile username password" NL
41a6c3
         NL
41a6c3
-        "\thtpasswd -n[imBdps] [-C cost] username" NL
41a6c3
-        "\thtpasswd -nb[mBdps] [-C cost] username password" NL
41a6c3
+        "\thtpasswd -n[imB25dps] [-C cost] [-r rounds] username" NL
41a6c3
+        "\thtpasswd -nb[mB25dps] [-C cost] [-r rounds] username password" NL
41a6c3
         " -c  Create a new file." NL
41a6c3
         " -n  Don't update file; display results on stdout." NL
41a6c3
         " -b  Use the password from the command line rather than prompting "
41a6c3
             "for it." NL
41a6c3
         " -i  Read password from stdin without verification (for script usage)." NL
41a6c3
         " -m  Force MD5 encryption of the password (default)." NL
41a6c3
-        " -B  Force bcrypt encryption of the password (very secure)." NL
41a6c3
+        " -2  Force SHA-256 crypt() hash of the password (secure)." NL
41a6c3
+        " -5  Force SHA-512 crypt() hash of the password (secure)." NL
41a6c3
+        " -B  Force bcrypt aencryption of the password (very secure)." NL
41a6c3
         " -C  Set the computing time used for the bcrypt algorithm" NL
41a6c3
         "     (higher is more secure but slower, default: %d, valid: 4 to 31)." NL
41a6c3
+        " -r  Set the number of rounds used for the SHA-256, SHA-512 algorithms" NL
41a6c3
+        "     (higher is more secure but slower, default: 5000)." NL
41a6c3
         " -d  Force CRYPT encryption of the password (8 chars max, insecure)." NL
41a6c3
-        " -s  Force SHA encryption of the password (insecure)." NL
41a6c3
+        " -s  Force SHA-1 encryption of the password (insecure)." NL
41a6c3
         " -p  Do not encrypt the password (plaintext, insecure)." NL
41a6c3
         " -D  Delete the specified user." NL
41a6c3
         " -v  Verify password for the specified user." NL
41a6c3
         "On other systems than Windows and NetWare the '-p' flag will "
41a6c3
             "probably not work." NL
41a6c3
-        "The SHA algorithm does not use a salt and is less secure than the "
41a6c3
+        "The SHA-1 algorithm does not use a salt and is less secure than the "
41a6c3
             "MD5 algorithm." NL,
41a6c3
         BCRYPT_DEFAULT_COST
41a6c3
     );
41a6c3
@@ -173,7 +177,7 @@
41a6c3
     if (rv != APR_SUCCESS)
41a6c3
         exit(ERR_SYNTAX);
41a6c3
 
41a6c3
-    while ((rv = apr_getopt(state, "cnmspdBbDiC:v", &opt, &opt_arg)) == APR_SUCCESS) {
41a6c3
+    while ((rv = apr_getopt(state, "cnmspdBbDi25C:r:v", &opt, &opt_arg)) == APR_SUCCESS) {
41a6c3
         switch (opt) {
41a6c3
         case 'c':
41a6c3
             *mask |= APHTP_NEWFILE;
41a6c3
--- httpd-2.4.6/support/passwd_common.c.r1861793+
41a6c3
+++ httpd-2.4.6/support/passwd_common.c
41a6c3
@@ -185,10 +185,15 @@
41a6c3
 #if CRYPT_ALGO_SUPPORTED
41a6c3
     char *cbuf;
41a6c3
 #endif
41a6c3
+#ifdef HAVE_CRYPT_SHA2
41a6c3
+    const char *setting;
41a6c3
+    char method;
41a6c3
+#endif
41a6c3
 
41a6c3
-    if (ctx->cost != 0 && ctx->alg != ALG_BCRYPT) {
41a6c3
+    if (ctx->cost != 0 && ctx->alg != ALG_BCRYPT
41a6c3
+        && ctx->alg != ALG_CRYPT_SHA256 && ctx->alg != ALG_CRYPT_SHA512 ) {
41a6c3
         apr_file_printf(errfile,
41a6c3
-                        "Warning: Ignoring -C argument for this algorithm." NL);
41a6c3
+                        "Warning: Ignoring -C/-r argument for this algorithm." NL);
41a6c3
     }
41a6c3
 
41a6c3
     if (ctx->passwd == NULL) {
41a6c3
@@ -246,6 +251,34 @@
41a6c3
         break;
41a6c3
 #endif /* CRYPT_ALGO_SUPPORTED */
41a6c3
 
41a6c3
+#ifdef HAVE_CRYPT_SHA2
41a6c3
+    case ALG_CRYPT_SHA256:
41a6c3
+    case ALG_CRYPT_SHA512:
41a6c3
+        ret = generate_salt(salt, 16, &ctx->errstr, ctx->pool);
41a6c3
+        if (ret != 0)
41a6c3
+            break;
41a6c3
+
41a6c3
+        method = ctx->alg == ALG_CRYPT_SHA256 ? '5': '6';
41a6c3
+
41a6c3
+        if (ctx->cost) 
41a6c3
+            setting = apr_psprintf(ctx->pool, "$%c$rounds=%d$%s",
41a6c3
+                                   method, ctx->cost, salt);
41a6c3
+        else
41a6c3
+            setting = apr_psprintf(ctx->pool, "$%c$%s",
41a6c3
+                                   method, salt);
41a6c3
+
41a6c3
+        cbuf = crypt(pw, setting);
41a6c3
+        if (cbuf == NULL) {
41a6c3
+            rv = APR_FROM_OS_ERROR(errno);
41a6c3
+            ctx->errstr = apr_psprintf(ctx->pool, "crypt() failed: %pm", &rv;;
41a6c3
+            ret = ERR_PWMISMATCH;
41a6c3
+            break;
41a6c3
+        }
41a6c3
+
41a6c3
+        apr_cpystrn(ctx->out, cbuf, ctx->out_len - 1);
41a6c3
+        break;
41a6c3
+#endif /* HAVE_CRYPT_SHA2 */
41a6c3
+
41a6c3
 #if BCRYPT_ALGO_SUPPORTED
41a6c3
     case ALG_BCRYPT:
41a6c3
         rv = apr_generate_random_bytes((unsigned char*)salt, 16);
41a6c3
@@ -294,6 +327,19 @@
41a6c3
     case 's':
41a6c3
         ctx->alg = ALG_APSHA;
41a6c3
         break;
41a6c3
+#ifdef HAVE_CRYPT_SHA2
41a6c3
+    case '2':
41a6c3
+        ctx->alg = ALG_CRYPT_SHA256;
41a6c3
+        break;
41a6c3
+    case '5':
41a6c3
+        ctx->alg = ALG_CRYPT_SHA512;
41a6c3
+        break;
41a6c3
+#else
41a6c3
+    case '2':
41a6c3
+    case '5':
41a6c3
+        ctx->errstr = "SHA-2 crypt() algorithms are not supported on this platform.";
41a6c3
+        return ERR_ALG_NOT_SUPP;
41a6c3
+#endif
41a6c3
     case 'p':
41a6c3
         ctx->alg = ALG_PLAIN;
41a6c3
 #if !PLAIN_ALGO_SUPPORTED
41a6c3
@@ -324,11 +370,12 @@
41a6c3
         return ERR_ALG_NOT_SUPP;
41a6c3
 #endif
41a6c3
         break;
41a6c3
-    case 'C': {
41a6c3
+    case 'C':
41a6c3
+    case 'r': {
41a6c3
             char *endptr;
41a6c3
             long num = strtol(opt_arg, &endptr, 10);
41a6c3
             if (*endptr != '\0' || num <= 0) {
41a6c3
-                ctx->errstr = "argument to -C must be a positive integer";
41a6c3
+                ctx->errstr = "argument to -C/-r must be a positive integer";
41a6c3
                 return ERR_SYNTAX;
41a6c3
             }
41a6c3
             ctx->cost = num;
41a6c3
--- httpd-2.4.6/support/passwd_common.h.r1861793+
41a6c3
+++ httpd-2.4.6/support/passwd_common.h
41a6c3
@@ -28,6 +28,8 @@
41a6c3
 #include "apu_version.h"
41a6c3
 #endif
41a6c3
 
41a6c3
+#include "ap_config_auto.h"
41a6c3
+
41a6c3
 #define MAX_STRING_LEN 256
41a6c3
 
41a6c3
 #define ALG_PLAIN 0
41a6c3
@@ -35,6 +37,8 @@
41a6c3
 #define ALG_APMD5 2
41a6c3
 #define ALG_APSHA 3
41a6c3
 #define ALG_BCRYPT 4
41a6c3
+#define ALG_CRYPT_SHA256 5
41a6c3
+#define ALG_CRYPT_SHA512 6
41a6c3
 
41a6c3
 #define BCRYPT_DEFAULT_COST 5
41a6c3
 
41a6c3
@@ -79,7 +83,7 @@
41a6c3
     apr_size_t      out_len;
41a6c3
     char            *passwd;
41a6c3
     int             alg;
41a6c3
-    int             cost;
41a6c3
+    int             cost; /* cost for bcrypt, rounds for SHA-2 */
41a6c3
     enum {
41a6c3
         PW_PROMPT = 0,
41a6c3
         PW_ARG,