forked from lda/telodendria
Fix up TlsOpenSSL a little bit.
Server is still broken...
This commit is contained in:
parent
aeb49f80e5
commit
a25573063f
1 changed files with 14 additions and 0 deletions
|
@ -124,32 +124,38 @@ TlsInitServer(int fd, const char *crt, const char *key)
|
||||||
cookie->ctx = SSL_CTX_new(cookie->method);
|
cookie->ctx = SSL_CTX_new(cookie->method);
|
||||||
if (!cookie->ctx)
|
if (!cookie->ctx)
|
||||||
{
|
{
|
||||||
|
Log(LOG_ERR, "TlsServerInit(): Unable to create SSL Context.");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SSL_CTX_use_certificate_file(cookie->ctx, crt, SSL_FILETYPE_PEM) <= 0)
|
if (SSL_CTX_use_certificate_file(cookie->ctx, crt, SSL_FILETYPE_PEM) <= 0)
|
||||||
{
|
{
|
||||||
|
Log(LOG_ERR, "TlsServerInit(): Unable to set certificate file.");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SSL_CTX_use_PrivateKey_file(cookie->ctx, key, SSL_FILETYPE_PEM) <= 0)
|
if (SSL_CTX_use_PrivateKey_file(cookie->ctx, key, SSL_FILETYPE_PEM) <= 0)
|
||||||
{
|
{
|
||||||
|
Log(LOG_ERR, "TlsServerInit(): Unable to set key file.");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
cookie->ssl = SSL_new(cookie->ctx);
|
cookie->ssl = SSL_new(cookie->ctx);
|
||||||
if (!cookie->ssl)
|
if (!cookie->ssl)
|
||||||
{
|
{
|
||||||
|
Log(LOG_ERR, "TlsServerInit(): Unable to create SSL object.");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!SSL_set_fd(cookie->ssl, fd))
|
if (!SSL_set_fd(cookie->ssl, fd))
|
||||||
{
|
{
|
||||||
|
Log(LOG_ERR, "TlsServerInit(): Unable to set file descriptor.");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SSL_accept(cookie->ssl) <= 0)
|
if (SSL_accept(cookie->ssl) <= 0)
|
||||||
{
|
{
|
||||||
|
Log(LOG_ERR, "TlsServerInit(): Unable to accept connection.");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,8 +195,12 @@ TlsRead(void *cookie, void *buf, size_t nBytes)
|
||||||
case SSL_ERROR_WANT_WRITE:
|
case SSL_ERROR_WANT_WRITE:
|
||||||
case SSL_ERROR_WANT_CONNECT:
|
case SSL_ERROR_WANT_CONNECT:
|
||||||
case SSL_ERROR_WANT_ACCEPT:
|
case SSL_ERROR_WANT_ACCEPT:
|
||||||
|
case SSL_ERROR_WANT_X509_LOOKUP:
|
||||||
errno = EAGAIN;
|
errno = EAGAIN;
|
||||||
break;
|
break;
|
||||||
|
case SSL_ERROR_ZERO_RETURN:
|
||||||
|
ret = 0;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
errno = EIO;
|
errno = EIO;
|
||||||
break;
|
break;
|
||||||
|
@ -215,8 +225,12 @@ TlsWrite(void *cookie, void *buf, size_t nBytes)
|
||||||
case SSL_ERROR_WANT_WRITE:
|
case SSL_ERROR_WANT_WRITE:
|
||||||
case SSL_ERROR_WANT_CONNECT:
|
case SSL_ERROR_WANT_CONNECT:
|
||||||
case SSL_ERROR_WANT_ACCEPT:
|
case SSL_ERROR_WANT_ACCEPT:
|
||||||
|
case SSL_ERROR_WANT_X509_LOOKUP:
|
||||||
errno = EAGAIN;
|
errno = EAGAIN;
|
||||||
break;
|
break;
|
||||||
|
case SSL_ERROR_ZERO_RETURN:
|
||||||
|
ret = 0;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
errno = EIO;
|
errno = EIO;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue