aboutsummaryrefslogtreecommitdiffstats
path: root/regress/148-custom-extensions.lua
diff options
context:
space:
mode:
authorLibravatarLibravatar daurnimator <quae@daurnimator.com> 2018-10-25 18:53:15 +1100
committerLibravatarLibravatar daurnimator <quae@daurnimator.com> 2018-10-31 13:13:23 +1100
commit7f297d41be8c77bffbbbac1dfced2586f07f538b (patch)
treeae62856924b1633a428763de8d5a26708b68d58d /regress/148-custom-extensions.lua
parent9228c0dea5feab7f71510e46e207e61c1188ec44 (diff)
downloadluaossl-7f297d41be8c77bffbbbac1dfced2586f07f538b.tar.gz
luaossl-7f297d41be8c77bffbbbac1dfced2586f07f538b.tar.bz2
luaossl-7f297d41be8c77bffbbbac1dfced2586f07f538b.zip
Add ssl.context:addCustomExtension()
Diffstat (limited to 'regress/148-custom-extensions.lua')
-rwxr-xr-xregress/148-custom-extensions.lua57
1 files changed, 57 insertions, 0 deletions
diff --git a/regress/148-custom-extensions.lua b/regress/148-custom-extensions.lua
new file mode 100755
index 0000000..110621c
--- /dev/null
+++ b/regress/148-custom-extensions.lua
@@ -0,0 +1,57 @@
+#!/usr/bin/env lua
+
+local regress = require "regress"
+local cqueues = require "cqueues"
+local cs = require "cqueues.socket"
+local openssl_ctx = require "openssl.ssl.context"
+
+local cli_ctx, srv_ctx
+local call_check = 0
+
+cli_ctx = regress.getsslctx("TLS", false, false)
+regress.check(cli_ctx.addCustomExtension, "Custom extension support not available")
+local function c_add_ext(ssl, ext_type, context) -- luacheck: ignore 212
+ call_check = call_check + 1
+ return "from the client"
+end
+local function c_parse_ext(ssl, ext_type, context, data) -- luacheck: ignore 212
+ call_check = call_check + 2
+ assert(data == "from the server")
+ return true
+end
+cli_ctx:addCustomExtension(5000,
+ openssl_ctx.EXT_CLIENT_HELLO +
+ openssl_ctx.EXT_TLS1_2_SERVER_HELLO +
+ openssl_ctx.EXT_TLS1_3_SERVER_HELLO
+, c_add_ext, c_parse_ext)
+
+
+srv_ctx = regress.getsslctx("TLS", true)
+local function s_add_ext(ssl, ext_type, context) -- luacheck: ignore 212
+ call_check = call_check + 4
+ return "from the server"
+end
+local function s_parse_ext(ssl, ext_type, context, data) -- luacheck: ignore 212
+ call_check = call_check + 8
+ assert(data == "from the client")
+ return true
+end
+srv_ctx:addCustomExtension(5000,
+ openssl_ctx.EXT_CLIENT_HELLO +
+ openssl_ctx.EXT_TLS1_2_SERVER_HELLO +
+ openssl_ctx.EXT_TLS1_3_SERVER_HELLO
+, s_add_ext, s_parse_ext)
+
+
+local srv, cli = regress.check(cs.pair(cs.SOCK_STREAM))
+local main = regress.check(cqueues.new())
+main:wrap(function ()
+ regress.check(cli:starttls(cli_ctx))
+end)
+main:wrap(function ()
+ regress.check(srv:starttls(srv_ctx))
+end)
+regress.check(main:loop())
+
+regress.check(call_check == 15, "callback count doesn't match")
+regress.say "OK"