char buf[150];
char key_b64[150];
char hash[20];
- int fd;
struct pollfd pfd;
static const char magic_websocket_guid[] =
"258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
* 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);
- close(fd);
goto bail2;
}
- close(fd);
lws_b64_encode_string(hash, 16, key_b64, sizeof key_b64);
char *response;
char *p;
char *m = mask_summing_buf;
- int fd;
int nonce_len;
int accept_len;
/* select the nonce */
- 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);
free(wsi->user_space);
goto bail;
}
- close(fd);
/* encode the nonce */
break;
}
+ close(this->fd_random);
+
#ifdef LWS_OPENSSL_SUPPORT
- if (this && this->ssl_ctx)
+ if (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
- if (this)
- free(this);
+ free(this);
}
/**
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';
static int
libwebsocket_0405_frame_mask_generate(struct libwebsocket *wsi)
{
- int fd;
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;
}
- close(fd);
/* 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;
+
+ int fd_random;
+
#ifdef LWS_OPENSSL_SUPPORT
int use_ssl;
SSL_CTX *ssl_ctx;