Browse Source

style linting

master
despair 5 years ago
parent
commit
5f980b0779
  1. 109
      src/networking/HTTPSRequest.cpp

109
src/networking/HTTPSRequest.cpp

@ -146,8 +146,7 @@ const std::string HTTPSRequest::methodToString(const Method meth) const { @@ -146,8 +146,7 @@ const std::string HTTPSRequest::methodToString(const Method meth) const {
}
}
bool HTTPSRequest::initTLS()
{
bool HTTPSRequest::initTLS(){
mbedtls_net_init( &server_fd );
mbedtls_ssl_init( &ssl );
mbedtls_ssl_config_init( &conf );
@ -155,37 +154,34 @@ bool HTTPSRequest::initTLS() @@ -155,37 +154,34 @@ bool HTTPSRequest::initTLS()
mbedtls_ctr_drbg_init( &ctr_drbg );
#ifndef FIXED_SEED
char seed[64];
char seed[64];
#endif
#if defined(_WIN32) && !defined(FIXED_SEED)
/* On Windows NT 4.0 or later, use CryptoAPI to grab 64 bytes of random data */
HCRYPTPROV hprovider = 0;
CryptAcquireContext(&hprovider, NULL, NULL, PROV_RSA_FULL,CRYPT_VERIFYCONTEXT | CRYPT_SILENT);
CryptGenRandom(hprovider, 64, (BYTE*)&seed);
/* On Windows NT 4.0 or later, use CryptoAPI to grab 64 bytes of random data */
HCRYPTPROV hprovider = 0;
CryptAcquireContext(&hprovider, NULL, NULL, PROV_RSA_FULL,CRYPT_VERIFYCONTEXT | CRYPT_SILENT);
CryptGenRandom(hprovider, 64, (BYTE*)&seed);
CryptReleaseContext(hprovider, 0);
#else
#if !defined(_WIN32) && !defined(FIXED_SEED)
int fd;
fd = open("/dev/urandom", O_RDONLY);
if (fd == -1)
return false;
if (try_read(fd, seed, 64) != 0) {
if (try_close(fd) != 0)
return false;
return false;
}
if (try_close(fd) != 0)
return false;
int fd;
fd = open("/dev/urandom", O_RDONLY);
if (fd == -1)
return false;
if (try_read(fd, seed, 64) != 0) {
if (try_close(fd) != 0)
return false;
return false;
}
if (try_close(fd) != 0)
return false;
#endif
#endif
// only define FIXED_SEED if yer platform does NOT provide a source of (extra) randomness!!!
// only define FIXED_SEED if yer platform does NOT provide a source of (extra) randomness!!!
#ifdef FIXED_SEED
const char *seed = "!@netrunner_ssl_seed$%?rvx86_despair##^^%$#@";
const char *seed = "!@netrunner_ssl_seed$%?rvx86_despair##^^%$#@";
#endif
mbedtls_entropy_init( &entropy );
@ -203,41 +199,38 @@ bool HTTPSRequest::initTLS() @@ -203,41 +199,38 @@ bool HTTPSRequest::initTLS()
/* Random seed generation, non-Windows */
#if !defined(_WIN32) && !defined(FIXED_SEED)
static int try_close(int fd)
{
int ret;
for (;;) {
errno = 0;
ret = close(fd);
if (ret == -1 && errno == EINTR)
continue;
break;
}
return ret;
static int try_close(int fd){
int ret;
for (;;) {
errno = 0;
ret = close(fd);
if (ret == -1 && errno == EINTR)
continue;
break;
}
return ret;
}
static int try_read(int fd, char *out, size_t count)
{
size_t total;
ssize_t partial;
total = 0;
while (total < count)
{
for (;;) {
errno = 0;
partial = read(fd, out + total, count - total);
if (partial == -1 && errno == EINTR)
continue;
break;
}
if (partial < 1)
return -1;
total += partial;
}
return 0;
static int try_read(int fd, char *out, size_t count){
size_t total;
ssize_t partial;
total = 0;
while (total < count){
for (;;) {
errno = 0;
partial = read(fd, out + total, count - total);
if (partial == -1 && errno == EINTR)
continue;
break;
}
if (partial < 1)
return -1;
total += partial;
}
return 0;
}
#endif
Loading…
Cancel
Save