Software /
code /
prosody
Annotate
util/id.lua @ 12525:8087f5357f53 0.12
mod_smacks: Fix bounce of stanzas directed to full JID on unclean disconnect
Fixes #1758
Introduced in 1ea01660c79a
In e62025f949f9 to and from was inverted since it changed from acting on
a reply to acting on the original stanza (or a clone thereof)
Unsure of the purpose of this check, you don't usually send stanzas to
your own full JID. Perhaps guarding against routing loops?
The check was present in the original commit of mod_smacks,
prosody-modules rev 9a7671720dec
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 27 May 2022 12:05:47 +0200 |
parent | 12111:f8d280215633 |
child | 12975:d10957394a3c |
rev | line source |
---|---|
8016
9546c629289b
util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 -- Prosody IM |
9546c629289b
util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 -- Copyright (C) 2008-2017 Matthew Wild |
9546c629289b
util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 -- Copyright (C) 2008-2017 Waqas Hussain |
9546c629289b
util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 -- Copyright (C) 2008-2017 Kim Alvefur |
9546c629289b
util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 -- |
9546c629289b
util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 -- This project is MIT/X11 licensed. Please see the |
9546c629289b
util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 -- COPYING file in the source package for more information. |
9546c629289b
util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 -- |
9546c629289b
util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 |
9546c629289b
util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 local s_gsub = string.gsub; |
9546c629289b
util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 local random_bytes = require "util.random".bytes; |
9546c629289b
util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 local base64_encode = require "util.encodings".base64.encode; |
9546c629289b
util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 |
9546c629289b
util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 local b64url = { ["+"] = "-", ["/"] = "_", ["="] = "" }; |
9546c629289b
util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 local function b64url_random(len) |
9546c629289b
util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 return (s_gsub(base64_encode(random_bytes(len)), "[+/=]", b64url)); |
9546c629289b
util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 end |
9546c629289b
util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 |
9546c629289b
util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 return { |
12110
b5b799a2a10c
util.id: Adjust entropy levels, with rationales
Kim Alvefur <zash@zash.se>
parents:
8016
diff
changeset
|
20 -- sizes divisible by 3 fit nicely into base64 without padding== |
b5b799a2a10c
util.id: Adjust entropy levels, with rationales
Kim Alvefur <zash@zash.se>
parents:
8016
diff
changeset
|
21 |
12111 | 22 -- for short lived things with low risk of collisions |
23 tiny = function() return b64url_random(3); end; | |
24 | |
12110
b5b799a2a10c
util.id: Adjust entropy levels, with rationales
Kim Alvefur <zash@zash.se>
parents:
8016
diff
changeset
|
25 -- close to 8 bytes, should be good enough for relatively short lived or uses |
b5b799a2a10c
util.id: Adjust entropy levels, with rationales
Kim Alvefur <zash@zash.se>
parents:
8016
diff
changeset
|
26 -- scoped by host or users, half the size of an uuid |
b5b799a2a10c
util.id: Adjust entropy levels, with rationales
Kim Alvefur <zash@zash.se>
parents:
8016
diff
changeset
|
27 short = function() return b64url_random(9); end; |
b5b799a2a10c
util.id: Adjust entropy levels, with rationales
Kim Alvefur <zash@zash.se>
parents:
8016
diff
changeset
|
28 |
b5b799a2a10c
util.id: Adjust entropy levels, with rationales
Kim Alvefur <zash@zash.se>
parents:
8016
diff
changeset
|
29 -- more entropy than uuid at 2/3 the size |
b5b799a2a10c
util.id: Adjust entropy levels, with rationales
Kim Alvefur <zash@zash.se>
parents:
8016
diff
changeset
|
30 -- should be okay for globally scoped ids or security token |
b5b799a2a10c
util.id: Adjust entropy levels, with rationales
Kim Alvefur <zash@zash.se>
parents:
8016
diff
changeset
|
31 medium = function() return b64url_random(18); end; |
b5b799a2a10c
util.id: Adjust entropy levels, with rationales
Kim Alvefur <zash@zash.se>
parents:
8016
diff
changeset
|
32 |
b5b799a2a10c
util.id: Adjust entropy levels, with rationales
Kim Alvefur <zash@zash.se>
parents:
8016
diff
changeset
|
33 -- as long as an uuid but MOAR entropy |
b5b799a2a10c
util.id: Adjust entropy levels, with rationales
Kim Alvefur <zash@zash.se>
parents:
8016
diff
changeset
|
34 long = function() return b64url_random(27); end; |
b5b799a2a10c
util.id: Adjust entropy levels, with rationales
Kim Alvefur <zash@zash.se>
parents:
8016
diff
changeset
|
35 |
b5b799a2a10c
util.id: Adjust entropy levels, with rationales
Kim Alvefur <zash@zash.se>
parents:
8016
diff
changeset
|
36 -- pick your own adventure |
8016
9546c629289b
util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 custom = function (size) |
9546c629289b
util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
38 return function () return b64url_random(size); end; |
9546c629289b
util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
39 end; |
9546c629289b
util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
40 } |