Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bind SSL_get_verify_result #75

Closed
daurnimator opened this issue Nov 9, 2016 · 5 comments
Closed

Bind SSL_get_verify_result #75

daurnimator opened this issue Nov 9, 2016 · 5 comments

Comments

@daurnimator
Copy link
Collaborator

daurnimator commented Nov 9, 2016

SSL_get_verify_result is required to find out why a TLS negotiation failed.

Unlike what the man page suggests, you don't need to have called SSL_get_peer_certificate for this to work.

@daurnimator
Copy link
Collaborator Author

Not sure if I should have this return the numeric error and/or the stringified version (get with X509_verify_cert_error_string), and in what order.

@daurnimator
Copy link
Collaborator Author

daurnimator commented Nov 9, 2016

Possible patch (just need to figure out return value convention):

diff --git a/src/openssl.c b/src/openssl.c
index f32dd6a..1c26b5c 100644
--- a/src/openssl.c
+++ b/src/openssl.c
@@ -7685,6 +7685,15 @@ static int ssl_clearOptions(lua_State *L) {
 } /* ssl_clearOptions() */


+static int ssl_getVerifyResult(lua_State *L) {
+       SSL *ssl = checksimple(L, 1, SSL_CLASS);
+       long res = SSL_get_verify_result(ssl);
+       lua_pushinteger(L, res);
+       lua_pushstring(L, X509_verify_cert_error_string(res));
+       return 2;
+} /* ssl_getVerifyResult() */
+
+
 static int ssl_getPeerCertificate(lua_State *L) {
        SSL *ssl = checksimple(L, 1, SSL_CLASS);
        X509 **x509 = prepsimple(L, X509_CERT_CLASS);
@@ -7872,6 +7881,7 @@ static const auxL_Reg ssl_methods[] = {
        { "setOptions",       &ssl_setOptions },
        { "getOptions",       &ssl_getOptions },
        { "clearOptions",     &ssl_clearOptions },
+       { "getVerifyResult",  &ssl_getVerifyResult },
        { "getPeerCertificate", &ssl_getPeerCertificate },
        { "getPeerChain",     &ssl_getPeerChain },
        { "getCipherInfo",    &ssl_getCipherInfo },

Should also expose the X509_V_* constants.

@daurnimator
Copy link
Collaborator Author

Thanks for commiting 670a112.

Do we want to expose the X509_V_ERR_* constants?
Looking through the openssl repository there were a few added in 1.0.0 and many added in 1.1.0

@wahern
Copy link
Owner

wahern commented Dec 12, 2016

Yes. I just wasn't sure precisely which module(s) to register them with, and because there wasn't a patch to force my hand I moved on to merging other stuff.

@daurnimator
Copy link
Collaborator Author

Closing this as the main goal is done. created #101 to track missing constants

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

No branches or pull requests

2 participants