Software / code / prosody
Annotate
spec/util_array_spec.lua @ 13801:a5d5fefb8b68 13.0
mod_tls: Enable Prosody's certificate checking for incoming s2s connections (fixes #1916) (thanks Damian, Zash)
Various options in Prosody allow control over the behaviour of the certificate
verification process For example, some deployments choose to allow falling
back to traditional "dialback" authentication (XEP-0220), while others verify
via DANE, hard-coded fingerprints, or other custom plugins.
Implementing this flexibility requires us to override OpenSSL's default
certificate verification, to allow Prosody to verify the certificate itself,
apply custom policies and make decisions based on the outcome.
To enable our custom logic, we have to suppress OpenSSL's default behaviour of
aborting the connection with a TLS alert message. With LuaSec, this can be
achieved by using the verifyext "lsec_continue" flag.
We also need to use the lsec_ignore_purpose flag, because XMPP s2s uses server
certificates as "client" certificates (for mutual TLS verification in outgoing
s2s connections).
Commit 99d2100d2918 moved these settings out of the defaults and into mod_s2s,
because we only really need these changes for s2s, and they should be opt-in,
rather than automatically applied to all TLS services we offer.
That commit was incomplete, because it only added the flags for incoming
direct TLS connections. StartTLS connections are handled by mod_tls, which was
not applying the lsec_* flags. It previously worked because they were already
in the defaults.
This resulted in incoming s2s connections with "invalid" certificates being
aborted early by OpenSSL, even if settings such as `s2s_secure_auth = false`
or DANE were present in the config.
Outgoing s2s connections inherit verify "none" from the defaults, which means
OpenSSL will receive the cert but will not terminate the connection when it is
deemed invalid. This means we don't need lsec_continue there, and we also
don't need lsec_ignore_purpose (because the remote peer is a "server").
Wondering why we can't just use verify "none" for incoming s2s? It's because
in that mode, OpenSSL won't request a certificate from the peer for incoming
connections. Setting verify "peer" is how you ask OpenSSL to request a
certificate from the client, but also what triggers its built-in verification.
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Tue, 01 Apr 2025 17:26:56 +0100 |
| parent | 13245:ffe4adbd2af9 |
| rev | line source |
|---|---|
| 10100 | 1 local array = require "util.array"; |
| 2 describe("util.array", function () | |
| 3 describe("creation", function () | |
|
13245
ffe4adbd2af9
util.array: Fix new() library function
Kim Alvefur <zash@zash.se>
parents:
11787
diff
changeset
|
4 describe("new", function () |
|
ffe4adbd2af9
util.array: Fix new() library function
Kim Alvefur <zash@zash.se>
parents:
11787
diff
changeset
|
5 it("works", function () |
|
ffe4adbd2af9
util.array: Fix new() library function
Kim Alvefur <zash@zash.se>
parents:
11787
diff
changeset
|
6 local a = array.new({"a", "b", "c"}); |
|
ffe4adbd2af9
util.array: Fix new() library function
Kim Alvefur <zash@zash.se>
parents:
11787
diff
changeset
|
7 assert.same({"a", "b", "c"}, a); |
|
ffe4adbd2af9
util.array: Fix new() library function
Kim Alvefur <zash@zash.se>
parents:
11787
diff
changeset
|
8 end); |
|
ffe4adbd2af9
util.array: Fix new() library function
Kim Alvefur <zash@zash.se>
parents:
11787
diff
changeset
|
9 end); |
|
ffe4adbd2af9
util.array: Fix new() library function
Kim Alvefur <zash@zash.se>
parents:
11787
diff
changeset
|
10 |
| 10397 | 11 describe("from table", function () |
| 10100 | 12 it("works", function () |
| 13 local a = array({"a", "b", "c"}); | |
| 14 assert.same({"a", "b", "c"}, a); | |
| 15 end); | |
| 16 end); | |
| 17 | |
| 18 describe("from iterator", function () | |
| 19 it("works", function () | |
| 20 -- collects the first value, ie the keys | |
| 21 local a = array(ipairs({true, true, true})); | |
| 22 assert.same({1, 2, 3}, a); | |
| 23 end); | |
| 24 end); | |
| 25 | |
| 26 describe("collect", function () | |
| 27 it("works", function () | |
| 28 -- collects the first value, ie the keys | |
| 29 local a = array.collect(ipairs({true, true, true})); | |
| 30 assert.same({1, 2, 3}, a); | |
| 31 end); | |
| 32 end); | |
| 33 | |
| 34 end); | |
| 35 | |
| 36 describe("metatable", function () | |
| 37 describe("operator", function () | |
| 38 describe("addition", function () | |
| 39 it("works", function () | |
| 40 local a = array({ "a", "b" }); | |
| 41 local b = array({ "c", "d" }); | |
| 42 assert.same({"a", "b", "c", "d"}, a + b); | |
| 43 end); | |
| 44 end); | |
| 45 | |
| 46 describe("equality", function () | |
| 47 it("works", function () | |
| 48 local a1 = array({ "a", "b" }); | |
| 49 local a2 = array({ "a", "b" }); | |
| 50 local b = array({ "c", "d" }); | |
| 51 assert.truthy(a1 == a2); | |
| 52 assert.falsy(a1 == b); | |
|
10590
257dc26e8e65
util.array: Add a test case for a behavior change in Lua 5.3
Kim Alvefur <zash@zash.se>
parents:
10397
diff
changeset
|
53 assert.falsy(a1 == { "a", "b" }, "Behavior of metatables changed in Lua 5.3"); |
| 10100 | 54 end); |
| 55 end); | |
| 56 | |
| 57 describe("division", function () | |
| 58 it("works", function () | |
| 59 local a = array({ "a", "b", "c" }); | |
| 60 local b = a / function (i) if i ~= "b" then return i .. "x" end end; | |
| 61 assert.same({ "ax", "cx" }, b); | |
| 62 end); | |
| 63 end); | |
| 64 | |
| 65 end); | |
| 66 end); | |
| 67 | |
| 68 describe("methods", function () | |
| 69 describe("map", function () | |
| 70 it("works", function () | |
| 71 local a = array({ "a", "b", "c" }); | |
| 72 local b = a:map(string.upper); | |
| 73 assert.same({ "A", "B", "C" }, b); | |
| 74 end); | |
| 75 end); | |
| 76 | |
| 77 describe("filter", function () | |
| 78 it("works", function () | |
| 79 local a = array({ "a", "b", "c" }); | |
| 80 a:filter(function (i) return i ~= "b" end); | |
| 81 assert.same({ "a", "c" }, a); | |
| 82 end); | |
| 83 end); | |
| 84 | |
| 85 describe("sort", function () | |
| 86 it("works", function () | |
| 87 local a = array({ 5, 4, 3, 1, 2, }); | |
| 88 a:sort(); | |
| 89 assert.same({ 1, 2, 3, 4, 5, }, a); | |
| 90 end); | |
| 91 end); | |
| 92 | |
| 93 describe("unique", function () | |
| 94 it("works", function () | |
| 95 local a = array({ "a", "b", "c", "c", "a", "b" }); | |
| 96 a:unique(); | |
| 97 assert.same({ "a", "b", "c" }, a); | |
| 98 end); | |
| 99 end); | |
| 100 | |
| 101 describe("pluck", function () | |
| 102 it("works", function () | |
| 103 local a = array({ { a = 1, b = -1 }, { a = 2, b = -2 }, }); | |
| 104 a:pluck("a"); | |
| 105 assert.same({ 1, 2 }, a); | |
| 106 end); | |
| 107 end); | |
| 108 | |
| 109 | |
| 110 describe("reverse", function () | |
| 111 it("works", function () | |
| 112 local a = array({ "a", "b", "c" }); | |
| 113 a:reverse(); | |
| 114 assert.same({ "c", "b", "a" }, a); | |
| 115 end); | |
| 116 end); | |
| 117 | |
| 118 -- TODO :shuffle | |
| 119 | |
| 120 describe("append", function () | |
| 121 it("works", function () | |
| 122 local a = array({ "a", "b", "c" }); | |
| 123 a:append(array({ "d", "e", })); | |
| 124 assert.same({ "a", "b", "c", "d", "e" }, a); | |
| 125 end); | |
| 126 end); | |
| 127 | |
| 128 describe("push", function () | |
| 129 it("works", function () | |
| 130 local a = array({ "a", "b", "c" }); | |
| 131 a:push("d"):push("e"); | |
| 132 assert.same({ "a", "b", "c", "d", "e" }, a); | |
| 133 end); | |
| 134 end); | |
| 135 | |
| 136 describe("pop", function () | |
| 137 it("works", function () | |
| 138 local a = array({ "a", "b", "c" }); | |
| 139 assert.equal("c", a:pop()); | |
| 140 assert.same({ "a", "b", }, a); | |
| 141 end); | |
| 142 end); | |
| 143 | |
| 144 describe("concat", function () | |
| 145 it("works", function () | |
| 146 local a = array({ "a", "b", "c" }); | |
| 147 assert.equal("a,b,c", a:concat(",")); | |
| 148 end); | |
| 149 end); | |
| 150 | |
| 151 describe("length", function () | |
| 152 it("works", function () | |
| 153 local a = array({ "a", "b", "c" }); | |
| 154 assert.equal(3, a:length()); | |
| 155 end); | |
| 156 end); | |
| 157 | |
|
11787
3ae6fa901a8b
util.array: Add :slice() method + tests
Matthew Wild <mwild1@gmail.com>
parents:
10590
diff
changeset
|
158 describe("slice", function () |
|
3ae6fa901a8b
util.array: Add :slice() method + tests
Matthew Wild <mwild1@gmail.com>
parents:
10590
diff
changeset
|
159 it("works", function () |
|
3ae6fa901a8b
util.array: Add :slice() method + tests
Matthew Wild <mwild1@gmail.com>
parents:
10590
diff
changeset
|
160 local a = array({ "a", "b", "c" }); |
|
3ae6fa901a8b
util.array: Add :slice() method + tests
Matthew Wild <mwild1@gmail.com>
parents:
10590
diff
changeset
|
161 assert.equal(array.slice(a, 1, 2), array{ "a", "b" }); |
|
3ae6fa901a8b
util.array: Add :slice() method + tests
Matthew Wild <mwild1@gmail.com>
parents:
10590
diff
changeset
|
162 assert.equal(array.slice(a, 1, 3), array{ "a", "b", "c" }); |
|
3ae6fa901a8b
util.array: Add :slice() method + tests
Matthew Wild <mwild1@gmail.com>
parents:
10590
diff
changeset
|
163 assert.equal(array.slice(a, 2, 3), array{ "b", "c" }); |
|
3ae6fa901a8b
util.array: Add :slice() method + tests
Matthew Wild <mwild1@gmail.com>
parents:
10590
diff
changeset
|
164 assert.equal(array.slice(a, 2), array{ "b", "c" }); |
|
3ae6fa901a8b
util.array: Add :slice() method + tests
Matthew Wild <mwild1@gmail.com>
parents:
10590
diff
changeset
|
165 assert.equal(array.slice(a, -4), array{ "a", "b", "c" }); |
|
3ae6fa901a8b
util.array: Add :slice() method + tests
Matthew Wild <mwild1@gmail.com>
parents:
10590
diff
changeset
|
166 assert.equal(array.slice(a, -3), array{ "a", "b", "c" }); |
|
3ae6fa901a8b
util.array: Add :slice() method + tests
Matthew Wild <mwild1@gmail.com>
parents:
10590
diff
changeset
|
167 assert.equal(array.slice(a, -2), array{ "b", "c" }); |
|
3ae6fa901a8b
util.array: Add :slice() method + tests
Matthew Wild <mwild1@gmail.com>
parents:
10590
diff
changeset
|
168 assert.equal(array.slice(a, -1), array{ "c" }); |
|
3ae6fa901a8b
util.array: Add :slice() method + tests
Matthew Wild <mwild1@gmail.com>
parents:
10590
diff
changeset
|
169 end); |
|
3ae6fa901a8b
util.array: Add :slice() method + tests
Matthew Wild <mwild1@gmail.com>
parents:
10590
diff
changeset
|
170 |
|
3ae6fa901a8b
util.array: Add :slice() method + tests
Matthew Wild <mwild1@gmail.com>
parents:
10590
diff
changeset
|
171 it("can mutate", function () |
|
3ae6fa901a8b
util.array: Add :slice() method + tests
Matthew Wild <mwild1@gmail.com>
parents:
10590
diff
changeset
|
172 local a = array({ "a", "b", "c" }); |
|
3ae6fa901a8b
util.array: Add :slice() method + tests
Matthew Wild <mwild1@gmail.com>
parents:
10590
diff
changeset
|
173 assert.equal(a:slice(-1), array{"c"}); |
|
3ae6fa901a8b
util.array: Add :slice() method + tests
Matthew Wild <mwild1@gmail.com>
parents:
10590
diff
changeset
|
174 assert.equal(a, array{"c"}); |
|
3ae6fa901a8b
util.array: Add :slice() method + tests
Matthew Wild <mwild1@gmail.com>
parents:
10590
diff
changeset
|
175 end); |
|
3ae6fa901a8b
util.array: Add :slice() method + tests
Matthew Wild <mwild1@gmail.com>
parents:
10590
diff
changeset
|
176 end); |
| 10100 | 177 end); |
| 178 | |
| 179 -- TODO The various array.foo(array ina, array outa) functions | |
| 180 end); | |
| 181 |