mirror of
https://github.com/brunoos/luasec.git
synced 2025-07-17 14:29:47 +02:00
Compare commits
5 Commits
luasec-0.7
...
luasec-0.5
Author | SHA1 | Date | |
---|---|---|---|
47cc914e69 | |||
90d4f2d95c | |||
172d324243 | |||
6cc8e951d4 | |||
d36e156fac |
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +0,0 @@
|
|||||||
/src/*.o
|
|
||||||
/src/luasocket/*.o
|
|
||||||
/*.dll
|
|
68
CHANGELOG
68
CHANGELOG
@ -1,69 +1,15 @@
|
|||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
LuaSec 0.7.2
|
LuaSec 0.5.1
|
||||||
---------------
|
|
||||||
This version includes:
|
|
||||||
|
|
||||||
* Fix unexported 'ssl.config' table
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
LuaSec 0.7.1
|
|
||||||
---------------
|
|
||||||
This version includes:
|
|
||||||
|
|
||||||
* Fix general_name leak in cert:extensions()
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
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 depends on OpenSSL, and integrates with LuaSocket to make it
|
- Check if SSLv3 protocol is available.
|
||||||
easy to add secure connections to any Lua applications or scripts.
|
- Fix push_asn1_string().
|
||||||
|
- Update samples to use 'sslv23' and 'tlsv1_2'.
|
||||||
Documentation: https://github.com/brunoos/luasec/wiki
|
- Update MACOSX_VERSION to 10.11 on Makefile.
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
=> Thanks to everyone who collaborate with LuaSec <=
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
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.
|
||||||
|
|
||||||
@ -137,7 +83,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<EFBFBD> Rebe)
|
||||||
- Add '_VERSION' variable to module.
|
- Add '_VERSION' variable to module.
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
6
INSTALL
6
INSTALL
@ -1,14 +1,14 @@
|
|||||||
LuaSec 0.7.2
|
LuaSec 0.5.1
|
||||||
------------
|
------------
|
||||||
|
|
||||||
* OpenSSL options:
|
* OpenSSL options:
|
||||||
|
|
||||||
By default, this version includes options for OpenSSL 1.1.1.
|
By default, LuaSec 0.5.1 includes options for OpenSSL 1.0.1e.
|
||||||
|
|
||||||
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.c
|
$ lua options.lua -g /usr/include/openssl/ssl.h > options.h
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
4
LICENSE
4
LICENSE
@ -1,5 +1,5 @@
|
|||||||
LuaSec 0.7.2 license
|
LuaSec 0.5.1 license
|
||||||
Copyright (C) 2006-2019 Bruno Silvestre, UFG
|
Copyright (C) 2006-2015 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
|
||||||
|
2
Makefile
2
Makefile
@ -16,7 +16,7 @@ INCDIR = -I. $(INC_PATH)
|
|||||||
LIBDIR = -L./luasocket $(LIB_PATH)
|
LIBDIR = -L./luasocket $(LIB_PATH)
|
||||||
|
|
||||||
# For Mac OS X: set the system version
|
# For Mac OS X: set the system version
|
||||||
MACOSX_VERSION=10.11
|
MACOSX_VERSION?=10.11
|
||||||
|
|
||||||
#----------------------
|
#----------------------
|
||||||
# Do not edit this part
|
# Do not edit this part
|
||||||
|
41
README.md
41
README.md
@ -1,6 +1,41 @@
|
|||||||
LuaSec 0.7.2
|
LuaSec 0.5.1
|
||||||
===============
|
============
|
||||||
|
- Check if SSLv3 protocol is available.
|
||||||
|
- Fix push_asn1_string().
|
||||||
|
- Update samples to use 'sslv23' and 'tlsv1_2'.
|
||||||
|
- Update MACOSX_VERSION to 10.11 on Makefile.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
Documentation: https://github.com/brunoos/luasec/wiki
|
This version includes:
|
||||||
|
|
||||||
|
* A new certificate (X509) API, which supports:
|
||||||
|
- Reading the subject (identity) and issuer of the certificate.
|
||||||
|
- Reading various X509 extensions, including email and dnsName.
|
||||||
|
- Converting certificates to and from the standard ASCII PEM
|
||||||
|
format.
|
||||||
|
- Generating the fingerprint/digest of a certificate (using SHA1,
|
||||||
|
SHA256 or SHA512).
|
||||||
|
- Reading the certificate's expiration, serial number, and other
|
||||||
|
info.
|
||||||
|
|
||||||
|
* The ability to get more detailed information from OpenSSL about
|
||||||
|
why a certificate failed verification, for each certificate in the
|
||||||
|
chain.
|
||||||
|
|
||||||
|
* Flags to force acceptance of invalid certificates, e.g. to allow
|
||||||
|
the use of self-signed certificates in a Trust On First Use model.
|
||||||
|
|
||||||
|
* Flags to control checking CRLs for certificate revocation status.
|
||||||
|
|
||||||
|
* Support for ECDH cipher suites.
|
||||||
|
|
||||||
|
* An API to get the TLS 'finished' messages used for SASL channel
|
||||||
|
binding (e.g. the SCRAM PLUS mechanisms).
|
||||||
|
|
||||||
|
The work in this release was undertaken by Kim Alvefur, Paul Aurich,
|
||||||
|
Tobias Markmann, Bruno Silvestre and Matthew Wild.
|
||||||
|
@ -1,105 +0,0 @@
|
|||||||
package = "LuaSec"
|
|
||||||
version = "0.7.2-1"
|
|
||||||
source = {
|
|
||||||
url = "https://github.com/brunoos/luasec/archive/luasec-0.7.2.tar.gz",
|
|
||||||
dir = "luasec-luasec-0.7.2"
|
|
||||||
}
|
|
||||||
description = {
|
|
||||||
summary = "A binding for OpenSSL library to provide TLS/SSL communication over LuaSocket.",
|
|
||||||
detailed = "This version delegates to LuaSocket the TCP connection establishment between the client and server. Then LuaSec uses this connection to start a secure TLS/SSL session.",
|
|
||||||
homepage = "https://github.com/brunoos/luasec/wiki",
|
|
||||||
license = "MIT"
|
|
||||||
}
|
|
||||||
dependencies = {
|
|
||||||
"lua >= 5.1", "luasocket"
|
|
||||||
}
|
|
||||||
external_dependencies = {
|
|
||||||
platforms = {
|
|
||||||
unix = {
|
|
||||||
OPENSSL = {
|
|
||||||
header = "openssl/ssl.h",
|
|
||||||
library = "ssl"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
windows = {
|
|
||||||
OPENSSL = {
|
|
||||||
header = "openssl/ssl.h",
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
build = {
|
|
||||||
type = "builtin",
|
|
||||||
copy_directories = {
|
|
||||||
"samples"
|
|
||||||
},
|
|
||||||
platforms = {
|
|
||||||
unix = {
|
|
||||||
install = {
|
|
||||||
lib = {
|
|
||||||
"ssl.so"
|
|
||||||
},
|
|
||||||
lua = {
|
|
||||||
"src/ssl.lua", ['ssl.https'] = "src/https.lua"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
modules = {
|
|
||||||
ssl = {
|
|
||||||
defines = {
|
|
||||||
"WITH_LUASOCKET", "LUASOCKET_DEBUG",
|
|
||||||
},
|
|
||||||
incdirs = {
|
|
||||||
"$(OPENSSL_INCDIR)", "src/", "src/luasocket",
|
|
||||||
},
|
|
||||||
libdirs = {
|
|
||||||
"$(OPENSSL_LIBDIR)"
|
|
||||||
},
|
|
||||||
libraries = {
|
|
||||||
"ssl", "crypto"
|
|
||||||
},
|
|
||||||
sources = {
|
|
||||||
"src/options.c", "src/config.c", "src/ec.c",
|
|
||||||
"src/x509.c", "src/context.c", "src/ssl.c",
|
|
||||||
"src/luasocket/buffer.c", "src/luasocket/io.c",
|
|
||||||
"src/luasocket/timeout.c", "src/luasocket/usocket.c"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
windows = {
|
|
||||||
install = {
|
|
||||||
lib = {
|
|
||||||
"ssl.dll"
|
|
||||||
},
|
|
||||||
lua = {
|
|
||||||
"src/ssl.lua", ['ssl.https'] = "src/https.lua"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
modules = {
|
|
||||||
ssl = {
|
|
||||||
defines = {
|
|
||||||
"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"
|
|
||||||
},
|
|
||||||
libdirs = {
|
|
||||||
"$(OPENSSL_LIBDIR)",
|
|
||||||
"$(OPENSSL_BINDIR)",
|
|
||||||
},
|
|
||||||
libraries = {
|
|
||||||
"libssl32MD", "libcrypto32MD", "ws2_32"
|
|
||||||
},
|
|
||||||
incdirs = {
|
|
||||||
"$(OPENSSL_INCDIR)", "src/", "src/luasocket"
|
|
||||||
},
|
|
||||||
sources = {
|
|
||||||
"src/options.c", "src/config.c", "src/ec.c",
|
|
||||||
"src/x509.c", "src/context.c", "src/ssl.c",
|
|
||||||
"src/luasocket/buffer.c", "src/luasocket/io.c",
|
|
||||||
"src/luasocket/timeout.c", "src/luasocket/wsocket.c"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
BIN
luasec.suo
Normal file
BIN
luasec.suo
Normal file
Binary file not shown.
253
luasec.vcproj
Normal file
253
luasec.vcproj
Normal file
@ -0,0 +1,253 @@
|
|||||||
|
<?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="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project DefaultTargets="Build" ToolsVersion="4.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,12 +18,10 @@
|
|||||||
<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">
|
||||||
@ -51,7 +49,7 @@
|
|||||||
<ClCompile>
|
<ClCompile>
|
||||||
<Optimization>Disabled</Optimization>
|
<Optimization>Disabled</Optimization>
|
||||||
<AdditionalIncludeDirectories>C:\devel\openssl\include;C:\devel\lua-dll9\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>C:\devel\openssl\include;C:\devel\lua-dll9\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;LUASEC_EXPORTS;LUASEC_INET_NTOP;WINVER=0x0501;_WIN32_WINNT=0x0501;NTDDI_VERSION=0x05010300;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;LUASEC_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<MinimalRebuild>true</MinimalRebuild>
|
<MinimalRebuild>true</MinimalRebuild>
|
||||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||||
@ -76,7 +74,7 @@
|
|||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
<AdditionalIncludeDirectories>C:\devel\openssl-1.1.0\include;C:\devel\lua-5.1\include;.\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>C:\devel\openssl\include;C:\devel\lua5.2\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>
|
||||||
@ -85,9 +83,9 @@
|
|||||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<AdditionalDependencies>ws2_32.lib;libssl32MD.lib;libcrypto32MD.lib;lua5.1.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>ws2_32.lib;libeay32MD.lib;ssleay32MD.lib;lua52.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
|
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
|
||||||
<AdditionalLibraryDirectories>C:\devel\openssl-1.1.0\lib\VC;C:\devel\lua-5.1\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
<AdditionalLibraryDirectories>C:\devel\openssl\lib\VC;C:\devel\lua5.2\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
<OptimizeReferences>true</OptimizeReferences>
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
@ -100,19 +98,15 @@
|
|||||||
</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" />
|
||||||
|
75
luasec.vcxproj.filters
Normal file
75
luasec.vcxproj.filters
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
<?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>
|
@ -17,7 +17,7 @@ Directories:
|
|||||||
Elliptic curve cipher.
|
Elliptic curve cipher.
|
||||||
|
|
||||||
* info
|
* info
|
||||||
Information about the connection.
|
Informations about the connection.
|
||||||
|
|
||||||
* key
|
* key
|
||||||
Test encrypted private key.
|
Test encrypted private key.
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
REM make sure the 'openssl.exe' commandline tool is in your path before starting!
|
|
||||||
REM set the path below;
|
|
||||||
set opensslpath=c:\program files (x86)\openssl-win32\bin
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
setlocal
|
|
||||||
set path=%opensslpath%;%path%
|
|
||||||
call roota.bat
|
|
||||||
call rootb.bat
|
|
||||||
call servera.bat
|
|
||||||
call serverb.bat
|
|
||||||
call clienta.bat
|
|
||||||
call clientb.bat
|
|
@ -1,9 +0,0 @@
|
|||||||
rem #!/bin/sh
|
|
||||||
|
|
||||||
openssl req -newkey rsa:1024 -sha1 -keyout clientAkey.pem -out clientAreq.pem -nodes -config ./clientA.cnf -days 365 -batch
|
|
||||||
|
|
||||||
openssl x509 -req -in clientAreq.pem -sha1 -extfile ./clientA.cnf -extensions usr_cert -CA rootA.pem -CAkey rootAkey.pem -CAcreateserial -out clientAcert.pem -days 365
|
|
||||||
|
|
||||||
copy clientAcert.pem + rootA.pem clientA.pem
|
|
||||||
|
|
||||||
openssl x509 -subject -issuer -noout -in clientA.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 extensions to add to the cert
|
x509_extensions = usr_cert # The extentions 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 extensions to add to the self signed cert
|
x509_extensions = v3_ca # The extentions 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 +0,0 @@
|
|||||||
rem #!/bin/sh
|
|
||||||
|
|
||||||
openssl req -newkey rsa:1024 -sha1 -keyout clientBkey.pem -out clientBreq.pem -nodes -config ./clientB.cnf -days 365 -batch
|
|
||||||
|
|
||||||
openssl x509 -req -in clientBreq.pem -sha1 -extfile ./clientB.cnf -extensions usr_cert -CA rootB.pem -CAkey rootBkey.pem -CAcreateserial -out clientBcert.pem -days 365
|
|
||||||
|
|
||||||
copy clientBcert.pem + rootB.pem clientB.pem
|
|
||||||
|
|
||||||
openssl x509 -subject -issuer -noout -in clientB.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 extensions to add to the cert
|
x509_extensions = usr_cert # The extentions 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 extensions to add to the self signed cert
|
x509_extensions = v3_ca # The extentions 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 +0,0 @@
|
|||||||
REM #!/bin/sh
|
|
||||||
|
|
||||||
openssl req -newkey rsa:1024 -sha1 -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 -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 extensions to add to the cert
|
x509_extensions = usr_cert # The extentions 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 extensions to add to the self signed cert
|
x509_extensions = v3_ca # The extentions 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 +0,0 @@
|
|||||||
rem #!/bin/sh
|
|
||||||
|
|
||||||
openssl req -newkey rsa:1024 -sha1 -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 -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 extensions to add to the cert
|
x509_extensions = usr_cert # The extentions 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 extensions to add to the self signed cert
|
x509_extensions = v3_ca # The extentions 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 +0,0 @@
|
|||||||
rem #!/bin/sh
|
|
||||||
|
|
||||||
openssl req -newkey rsa:1024 -keyout serverAkey.pem -out serverAreq.pem -config ./serverA.cnf -nodes -days 365 -batch
|
|
||||||
|
|
||||||
openssl x509 -req -in serverAreq.pem -sha1 -extfile ./serverA.cnf -extensions usr_cert -CA rootA.pem -CAkey rootAkey.pem -CAcreateserial -out serverAcert.pem -days 365
|
|
||||||
|
|
||||||
copy serverAcert.pem + rootA.pem serverA.pem
|
|
||||||
|
|
||||||
openssl x509 -subject -issuer -noout -in serverA.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 extensions to add to the cert
|
x509_extensions = usr_cert # The extentions 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 extensions to add to the self signed cert
|
x509_extensions = v3_ca # The extentions 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 +0,0 @@
|
|||||||
rem #!/bin/sh
|
|
||||||
|
|
||||||
openssl req -newkey rsa:1024 -keyout serverBkey.pem -out serverBreq.pem -config ./serverB.cnf -nodes -days 365 -batch
|
|
||||||
|
|
||||||
openssl x509 -req -in serverBreq.pem -sha1 -extfile ./serverB.cnf -extensions usr_cert -CA rootB.pem -CAkey rootBkey.pem -CAcreateserial -out serverBcert.pem -days 365
|
|
||||||
|
|
||||||
copy serverBcert.pem + rootB.pem serverB.pem
|
|
||||||
|
|
||||||
openssl x509 -subject -issuer -noout -in serverB.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 extensions to add to the cert
|
x509_extensions = usr_cert # The extentions 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 extensions to add to the self signed cert
|
x509_extensions = v3_ca # The extentions 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
|
||||||
|
@ -7,7 +7,7 @@ local util = require("util")
|
|||||||
|
|
||||||
local params = {
|
local params = {
|
||||||
mode = "server",
|
mode = "server",
|
||||||
protocol = "any",
|
protocol = "sslv23",
|
||||||
key = "../certs/serverAkey.pem",
|
key = "../certs/serverAkey.pem",
|
||||||
certificate = "../certs/serverA.pem",
|
certificate = "../certs/serverA.pem",
|
||||||
cafile = "../certs/rootA.pem",
|
cafile = "../certs/rootA.pem",
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
--
|
|
||||||
-- 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()
|
|
@ -1,37 +0,0 @@
|
|||||||
--
|
|
||||||
-- 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()
|
|
@ -31,7 +31,7 @@ end
|
|||||||
|
|
||||||
local params = {
|
local params = {
|
||||||
mode = "server",
|
mode = "server",
|
||||||
protocol = "any",
|
protocol = "sslv23",
|
||||||
key = "../certs/serverAkey.pem",
|
key = "../certs/serverAkey.pem",
|
||||||
certificate = "../certs/serverA.pem",
|
certificate = "../certs/serverA.pem",
|
||||||
cafile = "../certs/rootA.pem",
|
cafile = "../certs/rootA.pem",
|
||||||
|
@ -6,7 +6,7 @@ local ssl = require("ssl")
|
|||||||
|
|
||||||
local params = {
|
local params = {
|
||||||
mode = "server",
|
mode = "server",
|
||||||
protocol = "any",
|
protocol = "sslv23",
|
||||||
key = "../certs/serverAkey.pem",
|
key = "../certs/serverAkey.pem",
|
||||||
certificate = "../certs/serverA.pem",
|
certificate = "../certs/serverA.pem",
|
||||||
cafile = "../certs/rootA.pem",
|
cafile = "../certs/rootA.pem",
|
||||||
|
@ -6,7 +6,7 @@ local ssl = require("ssl")
|
|||||||
|
|
||||||
local params = {
|
local params = {
|
||||||
mode = "server",
|
mode = "server",
|
||||||
protocol = "any",
|
protocol = "sslv23",
|
||||||
key = "../certs/serverAkey.pem",
|
key = "../certs/serverAkey.pem",
|
||||||
certificate = "../certs/serverA.pem",
|
certificate = "../certs/serverA.pem",
|
||||||
cafile = "../certs/rootA.pem",
|
cafile = "../certs/rootA.pem",
|
||||||
|
@ -6,7 +6,7 @@ local ssl = require("ssl")
|
|||||||
|
|
||||||
local params = {
|
local params = {
|
||||||
mode = "server",
|
mode = "server",
|
||||||
protocol = "any",
|
protocol = "sslv23",
|
||||||
key = "../certs/serverAkey.pem",
|
key = "../certs/serverAkey.pem",
|
||||||
certificate = "../certs/serverA.pem",
|
certificate = "../certs/serverA.pem",
|
||||||
cafile = "../certs/rootA.pem",
|
cafile = "../certs/rootA.pem",
|
||||||
|
@ -5,7 +5,7 @@ local ssl = require("ssl")
|
|||||||
|
|
||||||
local pass = "foobar"
|
local pass = "foobar"
|
||||||
local cfg = {
|
local cfg = {
|
||||||
protocol = "tlsv1",
|
protocol = "tlsv1_2",
|
||||||
mode = "client",
|
mode = "client",
|
||||||
key = "key.pem",
|
key = "key.pem",
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ local ssl = require("ssl")
|
|||||||
|
|
||||||
local params = {
|
local params = {
|
||||||
mode = "server",
|
mode = "server",
|
||||||
protocol = "any",
|
protocol = "sslv23",
|
||||||
key = "../certs/serverAkey.pem",
|
key = "../certs/serverAkey.pem",
|
||||||
certificate = "../certs/serverA.pem",
|
certificate = "../certs/serverA.pem",
|
||||||
cafile = "../certs/rootA.pem",
|
cafile = "../certs/rootA.pem",
|
||||||
|
@ -6,7 +6,7 @@ local ssl = require("ssl")
|
|||||||
|
|
||||||
local params = {
|
local params = {
|
||||||
mode = "server",
|
mode = "server",
|
||||||
protocol = "any",
|
protocol = "sslv23",
|
||||||
key = "../certs/serverAkey.pem",
|
key = "../certs/serverAkey.pem",
|
||||||
certificate = "../certs/serverA.pem",
|
certificate = "../certs/serverA.pem",
|
||||||
cafile = "../certs/rootA.pem",
|
cafile = "../certs/rootA.pem",
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
--
|
|
||||||
-- 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()
|
|
@ -1,58 +0,0 @@
|
|||||||
--
|
|
||||||
-- 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()
|
|
@ -6,7 +6,7 @@ local ssl = require("ssl")
|
|||||||
|
|
||||||
local params = {
|
local params = {
|
||||||
mode = "server",
|
mode = "server",
|
||||||
protocol = "any",
|
protocol = "sslv23",
|
||||||
key = "../certs/serverAkey.pem",
|
key = "../certs/serverAkey.pem",
|
||||||
certificate = "../certs/serverA.pem",
|
certificate = "../certs/serverA.pem",
|
||||||
cafile = "../certs/rootA.pem",
|
cafile = "../certs/rootA.pem",
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
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",
|
|
||||||
options = "all",
|
|
||||||
}
|
|
||||||
|
|
||||||
local conn = socket.tcp()
|
|
||||||
conn:connect("127.0.0.1", 8888)
|
|
||||||
|
|
||||||
-- TLS/SSL initialization
|
|
||||||
conn = ssl.wrap(conn, params)
|
|
||||||
|
|
||||||
-- Comment the lines to not send a name
|
|
||||||
--conn:sni("servera.br")
|
|
||||||
--conn:sni("serveraa.br")
|
|
||||||
conn:sni("serverb.br")
|
|
||||||
|
|
||||||
assert(conn:dohandshake())
|
|
||||||
--
|
|
||||||
local cert = conn:getpeercertificate()
|
|
||||||
for k, v in pairs(cert:subject()) do
|
|
||||||
for i, j in pairs(v) do
|
|
||||||
print(i, j)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
--
|
|
||||||
print(conn:receive("*l"))
|
|
||||||
conn:close()
|
|
@ -1,52 +0,0 @@
|
|||||||
local socket = require("socket")
|
|
||||||
local ssl = require("ssl")
|
|
||||||
|
|
||||||
local params01 = {
|
|
||||||
mode = "server",
|
|
||||||
protocol = "any",
|
|
||||||
key = "../certs/serverAkey.pem",
|
|
||||||
certificate = "../certs/serverA.pem",
|
|
||||||
cafile = "../certs/rootA.pem",
|
|
||||||
verify = "none",
|
|
||||||
options = "all",
|
|
||||||
ciphers = "ALL:!ADH:@STRENGTH",
|
|
||||||
}
|
|
||||||
|
|
||||||
local params02 = {
|
|
||||||
mode = "server",
|
|
||||||
protocol = "any",
|
|
||||||
key = "../certs/serverAAkey.pem",
|
|
||||||
certificate = "../certs/serverAA.pem",
|
|
||||||
cafile = "../certs/rootA.pem",
|
|
||||||
verify = "none",
|
|
||||||
options = "all",
|
|
||||||
ciphers = "ALL:!ADH:@STRENGTH",
|
|
||||||
}
|
|
||||||
|
|
||||||
--
|
|
||||||
local ctx01 = ssl.newcontext(params01)
|
|
||||||
local ctx02 = ssl.newcontext(params02)
|
|
||||||
|
|
||||||
--
|
|
||||||
local server = socket.tcp()
|
|
||||||
server:setoption('reuseaddr', true)
|
|
||||||
server:bind("127.0.0.1", 8888)
|
|
||||||
server:listen()
|
|
||||||
local conn = server:accept()
|
|
||||||
--
|
|
||||||
|
|
||||||
-- Default context (when client does not send a name) is ctx01
|
|
||||||
conn = ssl.wrap(conn, ctx01)
|
|
||||||
|
|
||||||
-- Configure the name map
|
|
||||||
local sni_map = {
|
|
||||||
["servera.br"] = ctx01,
|
|
||||||
["serveraa.br"] = ctx02,
|
|
||||||
}
|
|
||||||
|
|
||||||
conn:sni(sni_map, true)
|
|
||||||
|
|
||||||
assert(conn:dohandshake())
|
|
||||||
--
|
|
||||||
conn:send("one line\n")
|
|
||||||
conn:close()
|
|
@ -6,7 +6,7 @@ local ssl = require("ssl")
|
|||||||
|
|
||||||
local params = {
|
local params = {
|
||||||
mode = "client",
|
mode = "client",
|
||||||
protocol = "tlsv1",
|
protocol = "tlsv1_2",
|
||||||
key = "../../certs/clientBkey.pem",
|
key = "../../certs/clientBkey.pem",
|
||||||
certificate = "../../certs/clientB.pem",
|
certificate = "../../certs/clientB.pem",
|
||||||
cafile = "../../certs/rootB.pem",
|
cafile = "../../certs/rootB.pem",
|
||||||
|
@ -6,7 +6,7 @@ local ssl = require("ssl")
|
|||||||
|
|
||||||
local params = {
|
local params = {
|
||||||
mode = "server",
|
mode = "server",
|
||||||
protocol = "tlsv1",
|
protocol = "sslv23",
|
||||||
key = "../../certs/serverAkey.pem",
|
key = "../../certs/serverAkey.pem",
|
||||||
certificate = "../../certs/serverA.pem",
|
certificate = "../../certs/serverA.pem",
|
||||||
cafile = "../../certs/rootA.pem",
|
cafile = "../../certs/rootA.pem",
|
||||||
|
@ -6,12 +6,12 @@ local ssl = require("ssl")
|
|||||||
|
|
||||||
local params = {
|
local params = {
|
||||||
mode = "client",
|
mode = "client",
|
||||||
protocol = "tlsv1",
|
protocol = "tlsv1_2",
|
||||||
key = "../../certs/clientBkey.pem",
|
key = "../../certs/clientBkey.pem",
|
||||||
certificate = "../../certs/clientB.pem",
|
certificate = "../../certs/clientB.pem",
|
||||||
cafile = "../../certs/rootB.pem",
|
cafile = "../../certs/rootB.pem",
|
||||||
verify = {"peer", "fail_if_no_peer_cert"},
|
verify = {"peer", "fail_if_no_peer_cert"},
|
||||||
options = "all",
|
options = "all", ,
|
||||||
verifyext = "lsec_continue",
|
verifyext = "lsec_continue",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ local ssl = require("ssl")
|
|||||||
|
|
||||||
local params = {
|
local params = {
|
||||||
mode = "server",
|
mode = "server",
|
||||||
protocol = "tlsv1",
|
protocol = "sslv23",
|
||||||
key = "../../certs/serverAkey.pem",
|
key = "../../certs/serverAkey.pem",
|
||||||
certificate = "../../certs/serverA.pem",
|
certificate = "../../certs/serverA.pem",
|
||||||
cafile = "../../certs/rootA.pem",
|
cafile = "../../certs/rootA.pem",
|
||||||
|
@ -6,7 +6,7 @@ local ssl = require("ssl")
|
|||||||
|
|
||||||
local params = {
|
local params = {
|
||||||
mode = "client",
|
mode = "client",
|
||||||
protocol = "tlsv1",
|
protocol = "tlsv1_2",
|
||||||
key = "../../certs/clientAkey.pem",
|
key = "../../certs/clientAkey.pem",
|
||||||
certificate = "../../certs/clientA.pem",
|
certificate = "../../certs/clientA.pem",
|
||||||
cafile = "../../certs/rootA.pem",
|
cafile = "../../certs/rootA.pem",
|
||||||
|
@ -6,7 +6,7 @@ local ssl = require("ssl")
|
|||||||
|
|
||||||
local params = {
|
local params = {
|
||||||
mode = "server",
|
mode = "server",
|
||||||
protocol = "tlsv1",
|
protocol = "sslv23",
|
||||||
key = "../../certs/serverAkey.pem",
|
key = "../../certs/serverAkey.pem",
|
||||||
certificate = "../../certs/serverA.pem",
|
certificate = "../../certs/serverA.pem",
|
||||||
cafile = "../../certs/rootA.pem",
|
cafile = "../../certs/rootA.pem",
|
||||||
|
@ -6,7 +6,7 @@ local ssl = require("ssl")
|
|||||||
|
|
||||||
local params = {
|
local params = {
|
||||||
mode = "server",
|
mode = "server",
|
||||||
protocol = "any",
|
protocol = "sslv23",
|
||||||
key = "../certs/serverAkey.pem",
|
key = "../certs/serverAkey.pem",
|
||||||
certificate = "../certs/serverA.pem",
|
certificate = "../certs/serverA.pem",
|
||||||
cafile = "../certs/rootA.pem",
|
cafile = "../certs/rootA.pem",
|
||||||
|
@ -6,7 +6,7 @@ local ssl = require("ssl")
|
|||||||
|
|
||||||
local params = {
|
local params = {
|
||||||
mode = "server",
|
mode = "server",
|
||||||
protocol = "any",
|
protocol = "sslv23",
|
||||||
key = "../certs/serverAkey.pem",
|
key = "../certs/serverAkey.pem",
|
||||||
certificate = "../certs/serverA.pem",
|
certificate = "../certs/serverA.pem",
|
||||||
cafile = "../certs/rootA.pem",
|
cafile = "../certs/rootA.pem",
|
||||||
|
@ -8,7 +8,7 @@ local ssl = require("ssl")
|
|||||||
|
|
||||||
local params = {
|
local params = {
|
||||||
mode = "server",
|
mode = "server",
|
||||||
protocol = "any",
|
protocol = "sslv23",
|
||||||
key = "../certs/serverAkey.pem",
|
key = "../certs/serverAkey.pem",
|
||||||
certificate = "../certs/serverA.pem",
|
certificate = "../certs/serverA.pem",
|
||||||
cafile = "../certs/rootA.pem",
|
cafile = "../certs/rootA.pem",
|
||||||
|
@ -8,7 +8,7 @@ print("Use Ctrl+S and Ctrl+Q to suspend and resume the server.")
|
|||||||
|
|
||||||
local params = {
|
local params = {
|
||||||
mode = "server",
|
mode = "server",
|
||||||
protocol = "any",
|
protocol = "sslv23",
|
||||||
key = "../certs/serverAkey.pem",
|
key = "../certs/serverAkey.pem",
|
||||||
certificate = "../certs/serverA.pem",
|
certificate = "../certs/serverA.pem",
|
||||||
cafile = "../certs/rootA.pem",
|
cafile = "../certs/rootA.pem",
|
||||||
|
23
src/Makefile
23
src/Makefile
@ -2,12 +2,9 @@ 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
|
||||||
|
|
||||||
@ -23,11 +20,12 @@ MAC_ENV=env MACOSX_DEPLOYMENT_TARGET='$(MACVER)'
|
|||||||
MAC_CFLAGS=-O2 -fno-common $(WARN) $(INCDIR) $(DEFS)
|
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
|
LD ?= $(MYENV) cc
|
||||||
CFLAGS += $(MYCFLAGS)
|
CFLAGS += $(MYCFLAGS)
|
||||||
LDFLAGS += $(MYLDFLAGS)
|
LDFLAGS += $(MYLDFLAGS)
|
||||||
|
DESTDIR ?= /
|
||||||
|
|
||||||
.PHONY: all clean install none linux bsd macosx luasocket
|
.PHONY: all clean install none linux bsd macosx luasocket
|
||||||
|
|
||||||
@ -35,9 +33,9 @@ all:
|
|||||||
|
|
||||||
install: $(CMOD) $(LMOD)
|
install: $(CMOD) $(LMOD)
|
||||||
$(INSTALL) -d $(DESTDIR)$(LUAPATH)/ssl $(DESTDIR)$(LUACPATH)
|
$(INSTALL) -d $(DESTDIR)$(LUAPATH)/ssl $(DESTDIR)$(LUACPATH)
|
||||||
$(INSTALL) $(CMOD) $(DESTDIR)$(LUACPATH)
|
$(INSTALL) -D $(CMOD) $(DESTDIR)$(LUACPATH)
|
||||||
$(INSTALL) -m644 $(LMOD) $(DESTDIR)$(LUAPATH)
|
$(INSTALL) -m644 -D $(LMOD) $(DESTDIR)$(LUAPATH)
|
||||||
$(INSTALL) -m644 https.lua $(DESTDIR)$(LUAPATH)/ssl
|
$(INSTALL) -m644 -D 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)"
|
||||||
@ -58,9 +56,6 @@ clean:
|
|||||||
cd luasocket && $(MAKE) clean
|
cd luasocket && $(MAKE) clean
|
||||||
rm -f $(OBJS) $(CMOD)
|
rm -f $(OBJS) $(CMOD)
|
||||||
|
|
||||||
options.o: options.h options.c
|
x509.o: x509.c x509.h config.h
|
||||||
ec.o: ec.c ec.h
|
context.o: context.c context.h ec.h config.h
|
||||||
x509.o: x509.c x509.h compat.h
|
ssl.o: ssl.c ssl.h context.h x509.h config.h
|
||||||
context.o: context.c context.h ec.h compat.h
|
|
||||||
ssl.o: ssl.c ssl.h context.h x509.h compat.h
|
|
||||||
config.o: config.c ec.h options.h compat.h
|
|
||||||
|
31
src/compat.h
31
src/compat.h
@ -1,31 +0,0 @@
|
|||||||
/*--------------------------------------------------------------------------
|
|
||||||
* LuaSec 0.7.2
|
|
||||||
*
|
|
||||||
* Copyright (C) 2006-2019 Bruno Silvestre
|
|
||||||
*
|
|
||||||
*--------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
#ifndef LSEC_COMPAT_H
|
|
||||||
#define LSEC_COMPAT_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
|
|
||||||
|
|
||||||
#endif
|
|
88
src/config.c
88
src/config.c
@ -1,88 +0,0 @@
|
|||||||
/*--------------------------------------------------------------------------
|
|
||||||
* LuaSec 0.7.2
|
|
||||||
*
|
|
||||||
* Copyright (C) 2006-2019 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);
|
|
||||||
|
|
||||||
#ifndef OPENSSL_NO_SSL3
|
|
||||||
lua_pushstring(L, "sslv3");
|
|
||||||
lua_pushboolean(L, 1);
|
|
||||||
lua_rawset(L, -3);
|
|
||||||
#endif
|
|
||||||
lua_pushstring(L, "tlsv1");
|
|
||||||
lua_pushboolean(L, 1);
|
|
||||||
lua_rawset(L, -3);
|
|
||||||
#if (OPENSSL_VERSION_NUMBER >= 0x1000100fL)
|
|
||||||
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);
|
|
||||||
#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);
|
|
||||||
|
|
||||||
#ifndef OPENSSL_NO_EC
|
|
||||||
#if defined(SSL_CTRL_SET_ECDH_AUTO) || defined(SSL_CTRL_SET_CURVES_LIST) || defined(SSL_CTX_set1_curves_list)
|
|
||||||
lua_pushstring(L, "curves_list");
|
|
||||||
lua_pushboolean(L, 1);
|
|
||||||
lua_rawset(L, -3);
|
|
||||||
#ifdef SSL_CTRL_SET_ECDH_AUTO
|
|
||||||
lua_pushstring(L, "ecdh_auto");
|
|
||||||
lua_pushboolean(L, 1);
|
|
||||||
lua_rawset(L, -3);
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
lua_rawset(L, -3);
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
20
src/config.h
Normal file
20
src/config.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/*--------------------------------------------------------------------------
|
||||||
|
* LuaSec 0.5.1
|
||||||
|
* Copyright (C) 2006-2015 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 lua_rawlen(L, i) lua_objlen(L, i)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
160
src/context.c
160
src/context.c
@ -1,9 +1,9 @@
|
|||||||
/*--------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------
|
||||||
* LuaSec 0.7.2
|
* LuaSec 0.5.1
|
||||||
*
|
*
|
||||||
* Copyright (C) 2014-2019 Kim Alvefur, Paul Aurich, Tobias Markmann,
|
* Copyright (C) 2014-2015 Kim Alvefur, Paul Aurich, Tobias Markmann,
|
||||||
* Matthew Wild.
|
* Matthew Wild.
|
||||||
* Copyright (C) 2006-2019 Bruno Silvestre.
|
* Copyright (C) 2006-2015 Bruno Silvestre.
|
||||||
*
|
*
|
||||||
*--------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
@ -24,7 +24,7 @@
|
|||||||
#include "context.h"
|
#include "context.h"
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
|
|
||||||
#ifndef OPENSSL_NO_EC
|
#ifndef OPENSSL_NO_ECDH
|
||||||
#include <openssl/ec.h>
|
#include <openssl/ec.h>
|
||||||
#include "ec.h"
|
#include "ec.h"
|
||||||
#endif
|
#endif
|
||||||
@ -35,6 +35,10 @@ typedef const SSL_METHOD LSEC_SSL_METHOD;
|
|||||||
typedef SSL_METHOD LSEC_SSL_METHOD;
|
typedef SSL_METHOD LSEC_SSL_METHOD;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if OPENSSL_VERSION_NUMBER>=0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)
|
||||||
|
#define SSLv23_method() TLS_method()
|
||||||
|
#endif
|
||||||
|
|
||||||
/*--------------------------- Auxiliary Functions ----------------------------*/
|
/*--------------------------- Auxiliary Functions ----------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,18 +49,13 @@ static p_context checkctx(lua_State *L, int idx)
|
|||||||
return (p_context)luaL_checkudata(L, idx, "SSL:Context");
|
return (p_context)luaL_checkudata(L, idx, "SSL:Context");
|
||||||
}
|
}
|
||||||
|
|
||||||
static p_context testctx(lua_State *L, int idx)
|
|
||||||
{
|
|
||||||
return (p_context)luaL_testudata(L, idx, "SSL:Context");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare the SSL options flag.
|
* Prepare the SSL options flag.
|
||||||
*/
|
*/
|
||||||
static int set_option_flag(const char *opt, unsigned long *flag)
|
static int set_option_flag(const char *opt, unsigned long *flag)
|
||||||
{
|
{
|
||||||
lsec_ssl_option_t *p;
|
ssl_option_t *p;
|
||||||
for (p = lsec_get_ssl_options(); p->name; p++) {
|
for (p = 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;
|
||||||
@ -70,8 +69,7 @@ static int set_option_flag(const char *opt, unsigned long *flag)
|
|||||||
*/
|
*/
|
||||||
static LSEC_SSL_METHOD* str2method(const char *method)
|
static LSEC_SSL_METHOD* str2method(const char *method)
|
||||||
{
|
{
|
||||||
if (!strcmp(method, "any")) return SSLv23_method();
|
if (!strcmp(method, "sslv23")) return SSLv23_method();
|
||||||
if (!strcmp(method, "sslv23")) return SSLv23_method(); // deprecated
|
|
||||||
#ifndef OPENSSL_NO_SSL3
|
#ifndef OPENSSL_NO_SSL3
|
||||||
if (!strcmp(method, "sslv3")) return SSLv3_method();
|
if (!strcmp(method, "sslv3")) return SSLv3_method();
|
||||||
#endif
|
#endif
|
||||||
@ -278,6 +276,18 @@ 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 -------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -391,17 +401,6 @@ static int load_key(lua_State *L)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Check that the certificate public key matches the private key
|
|
||||||
*/
|
|
||||||
|
|
||||||
static int check_key(lua_State *L)
|
|
||||||
{
|
|
||||||
SSL_CTX *ctx = lsec_checkcontext(L, 1);
|
|
||||||
lua_pushboolean(L, SSL_CTX_check_private_key(ctx));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the cipher list.
|
* Set the cipher list.
|
||||||
*/
|
*/
|
||||||
@ -425,7 +424,7 @@ static int set_cipher(lua_State *L)
|
|||||||
static int set_depth(lua_State *L)
|
static int set_depth(lua_State *L)
|
||||||
{
|
{
|
||||||
SSL_CTX *ctx = lsec_checkcontext(L, 1);
|
SSL_CTX *ctx = lsec_checkcontext(L, 1);
|
||||||
SSL_CTX_set_verify_depth(ctx, (int)luaL_checkinteger(L, 2));
|
SSL_CTX_set_verify_depth(ctx, luaL_checkint(L, 2));
|
||||||
lua_pushboolean(L, 1);
|
lua_pushboolean(L, 1);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -524,23 +523,27 @@ 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;
|
||||||
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);
|
|
||||||
|
|
||||||
EC_KEY *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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -554,33 +557,6 @@ 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);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(OPENSSL_NO_EC) && (defined(SSL_CTRL_SET_CURVES_LIST) || defined(SSL_CTX_set1_curves_list) || defined(SSL_CTRL_SET_ECDH_AUTO))
|
|
||||||
/**
|
|
||||||
* 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef SSL_CTRL_SET_ECDH_AUTO
|
|
||||||
SSL_CTX_set_ecdh_auto(ctx, 1);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
lua_pushboolean(L, 1);
|
lua_pushboolean(L, 1);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -594,22 +570,13 @@ static luaL_Reg funcs[] = {
|
|||||||
{"locations", load_locations},
|
{"locations", load_locations},
|
||||||
{"loadcert", load_cert},
|
{"loadcert", load_cert},
|
||||||
{"loadkey", load_key},
|
{"loadkey", load_key},
|
||||||
{"checkkey", check_key},
|
|
||||||
{"setcipher", set_cipher},
|
{"setcipher", set_cipher},
|
||||||
{"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},
|
||||||
{"setmode", set_mode},
|
{"setmode", set_mode},
|
||||||
|
|
||||||
#if !defined(OPENSSL_NO_EC)
|
|
||||||
{"setcurve", set_curve},
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(OPENSSL_NO_EC) && (defined(SSL_CTRL_SET_CURVES_LIST) || defined(SSL_CTX_set1_curves_list) || defined(SSL_CTRL_SET_ECDH_AUTO))
|
|
||||||
{"setcurveslist", set_curves_list},
|
|
||||||
#endif
|
|
||||||
|
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -736,12 +703,6 @@ SSL_CTX* lsec_checkcontext(lua_State *L, int idx)
|
|||||||
return ctx->context;
|
return ctx->context;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSL_CTX* lsec_testcontext(lua_State *L, int idx)
|
|
||||||
{
|
|
||||||
p_context ctx = testctx(L, idx);
|
|
||||||
return (ctx) ? ctx->context : NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the mode from the context in the Lua stack.
|
* Retrieve the mode from the context in the Lua stack.
|
||||||
*/
|
*/
|
||||||
@ -751,45 +712,44 @@ 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 ------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registre the module.
|
* Registre the module.
|
||||||
*/
|
*/
|
||||||
|
#if (LUA_VERSION_NUM == 501)
|
||||||
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: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);
|
luaL_register(L, NULL, meta);
|
||||||
|
|
||||||
/* Create __index metamethods for context */
|
/* Create __index metamethods for context */
|
||||||
luaL_newlib(L, meta_index);
|
lua_newtable(L);
|
||||||
|
luaL_register(L, NULL, meta_index);
|
||||||
lua_setfield(L, -2, "__index");
|
lua_setfield(L, -2, "__index");
|
||||||
|
|
||||||
lsec_load_curves(L);
|
/* Register the module */
|
||||||
|
luaL_register(L, "ssl.context", funcs);
|
||||||
/* Return the module */
|
|
||||||
luaL_newlib(L, funcs);
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
LSEC_API int luaopen_ssl_context(lua_State *L)
|
||||||
|
{
|
||||||
|
luaL_newmetatable(L, "SSL:DH:Registry"); /* Keep all DH callbacks */
|
||||||
|
luaL_newmetatable(L, "SSL:Verify:Registry"); /* Keep all verify flags */
|
||||||
|
luaL_newmetatable(L, "SSL:Context");
|
||||||
|
luaL_setfuncs(L, meta, 0);
|
||||||
|
|
||||||
|
/* Create __index metamethods for context */
|
||||||
|
lua_newtable(L);
|
||||||
|
luaL_setfuncs(L, meta_index, 0);
|
||||||
|
lua_setfield(L, -2, "__index");
|
||||||
|
|
||||||
|
/* Return the module */
|
||||||
|
lua_newtable(L);
|
||||||
|
luaL_setfuncs(L, funcs, 0);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
@ -2,16 +2,15 @@
|
|||||||
#define LSEC_CONTEXT_H
|
#define LSEC_CONTEXT_H
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------
|
||||||
* LuaSec 0.7.2
|
* LuaSec 0.5.1
|
||||||
*
|
* Copyright (C) 2006-2015 Bruno Silvestre
|
||||||
* Copyright (C) 2006-2019 Bruno Silvestre
|
|
||||||
*
|
*
|
||||||
*--------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include <lua.h>
|
#include <lua.h>
|
||||||
#include <openssl/ssl.h>
|
#include <openssl/ssl.h>
|
||||||
|
|
||||||
#include "compat.h"
|
#include "config.h"
|
||||||
|
|
||||||
#define LSEC_MODE_INVALID 0
|
#define LSEC_MODE_INVALID 0
|
||||||
#define LSEC_MODE_SERVER 1
|
#define LSEC_MODE_SERVER 1
|
||||||
@ -30,7 +29,6 @@ typedef t_context* p_context;
|
|||||||
|
|
||||||
/* Retrieve the SSL context from the Lua stack */
|
/* Retrieve the SSL context from the Lua stack */
|
||||||
SSL_CTX *lsec_checkcontext(lua_State *L, int idx);
|
SSL_CTX *lsec_checkcontext(lua_State *L, int idx);
|
||||||
SSL_CTX *lsec_testcontext(lua_State *L, int idx);
|
|
||||||
|
|
||||||
/* Retrieve the mode from the context in the Lua stack */
|
/* Retrieve the mode from the context in the Lua stack */
|
||||||
int lsec_getmode(lua_State *L, int idx);
|
int lsec_getmode(lua_State *L, int idx);
|
||||||
@ -38,9 +36,4 @@ 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
|
||||||
|
110
src/ec.c
110
src/ec.c
@ -1,110 +0,0 @@
|
|||||||
#include <openssl/objects.h>
|
|
||||||
|
|
||||||
#include "ec.h"
|
|
||||||
|
|
||||||
#ifndef OPENSSL_NO_ECDH
|
|
||||||
|
|
||||||
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;
|
|
||||||
#ifdef NID_X25519
|
|
||||||
case NID_X25519:
|
|
||||||
lua_pushstring(L, "X25519");
|
|
||||||
lua_pushnumber(L, curves[i].nid);
|
|
||||||
lua_rawset(L, -3);
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
#ifdef NID_X448
|
|
||||||
case NID_X448:
|
|
||||||
lua_pushstring(L, "X448");
|
|
||||||
lua_pushnumber(L, curves[i].nid);
|
|
||||||
lua_rawset(L, -3);
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
free(curves);
|
|
||||||
}
|
|
||||||
|
|
||||||
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,22 +1,64 @@
|
|||||||
/*--------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------
|
||||||
* LuaSec 0.7.2
|
* LuaSec 0.5.1
|
||||||
*
|
* Copyright (C) 2006-2015 Bruno Silvestre
|
||||||
* Copyright (C) 2006-2019 Bruno Silvestre
|
|
||||||
*
|
*
|
||||||
*--------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifndef LSEC_EC_H
|
#ifndef LSEC_EC_H
|
||||||
#define LSEC_EC_H
|
#define LSEC_EC_H
|
||||||
|
|
||||||
#include <lua.h>
|
#include <openssl/objects.h>
|
||||||
|
|
||||||
#ifndef OPENSSL_NO_ECDH
|
typedef struct t_ec_ {
|
||||||
#include <openssl/ec.h>
|
char *name;
|
||||||
|
int nid;
|
||||||
|
} t_ec;
|
||||||
|
typedef t_ec* p_ec;
|
||||||
|
|
||||||
EC_KEY *lsec_find_ec_key(lua_State *L, const char *str);
|
/* Elliptic curves supported */
|
||||||
#endif
|
static t_ec curves[] = {
|
||||||
|
/* SECG */
|
||||||
void lsec_get_curves(lua_State *L);
|
{"secp112r1", NID_secp112r1},
|
||||||
void lsec_load_curves(lua_State *L);
|
{"secp112r2", NID_secp112r2},
|
||||||
|
{"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,6 @@
|
|||||||
----------------------------------------------------------------------------
|
----------------------------------------------------------------------------
|
||||||
-- LuaSec 0.7.2
|
-- LuaSec 0.5.1
|
||||||
-- Copyright (C) 2009-2019 PUC-Rio
|
-- Copyright (C) 2009-2015 PUC-Rio
|
||||||
--
|
--
|
||||||
-- Author: Pablo Musa
|
-- Author: Pablo Musa
|
||||||
-- Author: Tomas Guisasola
|
-- Author: Tomas Guisasola
|
||||||
@ -12,21 +12,25 @@ local ltn12 = require("ltn12")
|
|||||||
local http = require("socket.http")
|
local http = require("socket.http")
|
||||||
local url = require("socket.url")
|
local url = require("socket.url")
|
||||||
|
|
||||||
|
local table = require("table")
|
||||||
|
local string = require("string")
|
||||||
|
|
||||||
local try = socket.try
|
local try = socket.try
|
||||||
|
local type = type
|
||||||
|
local pairs = pairs
|
||||||
|
local getmetatable = getmetatable
|
||||||
|
|
||||||
--
|
module("ssl.https")
|
||||||
-- Module
|
|
||||||
--
|
_VERSION = "0.5.1"
|
||||||
local _M = {
|
_COPYRIGHT = "LuaSec 0.5.1 - Copyright (C) 2009-2015 PUC-Rio"
|
||||||
_VERSION = "0.7.2",
|
|
||||||
_COPYRIGHT = "LuaSec 0.7.2 - Copyright (C) 2009-2019 PUC-Rio",
|
-- Default settings
|
||||||
PORT = 443,
|
PORT = 443
|
||||||
}
|
|
||||||
|
|
||||||
-- TLS configuration
|
|
||||||
local cfg = {
|
local cfg = {
|
||||||
protocol = "any",
|
protocol = "tlsv1",
|
||||||
options = {"all", "no_sslv2", "no_sslv3"},
|
options = "all",
|
||||||
verify = "none",
|
verify = "none",
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,7 +40,7 @@ local cfg = {
|
|||||||
|
|
||||||
-- Insert default HTTPS port.
|
-- Insert default HTTPS port.
|
||||||
local function default_https_port(u)
|
local function default_https_port(u)
|
||||||
return url.build(url.parse(u, {port = _M.PORT}))
|
return url.build(url.parse(u, {port = PORT}))
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Convert an URL to a table according to Luasocket needs.
|
-- Convert an URL to a table according to Luasocket needs.
|
||||||
@ -89,7 +93,6 @@ local function tcp(params)
|
|||||||
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)
|
|
||||||
try(self.sock:dohandshake())
|
try(self.sock:dohandshake())
|
||||||
reg(self, getmetatable(self.sock))
|
reg(self, getmetatable(self.sock))
|
||||||
return 1
|
return 1
|
||||||
@ -110,7 +113,7 @@ end
|
|||||||
-- @param body optional (string)
|
-- @param body optional (string)
|
||||||
-- @return (string if url == string or 1), code, headers, status
|
-- @return (string if url == string or 1), code, headers, status
|
||||||
--
|
--
|
||||||
local function request(url, body)
|
function request(url, body)
|
||||||
local result_table = {}
|
local result_table = {}
|
||||||
local stringrequest = type(url) == "string"
|
local stringrequest = type(url) == "string"
|
||||||
if stringrequest then
|
if stringrequest then
|
||||||
@ -133,11 +136,3 @@ local function request(url, body)
|
|||||||
end
|
end
|
||||||
return res, code, headers, status
|
return res, code, headers, status
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
-- Export module
|
|
||||||
--
|
|
||||||
|
|
||||||
_M.request = request
|
|
||||||
|
|
||||||
return _M
|
|
||||||
|
@ -6,7 +6,7 @@ OBJS= \
|
|||||||
|
|
||||||
CC ?= cc
|
CC ?= cc
|
||||||
CFLAGS += $(MYCFLAGS) -DLUASOCKET_DEBUG
|
CFLAGS += $(MYCFLAGS) -DLUASOCKET_DEBUG
|
||||||
AR ?= ar
|
AR := ar rcu
|
||||||
RANLIB ?= ranlib
|
RANLIB ?= ranlib
|
||||||
|
|
||||||
.PHONY: all clean
|
.PHONY: all clean
|
||||||
@ -14,7 +14,7 @@ RANLIB ?= ranlib
|
|||||||
all: libluasocket.a
|
all: libluasocket.a
|
||||||
|
|
||||||
libluasocket.a: $(OBJS)
|
libluasocket.a: $(OBJS)
|
||||||
$(AR) rcu $@ $(OBJS)
|
$(AR) $@ $(OBJS)
|
||||||
$(RANLIB) $@
|
$(RANLIB) $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
@ -135,7 +135,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 anything in the stack before pushing the
|
/* we can't push anyting 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));
|
||||||
|
@ -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 written */
|
char *data, /* pointer to buffer where data will be writen */
|
||||||
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 below implement a comfortable platform independent
|
* Functions bellow 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 milliseconds for operation */
|
double total; /* total number of miliseconds 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 modified them */
|
/* must set bits within loop, because select may have modifed 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; }
|
||||||
|
167
src/options.c
167
src/options.c
@ -1,167 +0,0 @@
|
|||||||
/*--------------------------------------------------------------------------
|
|
||||||
* LuaSec 0.7.2
|
|
||||||
*
|
|
||||||
* Copyright (C) 2006-2019 Bruno Silvestre
|
|
||||||
*
|
|
||||||
*--------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
#include <openssl/ssl.h>
|
|
||||||
|
|
||||||
#include "options.h"
|
|
||||||
|
|
||||||
/* If you need to generate these options again, see options.lua */
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
OpenSSL version: OpenSSL 1.1.1
|
|
||||||
*/
|
|
||||||
|
|
||||||
static lsec_ssl_option_t ssl_options[] = {
|
|
||||||
#if defined(SSL_OP_ALL)
|
|
||||||
{"all", SSL_OP_ALL},
|
|
||||||
#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_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_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_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_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;
|
|
||||||
}
|
|
||||||
|
|
125
src/options.h
125
src/options.h
@ -2,21 +2,130 @@
|
|||||||
#define LSEC_OPTIONS_H
|
#define LSEC_OPTIONS_H
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------
|
||||||
* LuaSec 0.7.2
|
* LuaSec 0.5.1
|
||||||
*
|
* Copyright (C) 2006-2015 Bruno Silvestre
|
||||||
* Copyright (C) 2006-2019 Bruno Silvestre
|
|
||||||
*
|
*
|
||||||
*--------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "compat.h"
|
#include <openssl/ssl.h>
|
||||||
|
|
||||||
struct lsec_ssl_option_s {
|
/* If you need to generate these options again, see options.lua */
|
||||||
|
|
||||||
|
/*
|
||||||
|
OpenSSL version: OpenSSL 1.0.1e 2013-06-12
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct ssl_option_s {
|
||||||
const char *name;
|
const char *name;
|
||||||
unsigned long code;
|
unsigned long code;
|
||||||
};
|
};
|
||||||
|
typedef struct ssl_option_s ssl_option_t;
|
||||||
|
|
||||||
typedef struct lsec_ssl_option_s lsec_ssl_option_t;
|
static ssl_option_t ssl_options[] = {
|
||||||
|
#if defined(SSL_OP_ALL)
|
||||||
LSEC_API lsec_ssl_option_t* lsec_get_ssl_options();
|
{"all", SSL_OP_ALL},
|
||||||
|
#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_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_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_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_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 [version] > options.c")
|
print(" lua options.lua -g /path/to/ssl.h [verion] > options.h")
|
||||||
print("* Examples:")
|
print("* Examples:")
|
||||||
print(" lua options.lua -g /usr/include/openssl/ssl.h > options.c\n")
|
print(" lua options.lua -g /usr/include/openssl/ssl.h > options.h\n")
|
||||||
print(" lua options.lua -g /usr/include/openssl/ssl.h \"OpenSSL 1.0.1 14\" > options.c\n")
|
print(" lua options.lua -g /usr/include/openssl/ssl.h \"OpenSSL 1.0.1 14\" > options.h\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,28 +17,33 @@ end
|
|||||||
|
|
||||||
local function generate(options, version)
|
local function generate(options, version)
|
||||||
print([[
|
print([[
|
||||||
|
#ifndef LSEC_OPTIONS_H
|
||||||
|
#define LSEC_OPTIONS_H
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------
|
||||||
* LuaSec 0.7.2
|
* LuaSec 0.5.1
|
||||||
*
|
* Copyright (C) 2006-2015 Bruno Silvestre
|
||||||
* Copyright (C) 2006-2019 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 lsec_ssl_option_t ssl_options[] = {]])
|
print([[static 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))
|
||||||
@ -50,9 +55,7 @@ local function generate(options, version)
|
|||||||
print([[
|
print([[
|
||||||
};
|
};
|
||||||
|
|
||||||
LSEC_API lsec_ssl_option_t* lsec_get_ssl_options() {
|
#endif
|
||||||
return ssl_options;
|
|
||||||
}
|
|
||||||
]])
|
]])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
236
src/ssl.c
236
src/ssl.c
@ -1,9 +1,9 @@
|
|||||||
/*--------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------
|
||||||
* LuaSec 0.7.2
|
* LuaSec 0.5.1
|
||||||
*
|
*
|
||||||
* Copyright (C) 2014-2019 Kim Alvefur, Paul Aurich, Tobias Markmann,
|
* Copyright (C) 2014-2015 Kim Alvefur, Paul Aurich, Tobias Markmann,
|
||||||
* Matthew Wild.
|
* Matthew Wild.
|
||||||
* Copyright (C) 2006-2019 Bruno Silvestre.
|
* Copyright (C) 2006-2014 Bruno Silvestre.
|
||||||
*
|
*
|
||||||
*--------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
@ -28,17 +28,8 @@
|
|||||||
#include <luasocket/socket.h>
|
#include <luasocket/socket.h>
|
||||||
|
|
||||||
#include "x509.h"
|
#include "x509.h"
|
||||||
#include "context.h"
|
|
||||||
#include "ssl.h"
|
#include "ssl.h"
|
||||||
|
|
||||||
|
|
||||||
#if defined(LIBRESSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER<0x10100000L
|
|
||||||
#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.
|
||||||
*/
|
*/
|
||||||
@ -89,15 +80,11 @@ static int meth_destroy(lua_State *L)
|
|||||||
}
|
}
|
||||||
ssl->state = LSEC_STATE_CLOSED;
|
ssl->state = LSEC_STATE_CLOSED;
|
||||||
if (ssl->ssl) {
|
if (ssl->ssl) {
|
||||||
/* Clear the registries */
|
/* Clear the registry */
|
||||||
luaL_getmetatable(L, "SSL:Verify:Registry");
|
luaL_getmetatable(L, "SSL:Verify:Registry");
|
||||||
lua_pushlightuserdata(L, (void*)ssl->ssl);
|
lua_pushlightuserdata(L, (void*)ssl->ssl);
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
lua_settable(L, -3);
|
lua_settable(L, -3);
|
||||||
luaL_getmetatable(L, "SSL:SNI:Registry");
|
|
||||||
lua_pushlightuserdata(L, (void*)ssl->ssl);
|
|
||||||
lua_pushnil(L);
|
|
||||||
lua_settable(L, -3);
|
|
||||||
/* Destroy the object */
|
/* Destroy the object */
|
||||||
SSL_free(ssl->ssl);
|
SSL_free(ssl->ssl);
|
||||||
ssl->ssl = NULL;
|
ssl->ssl = NULL;
|
||||||
@ -199,9 +186,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);
|
||||||
@ -211,6 +198,7 @@ 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);
|
||||||
@ -237,45 +225,26 @@ 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;
|
int mode = lsec_getmode(L, 1);
|
||||||
SSL_CTX *ctx;
|
SSL_CTX *ctx = lsec_checkcontext(L, 1);
|
||||||
|
|
||||||
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);
|
||||||
@ -283,21 +252,6 @@ 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 |
|
||||||
@ -371,7 +325,7 @@ static int meth_setfd(lua_State *L)
|
|||||||
p_ssl ssl = (p_ssl)luaL_checkudata(L, 1, "SSL:Connection");
|
p_ssl ssl = (p_ssl)luaL_checkudata(L, 1, "SSL:Connection");
|
||||||
if (ssl->state != LSEC_STATE_NEW)
|
if (ssl->state != LSEC_STATE_NEW)
|
||||||
luaL_argerror(L, 1, "invalid SSL object state");
|
luaL_argerror(L, 1, "invalid SSL object state");
|
||||||
ssl->sock = (t_socket)luaL_checkinteger(L, 2);
|
ssl->sock = luaL_checkint(L, 2);
|
||||||
socket_setnonblocking(&ssl->sock);
|
socket_setnonblocking(&ssl->sock);
|
||||||
SSL_set_fd(ssl->ssl, (int)ssl->sock);
|
SSL_set_fd(ssl->ssl, (int)ssl->sock);
|
||||||
return 0;
|
return 0;
|
||||||
@ -447,11 +401,7 @@ static int meth_want(lua_State *L)
|
|||||||
*/
|
*/
|
||||||
static int meth_compression(lua_State *L)
|
static int meth_compression(lua_State *L)
|
||||||
{
|
{
|
||||||
#ifdef OPENSSL_NO_COMP
|
|
||||||
const void *comp;
|
|
||||||
#else
|
|
||||||
const COMP_METHOD *comp;
|
const COMP_METHOD *comp;
|
||||||
#endif
|
|
||||||
p_ssl ssl = (p_ssl)luaL_checkudata(L, 1, "SSL:Connection");
|
p_ssl ssl = (p_ssl)luaL_checkudata(L, 1, "SSL:Connection");
|
||||||
if (ssl->state != LSEC_STATE_CONNECTED) {
|
if (ssl->state != LSEC_STATE_CONNECTED) {
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
@ -481,7 +431,7 @@ static int meth_getpeercertificate(lua_State *L)
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
/* Default to the first cert */
|
/* Default to the first cert */
|
||||||
n = (int)luaL_optinteger(L, 2, 1);
|
n = luaL_optint(L, 2, 1);
|
||||||
/* This function is 1-based, but OpenSSL is 0-based */
|
/* This function is 1-based, but OpenSSL is 0-based */
|
||||||
--n;
|
--n;
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
@ -500,7 +450,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_is_server(ssl->ssl))
|
if (ssl->ssl->server)
|
||||||
--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)) {
|
||||||
@ -510,7 +460,7 @@ 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. */
|
||||||
X509_up_ref(cert);
|
CRYPTO_add(&cert->references, 1, CRYPTO_LOCK_X509);
|
||||||
lsec_pushx509(L, cert);
|
lsec_pushx509(L, cert);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -532,7 +482,7 @@ static int meth_getpeerchain(lua_State *L)
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
if (SSL_is_server(ssl->ssl)) {
|
if (ssl->ssl->server) {
|
||||||
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++);
|
||||||
}
|
}
|
||||||
@ -542,7 +492,7 @@ 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. */
|
||||||
X509_up_ref(cert);
|
CRYPTO_add(&cert->references, 1, CRYPTO_LOCK_X509);
|
||||||
lsec_pushx509(L, cert);
|
lsec_pushx509(L, cert);
|
||||||
lua_rawseti(L, -2, idx++);
|
lua_rawseti(L, -2, idx++);
|
||||||
}
|
}
|
||||||
@ -703,100 +653,9 @@ static int meth_info(lua_State *L)
|
|||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sni_cb(SSL *ssl, int *ad, void *arg)
|
|
||||||
{
|
|
||||||
int strict;
|
|
||||||
SSL_CTX *newctx = NULL;
|
|
||||||
SSL_CTX *ctx = SSL_get_SSL_CTX(ssl);
|
|
||||||
lua_State *L = ((p_context)SSL_CTX_get_app_data(ctx))->L;
|
|
||||||
const char *name = SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name);
|
|
||||||
/* No name, use default context */
|
|
||||||
if (!name)
|
|
||||||
return SSL_TLSEXT_ERR_NOACK;
|
|
||||||
/* Retrieve struct from registry */
|
|
||||||
luaL_getmetatable(L, "SSL:SNI:Registry");
|
|
||||||
lua_pushlightuserdata(L, (void*)ssl);
|
|
||||||
lua_gettable(L, -2);
|
|
||||||
/* Strict search? */
|
|
||||||
lua_pushstring(L, "strict");
|
|
||||||
lua_gettable(L, -2);
|
|
||||||
strict = lua_toboolean(L, -1);
|
|
||||||
lua_pop(L, 1);
|
|
||||||
/* Search for the name in the map */
|
|
||||||
lua_pushstring(L, "map");
|
|
||||||
lua_gettable(L, -2);
|
|
||||||
lua_pushstring(L, name);
|
|
||||||
lua_gettable(L, -2);
|
|
||||||
if (lua_isuserdata(L, -1))
|
|
||||||
newctx = lsec_checkcontext(L, -1);
|
|
||||||
lua_pop(L, 4);
|
|
||||||
/* Found, use this context */
|
|
||||||
if (newctx) {
|
|
||||||
SSL_set_SSL_CTX(ssl, newctx);
|
|
||||||
return SSL_TLSEXT_ERR_OK;
|
|
||||||
}
|
|
||||||
/* Not found, but use initial context */
|
|
||||||
if (!strict)
|
|
||||||
return SSL_TLSEXT_ERR_OK;
|
|
||||||
return SSL_TLSEXT_ERR_ALERT_FATAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int meth_sni(lua_State *L)
|
|
||||||
{
|
|
||||||
int strict;
|
|
||||||
SSL_CTX *aux;
|
|
||||||
const char *name;
|
|
||||||
p_ssl ssl = (p_ssl)luaL_checkudata(L, 1, "SSL:Connection");
|
|
||||||
SSL_CTX *ctx = SSL_get_SSL_CTX(ssl->ssl);
|
|
||||||
p_context pctx = (p_context)SSL_CTX_get_app_data(ctx);
|
|
||||||
if (pctx->mode == LSEC_MODE_CLIENT) {
|
|
||||||
name = luaL_checkstring(L, 2);
|
|
||||||
SSL_set_tlsext_host_name(ssl->ssl, name);
|
|
||||||
return 0;
|
|
||||||
} else if (pctx->mode == LSEC_MODE_SERVER) {
|
|
||||||
luaL_checktype(L, 2, LUA_TTABLE);
|
|
||||||
strict = lua_toboolean(L, 3);
|
|
||||||
/* Check if the table contains only (string -> context) */
|
|
||||||
lua_pushnil(L);
|
|
||||||
while (lua_next(L, 2)) {
|
|
||||||
luaL_checkstring(L, -2);
|
|
||||||
aux = lsec_checkcontext(L, -1);
|
|
||||||
/* Set callback in every context */
|
|
||||||
SSL_CTX_set_tlsext_servername_callback(aux, sni_cb);
|
|
||||||
/* leave the next key on the stack */
|
|
||||||
lua_pop(L, 1);
|
|
||||||
}
|
|
||||||
/* Save table in the register */
|
|
||||||
luaL_getmetatable(L, "SSL:SNI:Registry");
|
|
||||||
lua_pushlightuserdata(L, (void*)ssl->ssl);
|
|
||||||
lua_newtable(L);
|
|
||||||
lua_pushstring(L, "map");
|
|
||||||
lua_pushvalue(L, 2);
|
|
||||||
lua_settable(L, -3);
|
|
||||||
lua_pushstring(L, "strict");
|
|
||||||
lua_pushboolean(L, strict);
|
|
||||||
lua_settable(L, -3);
|
|
||||||
lua_settable(L, -3);
|
|
||||||
/* Set callback in the default context */
|
|
||||||
SSL_CTX_set_tlsext_servername_callback(ctx, sni_cb);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int meth_getsniname(lua_State *L)
|
|
||||||
{
|
|
||||||
p_ssl ssl = (p_ssl)luaL_checkudata(L, 1, "SSL:Connection");
|
|
||||||
const char *name = SSL_get_servername(ssl->ssl, TLSEXT_NAMETYPE_host_name);
|
|
||||||
if (name)
|
|
||||||
lua_pushstring(L, name);
|
|
||||||
else
|
|
||||||
lua_pushnil(L);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int meth_copyright(lua_State *L)
|
static int meth_copyright(lua_State *L)
|
||||||
{
|
{
|
||||||
lua_pushstring(L, "LuaSec 0.7.2 - Copyright (C) 2006-2019 Bruno Silvestre, UFG"
|
lua_pushstring(L, "LuaSec 0.5.1 - Copyright (C) 2006-2015 Bruno Silvestre"
|
||||||
#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
|
||||||
@ -817,7 +676,6 @@ static luaL_Reg methods[] = {
|
|||||||
{"getpeerchain", meth_getpeerchain},
|
{"getpeerchain", meth_getpeerchain},
|
||||||
{"getpeerverification", meth_getpeerverification},
|
{"getpeerverification", meth_getpeerverification},
|
||||||
{"getpeerfinished", meth_getpeerfinished},
|
{"getpeerfinished", meth_getpeerfinished},
|
||||||
{"getsniname", meth_getsniname},
|
|
||||||
{"getstats", meth_getstats},
|
{"getstats", meth_getstats},
|
||||||
{"setstats", meth_setstats},
|
{"setstats", meth_setstats},
|
||||||
{"dirty", meth_dirty},
|
{"dirty", meth_dirty},
|
||||||
@ -825,7 +683,6 @@ static luaL_Reg methods[] = {
|
|||||||
{"receive", meth_receive},
|
{"receive", meth_receive},
|
||||||
{"send", meth_send},
|
{"send", meth_send},
|
||||||
{"settimeout", meth_settimeout},
|
{"settimeout", meth_settimeout},
|
||||||
{"sni", meth_sni},
|
|
||||||
{"want", meth_want},
|
{"want", meth_want},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
@ -855,6 +712,7 @@ static luaL_Reg funcs[] = {
|
|||||||
/**
|
/**
|
||||||
* Initialize modules.
|
* Initialize modules.
|
||||||
*/
|
*/
|
||||||
|
#if (LUA_VERSION_NUM == 501)
|
||||||
LSEC_API int luaopen_ssl_core(lua_State *L)
|
LSEC_API int luaopen_ssl_core(lua_State *L)
|
||||||
{
|
{
|
||||||
/* Initialize SSL */
|
/* Initialize SSL */
|
||||||
@ -870,33 +728,49 @@ LSEC_API int luaopen_ssl_core(lua_State *L)
|
|||||||
socket_open();
|
socket_open();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
luaL_newmetatable(L, "SSL:SNI:Registry");
|
|
||||||
|
|
||||||
/* Register the functions and tables */
|
/* Register the functions and tables */
|
||||||
luaL_newmetatable(L, "SSL:Connection");
|
luaL_newmetatable(L, "SSL:Connection");
|
||||||
setfuncs(L, meta);
|
luaL_register(L, NULL, meta);
|
||||||
|
|
||||||
luaL_newlib(L, methods);
|
lua_newtable(L);
|
||||||
|
luaL_register(L, NULL, methods);
|
||||||
lua_setfield(L, -2, "__index");
|
lua_setfield(L, -2, "__index");
|
||||||
|
|
||||||
luaL_newlib(L, funcs);
|
luaL_register(L, "ssl.core", funcs);
|
||||||
|
|
||||||
lua_pushstring(L, "SOCKET_INVALID");
|
|
||||||
lua_pushnumber(L, SOCKET_INVALID);
|
lua_pushnumber(L, SOCKET_INVALID);
|
||||||
lua_rawset(L, -3);
|
lua_setfield(L, -2, "invalidfd");
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
//------------------------------------------------------------------------------
|
LSEC_API int luaopen_ssl_core(lua_State *L)
|
||||||
|
{
|
||||||
#if defined(_MSC_VER)
|
/* Initialize SSL */
|
||||||
|
if (!SSL_library_init()) {
|
||||||
/* Empty implementation to allow building with LuaRocks and MS compilers */
|
lua_pushstring(L, "unable to initialize SSL library");
|
||||||
LSEC_API int luaopen_ssl(lua_State *L) {
|
|
||||||
lua_pushstring(L, "you should not call this function");
|
|
||||||
lua_error(L);
|
lua_error(L);
|
||||||
return 0;
|
}
|
||||||
}
|
OpenSSL_add_all_algorithms();
|
||||||
|
SSL_load_error_strings();
|
||||||
|
|
||||||
|
#if defined(WITH_LUASOCKET)
|
||||||
|
/* Initialize internal library */
|
||||||
|
socket_open();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Register the functions and tables */
|
||||||
|
luaL_newmetatable(L, "SSL:Connection");
|
||||||
|
luaL_setfuncs(L, meta, 0);
|
||||||
|
|
||||||
|
lua_newtable(L);
|
||||||
|
luaL_setfuncs(L, methods, 0);
|
||||||
|
lua_setfield(L, -2, "__index");
|
||||||
|
|
||||||
|
lua_newtable(L);
|
||||||
|
luaL_setfuncs(L, funcs, 0);
|
||||||
|
lua_pushnumber(L, SOCKET_INVALID);
|
||||||
|
lua_setfield(L, -2, "invalidfd");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -2,9 +2,8 @@
|
|||||||
#define LSEC_SSL_H
|
#define LSEC_SSL_H
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------
|
||||||
* LuaSec 0.7.2
|
* LuaSec 0.5.1
|
||||||
*
|
* Copyright (C) 2006-2015 Bruno Silvestre
|
||||||
* Copyright (C) 2006-2019 Bruno Silvestre
|
|
||||||
*
|
*
|
||||||
*--------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
@ -16,7 +15,7 @@
|
|||||||
#include <luasocket/timeout.h>
|
#include <luasocket/timeout.h>
|
||||||
#include <luasocket/socket.h>
|
#include <luasocket/socket.h>
|
||||||
|
|
||||||
#include "compat.h"
|
#include "config.h"
|
||||||
#include "context.h"
|
#include "context.h"
|
||||||
|
|
||||||
#define LSEC_STATE_NEW 1
|
#define LSEC_STATE_NEW 1
|
||||||
|
50
src/ssl.lua
50
src/ssl.lua
@ -1,16 +1,20 @@
|
|||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
-- LuaSec 0.7.2
|
-- LuaSec 0.5.1
|
||||||
--
|
-- Copyright (C) 2006-2015 Bruno Silvestre
|
||||||
-- Copyright (C) 2006-2019 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
|
module("ssl", package.seeall)
|
||||||
|
|
||||||
|
_VERSION = "0.5.1"
|
||||||
|
_COPYRIGHT = core.copyright()
|
||||||
|
|
||||||
|
-- Export
|
||||||
|
loadcertificate = x509.load
|
||||||
|
|
||||||
-- We must prevent the contexts to be collected before the connections,
|
-- We must prevent the contexts to be collected before the connections,
|
||||||
-- otherwise the C registry will be cleared.
|
-- otherwise the C registry will be cleared.
|
||||||
@ -33,7 +37,7 @@ end
|
|||||||
--
|
--
|
||||||
--
|
--
|
||||||
--
|
--
|
||||||
local function newcontext(cfg)
|
function newcontext(cfg)
|
||||||
local succ, msg, ctx
|
local succ, msg, ctx
|
||||||
-- Create the context
|
-- Create the context
|
||||||
ctx, msg = context.create(cfg.protocol)
|
ctx, msg = context.create(cfg.protocol)
|
||||||
@ -56,10 +60,6 @@ local function newcontext(cfg)
|
|||||||
if cfg.certificate then
|
if cfg.certificate then
|
||||||
succ, msg = context.loadcert(ctx, cfg.certificate)
|
succ, msg = context.loadcert(ctx, cfg.certificate)
|
||||||
if not succ then return nil, msg end
|
if not succ then return nil, msg end
|
||||||
if cfg.key and context.checkkey then
|
|
||||||
succ = context.checkkey(ctx)
|
|
||||||
if not succ then return nil, "private key does not match public key" 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
|
||||||
@ -94,19 +94,11 @@ local function newcontext(cfg)
|
|||||||
end
|
end
|
||||||
context.setdhparam(ctx, cfg.dhparam)
|
context.setdhparam(ctx, cfg.dhparam)
|
||||||
end
|
end
|
||||||
|
-- Set elliptic curve
|
||||||
-- Set elliptic curves
|
if cfg.curve then
|
||||||
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)
|
||||||
@ -119,7 +111,7 @@ end
|
|||||||
--
|
--
|
||||||
--
|
--
|
||||||
--
|
--
|
||||||
local function wrap(sock, cfg)
|
function wrap(sock, cfg)
|
||||||
local ctx, msg
|
local ctx, msg
|
||||||
if type(cfg) == "table" then
|
if type(cfg) == "table" then
|
||||||
ctx, msg = newcontext(cfg)
|
ctx, msg = newcontext(cfg)
|
||||||
@ -130,7 +122,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(core.SOCKET_INVALID)
|
sock:setfd(core.invalidfd)
|
||||||
registry[s] = ctx
|
registry[s] = ctx
|
||||||
return s
|
return s
|
||||||
end
|
end
|
||||||
@ -174,17 +166,3 @@ end
|
|||||||
--
|
--
|
||||||
core.setmethod("info", info)
|
core.setmethod("info", info)
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
-- Export module
|
|
||||||
--
|
|
||||||
|
|
||||||
local _M = {
|
|
||||||
_VERSION = "0.7.2",
|
|
||||||
_COPYRIGHT = core.copyright(),
|
|
||||||
config = config,
|
|
||||||
loadcertificate = x509.load,
|
|
||||||
newcontext = newcontext,
|
|
||||||
wrap = wrap,
|
|
||||||
}
|
|
||||||
|
|
||||||
return _M
|
|
||||||
|
270
src/x509.c
270
src/x509.c
@ -1,22 +1,15 @@
|
|||||||
/*--------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------
|
||||||
* LuaSec 0.7.2
|
* LuaSec 0.5.1
|
||||||
*
|
*
|
||||||
* Copyright (C) 2014-2019 Kim Alvefur, Paul Aurich, Tobias Markmann
|
* Copyright (C) 2014-2015 Kim Alvefur, Paul Aurich, Tobias Markmann
|
||||||
* Matthew Wild, Bruno Silvestre.
|
* Matthew Wild, Bruno Silvestre.
|
||||||
*
|
*
|
||||||
*--------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#if defined(WIN32)
|
#if defined(WIN32)
|
||||||
#include <ws2tcpip.h>
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#else
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <openssl/ssl.h>
|
#include <openssl/ssl.h>
|
||||||
@ -32,17 +25,6 @@
|
|||||||
|
|
||||||
#include "x509.h"
|
#include "x509.h"
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* ASN1_STRING_data is deprecated in OpenSSL 1.1.0
|
|
||||||
*/
|
|
||||||
#if OPENSSL_VERSION_NUMBER>=0x1010000fL && !defined(LIBRESSL_VERSION_NUMBER)
|
|
||||||
#define LSEC_ASN1_STRING_data(x) ASN1_STRING_get0_data(x)
|
|
||||||
#else
|
|
||||||
#define LSEC_ASN1_STRING_data(x) ASN1_STRING_data(x)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
static const char* hex_tab = "0123456789abcdef";
|
static const char* hex_tab = "0123456789abcdef";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -75,51 +57,6 @@ p_x509 lsec_checkp_x509(lua_State* L, int idx)
|
|||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#if defined(LUASEC_INET_NTOP)
|
|
||||||
/*
|
|
||||||
* For WinXP (SP3), set the following preprocessor macros:
|
|
||||||
* LUASEC_INET_NTOP
|
|
||||||
* WINVER=0x0501
|
|
||||||
* _WIN32_WINNT=0x0501
|
|
||||||
* NTDDI_VERSION=0x05010300
|
|
||||||
*
|
|
||||||
* For IPv6 addresses, you need to add IPv6 Protocol to your interface.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
static const char *inet_ntop(int af, const char *src, char *dst, socklen_t size)
|
|
||||||
{
|
|
||||||
int addrsize;
|
|
||||||
struct sockaddr *addr;
|
|
||||||
struct sockaddr_in addr4;
|
|
||||||
struct sockaddr_in6 addr6;
|
|
||||||
|
|
||||||
switch (af) {
|
|
||||||
case AF_INET:
|
|
||||||
memset((void*)&addr4, 0, sizeof(addr4));
|
|
||||||
addr4.sin_family = AF_INET;
|
|
||||||
memcpy((void*)&addr4.sin_addr, src, sizeof(struct in_addr));
|
|
||||||
addr = (struct sockaddr*)&addr4;
|
|
||||||
addrsize = sizeof(struct sockaddr_in);
|
|
||||||
break;
|
|
||||||
case AF_INET6:
|
|
||||||
memset((void*)&addr6, 0, sizeof(addr6));
|
|
||||||
addr6.sin6_family = AF_INET6;
|
|
||||||
memcpy((void*)&addr6.sin6_addr, src, sizeof(struct in6_addr));
|
|
||||||
addr = (struct sockaddr*)&addr6;
|
|
||||||
addrsize = sizeof(struct sockaddr_in6);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(getnameinfo(addr, addrsize, dst, size, NULL, 0, NI_NUMERICHOST) != 0)
|
|
||||||
return NULL;
|
|
||||||
return dst;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert the buffer 'in' to hexadecimal.
|
* Convert the buffer 'in' to hexadecimal.
|
||||||
*/
|
*/
|
||||||
@ -157,7 +94,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*)LSEC_ASN1_STRING_data(string),
|
lua_pushlstring(L, (char*)ASN1_STRING_data(string),
|
||||||
ASN1_STRING_length(string));
|
ASN1_STRING_length(string));
|
||||||
break;
|
break;
|
||||||
case LSEC_UTF8_STRING:
|
case LSEC_UTF8_STRING:
|
||||||
@ -186,31 +123,6 @@ static int push_asn1_time(lua_State *L, ASN1_UTCTIME *tm)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a human readable IP address.
|
|
||||||
*/
|
|
||||||
static void push_asn1_ip(lua_State *L, ASN1_STRING *string)
|
|
||||||
{
|
|
||||||
int af;
|
|
||||||
char dst[INET6_ADDRSTRLEN];
|
|
||||||
unsigned char *ip = (unsigned char*)LSEC_ASN1_STRING_data(string);
|
|
||||||
switch(ASN1_STRING_length(string)) {
|
|
||||||
case 4:
|
|
||||||
af = AF_INET;
|
|
||||||
break;
|
|
||||||
case 16:
|
|
||||||
af = AF_INET6;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
lua_pushnil(L);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(inet_ntop(af, ip, dst, INET6_ADDRSTRLEN))
|
|
||||||
lua_pushstring(L, dst);
|
|
||||||
else
|
|
||||||
lua_pushnil(L);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -232,7 +144,7 @@ static int push_subtable(lua_State* L, int idx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the general names from the object.
|
* Retrive 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)
|
||||||
{
|
{
|
||||||
@ -260,7 +172,7 @@ static int push_x509_name(lua_State* L, X509_NAME *name, int encode)
|
|||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the Subject from the certificate.
|
* Retrive the Subject from the certificate.
|
||||||
*/
|
*/
|
||||||
static int meth_subject(lua_State* L)
|
static int meth_subject(lua_State* L)
|
||||||
{
|
{
|
||||||
@ -269,7 +181,7 @@ static int meth_subject(lua_State* L)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the Issuer from the certificate.
|
* Retrive the Issuer from the certificate.
|
||||||
*/
|
*/
|
||||||
static int meth_issuer(lua_State* L)
|
static int meth_issuer(lua_State* L)
|
||||||
{
|
{
|
||||||
@ -304,11 +216,11 @@ int meth_extensions(lua_State* L)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
/* Push ret[oid] */
|
/* Push ret[oid] */
|
||||||
push_asn1_objname(L, X509_EXTENSION_get_object(extension), 1);
|
push_asn1_objname(L, extension->object, 1);
|
||||||
push_subtable(L, -2);
|
push_subtable(L, -2);
|
||||||
|
|
||||||
/* Set ret[oid].name = name */
|
/* Set ret[oid].name = name */
|
||||||
push_asn1_objname(L, X509_EXTENSION_get_object(extension), 0);
|
push_asn1_objname(L, extension->object, 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);
|
||||||
@ -350,7 +262,7 @@ int meth_extensions(lua_State* L)
|
|||||||
case GEN_IPADD:
|
case GEN_IPADD:
|
||||||
lua_pushstring(L, "iPAddress");
|
lua_pushstring(L, "iPAddress");
|
||||||
push_subtable(L, -2);
|
push_subtable(L, -2);
|
||||||
push_asn1_ip(L, general_name->d.iPAddress);
|
push_asn1_string(L, general_name->d.iPAddress, px->encode);
|
||||||
lua_rawseti(L, -2, lua_rawlen(L, -2)+1);
|
lua_rawseti(L, -2, lua_rawlen(L, -2)+1);
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
break;
|
break;
|
||||||
@ -371,9 +283,7 @@ 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 */
|
||||||
}
|
}
|
||||||
@ -402,52 +312,6 @@ static int meth_pem(lua_State* L)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Extract public key in PEM format.
|
|
||||||
*/
|
|
||||||
static int meth_pubkey(lua_State* L)
|
|
||||||
{
|
|
||||||
char* data;
|
|
||||||
long bytes;
|
|
||||||
int ret = 1;
|
|
||||||
X509* cert = lsec_checkx509(L, 1);
|
|
||||||
BIO *bio = BIO_new(BIO_s_mem());
|
|
||||||
EVP_PKEY *pkey = X509_get_pubkey(cert);
|
|
||||||
if(PEM_write_bio_PUBKEY(bio, pkey)) {
|
|
||||||
bytes = BIO_get_mem_data(bio, &data);
|
|
||||||
if (bytes > 0) {
|
|
||||||
lua_pushlstring(L, data, bytes);
|
|
||||||
switch(EVP_PKEY_base_id(pkey)) {
|
|
||||||
case EVP_PKEY_RSA:
|
|
||||||
lua_pushstring(L, "RSA");
|
|
||||||
break;
|
|
||||||
case EVP_PKEY_DSA:
|
|
||||||
lua_pushstring(L, "DSA");
|
|
||||||
break;
|
|
||||||
case EVP_PKEY_DH:
|
|
||||||
lua_pushstring(L, "DH");
|
|
||||||
break;
|
|
||||||
case EVP_PKEY_EC:
|
|
||||||
lua_pushstring(L, "EC");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
lua_pushstring(L, "Unknown");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
lua_pushinteger(L, EVP_PKEY_bits(pkey));
|
|
||||||
ret = 3;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
lua_pushnil(L);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
lua_pushnil(L);
|
|
||||||
/* Cleanup */
|
|
||||||
BIO_free(bio);
|
|
||||||
EVP_PKEY_free(pkey);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compute the fingerprint.
|
* Compute the fingerprint.
|
||||||
*/
|
*/
|
||||||
@ -533,91 +397,6 @@ static int meth_notafter(lua_State *L)
|
|||||||
return push_asn1_time(L, X509_get_notAfter(cert));
|
return push_asn1_time(L, X509_get_notAfter(cert));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if this certificate issued some other certificate
|
|
||||||
*/
|
|
||||||
static int meth_issued(lua_State* L)
|
|
||||||
{
|
|
||||||
int ret, i, len;
|
|
||||||
|
|
||||||
X509_STORE_CTX* ctx = NULL;
|
|
||||||
X509_STORE* root = NULL;
|
|
||||||
STACK_OF(X509)* chain = NULL;
|
|
||||||
|
|
||||||
X509* issuer = lsec_checkx509(L, 1);
|
|
||||||
X509* subject = lsec_checkx509(L, 2);
|
|
||||||
X509* cert = NULL;
|
|
||||||
|
|
||||||
len = lua_gettop(L);
|
|
||||||
|
|
||||||
/* Check that all arguments are certificates */
|
|
||||||
|
|
||||||
for (i = 3; i <= len; i++) {
|
|
||||||
lsec_checkx509(L, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Before allocating things that require freeing afterwards */
|
|
||||||
|
|
||||||
chain = sk_X509_new_null();
|
|
||||||
ctx = X509_STORE_CTX_new();
|
|
||||||
root = X509_STORE_new();
|
|
||||||
|
|
||||||
if (ctx == NULL || root == NULL) {
|
|
||||||
lua_pushnil(L);
|
|
||||||
lua_pushstring(L, "X509_STORE_new() or X509_STORE_CTX_new() error");
|
|
||||||
ret = 2;
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = X509_STORE_add_cert(root, issuer);
|
|
||||||
|
|
||||||
if(!ret) {
|
|
||||||
lua_pushnil(L);
|
|
||||||
lua_pushstring(L, "X509_STORE_add_cert() error");
|
|
||||||
ret = 2;
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 3; i <= len && lua_isuserdata(L, i); i++) {
|
|
||||||
cert = lsec_checkx509(L, i);
|
|
||||||
sk_X509_push(chain, cert);
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = X509_STORE_CTX_init(ctx, root, subject, chain);
|
|
||||||
|
|
||||||
if(!ret) {
|
|
||||||
lua_pushnil(L);
|
|
||||||
lua_pushstring(L, "X509_STORE_CTX_init() error");
|
|
||||||
ret = 2;
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Actual verification */
|
|
||||||
if (X509_verify_cert(ctx) <= 0) {
|
|
||||||
ret = X509_STORE_CTX_get_error(ctx);
|
|
||||||
lua_pushnil(L);
|
|
||||||
lua_pushstring(L, X509_verify_cert_error_string(ret));
|
|
||||||
ret = 2;
|
|
||||||
} else {
|
|
||||||
lua_pushboolean(L, 1);
|
|
||||||
ret = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup:
|
|
||||||
|
|
||||||
if (ctx != NULL) {
|
|
||||||
X509_STORE_CTX_free(ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (chain != NULL) {
|
|
||||||
X509_STORE_free(root);
|
|
||||||
}
|
|
||||||
|
|
||||||
sk_X509_free(chain);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collect X509 objects.
|
* Collect X509 objects.
|
||||||
*/
|
*/
|
||||||
@ -684,9 +463,7 @@ static luaL_Reg methods[] = {
|
|||||||
{"issuer", meth_issuer},
|
{"issuer", meth_issuer},
|
||||||
{"notbefore", meth_notbefore},
|
{"notbefore", meth_notbefore},
|
||||||
{"notafter", meth_notafter},
|
{"notafter", meth_notafter},
|
||||||
{"issued", meth_issued},
|
|
||||||
{"pem", meth_pem},
|
{"pem", meth_pem},
|
||||||
{"pubkey", meth_pubkey},
|
|
||||||
{"serial", meth_serial},
|
{"serial", meth_serial},
|
||||||
{"subject", meth_subject},
|
{"subject", meth_subject},
|
||||||
{"validat", meth_valid_at},
|
{"validat", meth_valid_at},
|
||||||
@ -712,16 +489,39 @@ static luaL_Reg funcs[] = {
|
|||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#if (LUA_VERSION_NUM == 501)
|
||||||
|
|
||||||
LSEC_API int luaopen_ssl_x509(lua_State *L)
|
LSEC_API int luaopen_ssl_x509(lua_State *L)
|
||||||
{
|
{
|
||||||
/* Register the functions and tables */
|
/* Register the functions and tables */
|
||||||
luaL_newmetatable(L, "SSL:Certificate");
|
luaL_newmetatable(L, "SSL:Certificate");
|
||||||
setfuncs(L, meta);
|
luaL_register(L, NULL, meta);
|
||||||
|
|
||||||
luaL_newlib(L, methods);
|
lua_newtable(L);
|
||||||
|
luaL_register(L, NULL, methods);
|
||||||
lua_setfield(L, -2, "__index");
|
lua_setfield(L, -2, "__index");
|
||||||
|
|
||||||
luaL_newlib(L, funcs);
|
luaL_register(L, "ssl.x509", funcs);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
LSEC_API int luaopen_ssl_x509(lua_State *L)
|
||||||
|
{
|
||||||
|
/* Register the functions and tables */
|
||||||
|
luaL_newmetatable(L, "SSL:Certificate");
|
||||||
|
luaL_setfuncs(L, meta, 0);
|
||||||
|
|
||||||
|
lua_newtable(L);
|
||||||
|
luaL_setfuncs(L, methods, 0);
|
||||||
|
lua_setfield(L, -2, "__index");
|
||||||
|
|
||||||
|
lua_newtable(L);
|
||||||
|
luaL_setfuncs(L, funcs, 0);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*--------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------
|
||||||
* LuaSec 0.7.2
|
* LuaSec 0.5.1
|
||||||
*
|
*
|
||||||
* Copyright (C) 2014-2019 Kim Alvefur, Paul Aurich, Tobias Markmann
|
* Copyright (C) 2014-2015 Kim Alvefur, Paul Aurich, Tobias Markmann
|
||||||
* Matthew Wild, Bruno Silvestre.
|
* Matthew Wild, Bruno Silvestre.
|
||||||
*
|
*
|
||||||
*--------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------*/
|
||||||
@ -12,7 +12,7 @@
|
|||||||
#include <openssl/x509v3.h>
|
#include <openssl/x509v3.h>
|
||||||
#include <lua.h>
|
#include <lua.h>
|
||||||
|
|
||||||
#include "compat.h"
|
#include "config.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 };
|
||||||
|
Reference in New Issue
Block a user