Software / code / prosody
Comparison
plugins/mod_auth_internal_hashed.lua @ 4764:0df5b2d5dff3
mod_auth_internal_hashed: Remove COMPAT code (upgrading old hashed storage format from pre-0.8)
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sat, 28 Apr 2012 03:59:31 +0100 |
| parent | 4763:322b7335fbf3 |
| child | 5116:5f9066db1b4d |
comparison
equal
deleted
inserted
replaced
| 4763:322b7335fbf3 | 4764:0df5b2d5dff3 |
|---|---|
| 12 local getAuthenticationDatabaseSHA1 = require "util.sasl.scram".getAuthenticationDatabaseSHA1; | 12 local getAuthenticationDatabaseSHA1 = require "util.sasl.scram".getAuthenticationDatabaseSHA1; |
| 13 local usermanager = require "core.usermanager"; | 13 local usermanager = require "core.usermanager"; |
| 14 local generate_uuid = require "util.uuid".generate; | 14 local generate_uuid = require "util.uuid".generate; |
| 15 local new_sasl = require "util.sasl".new; | 15 local new_sasl = require "util.sasl".new; |
| 16 local nodeprep = require "util.encodings".stringprep.nodeprep; | 16 local nodeprep = require "util.encodings".stringprep.nodeprep; |
| 17 | |
| 18 -- COMPAT w/old trunk: remove these two lines before 0.8 release | |
| 19 local hmac_sha1 = require "util.hmac".sha1; | |
| 20 local sha1 = require "util.hashes".sha1; | |
| 21 | 17 |
| 22 local to_hex; | 18 local to_hex; |
| 23 do | 19 do |
| 24 local function replace_byte_with_hex(byte) | 20 local function replace_byte_with_hex(byte) |
| 25 return ("%02x"):format(byte:byte()); | 21 return ("%02x"):format(byte:byte()); |
| 62 end | 58 end |
| 63 end | 59 end |
| 64 | 60 |
| 65 if credentials.iteration_count == nil or credentials.salt == nil or string.len(credentials.salt) == 0 then | 61 if credentials.iteration_count == nil or credentials.salt == nil or string.len(credentials.salt) == 0 then |
| 66 return nil, "Auth failed. Stored salt and iteration count information is not complete."; | 62 return nil, "Auth failed. Stored salt and iteration count information is not complete."; |
| 67 end | |
| 68 | |
| 69 -- convert hexpass to stored_key and server_key | |
| 70 -- COMPAT w/old trunk: remove before 0.8 release | |
| 71 if credentials.hashpass then | |
| 72 local salted_password = from_hex(credentials.hashpass); | |
| 73 credentials.stored_key = sha1(hmac_sha1(salted_password, "Client Key"), true); | |
| 74 credentials.server_key = to_hex(hmac_sha1(salted_password, "Server Key")); | |
| 75 credentials.hashpass = nil | |
| 76 datamanager.store(username, host, "accounts", credentials); | |
| 77 end | 63 end |
| 78 | 64 |
| 79 local valid, stored_key, server_key = getAuthenticationDatabaseSHA1(password, credentials.salt, credentials.iteration_count); | 65 local valid, stored_key, server_key = getAuthenticationDatabaseSHA1(password, credentials.salt, credentials.iteration_count); |
| 80 | 66 |
| 81 local stored_key_hex = to_hex(stored_key); | 67 local stored_key_hex = to_hex(stored_key); |
| 147 usermanager.set_password(username, credentials.password, host); | 133 usermanager.set_password(username, credentials.password, host); |
| 148 credentials = datamanager.load(username, host, "accounts"); | 134 credentials = datamanager.load(username, host, "accounts"); |
| 149 if not credentials then return; end | 135 if not credentials then return; end |
| 150 end | 136 end |
| 151 | 137 |
| 152 -- convert hexpass to stored_key and server_key | |
| 153 -- COMPAT w/old trunk: remove before 0.8 release | |
| 154 if credentials.hashpass then | |
| 155 local salted_password = from_hex(credentials.hashpass); | |
| 156 credentials.stored_key = sha1(hmac_sha1(salted_password, "Client Key"), true); | |
| 157 credentials.server_key = to_hex(hmac_sha1(salted_password, "Server Key")); | |
| 158 credentials.hashpass = nil | |
| 159 datamanager.store(username, host, "accounts", credentials); | |
| 160 end | |
| 161 | |
| 162 local stored_key, server_key, iteration_count, salt = credentials.stored_key, credentials.server_key, credentials.iteration_count, credentials.salt; | 138 local stored_key, server_key, iteration_count, salt = credentials.stored_key, credentials.server_key, credentials.iteration_count, credentials.salt; |
| 163 stored_key = stored_key and from_hex(stored_key); | 139 stored_key = stored_key and from_hex(stored_key); |
| 164 server_key = server_key and from_hex(server_key); | 140 server_key = server_key and from_hex(server_key); |
| 165 return stored_key, server_key, iteration_count, salt, true; | 141 return stored_key, server_key, iteration_count, salt, true; |
| 166 end | 142 end |