Comments (9)
please consider d774cab,
and you can try https://github.com/zhaozg/lua-openssl/blob/master/ldoc/openssl.lua#L28-L33 and d774cab#diff-1414f3bd5705103f433eca15f5ef60b7R315
from lua-openssl.
Thanks. It works.
Can you help me to understand right way to implement error handling
E.g. this is function to implement SSL decoding (bases on your luv ssl example)
-- self._out - BIO_mem
-- self._ssl - SSL context
-- self._obuffer - buffer that contain data that shuld be encoded
-- this function returns next chunk of encoded data
function SSLDecoder:output()
-- Here we should clear OpenSSL error queue?
ssl.last_error(true)
local chunk, err = self._out:read()
if not chunk then
-- shuld we check err or just call `last_error`
local code, reason = ssl.last_error()
if code then --[[handle error]] end
elseif #chunk > 0 then return chunk end
while not self._obuffer:empty() do
-- next chunk do decode
chunk = self._obuffer:read_some(OCHUNK_SIZE)
local n, err = self._ssl:write(chunk)
-- same as in case of `self._out:read()`?
...
You can check out my code here
from lua-openssl.
ok, my pleasure
from lua-openssl.
Questions in comments in code snippets.
from lua-openssl.
Sorry for can't give solution right now, but I can write some article to show how to handle it with lua-openssl in some days.
from lua-openssl.
Thanks. It would be halpful.
from lua-openssl.
https://github.com/zhaozg/lua-openssl#howto-5-handle-fail-or-error
https://github.com/zhaozg/lua-openssl/blob/master/ldoc/ssl.lua#L218
-- self._out - BIO_mem
-- self._ssl - SSL context
-- self._obuffer - buffer that contain data that shuld be encoded
-- this function returns next chunk of encoded data
function SSLDecoder:output()
ssl.error(true) --better to clear error queue
local chunk, err = self._out:read()
if chunk then return chunk end --success
if chunk==nil then -- ssl or syscall error,real error
print('ERROR with:'..err)
end
assert(chunk==false) --ssl IO need lua script to do something,
if err==0 then
print('SSL has been closed') --just connection really closed
return
end
print('want to',err) -- want_read/write/x509_lookup/... SSL not fail, but want API do something
local n, err = self._ssl:write(chunk)
-- n is bytes count successfully write, for read that is input string,
-- err same with read.
from lua-openssl.
I have some questions
self._out:read()
is read from BIO_mem
object so in local chunk, err = self._out:read()
chunk
can be only nil
or string
but not false because it is not SSL function.
local chunk, err = self._out:read()
if not chunk then -- Error and we get error code
return nil, openssl.error(err) -- get error info
end
-- we can not get chunk == false because this is just BIO operation?
assert(type(chunk) == 'string')
-- success only if chunk not empty?
-- I get chunk == '' while ssl:write returns false, 'want_read'
if #chunk > 0 then return chunk end
while ... do
-- here we try to encode next chunk from input stream and try read again
chunk = .... next decoded chunk
local n, err = self._ssl:write(chunk)
if not n then
if n == nil then -- ssl/syscall - check out last error
return nil, openssl.error()
end
assert(n == false)
if err==0 then
print('SSL has been closed') --just connection really closed
return nil, 'EOF'
end
-- is it possible get err == 'want_write' after write operation.
-- if yes should I just increase chunk or write next chunk?
return ''
end
-- repeat read from self._out:read()
from lua-openssl.
That is right.
self._out:read()
is read from BIO_mem
object so in local chunk, err = self._out:read()
chunk
can be only nil
or string
but not false because it is not SSL function.
Your code is right too.
when bio:read() return string '', should continue to do something and retry read,
from lua-openssl.
Related Issues (20)
- undefined symbol: d2i_OCSP_REQUEST, by openssl version 1.1.1 and lua5.4 HOT 1
- Luarocks.org module does not support 5.4 HOT 1
- ECC verify is not working as expected HOT 3
- 实在搞不定了了 make安装正常 HOT 3
- Compilation will fail with >=clang-16: src/ocsp.c: error: incompatible function pointer types passing char ( )() to parameter of type d2i HOT 6
- Support ED25519 and co.
- Compile with C++ HOT 1
- Build without external dependencies HOT 1
- src/mac.c not included in library target
- 编译报错
- openssl.error() return values changed order
- gcm support HOT 1
- Add logs and update the docs to inform that FIPS is intentionally disabled for OpenSSL1.1.1 and OpenSSL 1.0.2 series HOT 3
- Can't install via luarocks with --verify flag HOT 1
- Having trouble creating an EC PRIVATE KEY with explicit curve (which seems to make a longer key) HOT 1
- Link against the Lua library on Unix/Linux
- Cant compile
- ocsp.c:190:29: error: passing argument 1 of PEM_ASN1_read_bio from incompatible pointer type HOT 1
- Ed25519 private key
- inconsistence of srp api
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lua-openssl.