Skip to content

AES get error message#65

Closed
toruneko wants to merge 1 commit into
openresty:masterfrom
toruneko:master
Closed

AES get error message#65
toruneko wants to merge 1 commit into
openresty:masterfrom
toruneko:master

Conversation

@toruneko

Copy link
Copy Markdown

No description provided.

un-def added a commit to un-def/tinystash that referenced this pull request Jul 15, 2020
This addition fixes the following alert in nginx logs:

[alert] ignoring stale global SSL error

See: openresty/lua-resty-string#65
@un-def

un-def commented Jul 15, 2020

Copy link
Copy Markdown

This patch not only improves informativity but also eliminates the following alert in the nginx log:

[alert] ... ignoring stale global SSL error (<error message>)

The alert is emitted during the successful subsequent method call.

@syzh

syzh commented Jul 18, 2020

Copy link
Copy Markdown

@un-def could you help to add more test to cover the more error case?

Comment thread lib/resty/aes.lua
end

local msg = ffi_new("char[?]", 256)
C.ERR_error_string_n(errno, msg, 256)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One OpenSSL call may cause several error messages. Therefore, to handle the error message properly, we need to draw the whole error messages out like:
https://github.com/spacewander/lua-resty-rsa/blob/6a6073f2dcfc319fdf760c65a26382f2a8cf67df/lib/resty/rsa.lua#L158

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One OpenSSL call may cause several error messages

I suspected it but couldn't find confirmation in the OpenSSL documentation. Does the documentation say it clearly or you know it from source code (or another source)?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

attention with https://github.com/spacewander/lua-resty-rsa/blob/6a6073f2dcfc319fdf760c65a26382f2a8cf67df/lib/resty/rsa.lua#L158.
C.ERR_reason_error_string function may return a null value when the code not match a human readable message.
so null value checking for err variable

local err = C.ERR_reason_error_string(code)
if err ~= ffi.null then
    err_queue[i] = ffi_str(err)
    ...
end

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@toruneko
Yes, you are right. We need to check the returned err before using it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, sometimes OpenSSL don't even return an error message when the call is failed. (Perhaps it is a bug): openssl/openssl#11962

So strictly speaking, we need to provide a default one if no error is found:
https://github.com/spacewander/lua-resty-rsa/blob/6a6073f2dcfc319fdf760c65a26382f2a8cf67df/lib/resty/rsa.lua#L180

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@spacewander I've seen it, but this is not the official OpenSSL wiki and has not been updated for a long time. I meant the official docs hosted at https://www.openssl.org/ or official wiki https://wiki.openssl.org/ Anyway, I agree that it's worth popping all entries from the error stack, it's safe and future-compatible.

@un-def

un-def commented Jul 19, 2020

Copy link
Copy Markdown

@syzh what error cases did you mean? Should we add test cases for each OpenSSL FFI call that can produce an error (in other words, cover each place where get_error is used, 8 different OpenSSL functions)?

BTW, I am not the author of this PR :) I just came across it when discovered the reason of stale global SSL error alerts in my logs.

@syzh syzh left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@syzh what error cases did you mean? Should we add test cases for each OpenSSL FFI call that can produce an error (in other words, cover each place where get_error is used, 8 different OpenSSL functions)?

Exactly

Comment thread lib/resty/aes.lua
Comment on lines +116 to +117
local msg = ffi_new("char[?]", 256)
C.ERR_error_string_n(errno, msg, 256)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hope don’t usage magic number

@RaidAndFade

Copy link
Copy Markdown

Hello Team,

I hope this PR has not been frozen in development, as the Decrypt Failures can lead to OpenSSL SSL Handshake errors, as the NGINX SSL Handshake Flow checks for errors in the process. (and this decrypt will show up and prevent successful SSL Handshake, even with a valid certificate)

I have for now bypassed this issue by calling the ERR_get_error in my own code if the decrypt returns nil, but this PR proposes a much cleaner and more unified solution.

👍 to this PR, please seriously review this as even unrelated decrypt failures cause SSL handshake errors and prevent successful requests.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants