7

I am very new to SSL , Actually I would say I know nothing about it.

I am using the method "SSL_CTX_new" to create an SSL_CTX object. The method returns null.The documentation says I can check the error stack in order to get the cause for this.

So I have the function "int SSL_get_error(SSL *s,int ret_code)" which (as I understand) I have to use in order to get the error message. the documentation of the method says nothing about the first parameter of the function. It only says that the second ("ret") parameter should be equal to the return code from the failed operation which can be any of the following :

SSL_connect(), SSL_accept(), SSL_do_handshake(), SSL_read(), SSL_peek(), or SSL_write()

So now I am having two problems. The first is that I didn't use any of those functions but rather use SSL_CTX_new that doesn't return any kind of return code (it returns a pointer to SSX_CTX object) So i don't know what to put as the "ret" parameter. The second problem is that I don't know what does the first parameter mean and what should I put there , because the doc says nothing about it.

4

2 回答 2

8

根据http://www.mail-archive.com/openssl-users@openssl.org/msg51543.html,您可能错过了对SSL_library_init(). 在 SSL_CTX_NEW(..) 调用之前添加它为我解决了 NULL 值问题。

于 2012-11-07T04:17:47.933 回答
8

您需要一个有效的上下文来创建 SSL 对象。

由于您无法创建上下文,因此您无法使用 SSL_get_error。

尝试使用 ERR_print_errors 看看出了什么问题

#include "openssl/err.h"
...

SSL_CTX * ctx = SSL_CTX_new(....);
if(!ctx) {
    ERR_print_errors_fp(stderr);
    //throw or return an error 
}

我刚刚阅读了 SSL 文档。如果您需要以编程方式获取错误代码/错误字符串,您应该使用 ERR_get_error 和 ERR_error_string 函数。

看看这里这里

于 2009-05-25T16:43:51.080 回答