Signed-off-by: Andy Green <andy.green@linaro.org>
char buf[150];
char key_b64[150];
char hash[20];
char buf[150];
char key_b64[150];
char hash[20];
struct pollfd pfd;
static const char magic_websocket_guid[] =
"258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
struct pollfd pfd;
static const char magic_websocket_guid[] =
"258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
* create the random key
*/
* create the random key
*/
- fd = open(SYSTEM_RANDOM_FILEPATH, O_RDONLY);
- if (fd < 1) {
- fprintf(stderr, "Unable to open random device %s\n",
- SYSTEM_RANDOM_FILEPATH);
- goto bail2;
- }
- n = read(fd, hash, 16);
+ n = read(this->fd_random, hash, 16);
if (n != 16) {
fprintf(stderr, "Unable to read from random device %s\n",
SYSTEM_RANDOM_FILEPATH);
if (n != 16) {
fprintf(stderr, "Unable to read from random device %s\n",
SYSTEM_RANDOM_FILEPATH);
lws_b64_encode_string(hash, 16, key_b64, sizeof key_b64);
lws_b64_encode_string(hash, 16, key_b64, sizeof key_b64);
char *response;
char *p;
char *m = mask_summing_buf;
char *response;
char *p;
char *m = mask_summing_buf;
int nonce_len;
int accept_len;
int nonce_len;
int accept_len;
- fd = open(SYSTEM_RANDOM_FILEPATH, O_RDONLY);
- if (fd < 1) {
- fprintf(stderr, "Unable to open random device %s\n",
- SYSTEM_RANDOM_FILEPATH);
- if (wsi->user_space)
- free(wsi->user_space);
- goto bail;
- }
- n = read(fd, hash, 16);
+ n = read(wsi->protocol->owning_server->fd_random, hash, 16);
if (n != 16) {
fprintf(stderr, "Unable to read from random device %s %d\n",
SYSTEM_RANDOM_FILEPATH, n);
if (n != 16) {
fprintf(stderr, "Unable to read from random device %s %d\n",
SYSTEM_RANDOM_FILEPATH, n);
free(wsi->user_space);
goto bail;
}
free(wsi->user_space);
goto bail;
}
+ close(this->fd_random);
+
#ifdef LWS_OPENSSL_SUPPORT
#ifdef LWS_OPENSSL_SUPPORT
- if (this && this->ssl_ctx)
SSL_CTX_free(this->ssl_ctx);
SSL_CTX_free(this->ssl_ctx);
- if (this && this->ssl_client_ctx)
+ if (this->ssl_client_ctx)
SSL_CTX_free(this->ssl_client_ctx);
#endif
SSL_CTX_free(this->ssl_client_ctx);
#endif
- if (this)
- free(this);
this->http_proxy_address[0] = '\0';
this->options = options;
this->http_proxy_address[0] = '\0';
this->options = options;
+ this->fd_random = open(SYSTEM_RANDOM_FILEPATH, O_RDONLY);
+ if (this->fd_random < 0) {
+ fprintf(stderr, "Unable to open random device %s %d\n",
+ SYSTEM_RANDOM_FILEPATH, this->fd_random);
+ return NULL;
+ }
+
/* find canonical hostname */
hostname[(sizeof hostname) - 1] = '\0';
/* find canonical hostname */
hostname[(sizeof hostname) - 1] = '\0';
static int
libwebsocket_0405_frame_mask_generate(struct libwebsocket *wsi)
{
static int
libwebsocket_0405_frame_mask_generate(struct libwebsocket *wsi)
{
char buf[4 + 20];
int n;
/* fetch the per-frame nonce */
char buf[4 + 20];
int n;
/* fetch the per-frame nonce */
- fd = open(SYSTEM_RANDOM_FILEPATH, O_RDONLY);
- if (fd < 0) {
- fprintf(stderr, "Unable to open random device %s %d\n",
- SYSTEM_RANDOM_FILEPATH, fd);
- return 1;
- }
- n = read(fd, wsi->frame_masking_nonce_04, 4);
+ n = read(wsi->protocol->owning_server->fd_random,
+ wsi->frame_masking_nonce_04, 4);
if (n != 4) {
fprintf(stderr, "Unable to read from random device %s %d\n",
SYSTEM_RANDOM_FILEPATH, n);
return 1;
}
if (n != 4) {
fprintf(stderr, "Unable to read from random device %s %d\n",
SYSTEM_RANDOM_FILEPATH, n);
return 1;
}
/* start masking from first byte of masking key buffer */
wsi->frame_mask_index = 0;
/* start masking from first byte of masking key buffer */
wsi->frame_mask_index = 0;
char canonical_hostname[1024];
unsigned int http_proxy_port;
unsigned int options;
char canonical_hostname[1024];
unsigned int http_proxy_port;
unsigned int options;
#ifdef LWS_OPENSSL_SUPPORT
int use_ssl;
SSL_CTX *ssl_ctx;
#ifdef LWS_OPENSSL_SUPPORT
int use_ssl;
SSL_CTX *ssl_ctx;