Use openssl random number generator
We already have a generator class. We should use it. Wrap this into a
function that can be unit tested, and add unit tests.
Note, some files also needed to change name, because random.hpp
conflicts with the built in random, and causes circular build problems.
This commit changes it to ossl_random.
Tested: Unit tests pass. Now has coverage.
Redfish service validator passes.
Change-Id: I5f8eee1af5f4843a352c6fd0e26d67fd3320ef53
Signed-off-by: Ed Tanous <edtanous@google.com>
diff --git a/include/image_upload.hpp b/include/image_upload.hpp
index 18a0c09..cdd7dd4 100644
--- a/include/image_upload.hpp
+++ b/include/image_upload.hpp
@@ -3,10 +3,8 @@
#include "app.hpp"
#include "dbus_singleton.hpp"
#include "dbus_utility.hpp"
+#include "ossl_random.hpp"
-#include <boost/uuid/uuid.hpp>
-#include <boost/uuid/uuid_generators.hpp>
-#include <boost/uuid/uuid_io.hpp>
#include <sdbusplus/bus/match.hpp>
#include <cstdio>
@@ -93,9 +91,7 @@
"member='InterfacesAdded',path='/xyz/openbmc_project/software'",
callback);
- std::string filepath(
- "/tmp/images/" +
- boost::uuids::to_string(boost::uuids::random_generator()()));
+ std::string filepath("/tmp/images/" + bmcweb::getRandomUUID());
BMCWEB_LOG_DEBUG << "Writing file to " << filepath;
std::ofstream out(filepath, std::ofstream::out | std::ofstream::binary |
std::ofstream::trunc);
diff --git a/include/random.hpp b/include/ossl_random.hpp
similarity index 94%
rename from include/random.hpp
rename to include/ossl_random.hpp
index f5f0946..2cbec84 100644
--- a/include/random.hpp
+++ b/include/ossl_random.hpp
@@ -4,6 +4,7 @@
#include <iostream>
#include <limits>
+#include <string>
namespace bmcweb
{
@@ -46,4 +47,6 @@
bool err = false;
};
+std::string getRandomUUID();
+
} // namespace bmcweb
diff --git a/include/persistent_data.hpp b/include/persistent_data.hpp
index 4344074..a08ca7e 100644
--- a/include/persistent_data.hpp
+++ b/include/persistent_data.hpp
@@ -3,12 +3,10 @@
#include "event_service_store.hpp"
#include "http_request.hpp"
#include "http_response.hpp"
+#include "ossl_random.hpp"
#include "sessions.hpp"
#include <boost/beast/http/fields.hpp>
-#include <boost/uuid/uuid.hpp>
-#include <boost/uuid/uuid_generators.hpp>
-#include <boost/uuid/uuid_io.hpp>
#include <nlohmann/json.hpp>
#include <filesystem>
@@ -178,8 +176,7 @@
if (systemUuid.empty())
{
- systemUuid =
- boost::uuids::to_string(boost::uuids::random_generator()());
+ systemUuid = bmcweb::getRandomUUID();
needWrite = true;
}
if (fileRevision < jsonRevision)
diff --git a/include/sessions.hpp b/include/sessions.hpp
index 98912e8..9179723 100644
--- a/include/sessions.hpp
+++ b/include/sessions.hpp
@@ -1,7 +1,7 @@
#pragma once
#include "logging.hpp"
-#include "random.hpp"
+#include "ossl_random.hpp"
#include "utility.hpp"
#include "utils/ip_utils.hpp"
diff --git a/include/ssl_key_handler.hpp b/include/ssl_key_handler.hpp
index 0794fdc..abc9b50 100644
--- a/include/ssl_key_handler.hpp
+++ b/include/ssl_key_handler.hpp
@@ -1,7 +1,7 @@
#pragma once
#include "logging.hpp"
-#include "random.hpp"
+#include "ossl_random.hpp"
extern "C"
{