Merge pull request #249 from metalefty/freebsd/tls
common: fix #248 TLS on FreeBSD
This commit is contained in:
commit
2a8209ca8b
@ -562,11 +562,7 @@ ssl_tls_print_error(char *func, SSL *connection, int value)
|
|||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
case SSL_ERROR_WANT_READ:
|
case SSL_ERROR_WANT_READ:
|
||||||
g_writeln("ssl_tls_print_error: SSL_ERROR_WANT_READ");
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
case SSL_ERROR_WANT_WRITE:
|
case SSL_ERROR_WANT_WRITE:
|
||||||
g_writeln("ssl_tls_print_error: SSL_ERROR_WANT_WRITE");
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case SSL_ERROR_SYSCALL:
|
case SSL_ERROR_SYSCALL:
|
||||||
@ -669,13 +665,24 @@ ssl_tls_accept(struct ssl_tls *self)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
connection_status = SSL_accept(self->ssl);
|
while(1) {
|
||||||
|
connection_status = SSL_accept(self->ssl);
|
||||||
|
|
||||||
if (connection_status <= 0)
|
if (connection_status <= 0)
|
||||||
{
|
|
||||||
if (ssl_tls_print_error("SSL_accept", self->ssl, connection_status))
|
|
||||||
{
|
{
|
||||||
return 1;
|
if (ssl_tls_print_error("SSL_accept", self->ssl, connection_status))
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* retry when SSL_get_error returns:
|
||||||
|
* SSL_ERROR_WANT_READ
|
||||||
|
* SSL_ERROR_WANT_WRITE
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -709,6 +716,11 @@ ssl_tls_disconnect(struct ssl_tls *self)
|
|||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* retry when SSL_get_error returns:
|
||||||
|
* SSL_ERROR_WANT_READ
|
||||||
|
* SSL_ERROR_WANT_WRITE
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -737,23 +749,37 @@ int APP_CC
|
|||||||
ssl_tls_read(struct ssl_tls *tls, char *data, int length)
|
ssl_tls_read(struct ssl_tls *tls, char *data, int length)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
|
int break_flag;
|
||||||
|
|
||||||
status = SSL_read(tls->ssl, data, length);
|
while(1) {
|
||||||
|
status = SSL_read(tls->ssl, data, length);
|
||||||
|
|
||||||
switch (SSL_get_error(tls->ssl, status))
|
switch (SSL_get_error(tls->ssl, status))
|
||||||
{
|
{
|
||||||
case SSL_ERROR_NONE:
|
case SSL_ERROR_NONE:
|
||||||
break;
|
break_flag = 1;
|
||||||
|
break;
|
||||||
case SSL_ERROR_WANT_READ:
|
|
||||||
case SSL_ERROR_WANT_WRITE:
|
case SSL_ERROR_WANT_READ:
|
||||||
status = 0;
|
case SSL_ERROR_WANT_WRITE:
|
||||||
break;
|
/**
|
||||||
|
* retry when SSL_get_error returns:
|
||||||
default:
|
* SSL_ERROR_WANT_READ
|
||||||
ssl_tls_print_error("SSL_read", tls->ssl, status);
|
* SSL_ERROR_WANT_WRITE
|
||||||
status = -1;
|
*/
|
||||||
|
continue;
|
||||||
|
|
||||||
|
default:
|
||||||
|
ssl_tls_print_error("SSL_read", tls->ssl, status);
|
||||||
|
status = -1;
|
||||||
|
break_flag = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (break_flag)
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SSL_pending(tls->ssl) > 0)
|
if (SSL_pending(tls->ssl) > 0)
|
||||||
@ -769,23 +795,37 @@ int APP_CC
|
|||||||
ssl_tls_write(struct ssl_tls *tls, const char *data, int length)
|
ssl_tls_write(struct ssl_tls *tls, const char *data, int length)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
|
int break_flag;
|
||||||
|
|
||||||
status = SSL_write(tls->ssl, data, length);
|
while(1) {
|
||||||
|
status = SSL_write(tls->ssl, data, length);
|
||||||
|
|
||||||
switch (SSL_get_error(tls->ssl, status))
|
switch (SSL_get_error(tls->ssl, status))
|
||||||
{
|
{
|
||||||
case SSL_ERROR_NONE:
|
case SSL_ERROR_NONE:
|
||||||
break;
|
break_flag = 1;
|
||||||
|
break;
|
||||||
case SSL_ERROR_WANT_READ:
|
|
||||||
case SSL_ERROR_WANT_WRITE:
|
case SSL_ERROR_WANT_READ:
|
||||||
status = 0;
|
case SSL_ERROR_WANT_WRITE:
|
||||||
break;
|
/**
|
||||||
|
* retry when SSL_get_error returns:
|
||||||
default:
|
* SSL_ERROR_WANT_READ
|
||||||
ssl_tls_print_error("SSL_write", tls->ssl, status);
|
* SSL_ERROR_WANT_WRITE
|
||||||
status = -1;
|
*/
|
||||||
|
continue;
|
||||||
|
|
||||||
|
default:
|
||||||
|
ssl_tls_print_error("SSL_write", tls->ssl, status);
|
||||||
|
status = -1;
|
||||||
|
break_flag = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (break_flag)
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
|
Loading…
Reference in New Issue
Block a user