Revert of Removing #defines previously used for building without BoringSSL/OpenSSL. (patchset #2 id:20001 of https://codereview.webrtc.org/2640513002/ )
Reason for revert:
Broke chromium build, due to a config being removed. Will add it back and remove the dependency in a chromium CL.
Original issue's description:
> Removing #defines previously used for building without BoringSSL/OpenSSL.
>
> These defines don't work any more, so they only cause confusion:
>
> FEATURE_ENABLE_SSL
> HAVE_OPENSSL_SSL_H
> SSL_USE_OPENSSL
>
> BUG=webrtc:7025
>
> Review-Url: https://codereview.webrtc.org/2640513002
> Cr-Commit-Position: refs/heads/master@{#16196}
> Committed: eaa826c2ee
TBR=kjellander@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:7025
Review-Url: https://codereview.webrtc.org/2648003003
Cr-Commit-Position: refs/heads/master@{#16197}
This commit is contained in:
@ -13,7 +13,18 @@
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
|
||||
#if defined(FEATURE_ENABLE_SSL)
|
||||
#include "webrtc/base/sslconfig.h"
|
||||
#if defined(SSL_USE_OPENSSL)
|
||||
#include <openssl/rand.h>
|
||||
#else
|
||||
#if defined(WEBRTC_WIN)
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <ntsecapi.h>
|
||||
#endif // WEBRTC_WIN
|
||||
#endif // else
|
||||
#endif // FEATURE_ENABLED_SSL
|
||||
|
||||
#include "webrtc/base/base64.h"
|
||||
#include "webrtc/base/basictypes.h"
|
||||
@ -34,6 +45,7 @@ class RandomGenerator {
|
||||
virtual bool Generate(void* buf, size_t len) = 0;
|
||||
};
|
||||
|
||||
#if defined(SSL_USE_OPENSSL)
|
||||
// The OpenSSL RNG.
|
||||
class SecureRandomGenerator : public RandomGenerator {
|
||||
public:
|
||||
@ -45,6 +57,79 @@ class SecureRandomGenerator : public RandomGenerator {
|
||||
}
|
||||
};
|
||||
|
||||
#else
|
||||
#if defined(WEBRTC_WIN)
|
||||
class SecureRandomGenerator : public RandomGenerator {
|
||||
public:
|
||||
SecureRandomGenerator() : advapi32_(NULL), rtl_gen_random_(NULL) {}
|
||||
~SecureRandomGenerator() {
|
||||
FreeLibrary(advapi32_);
|
||||
}
|
||||
|
||||
virtual bool Init(const void* seed, size_t seed_len) {
|
||||
// We don't do any additional seeding on Win32, we just use the CryptoAPI
|
||||
// RNG (which is exposed as a hidden function off of ADVAPI32 so that we
|
||||
// don't need to drag in all of CryptoAPI)
|
||||
if (rtl_gen_random_) {
|
||||
return true;
|
||||
}
|
||||
|
||||
advapi32_ = LoadLibrary(L"advapi32.dll");
|
||||
if (!advapi32_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
rtl_gen_random_ = reinterpret_cast<RtlGenRandomProc>(
|
||||
GetProcAddress(advapi32_, "SystemFunction036"));
|
||||
if (!rtl_gen_random_) {
|
||||
FreeLibrary(advapi32_);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
virtual bool Generate(void* buf, size_t len) {
|
||||
if (!rtl_gen_random_ && !Init(NULL, 0)) {
|
||||
return false;
|
||||
}
|
||||
return (rtl_gen_random_(buf, static_cast<int>(len)) != FALSE);
|
||||
}
|
||||
|
||||
private:
|
||||
typedef BOOL (WINAPI *RtlGenRandomProc)(PVOID, ULONG);
|
||||
HINSTANCE advapi32_;
|
||||
RtlGenRandomProc rtl_gen_random_;
|
||||
};
|
||||
|
||||
#elif !defined(FEATURE_ENABLE_SSL)
|
||||
|
||||
// No SSL implementation -- use rand()
|
||||
class SecureRandomGenerator : public RandomGenerator {
|
||||
public:
|
||||
virtual bool Init(const void* seed, size_t len) {
|
||||
if (len >= 4) {
|
||||
srand(*reinterpret_cast<const int*>(seed));
|
||||
} else {
|
||||
srand(*reinterpret_cast<const char*>(seed));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
virtual bool Generate(void* buf, size_t len) {
|
||||
char* bytes = reinterpret_cast<char*>(buf);
|
||||
for (size_t i = 0; i < len; ++i) {
|
||||
bytes[i] = static_cast<char>(rand());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
#error No SSL implementation has been selected!
|
||||
|
||||
#endif // WEBRTC_WIN
|
||||
#endif
|
||||
|
||||
// A test random generator, for predictable output.
|
||||
class TestRandomGenerator : public RandomGenerator {
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user