openresty / openresty/lua-resty-core

ngx.ssl.proxysslverify.set_verify_result gets ignored in case of X509_V_OK (0)

Open
#531 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Lua
Stars
853
Forks
286
Avg merge
35m
Merged PRs (30d)
1

Description

ngx.ssl.proxysslverify.set_verify_result(0) gets ignored

using OpenResty Version: 1.29.2.5

I am failing to set the "SSL verify result" to X509_V_OK, or better: When I set the verification result to 0 it gets ignored.
The upstream server certificate does not include the ip. The proxy pass connection URL uses the IPV4 URL so "verify result" is 18 when I ask for it and the nginx error message tells me that the IPV4 is not part of the upstream certificate.
I want to set the "verify result" to OK in this special case. If I run the same code using another value, greater than 0, it works! The behavior I expect that I can set the verification result to every value I can find in x509_vfy.h including the X509_V_OK (0). So setting this value to 0 would end up in positiv verification result.

my nginx.conf (constructed as an example for you)

server {
    # ... reverse proxy configuration
    location / {
        proxy_ssl_verify "on";
        proxy_ssl_trusted_certificate /etc/ssl/certs/ca-certificates.pem;
        proxy_pass "https://192.168.0.41";
        proxy_ssl_verify_by_lua_block {
            local proxy_ssl_vfy = require "ngx.ssl.proxysslverify"
            local log = ngx.log
            local DEBUG = ngx.DEBUG
            local INFO = ngx.NOTICE
            local ERR = ngx.ERR
            local result, err = proxy_ssl_vfy.get_verify_result()
            log(INFO,"result:",result)
            local cert, cert_err = proxy_ssl_vfy.get_verify_cert()
            --local X509_V_OK=0
            local X509_V_OK=3
            if err then
                log(ERR,err)
            end
            local ok, err = proxy_ssl_vfy.set_verify_result(X509_V_OK)
            if not ok then
                log(ERR, "failed to set ssl verify: ", err)
                return ngx.exit(ngx.ERROR)
            else
                log(DEBUG, "successfully set verify result to:",X509_V_OK)
            end
        }
    }
}

log-output:

8: result:18 while loading proxy ssl verify by lua
20: successfully set verify result to:3
upstream SSL certificate verify error: (3:unable to get certificate CRL) while proxy pass SSL handshaking

If I now change the value to zero (in line 16) before setting the result the output changes to:

8: result:18 while loading proxy ssl verify by lua
20: successfully set verify reult to:0
error: upstream SSL certificate does not match "192.168.0.41" while proxy pass SSL handshaking

To me, this is the same result as without setting any "verify result" by Lua.
Seems like I can overwrite the SSL verfication result with any value except zero. This way I can not bypass the verification, here I can only set Errors, not OK! Am I right that it should be possible to end up in HTTP200 by setting "verify result" to 0? If so, there might be a bug somewhere. If I comment out proxy_ssl_verify "on" the connection ends up in HTTP Code 200 (success).

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the nginx.conf example with ngx.ssl.proxysslverify.set_verify_result(0), then compare it with a nonzero result and the unset case. Trace the set_verify_result entry point and its handling of X509_V_OK, using x509_vfy.h for the expected value. Done means the documented result 0 is honored consistently and the behavior is covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
backend, security
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.