NOTES
Glibc Notes
The glibc2 version of this function supports additional encryption
algorithms.
If salt is a character string starting with the characters "$id$" fol‐
lowed by a string terminated by "$":
$id$salt$encrypted
then instead of using the DES machine, id identifies the encryption
method used and this then determines how the rest of the password
string is interpreted. The following values of id are supported:
ID | Method
─────────────────────────────────────────────────────────
1 | MD5
2a | Blowfish (not in mainline glibc; added in some
| Linux distributions)
5 | SHA-256 (since glibc 2.7)
6 | SHA-512 (since glibc 2.7)
So $5$salt$encrypted is an SHA-256 encoded password and
$6$salt$encrypted is an SHA-512 encoded one.
"salt" stands for the up to 16 characters following "$id$" in the salt.
The encrypted part of the password string is the actual computed pass‐
word. The size of this string is fixed:
MD5 | 22 characters
SHA-256 | 43 characters
SHA-512 | 86 characters
The characters in "salt" and "encrypted" are drawn from the set
[a–zA–Z0–9./]. In the MD5 and SHA implementations the entire key is
significant (instead of only the first 8 bytes in DES).
The patch I did doesn't presume that you're using these modes, but the application I'm doing needs to have support there since we're a heightened security design that needs to use the 512-bit mode for passphrases.
diff -rupN hiawatha-8.7-orig/src/httpauth.c hiawatha-8.7/src/httpauth.c
--- hiawatha-8.7-orig/src/httpauth.c 2013-01-09 12:18:21.000000000 -0700
+++ hiawatha-8.7/src/httpauth.c 2013-01-24 13:03:11.305384682 -0700
@@ -205,8 +205,8 @@ static char *get_A1(t_session *session,
*/
static int basic_http_authentication(t_session *session, char *auth_str) {
size_t auth_len;
- int retval;
- char *auth_user, *auth_passwd, *passwd, *encrypted, salt[3];
+ int retval, loop;
+ char *auth_user, *auth_passwd, *passwd, *encrypted, salt[21];
auth_len = strlen(auth_str);
if ((auth_user = (char*)malloc(auth_len + 1)) == NULL) {
@@ -249,9 +249,43 @@ static int basic_http_authentication(t_s
return ha_DENIED;
}
+#if 0
+ /*
+ * This presumes that the salt will ALWAYS be two bytes, which is...
+ * not always so. GNU's crypt() call is expanded and the code that's
+ * in the #else side of this #if 0 block handles detection of whether
+ * or not we're working with an extended salt or not in the password
+ * file. This is being done to account for FreeWave's using SHA-512
+ * bit hashes to support something more akin to a FIPS compliant
+ * password in the file.
+ *
+ * FCE (01-24-13)
+ */
salt[0] = *passwd;
salt[1] = *(passwd + 1);
salt[2] = '\0';
+#else
+ memcpy(salt, passwd, 3);
+ if ((salt[0] == '$') && (salt[2] == '$') && ((salt[1] == '1') || (salt[1] == '5') || (salt[1] == '6')))
+ {
+ /* GNU extended crypt() salt - nab the rest up to the closing '$' */
+ for(loop = 0; loop < 17; loop++)
+ {
+ salt[3 + loop] = passwd[3 + loop];
+ if (passwd[3 + loop] == '$')
+ {
+ loop++;
+ break;
+ }
+ }
+ salt[3 + loop] = 0;
+ }
+ else
+ {
+ /* Regular crypt() salt */
+ salt[2] = 0;
+ }
+#endif
encrypted = crypt(auth_passwd, salt);
/* Password match?
It's probably not QUITE the way you want it done in your code- which is why I started the conversation. It still needs to account for the widened support because most servers handle this one correctly- and I really, really want to use yours since it is one of the lightest, yet most secure ones out there.