aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-12-02 01:14:55 +0100
committerKim Alvefur <zash@zash.se>2021-12-02 01:14:55 +0100
commita3ea469ed9ebeab2c4db54712f0b8ace3f28e15f (patch)
tree73afa5f5b01ce5511adea6f669f1e707ae2fcb1e
parent5797a3f65dd0ae2c8393b6992522fcfb34be2fc5 (diff)
downloadprosody-a3ea469ed9ebeab2c4db54712f0b8ace3f28e15f.tar.gz
prosody-a3ea469ed9ebeab2c4db54712f0b8ace3f28e15f.zip
util.id: Adjust entropy levels, with rationales
Modules using ids for logging should not need the now pretty large medium one.
-rw-r--r--net/server_epoll.lua2
-rw-r--r--net/unbound.lua2
-rw-r--r--plugins/mod_scansion_record.lua2
-rw-r--r--util/id.lua17
4 files changed, 17 insertions, 6 deletions
diff --git a/net/server_epoll.lua b/net/server_epoll.lua
index f61c204c..faa6a1b5 100644
--- a/net/server_epoll.lua
+++ b/net/server_epoll.lua
@@ -26,7 +26,7 @@ local createtable = require "util.table".create;
local inet = require "util.net";
local inet_pton = inet.pton;
local _SOCKETINVALID = socket._SOCKETINVALID or -1;
-local new_id = require "util.id".medium;
+local new_id = require "util.id".short;
local xpcall = require "util.xpcall".xpcall;
local poller = require "util.poll"
diff --git a/net/unbound.lua b/net/unbound.lua
index 22b0614b..4a6f0241 100644
--- a/net/unbound.lua
+++ b/net/unbound.lua
@@ -18,7 +18,7 @@ local log = logger.init("unbound");
local net_server = require "net.server";
local libunbound = require"lunbound";
local promise = require"util.promise";
-local new_id = require "util.id".medium;
+local new_id = require "util.id".short;
local gettime = require"socket".gettime;
local dns_utils = require"util.dns";
diff --git a/plugins/mod_scansion_record.lua b/plugins/mod_scansion_record.lua
index 6d57c209..5fefd398 100644
--- a/plugins/mod_scansion_record.lua
+++ b/plugins/mod_scansion_record.lua
@@ -8,7 +8,7 @@ local dt = require "util.datetime";
local dm = require "util.datamanager";
local st = require "util.stanza";
-local record_id = id.medium():lower();
+local record_id = id.short():lower();
local record_date = os.date("%Y%b%d"):lower();
local header_file = dm.getpath(record_id, "scansion", record_date, "scs", true);
local record_file = dm.getpath(record_id, "scansion", record_date, "log", true);
diff --git a/util/id.lua b/util/id.lua
index 731355fa..64b56662 100644
--- a/util/id.lua
+++ b/util/id.lua
@@ -17,9 +17,20 @@ local function b64url_random(len)
end
return {
- short = function () return b64url_random(6); end;
- medium = function () return b64url_random(12); end;
- long = function () return b64url_random(24); end;
+ -- sizes divisible by 3 fit nicely into base64 without padding==
+
+ -- close to 8 bytes, should be good enough for relatively short lived or uses
+ -- scoped by host or users, half the size of an uuid
+ short = function() return b64url_random(9); end;
+
+ -- more entropy than uuid at 2/3 the size
+ -- should be okay for globally scoped ids or security token
+ medium = function() return b64url_random(18); end;
+
+ -- as long as an uuid but MOAR entropy
+ long = function() return b64url_random(27); end;
+
+ -- pick your own adventure
custom = function (size)
return function () return b64url_random(size); end;
end;