mirror of
https://github.com/brunoos/luasec.git
synced 2025-04-21 16:06:45 +02:00
Compare commits
175 Commits
luasec-0.6
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
4c06287052 | ||
|
5f4799d8cf | ||
|
5787d51bb8 | ||
|
a2b211f847 | ||
|
769ac528e2 | ||
|
0f0e07eb41 | ||
|
fddde111f7 | ||
|
6405645155 | ||
|
e01c6e63cd | ||
|
c297c5204c | ||
|
e42bc358e2 | ||
|
f72457bbf9 | ||
|
361813c0da | ||
|
e53caaad73 | ||
|
0e669f6c82 | ||
|
c3f12b8c4d | ||
|
38bb3edfb4 | ||
|
50431ed511 | ||
|
b321ba8fab | ||
|
6708ccc381 | ||
|
4f28db9f53 | ||
|
dd8ba1fc92 | ||
|
9b09c93249 | ||
|
0f793b73c0 | ||
|
7b60dc4794 | ||
|
4f6aec07f6 | ||
|
c87fe7d5ea | ||
|
842380caf6 | ||
|
b47bfff382 | ||
|
480aef1626 | ||
|
4cecbb2783 | ||
|
d9215ee00f | ||
|
03e03140cd | ||
|
8b3b2318d2 | ||
|
2c248947df | ||
|
f22b3ea609 | ||
|
c9539bca86 | ||
|
afb2d44b0e | ||
|
f9afada3d1 | ||
|
371abcf718 | ||
|
df27c62f4c | ||
|
09691fe782 | ||
|
3a71559e13 | ||
|
3f04fd7529 | ||
|
d7161ca026 | ||
|
65ee83275b | ||
|
ef14b27a2c | ||
|
316bea078c | ||
|
79bbc0bc3e | ||
|
8cba350f37 | ||
|
eedebb2477 | ||
|
c1e28e9132 | ||
|
cdcf5fdb30 | ||
|
bdbc67b188 | ||
|
359151144b | ||
|
d6b2fd7d35 | ||
|
d5df315617 | ||
|
34252fb10a | ||
|
711a98b760 | ||
|
4894c2f6a4 | ||
|
ae774258c5 | ||
|
de393417b7 | ||
|
22eadbd20e | ||
|
63e35c161f | ||
|
c6704919bd | ||
|
d7ccfad97f | ||
|
43feb51c5e | ||
|
860b2a8b5f | ||
|
caeaa5ffda | ||
|
9d84469912 | ||
|
87e51d99ea | ||
|
7898bd2043 | ||
|
c810df6839 | ||
|
1e2f342006 | ||
|
8ef33e33cf | ||
|
3490d8d1c0 | ||
|
86c8fa40c9 | ||
|
4903e2f2c1 | ||
|
2480572bdf | ||
|
c26513f4f7 | ||
|
f64e660de0 | ||
|
8722f83e8f | ||
|
a2dcfffcfa | ||
|
18fa0118be | ||
|
9f3a97e397 | ||
|
daf728fec2 | ||
|
041a37874b | ||
|
d6ba8d21da | ||
|
f8b2968e79 | ||
|
57f2f1363f | ||
|
1efa37087e | ||
|
1c9401ae54 | ||
|
ea8ccc3113 | ||
|
c0cb85d77f | ||
|
1c3bf23551 | ||
|
31237195a3 | ||
|
c72dc02ecb | ||
|
143ccf1323 | ||
|
5e2b27fa71 | ||
|
ff868e4a06 | ||
|
ef342a7cda | ||
|
569d12dc64 | ||
|
79c629956e | ||
|
81c38864d4 | ||
|
0775d5744f | ||
|
8bcabff0c1 | ||
|
3f38f0929c | ||
|
5ffe22e98e | ||
|
6359275c5f | ||
|
550777a9d6 | ||
|
4c5996a499 | ||
|
421c897dd3 | ||
|
2ecf239cfe | ||
|
113331fa0c | ||
|
8440bc3d59 | ||
|
5ece6049e5 | ||
|
9883782102 | ||
|
661d08e5f3 | ||
|
5514c4a06e | ||
|
f42c171d55 | ||
|
706e0f0281 | ||
|
d4ea2d12f3 | ||
|
dea60edf4f | ||
|
fdb2fa5f59 | ||
|
93e0e8cc64 | ||
|
d9d0cd620d | ||
|
953a363a59 | ||
|
28e247dbc5 | ||
|
89bdc6148c | ||
|
8212b89f1a | ||
|
879ba6d4f9 | ||
|
4d10a5a0c0 | ||
|
de63f21f63 | ||
|
fbbaa866c3 | ||
|
bd87aafaaf | ||
|
be3c6d67e0 | ||
|
2f562e1399 | ||
|
7934e58b4b | ||
|
3a8d6e71c4 | ||
|
3d170e9f9d | ||
|
ea6a65de84 | ||
|
0d01b53461 | ||
|
8762441cd2 | ||
|
60f02f7701 | ||
|
fe1fb0b350 | ||
|
db42a5084a | ||
|
0b99832ec7 | ||
|
fc757e1fd0 | ||
|
64f11f515d | ||
|
e90a264c93 | ||
|
5299803bef | ||
|
9c41eaf09a | ||
|
31b7a4744b | ||
|
d9e7c5d466 | ||
|
6b82fa6104 | ||
|
9f6d623ccb | ||
|
67a2133e7d | ||
|
622ef3d6a6 | ||
|
231563682a | ||
|
3ec117667d | ||
|
98f8872743 | ||
|
77b88e0b0d | ||
|
4889830d53 | ||
|
80a527d630 | ||
|
53db804b9d | ||
|
22e6652d88 | ||
|
6bb007b75f | ||
|
3cfdb878dd | ||
|
4101af103e | ||
|
9efa963e35 | ||
|
4aa9ec3b60 | ||
|
d45c03a1ad | ||
|
0f4eaf06e4 | ||
|
5a98bb6adb | ||
|
27fbd70424 |
143
CHANGELOG
143
CHANGELOG
@ -1,3 +1,143 @@
|
|||||||
|
--------------------------------------------------------------------------------
|
||||||
|
LuaSec 1.3.2
|
||||||
|
---------------
|
||||||
|
This version includes:
|
||||||
|
|
||||||
|
* Fix: place EAI_OVERFLOW inside macro, unbreak build on <10.7 (Sergey Fedorov)
|
||||||
|
* Fix: Expand workaround for zero errno to OpenSSL 3.0.x (Kim Alvefur)
|
||||||
|
* Fix: reset block timeout at send or receive (MartinDahlberg)
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
LuaSec 1.3.1
|
||||||
|
---------------
|
||||||
|
This version includes:
|
||||||
|
|
||||||
|
* Fix: check if PSK is available
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
LuaSec 1.3.0
|
||||||
|
---------------
|
||||||
|
This version includes:
|
||||||
|
|
||||||
|
* Add :getlocalchain() + :getlocalcertificate() to mirror the peer methods (@mwild1)
|
||||||
|
* Add Pre-Shared Key (PSK) support (@jclab-joseph)
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
LuaSec 1.2.0
|
||||||
|
---------------
|
||||||
|
This version includes:
|
||||||
|
|
||||||
|
* Add key material export method
|
||||||
|
* Backguard compat for openssl on providers, like LTS linuxes
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
LuaSec 1.1.0
|
||||||
|
---------------
|
||||||
|
This version includes:
|
||||||
|
|
||||||
|
* Fix missing DANE flag
|
||||||
|
* Remove unused parameter in https.lua
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
LuaSec 1.0.2
|
||||||
|
---------------
|
||||||
|
This version includes:
|
||||||
|
|
||||||
|
* Fix handle SSL_send SYSCALL error without errno
|
||||||
|
* Fix off by one in cert:validat(notafter)
|
||||||
|
* Fix meth_get_{sinagure => signature}_name function name
|
||||||
|
* Fix update the Lua state reference on the selected SSL context after SNI
|
||||||
|
* Fix ignore SSL_OP_BIT(n) macro and update option.c
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
LuaSec 1.0.1
|
||||||
|
---------------
|
||||||
|
This version includes:
|
||||||
|
|
||||||
|
|
||||||
|
* Fix luaL_buffinit() can use the stack and broke buffer_meth_receive()
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
LuaSec 1.0
|
||||||
|
---------------
|
||||||
|
This version includes:
|
||||||
|
|
||||||
|
|
||||||
|
* Add cert:getsignaturename()
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
LuaSec 0.9
|
||||||
|
---------------
|
||||||
|
This version includes:
|
||||||
|
|
||||||
|
|
||||||
|
* Add DNS-based Authentication of Named Entities (DANE) support
|
||||||
|
* Add __close() metamethod
|
||||||
|
* Fix deprecation warnings with OpenSSL 1.1
|
||||||
|
* Fix special case listing of TLS 1.3 EC curves
|
||||||
|
* Fix general_name leak in cert:extensions()
|
||||||
|
* Fix unexported 'ssl.config' table
|
||||||
|
* Replace $(LD) with $(CCLD) variable
|
||||||
|
* Remove multiple definitions of 'ssl_options' variable
|
||||||
|
* Use tag in git format: v0.9
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
LuaSec 0.8.2
|
||||||
|
---------------
|
||||||
|
This version includes:
|
||||||
|
|
||||||
|
* Fix unexported 'ssl.config' table (backported)
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
LuaSec 0.8.1
|
||||||
|
---------------
|
||||||
|
This version includes:
|
||||||
|
|
||||||
|
* Fix general_name leak in cert:extensions() (backported)
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
LuaSec 0.8
|
||||||
|
---------------
|
||||||
|
This version includes:
|
||||||
|
|
||||||
|
* Add support to ALPN
|
||||||
|
* Add support to TLS 1.3
|
||||||
|
* Add support to multiple certificates
|
||||||
|
* Add timeout to https module (https.TIMEOUT)
|
||||||
|
* Drop support to SSL 3.0
|
||||||
|
* Drop support to TLS 1.0 from https module
|
||||||
|
* Fix invalid reference to Lua state
|
||||||
|
* Fix memory leak when get certficate extensions
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
LuaSec 0.7.2
|
||||||
|
---------------
|
||||||
|
This version includes:
|
||||||
|
|
||||||
|
* Fix unexported 'ssl.config' table (backported)
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
LuaSec 0.7.1
|
||||||
|
---------------
|
||||||
|
This version includes:
|
||||||
|
|
||||||
|
* Fix general_name leak in cert:extensions() (backported)
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
LuaSec 0.7
|
||||||
|
---------------
|
||||||
|
LuaSec depends on OpenSSL, and integrates with LuaSocket to make it
|
||||||
|
easy to add secure connections to any Lua applications or scripts.
|
||||||
|
|
||||||
|
Documentation: https://github.com/brunoos/luasec/wiki
|
||||||
|
|
||||||
|
This version includes:
|
||||||
|
|
||||||
|
* Add support to OpenSSL 1.1.0
|
||||||
|
* Add support to elliptic curves list
|
||||||
|
* Add ssl.config that exports some OpenSSL information
|
||||||
|
* Add integration with luaossl
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
LuaSec 0.6
|
LuaSec 0.6
|
||||||
------------
|
------------
|
||||||
@ -35,7 +175,6 @@ This version includes:
|
|||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
LuaSec 0.5
|
LuaSec 0.5
|
||||||
------------
|
------------
|
||||||
|
|
||||||
LuaSec depends on OpenSSL, and integrates with LuaSocket to make it
|
LuaSec depends on OpenSSL, and integrates with LuaSocket to make it
|
||||||
easy to add secure connections to any Lua applications or scripts.
|
easy to add secure connections to any Lua applications or scripts.
|
||||||
|
|
||||||
@ -109,7 +248,7 @@ LuaSec 0.3
|
|||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
LuaSec 0.2.1
|
LuaSec 0.2.1
|
||||||
------------
|
------------
|
||||||
- 'key' and 'certificate' configurations become optional. (thanks René Rebe)
|
- 'key' and 'certificate' configurations become optional. (thanks René Rebe)
|
||||||
- Add '_VERSION' variable to module.
|
- Add '_VERSION' variable to module.
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
6
INSTALL
6
INSTALL
@ -1,14 +1,14 @@
|
|||||||
LuaSec 0.6
|
LuaSec 1.3.2
|
||||||
------------
|
------------
|
||||||
|
|
||||||
* OpenSSL options:
|
* OpenSSL options:
|
||||||
|
|
||||||
By default, LuaSec 0.6 includes options for OpenSSL 1.0.2f.
|
By default, this version includes options for OpenSSL 3.0.8
|
||||||
|
|
||||||
If you need to generate the options for a different version of OpenSSL:
|
If you need to generate the options for a different version of OpenSSL:
|
||||||
|
|
||||||
$ cd src
|
$ cd src
|
||||||
$ lua options.lua -g /usr/include/openssl/ssl.h > options.h
|
$ lua options.lua -g /usr/include/openssl/ssl.h > options.c
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
4
LICENSE
4
LICENSE
@ -1,5 +1,5 @@
|
|||||||
LuaSec 0.6 license
|
LuaSec 1.3.2 license
|
||||||
Copyright (C) 2006-2015 Bruno Silvestre, UFG
|
Copyright (C) 2006-2023 Bruno Silvestre, UFG
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
a copy of this software and associated documentation files (the
|
a copy of this software and associated documentation files (the
|
||||||
|
34
README.md
34
README.md
@ -1,36 +1,6 @@
|
|||||||
LuaSec 0.6
|
LuaSec 1.3.2
|
||||||
==========
|
===============
|
||||||
LuaSec depends on OpenSSL, and integrates with LuaSocket to make it
|
LuaSec depends on OpenSSL, and integrates with LuaSocket to make it
|
||||||
easy to add secure connections to any Lua applications or scripts.
|
easy to add secure connections to any Lua applications or scripts.
|
||||||
|
|
||||||
Documentation: https://github.com/brunoos/luasec/wiki
|
Documentation: https://github.com/brunoos/luasec/wiki
|
||||||
|
|
||||||
This version includes:
|
|
||||||
|
|
||||||
* Lua 5.2 and 5.3 compatibility
|
|
||||||
|
|
||||||
* Context module:
|
|
||||||
- Add ctx:checkkey()
|
|
||||||
|
|
||||||
* SSL module:
|
|
||||||
- Add conn:sni() and conn:getsniname()
|
|
||||||
|
|
||||||
* Context options:
|
|
||||||
- Add "any" protocol ("sslv23" is deprecated)
|
|
||||||
|
|
||||||
* HTTPS module:
|
|
||||||
- Using "any" protocol without SSLv2/SSLv3, by default
|
|
||||||
|
|
||||||
* X509 module:
|
|
||||||
- Human readable IP address
|
|
||||||
- Add cert:issued()
|
|
||||||
- Add cert:pubkey()
|
|
||||||
|
|
||||||
* Some bug fixes
|
|
||||||
|
|
||||||
|
|
||||||
********************************************************************************
|
|
||||||
|
|
||||||
PS: 10th anniversary! Thanks to everyone who collaborate with LuaSec.
|
|
||||||
|
|
||||||
********************************************************************************
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package = "LuaSec"
|
package = "LuaSec"
|
||||||
version = "0.6-1"
|
version = "1.3.2-1"
|
||||||
source = {
|
source = {
|
||||||
url = "git://github.com/brunoos/luasec.git",
|
url = "git+https://github.com/brunoos/luasec",
|
||||||
tag = "luasec-0.6"
|
tag = "v1.3.2",
|
||||||
}
|
}
|
||||||
description = {
|
description = {
|
||||||
summary = "A binding for OpenSSL library to provide TLS/SSL communication over LuaSocket.",
|
summary = "A binding for OpenSSL library to provide TLS/SSL communication over LuaSocket.",
|
||||||
@ -45,6 +45,9 @@ build = {
|
|||||||
},
|
},
|
||||||
modules = {
|
modules = {
|
||||||
ssl = {
|
ssl = {
|
||||||
|
defines = {
|
||||||
|
"WITH_LUASOCKET", "LUASOCKET_DEBUG",
|
||||||
|
},
|
||||||
incdirs = {
|
incdirs = {
|
||||||
"$(OPENSSL_INCDIR)", "src/", "src/luasocket",
|
"$(OPENSSL_INCDIR)", "src/", "src/luasocket",
|
||||||
},
|
},
|
||||||
@ -55,6 +58,7 @@ build = {
|
|||||||
"ssl", "crypto"
|
"ssl", "crypto"
|
||||||
},
|
},
|
||||||
sources = {
|
sources = {
|
||||||
|
"src/options.c", "src/config.c", "src/ec.c",
|
||||||
"src/x509.c", "src/context.c", "src/ssl.c",
|
"src/x509.c", "src/context.c", "src/ssl.c",
|
||||||
"src/luasocket/buffer.c", "src/luasocket/io.c",
|
"src/luasocket/buffer.c", "src/luasocket/io.c",
|
||||||
"src/luasocket/timeout.c", "src/luasocket/usocket.c"
|
"src/luasocket/timeout.c", "src/luasocket/usocket.c"
|
||||||
@ -75,6 +79,7 @@ build = {
|
|||||||
ssl = {
|
ssl = {
|
||||||
defines = {
|
defines = {
|
||||||
"WIN32", "NDEBUG", "_WINDOWS", "_USRDLL", "LSEC_EXPORTS", "BUFFER_DEBUG", "LSEC_API=__declspec(dllexport)",
|
"WIN32", "NDEBUG", "_WINDOWS", "_USRDLL", "LSEC_EXPORTS", "BUFFER_DEBUG", "LSEC_API=__declspec(dllexport)",
|
||||||
|
"WITH_LUASOCKET", "LUASOCKET_DEBUG",
|
||||||
"LUASEC_INET_NTOP", "WINVER=0x0501", "_WIN32_WINNT=0x0501", "NTDDI_VERSION=0x05010300"
|
"LUASEC_INET_NTOP", "WINVER=0x0501", "_WIN32_WINNT=0x0501", "NTDDI_VERSION=0x05010300"
|
||||||
},
|
},
|
||||||
libdirs = {
|
libdirs = {
|
||||||
@ -82,32 +87,18 @@ build = {
|
|||||||
"$(OPENSSL_BINDIR)",
|
"$(OPENSSL_BINDIR)",
|
||||||
},
|
},
|
||||||
libraries = {
|
libraries = {
|
||||||
"libeay32", "ssleay32", "ws2_32"
|
"libssl", "libcrypto", "ws2_32"
|
||||||
},
|
},
|
||||||
incdirs = {
|
incdirs = {
|
||||||
"$(OPENSSL_INCDIR)", "src/", "src/luasocket"
|
"$(OPENSSL_INCDIR)", "src/", "src/luasocket"
|
||||||
},
|
},
|
||||||
sources = {
|
sources = {
|
||||||
|
"src/options.c", "src/config.c", "src/ec.c",
|
||||||
"src/x509.c", "src/context.c", "src/ssl.c",
|
"src/x509.c", "src/context.c", "src/ssl.c",
|
||||||
"src/luasocket/buffer.c", "src/luasocket/io.c",
|
"src/luasocket/buffer.c", "src/luasocket/io.c",
|
||||||
"src/luasocket/timeout.c", "src/luasocket/wsocket.c"
|
"src/luasocket/timeout.c", "src/luasocket/wsocket.c"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
patches = {
|
|
||||||
["luarocks_vs_compiler.patch"] = [[
|
|
||||||
--- a/src/ssl.c.orig
|
|
||||||
+++ b/src/ssl.c
|
|
||||||
@@ -844,3 +844,8 @@ LSEC_API int luaopen_ssl_core(lua_State *L)
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
+
|
|
||||||
+#if defined(_MSC_VER)
|
|
||||||
+/* Empty implementation to allow building with LuaRocks and MS compilers */
|
|
||||||
+LSEC_API int luaopen_ssl(lua_State *L) { return 0; }
|
|
||||||
+#endif
|
|
||||||
]]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
BIN
luasec.suo
BIN
luasec.suo
Binary file not shown.
253
luasec.vcproj
253
luasec.vcproj
@ -1,253 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="Windows-1252"?>
|
|
||||||
<VisualStudioProject
|
|
||||||
ProjectType="Visual C++"
|
|
||||||
Version="9,00"
|
|
||||||
Name="luasec"
|
|
||||||
ProjectGUID="{A629932F-8819-4C0B-8835-CBF1FEED6376}"
|
|
||||||
Keyword="Win32Proj"
|
|
||||||
TargetFrameworkVersion="131072"
|
|
||||||
>
|
|
||||||
<Platforms>
|
|
||||||
<Platform
|
|
||||||
Name="Win32"
|
|
||||||
/>
|
|
||||||
</Platforms>
|
|
||||||
<ToolFiles>
|
|
||||||
</ToolFiles>
|
|
||||||
<Configurations>
|
|
||||||
<Configuration
|
|
||||||
Name="Debug|Win32"
|
|
||||||
OutputDirectory="Debug"
|
|
||||||
IntermediateDirectory="Debug"
|
|
||||||
ConfigurationType="2"
|
|
||||||
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
|
|
||||||
CharacterSet="2"
|
|
||||||
>
|
|
||||||
<Tool
|
|
||||||
Name="VCPreBuildEventTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCCustomBuildTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCXMLDataGeneratorTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCWebServiceProxyGeneratorTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCMIDLTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
Optimization="0"
|
|
||||||
AdditionalIncludeDirectories="C:\devel\openssl\include;C:\devel\lua-dll9\include"
|
|
||||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;LUASEC_EXPORTS"
|
|
||||||
MinimalRebuild="true"
|
|
||||||
BasicRuntimeChecks="3"
|
|
||||||
RuntimeLibrary="3"
|
|
||||||
UsePrecompiledHeader="0"
|
|
||||||
WarningLevel="3"
|
|
||||||
DebugInformationFormat="4"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCManagedResourceCompilerTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCResourceCompilerTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCPreLinkEventTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCLinkerTool"
|
|
||||||
AdditionalDependencies="ws2_32.lib libeay32MDd.lib ssleay32MDd.lib lua5.1.lib"
|
|
||||||
OutputFile="$(OutDir)/ssl.dll"
|
|
||||||
LinkIncremental="2"
|
|
||||||
AdditionalLibraryDirectories="C:\devel\openssl\lib\VC;C:\devel\lua-dll9"
|
|
||||||
GenerateDebugInformation="true"
|
|
||||||
ProgramDatabaseFile="$(OutDir)/luasec.pdb"
|
|
||||||
SubSystem="2"
|
|
||||||
RandomizedBaseAddress="1"
|
|
||||||
DataExecutionPrevention="0"
|
|
||||||
ImportLibrary="$(OutDir)/ssl.lib"
|
|
||||||
TargetMachine="1"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCALinkTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCManifestTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCXDCMakeTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCBscMakeTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCFxCopTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCAppVerifierTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCPostBuildEventTool"
|
|
||||||
/>
|
|
||||||
</Configuration>
|
|
||||||
<Configuration
|
|
||||||
Name="Release|Win32"
|
|
||||||
OutputDirectory="Release"
|
|
||||||
IntermediateDirectory="Release"
|
|
||||||
ConfigurationType="2"
|
|
||||||
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
|
|
||||||
CharacterSet="2"
|
|
||||||
>
|
|
||||||
<Tool
|
|
||||||
Name="VCPreBuildEventTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCCustomBuildTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCXMLDataGeneratorTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCWebServiceProxyGeneratorTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCMIDLTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
AdditionalIncludeDirectories="C:\devel\openssl\include;C:\devel\lua-dll9\include"
|
|
||||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;BUFFER_DEBUG"
|
|
||||||
RuntimeLibrary="2"
|
|
||||||
UsePrecompiledHeader="0"
|
|
||||||
WarningLevel="3"
|
|
||||||
DebugInformationFormat="3"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCManagedResourceCompilerTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCResourceCompilerTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCPreLinkEventTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCLinkerTool"
|
|
||||||
AdditionalDependencies="ws2_32.lib libeay32MD.lib ssleay32MD.lib lua5.1.lib"
|
|
||||||
OutputFile="$(OutDir)/ssl.dll"
|
|
||||||
LinkIncremental="1"
|
|
||||||
AdditionalLibraryDirectories="C:\devel\openssl\lib\VC;C:\devel\lua-dll9\lib"
|
|
||||||
GenerateDebugInformation="true"
|
|
||||||
SubSystem="2"
|
|
||||||
OptimizeReferences="2"
|
|
||||||
EnableCOMDATFolding="2"
|
|
||||||
RandomizedBaseAddress="1"
|
|
||||||
DataExecutionPrevention="0"
|
|
||||||
ImportLibrary="$(OutDir)/ssl.lib"
|
|
||||||
TargetMachine="1"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCALinkTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCManifestTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCXDCMakeTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCBscMakeTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCFxCopTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCAppVerifierTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCPostBuildEventTool"
|
|
||||||
/>
|
|
||||||
</Configuration>
|
|
||||||
</Configurations>
|
|
||||||
<References>
|
|
||||||
</References>
|
|
||||||
<Files>
|
|
||||||
<Filter
|
|
||||||
Name="Source Files"
|
|
||||||
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
|
||||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
|
||||||
>
|
|
||||||
<File
|
|
||||||
RelativePath=".\src\buffer.c"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\src\context.c"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\src\io.c"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\src\ssl.c"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\src\timeout.c"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\src\wsocket.c"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
</Filter>
|
|
||||||
<Filter
|
|
||||||
Name="Header Files"
|
|
||||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
|
||||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
|
||||||
>
|
|
||||||
<File
|
|
||||||
RelativePath=".\src\buffer.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\src\context.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\src\io.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\src\socket.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\src\ssl.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\src\timeout.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\src\wsocket.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
</Filter>
|
|
||||||
<Filter
|
|
||||||
Name="Resource Files"
|
|
||||||
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
|
|
||||||
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
|
|
||||||
>
|
|
||||||
</Filter>
|
|
||||||
</Files>
|
|
||||||
<Globals>
|
|
||||||
</Globals>
|
|
||||||
</VisualStudioProject>
|
|
@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<ItemGroup Label="ProjectConfigurations">
|
<ItemGroup Label="ProjectConfigurations">
|
||||||
<ProjectConfiguration Include="Debug|Win32">
|
<ProjectConfiguration Include="Debug|Win32">
|
||||||
<Configuration>Debug</Configuration>
|
<Configuration>Debug</Configuration>
|
||||||
@ -18,10 +18,12 @@
|
|||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
|
<PlatformToolset>v140</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
|
<PlatformToolset>v140</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
<ImportGroup Label="ExtensionSettings">
|
<ImportGroup Label="ExtensionSettings">
|
||||||
@ -59,7 +61,7 @@
|
|||||||
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
|
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<AdditionalDependencies>ws2_32.lib;libeay32MDd.lib;ssleay32MDd.lib;lua5.1.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>ws2_32.lib;libssl.lib;libcrypto.lib;lua5.1.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
<OutputFile>$(OutDir)ssl.dll</OutputFile>
|
<OutputFile>$(OutDir)ssl.dll</OutputFile>
|
||||||
<AdditionalLibraryDirectories>C:\devel\openssl\lib\VC;C:\devel\lua-dll9;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
<AdditionalLibraryDirectories>C:\devel\openssl\lib\VC;C:\devel\lua-dll9;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
@ -74,7 +76,7 @@
|
|||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
<AdditionalIncludeDirectories>C:\devel\openssl\include;C:\devel\lua5.2\include;.\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>C:\devel\openssl-1.1.0\include;C:\devel\lua-5.1\include;.\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
<PreprocessorDefinitions>WIN32;_WIN32;NDEBUG;_WINDOWS;_USRDLL;LUASOCKET_DEBUG;WITH_LUASOCKET;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;_WIN32;NDEBUG;_WINDOWS;_USRDLL;LUASOCKET_DEBUG;WITH_LUASOCKET;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||||
<PrecompiledHeader>
|
<PrecompiledHeader>
|
||||||
@ -83,9 +85,9 @@
|
|||||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<AdditionalDependencies>ws2_32.lib;libeay32MD.lib;ssleay32MD.lib;lua52.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>ws2_32.lib;libssl.lib;libcrypto.lib;lua5.1.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
|
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
|
||||||
<AdditionalLibraryDirectories>C:\devel\openssl\lib\VC;C:\devel\lua5.2\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
<AdditionalLibraryDirectories>C:\devel\openssl-1.1.0\lib\VC;C:\devel\lua-5.1\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
<OptimizeReferences>true</OptimizeReferences>
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
@ -98,15 +100,19 @@
|
|||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClCompile Include="src\config.c" />
|
||||||
<ClCompile Include="src\context.c" />
|
<ClCompile Include="src\context.c" />
|
||||||
|
<ClCompile Include="src\ec.c" />
|
||||||
<ClCompile Include="src\luasocket\buffer.c" />
|
<ClCompile Include="src\luasocket\buffer.c" />
|
||||||
<ClCompile Include="src\luasocket\io.c" />
|
<ClCompile Include="src\luasocket\io.c" />
|
||||||
<ClCompile Include="src\luasocket\timeout.c" />
|
<ClCompile Include="src\luasocket\timeout.c" />
|
||||||
<ClCompile Include="src\luasocket\wsocket.c" />
|
<ClCompile Include="src\luasocket\wsocket.c" />
|
||||||
|
<ClCompile Include="src\options.c" />
|
||||||
<ClCompile Include="src\ssl.c" />
|
<ClCompile Include="src\ssl.c" />
|
||||||
<ClCompile Include="src\x509.c" />
|
<ClCompile Include="src\x509.c" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClInclude Include="src\compat.h" />
|
||||||
<ClInclude Include="src\config.h" />
|
<ClInclude Include="src\config.h" />
|
||||||
<ClInclude Include="src\context.h" />
|
<ClInclude Include="src\context.h" />
|
||||||
<ClInclude Include="src\ec.h" />
|
<ClInclude Include="src\ec.h" />
|
||||||
|
@ -1,75 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<ItemGroup>
|
|
||||||
<Filter Include="Source Files">
|
|
||||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
|
||||||
<Extensions>cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
|
||||||
</Filter>
|
|
||||||
<Filter Include="Header Files">
|
|
||||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
|
||||||
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
|
||||||
</Filter>
|
|
||||||
<Filter Include="Resource Files">
|
|
||||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
|
||||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx</Extensions>
|
|
||||||
</Filter>
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<ClCompile Include="src\x509.c">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="src\context.c">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="src\ssl.c">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="src\luasocket\wsocket.c">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="src\luasocket\buffer.c">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="src\luasocket\io.c">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="src\luasocket\timeout.c">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<ClInclude Include="src\x509.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="src\config.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="src\context.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="src\ec.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="src\options.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="src\ssl.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="src\luasocket\wsocket.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="src\luasocket\buffer.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="src\luasocket\io.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="src\luasocket\socket.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="src\luasocket\timeout.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
</ItemGroup>
|
|
||||||
</Project>
|
|
@ -1,5 +1,8 @@
|
|||||||
Directories:
|
Directories:
|
||||||
------------
|
------------
|
||||||
|
* alpn
|
||||||
|
Test ALPN (Application-Layer Protocol Negotiation) support.
|
||||||
|
|
||||||
* certs
|
* certs
|
||||||
Contains scripts to generate the certificates used by the examples.
|
Contains scripts to generate the certificates used by the examples.
|
||||||
Generate Root CA 'A' and 'B' first, then the servers and clients.
|
Generate Root CA 'A' and 'B' first, then the servers and clients.
|
||||||
@ -7,6 +10,9 @@ Directories:
|
|||||||
* chain
|
* chain
|
||||||
Example of certificate chain in handshake.
|
Example of certificate chain in handshake.
|
||||||
|
|
||||||
|
* curve-negotiation
|
||||||
|
Elliptic curve negotiation.
|
||||||
|
|
||||||
* dhparam
|
* dhparam
|
||||||
DH parameters for handshake.
|
DH parameters for handshake.
|
||||||
|
|
||||||
@ -17,7 +23,7 @@ Directories:
|
|||||||
Elliptic curve cipher.
|
Elliptic curve cipher.
|
||||||
|
|
||||||
* info
|
* info
|
||||||
Informations about the connection.
|
Information about the connection.
|
||||||
|
|
||||||
* key
|
* key
|
||||||
Test encrypted private key.
|
Test encrypted private key.
|
||||||
@ -30,20 +36,32 @@ Directories:
|
|||||||
Same of above, but the connection is not explicit closed, the gabage
|
Same of above, but the connection is not explicit closed, the gabage
|
||||||
collector is encharge of that.
|
collector is encharge of that.
|
||||||
|
|
||||||
|
* luaossl
|
||||||
|
Integration with luaossl.
|
||||||
|
|
||||||
|
* multicert
|
||||||
|
Support to multiple certificate for dual RSA/ECDSA.
|
||||||
|
|
||||||
* oneshot
|
* oneshot
|
||||||
A simple connection example.
|
A simple connection example.
|
||||||
|
|
||||||
|
* psk
|
||||||
|
PSK(Pre Shared Key) support.
|
||||||
|
|
||||||
|
* sni
|
||||||
|
Support to SNI (Server Name Indication).
|
||||||
|
|
||||||
* verification
|
* verification
|
||||||
Retrieve the certificate verification errors from the handshake.
|
Retrieve the certificate verification errors from the handshake.
|
||||||
|
|
||||||
* verify
|
* verify
|
||||||
Ignore handshake errors and proceed.
|
Ignore handshake errors and proceed.
|
||||||
|
|
||||||
|
* want
|
||||||
|
Test want() method.
|
||||||
|
|
||||||
* wantread
|
* wantread
|
||||||
Test timeout in handshake() and receive().
|
Test timeout in handshake() and receive().
|
||||||
|
|
||||||
* wantwrite
|
* wantwrite
|
||||||
Test timeout in send().
|
Test timeout in send().
|
||||||
|
|
||||||
* want
|
|
||||||
Test want() method.
|
|
||||||
|
27
samples/alpn/client.lua
Normal file
27
samples/alpn/client.lua
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
--
|
||||||
|
-- Public domain
|
||||||
|
--
|
||||||
|
local socket = require("socket")
|
||||||
|
local ssl = require("ssl")
|
||||||
|
|
||||||
|
local params = {
|
||||||
|
mode = "client",
|
||||||
|
protocol = "tlsv1_2",
|
||||||
|
key = "../certs/clientAkey.pem",
|
||||||
|
certificate = "../certs/clientA.pem",
|
||||||
|
cafile = "../certs/rootA.pem",
|
||||||
|
verify = {"peer", "fail_if_no_peer_cert"},
|
||||||
|
options = "all",
|
||||||
|
--alpn = {"foo","bar","baz"}
|
||||||
|
alpn = "foo"
|
||||||
|
}
|
||||||
|
|
||||||
|
local peer = socket.tcp()
|
||||||
|
peer:connect("127.0.0.1", 8888)
|
||||||
|
|
||||||
|
peer = assert( ssl.wrap(peer, params) )
|
||||||
|
assert(peer:dohandshake())
|
||||||
|
|
||||||
|
print("ALPN", peer:getalpn())
|
||||||
|
|
||||||
|
peer:close()
|
77
samples/alpn/server.lua
Normal file
77
samples/alpn/server.lua
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
--
|
||||||
|
-- Public domain
|
||||||
|
--
|
||||||
|
local socket = require("socket")
|
||||||
|
local ssl = require("ssl")
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Callback that selects one protocol from client's list.
|
||||||
|
--
|
||||||
|
local function alpncb01(protocols)
|
||||||
|
print("--- ALPN protocols from client")
|
||||||
|
for k, v in ipairs(protocols) do
|
||||||
|
print(k, v)
|
||||||
|
end
|
||||||
|
print("--- Selecting:", protocols[1])
|
||||||
|
return protocols[1]
|
||||||
|
end
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Callback that returns a fixed list, ignoring the client's list.
|
||||||
|
--
|
||||||
|
local function alpncb02(protocols)
|
||||||
|
print("--- ALPN protocols from client")
|
||||||
|
for k, v in ipairs(protocols) do
|
||||||
|
print(k, v)
|
||||||
|
end
|
||||||
|
print("--- Returning a fixed list")
|
||||||
|
return {"bar", "foo"}
|
||||||
|
end
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Callback that generates a list as it whishes.
|
||||||
|
--
|
||||||
|
local function alpncb03(protocols)
|
||||||
|
local resp = {}
|
||||||
|
print("--- ALPN protocols from client")
|
||||||
|
for k, v in ipairs(protocols) do
|
||||||
|
print(k, v)
|
||||||
|
if k%2 ~= 0 then resp[#resp+1] = v end
|
||||||
|
end
|
||||||
|
print("--- Returning an odd list")
|
||||||
|
return resp
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local params = {
|
||||||
|
mode = "server",
|
||||||
|
protocol = "any",
|
||||||
|
key = "../certs/serverAkey.pem",
|
||||||
|
certificate = "../certs/serverA.pem",
|
||||||
|
cafile = "../certs/rootA.pem",
|
||||||
|
verify = {"peer", "fail_if_no_peer_cert"},
|
||||||
|
options = "all",
|
||||||
|
--alpn = alpncb01,
|
||||||
|
--alpn = alpncb02,
|
||||||
|
--alpn = alpncb03,
|
||||||
|
alpn = {"bar", "baz", "foo"},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
-- [[ SSL context
|
||||||
|
local ctx = assert(ssl.newcontext(params))
|
||||||
|
--]]
|
||||||
|
|
||||||
|
local server = socket.tcp()
|
||||||
|
server:setoption('reuseaddr', true)
|
||||||
|
assert( server:bind("127.0.0.1", 8888) )
|
||||||
|
server:listen()
|
||||||
|
|
||||||
|
local peer = server:accept()
|
||||||
|
peer = assert( ssl.wrap(peer, ctx) )
|
||||||
|
assert( peer:dohandshake() )
|
||||||
|
|
||||||
|
print("ALPN", peer:getalpn())
|
||||||
|
|
||||||
|
peer:close()
|
||||||
|
server:close()
|
7
samples/certs/all.sh
Executable file
7
samples/certs/all.sh
Executable file
@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
./rootA.sh
|
||||||
|
./rootB.sh
|
||||||
|
./clientA.sh
|
||||||
|
./clientB.sh
|
||||||
|
./serverA.sh
|
||||||
|
./serverB.sh
|
@ -50,7 +50,7 @@ crl = $dir/crl.pem # The current CRL
|
|||||||
private_key = $dir/private/cakey.pem # The private key
|
private_key = $dir/private/cakey.pem # The private key
|
||||||
RANDFILE = $dir/private/.rand # private random number file
|
RANDFILE = $dir/private/.rand # private random number file
|
||||||
|
|
||||||
x509_extensions = usr_cert # The extentions to add to the cert
|
x509_extensions = usr_cert # The extensions to add to the cert
|
||||||
|
|
||||||
# Comment out the following two lines for the "traditional"
|
# Comment out the following two lines for the "traditional"
|
||||||
# (and highly broken) format.
|
# (and highly broken) format.
|
||||||
@ -102,7 +102,7 @@ default_bits = 1024
|
|||||||
default_keyfile = privkey.pem
|
default_keyfile = privkey.pem
|
||||||
distinguished_name = req_distinguished_name
|
distinguished_name = req_distinguished_name
|
||||||
attributes = req_attributes
|
attributes = req_attributes
|
||||||
x509_extensions = v3_ca # The extentions to add to the self signed cert
|
x509_extensions = v3_ca # The extensions to add to the self signed cert
|
||||||
|
|
||||||
# Passwords for private keys if not present they will be prompted for
|
# Passwords for private keys if not present they will be prompted for
|
||||||
# input_password = secret
|
# input_password = secret
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
openssl req -newkey rsa:1024 -sha1 -keyout clientAkey.pem -out clientAreq.pem \
|
openssl req -newkey rsa:2048 -sha256 -keyout clientAkey.pem -out clientAreq.pem \
|
||||||
-nodes -config ./clientA.cnf -days 365 -batch
|
-nodes -config ./clientA.cnf -days 365 -batch
|
||||||
|
|
||||||
openssl x509 -req -in clientAreq.pem -sha1 -extfile ./clientA.cnf \
|
openssl x509 -req -in clientAreq.pem -sha256 -extfile ./clientA.cnf \
|
||||||
-extensions usr_cert -CA rootA.pem -CAkey rootAkey.pem -CAcreateserial \
|
-extensions usr_cert -CA rootA.pem -CAkey rootAkey.pem -CAcreateserial \
|
||||||
-out clientAcert.pem -days 365
|
-out clientAcert.pem -days 365
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ crl = $dir/crl.pem # The current CRL
|
|||||||
private_key = $dir/private/cakey.pem # The private key
|
private_key = $dir/private/cakey.pem # The private key
|
||||||
RANDFILE = $dir/private/.rand # private random number file
|
RANDFILE = $dir/private/.rand # private random number file
|
||||||
|
|
||||||
x509_extensions = usr_cert # The extentions to add to the cert
|
x509_extensions = usr_cert # The extensions to add to the cert
|
||||||
|
|
||||||
# Comment out the following two lines for the "traditional"
|
# Comment out the following two lines for the "traditional"
|
||||||
# (and highly broken) format.
|
# (and highly broken) format.
|
||||||
@ -102,7 +102,7 @@ default_bits = 1024
|
|||||||
default_keyfile = privkey.pem
|
default_keyfile = privkey.pem
|
||||||
distinguished_name = req_distinguished_name
|
distinguished_name = req_distinguished_name
|
||||||
attributes = req_attributes
|
attributes = req_attributes
|
||||||
x509_extensions = v3_ca # The extentions to add to the self signed cert
|
x509_extensions = v3_ca # The extensions to add to the self signed cert
|
||||||
|
|
||||||
# Passwords for private keys if not present they will be prompted for
|
# Passwords for private keys if not present they will be prompted for
|
||||||
# input_password = secret
|
# input_password = secret
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
openssl req -newkey rsa:1024 -sha1 -keyout clientBkey.pem -out clientBreq.pem \
|
openssl req -newkey rsa:2048 -sha256 -keyout clientBkey.pem -out clientBreq.pem \
|
||||||
-nodes -config ./clientB.cnf -days 365 -batch
|
-nodes -config ./clientB.cnf -days 365 -batch
|
||||||
|
|
||||||
openssl x509 -req -in clientBreq.pem -sha1 -extfile ./clientB.cnf \
|
openssl x509 -req -in clientBreq.pem -sha256 -extfile ./clientB.cnf \
|
||||||
-extensions usr_cert -CA rootB.pem -CAkey rootBkey.pem -CAcreateserial \
|
-extensions usr_cert -CA rootB.pem -CAkey rootBkey.pem -CAcreateserial \
|
||||||
-out clientBcert.pem -days 365
|
-out clientBcert.pem -days 365
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ crl = $dir/crl.pem # The current CRL
|
|||||||
private_key = $dir/private/cakey.pem # The private key
|
private_key = $dir/private/cakey.pem # The private key
|
||||||
RANDFILE = $dir/private/.rand # private random number file
|
RANDFILE = $dir/private/.rand # private random number file
|
||||||
|
|
||||||
x509_extensions = usr_cert # The extentions to add to the cert
|
x509_extensions = usr_cert # The extensions to add to the cert
|
||||||
|
|
||||||
# Comment out the following two lines for the "traditional"
|
# Comment out the following two lines for the "traditional"
|
||||||
# (and highly broken) format.
|
# (and highly broken) format.
|
||||||
@ -102,7 +102,7 @@ default_bits = 1024
|
|||||||
default_keyfile = privkey.pem
|
default_keyfile = privkey.pem
|
||||||
distinguished_name = req_distinguished_name
|
distinguished_name = req_distinguished_name
|
||||||
attributes = req_attributes
|
attributes = req_attributes
|
||||||
x509_extensions = v3_ca # The extentions to add to the self signed cert
|
x509_extensions = v3_ca # The extensions to add to the self signed cert
|
||||||
|
|
||||||
# Passwords for private keys if not present they will be prompted for
|
# Passwords for private keys if not present they will be prompted for
|
||||||
# input_password = secret
|
# input_password = secret
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
openssl req -newkey rsa:1024 -sha1 -keyout rootAkey.pem -out rootAreq.pem -nodes -config ./rootA.cnf -days 365 -batch
|
openssl req -newkey rsa:2048 -sha256 -keyout rootAkey.pem -out rootAreq.pem -nodes -config ./rootA.cnf -days 365 -batch
|
||||||
|
|
||||||
openssl x509 -req -in rootAreq.pem -sha1 -extfile ./rootA.cnf -extensions v3_ca -signkey rootAkey.pem -out rootA.pem -days 365
|
openssl x509 -req -in rootAreq.pem -sha256 -extfile ./rootA.cnf -extensions v3_ca -signkey rootAkey.pem -out rootA.pem -days 365
|
||||||
|
|
||||||
openssl x509 -subject -issuer -noout -in rootA.pem
|
openssl x509 -subject -issuer -noout -in rootA.pem
|
||||||
|
@ -50,7 +50,7 @@ crl = $dir/crl.pem # The current CRL
|
|||||||
private_key = $dir/private/cakey.pem # The private key
|
private_key = $dir/private/cakey.pem # The private key
|
||||||
RANDFILE = $dir/private/.rand # private random number file
|
RANDFILE = $dir/private/.rand # private random number file
|
||||||
|
|
||||||
x509_extensions = usr_cert # The extentions to add to the cert
|
x509_extensions = usr_cert # The extensions to add to the cert
|
||||||
|
|
||||||
# Comment out the following two lines for the "traditional"
|
# Comment out the following two lines for the "traditional"
|
||||||
# (and highly broken) format.
|
# (and highly broken) format.
|
||||||
@ -102,7 +102,7 @@ default_bits = 1024
|
|||||||
default_keyfile = privkey.pem
|
default_keyfile = privkey.pem
|
||||||
distinguished_name = req_distinguished_name
|
distinguished_name = req_distinguished_name
|
||||||
attributes = req_attributes
|
attributes = req_attributes
|
||||||
x509_extensions = v3_ca # The extentions to add to the self signed cert
|
x509_extensions = v3_ca # The extensions to add to the self signed cert
|
||||||
|
|
||||||
# Passwords for private keys if not present they will be prompted for
|
# Passwords for private keys if not present they will be prompted for
|
||||||
# input_password = secret
|
# input_password = secret
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
openssl req -newkey rsa:1024 -sha1 -keyout rootBkey.pem -out rootBreq.pem -nodes -config ./rootB.cnf -days 365 -batch
|
openssl req -newkey rsa:2048 -sha256 -keyout rootBkey.pem -out rootBreq.pem -nodes -config ./rootB.cnf -days 365 -batch
|
||||||
|
|
||||||
openssl x509 -req -in rootBreq.pem -sha1 -extfile ./rootB.cnf -extensions v3_ca -signkey rootBkey.pem -out rootB.pem -days 365
|
openssl x509 -req -in rootBreq.pem -sha256 -extfile ./rootB.cnf -extensions v3_ca -signkey rootBkey.pem -out rootB.pem -days 365
|
||||||
|
|
||||||
openssl x509 -subject -issuer -noout -in rootB.pem
|
openssl x509 -subject -issuer -noout -in rootB.pem
|
||||||
|
@ -50,7 +50,7 @@ crl = $dir/crl.pem # The current CRL
|
|||||||
private_key = $dir/private/cakey.pem # The private key
|
private_key = $dir/private/cakey.pem # The private key
|
||||||
RANDFILE = $dir/private/.rand # private random number file
|
RANDFILE = $dir/private/.rand # private random number file
|
||||||
|
|
||||||
x509_extensions = usr_cert # The extentions to add to the cert
|
x509_extensions = usr_cert # The extensions to add to the cert
|
||||||
|
|
||||||
# Comment out the following two lines for the "traditional"
|
# Comment out the following two lines for the "traditional"
|
||||||
# (and highly broken) format.
|
# (and highly broken) format.
|
||||||
@ -102,7 +102,7 @@ default_bits = 1024
|
|||||||
default_keyfile = privkey.pem
|
default_keyfile = privkey.pem
|
||||||
distinguished_name = req_distinguished_name
|
distinguished_name = req_distinguished_name
|
||||||
attributes = req_attributes
|
attributes = req_attributes
|
||||||
x509_extensions = v3_ca # The extentions to add to the self signed cert
|
x509_extensions = v3_ca # The extensions to add to the self signed cert
|
||||||
|
|
||||||
# Passwords for private keys if not present they will be prompted for
|
# Passwords for private keys if not present they will be prompted for
|
||||||
# input_password = secret
|
# input_password = secret
|
||||||
@ -118,7 +118,7 @@ x509_extensions = v3_ca # The extentions to add to the self signed cert
|
|||||||
# so use this option with caution!
|
# so use this option with caution!
|
||||||
string_mask = nombstr
|
string_mask = nombstr
|
||||||
|
|
||||||
# req_extensions = v3_req # The extensions to add to a certificate request
|
# req_extensions = v3_ext # The extensions to add to a certificate request
|
||||||
|
|
||||||
[ req_distinguished_name ]
|
[ req_distinguished_name ]
|
||||||
countryName = Country Name (2 letter code)
|
countryName = Country Name (2 letter code)
|
||||||
@ -198,7 +198,7 @@ authorityKeyIdentifier=keyid,issuer
|
|||||||
# subjectAltName=email:copy
|
# subjectAltName=email:copy
|
||||||
# An alternative to produce certificates that aren't
|
# An alternative to produce certificates that aren't
|
||||||
# deprecated according to PKIX.
|
# deprecated according to PKIX.
|
||||||
# subjectAltName=email:move
|
subjectAltName=DNS:foo.bar.example
|
||||||
|
|
||||||
# Copy subject details
|
# Copy subject details
|
||||||
# issuerAltName=issuer:copy
|
# issuerAltName=issuer:copy
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
openssl req -newkey rsa:1024 -keyout serverAkey.pem -out serverAreq.pem \
|
openssl req -newkey rsa:2048 -sha256 -keyout serverAkey.pem -out serverAreq.pem \
|
||||||
-config ./serverA.cnf -nodes -days 365 -batch
|
-config ./serverA.cnf -nodes -days 365 -batch
|
||||||
|
|
||||||
openssl x509 -req -in serverAreq.pem -sha1 -extfile ./serverA.cnf \
|
openssl x509 -req -in serverAreq.pem -sha256 -extfile ./serverA.cnf \
|
||||||
-extensions usr_cert -CA rootA.pem -CAkey rootAkey.pem -CAcreateserial \
|
-extensions usr_cert -CA rootA.pem -CAkey rootAkey.pem -CAcreateserial \
|
||||||
-out serverAcert.pem -days 365
|
-out serverAcert.pem -days 365
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ crl = $dir/crl.pem # The current CRL
|
|||||||
private_key = $dir/private/cakey.pem # The private key
|
private_key = $dir/private/cakey.pem # The private key
|
||||||
RANDFILE = $dir/private/.rand # private random number file
|
RANDFILE = $dir/private/.rand # private random number file
|
||||||
|
|
||||||
x509_extensions = usr_cert # The extentions to add to the cert
|
x509_extensions = usr_cert # The extensions to add to the cert
|
||||||
|
|
||||||
# Comment out the following two lines for the "traditional"
|
# Comment out the following two lines for the "traditional"
|
||||||
# (and highly broken) format.
|
# (and highly broken) format.
|
||||||
@ -102,7 +102,7 @@ default_bits = 1024
|
|||||||
default_keyfile = privkey.pem
|
default_keyfile = privkey.pem
|
||||||
distinguished_name = req_distinguished_name
|
distinguished_name = req_distinguished_name
|
||||||
attributes = req_attributes
|
attributes = req_attributes
|
||||||
x509_extensions = v3_ca # The extentions to add to the self signed cert
|
x509_extensions = v3_ca # The extensions to add to the self signed cert
|
||||||
|
|
||||||
# Passwords for private keys if not present they will be prompted for
|
# Passwords for private keys if not present they will be prompted for
|
||||||
# input_password = secret
|
# input_password = secret
|
||||||
@ -195,7 +195,7 @@ authorityKeyIdentifier=keyid,issuer
|
|||||||
|
|
||||||
# This stuff is for subjectAltName and issuerAltname.
|
# This stuff is for subjectAltName and issuerAltname.
|
||||||
# Import the email address.
|
# Import the email address.
|
||||||
# subjectAltName=email:copy
|
subjectAltName=DNS:fnord.bar.example
|
||||||
# An alternative to produce certificates that aren't
|
# An alternative to produce certificates that aren't
|
||||||
# deprecated according to PKIX.
|
# deprecated according to PKIX.
|
||||||
# subjectAltName=email:move
|
# subjectAltName=email:move
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
openssl req -newkey rsa:1024 -keyout serverBkey.pem -out serverBreq.pem \
|
openssl req -newkey rsa:2048 -sha256 -keyout serverBkey.pem -out serverBreq.pem \
|
||||||
-config ./serverB.cnf -nodes -days 365 -batch
|
-config ./serverB.cnf -nodes -days 365 -batch
|
||||||
|
|
||||||
openssl x509 -req -in serverBreq.pem -sha1 -extfile ./serverB.cnf \
|
openssl x509 -req -in serverBreq.pem -sha256 -extfile ./serverB.cnf \
|
||||||
-extensions usr_cert -CA rootB.pem -CAkey rootBkey.pem -CAcreateserial \
|
-extensions usr_cert -CA rootB.pem -CAkey rootBkey.pem -CAcreateserial \
|
||||||
-out serverBcert.pem -days 365
|
-out serverBcert.pem -days 365
|
||||||
|
|
||||||
|
@ -31,8 +31,27 @@ util.show( conn:getpeercertificate() )
|
|||||||
|
|
||||||
print("----------------------------------------------------------------------")
|
print("----------------------------------------------------------------------")
|
||||||
|
|
||||||
for k, cert in ipairs( conn:getpeerchain() ) do
|
local expectedpeerchain = { "../certs/clientAcert.pem", "../certs/rootA.pem" }
|
||||||
|
|
||||||
|
local peerchain = conn:getpeerchain()
|
||||||
|
assert(#peerchain == #expectedpeerchain)
|
||||||
|
for k, cert in ipairs( peerchain ) do
|
||||||
util.show(cert)
|
util.show(cert)
|
||||||
|
local expectedpem = assert(io.open(expectedpeerchain[k])):read("*a")
|
||||||
|
assert(cert:pem() == expectedpem, "peer chain mismatch @ "..tostring(k))
|
||||||
|
end
|
||||||
|
|
||||||
|
local expectedlocalchain = { "../certs/serverAcert.pem" }
|
||||||
|
|
||||||
|
local localchain = assert(conn:getlocalchain())
|
||||||
|
assert(#localchain == #expectedlocalchain)
|
||||||
|
for k, cert in ipairs( localchain ) do
|
||||||
|
util.show(cert)
|
||||||
|
local expectedpem = assert(io.open(expectedlocalchain[k])):read("*a")
|
||||||
|
assert(cert:pem() == expectedpem, "local chain mismatch @ "..tostring(k))
|
||||||
|
if k == 1 then
|
||||||
|
assert(cert:pem() == conn:getlocalcertificate():pem())
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local f = io.open(params.certificate)
|
local f = io.open(params.certificate)
|
||||||
|
28
samples/curve-negotiation/client.lua
Normal file
28
samples/curve-negotiation/client.lua
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
--
|
||||||
|
-- Public domain
|
||||||
|
--
|
||||||
|
local socket = require("socket")
|
||||||
|
local ssl = require("ssl")
|
||||||
|
|
||||||
|
local params = {
|
||||||
|
mode = "client",
|
||||||
|
protocol = "any",
|
||||||
|
key = "../certs/clientAkey.pem",
|
||||||
|
certificate = "../certs/clientA.pem",
|
||||||
|
cafile = "../certs/rootA.pem",
|
||||||
|
verify = {"peer", "fail_if_no_peer_cert"},
|
||||||
|
options = {"all"},
|
||||||
|
--
|
||||||
|
curve = "P-256:P-384",
|
||||||
|
}
|
||||||
|
|
||||||
|
local peer = socket.tcp()
|
||||||
|
peer:connect("127.0.0.1", 8888)
|
||||||
|
|
||||||
|
-- [[ SSL wrapper
|
||||||
|
peer = assert( ssl.wrap(peer, params) )
|
||||||
|
assert(peer:dohandshake())
|
||||||
|
--]]
|
||||||
|
|
||||||
|
print(peer:receive("*l"))
|
||||||
|
peer:close()
|
37
samples/curve-negotiation/server.lua
Normal file
37
samples/curve-negotiation/server.lua
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
--
|
||||||
|
-- Public domain
|
||||||
|
--
|
||||||
|
local socket = require("socket")
|
||||||
|
local ssl = require("ssl")
|
||||||
|
|
||||||
|
local params = {
|
||||||
|
mode = "server",
|
||||||
|
protocol = "any",
|
||||||
|
key = "../certs/serverAkey.pem",
|
||||||
|
certificate = "../certs/serverA.pem",
|
||||||
|
cafile = "../certs/rootA.pem",
|
||||||
|
verify = {"peer", "fail_if_no_peer_cert"},
|
||||||
|
options = {"all"},
|
||||||
|
--
|
||||||
|
curve = "P-384:P-256:P-521",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
-- [[ SSL context
|
||||||
|
local ctx = assert(ssl.newcontext(params))
|
||||||
|
--]]
|
||||||
|
|
||||||
|
local server = socket.tcp()
|
||||||
|
server:setoption('reuseaddr', true)
|
||||||
|
assert( server:bind("127.0.0.1", 8888) )
|
||||||
|
server:listen()
|
||||||
|
|
||||||
|
local peer = server:accept()
|
||||||
|
|
||||||
|
-- [[ SSL wrapper
|
||||||
|
peer = assert( ssl.wrap(peer, ctx) )
|
||||||
|
assert( peer:dohandshake() )
|
||||||
|
--]]
|
||||||
|
|
||||||
|
peer:send("oneshot with curve negotiation test\n")
|
||||||
|
peer:close()
|
40
samples/dane/client.lua
Normal file
40
samples/dane/client.lua
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
|
||||||
|
local socket = require "socket";
|
||||||
|
local ssl = require "ssl";
|
||||||
|
|
||||||
|
local dns = require "lunbound".new();
|
||||||
|
|
||||||
|
|
||||||
|
local cfg = {
|
||||||
|
protocol = "tlsv1_2",
|
||||||
|
mode = "client",
|
||||||
|
ciphers = "DEFAULT",
|
||||||
|
capath = "/etc/ssl/certs",
|
||||||
|
verify = "peer",
|
||||||
|
dane = true,
|
||||||
|
};
|
||||||
|
|
||||||
|
local function daneconnect(host, port)
|
||||||
|
port = port or "443";
|
||||||
|
local conn = ssl.wrap(socket.connect(host, port), cfg);
|
||||||
|
|
||||||
|
local tlsa = dns:resolve("_" .. port .. "._tcp." .. host, 52);
|
||||||
|
assert(tlsa.secure, "Insecure DNS");
|
||||||
|
|
||||||
|
assert(conn:setdane(host));
|
||||||
|
for i = 1, tlsa.n do
|
||||||
|
local usage, selector, mtype = tlsa[i] :byte(1, 3);
|
||||||
|
assert(conn:settlsa(usage, selector, mtype, tlsa[i] :sub(4, - 1)));
|
||||||
|
end
|
||||||
|
|
||||||
|
assert(conn:dohandshake());
|
||||||
|
return conn;
|
||||||
|
end
|
||||||
|
|
||||||
|
if not ... then
|
||||||
|
print("Usage: client.lua example.com [port]");
|
||||||
|
return os.exit(1);
|
||||||
|
end
|
||||||
|
local conn = daneconnect(...);
|
||||||
|
|
||||||
|
print(conn:getpeerverification());
|
@ -6,12 +6,13 @@ local ssl = require("ssl")
|
|||||||
|
|
||||||
local params = {
|
local params = {
|
||||||
mode = "client",
|
mode = "client",
|
||||||
protocol = "tlsv1_2",
|
protocol = "any",
|
||||||
key = "../certs/clientAkey.pem",
|
key = "../certs/clientAkey.pem",
|
||||||
certificate = "../certs/clientA.pem",
|
certificate = "../certs/clientA.pem",
|
||||||
cafile = "../certs/rootA.pem",
|
cafile = "../certs/rootA.pem",
|
||||||
verify = {"peer", "fail_if_no_peer_cert"},
|
verify = {"peer", "fail_if_no_peer_cert"},
|
||||||
options = "all",
|
options = "all",
|
||||||
|
ciphers = "EDH+AESGCM"
|
||||||
}
|
}
|
||||||
|
|
||||||
local peer = socket.tcp()
|
local peer = socket.tcp()
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/bin/sh
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
openssl dhparam -2 -out dh-512.pem -outform PEM 512
|
openssl dhparam -2 -out dh-512.pem -outform PEM 512
|
||||||
openssl dhparam -2 -out dh-1024.pem -outform PEM 1024
|
openssl dhparam -2 -out dh-1024.pem -outform PEM 1024
|
||||||
|
@ -38,6 +38,7 @@ local params = {
|
|||||||
verify = {"peer", "fail_if_no_peer_cert"},
|
verify = {"peer", "fail_if_no_peer_cert"},
|
||||||
options = "all",
|
options = "all",
|
||||||
dhparam = dhparam_cb,
|
dhparam = dhparam_cb,
|
||||||
|
ciphers = "EDH+AESGCM"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
2
samples/key/genkey.sh
Normal file → Executable file
2
samples/key/genkey.sh
Normal file → Executable file
@ -1,3 +1,3 @@
|
|||||||
#!/bin/sh
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
openssl genrsa -des3 -out key.pem -passout pass:foobar 2048
|
openssl genrsa -des3 -out key.pem -passout pass:foobar 2048
|
||||||
|
@ -23,6 +23,8 @@ while true do
|
|||||||
assert( peer:dohandshake() )
|
assert( peer:dohandshake() )
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
|
peer:getpeercertificate():extensions()
|
||||||
|
|
||||||
print(peer:receive("*l"))
|
print(peer:receive("*l"))
|
||||||
peer:close()
|
peer:close()
|
||||||
end
|
end
|
||||||
|
40
samples/luaossl/client.lua
Normal file
40
samples/luaossl/client.lua
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
--
|
||||||
|
-- Public domain
|
||||||
|
--
|
||||||
|
local socket = require("socket")
|
||||||
|
local ssl = require("ssl")
|
||||||
|
|
||||||
|
local pkey = require "openssl.pkey"
|
||||||
|
local ssl_context = require "openssl.ssl.context"
|
||||||
|
local x509 = require "openssl.x509"
|
||||||
|
local x509_store = require "openssl.x509.store"
|
||||||
|
|
||||||
|
local function read_file(path)
|
||||||
|
local file, err, errno = io.open(path, "rb")
|
||||||
|
if not file then
|
||||||
|
return nil, err, errno
|
||||||
|
end
|
||||||
|
local contents
|
||||||
|
contents, err, errno = file:read "*a"
|
||||||
|
file:close()
|
||||||
|
return contents, err, errno
|
||||||
|
end
|
||||||
|
|
||||||
|
local ctx = ssl_context.new("TLSv1_2", false)
|
||||||
|
ctx:setPrivateKey(pkey.new(assert(read_file("../certs/clientAkey.pem"))))
|
||||||
|
ctx:setCertificate(x509.new(assert(read_file("../certs/clientA.pem"))))
|
||||||
|
local store = x509_store.new()
|
||||||
|
store:add("../certs/rootA.pem")
|
||||||
|
ctx:setStore(store)
|
||||||
|
ctx:setVerify(ssl_context.VERIFY_FAIL_IF_NO_PEER_CERT)
|
||||||
|
|
||||||
|
local peer = socket.tcp()
|
||||||
|
peer:connect("127.0.0.1", 8888)
|
||||||
|
|
||||||
|
-- [[ SSL wrapper
|
||||||
|
peer = assert( ssl.wrap(peer, ctx) )
|
||||||
|
assert(peer:dohandshake())
|
||||||
|
--]]
|
||||||
|
|
||||||
|
print(peer:receive("*l"))
|
||||||
|
peer:close()
|
58
samples/luaossl/server.lua
Normal file
58
samples/luaossl/server.lua
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
--
|
||||||
|
-- Public domain
|
||||||
|
--
|
||||||
|
local socket = require("socket")
|
||||||
|
local ssl = require("ssl")
|
||||||
|
|
||||||
|
local pkey = require "openssl.pkey"
|
||||||
|
local ssl_context = require "openssl.ssl.context"
|
||||||
|
local x509 = require "openssl.x509"
|
||||||
|
local x509_store = require "openssl.x509.store"
|
||||||
|
|
||||||
|
local function read_file(path)
|
||||||
|
local file, err, errno = io.open(path, "rb")
|
||||||
|
if not file then
|
||||||
|
return nil, err, errno
|
||||||
|
end
|
||||||
|
local contents
|
||||||
|
contents, err, errno = file:read "*a"
|
||||||
|
file:close()
|
||||||
|
return contents, err, errno
|
||||||
|
end
|
||||||
|
|
||||||
|
local ctx = ssl_context.new("TLSv1_2", true)
|
||||||
|
ctx:setPrivateKey(pkey.new(assert(read_file("../certs/serverAkey.pem"))))
|
||||||
|
ctx:setCertificate(x509.new(assert(read_file("../certs/serverA.pem"))))
|
||||||
|
local store = x509_store.new()
|
||||||
|
store:add("../certs/rootA.pem")
|
||||||
|
ctx:setStore(store)
|
||||||
|
ctx:setVerify(ssl_context.VERIFY_FAIL_IF_NO_PEER_CERT)
|
||||||
|
|
||||||
|
|
||||||
|
local server = socket.tcp()
|
||||||
|
server:setoption('reuseaddr', true)
|
||||||
|
assert( server:bind("127.0.0.1", 8888) )
|
||||||
|
server:listen()
|
||||||
|
|
||||||
|
local peer = server:accept()
|
||||||
|
|
||||||
|
-- [[ SSL wrapper
|
||||||
|
peer = assert( ssl.wrap(peer, ctx) )
|
||||||
|
|
||||||
|
-- Before handshake: nil
|
||||||
|
print( peer:info() )
|
||||||
|
|
||||||
|
assert( peer:dohandshake() )
|
||||||
|
--]]
|
||||||
|
|
||||||
|
print("---")
|
||||||
|
local info = peer:info()
|
||||||
|
for k, v in pairs(info) do
|
||||||
|
print(k, v)
|
||||||
|
end
|
||||||
|
|
||||||
|
print("---")
|
||||||
|
print("-> Compression", peer:info("compression"))
|
||||||
|
|
||||||
|
peer:send("oneshot test\n")
|
||||||
|
peer:close()
|
29
samples/multicert/client-ecdsa.lua
Normal file
29
samples/multicert/client-ecdsa.lua
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
--
|
||||||
|
-- Public domain
|
||||||
|
--
|
||||||
|
local socket = require("socket")
|
||||||
|
local ssl = require("ssl")
|
||||||
|
|
||||||
|
local params = {
|
||||||
|
mode = "client",
|
||||||
|
protocol = "tlsv1_2",
|
||||||
|
key = "certs/clientECDSAkey.pem",
|
||||||
|
certificate = "certs/clientECDSA.pem",
|
||||||
|
verify = "none",
|
||||||
|
options = "all",
|
||||||
|
ciphers = "ALL:!aRSA"
|
||||||
|
}
|
||||||
|
|
||||||
|
local peer = socket.tcp()
|
||||||
|
peer:connect("127.0.0.1", 8888)
|
||||||
|
|
||||||
|
-- [[ SSL wrapper
|
||||||
|
peer = assert( ssl.wrap(peer, params) )
|
||||||
|
assert(peer:dohandshake())
|
||||||
|
--]]
|
||||||
|
|
||||||
|
local i = peer:info()
|
||||||
|
for k, v in pairs(i) do print(k, v) end
|
||||||
|
|
||||||
|
print(peer:receive("*l"))
|
||||||
|
peer:close()
|
29
samples/multicert/client-rsa.lua
Normal file
29
samples/multicert/client-rsa.lua
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
--
|
||||||
|
-- Public domain
|
||||||
|
--
|
||||||
|
local socket = require("socket")
|
||||||
|
local ssl = require("ssl")
|
||||||
|
|
||||||
|
local params = {
|
||||||
|
mode = "client",
|
||||||
|
protocol = "tlsv1_2",
|
||||||
|
key = "certs/clientRSAkey.pem",
|
||||||
|
certificate = "certs/clientRSA.pem",
|
||||||
|
verify = "none",
|
||||||
|
options = "all",
|
||||||
|
ciphers = "ALL:!ECDSA"
|
||||||
|
}
|
||||||
|
|
||||||
|
local peer = socket.tcp()
|
||||||
|
peer:connect("127.0.0.1", 8888)
|
||||||
|
|
||||||
|
-- [[ SSL wrapper
|
||||||
|
peer = assert( ssl.wrap(peer, params) )
|
||||||
|
assert(peer:dohandshake())
|
||||||
|
--]]
|
||||||
|
|
||||||
|
local i = peer:info()
|
||||||
|
for k, v in pairs(i) do print(k, v) end
|
||||||
|
|
||||||
|
print(peer:receive("*l"))
|
||||||
|
peer:close()
|
13
samples/multicert/gencerts.sh
Executable file
13
samples/multicert/gencerts.sh
Executable file
@ -0,0 +1,13 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
mkdir -p certs
|
||||||
|
|
||||||
|
openssl ecparam -name secp256r1 -genkey -out certs/serverECDSAkey.pem
|
||||||
|
openssl req -new -config ../certs/serverA.cnf -extensions usr_cert -x509 -key certs/serverECDSAkey.pem -out certs/serverECDSA.pem -days 360 -batch
|
||||||
|
|
||||||
|
openssl ecparam -name secp256r1 -genkey -out certs/clientECDSAkey.pem
|
||||||
|
openssl req -config ../certs/clientA.cnf -extensions usr_cert -x509 -new -key certs/clientECDSAkey.pem -out certs/clientECDSA.pem -days 360 -batch
|
||||||
|
|
||||||
|
openssl req -config ../certs/serverB.cnf -extensions usr_cert -x509 -new -newkey rsa:2048 -keyout certs/serverRSAkey.pem -out certs/serverRSA.pem -nodes -days 365 -batch
|
||||||
|
|
||||||
|
openssl req -config ../certs/clientB.cnf -extensions usr_cert -x509 -new -newkey rsa:2048 -keyout certs/clientRSAkey.pem -out certs/clientRSA.pem -nodes -days 365 -batch
|
38
samples/multicert/server.lua
Normal file
38
samples/multicert/server.lua
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
--
|
||||||
|
-- Public domain
|
||||||
|
--
|
||||||
|
local socket = require("socket")
|
||||||
|
local ssl = require("ssl")
|
||||||
|
|
||||||
|
local params = {
|
||||||
|
mode = "server",
|
||||||
|
protocol = "any",
|
||||||
|
certificates = {
|
||||||
|
-- Comment line below and 'client-rsa' stop working
|
||||||
|
{ certificate = "certs/serverRSA.pem", key = "certs/serverRSAkey.pem" },
|
||||||
|
-- Comment line below and 'client-ecdsa' stop working
|
||||||
|
{ certificate = "certs/serverECDSA.pem", key = "certs/serverECDSAkey.pem" }
|
||||||
|
},
|
||||||
|
verify = "none",
|
||||||
|
options = "all"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
-- [[ SSL context
|
||||||
|
local ctx = assert(ssl.newcontext(params))
|
||||||
|
--]]
|
||||||
|
|
||||||
|
local server = socket.tcp()
|
||||||
|
server:setoption('reuseaddr', true)
|
||||||
|
assert( server:bind("127.0.0.1", 8888) )
|
||||||
|
server:listen()
|
||||||
|
|
||||||
|
local peer = server:accept()
|
||||||
|
|
||||||
|
-- [[ SSL wrapper
|
||||||
|
peer = assert( ssl.wrap(peer, ctx) )
|
||||||
|
assert( peer:dohandshake() )
|
||||||
|
--]]
|
||||||
|
|
||||||
|
peer:send("oneshot test\n")
|
||||||
|
peer:close()
|
41
samples/psk/client.lua
Normal file
41
samples/psk/client.lua
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
--
|
||||||
|
-- Public domain
|
||||||
|
--
|
||||||
|
local socket = require("socket")
|
||||||
|
local ssl = require("ssl")
|
||||||
|
|
||||||
|
if not ssl.config.capabilities.psk then
|
||||||
|
print("[ERRO] PSK not available")
|
||||||
|
os.exit(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- @param hint (nil | string)
|
||||||
|
-- @param max_identity_len (number)
|
||||||
|
-- @param max_psk_len (number)
|
||||||
|
-- @return identity (string)
|
||||||
|
-- @return PSK (string)
|
||||||
|
local function pskcb(hint, max_identity_len, max_psk_len)
|
||||||
|
print(string.format("PSK Callback: hint=%q, max_identity_len=%d, max_psk_len=%d", hint, max_identity_len, max_psk_len))
|
||||||
|
return "abcd", "1234"
|
||||||
|
end
|
||||||
|
|
||||||
|
local params = {
|
||||||
|
mode = "client",
|
||||||
|
protocol = "tlsv1_2",
|
||||||
|
psk = pskcb,
|
||||||
|
}
|
||||||
|
|
||||||
|
local peer = socket.tcp()
|
||||||
|
peer:connect("127.0.0.1", 8888)
|
||||||
|
|
||||||
|
peer = assert( ssl.wrap(peer, params) )
|
||||||
|
assert(peer:dohandshake())
|
||||||
|
|
||||||
|
print("--- INFO ---")
|
||||||
|
local info = peer:info()
|
||||||
|
for k, v in pairs(info) do
|
||||||
|
print(k, v)
|
||||||
|
end
|
||||||
|
print("---")
|
||||||
|
|
||||||
|
peer:close()
|
60
samples/psk/server.lua
Normal file
60
samples/psk/server.lua
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
--
|
||||||
|
-- Public domain
|
||||||
|
--
|
||||||
|
local socket = require("socket")
|
||||||
|
local ssl = require("ssl")
|
||||||
|
|
||||||
|
if not ssl.config.capabilities.psk then
|
||||||
|
print("[ERRO] PSK not available")
|
||||||
|
os.exit(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- @param identity (string)
|
||||||
|
-- @param max_psk_len (number)
|
||||||
|
-- @return psk (string)
|
||||||
|
local function pskcb(identity, max_psk_len)
|
||||||
|
print(string.format("PSK Callback: identity=%q, max_psk_len=%d", identity, max_psk_len))
|
||||||
|
if identity == "abcd" then
|
||||||
|
return "1234"
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
local params = {
|
||||||
|
mode = "server",
|
||||||
|
protocol = "any",
|
||||||
|
options = "all",
|
||||||
|
|
||||||
|
-- PSK with just a callback
|
||||||
|
psk = pskcb,
|
||||||
|
|
||||||
|
-- PSK with identity hint
|
||||||
|
-- psk = {
|
||||||
|
-- hint = "hintpsksample",
|
||||||
|
-- callback = pskcb,
|
||||||
|
-- },
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
-- [[ SSL context
|
||||||
|
local ctx = assert(ssl.newcontext(params))
|
||||||
|
--]]
|
||||||
|
|
||||||
|
local server = socket.tcp()
|
||||||
|
server:setoption('reuseaddr', true)
|
||||||
|
assert( server:bind("127.0.0.1", 8888) )
|
||||||
|
server:listen()
|
||||||
|
|
||||||
|
local peer = server:accept()
|
||||||
|
peer = assert( ssl.wrap(peer, ctx) )
|
||||||
|
assert( peer:dohandshake() )
|
||||||
|
|
||||||
|
print("--- INFO ---")
|
||||||
|
local info = peer:info()
|
||||||
|
for k, v in pairs(info) do
|
||||||
|
print(k, v)
|
||||||
|
end
|
||||||
|
print("---")
|
||||||
|
|
||||||
|
peer:close()
|
||||||
|
server:close()
|
28
src/Makefile
28
src/Makefile
@ -2,9 +2,12 @@ CMOD=ssl.so
|
|||||||
LMOD=ssl.lua
|
LMOD=ssl.lua
|
||||||
|
|
||||||
OBJS= \
|
OBJS= \
|
||||||
|
options.o \
|
||||||
x509.o \
|
x509.o \
|
||||||
context.o \
|
context.o \
|
||||||
ssl.o
|
ssl.o \
|
||||||
|
config.o \
|
||||||
|
ec.o
|
||||||
|
|
||||||
LIBS=-lssl -lcrypto -lluasocket
|
LIBS=-lssl -lcrypto -lluasocket
|
||||||
|
|
||||||
@ -21,8 +24,8 @@ MAC_CFLAGS=-O2 -fno-common $(WARN) $(INCDIR) $(DEFS)
|
|||||||
MAC_LDFLAGS=-bundle -undefined dynamic_lookup $(LIBDIR)
|
MAC_LDFLAGS=-bundle -undefined dynamic_lookup $(LIBDIR)
|
||||||
|
|
||||||
INSTALL = install
|
INSTALL = install
|
||||||
CC = cc
|
CC ?= cc
|
||||||
LD = $(MYENV) cc
|
CCLD ?= $(MYENV) $(CC)
|
||||||
CFLAGS += $(MYCFLAGS)
|
CFLAGS += $(MYCFLAGS)
|
||||||
LDFLAGS += $(MYLDFLAGS)
|
LDFLAGS += $(MYLDFLAGS)
|
||||||
|
|
||||||
@ -31,10 +34,10 @@ LDFLAGS += $(MYLDFLAGS)
|
|||||||
all:
|
all:
|
||||||
|
|
||||||
install: $(CMOD) $(LMOD)
|
install: $(CMOD) $(LMOD)
|
||||||
$(INSTALL) -d $(LUAPATH)/ssl $(LUACPATH)
|
$(INSTALL) -d $(DESTDIR)$(LUAPATH)/ssl $(DESTDIR)$(LUACPATH)
|
||||||
$(INSTALL) $(CMOD) $(LUACPATH)
|
$(INSTALL) $(CMOD) $(DESTDIR)$(LUACPATH)
|
||||||
$(INSTALL) -m644 $(LMOD) $(LUAPATH)
|
$(INSTALL) -m644 $(LMOD) $(DESTDIR)$(LUAPATH)
|
||||||
$(INSTALL) -m644 https.lua $(LUAPATH)/ssl
|
$(INSTALL) -m644 https.lua $(DESTDIR)$(LUAPATH)/ssl
|
||||||
|
|
||||||
linux:
|
linux:
|
||||||
@$(MAKE) $(CMOD) MYCFLAGS="$(LNX_CFLAGS)" MYLDFLAGS="$(LNX_LDFLAGS)" EXTRA="$(EXTRA)"
|
@$(MAKE) $(CMOD) MYCFLAGS="$(LNX_CFLAGS)" MYLDFLAGS="$(LNX_LDFLAGS)" EXTRA="$(EXTRA)"
|
||||||
@ -49,12 +52,15 @@ luasocket:
|
|||||||
@cd luasocket && $(MAKE)
|
@cd luasocket && $(MAKE)
|
||||||
|
|
||||||
$(CMOD): $(EXTRA) $(OBJS)
|
$(CMOD): $(EXTRA) $(OBJS)
|
||||||
$(LD) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
|
$(CCLD) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
cd luasocket && $(MAKE) clean
|
cd luasocket && $(MAKE) clean
|
||||||
rm -f $(OBJS) $(CMOD)
|
rm -f $(OBJS) $(CMOD)
|
||||||
|
|
||||||
x509.o: x509.c x509.h config.h
|
options.o: options.h options.c
|
||||||
context.o: context.c context.h ec.h config.h
|
ec.o: ec.c ec.h
|
||||||
ssl.o: ssl.c ssl.h context.h x509.h config.h
|
x509.o: x509.c x509.h compat.h
|
||||||
|
context.o: context.c context.h ec.h compat.h options.h
|
||||||
|
ssl.o: ssl.c ssl.h context.h x509.h compat.h
|
||||||
|
config.o: config.c ec.h options.h compat.h
|
||||||
|
63
src/compat.h
Normal file
63
src/compat.h
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
/*--------------------------------------------------------------------------
|
||||||
|
* LuaSec 1.3.2
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2023 Bruno Silvestre
|
||||||
|
*
|
||||||
|
*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef LSEC_COMPAT_H
|
||||||
|
#define LSEC_COMPAT_H
|
||||||
|
|
||||||
|
#include <openssl/ssl.h>
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#define LSEC_API __declspec(dllexport)
|
||||||
|
#else
|
||||||
|
#define LSEC_API extern
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#if (LUA_VERSION_NUM == 501)
|
||||||
|
|
||||||
|
#define luaL_testudata(L, ud, tname) lsec_testudata(L, ud, tname)
|
||||||
|
#define setfuncs(L, R) luaL_register(L, NULL, R)
|
||||||
|
#define lua_rawlen(L, i) lua_objlen(L, i)
|
||||||
|
|
||||||
|
#ifndef luaL_newlib
|
||||||
|
#define luaL_newlib(L, R) do { lua_newtable(L); luaL_register(L, NULL, R); } while(0)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#else
|
||||||
|
#define setfuncs(L, R) luaL_setfuncs(L, R, 0)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#if (!defined(LIBRESSL_VERSION_NUMBER) && (OPENSSL_VERSION_NUMBER >= 0x1010000fL))
|
||||||
|
#define LSEC_ENABLE_DANE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#if !((defined(LIBRESSL_VERSION_NUMBER) && (LIBRESSL_VERSION_NUMBER < 0x2070000fL)) || (OPENSSL_VERSION_NUMBER < 0x1010000fL))
|
||||||
|
#define LSEC_API_OPENSSL_1_1_0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#if !defined(LIBRESSL_VERSION_NUMBER) && ((OPENSSL_VERSION_NUMBER & 0xFFFFF000L) == 0x10101000L || (OPENSSL_VERSION_NUMBER & 0xFFFFF000L) == 0x30000000L)
|
||||||
|
#define LSEC_OPENSSL_ERRNO_BUG
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#if !defined(LIBRESSL_VERSION_NUMBER) && !defined(OPENSSL_NO_PSK)
|
||||||
|
#define LSEC_ENABLE_PSK
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#endif
|
108
src/config.c
Normal file
108
src/config.c
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
/*--------------------------------------------------------------------------
|
||||||
|
* LuaSec 1.3.2
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2023 Bruno Silvestre
|
||||||
|
*
|
||||||
|
*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "compat.h"
|
||||||
|
#include "options.h"
|
||||||
|
#include "ec.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registre the module.
|
||||||
|
*/
|
||||||
|
LSEC_API int luaopen_ssl_config(lua_State *L)
|
||||||
|
{
|
||||||
|
lsec_ssl_option_t *opt;
|
||||||
|
|
||||||
|
lua_newtable(L);
|
||||||
|
|
||||||
|
// Options
|
||||||
|
lua_pushstring(L, "options");
|
||||||
|
lua_newtable(L);
|
||||||
|
for (opt = lsec_get_ssl_options(); opt->name; opt++) {
|
||||||
|
lua_pushstring(L, opt->name);
|
||||||
|
lua_pushboolean(L, 1);
|
||||||
|
lua_rawset(L, -3);
|
||||||
|
}
|
||||||
|
lua_rawset(L, -3);
|
||||||
|
|
||||||
|
// Protocols
|
||||||
|
lua_pushstring(L, "protocols");
|
||||||
|
lua_newtable(L);
|
||||||
|
|
||||||
|
lua_pushstring(L, "tlsv1");
|
||||||
|
lua_pushboolean(L, 1);
|
||||||
|
lua_rawset(L, -3);
|
||||||
|
lua_pushstring(L, "tlsv1_1");
|
||||||
|
lua_pushboolean(L, 1);
|
||||||
|
lua_rawset(L, -3);
|
||||||
|
lua_pushstring(L, "tlsv1_2");
|
||||||
|
lua_pushboolean(L, 1);
|
||||||
|
lua_rawset(L, -3);
|
||||||
|
#ifdef TLS1_3_VERSION
|
||||||
|
lua_pushstring(L, "tlsv1_3");
|
||||||
|
lua_pushboolean(L, 1);
|
||||||
|
lua_rawset(L, -3);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
lua_rawset(L, -3);
|
||||||
|
|
||||||
|
// Algorithms
|
||||||
|
lua_pushstring(L, "algorithms");
|
||||||
|
lua_newtable(L);
|
||||||
|
|
||||||
|
#ifndef OPENSSL_NO_EC
|
||||||
|
lua_pushstring(L, "ec");
|
||||||
|
lua_pushboolean(L, 1);
|
||||||
|
lua_rawset(L, -3);
|
||||||
|
#endif
|
||||||
|
lua_rawset(L, -3);
|
||||||
|
|
||||||
|
// Curves
|
||||||
|
lua_pushstring(L, "curves");
|
||||||
|
lsec_get_curves(L);
|
||||||
|
lua_rawset(L, -3);
|
||||||
|
|
||||||
|
// Capabilities
|
||||||
|
lua_pushstring(L, "capabilities");
|
||||||
|
lua_newtable(L);
|
||||||
|
|
||||||
|
// ALPN
|
||||||
|
lua_pushstring(L, "alpn");
|
||||||
|
lua_pushboolean(L, 1);
|
||||||
|
lua_rawset(L, -3);
|
||||||
|
|
||||||
|
#ifdef LSEC_ENABLE_PSK
|
||||||
|
lua_pushstring(L, "psk");
|
||||||
|
lua_pushboolean(L, 1);
|
||||||
|
lua_rawset(L, -3);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef LSEC_ENABLE_DANE
|
||||||
|
// DANE
|
||||||
|
lua_pushstring(L, "dane");
|
||||||
|
#ifdef DANE_FLAG_NO_DANE_EE_NAMECHECKS
|
||||||
|
lua_createtable(L, 0, 1);
|
||||||
|
lua_pushstring(L, "no_ee_namechecks");
|
||||||
|
lua_pushboolean(L, 1);
|
||||||
|
lua_rawset(L, -3);
|
||||||
|
#else
|
||||||
|
lua_pushboolean(L, 1);
|
||||||
|
#endif
|
||||||
|
lua_rawset(L, -3);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef OPENSSL_NO_EC
|
||||||
|
lua_pushstring(L, "curves_list");
|
||||||
|
lua_pushboolean(L, 1);
|
||||||
|
lua_rawset(L, -3);
|
||||||
|
lua_pushstring(L, "ecdh_auto");
|
||||||
|
lua_pushboolean(L, 1);
|
||||||
|
lua_rawset(L, -3);
|
||||||
|
#endif
|
||||||
|
lua_rawset(L, -3);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
24
src/config.h
24
src/config.h
@ -1,24 +0,0 @@
|
|||||||
/*--------------------------------------------------------------------------
|
|
||||||
* LuaSec 0.6
|
|
||||||
* Copyright (C) 2006-2016 Bruno Silvestre
|
|
||||||
*
|
|
||||||
*--------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
#ifndef LSEC_CONFIG_H
|
|
||||||
#define LSEC_CONFIG_H
|
|
||||||
|
|
||||||
#if defined(_WIN32)
|
|
||||||
#define LSEC_API __declspec(dllexport)
|
|
||||||
#else
|
|
||||||
#define LSEC_API extern
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if (LUA_VERSION_NUM == 501)
|
|
||||||
#define setfuncs(L, R) luaL_register(L, NULL, R)
|
|
||||||
#define lua_rawlen(L, i) lua_objlen(L, i)
|
|
||||||
#define luaL_newlib(L, R) do { lua_newtable(L); luaL_register(L, NULL, R); } while(0)
|
|
||||||
#else
|
|
||||||
#define setfuncs(L, R) luaL_setfuncs(L, R, 0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
510
src/context.c
510
src/context.c
@ -1,9 +1,8 @@
|
|||||||
/*--------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------
|
||||||
* LuaSec 0.6
|
* LuaSec 1.3.2
|
||||||
*
|
*
|
||||||
* Copyright (C) 2014-2016 Kim Alvefur, Paul Aurich, Tobias Markmann,
|
* Copyright (C) 2014-2023 Kim Alvefur, Paul Aurich, Tobias Markmann, Matthew Wild
|
||||||
* Matthew Wild.
|
* Copyright (C) 2006-2023 Bruno Silvestre
|
||||||
* Copyright (C) 2006-2016 Bruno Silvestre.
|
|
||||||
*
|
*
|
||||||
*--------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
@ -17,50 +16,21 @@
|
|||||||
#include <openssl/err.h>
|
#include <openssl/err.h>
|
||||||
#include <openssl/x509.h>
|
#include <openssl/x509.h>
|
||||||
#include <openssl/x509v3.h>
|
#include <openssl/x509v3.h>
|
||||||
|
#include <openssl/x509_vfy.h>
|
||||||
|
#include <openssl/dh.h>
|
||||||
|
|
||||||
#include <lua.h>
|
#include <lua.h>
|
||||||
#include <lauxlib.h>
|
#include <lauxlib.h>
|
||||||
|
|
||||||
|
#include "compat.h"
|
||||||
#include "context.h"
|
#include "context.h"
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
|
|
||||||
#ifndef OPENSSL_NO_ECDH
|
#ifndef OPENSSL_NO_EC
|
||||||
#include <openssl/ec.h>
|
#include <openssl/ec.h>
|
||||||
#include "ec.h"
|
#include "ec.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (OPENSSL_VERSION_NUMBER >= 0x1000000fL)
|
|
||||||
typedef const SSL_METHOD LSEC_SSL_METHOD;
|
|
||||||
#else
|
|
||||||
typedef SSL_METHOD LSEC_SSL_METHOD;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if OPENSSL_VERSION_NUMBER>=0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)
|
|
||||||
#define SSLv23_method() TLS_method()
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*-- Compat - Lua 5.1 --------------------------------------------------------*/
|
|
||||||
|
|
||||||
#if (LUA_VERSION_NUM == 501)
|
|
||||||
|
|
||||||
#define luaL_testudata(L, ud, tname) testudata(L, ud, tname)
|
|
||||||
|
|
||||||
static void *testudata (lua_State *L, int ud, const char *tname) {
|
|
||||||
void *p = lua_touserdata(L, ud);
|
|
||||||
if (p != NULL) { /* value is a userdata? */
|
|
||||||
if (lua_getmetatable(L, ud)) { /* does it have a metatable? */
|
|
||||||
luaL_getmetatable(L, tname); /* get correct metatable */
|
|
||||||
if (!lua_rawequal(L, -1, -2)) /* not the same? */
|
|
||||||
p = NULL; /* value is a userdata with wrong metatable */
|
|
||||||
lua_pop(L, 2); /* remove both metatables */
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NULL; /* value is not a userdata with a metatable */
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*--------------------------- Auxiliary Functions ----------------------------*/
|
/*--------------------------- Auxiliary Functions ----------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -81,8 +51,8 @@ static p_context testctx(lua_State *L, int idx)
|
|||||||
*/
|
*/
|
||||||
static int set_option_flag(const char *opt, unsigned long *flag)
|
static int set_option_flag(const char *opt, unsigned long *flag)
|
||||||
{
|
{
|
||||||
ssl_option_t *p;
|
lsec_ssl_option_t *p;
|
||||||
for (p = ssl_options; p->name; p++) {
|
for (p = lsec_get_ssl_options(); p->name; p++) {
|
||||||
if (!strcmp(opt, p->name)) {
|
if (!strcmp(opt, p->name)) {
|
||||||
*flag |= p->code;
|
*flag |= p->code;
|
||||||
return 1;
|
return 1;
|
||||||
@ -91,23 +61,59 @@ static int set_option_flag(const char *opt, unsigned long *flag)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef LSEC_API_OPENSSL_1_1_0
|
||||||
/**
|
/**
|
||||||
* Find the protocol.
|
* Find the protocol.
|
||||||
*/
|
*/
|
||||||
static LSEC_SSL_METHOD* str2method(const char *method)
|
static const SSL_METHOD* str2method(const char *method, int *vmin, int *vmax)
|
||||||
{
|
{
|
||||||
|
(void)vmin;
|
||||||
|
(void)vmax;
|
||||||
if (!strcmp(method, "any")) return SSLv23_method();
|
if (!strcmp(method, "any")) return SSLv23_method();
|
||||||
if (!strcmp(method, "sslv23")) return SSLv23_method(); // deprecated
|
if (!strcmp(method, "sslv23")) return SSLv23_method(); // deprecated
|
||||||
#ifndef OPENSSL_NO_SSL3
|
|
||||||
if (!strcmp(method, "sslv3")) return SSLv3_method();
|
|
||||||
#endif
|
|
||||||
if (!strcmp(method, "tlsv1")) return TLSv1_method();
|
if (!strcmp(method, "tlsv1")) return TLSv1_method();
|
||||||
#if (OPENSSL_VERSION_NUMBER >= 0x1000100fL)
|
|
||||||
if (!strcmp(method, "tlsv1_1")) return TLSv1_1_method();
|
if (!strcmp(method, "tlsv1_1")) return TLSv1_1_method();
|
||||||
if (!strcmp(method, "tlsv1_2")) return TLSv1_2_method();
|
if (!strcmp(method, "tlsv1_2")) return TLSv1_2_method();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the protocol.
|
||||||
|
*/
|
||||||
|
static const SSL_METHOD* str2method(const char *method, int *vmin, int *vmax)
|
||||||
|
{
|
||||||
|
if (!strcmp(method, "any") || !strcmp(method, "sslv23")) { // 'sslv23' is deprecated
|
||||||
|
*vmin = 0;
|
||||||
|
*vmax = 0;
|
||||||
|
return TLS_method();
|
||||||
|
}
|
||||||
|
else if (!strcmp(method, "tlsv1")) {
|
||||||
|
*vmin = TLS1_VERSION;
|
||||||
|
*vmax = TLS1_VERSION;
|
||||||
|
return TLS_method();
|
||||||
|
}
|
||||||
|
else if (!strcmp(method, "tlsv1_1")) {
|
||||||
|
*vmin = TLS1_1_VERSION;
|
||||||
|
*vmax = TLS1_1_VERSION;
|
||||||
|
return TLS_method();
|
||||||
|
}
|
||||||
|
else if (!strcmp(method, "tlsv1_2")) {
|
||||||
|
*vmin = TLS1_2_VERSION;
|
||||||
|
*vmax = TLS1_2_VERSION;
|
||||||
|
return TLS_method();
|
||||||
|
}
|
||||||
|
#if defined(TLS1_3_VERSION)
|
||||||
|
else if (!strcmp(method, "tlsv1_3")) {
|
||||||
|
*vmin = TLS1_3_VERSION;
|
||||||
|
*vmax = TLS1_3_VERSION;
|
||||||
|
return TLS_method();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare the SSL handshake verify flag.
|
* Prepare the SSL handshake verify flag.
|
||||||
@ -194,7 +200,6 @@ static DH *dhparam_cb(SSL *ssl, int is_export, int keylength)
|
|||||||
{
|
{
|
||||||
BIO *bio;
|
BIO *bio;
|
||||||
lua_State *L;
|
lua_State *L;
|
||||||
DH *dh_tmp = NULL;
|
|
||||||
SSL_CTX *ctx = SSL_get_SSL_CTX(ssl);
|
SSL_CTX *ctx = SSL_get_SSL_CTX(ssl);
|
||||||
p_context pctx = (p_context)SSL_CTX_get_app_data(ctx);
|
p_context pctx = (p_context)SSL_CTX_get_app_data(ctx);
|
||||||
|
|
||||||
@ -215,24 +220,15 @@ static DH *dhparam_cb(SSL *ssl, int is_export, int keylength)
|
|||||||
lua_pop(L, 2); /* Remove values from stack */
|
lua_pop(L, 2); /* Remove values from stack */
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
bio = BIO_new_mem_buf((void*)lua_tostring(L, -1),
|
|
||||||
lua_rawlen(L, -1));
|
bio = BIO_new_mem_buf((void*)lua_tostring(L, -1), lua_rawlen(L, -1));
|
||||||
if (bio) {
|
if (bio) {
|
||||||
dh_tmp = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
|
pctx->dh_param = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
|
||||||
BIO_free(bio);
|
BIO_free(bio);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* OpenSSL exepcts the callback to maintain a reference to the DH*. So,
|
|
||||||
* cache it here, and clean up the previous set of parameters. Any remaining
|
|
||||||
* set is cleaned up when destroying the LuaSec context.
|
|
||||||
*/
|
|
||||||
if (pctx->dh_param)
|
|
||||||
DH_free(pctx->dh_param);
|
|
||||||
pctx->dh_param = dh_tmp;
|
|
||||||
|
|
||||||
lua_pop(L, 2); /* Remove values from stack */
|
lua_pop(L, 2); /* Remove values from stack */
|
||||||
return dh_tmp;
|
return pctx->dh_param;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -304,18 +300,6 @@ static int verify_cb(int preverify_ok, X509_STORE_CTX *x509_ctx)
|
|||||||
return (verify & LSEC_VERIFY_CONTINUE ? 1 : preverify_ok);
|
return (verify & LSEC_VERIFY_CONTINUE ? 1 : preverify_ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef OPENSSL_NO_ECDH
|
|
||||||
static EC_KEY *find_ec_key(const char *str)
|
|
||||||
{
|
|
||||||
p_ec ptr;
|
|
||||||
for (ptr = curves; ptr->name; ptr++) {
|
|
||||||
if (!strcmp(str, ptr->name))
|
|
||||||
return EC_KEY_new_by_curve_name(ptr->nid);
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*------------------------------ Lua Functions -------------------------------*/
|
/*------------------------------ Lua Functions -------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -325,10 +309,11 @@ static int create(lua_State *L)
|
|||||||
{
|
{
|
||||||
p_context ctx;
|
p_context ctx;
|
||||||
const char *str_method;
|
const char *str_method;
|
||||||
LSEC_SSL_METHOD *method;
|
const SSL_METHOD *method;
|
||||||
|
int vmin, vmax;
|
||||||
|
|
||||||
str_method = luaL_checkstring(L, 1);
|
str_method = luaL_checkstring(L, 1);
|
||||||
method = str2method(str_method);
|
method = str2method(str_method, &vmin, &vmax);
|
||||||
if (!method) {
|
if (!method) {
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
lua_pushfstring(L, "invalid protocol (%s)", str_method);
|
lua_pushfstring(L, "invalid protocol (%s)", str_method);
|
||||||
@ -348,6 +333,10 @@ static int create(lua_State *L)
|
|||||||
ERR_reason_error_string(ERR_get_error()));
|
ERR_reason_error_string(ERR_get_error()));
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
#ifdef LSEC_API_OPENSSL_1_1_0
|
||||||
|
SSL_CTX_set_min_proto_version(ctx->context, vmin);
|
||||||
|
SSL_CTX_set_max_proto_version(ctx->context, vmax);
|
||||||
|
#endif
|
||||||
ctx->mode = LSEC_MODE_INVALID;
|
ctx->mode = LSEC_MODE_INVALID;
|
||||||
ctx->L = L;
|
ctx->L = L;
|
||||||
luaL_getmetatable(L, "SSL:Context");
|
luaL_getmetatable(L, "SSL:Context");
|
||||||
@ -449,14 +438,31 @@ static int set_cipher(lua_State *L)
|
|||||||
const char *list = luaL_checkstring(L, 2);
|
const char *list = luaL_checkstring(L, 2);
|
||||||
if (SSL_CTX_set_cipher_list(ctx, list) != 1) {
|
if (SSL_CTX_set_cipher_list(ctx, list) != 1) {
|
||||||
lua_pushboolean(L, 0);
|
lua_pushboolean(L, 0);
|
||||||
lua_pushfstring(L, "error setting cipher list (%s)",
|
lua_pushfstring(L, "error setting cipher list (%s)", ERR_reason_error_string(ERR_get_error()));
|
||||||
ERR_reason_error_string(ERR_get_error()));
|
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
lua_pushboolean(L, 1);
|
lua_pushboolean(L, 1);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the cipher suites.
|
||||||
|
*/
|
||||||
|
static int set_ciphersuites(lua_State *L)
|
||||||
|
{
|
||||||
|
#if defined(TLS1_3_VERSION)
|
||||||
|
SSL_CTX *ctx = lsec_checkcontext(L, 1);
|
||||||
|
const char *list = luaL_checkstring(L, 2);
|
||||||
|
if (SSL_CTX_set_ciphersuites(ctx, list) != 1) {
|
||||||
|
lua_pushboolean(L, 0);
|
||||||
|
lua_pushfstring(L, "error setting cipher list (%s)", ERR_reason_error_string(ERR_get_error()));
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
lua_pushboolean(L, 1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the depth for certificate checking.
|
* Set the depth for certificate checking.
|
||||||
*/
|
*/
|
||||||
@ -505,12 +511,6 @@ static int set_options(lua_State *L)
|
|||||||
if (max > 1) {
|
if (max > 1) {
|
||||||
for (i = 2; i <= max; i++) {
|
for (i = 2; i <= max; i++) {
|
||||||
str = luaL_checkstring(L, i);
|
str = luaL_checkstring(L, i);
|
||||||
#if !defined(SSL_OP_NO_COMPRESSION) && (OPENSSL_VERSION_NUMBER >= 0x0090800f) && (OPENSSL_VERSION_NUMBER < 0x1000000fL)
|
|
||||||
/* Version 0.9.8 has a different way to disable compression */
|
|
||||||
if (!strcmp(str, "no_compression"))
|
|
||||||
ctx->comp_methods = NULL;
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
if (!set_option_flag(str, &flag)) {
|
if (!set_option_flag(str, &flag)) {
|
||||||
lua_pushboolean(L, 0);
|
lua_pushboolean(L, 0);
|
||||||
lua_pushfstring(L, "invalid option (%s)", str);
|
lua_pushfstring(L, "invalid option (%s)", str);
|
||||||
@ -562,27 +562,24 @@ static int set_dhparam(lua_State *L)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined(OPENSSL_NO_EC)
|
||||||
/**
|
/**
|
||||||
* Set elliptic curve.
|
* Set elliptic curve.
|
||||||
*/
|
*/
|
||||||
#ifdef OPENSSL_NO_ECDH
|
|
||||||
static int set_curve(lua_State *L)
|
|
||||||
{
|
|
||||||
lua_pushboolean(L, 0);
|
|
||||||
lua_pushstring(L, "OpenSSL does not support ECDH");
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
static int set_curve(lua_State *L)
|
static int set_curve(lua_State *L)
|
||||||
{
|
{
|
||||||
long ret;
|
long ret;
|
||||||
|
EC_KEY *key = NULL;
|
||||||
SSL_CTX *ctx = lsec_checkcontext(L, 1);
|
SSL_CTX *ctx = lsec_checkcontext(L, 1);
|
||||||
const char *str = luaL_checkstring(L, 2);
|
const char *str = luaL_checkstring(L, 2);
|
||||||
EC_KEY *key = find_ec_key(str);
|
|
||||||
|
SSL_CTX_set_options(ctx, SSL_OP_SINGLE_ECDH_USE);
|
||||||
|
|
||||||
|
key = lsec_find_ec_key(L, str);
|
||||||
|
|
||||||
if (!key) {
|
if (!key) {
|
||||||
lua_pushboolean(L, 0);
|
lua_pushboolean(L, 0);
|
||||||
lua_pushfstring(L, "elliptic curve %s not supported", str);
|
lua_pushfstring(L, "elliptic curve '%s' not supported", str);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -596,9 +593,289 @@ static int set_curve(lua_State *L)
|
|||||||
ERR_reason_error_string(ERR_get_error()));
|
ERR_reason_error_string(ERR_get_error()));
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_pushboolean(L, 1);
|
lua_pushboolean(L, 1);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set elliptic curves list.
|
||||||
|
*/
|
||||||
|
static int set_curves_list(lua_State *L)
|
||||||
|
{
|
||||||
|
SSL_CTX *ctx = lsec_checkcontext(L, 1);
|
||||||
|
const char *str = luaL_checkstring(L, 2);
|
||||||
|
|
||||||
|
SSL_CTX_set_options(ctx, SSL_OP_SINGLE_ECDH_USE);
|
||||||
|
|
||||||
|
if (SSL_CTX_set1_curves_list(ctx, str) != 1) {
|
||||||
|
lua_pushboolean(L, 0);
|
||||||
|
lua_pushfstring(L, "unknown elliptic curve in \"%s\"", str);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(LIBRESSL_VERSION_NUMBER) || !defined(LSEC_API_OPENSSL_1_1_0)
|
||||||
|
(void)SSL_CTX_set_ecdh_auto(ctx, 1);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
lua_pushboolean(L, 1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the protocols a client should send for ALPN.
|
||||||
|
*/
|
||||||
|
static int set_alpn(lua_State *L)
|
||||||
|
{
|
||||||
|
long ret;
|
||||||
|
size_t len;
|
||||||
|
p_context ctx = checkctx(L, 1);
|
||||||
|
const char *str = luaL_checklstring(L, 2, &len);
|
||||||
|
|
||||||
|
ret = SSL_CTX_set_alpn_protos(ctx->context, (const unsigned char*)str, len);
|
||||||
|
if (ret) {
|
||||||
|
lua_pushboolean(L, 0);
|
||||||
|
lua_pushfstring(L, "error setting ALPN (%s)", ERR_reason_error_string(ERR_get_error()));
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
lua_pushboolean(L, 1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This standard callback calls the server's callback in Lua sapce.
|
||||||
|
* The server has to return a list in wire-format strings.
|
||||||
|
* This function uses a helper function to match server and client lists.
|
||||||
|
*/
|
||||||
|
static int alpn_cb(SSL *s, const unsigned char **out, unsigned char *outlen,
|
||||||
|
const unsigned char *in, unsigned int inlen, void *arg)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
size_t server_len;
|
||||||
|
const char *server;
|
||||||
|
p_context ctx = (p_context)arg;
|
||||||
|
lua_State *L = ctx->L;
|
||||||
|
|
||||||
|
luaL_getmetatable(L, "SSL:ALPN:Registry");
|
||||||
|
lua_pushlightuserdata(L, (void*)ctx->context);
|
||||||
|
lua_gettable(L, -2);
|
||||||
|
|
||||||
|
lua_pushlstring(L, (const char*)in, inlen);
|
||||||
|
|
||||||
|
lua_call(L, 1, 1);
|
||||||
|
|
||||||
|
if (!lua_isstring(L, -1)) {
|
||||||
|
lua_pop(L, 2);
|
||||||
|
return SSL_TLSEXT_ERR_NOACK;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Protocol list from server in wire-format string
|
||||||
|
server = luaL_checklstring(L, -1, &server_len);
|
||||||
|
ret = SSL_select_next_proto((unsigned char**)out, outlen, (const unsigned char*)server,
|
||||||
|
server_len, in, inlen);
|
||||||
|
if (ret != OPENSSL_NPN_NEGOTIATED) {
|
||||||
|
lua_pop(L, 2);
|
||||||
|
return SSL_TLSEXT_ERR_NOACK;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy the result because lua_pop() can collect the pointer
|
||||||
|
ctx->alpn = malloc(*outlen);
|
||||||
|
memcpy(ctx->alpn, (void*)*out, *outlen);
|
||||||
|
*out = (const unsigned char*)ctx->alpn;
|
||||||
|
|
||||||
|
lua_pop(L, 2);
|
||||||
|
|
||||||
|
return SSL_TLSEXT_ERR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a callback a server can use to select the next protocol with ALPN.
|
||||||
|
*/
|
||||||
|
static int set_alpn_cb(lua_State *L)
|
||||||
|
{
|
||||||
|
p_context ctx = checkctx(L, 1);
|
||||||
|
|
||||||
|
luaL_getmetatable(L, "SSL:ALPN:Registry");
|
||||||
|
lua_pushlightuserdata(L, (void*)ctx->context);
|
||||||
|
lua_pushvalue(L, 2);
|
||||||
|
lua_settable(L, -3);
|
||||||
|
|
||||||
|
SSL_CTX_set_alpn_select_cb(ctx->context, alpn_cb, ctx);
|
||||||
|
|
||||||
|
lua_pushboolean(L, 1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(LSEC_ENABLE_PSK)
|
||||||
|
/**
|
||||||
|
* Callback to select the PSK.
|
||||||
|
*/
|
||||||
|
static unsigned int server_psk_cb(SSL *ssl, const char *identity, unsigned char *psk,
|
||||||
|
unsigned int max_psk_len)
|
||||||
|
{
|
||||||
|
size_t psk_len;
|
||||||
|
const char *ret_psk;
|
||||||
|
SSL_CTX *ctx = SSL_get_SSL_CTX(ssl);
|
||||||
|
p_context pctx = (p_context)SSL_CTX_get_app_data(ctx);
|
||||||
|
lua_State *L = pctx->L;
|
||||||
|
|
||||||
|
luaL_getmetatable(L, "SSL:PSK:Registry");
|
||||||
|
lua_pushlightuserdata(L, (void*)pctx->context);
|
||||||
|
lua_gettable(L, -2);
|
||||||
|
|
||||||
|
lua_pushstring(L, identity);
|
||||||
|
lua_pushinteger(L, max_psk_len);
|
||||||
|
|
||||||
|
lua_call(L, 2, 1);
|
||||||
|
|
||||||
|
if (!lua_isstring(L, -1)) {
|
||||||
|
lua_pop(L, 2);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret_psk = lua_tolstring(L, -1, &psk_len);
|
||||||
|
|
||||||
|
if (psk_len == 0 || psk_len > max_psk_len)
|
||||||
|
psk_len = 0;
|
||||||
|
else
|
||||||
|
memcpy(psk, ret_psk, psk_len);
|
||||||
|
|
||||||
|
lua_pop(L, 2);
|
||||||
|
|
||||||
|
return psk_len;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a PSK callback for server.
|
||||||
|
*/
|
||||||
|
static int set_server_psk_cb(lua_State *L)
|
||||||
|
{
|
||||||
|
p_context ctx = checkctx(L, 1);
|
||||||
|
|
||||||
|
luaL_getmetatable(L, "SSL:PSK:Registry");
|
||||||
|
lua_pushlightuserdata(L, (void*)ctx->context);
|
||||||
|
lua_pushvalue(L, 2);
|
||||||
|
lua_settable(L, -3);
|
||||||
|
|
||||||
|
SSL_CTX_set_psk_server_callback(ctx->context, server_psk_cb);
|
||||||
|
|
||||||
|
lua_pushboolean(L, 1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set the PSK indentity hint.
|
||||||
|
*/
|
||||||
|
static int set_psk_identity_hint(lua_State *L)
|
||||||
|
{
|
||||||
|
p_context ctx = checkctx(L, 1);
|
||||||
|
const char *hint = luaL_checkstring(L, 2);
|
||||||
|
int ret = SSL_CTX_use_psk_identity_hint(ctx->context, hint);
|
||||||
|
lua_pushboolean(L, ret);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Client callback to PSK.
|
||||||
|
*/
|
||||||
|
static unsigned int client_psk_cb(SSL *ssl, const char *hint, char *identity,
|
||||||
|
unsigned int max_identity_len, unsigned char *psk, unsigned int max_psk_len)
|
||||||
|
{
|
||||||
|
size_t psk_len;
|
||||||
|
size_t identity_len;
|
||||||
|
const char *ret_psk;
|
||||||
|
const char *ret_identity;
|
||||||
|
SSL_CTX *ctx = SSL_get_SSL_CTX(ssl);
|
||||||
|
p_context pctx = (p_context)SSL_CTX_get_app_data(ctx);
|
||||||
|
lua_State *L = pctx->L;
|
||||||
|
|
||||||
|
luaL_getmetatable(L, "SSL:PSK:Registry");
|
||||||
|
lua_pushlightuserdata(L, (void*)pctx->context);
|
||||||
|
lua_gettable(L, -2);
|
||||||
|
|
||||||
|
if (hint)
|
||||||
|
lua_pushstring(L, hint);
|
||||||
|
else
|
||||||
|
lua_pushnil(L);
|
||||||
|
|
||||||
|
// Leave space to '\0'
|
||||||
|
lua_pushinteger(L, max_identity_len-1);
|
||||||
|
lua_pushinteger(L, max_psk_len);
|
||||||
|
|
||||||
|
lua_call(L, 3, 2);
|
||||||
|
|
||||||
|
if (!lua_isstring(L, -1) || !lua_isstring(L, -2)) {
|
||||||
|
lua_pop(L, 3);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret_identity = lua_tolstring(L, -2, &identity_len);
|
||||||
|
ret_psk = lua_tolstring(L, -1, &psk_len);
|
||||||
|
|
||||||
|
if (identity_len >= max_identity_len || psk_len > max_psk_len)
|
||||||
|
psk_len = 0;
|
||||||
|
else {
|
||||||
|
memcpy(identity, ret_identity, identity_len);
|
||||||
|
identity[identity_len] = 0;
|
||||||
|
memcpy(psk, ret_psk, psk_len);
|
||||||
|
}
|
||||||
|
|
||||||
|
lua_pop(L, 3);
|
||||||
|
|
||||||
|
return psk_len;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a PSK callback for client.
|
||||||
|
*/
|
||||||
|
static int set_client_psk_cb(lua_State *L) {
|
||||||
|
p_context ctx = checkctx(L, 1);
|
||||||
|
|
||||||
|
luaL_getmetatable(L, "SSL:PSK:Registry");
|
||||||
|
lua_pushlightuserdata(L, (void*)ctx->context);
|
||||||
|
lua_pushvalue(L, 2);
|
||||||
|
lua_settable(L, -3);
|
||||||
|
|
||||||
|
SSL_CTX_set_psk_client_callback(ctx->context, client_psk_cb);
|
||||||
|
|
||||||
|
lua_pushboolean(L, 1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(LSEC_ENABLE_DANE)
|
||||||
|
/*
|
||||||
|
* DANE
|
||||||
|
*/
|
||||||
|
static int dane_options[] = {
|
||||||
|
/* TODO move into options.c
|
||||||
|
* however this symbol is not from openssl/ssl.h but rather from
|
||||||
|
* openssl/x509_vfy.h
|
||||||
|
* */
|
||||||
|
#ifdef DANE_FLAG_NO_DANE_EE_NAMECHECKS
|
||||||
|
DANE_FLAG_NO_DANE_EE_NAMECHECKS,
|
||||||
|
#endif
|
||||||
|
0
|
||||||
|
};
|
||||||
|
static const char *dane_option_names[] = {
|
||||||
|
#ifdef DANE_FLAG_NO_DANE_EE_NAMECHECKS
|
||||||
|
"no_ee_namechecks",
|
||||||
|
#endif
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
static int set_dane(lua_State *L)
|
||||||
|
{
|
||||||
|
int ret, i;
|
||||||
|
SSL_CTX *ctx = lsec_checkcontext(L, 1);
|
||||||
|
ret = SSL_CTX_dane_enable(ctx);
|
||||||
|
for (i = 2; ret > 0 && i <= lua_gettop(L); i++) {
|
||||||
|
ret = SSL_CTX_dane_set_flags(ctx, dane_options[luaL_checkoption(L, i, NULL, dane_option_names)]);
|
||||||
|
}
|
||||||
|
lua_pushboolean(L, (ret > 0));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -610,13 +887,27 @@ static luaL_Reg funcs[] = {
|
|||||||
{"loadcert", load_cert},
|
{"loadcert", load_cert},
|
||||||
{"loadkey", load_key},
|
{"loadkey", load_key},
|
||||||
{"checkkey", check_key},
|
{"checkkey", check_key},
|
||||||
|
{"setalpn", set_alpn},
|
||||||
|
{"setalpncb", set_alpn_cb},
|
||||||
{"setcipher", set_cipher},
|
{"setcipher", set_cipher},
|
||||||
|
{"setciphersuites", set_ciphersuites},
|
||||||
{"setdepth", set_depth},
|
{"setdepth", set_depth},
|
||||||
{"setdhparam", set_dhparam},
|
{"setdhparam", set_dhparam},
|
||||||
{"setcurve", set_curve},
|
|
||||||
{"setverify", set_verify},
|
{"setverify", set_verify},
|
||||||
{"setoptions", set_options},
|
{"setoptions", set_options},
|
||||||
|
#if defined(LSEC_ENABLE_PSK)
|
||||||
|
{"setpskhint", set_psk_identity_hint},
|
||||||
|
{"setserverpskcb", set_server_psk_cb},
|
||||||
|
{"setclientpskcb", set_client_psk_cb},
|
||||||
|
#endif
|
||||||
{"setmode", set_mode},
|
{"setmode", set_mode},
|
||||||
|
#if !defined(OPENSSL_NO_EC)
|
||||||
|
{"setcurve", set_curve},
|
||||||
|
{"setcurveslist", set_curves_list},
|
||||||
|
#endif
|
||||||
|
#if defined(LSEC_ENABLE_DANE)
|
||||||
|
{"setdane", set_dane},
|
||||||
|
#endif
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -638,15 +929,18 @@ static int meth_destroy(lua_State *L)
|
|||||||
lua_pushlightuserdata(L, (void*)ctx->context);
|
lua_pushlightuserdata(L, (void*)ctx->context);
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
lua_settable(L, -3);
|
lua_settable(L, -3);
|
||||||
|
luaL_getmetatable(L, "SSL:ALPN:Registry");
|
||||||
|
lua_pushlightuserdata(L, (void*)ctx->context);
|
||||||
|
lua_pushnil(L);
|
||||||
|
lua_settable(L, -3);
|
||||||
|
luaL_getmetatable(L, "SSL:PSK:Registry");
|
||||||
|
lua_pushlightuserdata(L, (void*)ctx->context);
|
||||||
|
lua_pushnil(L);
|
||||||
|
lua_settable(L, -3);
|
||||||
|
|
||||||
SSL_CTX_free(ctx->context);
|
SSL_CTX_free(ctx->context);
|
||||||
ctx->context = NULL;
|
ctx->context = NULL;
|
||||||
}
|
}
|
||||||
if (ctx->dh_param) {
|
|
||||||
DH_free(ctx->dh_param);
|
|
||||||
ctx->dh_param = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -718,6 +1012,7 @@ static int meth_set_verify_ext(lua_State *L)
|
|||||||
* Context metamethods.
|
* Context metamethods.
|
||||||
*/
|
*/
|
||||||
static luaL_Reg meta[] = {
|
static luaL_Reg meta[] = {
|
||||||
|
{"__close", meth_destroy},
|
||||||
{"__gc", meth_destroy},
|
{"__gc", meth_destroy},
|
||||||
{"__tostring", meth_tostring},
|
{"__tostring", meth_tostring},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
@ -758,6 +1053,25 @@ int lsec_getmode(lua_State *L, int idx)
|
|||||||
return ctx->mode;
|
return ctx->mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*-- Compat - Lua 5.1 --*/
|
||||||
|
#if (LUA_VERSION_NUM == 501)
|
||||||
|
|
||||||
|
void *lsec_testudata (lua_State *L, int ud, const char *tname) {
|
||||||
|
void *p = lua_touserdata(L, ud);
|
||||||
|
if (p != NULL) { /* value is a userdata? */
|
||||||
|
if (lua_getmetatable(L, ud)) { /* does it have a metatable? */
|
||||||
|
luaL_getmetatable(L, tname); /* get correct metatable */
|
||||||
|
if (!lua_rawequal(L, -1, -2)) /* not the same? */
|
||||||
|
p = NULL; /* value is a userdata with wrong metatable */
|
||||||
|
lua_pop(L, 2); /* remove both metatables */
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL; /* value is not a userdata with a metatable */
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/*------------------------------ Initialization ------------------------------*/
|
/*------------------------------ Initialization ------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -766,6 +1080,8 @@ int lsec_getmode(lua_State *L, int idx)
|
|||||||
LSEC_API int luaopen_ssl_context(lua_State *L)
|
LSEC_API int luaopen_ssl_context(lua_State *L)
|
||||||
{
|
{
|
||||||
luaL_newmetatable(L, "SSL:DH:Registry"); /* Keep all DH callbacks */
|
luaL_newmetatable(L, "SSL:DH:Registry"); /* Keep all DH callbacks */
|
||||||
|
luaL_newmetatable(L, "SSL:ALPN:Registry"); /* Keep all ALPN callbacks */
|
||||||
|
luaL_newmetatable(L, "SSL:PSK:Registry"); /* Keep all PSK callbacks */
|
||||||
luaL_newmetatable(L, "SSL:Verify:Registry"); /* Keep all verify flags */
|
luaL_newmetatable(L, "SSL:Verify:Registry"); /* Keep all verify flags */
|
||||||
luaL_newmetatable(L, "SSL:Context");
|
luaL_newmetatable(L, "SSL:Context");
|
||||||
setfuncs(L, meta);
|
setfuncs(L, meta);
|
||||||
@ -774,6 +1090,8 @@ LSEC_API int luaopen_ssl_context(lua_State *L)
|
|||||||
luaL_newlib(L, meta_index);
|
luaL_newlib(L, meta_index);
|
||||||
lua_setfield(L, -2, "__index");
|
lua_setfield(L, -2, "__index");
|
||||||
|
|
||||||
|
lsec_load_curves(L);
|
||||||
|
|
||||||
/* Return the module */
|
/* Return the module */
|
||||||
luaL_newlib(L, funcs);
|
luaL_newlib(L, funcs);
|
||||||
|
|
||||||
|
@ -2,15 +2,16 @@
|
|||||||
#define LSEC_CONTEXT_H
|
#define LSEC_CONTEXT_H
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------
|
||||||
* LuaSec 0.6
|
* LuaSec 1.3.2
|
||||||
* Copyright (C) 2006-2016 Bruno Silvestre
|
*
|
||||||
|
* Copyright (C) 2006-2023 Bruno Silvestre
|
||||||
*
|
*
|
||||||
*--------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include <lua.h>
|
#include <lua.h>
|
||||||
#include <openssl/ssl.h>
|
#include <openssl/ssl.h>
|
||||||
|
|
||||||
#include "config.h"
|
#include "compat.h"
|
||||||
|
|
||||||
#define LSEC_MODE_INVALID 0
|
#define LSEC_MODE_INVALID 0
|
||||||
#define LSEC_MODE_SERVER 1
|
#define LSEC_MODE_SERVER 1
|
||||||
@ -23,6 +24,7 @@ typedef struct t_context_ {
|
|||||||
SSL_CTX *context;
|
SSL_CTX *context;
|
||||||
lua_State *L;
|
lua_State *L;
|
||||||
DH *dh_param;
|
DH *dh_param;
|
||||||
|
void *alpn;
|
||||||
int mode;
|
int mode;
|
||||||
} t_context;
|
} t_context;
|
||||||
typedef t_context* p_context;
|
typedef t_context* p_context;
|
||||||
@ -37,4 +39,9 @@ int lsec_getmode(lua_State *L, int idx);
|
|||||||
/* Registre the module. */
|
/* Registre the module. */
|
||||||
LSEC_API int luaopen_ssl_context(lua_State *L);
|
LSEC_API int luaopen_ssl_context(lua_State *L);
|
||||||
|
|
||||||
|
/* Compat - Lua 5.1 */
|
||||||
|
#if (LUA_VERSION_NUM == 501)
|
||||||
|
void *lsec_testudata (lua_State *L, int ud, const char *tname);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
116
src/ec.c
Normal file
116
src/ec.c
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
/*--------------------------------------------------------------------------
|
||||||
|
* LuaSec 1.3.2
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2023 Bruno Silvestre
|
||||||
|
*
|
||||||
|
*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include <openssl/objects.h>
|
||||||
|
|
||||||
|
#include "ec.h"
|
||||||
|
|
||||||
|
#ifndef OPENSSL_NO_EC
|
||||||
|
|
||||||
|
EC_KEY *lsec_find_ec_key(lua_State *L, const char *str)
|
||||||
|
{
|
||||||
|
int nid;
|
||||||
|
lua_pushstring(L, "SSL:EC:CURVES");
|
||||||
|
lua_rawget(L, LUA_REGISTRYINDEX);
|
||||||
|
lua_pushstring(L, str);
|
||||||
|
lua_rawget(L, -2);
|
||||||
|
|
||||||
|
if (!lua_isnumber(L, -1))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
nid = (int)lua_tonumber(L, -1);
|
||||||
|
return EC_KEY_new_by_curve_name(nid);
|
||||||
|
}
|
||||||
|
|
||||||
|
void lsec_load_curves(lua_State *L)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
size_t size;
|
||||||
|
const char *name;
|
||||||
|
EC_builtin_curve *curves = NULL;
|
||||||
|
|
||||||
|
lua_pushstring(L, "SSL:EC:CURVES");
|
||||||
|
lua_newtable(L);
|
||||||
|
|
||||||
|
size = EC_get_builtin_curves(NULL, 0);
|
||||||
|
if (size > 0) {
|
||||||
|
curves = (EC_builtin_curve*)malloc(sizeof(EC_builtin_curve) * size);
|
||||||
|
EC_get_builtin_curves(curves, size);
|
||||||
|
for (i = 0; i < size; i++) {
|
||||||
|
name = OBJ_nid2sn(curves[i].nid);
|
||||||
|
if (name != NULL) {
|
||||||
|
lua_pushstring(L, name);
|
||||||
|
lua_pushnumber(L, curves[i].nid);
|
||||||
|
lua_rawset(L, -3);
|
||||||
|
}
|
||||||
|
switch (curves[i].nid) {
|
||||||
|
case NID_X9_62_prime256v1:
|
||||||
|
lua_pushstring(L, "P-256");
|
||||||
|
lua_pushnumber(L, curves[i].nid);
|
||||||
|
lua_rawset(L, -3);
|
||||||
|
break;
|
||||||
|
case NID_secp384r1:
|
||||||
|
lua_pushstring(L, "P-384");
|
||||||
|
lua_pushnumber(L, curves[i].nid);
|
||||||
|
lua_rawset(L, -3);
|
||||||
|
break;
|
||||||
|
case NID_secp521r1:
|
||||||
|
lua_pushstring(L, "P-521");
|
||||||
|
lua_pushnumber(L, curves[i].nid);
|
||||||
|
lua_rawset(L, -3);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(curves);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* These are special so are manually added here */
|
||||||
|
#ifdef NID_X25519
|
||||||
|
lua_pushstring(L, "X25519");
|
||||||
|
lua_pushnumber(L, NID_X25519);
|
||||||
|
lua_rawset(L, -3);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef NID_X448
|
||||||
|
lua_pushstring(L, "X448");
|
||||||
|
lua_pushnumber(L, NID_X448);
|
||||||
|
lua_rawset(L, -3);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
lua_rawset(L, LUA_REGISTRYINDEX);
|
||||||
|
}
|
||||||
|
|
||||||
|
void lsec_get_curves(lua_State *L)
|
||||||
|
{
|
||||||
|
lua_newtable(L);
|
||||||
|
|
||||||
|
lua_pushstring(L, "SSL:EC:CURVES");
|
||||||
|
lua_rawget(L, LUA_REGISTRYINDEX);
|
||||||
|
|
||||||
|
lua_pushnil(L);
|
||||||
|
while (lua_next(L, -2) != 0) {
|
||||||
|
lua_pop(L, 1);
|
||||||
|
lua_pushvalue(L, -1);
|
||||||
|
lua_pushboolean(L, 1);
|
||||||
|
lua_rawset(L, -5);
|
||||||
|
}
|
||||||
|
lua_pop(L, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
void lsec_load_curves(lua_State *L)
|
||||||
|
{
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
void lsec_get_curves(lua_State *L)
|
||||||
|
{
|
||||||
|
lua_newtable(L);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
64
src/ec.h
64
src/ec.h
@ -1,64 +1,22 @@
|
|||||||
/*--------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------
|
||||||
* LuaSec 0.6
|
* LuaSec 1.3.2
|
||||||
* Copyright (C) 2006-2016 Bruno Silvestre
|
*
|
||||||
|
* Copyright (C) 2006-2023 Bruno Silvestre
|
||||||
*
|
*
|
||||||
*--------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifndef LSEC_EC_H
|
#ifndef LSEC_EC_H
|
||||||
#define LSEC_EC_H
|
#define LSEC_EC_H
|
||||||
|
|
||||||
#include <openssl/objects.h>
|
#include <lua.h>
|
||||||
|
|
||||||
typedef struct t_ec_ {
|
#ifndef OPENSSL_NO_EC
|
||||||
char *name;
|
#include <openssl/ec.h>
|
||||||
int nid;
|
|
||||||
} t_ec;
|
|
||||||
typedef t_ec* p_ec;
|
|
||||||
|
|
||||||
/* Elliptic curves supported */
|
EC_KEY *lsec_find_ec_key(lua_State *L, const char *str);
|
||||||
static t_ec curves[] = {
|
#endif
|
||||||
/* SECG */
|
|
||||||
{"secp112r1", NID_secp112r1},
|
void lsec_get_curves(lua_State *L);
|
||||||
{"secp112r2", NID_secp112r2},
|
void lsec_load_curves(lua_State *L);
|
||||||
{"secp128r1", NID_secp128r1},
|
|
||||||
{"secp128r2", NID_secp128r2},
|
|
||||||
{"secp160k1", NID_secp160k1},
|
|
||||||
{"secp160r1", NID_secp160r1},
|
|
||||||
{"secp160r2", NID_secp160r2},
|
|
||||||
{"secp192k1", NID_secp192k1},
|
|
||||||
{"secp224k1", NID_secp224k1},
|
|
||||||
{"secp224r1", NID_secp224r1},
|
|
||||||
{"secp256k1", NID_secp256k1},
|
|
||||||
{"secp384r1", NID_secp384r1},
|
|
||||||
{"secp521r1", NID_secp521r1},
|
|
||||||
{"sect113r1", NID_sect113r1},
|
|
||||||
{"sect113r2", NID_sect113r2},
|
|
||||||
{"sect131r1", NID_sect131r1},
|
|
||||||
{"sect131r2", NID_sect131r2},
|
|
||||||
{"sect163k1", NID_sect163k1},
|
|
||||||
{"sect163r1", NID_sect163r1},
|
|
||||||
{"sect163r2", NID_sect163r2},
|
|
||||||
{"sect193r1", NID_sect193r1},
|
|
||||||
{"sect193r2", NID_sect193r2},
|
|
||||||
{"sect233k1", NID_sect233k1},
|
|
||||||
{"sect233r1", NID_sect233r1},
|
|
||||||
{"sect239k1", NID_sect239k1},
|
|
||||||
{"sect283k1", NID_sect283k1},
|
|
||||||
{"sect283r1", NID_sect283r1},
|
|
||||||
{"sect409k1", NID_sect409k1},
|
|
||||||
{"sect409r1", NID_sect409r1},
|
|
||||||
{"sect571k1", NID_sect571k1},
|
|
||||||
{"sect571r1", NID_sect571r1},
|
|
||||||
/* ANSI X9.62 */
|
|
||||||
{"prime192v1", NID_X9_62_prime192v1},
|
|
||||||
{"prime192v2", NID_X9_62_prime192v2},
|
|
||||||
{"prime192v3", NID_X9_62_prime192v3},
|
|
||||||
{"prime239v1", NID_X9_62_prime239v1},
|
|
||||||
{"prime239v2", NID_X9_62_prime239v2},
|
|
||||||
{"prime239v3", NID_X9_62_prime239v3},
|
|
||||||
{"prime256v1", NID_X9_62_prime256v1},
|
|
||||||
/* End */
|
|
||||||
{NULL, 0U}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
----------------------------------------------------------------------------
|
----------------------------------------------------------------------------
|
||||||
-- LuaSec 0.6
|
-- LuaSec 1.3.2
|
||||||
-- Copyright (C) 2009-2016 PUC-Rio
|
--
|
||||||
|
-- Copyright (C) 2009-2023 PUC-Rio
|
||||||
--
|
--
|
||||||
-- Author: Pablo Musa
|
-- Author: Pablo Musa
|
||||||
-- Author: Tomas Guisasola
|
-- Author: Tomas Guisasola
|
||||||
@ -18,15 +19,16 @@ local try = socket.try
|
|||||||
-- Module
|
-- Module
|
||||||
--
|
--
|
||||||
local _M = {
|
local _M = {
|
||||||
_VERSION = "0.6",
|
_VERSION = "1.3.2",
|
||||||
_COPYRIGHT = "LuaSec 0.6 - Copyright (C) 2009-2016 PUC-Rio",
|
_COPYRIGHT = "LuaSec 1.3.2 - Copyright (C) 2009-2023 PUC-Rio",
|
||||||
PORT = 443,
|
PORT = 443,
|
||||||
|
TIMEOUT = 60
|
||||||
}
|
}
|
||||||
|
|
||||||
-- TLS configuration
|
-- TLS configuration
|
||||||
local cfg = {
|
local cfg = {
|
||||||
protocol = "any",
|
protocol = "any",
|
||||||
options = {"all", "no_sslv2", "no_sslv3"},
|
options = {"all", "no_sslv2", "no_sslv3", "no_tlsv1"},
|
||||||
verify = "none",
|
verify = "none",
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,14 +85,16 @@ local function tcp(params)
|
|||||||
conn.sock = try(socket.tcp())
|
conn.sock = try(socket.tcp())
|
||||||
local st = getmetatable(conn.sock).__index.settimeout
|
local st = getmetatable(conn.sock).__index.settimeout
|
||||||
function conn:settimeout(...)
|
function conn:settimeout(...)
|
||||||
return st(self.sock, ...)
|
return st(self.sock, _M.TIMEOUT)
|
||||||
end
|
end
|
||||||
-- Replace TCP's connection function
|
-- Replace TCP's connection function
|
||||||
function conn:connect(host, port)
|
function conn:connect(host, port)
|
||||||
try(self.sock:connect(host, port))
|
try(self.sock:connect(host, port))
|
||||||
self.sock = try(ssl.wrap(self.sock, params))
|
self.sock = try(ssl.wrap(self.sock, params))
|
||||||
|
self.sock:sni(host)
|
||||||
|
self.sock:settimeout(_M.TIMEOUT)
|
||||||
try(self.sock:dohandshake())
|
try(self.sock:dohandshake())
|
||||||
reg(self, getmetatable(self.sock))
|
reg(self)
|
||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
return conn
|
return conn
|
||||||
@ -138,5 +142,6 @@ end
|
|||||||
--
|
--
|
||||||
|
|
||||||
_M.request = request
|
_M.request = request
|
||||||
|
_M.tcp = tcp
|
||||||
|
|
||||||
return _M
|
return _M
|
||||||
|
@ -78,9 +78,7 @@ int buffer_meth_send(lua_State *L, p_buffer buf) {
|
|||||||
const char *data = luaL_checklstring(L, 2, &size);
|
const char *data = luaL_checklstring(L, 2, &size);
|
||||||
long start = (long) luaL_optnumber(L, 3, 1);
|
long start = (long) luaL_optnumber(L, 3, 1);
|
||||||
long end = (long) luaL_optnumber(L, 4, -1);
|
long end = (long) luaL_optnumber(L, 4, -1);
|
||||||
#ifdef LUASOCKET_DEBUG
|
timeout_markstart(buf->tm);
|
||||||
p_timeout tm = timeout_markstart(buf->tm);
|
|
||||||
#endif
|
|
||||||
if (start < 0) start = (long) (size+start+1);
|
if (start < 0) start = (long) (size+start+1);
|
||||||
if (end < 0) end = (long) (size+end+1);
|
if (end < 0) end = (long) (size+end+1);
|
||||||
if (start < 1) start = (long) 1;
|
if (start < 1) start = (long) 1;
|
||||||
@ -98,7 +96,7 @@ int buffer_meth_send(lua_State *L, p_buffer buf) {
|
|||||||
}
|
}
|
||||||
#ifdef LUASOCKET_DEBUG
|
#ifdef LUASOCKET_DEBUG
|
||||||
/* push time elapsed during operation as the last return value */
|
/* push time elapsed during operation as the last return value */
|
||||||
lua_pushnumber(L, timeout_gettime() - timeout_getstart(tm));
|
lua_pushnumber(L, timeout_gettime() - timeout_getstart(buf->tm));
|
||||||
#endif
|
#endif
|
||||||
return lua_gettop(L) - top;
|
return lua_gettop(L) - top;
|
||||||
}
|
}
|
||||||
@ -107,13 +105,17 @@ int buffer_meth_send(lua_State *L, p_buffer buf) {
|
|||||||
* object:receive() interface
|
* object:receive() interface
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int buffer_meth_receive(lua_State *L, p_buffer buf) {
|
int buffer_meth_receive(lua_State *L, p_buffer buf) {
|
||||||
int err = IO_DONE, top = lua_gettop(L);
|
|
||||||
luaL_Buffer b;
|
luaL_Buffer b;
|
||||||
size_t size;
|
size_t size;
|
||||||
const char *part = luaL_optlstring(L, 3, "", &size);
|
const char *part;
|
||||||
#ifdef LUASOCKET_DEBUG
|
int err = IO_DONE;
|
||||||
p_timeout tm = timeout_markstart(buf->tm);
|
int top = lua_gettop(L);
|
||||||
#endif
|
if (top < 3) {
|
||||||
|
lua_settop(L, 3);
|
||||||
|
top = 3;
|
||||||
|
}
|
||||||
|
part = luaL_optlstring(L, 3, "", &size);
|
||||||
|
timeout_markstart(buf->tm);
|
||||||
/* initialize buffer with optional extra prefix
|
/* initialize buffer with optional extra prefix
|
||||||
* (useful for concatenating previous partial results) */
|
* (useful for concatenating previous partial results) */
|
||||||
luaL_buffinit(L, &b);
|
luaL_buffinit(L, &b);
|
||||||
@ -135,7 +137,7 @@ int buffer_meth_receive(lua_State *L, p_buffer buf) {
|
|||||||
}
|
}
|
||||||
/* check if there was an error */
|
/* check if there was an error */
|
||||||
if (err != IO_DONE) {
|
if (err != IO_DONE) {
|
||||||
/* we can't push anyting in the stack before pushing the
|
/* we can't push anything in the stack before pushing the
|
||||||
* contents of the buffer. this is the reason for the complication */
|
* contents of the buffer. this is the reason for the complication */
|
||||||
luaL_pushresult(&b);
|
luaL_pushresult(&b);
|
||||||
lua_pushstring(L, buf->io->error(buf->io->ctx, err));
|
lua_pushstring(L, buf->io->error(buf->io->ctx, err));
|
||||||
@ -149,7 +151,7 @@ int buffer_meth_receive(lua_State *L, p_buffer buf) {
|
|||||||
}
|
}
|
||||||
#ifdef LUASOCKET_DEBUG
|
#ifdef LUASOCKET_DEBUG
|
||||||
/* push time elapsed during operation as the last return value */
|
/* push time elapsed during operation as the last return value */
|
||||||
lua_pushnumber(L, timeout_gettime() - timeout_getstart(tm));
|
lua_pushnumber(L, timeout_gettime() - timeout_getstart(buf->tm));
|
||||||
#endif
|
#endif
|
||||||
return lua_gettop(L) - top;
|
return lua_gettop(L) - top;
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ typedef int (*p_send) (
|
|||||||
/* interface to recv function */
|
/* interface to recv function */
|
||||||
typedef int (*p_recv) (
|
typedef int (*p_recv) (
|
||||||
void *ctx, /* context needed by recv */
|
void *ctx, /* context needed by recv */
|
||||||
char *data, /* pointer to buffer where data will be writen */
|
char *data, /* pointer to buffer where data will be written */
|
||||||
size_t count, /* number of bytes to receive into buffer */
|
size_t count, /* number of bytes to receive into buffer */
|
||||||
size_t *got, /* number of bytes received uppon return */
|
size_t *got, /* number of bytes received uppon return */
|
||||||
p_timeout tm /* timeout control */
|
p_timeout tm /* timeout control */
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
typedef struct sockaddr SA;
|
typedef struct sockaddr SA;
|
||||||
|
|
||||||
/*=========================================================================*\
|
/*=========================================================================*\
|
||||||
* Functions bellow implement a comfortable platform independent
|
* Functions below implement a comfortable platform independent
|
||||||
* interface to sockets
|
* interface to sockets
|
||||||
\*=========================================================================*/
|
\*=========================================================================*/
|
||||||
int socket_open(void);
|
int socket_open(void);
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
/* timeout control structure */
|
/* timeout control structure */
|
||||||
typedef struct t_timeout_ {
|
typedef struct t_timeout_ {
|
||||||
double block; /* maximum time for blocking calls */
|
double block; /* maximum time for blocking calls */
|
||||||
double total; /* total number of miliseconds for operation */
|
double total; /* total number of milliseconds for operation */
|
||||||
double start; /* time of start of operation */
|
double start; /* time of start of operation */
|
||||||
} t_timeout;
|
} t_timeout;
|
||||||
typedef t_timeout *p_timeout;
|
typedef t_timeout *p_timeout;
|
||||||
|
@ -40,7 +40,7 @@ int socket_waitfd(p_socket ps, int sw, p_timeout tm) {
|
|||||||
if (*ps >= FD_SETSIZE) return EINVAL;
|
if (*ps >= FD_SETSIZE) return EINVAL;
|
||||||
if (timeout_iszero(tm)) return IO_TIMEOUT; /* optimize timeout == 0 case */
|
if (timeout_iszero(tm)) return IO_TIMEOUT; /* optimize timeout == 0 case */
|
||||||
do {
|
do {
|
||||||
/* must set bits within loop, because select may have modifed them */
|
/* must set bits within loop, because select may have modified them */
|
||||||
rp = wp = NULL;
|
rp = wp = NULL;
|
||||||
if (sw & WAITFD_R) { FD_ZERO(&rfds); FD_SET(*ps, &rfds); rp = &rfds; }
|
if (sw & WAITFD_R) { FD_ZERO(&rfds); FD_SET(*ps, &rfds); rp = &rfds; }
|
||||||
if (sw & WAITFD_W) { FD_ZERO(&wfds); FD_SET(*ps, &wfds); wp = &wfds; }
|
if (sw & WAITFD_W) { FD_ZERO(&wfds); FD_SET(*ps, &wfds); wp = &wfds; }
|
||||||
@ -426,7 +426,9 @@ const char *socket_gaistrerror(int err) {
|
|||||||
case EAI_MEMORY: return "memory allocation failure";
|
case EAI_MEMORY: return "memory allocation failure";
|
||||||
case EAI_NONAME:
|
case EAI_NONAME:
|
||||||
return "host or service not provided, or not known";
|
return "host or service not provided, or not known";
|
||||||
|
#ifdef EAI_OVERFLOW
|
||||||
case EAI_OVERFLOW: return "argument buffer overflow";
|
case EAI_OVERFLOW: return "argument buffer overflow";
|
||||||
|
#endif
|
||||||
#ifdef EAI_PROTOCOL
|
#ifdef EAI_PROTOCOL
|
||||||
case EAI_PROTOCOL: return "resolved protocol is unknown";
|
case EAI_PROTOCOL: return "resolved protocol is unknown";
|
||||||
#endif
|
#endif
|
||||||
|
185
src/options.c
Normal file
185
src/options.c
Normal file
@ -0,0 +1,185 @@
|
|||||||
|
/*--------------------------------------------------------------------------
|
||||||
|
* LuaSec 1.3.2
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2023 Bruno Silvestre
|
||||||
|
*
|
||||||
|
*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include <openssl/ssl.h>
|
||||||
|
|
||||||
|
#include "options.h"
|
||||||
|
|
||||||
|
/* If you need to generate these options again, see options.lua */
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
OpenSSL version: OpenSSL 3.0.8
|
||||||
|
*/
|
||||||
|
|
||||||
|
static lsec_ssl_option_t ssl_options[] = {
|
||||||
|
#if defined(SSL_OP_ALL)
|
||||||
|
{"all", SSL_OP_ALL},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_ALLOW_CLIENT_RENEGOTIATION)
|
||||||
|
{"allow_client_renegotiation", SSL_OP_ALLOW_CLIENT_RENEGOTIATION},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_ALLOW_NO_DHE_KEX)
|
||||||
|
{"allow_no_dhe_kex", SSL_OP_ALLOW_NO_DHE_KEX},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION)
|
||||||
|
{"allow_unsafe_legacy_renegotiation", SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_CIPHER_SERVER_PREFERENCE)
|
||||||
|
{"cipher_server_preference", SSL_OP_CIPHER_SERVER_PREFERENCE},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_CISCO_ANYCONNECT)
|
||||||
|
{"cisco_anyconnect", SSL_OP_CISCO_ANYCONNECT},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_CLEANSE_PLAINTEXT)
|
||||||
|
{"cleanse_plaintext", SSL_OP_CLEANSE_PLAINTEXT},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_COOKIE_EXCHANGE)
|
||||||
|
{"cookie_exchange", SSL_OP_COOKIE_EXCHANGE},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_CRYPTOPRO_TLSEXT_BUG)
|
||||||
|
{"cryptopro_tlsext_bug", SSL_OP_CRYPTOPRO_TLSEXT_BUG},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_DISABLE_TLSEXT_CA_NAMES)
|
||||||
|
{"disable_tlsext_ca_names", SSL_OP_DISABLE_TLSEXT_CA_NAMES},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS)
|
||||||
|
{"dont_insert_empty_fragments", SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_ENABLE_KTLS)
|
||||||
|
{"enable_ktls", SSL_OP_ENABLE_KTLS},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_ENABLE_MIDDLEBOX_COMPAT)
|
||||||
|
{"enable_middlebox_compat", SSL_OP_ENABLE_MIDDLEBOX_COMPAT},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_EPHEMERAL_RSA)
|
||||||
|
{"ephemeral_rsa", SSL_OP_EPHEMERAL_RSA},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_IGNORE_UNEXPECTED_EOF)
|
||||||
|
{"ignore_unexpected_eof", SSL_OP_IGNORE_UNEXPECTED_EOF},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_LEGACY_SERVER_CONNECT)
|
||||||
|
{"legacy_server_connect", SSL_OP_LEGACY_SERVER_CONNECT},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER)
|
||||||
|
{"microsoft_big_sslv3_buffer", SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_MICROSOFT_SESS_ID_BUG)
|
||||||
|
{"microsoft_sess_id_bug", SSL_OP_MICROSOFT_SESS_ID_BUG},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_MSIE_SSLV2_RSA_PADDING)
|
||||||
|
{"msie_sslv2_rsa_padding", SSL_OP_MSIE_SSLV2_RSA_PADDING},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_NETSCAPE_CA_DN_BUG)
|
||||||
|
{"netscape_ca_dn_bug", SSL_OP_NETSCAPE_CA_DN_BUG},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_NETSCAPE_CHALLENGE_BUG)
|
||||||
|
{"netscape_challenge_bug", SSL_OP_NETSCAPE_CHALLENGE_BUG},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG)
|
||||||
|
{"netscape_demo_cipher_change_bug", SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG)
|
||||||
|
{"netscape_reuse_cipher_change_bug", SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_NO_ANTI_REPLAY)
|
||||||
|
{"no_anti_replay", SSL_OP_NO_ANTI_REPLAY},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_NO_COMPRESSION)
|
||||||
|
{"no_compression", SSL_OP_NO_COMPRESSION},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_NO_DTLS_MASK)
|
||||||
|
{"no_dtls_mask", SSL_OP_NO_DTLS_MASK},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_NO_DTLSv1)
|
||||||
|
{"no_dtlsv1", SSL_OP_NO_DTLSv1},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_NO_DTLSv1_2)
|
||||||
|
{"no_dtlsv1_2", SSL_OP_NO_DTLSv1_2},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_NO_ENCRYPT_THEN_MAC)
|
||||||
|
{"no_encrypt_then_mac", SSL_OP_NO_ENCRYPT_THEN_MAC},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_NO_EXTENDED_MASTER_SECRET)
|
||||||
|
{"no_extended_master_secret", SSL_OP_NO_EXTENDED_MASTER_SECRET},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_NO_QUERY_MTU)
|
||||||
|
{"no_query_mtu", SSL_OP_NO_QUERY_MTU},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_NO_RENEGOTIATION)
|
||||||
|
{"no_renegotiation", SSL_OP_NO_RENEGOTIATION},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION)
|
||||||
|
{"no_session_resumption_on_renegotiation", SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_NO_SSL_MASK)
|
||||||
|
{"no_ssl_mask", SSL_OP_NO_SSL_MASK},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_NO_SSLv2)
|
||||||
|
{"no_sslv2", SSL_OP_NO_SSLv2},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_NO_SSLv3)
|
||||||
|
{"no_sslv3", SSL_OP_NO_SSLv3},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_NO_TICKET)
|
||||||
|
{"no_ticket", SSL_OP_NO_TICKET},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_NO_TLSv1)
|
||||||
|
{"no_tlsv1", SSL_OP_NO_TLSv1},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_NO_TLSv1_1)
|
||||||
|
{"no_tlsv1_1", SSL_OP_NO_TLSv1_1},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_NO_TLSv1_2)
|
||||||
|
{"no_tlsv1_2", SSL_OP_NO_TLSv1_2},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_NO_TLSv1_3)
|
||||||
|
{"no_tlsv1_3", SSL_OP_NO_TLSv1_3},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_PKCS1_CHECK_1)
|
||||||
|
{"pkcs1_check_1", SSL_OP_PKCS1_CHECK_1},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_PKCS1_CHECK_2)
|
||||||
|
{"pkcs1_check_2", SSL_OP_PKCS1_CHECK_2},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_PRIORITIZE_CHACHA)
|
||||||
|
{"prioritize_chacha", SSL_OP_PRIORITIZE_CHACHA},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_SAFARI_ECDHE_ECDSA_BUG)
|
||||||
|
{"safari_ecdhe_ecdsa_bug", SSL_OP_SAFARI_ECDHE_ECDSA_BUG},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_SINGLE_DH_USE)
|
||||||
|
{"single_dh_use", SSL_OP_SINGLE_DH_USE},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_SINGLE_ECDH_USE)
|
||||||
|
{"single_ecdh_use", SSL_OP_SINGLE_ECDH_USE},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_SSLEAY_080_CLIENT_DH_BUG)
|
||||||
|
{"ssleay_080_client_dh_bug", SSL_OP_SSLEAY_080_CLIENT_DH_BUG},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG)
|
||||||
|
{"sslref2_reuse_cert_type_bug", SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_TLSEXT_PADDING)
|
||||||
|
{"tlsext_padding", SSL_OP_TLSEXT_PADDING},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_TLS_BLOCK_PADDING_BUG)
|
||||||
|
{"tls_block_padding_bug", SSL_OP_TLS_BLOCK_PADDING_BUG},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_TLS_D5_BUG)
|
||||||
|
{"tls_d5_bug", SSL_OP_TLS_D5_BUG},
|
||||||
|
#endif
|
||||||
|
#if defined(SSL_OP_TLS_ROLLBACK_BUG)
|
||||||
|
{"tls_rollback_bug", SSL_OP_TLS_ROLLBACK_BUG},
|
||||||
|
#endif
|
||||||
|
{NULL, 0L}
|
||||||
|
};
|
||||||
|
|
||||||
|
LSEC_API lsec_ssl_option_t* lsec_get_ssl_options() {
|
||||||
|
return ssl_options;
|
||||||
|
}
|
||||||
|
|
140
src/options.h
140
src/options.h
@ -2,145 +2,21 @@
|
|||||||
#define LSEC_OPTIONS_H
|
#define LSEC_OPTIONS_H
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------
|
||||||
* LuaSec 0.6
|
* LuaSec 1.3.2
|
||||||
* Copyright (C) 2006-2016 Bruno Silvestre
|
*
|
||||||
|
* Copyright (C) 2006-2023 Bruno Silvestre
|
||||||
*
|
*
|
||||||
*--------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include <openssl/ssl.h>
|
#include "compat.h"
|
||||||
|
|
||||||
/* If you need to generate these options again, see options.lua */
|
struct lsec_ssl_option_s {
|
||||||
|
|
||||||
/*
|
|
||||||
OpenSSL version: OpenSSL 1.0.2f
|
|
||||||
*/
|
|
||||||
|
|
||||||
struct ssl_option_s {
|
|
||||||
const char *name;
|
const char *name;
|
||||||
unsigned long code;
|
unsigned long code;
|
||||||
};
|
};
|
||||||
typedef struct ssl_option_s ssl_option_t;
|
|
||||||
|
|
||||||
static ssl_option_t ssl_options[] = {
|
typedef struct lsec_ssl_option_s lsec_ssl_option_t;
|
||||||
#if defined(SSL_OP_ALL)
|
|
||||||
{"all", SSL_OP_ALL},
|
LSEC_API lsec_ssl_option_t* lsec_get_ssl_options();
|
||||||
#endif
|
|
||||||
#if defined(SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION)
|
|
||||||
{"allow_unsafe_legacy_renegotiation", SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION},
|
|
||||||
#endif
|
|
||||||
#if defined(SSL_OP_CIPHER_SERVER_PREFERENCE)
|
|
||||||
{"cipher_server_preference", SSL_OP_CIPHER_SERVER_PREFERENCE},
|
|
||||||
#endif
|
|
||||||
#if defined(SSL_OP_CISCO_ANYCONNECT)
|
|
||||||
{"cisco_anyconnect", SSL_OP_CISCO_ANYCONNECT},
|
|
||||||
#endif
|
|
||||||
#if defined(SSL_OP_COOKIE_EXCHANGE)
|
|
||||||
{"cookie_exchange", SSL_OP_COOKIE_EXCHANGE},
|
|
||||||
#endif
|
|
||||||
#if defined(SSL_OP_CRYPTOPRO_TLSEXT_BUG)
|
|
||||||
{"cryptopro_tlsext_bug", SSL_OP_CRYPTOPRO_TLSEXT_BUG},
|
|
||||||
#endif
|
|
||||||
#if defined(SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS)
|
|
||||||
{"dont_insert_empty_fragments", SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS},
|
|
||||||
#endif
|
|
||||||
#if defined(SSL_OP_EPHEMERAL_RSA)
|
|
||||||
{"ephemeral_rsa", SSL_OP_EPHEMERAL_RSA},
|
|
||||||
#endif
|
|
||||||
#if defined(SSL_OP_LEGACY_SERVER_CONNECT)
|
|
||||||
{"legacy_server_connect", SSL_OP_LEGACY_SERVER_CONNECT},
|
|
||||||
#endif
|
|
||||||
#if defined(SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER)
|
|
||||||
{"microsoft_big_sslv3_buffer", SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER},
|
|
||||||
#endif
|
|
||||||
#if defined(SSL_OP_MICROSOFT_SESS_ID_BUG)
|
|
||||||
{"microsoft_sess_id_bug", SSL_OP_MICROSOFT_SESS_ID_BUG},
|
|
||||||
#endif
|
|
||||||
#if defined(SSL_OP_MSIE_SSLV2_RSA_PADDING)
|
|
||||||
{"msie_sslv2_rsa_padding", SSL_OP_MSIE_SSLV2_RSA_PADDING},
|
|
||||||
#endif
|
|
||||||
#if defined(SSL_OP_NETSCAPE_CA_DN_BUG)
|
|
||||||
{"netscape_ca_dn_bug", SSL_OP_NETSCAPE_CA_DN_BUG},
|
|
||||||
#endif
|
|
||||||
#if defined(SSL_OP_NETSCAPE_CHALLENGE_BUG)
|
|
||||||
{"netscape_challenge_bug", SSL_OP_NETSCAPE_CHALLENGE_BUG},
|
|
||||||
#endif
|
|
||||||
#if defined(SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG)
|
|
||||||
{"netscape_demo_cipher_change_bug", SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG},
|
|
||||||
#endif
|
|
||||||
#if defined(SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG)
|
|
||||||
{"netscape_reuse_cipher_change_bug", SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG},
|
|
||||||
#endif
|
|
||||||
#if defined(SSL_OP_NO_COMPRESSION)
|
|
||||||
{"no_compression", SSL_OP_NO_COMPRESSION},
|
|
||||||
#endif
|
|
||||||
#if defined(SSL_OP_NO_DTLSv1)
|
|
||||||
{"no_dtlsv1", SSL_OP_NO_DTLSv1},
|
|
||||||
#endif
|
|
||||||
#if defined(SSL_OP_NO_DTLSv1_2)
|
|
||||||
{"no_dtlsv1_2", SSL_OP_NO_DTLSv1_2},
|
|
||||||
#endif
|
|
||||||
#if defined(SSL_OP_NO_QUERY_MTU)
|
|
||||||
{"no_query_mtu", SSL_OP_NO_QUERY_MTU},
|
|
||||||
#endif
|
|
||||||
#if defined(SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION)
|
|
||||||
{"no_session_resumption_on_renegotiation", SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION},
|
|
||||||
#endif
|
|
||||||
#if defined(SSL_OP_NO_SSL_MASK)
|
|
||||||
{"no_ssl_mask", SSL_OP_NO_SSL_MASK},
|
|
||||||
#endif
|
|
||||||
#if defined(SSL_OP_NO_SSLv2)
|
|
||||||
{"no_sslv2", SSL_OP_NO_SSLv2},
|
|
||||||
#endif
|
|
||||||
#if defined(SSL_OP_NO_SSLv3)
|
|
||||||
{"no_sslv3", SSL_OP_NO_SSLv3},
|
|
||||||
#endif
|
|
||||||
#if defined(SSL_OP_NO_TICKET)
|
|
||||||
{"no_ticket", SSL_OP_NO_TICKET},
|
|
||||||
#endif
|
|
||||||
#if defined(SSL_OP_NO_TLSv1)
|
|
||||||
{"no_tlsv1", SSL_OP_NO_TLSv1},
|
|
||||||
#endif
|
|
||||||
#if defined(SSL_OP_NO_TLSv1_1)
|
|
||||||
{"no_tlsv1_1", SSL_OP_NO_TLSv1_1},
|
|
||||||
#endif
|
|
||||||
#if defined(SSL_OP_NO_TLSv1_2)
|
|
||||||
{"no_tlsv1_2", SSL_OP_NO_TLSv1_2},
|
|
||||||
#endif
|
|
||||||
#if defined(SSL_OP_PKCS1_CHECK_1)
|
|
||||||
{"pkcs1_check_1", SSL_OP_PKCS1_CHECK_1},
|
|
||||||
#endif
|
|
||||||
#if defined(SSL_OP_PKCS1_CHECK_2)
|
|
||||||
{"pkcs1_check_2", SSL_OP_PKCS1_CHECK_2},
|
|
||||||
#endif
|
|
||||||
#if defined(SSL_OP_SAFARI_ECDHE_ECDSA_BUG)
|
|
||||||
{"safari_ecdhe_ecdsa_bug", SSL_OP_SAFARI_ECDHE_ECDSA_BUG},
|
|
||||||
#endif
|
|
||||||
#if defined(SSL_OP_SINGLE_DH_USE)
|
|
||||||
{"single_dh_use", SSL_OP_SINGLE_DH_USE},
|
|
||||||
#endif
|
|
||||||
#if defined(SSL_OP_SINGLE_ECDH_USE)
|
|
||||||
{"single_ecdh_use", SSL_OP_SINGLE_ECDH_USE},
|
|
||||||
#endif
|
|
||||||
#if defined(SSL_OP_SSLEAY_080_CLIENT_DH_BUG)
|
|
||||||
{"ssleay_080_client_dh_bug", SSL_OP_SSLEAY_080_CLIENT_DH_BUG},
|
|
||||||
#endif
|
|
||||||
#if defined(SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG)
|
|
||||||
{"sslref2_reuse_cert_type_bug", SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG},
|
|
||||||
#endif
|
|
||||||
#if defined(SSL_OP_TLSEXT_PADDING)
|
|
||||||
{"tlsext_padding", SSL_OP_TLSEXT_PADDING},
|
|
||||||
#endif
|
|
||||||
#if defined(SSL_OP_TLS_BLOCK_PADDING_BUG)
|
|
||||||
{"tls_block_padding_bug", SSL_OP_TLS_BLOCK_PADDING_BUG},
|
|
||||||
#endif
|
|
||||||
#if defined(SSL_OP_TLS_D5_BUG)
|
|
||||||
{"tls_d5_bug", SSL_OP_TLS_D5_BUG},
|
|
||||||
#endif
|
|
||||||
#if defined(SSL_OP_TLS_ROLLBACK_BUG)
|
|
||||||
{"tls_rollback_bug", SSL_OP_TLS_ROLLBACK_BUG},
|
|
||||||
#endif
|
|
||||||
{NULL, 0L}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
local function usage()
|
local function usage()
|
||||||
print("Usage:")
|
print("Usage:")
|
||||||
print("* Generate options of your system:")
|
print("* Generate options of your system:")
|
||||||
print(" lua options.lua -g /path/to/ssl.h [verion] > options.h")
|
print(" lua options.lua -g /path/to/ssl.h [version] > options.c")
|
||||||
print("* Examples:")
|
print("* Examples:")
|
||||||
print(" lua options.lua -g /usr/include/openssl/ssl.h > options.h\n")
|
print(" lua options.lua -g /usr/include/openssl/ssl.h > options.c\n")
|
||||||
print(" lua options.lua -g /usr/include/openssl/ssl.h \"OpenSSL 1.0.1 14\" > options.h\n")
|
print(" lua options.lua -g /usr/include/openssl/ssl.h \"OpenSSL 1.1.1f\" > options.c\n")
|
||||||
|
|
||||||
print("* List options of your system:")
|
print("* List options of your system:")
|
||||||
print(" lua options.lua -l /path/to/ssl.h\n")
|
print(" lua options.lua -l /path/to/ssl.h\n")
|
||||||
@ -17,33 +17,28 @@ end
|
|||||||
|
|
||||||
local function generate(options, version)
|
local function generate(options, version)
|
||||||
print([[
|
print([[
|
||||||
#ifndef LSEC_OPTIONS_H
|
|
||||||
#define LSEC_OPTIONS_H
|
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------
|
||||||
* LuaSec 0.6
|
* LuaSec 1.3.2
|
||||||
* Copyright (C) 2006-2016 Bruno Silvestre
|
*
|
||||||
|
* Copyright (C) 2006-2023 Bruno Silvestre
|
||||||
*
|
*
|
||||||
*--------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include <openssl/ssl.h>
|
#include <openssl/ssl.h>
|
||||||
|
|
||||||
|
#include "options.h"
|
||||||
|
|
||||||
/* If you need to generate these options again, see options.lua */
|
/* If you need to generate these options again, see options.lua */
|
||||||
|
|
||||||
]])
|
]])
|
||||||
|
|
||||||
printf([[
|
printf([[
|
||||||
/*
|
/*
|
||||||
OpenSSL version: %s
|
OpenSSL version: %s
|
||||||
*/
|
*/
|
||||||
]], version)
|
]], version)
|
||||||
print([[
|
|
||||||
struct ssl_option_s {
|
|
||||||
const char *name;
|
|
||||||
unsigned long code;
|
|
||||||
};
|
|
||||||
typedef struct ssl_option_s ssl_option_t;
|
|
||||||
]])
|
|
||||||
|
|
||||||
print([[static ssl_option_t ssl_options[] = {]])
|
print([[static lsec_ssl_option_t ssl_options[] = {]])
|
||||||
|
|
||||||
for k, option in ipairs(options) do
|
for k, option in ipairs(options) do
|
||||||
local name = string.lower(string.sub(option, 8))
|
local name = string.lower(string.sub(option, 8))
|
||||||
@ -55,7 +50,9 @@ typedef struct ssl_option_s ssl_option_t;
|
|||||||
print([[
|
print([[
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
LSEC_API lsec_ssl_option_t* lsec_get_ssl_options() {
|
||||||
|
return ssl_options;
|
||||||
|
}
|
||||||
]])
|
]])
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -63,11 +60,14 @@ local function loadoptions(file)
|
|||||||
local options = {}
|
local options = {}
|
||||||
local f = assert(io.open(file, "r"))
|
local f = assert(io.open(file, "r"))
|
||||||
for line in f:lines() do
|
for line in f:lines() do
|
||||||
local op = string.match(line, "define%s+(SSL_OP_%S+)")
|
local op = string.match(line, "define%s+(SSL_OP_BIT%()")
|
||||||
|
if not op then
|
||||||
|
op = string.match(line, "define%s+(SSL_OP_%S+)")
|
||||||
if op then
|
if op then
|
||||||
table.insert(options, op)
|
table.insert(options, op)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
table.sort(options, function(a,b) return a<b end)
|
table.sort(options, function(a,b) return a<b end)
|
||||||
return options
|
return options
|
||||||
end
|
end
|
||||||
|
300
src/ssl.c
300
src/ssl.c
@ -1,9 +1,8 @@
|
|||||||
/*--------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------
|
||||||
* LuaSec 0.6
|
* LuaSec 1.3.2
|
||||||
*
|
*
|
||||||
* Copyright (C) 2014-2016 Kim Alvefur, Paul Aurich, Tobias Markmann,
|
* Copyright (C) 2014-2023 Kim Alvefur, Paul Aurich, Tobias Markmann, Matthew Wild
|
||||||
* Matthew Wild.
|
* Copyright (C) 2006-2023 Bruno Silvestre
|
||||||
* Copyright (C) 2006-2016 Bruno Silvestre.
|
|
||||||
*
|
*
|
||||||
*--------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
@ -11,13 +10,14 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#if defined(WIN32)
|
#if defined(WIN32)
|
||||||
#include <Winsock2.h>
|
#include <winsock2.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <openssl/ssl.h>
|
#include <openssl/ssl.h>
|
||||||
#include <openssl/x509v3.h>
|
#include <openssl/x509v3.h>
|
||||||
#include <openssl/x509_vfy.h>
|
#include <openssl/x509_vfy.h>
|
||||||
#include <openssl/err.h>
|
#include <openssl/err.h>
|
||||||
|
#include <openssl/dh.h>
|
||||||
|
|
||||||
#include <lua.h>
|
#include <lua.h>
|
||||||
#include <lauxlib.h>
|
#include <lauxlib.h>
|
||||||
@ -31,6 +31,14 @@
|
|||||||
#include "context.h"
|
#include "context.h"
|
||||||
#include "ssl.h"
|
#include "ssl.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef LSEC_API_OPENSSL_1_1_0
|
||||||
|
#define SSL_is_server(s) (s->server)
|
||||||
|
#define SSL_up_ref(ssl) CRYPTO_add(&(ssl)->references, 1, CRYPTO_LOCK_SSL)
|
||||||
|
#define X509_up_ref(c) CRYPTO_add(&c->references, 1, CRYPTO_LOCK_X509)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Underline socket error.
|
* Underline socket error.
|
||||||
*/
|
*/
|
||||||
@ -39,6 +47,11 @@ static int lsec_socket_error()
|
|||||||
#if defined(WIN32)
|
#if defined(WIN32)
|
||||||
return WSAGetLastError();
|
return WSAGetLastError();
|
||||||
#else
|
#else
|
||||||
|
#if defined(LSEC_OPENSSL_ERRNO_BUG)
|
||||||
|
// Bug in OpenSSL
|
||||||
|
if (errno == 0)
|
||||||
|
return LSEC_IO_SSL;
|
||||||
|
#endif
|
||||||
return errno;
|
return errno;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -191,9 +204,9 @@ static int ssl_recv(void *ctx, char *data, size_t count, size_t *got,
|
|||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
p_ssl ssl = (p_ssl)ctx;
|
p_ssl ssl = (p_ssl)ctx;
|
||||||
|
*got = 0;
|
||||||
if (ssl->state != LSEC_STATE_CONNECTED)
|
if (ssl->state != LSEC_STATE_CONNECTED)
|
||||||
return IO_CLOSED;
|
return IO_CLOSED;
|
||||||
*got = 0;
|
|
||||||
for ( ; ; ) {
|
for ( ; ; ) {
|
||||||
ERR_clear_error();
|
ERR_clear_error();
|
||||||
err = SSL_read(ssl->ssl, data, (int)count);
|
err = SSL_read(ssl->ssl, data, (int)count);
|
||||||
@ -203,7 +216,6 @@ static int ssl_recv(void *ctx, char *data, size_t count, size_t *got,
|
|||||||
*got = err;
|
*got = err;
|
||||||
return IO_DONE;
|
return IO_DONE;
|
||||||
case SSL_ERROR_ZERO_RETURN:
|
case SSL_ERROR_ZERO_RETURN:
|
||||||
*got = err;
|
|
||||||
return IO_CLOSED;
|
return IO_CLOSED;
|
||||||
case SSL_ERROR_WANT_READ:
|
case SSL_ERROR_WANT_READ:
|
||||||
err = socket_waitfd(&ssl->sock, WAITFD_R, tm);
|
err = socket_waitfd(&ssl->sock, WAITFD_R, tm);
|
||||||
@ -230,26 +242,45 @@ static int ssl_recv(void *ctx, char *data, size_t count, size_t *got,
|
|||||||
return IO_UNKNOWN;
|
return IO_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static SSL_CTX* luaossl_testcontext(lua_State *L, int arg) {
|
||||||
|
SSL_CTX **ctx = luaL_testudata(L, arg, "SSL_CTX*");
|
||||||
|
if (ctx)
|
||||||
|
return *ctx;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static SSL* luaossl_testssl(lua_State *L, int arg) {
|
||||||
|
SSL **ssl = luaL_testudata(L, arg, "SSL*");
|
||||||
|
if (ssl)
|
||||||
|
return *ssl;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new TLS/SSL object and mark it as new.
|
* Create a new TLS/SSL object and mark it as new.
|
||||||
*/
|
*/
|
||||||
static int meth_create(lua_State *L)
|
static int meth_create(lua_State *L)
|
||||||
{
|
{
|
||||||
p_ssl ssl;
|
p_ssl ssl;
|
||||||
int mode = lsec_getmode(L, 1);
|
int mode;
|
||||||
SSL_CTX *ctx = lsec_checkcontext(L, 1);
|
SSL_CTX *ctx;
|
||||||
|
|
||||||
|
lua_settop(L, 1);
|
||||||
|
|
||||||
if (mode == LSEC_MODE_INVALID) {
|
|
||||||
lua_pushnil(L);
|
|
||||||
lua_pushstring(L, "invalid mode");
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
ssl = (p_ssl)lua_newuserdata(L, sizeof(t_ssl));
|
ssl = (p_ssl)lua_newuserdata(L, sizeof(t_ssl));
|
||||||
if (!ssl) {
|
if (!ssl) {
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
lua_pushstring(L, "error creating SSL object");
|
lua_pushstring(L, "error creating SSL object");
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((ctx = lsec_testcontext(L, 1))) {
|
||||||
|
mode = lsec_getmode(L, 1);
|
||||||
|
if (mode == LSEC_MODE_INVALID) {
|
||||||
|
lua_pushnil(L);
|
||||||
|
lua_pushstring(L, "invalid mode");
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
ssl->ssl = SSL_new(ctx);
|
ssl->ssl = SSL_new(ctx);
|
||||||
if (!ssl->ssl) {
|
if (!ssl->ssl) {
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
@ -257,13 +288,26 @@ static int meth_create(lua_State *L)
|
|||||||
ERR_reason_error_string(ERR_get_error()));
|
ERR_reason_error_string(ERR_get_error()));
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
} else if ((ctx = luaossl_testcontext(L, 1))) {
|
||||||
|
ssl->ssl = SSL_new(ctx);
|
||||||
|
if (!ssl->ssl) {
|
||||||
|
lua_pushnil(L);
|
||||||
|
lua_pushfstring(L, "error creating SSL object (%s)",
|
||||||
|
ERR_reason_error_string(ERR_get_error()));
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
mode = SSL_is_server(ssl->ssl) ? LSEC_MODE_SERVER : LSEC_MODE_CLIENT;
|
||||||
|
} else if ((ssl->ssl = luaossl_testssl(L, 1))) {
|
||||||
|
SSL_up_ref(ssl->ssl);
|
||||||
|
mode = SSL_is_server(ssl->ssl) ? LSEC_MODE_SERVER : LSEC_MODE_CLIENT;
|
||||||
|
} else {
|
||||||
|
return luaL_argerror(L, 1, "invalid context");
|
||||||
|
}
|
||||||
ssl->state = LSEC_STATE_NEW;
|
ssl->state = LSEC_STATE_NEW;
|
||||||
SSL_set_fd(ssl->ssl, (int)SOCKET_INVALID);
|
SSL_set_fd(ssl->ssl, (int)SOCKET_INVALID);
|
||||||
SSL_set_mode(ssl->ssl, SSL_MODE_ENABLE_PARTIAL_WRITE |
|
SSL_set_mode(ssl->ssl, SSL_MODE_ENABLE_PARTIAL_WRITE |
|
||||||
SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);
|
SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);
|
||||||
#if defined(SSL_MODE_RELEASE_BUFFERS)
|
|
||||||
SSL_set_mode(ssl->ssl, SSL_MODE_RELEASE_BUFFERS);
|
SSL_set_mode(ssl->ssl, SSL_MODE_RELEASE_BUFFERS);
|
||||||
#endif
|
|
||||||
if (mode == LSEC_MODE_SERVER)
|
if (mode == LSEC_MODE_SERVER)
|
||||||
SSL_set_accept_state(ssl->ssl);
|
SSL_set_accept_state(ssl->ssl);
|
||||||
else
|
else
|
||||||
@ -341,8 +385,19 @@ static int meth_setfd(lua_State *L)
|
|||||||
*/
|
*/
|
||||||
static int meth_handshake(lua_State *L)
|
static int meth_handshake(lua_State *L)
|
||||||
{
|
{
|
||||||
|
int err;
|
||||||
p_ssl ssl = (p_ssl)luaL_checkudata(L, 1, "SSL:Connection");
|
p_ssl ssl = (p_ssl)luaL_checkudata(L, 1, "SSL:Connection");
|
||||||
int err = handshake(ssl);
|
p_context ctx = (p_context)SSL_CTX_get_app_data(SSL_get_SSL_CTX(ssl->ssl));
|
||||||
|
ctx->L = L;
|
||||||
|
err = handshake(ssl);
|
||||||
|
if (ctx->dh_param) {
|
||||||
|
DH_free(ctx->dh_param);
|
||||||
|
ctx->dh_param = NULL;
|
||||||
|
}
|
||||||
|
if (ctx->alpn) {
|
||||||
|
free(ctx->alpn);
|
||||||
|
ctx->alpn = NULL;
|
||||||
|
}
|
||||||
if (err == IO_DONE) {
|
if (err == IO_DONE) {
|
||||||
lua_pushboolean(L, 1);
|
lua_pushboolean(L, 1);
|
||||||
return 1;
|
return 1;
|
||||||
@ -406,7 +461,9 @@ static int meth_want(lua_State *L)
|
|||||||
*/
|
*/
|
||||||
static int meth_compression(lua_State *L)
|
static int meth_compression(lua_State *L)
|
||||||
{
|
{
|
||||||
#if !defined(OPENSSL_NO_COMP)
|
#ifdef OPENSSL_NO_COMP
|
||||||
|
const void *comp;
|
||||||
|
#else
|
||||||
const COMP_METHOD *comp;
|
const COMP_METHOD *comp;
|
||||||
#endif
|
#endif
|
||||||
p_ssl ssl = (p_ssl)luaL_checkudata(L, 1, "SSL:Connection");
|
p_ssl ssl = (p_ssl)luaL_checkudata(L, 1, "SSL:Connection");
|
||||||
@ -415,15 +472,11 @@ static int meth_compression(lua_State *L)
|
|||||||
lua_pushstring(L, "closed");
|
lua_pushstring(L, "closed");
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
#if !defined(OPENSSL_NO_COMP)
|
|
||||||
comp = SSL_get_current_compression(ssl->ssl);
|
comp = SSL_get_current_compression(ssl->ssl);
|
||||||
if (comp)
|
if (comp)
|
||||||
lua_pushstring(L, SSL_COMP_get_name(comp));
|
lua_pushstring(L, SSL_COMP_get_name(comp));
|
||||||
else
|
else
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
#else
|
|
||||||
lua_pushnil(L);
|
|
||||||
#endif
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -461,7 +514,7 @@ static int meth_getpeercertificate(lua_State *L)
|
|||||||
/* In a server-context, the stack doesn't contain the peer cert,
|
/* In a server-context, the stack doesn't contain the peer cert,
|
||||||
* so adjust accordingly.
|
* so adjust accordingly.
|
||||||
*/
|
*/
|
||||||
if (ssl->ssl->server)
|
if (SSL_is_server(ssl->ssl))
|
||||||
--n;
|
--n;
|
||||||
certs = SSL_get_peer_cert_chain(ssl->ssl);
|
certs = SSL_get_peer_cert_chain(ssl->ssl);
|
||||||
if (n >= sk_X509_num(certs)) {
|
if (n >= sk_X509_num(certs)) {
|
||||||
@ -471,11 +524,63 @@ static int meth_getpeercertificate(lua_State *L)
|
|||||||
cert = sk_X509_value(certs, n);
|
cert = sk_X509_value(certs, n);
|
||||||
/* Increment the reference counting of the object. */
|
/* Increment the reference counting of the object. */
|
||||||
/* See SSL_get_peer_certificate() source code. */
|
/* See SSL_get_peer_certificate() source code. */
|
||||||
CRYPTO_add(&cert->references, 1, CRYPTO_LOCK_X509);
|
X509_up_ref(cert);
|
||||||
lsec_pushx509(L, cert);
|
lsec_pushx509(L, cert);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the nth certificate of the chain sent to our peer.
|
||||||
|
*/
|
||||||
|
static int meth_getlocalcertificate(lua_State *L)
|
||||||
|
{
|
||||||
|
int n;
|
||||||
|
X509 *cert;
|
||||||
|
STACK_OF(X509) *certs;
|
||||||
|
p_ssl ssl = (p_ssl)luaL_checkudata(L, 1, "SSL:Connection");
|
||||||
|
if (ssl->state != LSEC_STATE_CONNECTED) {
|
||||||
|
lua_pushnil(L);
|
||||||
|
lua_pushstring(L, "closed");
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
/* Default to the first cert */
|
||||||
|
n = (int)luaL_optinteger(L, 2, 1);
|
||||||
|
/* This function is 1-based, but OpenSSL is 0-based */
|
||||||
|
--n;
|
||||||
|
if (n < 0) {
|
||||||
|
lua_pushnil(L);
|
||||||
|
lua_pushliteral(L, "invalid certificate index");
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
if (n == 0) {
|
||||||
|
cert = SSL_get_certificate(ssl->ssl);
|
||||||
|
if (cert)
|
||||||
|
lsec_pushx509(L, cert);
|
||||||
|
else
|
||||||
|
lua_pushnil(L);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
/* In a server-context, the stack doesn't contain the peer cert,
|
||||||
|
* so adjust accordingly.
|
||||||
|
*/
|
||||||
|
if (SSL_is_server(ssl->ssl))
|
||||||
|
--n;
|
||||||
|
if(SSL_get0_chain_certs(ssl->ssl, &certs) != 1) {
|
||||||
|
lua_pushnil(L);
|
||||||
|
} else {
|
||||||
|
if (n >= sk_X509_num(certs)) {
|
||||||
|
lua_pushnil(L);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
cert = sk_X509_value(certs, n);
|
||||||
|
/* Increment the reference counting of the object. */
|
||||||
|
/* See SSL_get_peer_certificate() source code. */
|
||||||
|
X509_up_ref(cert);
|
||||||
|
lsec_pushx509(L, cert);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the chain of certificate of the peer.
|
* Return the chain of certificate of the peer.
|
||||||
*/
|
*/
|
||||||
@ -493,7 +598,7 @@ static int meth_getpeerchain(lua_State *L)
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
if (ssl->ssl->server) {
|
if (SSL_is_server(ssl->ssl)) {
|
||||||
lsec_pushx509(L, SSL_get_peer_certificate(ssl->ssl));
|
lsec_pushx509(L, SSL_get_peer_certificate(ssl->ssl));
|
||||||
lua_rawseti(L, -2, idx++);
|
lua_rawseti(L, -2, idx++);
|
||||||
}
|
}
|
||||||
@ -503,13 +608,48 @@ static int meth_getpeerchain(lua_State *L)
|
|||||||
cert = sk_X509_value(certs, i);
|
cert = sk_X509_value(certs, i);
|
||||||
/* Increment the reference counting of the object. */
|
/* Increment the reference counting of the object. */
|
||||||
/* See SSL_get_peer_certificate() source code. */
|
/* See SSL_get_peer_certificate() source code. */
|
||||||
CRYPTO_add(&cert->references, 1, CRYPTO_LOCK_X509);
|
X509_up_ref(cert);
|
||||||
lsec_pushx509(L, cert);
|
lsec_pushx509(L, cert);
|
||||||
lua_rawseti(L, -2, idx++);
|
lua_rawseti(L, -2, idx++);
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the chain of certificates sent to the peer.
|
||||||
|
*/
|
||||||
|
static int meth_getlocalchain(lua_State *L)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int idx = 1;
|
||||||
|
int n_certs;
|
||||||
|
X509 *cert;
|
||||||
|
STACK_OF(X509) *certs;
|
||||||
|
p_ssl ssl = (p_ssl)luaL_checkudata(L, 1, "SSL:Connection");
|
||||||
|
if (ssl->state != LSEC_STATE_CONNECTED) {
|
||||||
|
lua_pushnil(L);
|
||||||
|
lua_pushstring(L, "closed");
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
lua_newtable(L);
|
||||||
|
if (SSL_is_server(ssl->ssl)) {
|
||||||
|
lsec_pushx509(L, SSL_get_certificate(ssl->ssl));
|
||||||
|
lua_rawseti(L, -2, idx++);
|
||||||
|
}
|
||||||
|
if(SSL_get0_chain_certs(ssl->ssl, &certs)) {
|
||||||
|
n_certs = sk_X509_num(certs);
|
||||||
|
for (i = 0; i < n_certs; i++) {
|
||||||
|
cert = sk_X509_value(certs, i);
|
||||||
|
/* Increment the reference counting of the object. */
|
||||||
|
/* See SSL_get_peer_certificate() source code. */
|
||||||
|
X509_up_ref(cert);
|
||||||
|
lsec_pushx509(L, cert);
|
||||||
|
lua_rawseti(L, -2, idx++);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy the table src to the table dst.
|
* Copy the table src to the table dst.
|
||||||
*/
|
*/
|
||||||
@ -617,6 +757,41 @@ static int meth_getpeerfinished(lua_State *L)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get some shared keying material
|
||||||
|
*/
|
||||||
|
static int meth_exportkeyingmaterial(lua_State *L)
|
||||||
|
{
|
||||||
|
p_ssl ssl = (p_ssl)luaL_checkudata(L, 1, "SSL:Connection");
|
||||||
|
|
||||||
|
if(ssl->state != LSEC_STATE_CONNECTED) {
|
||||||
|
lua_pushnil(L);
|
||||||
|
lua_pushstring(L, "closed");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t llen = 0;
|
||||||
|
size_t contextlen = 0;
|
||||||
|
const unsigned char *context = NULL;
|
||||||
|
const char *label = (const char*)luaL_checklstring(L, 2, &llen);
|
||||||
|
size_t olen = (size_t)luaL_checkinteger(L, 3);
|
||||||
|
|
||||||
|
if (!lua_isnoneornil(L, 4))
|
||||||
|
context = (const unsigned char*)luaL_checklstring(L, 4, &contextlen);
|
||||||
|
|
||||||
|
/* Temporary buffer memory-managed by Lua itself */
|
||||||
|
unsigned char *out = (unsigned char*)lua_newuserdata(L, olen);
|
||||||
|
|
||||||
|
if(SSL_export_keying_material(ssl->ssl, out, olen, label, llen, context, contextlen, context != NULL) != 1) {
|
||||||
|
lua_pushnil(L);
|
||||||
|
lua_pushstring(L, "error exporting keying material");
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
lua_pushlstring(L, (char*)out, olen);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Object information -- tostring metamethod
|
* Object information -- tostring metamethod
|
||||||
*/
|
*/
|
||||||
@ -693,6 +868,8 @@ static int sni_cb(SSL *ssl, int *ad, void *arg)
|
|||||||
lua_pop(L, 4);
|
lua_pop(L, 4);
|
||||||
/* Found, use this context */
|
/* Found, use this context */
|
||||||
if (newctx) {
|
if (newctx) {
|
||||||
|
p_context pctx = (p_context)SSL_CTX_get_app_data(newctx);
|
||||||
|
pctx->L = L;
|
||||||
SSL_set_SSL_CTX(ssl, newctx);
|
SSL_set_SSL_CTX(ssl, newctx);
|
||||||
return SSL_TLSEXT_ERR_OK;
|
return SSL_TLSEXT_ERR_OK;
|
||||||
}
|
}
|
||||||
@ -755,9 +932,22 @@ static int meth_getsniname(lua_State *L)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int meth_getalpn(lua_State *L)
|
||||||
|
{
|
||||||
|
unsigned len;
|
||||||
|
const unsigned char *data;
|
||||||
|
p_ssl ssl = (p_ssl)luaL_checkudata(L, 1, "SSL:Connection");
|
||||||
|
SSL_get0_alpn_selected(ssl->ssl, &data, &len);
|
||||||
|
if (data == NULL && len == 0)
|
||||||
|
lua_pushnil(L);
|
||||||
|
else
|
||||||
|
lua_pushlstring(L, (const char*)data, len);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static int meth_copyright(lua_State *L)
|
static int meth_copyright(lua_State *L)
|
||||||
{
|
{
|
||||||
lua_pushstring(L, "LuaSec 0.6 - Copyright (C) 2006-2016 Bruno Silvestre, UFG"
|
lua_pushstring(L, "LuaSec 1.3.2 - Copyright (C) 2006-2023 Bruno Silvestre, UFG"
|
||||||
#if defined(WITH_LUASOCKET)
|
#if defined(WITH_LUASOCKET)
|
||||||
"\nLuaSocket 3.0-RC1 - Copyright (C) 2004-2013 Diego Nehab"
|
"\nLuaSocket 3.0-RC1 - Copyright (C) 2004-2013 Diego Nehab"
|
||||||
#endif
|
#endif
|
||||||
@ -765,6 +955,34 @@ static int meth_copyright(lua_State *L)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(LSEC_ENABLE_DANE)
|
||||||
|
static int meth_dane(lua_State *L)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
p_ssl ssl = (p_ssl)luaL_checkudata(L, 1, "SSL:Connection");
|
||||||
|
ret = SSL_dane_enable(ssl->ssl, luaL_checkstring(L, 2));
|
||||||
|
lua_pushboolean(L, (ret > 0));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int meth_tlsa(lua_State *L)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
size_t len;
|
||||||
|
p_ssl ssl = (p_ssl)luaL_checkudata(L, 1, "SSL:Connection");
|
||||||
|
uint8_t usage = (uint8_t)luaL_checkinteger(L, 2);
|
||||||
|
uint8_t selector = (uint8_t)luaL_checkinteger(L, 3);
|
||||||
|
uint8_t mtype = (uint8_t)luaL_checkinteger(L, 4);
|
||||||
|
unsigned char *data = (unsigned char*)luaL_checklstring(L, 5, &len);
|
||||||
|
|
||||||
|
ERR_clear_error();
|
||||||
|
ret = SSL_dane_tlsa_add(ssl->ssl, usage, selector, mtype, data, len);
|
||||||
|
lua_pushboolean(L, (ret > 0));
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -772,12 +990,16 @@ static int meth_copyright(lua_State *L)
|
|||||||
*/
|
*/
|
||||||
static luaL_Reg methods[] = {
|
static luaL_Reg methods[] = {
|
||||||
{"close", meth_close},
|
{"close", meth_close},
|
||||||
|
{"getalpn", meth_getalpn},
|
||||||
{"getfd", meth_getfd},
|
{"getfd", meth_getfd},
|
||||||
{"getfinished", meth_getfinished},
|
{"getfinished", meth_getfinished},
|
||||||
{"getpeercertificate", meth_getpeercertificate},
|
{"getpeercertificate", meth_getpeercertificate},
|
||||||
|
{"getlocalcertificate", meth_getlocalcertificate},
|
||||||
{"getpeerchain", meth_getpeerchain},
|
{"getpeerchain", meth_getpeerchain},
|
||||||
|
{"getlocalchain", meth_getlocalchain},
|
||||||
{"getpeerverification", meth_getpeerverification},
|
{"getpeerverification", meth_getpeerverification},
|
||||||
{"getpeerfinished", meth_getpeerfinished},
|
{"getpeerfinished", meth_getpeerfinished},
|
||||||
|
{"exportkeyingmaterial",meth_exportkeyingmaterial},
|
||||||
{"getsniname", meth_getsniname},
|
{"getsniname", meth_getsniname},
|
||||||
{"getstats", meth_getstats},
|
{"getstats", meth_getstats},
|
||||||
{"setstats", meth_setstats},
|
{"setstats", meth_setstats},
|
||||||
@ -788,6 +1010,10 @@ static luaL_Reg methods[] = {
|
|||||||
{"settimeout", meth_settimeout},
|
{"settimeout", meth_settimeout},
|
||||||
{"sni", meth_sni},
|
{"sni", meth_sni},
|
||||||
{"want", meth_want},
|
{"want", meth_want},
|
||||||
|
#if defined(LSEC_ENABLE_DANE)
|
||||||
|
{"setdane", meth_dane},
|
||||||
|
{"settlsa", meth_tlsa},
|
||||||
|
#endif
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -795,6 +1021,7 @@ static luaL_Reg methods[] = {
|
|||||||
* SSL metamethods.
|
* SSL metamethods.
|
||||||
*/
|
*/
|
||||||
static luaL_Reg meta[] = {
|
static luaL_Reg meta[] = {
|
||||||
|
{"__close", meth_destroy},
|
||||||
{"__gc", meth_destroy},
|
{"__gc", meth_destroy},
|
||||||
{"__tostring", meth_tostring},
|
{"__tostring", meth_tostring},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
@ -818,6 +1045,7 @@ static luaL_Reg funcs[] = {
|
|||||||
*/
|
*/
|
||||||
LSEC_API int luaopen_ssl_core(lua_State *L)
|
LSEC_API int luaopen_ssl_core(lua_State *L)
|
||||||
{
|
{
|
||||||
|
#ifndef LSEC_API_OPENSSL_1_1_0
|
||||||
/* Initialize SSL */
|
/* Initialize SSL */
|
||||||
if (!SSL_library_init()) {
|
if (!SSL_library_init()) {
|
||||||
lua_pushstring(L, "unable to initialize SSL library");
|
lua_pushstring(L, "unable to initialize SSL library");
|
||||||
@ -825,6 +1053,7 @@ LSEC_API int luaopen_ssl_core(lua_State *L)
|
|||||||
}
|
}
|
||||||
OpenSSL_add_all_algorithms();
|
OpenSSL_add_all_algorithms();
|
||||||
SSL_load_error_strings();
|
SSL_load_error_strings();
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(WITH_LUASOCKET)
|
#if defined(WITH_LUASOCKET)
|
||||||
/* Initialize internal library */
|
/* Initialize internal library */
|
||||||
@ -842,5 +1071,22 @@ LSEC_API int luaopen_ssl_core(lua_State *L)
|
|||||||
|
|
||||||
luaL_newlib(L, funcs);
|
luaL_newlib(L, funcs);
|
||||||
|
|
||||||
|
lua_pushstring(L, "SOCKET_INVALID");
|
||||||
|
lua_pushinteger(L, SOCKET_INVALID);
|
||||||
|
lua_rawset(L, -3);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
|
||||||
|
/* Empty implementation to allow building with LuaRocks and MS compilers */
|
||||||
|
LSEC_API int luaopen_ssl(lua_State *L) {
|
||||||
|
lua_pushstring(L, "you should not call this function");
|
||||||
|
lua_error(L);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@ -2,8 +2,9 @@
|
|||||||
#define LSEC_SSL_H
|
#define LSEC_SSL_H
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------
|
||||||
* LuaSec 0.6
|
* LuaSec 1.3.2
|
||||||
* Copyright (C) 2006-2016 Bruno Silvestre
|
*
|
||||||
|
* Copyright (C) 2006-2023 Bruno Silvestre
|
||||||
*
|
*
|
||||||
*--------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
@ -15,7 +16,7 @@
|
|||||||
#include <luasocket/timeout.h>
|
#include <luasocket/timeout.h>
|
||||||
#include <luasocket/socket.h>
|
#include <luasocket/socket.h>
|
||||||
|
|
||||||
#include "config.h"
|
#include "compat.h"
|
||||||
#include "context.h"
|
#include "context.h"
|
||||||
|
|
||||||
#define LSEC_STATE_NEW 1
|
#define LSEC_STATE_NEW 1
|
||||||
|
164
src/ssl.lua
164
src/ssl.lua
@ -1,12 +1,14 @@
|
|||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
-- LuaSec 0.6
|
-- LuaSec 1.3.2
|
||||||
-- Copyright (C) 2006-2016 Bruno Silvestre
|
--
|
||||||
|
-- Copyright (C) 2006-2023 Bruno Silvestre
|
||||||
--
|
--
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
|
|
||||||
local core = require("ssl.core")
|
local core = require("ssl.core")
|
||||||
local context = require("ssl.context")
|
local context = require("ssl.context")
|
||||||
local x509 = require("ssl.x509")
|
local x509 = require("ssl.x509")
|
||||||
|
local config = require("ssl.config")
|
||||||
|
|
||||||
local unpack = table.unpack or unpack
|
local unpack = table.unpack or unpack
|
||||||
|
|
||||||
@ -28,6 +30,39 @@ local function optexec(func, param, ctx)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Convert an array of strings to wire-format
|
||||||
|
--
|
||||||
|
local function array2wireformat(array)
|
||||||
|
local str = ""
|
||||||
|
for k, v in ipairs(array) do
|
||||||
|
if type(v) ~= "string" then return nil end
|
||||||
|
local len = #v
|
||||||
|
if len == 0 then
|
||||||
|
return nil, "invalid ALPN name (empty string)"
|
||||||
|
elseif len > 255 then
|
||||||
|
return nil, "invalid ALPN name (length > 255)"
|
||||||
|
end
|
||||||
|
str = str .. string.char(len) .. v
|
||||||
|
end
|
||||||
|
if str == "" then return nil, "invalid ALPN list (empty)" end
|
||||||
|
return str
|
||||||
|
end
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Convert wire-string format to array
|
||||||
|
--
|
||||||
|
local function wireformat2array(str)
|
||||||
|
local i = 1
|
||||||
|
local array = {}
|
||||||
|
while i < #str do
|
||||||
|
local len = str:byte(i)
|
||||||
|
array[#array + 1] = str:sub(i + 1, i + len)
|
||||||
|
i = i + len + 1
|
||||||
|
end
|
||||||
|
return array
|
||||||
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
--
|
--
|
||||||
--
|
--
|
||||||
@ -39,26 +74,34 @@ local function newcontext(cfg)
|
|||||||
-- Mode
|
-- Mode
|
||||||
succ, msg = context.setmode(ctx, cfg.mode)
|
succ, msg = context.setmode(ctx, cfg.mode)
|
||||||
if not succ then return nil, msg end
|
if not succ then return nil, msg end
|
||||||
|
local certificates = cfg.certificates
|
||||||
|
if not certificates then
|
||||||
|
certificates = {
|
||||||
|
{ certificate = cfg.certificate, key = cfg.key, password = cfg.password }
|
||||||
|
}
|
||||||
|
end
|
||||||
|
for _, certificate in ipairs(certificates) do
|
||||||
-- Load the key
|
-- Load the key
|
||||||
if cfg.key then
|
if certificate.key then
|
||||||
if cfg.password and
|
if certificate.password and
|
||||||
type(cfg.password) ~= "function" and
|
type(certificate.password) ~= "function" and
|
||||||
type(cfg.password) ~= "string"
|
type(certificate.password) ~= "string"
|
||||||
then
|
then
|
||||||
return nil, "invalid password type"
|
return nil, "invalid password type"
|
||||||
end
|
end
|
||||||
succ, msg = context.loadkey(ctx, cfg.key, cfg.password)
|
succ, msg = context.loadkey(ctx, certificate.key, certificate.password)
|
||||||
if not succ then return nil, msg end
|
if not succ then return nil, msg end
|
||||||
end
|
end
|
||||||
-- Load the certificate
|
-- Load the certificate(s)
|
||||||
if cfg.certificate then
|
if certificate.certificate then
|
||||||
succ, msg = context.loadcert(ctx, cfg.certificate)
|
succ, msg = context.loadcert(ctx, certificate.certificate)
|
||||||
if not succ then return nil, msg end
|
if not succ then return nil, msg end
|
||||||
if cfg.key and context.checkkey then
|
if certificate.key and context.checkkey then
|
||||||
succ = context.checkkey(ctx)
|
succ = context.checkkey(ctx)
|
||||||
if not succ then return nil, "private key does not match public key" end
|
if not succ then return nil, "private key does not match public key" end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
-- Load the CA certificates
|
-- Load the CA certificates
|
||||||
if cfg.cafile or cfg.capath then
|
if cfg.cafile or cfg.capath then
|
||||||
succ, msg = context.locations(ctx, cfg.cafile, cfg.capath)
|
succ, msg = context.locations(ctx, cfg.cafile, cfg.capath)
|
||||||
@ -68,6 +111,11 @@ local function newcontext(cfg)
|
|||||||
if cfg.ciphers then
|
if cfg.ciphers then
|
||||||
succ, msg = context.setcipher(ctx, cfg.ciphers)
|
succ, msg = context.setcipher(ctx, cfg.ciphers)
|
||||||
if not succ then return nil, msg end
|
if not succ then return nil, msg end
|
||||||
|
end
|
||||||
|
-- Set SSL cipher suites
|
||||||
|
if cfg.ciphersuites then
|
||||||
|
succ, msg = context.setciphersuites(ctx, cfg.ciphersuites)
|
||||||
|
if not succ then return nil, msg end
|
||||||
end
|
end
|
||||||
-- Set the verification options
|
-- Set the verification options
|
||||||
succ, msg = optexec(context.setverify, cfg.verify, ctx)
|
succ, msg = optexec(context.setverify, cfg.verify, ctx)
|
||||||
@ -92,17 +140,102 @@ local function newcontext(cfg)
|
|||||||
end
|
end
|
||||||
context.setdhparam(ctx, cfg.dhparam)
|
context.setdhparam(ctx, cfg.dhparam)
|
||||||
end
|
end
|
||||||
-- Set elliptic curve
|
|
||||||
if cfg.curve then
|
-- Set elliptic curves
|
||||||
|
if (not config.algorithms.ec) and (cfg.curve or cfg.curveslist) then
|
||||||
|
return false, "elliptic curves not supported"
|
||||||
|
end
|
||||||
|
if config.capabilities.curves_list and cfg.curveslist then
|
||||||
|
succ, msg = context.setcurveslist(ctx, cfg.curveslist)
|
||||||
|
if not succ then return nil, msg end
|
||||||
|
elseif cfg.curve then
|
||||||
succ, msg = context.setcurve(ctx, cfg.curve)
|
succ, msg = context.setcurve(ctx, cfg.curve)
|
||||||
if not succ then return nil, msg end
|
if not succ then return nil, msg end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Set extra verification options
|
-- Set extra verification options
|
||||||
if cfg.verifyext and ctx.setverifyext then
|
if cfg.verifyext and ctx.setverifyext then
|
||||||
succ, msg = optexec(ctx.setverifyext, cfg.verifyext, ctx)
|
succ, msg = optexec(ctx.setverifyext, cfg.verifyext, ctx)
|
||||||
if not succ then return nil, msg end
|
if not succ then return nil, msg end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- ALPN
|
||||||
|
if cfg.mode == "server" and cfg.alpn then
|
||||||
|
if type(cfg.alpn) == "function" then
|
||||||
|
local alpncb = cfg.alpn
|
||||||
|
-- This callback function has to return one value only
|
||||||
|
succ, msg = context.setalpncb(ctx, function(str)
|
||||||
|
local protocols = alpncb(wireformat2array(str))
|
||||||
|
if type(protocols) == "string" then
|
||||||
|
protocols = { protocols }
|
||||||
|
elseif type(protocols) ~= "table" then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
return (array2wireformat(protocols)) -- use "()" to drop error message
|
||||||
|
end)
|
||||||
|
if not succ then return nil, msg end
|
||||||
|
elseif type(cfg.alpn) == "table" then
|
||||||
|
local protocols = cfg.alpn
|
||||||
|
-- check if array is valid before use it
|
||||||
|
succ, msg = array2wireformat(protocols)
|
||||||
|
if not succ then return nil, msg end
|
||||||
|
-- This callback function has to return one value only
|
||||||
|
succ, msg = context.setalpncb(ctx, function()
|
||||||
|
return (array2wireformat(protocols)) -- use "()" to drop error message
|
||||||
|
end)
|
||||||
|
if not succ then return nil, msg end
|
||||||
|
else
|
||||||
|
return nil, "invalid ALPN parameter"
|
||||||
|
end
|
||||||
|
elseif cfg.mode == "client" and cfg.alpn then
|
||||||
|
local alpn
|
||||||
|
if type(cfg.alpn) == "string" then
|
||||||
|
alpn, msg = array2wireformat({ cfg.alpn })
|
||||||
|
elseif type(cfg.alpn) == "table" then
|
||||||
|
alpn, msg = array2wireformat(cfg.alpn)
|
||||||
|
else
|
||||||
|
return nil, "invalid ALPN parameter"
|
||||||
|
end
|
||||||
|
if not alpn then return nil, msg end
|
||||||
|
succ, msg = context.setalpn(ctx, alpn)
|
||||||
|
if not succ then return nil, msg end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- PSK
|
||||||
|
if config.capabilities.psk and cfg.psk then
|
||||||
|
if cfg.mode == "client" then
|
||||||
|
if type(cfg.psk) ~= "function" then
|
||||||
|
return nil, "invalid PSK configuration"
|
||||||
|
end
|
||||||
|
succ = context.setclientpskcb(ctx, cfg.psk)
|
||||||
|
if not succ then return nil, msg end
|
||||||
|
elseif cfg.mode == "server" then
|
||||||
|
if type(cfg.psk) == "function" then
|
||||||
|
succ, msg = context.setserverpskcb(ctx, cfg.psk)
|
||||||
|
if not succ then return nil, msg end
|
||||||
|
elseif type(cfg.psk) == "table" then
|
||||||
|
if type(cfg.psk.hint) == "string" and type(cfg.psk.callback) == "function" then
|
||||||
|
succ, msg = context.setpskhint(ctx, cfg.psk.hint)
|
||||||
|
if not succ then return succ, msg end
|
||||||
|
succ = context.setserverpskcb(ctx, cfg.psk.callback)
|
||||||
|
if not succ then return succ, msg end
|
||||||
|
else
|
||||||
|
return nil, "invalid PSK configuration"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
return nil, "invalid PSK configuration"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if config.capabilities.dane and cfg.dane then
|
||||||
|
if type(cfg.dane) == "table" then
|
||||||
|
context.setdane(ctx, unpack(cfg.dane))
|
||||||
|
else
|
||||||
|
context.setdane(ctx)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return ctx
|
return ctx
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -120,7 +253,7 @@ local function wrap(sock, cfg)
|
|||||||
local s, msg = core.create(ctx)
|
local s, msg = core.create(ctx)
|
||||||
if s then
|
if s then
|
||||||
core.setfd(s, sock:getfd())
|
core.setfd(s, sock:getfd())
|
||||||
sock:setfd(-1)
|
sock:setfd(core.SOCKET_INVALID)
|
||||||
registry[s] = ctx
|
registry[s] = ctx
|
||||||
return s
|
return s
|
||||||
end
|
end
|
||||||
@ -169,8 +302,9 @@ core.setmethod("info", info)
|
|||||||
--
|
--
|
||||||
|
|
||||||
local _M = {
|
local _M = {
|
||||||
_VERSION = "0.6",
|
_VERSION = "1.3.2",
|
||||||
_COPYRIGHT = core.copyright(),
|
_COPYRIGHT = core.copyright(),
|
||||||
|
config = config,
|
||||||
loadcertificate = x509.load,
|
loadcertificate = x509.load,
|
||||||
newcontext = newcontext,
|
newcontext = newcontext,
|
||||||
wrap = wrap,
|
wrap = wrap,
|
||||||
|
72
src/x509.c
72
src/x509.c
@ -1,8 +1,8 @@
|
|||||||
/*--------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------
|
||||||
* LuaSec 0.6
|
* LuaSec 1.3.2
|
||||||
*
|
*
|
||||||
* Copyright (C) 2014-2016 Kim Alvefur, Paul Aurich, Tobias Markmann
|
* Copyright (C) 2014-2023 Kim Alvefur, Paul Aurich, Tobias Markmann, Matthew Wild
|
||||||
* Matthew Wild, Bruno Silvestre.
|
* Copyright (C) 2014-2023 Bruno Silvestre
|
||||||
*
|
*
|
||||||
*--------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
@ -32,6 +32,13 @@
|
|||||||
|
|
||||||
#include "x509.h"
|
#include "x509.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef LSEC_API_OPENSSL_1_1_0
|
||||||
|
#define X509_get0_notBefore X509_get_notBefore
|
||||||
|
#define X509_get0_notAfter X509_get_notAfter
|
||||||
|
#define ASN1_STRING_get0_data ASN1_STRING_data
|
||||||
|
#endif
|
||||||
|
|
||||||
static const char* hex_tab = "0123456789abcdef";
|
static const char* hex_tab = "0123456789abcdef";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -146,8 +153,7 @@ static void push_asn1_string(lua_State* L, ASN1_STRING *string, int encode)
|
|||||||
}
|
}
|
||||||
switch (encode) {
|
switch (encode) {
|
||||||
case LSEC_AI5_STRING:
|
case LSEC_AI5_STRING:
|
||||||
lua_pushlstring(L, (char*)ASN1_STRING_data(string),
|
lua_pushlstring(L, (char*)ASN1_STRING_get0_data(string), ASN1_STRING_length(string));
|
||||||
ASN1_STRING_length(string));
|
|
||||||
break;
|
break;
|
||||||
case LSEC_UTF8_STRING:
|
case LSEC_UTF8_STRING:
|
||||||
len = ASN1_STRING_to_UTF8(&data, string);
|
len = ASN1_STRING_to_UTF8(&data, string);
|
||||||
@ -163,7 +169,7 @@ static void push_asn1_string(lua_State* L, ASN1_STRING *string, int encode)
|
|||||||
/**
|
/**
|
||||||
* Return a human readable time.
|
* Return a human readable time.
|
||||||
*/
|
*/
|
||||||
static int push_asn1_time(lua_State *L, ASN1_UTCTIME *tm)
|
static int push_asn1_time(lua_State *L, const ASN1_UTCTIME *tm)
|
||||||
{
|
{
|
||||||
char *tmp;
|
char *tmp;
|
||||||
long size;
|
long size;
|
||||||
@ -182,7 +188,7 @@ static void push_asn1_ip(lua_State *L, ASN1_STRING *string)
|
|||||||
{
|
{
|
||||||
int af;
|
int af;
|
||||||
char dst[INET6_ADDRSTRLEN];
|
char dst[INET6_ADDRSTRLEN];
|
||||||
unsigned char *ip = ASN1_STRING_data(string);
|
unsigned char *ip = (unsigned char*)ASN1_STRING_get0_data(string);
|
||||||
switch(ASN1_STRING_length(string)) {
|
switch(ASN1_STRING_length(string)) {
|
||||||
case 4:
|
case 4:
|
||||||
af = AF_INET;
|
af = AF_INET;
|
||||||
@ -221,7 +227,7 @@ static int push_subtable(lua_State* L, int idx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrive the general names from the object.
|
* Retrieve the general names from the object.
|
||||||
*/
|
*/
|
||||||
static int push_x509_name(lua_State* L, X509_NAME *name, int encode)
|
static int push_x509_name(lua_State* L, X509_NAME *name, int encode)
|
||||||
{
|
{
|
||||||
@ -249,7 +255,7 @@ static int push_x509_name(lua_State* L, X509_NAME *name, int encode)
|
|||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrive the Subject from the certificate.
|
* Retrieve the Subject from the certificate.
|
||||||
*/
|
*/
|
||||||
static int meth_subject(lua_State* L)
|
static int meth_subject(lua_State* L)
|
||||||
{
|
{
|
||||||
@ -258,7 +264,7 @@ static int meth_subject(lua_State* L)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrive the Issuer from the certificate.
|
* Retrieve the Issuer from the certificate.
|
||||||
*/
|
*/
|
||||||
static int meth_issuer(lua_State* L)
|
static int meth_issuer(lua_State* L)
|
||||||
{
|
{
|
||||||
@ -293,11 +299,11 @@ int meth_extensions(lua_State* L)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
/* Push ret[oid] */
|
/* Push ret[oid] */
|
||||||
push_asn1_objname(L, extension->object, 1);
|
push_asn1_objname(L, X509_EXTENSION_get_object(extension), 1);
|
||||||
push_subtable(L, -2);
|
push_subtable(L, -2);
|
||||||
|
|
||||||
/* Set ret[oid].name = name */
|
/* Set ret[oid].name = name */
|
||||||
push_asn1_objname(L, extension->object, 0);
|
push_asn1_objname(L, X509_EXTENSION_get_object(extension), 0);
|
||||||
lua_setfield(L, -2, "name");
|
lua_setfield(L, -2, "name");
|
||||||
|
|
||||||
n_general_names = sk_GENERAL_NAME_num(values);
|
n_general_names = sk_GENERAL_NAME_num(values);
|
||||||
@ -360,7 +366,9 @@ int meth_extensions(lua_State* L)
|
|||||||
/* not supported */
|
/* not supported */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
GENERAL_NAME_free(general_name);
|
||||||
}
|
}
|
||||||
|
sk_GENERAL_NAME_free(values);
|
||||||
lua_pop(L, 1); /* ret[oid] */
|
lua_pop(L, 1); /* ret[oid] */
|
||||||
i++; /* Next extension */
|
i++; /* Next extension */
|
||||||
}
|
}
|
||||||
@ -404,7 +412,7 @@ static int meth_pubkey(lua_State* L)
|
|||||||
bytes = BIO_get_mem_data(bio, &data);
|
bytes = BIO_get_mem_data(bio, &data);
|
||||||
if (bytes > 0) {
|
if (bytes > 0) {
|
||||||
lua_pushlstring(L, data, bytes);
|
lua_pushlstring(L, data, bytes);
|
||||||
switch(EVP_PKEY_type(pkey->type)) {
|
switch(EVP_PKEY_base_id(pkey)) {
|
||||||
case EVP_PKEY_RSA:
|
case EVP_PKEY_RSA:
|
||||||
lua_pushstring(L, "RSA");
|
lua_pushstring(L, "RSA");
|
||||||
break;
|
break;
|
||||||
@ -477,10 +485,13 @@ static int meth_digest(lua_State* L)
|
|||||||
*/
|
*/
|
||||||
static int meth_valid_at(lua_State* L)
|
static int meth_valid_at(lua_State* L)
|
||||||
{
|
{
|
||||||
|
int nb, na;
|
||||||
X509* cert = lsec_checkx509(L, 1);
|
X509* cert = lsec_checkx509(L, 1);
|
||||||
time_t time = luaL_checkinteger(L, 2);
|
time_t time = luaL_checkinteger(L, 2);
|
||||||
lua_pushboolean(L, (X509_cmp_time(X509_get_notAfter(cert), &time) >= 0
|
nb = X509_cmp_time(X509_get0_notBefore(cert), &time);
|
||||||
&& X509_cmp_time(X509_get_notBefore(cert), &time) <= 0));
|
time -= 1;
|
||||||
|
na = X509_cmp_time(X509_get0_notAfter(cert), &time);
|
||||||
|
lua_pushboolean(L, nb == -1 && na == 1);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -508,7 +519,7 @@ static int meth_serial(lua_State *L)
|
|||||||
static int meth_notbefore(lua_State *L)
|
static int meth_notbefore(lua_State *L)
|
||||||
{
|
{
|
||||||
X509* cert = lsec_checkx509(L, 1);
|
X509* cert = lsec_checkx509(L, 1);
|
||||||
return push_asn1_time(L, X509_get_notBefore(cert));
|
return push_asn1_time(L, X509_get0_notBefore(cert));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -517,7 +528,7 @@ static int meth_notbefore(lua_State *L)
|
|||||||
static int meth_notafter(lua_State *L)
|
static int meth_notafter(lua_State *L)
|
||||||
{
|
{
|
||||||
X509* cert = lsec_checkx509(L, 1);
|
X509* cert = lsec_checkx509(L, 1);
|
||||||
return push_asn1_time(L, X509_get_notAfter(cert));
|
return push_asn1_time(L, X509_get0_notAfter(cert));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -610,7 +621,11 @@ cleanup:
|
|||||||
*/
|
*/
|
||||||
static int meth_destroy(lua_State* L)
|
static int meth_destroy(lua_State* L)
|
||||||
{
|
{
|
||||||
X509_free(lsec_checkx509(L, 1));
|
p_x509 px = lsec_checkp_x509(L, 1);
|
||||||
|
if (px->cert) {
|
||||||
|
X509_free(px->cert);
|
||||||
|
px->cert = NULL;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -640,6 +655,23 @@ static int meth_set_encode(lua_State* L)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if (OPENSSL_VERSION_NUMBER >= 0x1010000fL)
|
||||||
|
/**
|
||||||
|
* Get signature name.
|
||||||
|
*/
|
||||||
|
static int meth_get_signature_name(lua_State* L)
|
||||||
|
{
|
||||||
|
p_x509 px = lsec_checkp_x509(L, 1);
|
||||||
|
int nid = X509_get_signature_nid(px->cert);
|
||||||
|
const char *name = OBJ_nid2sn(nid);
|
||||||
|
if (!name)
|
||||||
|
lua_pushnil(L);
|
||||||
|
else
|
||||||
|
lua_pushstring(L, name);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
static int load_cert(lua_State* L)
|
static int load_cert(lua_State* L)
|
||||||
@ -668,6 +700,9 @@ static luaL_Reg methods[] = {
|
|||||||
{"digest", meth_digest},
|
{"digest", meth_digest},
|
||||||
{"setencode", meth_set_encode},
|
{"setencode", meth_set_encode},
|
||||||
{"extensions", meth_extensions},
|
{"extensions", meth_extensions},
|
||||||
|
#if (OPENSSL_VERSION_NUMBER >= 0x1010000fL)
|
||||||
|
{"getsignaturename", meth_get_signature_name},
|
||||||
|
#endif
|
||||||
{"issuer", meth_issuer},
|
{"issuer", meth_issuer},
|
||||||
{"notbefore", meth_notbefore},
|
{"notbefore", meth_notbefore},
|
||||||
{"notafter", meth_notafter},
|
{"notafter", meth_notafter},
|
||||||
@ -684,6 +719,7 @@ static luaL_Reg methods[] = {
|
|||||||
* X509 metamethods.
|
* X509 metamethods.
|
||||||
*/
|
*/
|
||||||
static luaL_Reg meta[] = {
|
static luaL_Reg meta[] = {
|
||||||
|
{"__close", meth_destroy},
|
||||||
{"__gc", meth_destroy},
|
{"__gc", meth_destroy},
|
||||||
{"__tostring", meth_tostring},
|
{"__tostring", meth_tostring},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/*--------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------
|
||||||
* LuaSec 0.6
|
* LuaSec 1.3.2
|
||||||
*
|
*
|
||||||
* Copyright (C) 2014-2016 Kim Alvefur, Paul Aurich, Tobias Markmann
|
* Copyright (C) 2014-2023 Kim Alvefur, Paul Aurich, Tobias Markmann, Matthew Wild
|
||||||
* Matthew Wild, Bruno Silvestre.
|
* Copyright (C) 2013-2023 Bruno Silvestre
|
||||||
*
|
*
|
||||||
*--------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
@ -12,7 +12,7 @@
|
|||||||
#include <openssl/x509v3.h>
|
#include <openssl/x509v3.h>
|
||||||
#include <lua.h>
|
#include <lua.h>
|
||||||
|
|
||||||
#include "config.h"
|
#include "compat.h"
|
||||||
|
|
||||||
/* We do not support UniversalString nor BMPString as ASN.1 String types */
|
/* We do not support UniversalString nor BMPString as ASN.1 String types */
|
||||||
enum { LSEC_AI5_STRING, LSEC_UTF8_STRING };
|
enum { LSEC_AI5_STRING, LSEC_UTF8_STRING };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user