mirror of
https://github.com/Telecominfraproject/wlan-cloud-ucentralgw.git
synced 2025-11-01 19:28:01 +00:00
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
This commit is contained in:
@@ -231,10 +231,7 @@ namespace OpenWifi {
|
||||
Details.set(uCentralProtocol::TIMESTAMP, Utils::Now());
|
||||
Details.set(uCentralProtocol::UUID,uuid);
|
||||
Disconnect.set(uCentralProtocol::DISCONNECTION, Details);
|
||||
Poco::JSON::Stringifier Stringify;
|
||||
std::ostringstream OS;
|
||||
Stringify.condense(Disconnect, OS);
|
||||
KafkaManager()->PostMessage(KafkaTopics::CONNECTION, SerialNumber, std::make_shared<std::string>(OS.str()));
|
||||
KafkaManager()->PostMessage(KafkaTopics::CONNECTION, SerialNumber, Disconnect);
|
||||
} catch (...) {
|
||||
}
|
||||
}
|
||||
@@ -725,10 +722,7 @@ namespace OpenWifi {
|
||||
PingDetails.set(uCentralProtocol::UUID, uuid_);
|
||||
PingDetails.set("locale", State_.locale);
|
||||
PingObject.set(uCentralProtocol::PING, PingDetails);
|
||||
Poco::JSON::Stringifier Stringify;
|
||||
std::ostringstream OS;
|
||||
Stringify.condense(PingObject, OS);
|
||||
KafkaManager()->PostMessage(KafkaTopics::CONNECTION, SerialNumber_, std::make_shared<std::string>(OS.str()));
|
||||
KafkaManager()->PostMessage(KafkaTopics::CONNECTION, SerialNumber_,PingObject);
|
||||
}
|
||||
return;
|
||||
} break;
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace OpenWifi {
|
||||
Poco::JSON::Stringifier Stringify;
|
||||
std::ostringstream OS;
|
||||
Stringify.condense(ParamsObj, OS);
|
||||
KafkaManager()->PostMessage(KafkaTopics::ALERTS, SerialNumber_, std::make_shared<std::string>(OS.str()));
|
||||
KafkaManager()->PostMessage(KafkaTopics::ALERTS, SerialNumber_, OS.str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,9 +32,7 @@ namespace OpenWifi {
|
||||
Event.set("type", "device.firmware_change");
|
||||
Event.set("timestamp", Utils::Now());
|
||||
Event.set("payload", EventDetails);
|
||||
std::ostringstream OS;
|
||||
Event.stringify(OS);
|
||||
KafkaManager()->PostMessage(KafkaTopics::DEVICE_EVENT_QUEUE, SerialNumber, std::make_shared<std::string>(OS.str()));
|
||||
KafkaManager()->PostMessage(KafkaTopics::DEVICE_EVENT_QUEUE, SerialNumber, Event);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,9 +49,7 @@ namespace OpenWifi {
|
||||
Event.set("type", "device.not_provisioned");
|
||||
Event.set("timestamp", Utils::Now());
|
||||
Event.set("payload", EventDetails);
|
||||
std::ostringstream OS;
|
||||
Event.stringify(OS);
|
||||
KafkaManager()->PostMessage(KafkaTopics::DEVICE_EVENT_QUEUE, SerialNumber, std::make_shared<std::string>(OS.str()));
|
||||
KafkaManager()->PostMessage(KafkaTopics::DEVICE_EVENT_QUEUE, SerialNumber, Event);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,15 +281,11 @@ namespace OpenWifi {
|
||||
GWWebSocketNotifications::DeviceConnected(Notification);
|
||||
|
||||
if (KafkaManager()->Enabled()) {
|
||||
Poco::JSON::Stringifier Stringify;
|
||||
|
||||
ParamsObj->set(uCentralProtocol::CONNECTIONIP, CId_);
|
||||
ParamsObj->set("locale", State_.locale);
|
||||
ParamsObj->set(uCentralProtocol::TIMESTAMP, Utils::Now());
|
||||
ParamsObj->set(uCentralProtocol::UUID, uuid_);
|
||||
std::ostringstream OS;
|
||||
Stringify.condense(ParamsObj, OS);
|
||||
KafkaManager()->PostMessage(KafkaTopics::CONNECTION, SerialNumber_, std::make_shared<std::string>(OS.str()));
|
||||
KafkaManager()->PostMessage(KafkaTopics::CONNECTION, SerialNumber_, *ParamsObj);
|
||||
}
|
||||
} else {
|
||||
poco_warning(
|
||||
|
||||
@@ -34,11 +34,8 @@ namespace OpenWifi {
|
||||
FullEvent.set("type", EventType);
|
||||
FullEvent.set("timestamp", EventTimeStamp);
|
||||
FullEvent.set("payload", EventPayload);
|
||||
|
||||
std::ostringstream OS;
|
||||
FullEvent.stringify(OS);
|
||||
KafkaManager()->PostMessage(KafkaTopics::DEVICE_EVENT_QUEUE, SerialNumber_,
|
||||
std::make_shared<std::string>(OS.str()));
|
||||
FullEvent);
|
||||
}
|
||||
}
|
||||
} catch (const Poco::Exception &E) {
|
||||
|
||||
@@ -60,11 +60,7 @@ namespace OpenWifi {
|
||||
|
||||
SetLastHealthCheck(Check);
|
||||
if (KafkaManager()->Enabled()) {
|
||||
Poco::JSON::Stringifier Stringify;
|
||||
std::ostringstream OS;
|
||||
ParamsObj->set("timestamp", Utils::Now());
|
||||
Stringify.condense(ParamsObj, OS);
|
||||
KafkaManager()->PostMessage(KafkaTopics::HEALTHCHECK, SerialNumber_, std::make_shared<std::string>(OS.str()));
|
||||
KafkaManager()->PostMessage(KafkaTopics::HEALTHCHECK, SerialNumber_, *ParamsObj);
|
||||
}
|
||||
} else {
|
||||
poco_warning(Logger_, fmt::format("HEALTHCHECK({}): Missing parameter", CId_));
|
||||
|
||||
@@ -56,10 +56,7 @@ namespace OpenWifi {
|
||||
State_.Associations_5G, State_.Associations_6G);
|
||||
|
||||
if (KafkaManager()->Enabled()) {
|
||||
Poco::JSON::Stringifier Stringify;
|
||||
std::ostringstream OS;
|
||||
Stringify.condense(ParamsObj, OS);
|
||||
KafkaManager()->PostMessage(KafkaTopics::STATE, SerialNumber_, std::make_shared<std::string>(OS.str()));
|
||||
KafkaManager()->PostMessage(KafkaTopics::STATE, SerialNumber_, *ParamsObj);
|
||||
}
|
||||
|
||||
GWWebSocketNotifications::SingleDevice_t N;
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace OpenWifi {
|
||||
std::ostringstream SS;
|
||||
Payload->stringify(SS);
|
||||
auto now = Utils::Now();
|
||||
auto KafkaPayload = std::make_shared<std::string>(SS.str());
|
||||
auto KafkaPayload = SS.str();
|
||||
if (ParamsObj->has("adhoc")) {
|
||||
KafkaManager()->PostMessage(KafkaTopics::DEVICE_TELEMETRY, SerialNumber_,
|
||||
KafkaPayload);
|
||||
@@ -39,7 +39,7 @@ namespace OpenWifi {
|
||||
// std::endl;
|
||||
TelemetryWebSocketPackets_++;
|
||||
State_.websocketPackets = TelemetryWebSocketPackets_;
|
||||
TelemetryStream()->NotifyEndPoint(SerialNumberInt_, *KafkaPayload);
|
||||
TelemetryStream()->NotifyEndPoint(SerialNumberInt_, KafkaPayload);
|
||||
} else {
|
||||
StopWebSocketTelemetry(CommandManager()->Next_RPC_ID());
|
||||
}
|
||||
|
||||
@@ -21,11 +21,7 @@ namespace OpenWifi {
|
||||
|
||||
if (ParamsObj->has(uCentralProtocol::SERIAL) && ParamsObj->has(uCentralProtocol::DATA)) {
|
||||
if (KafkaManager()->Enabled()) {
|
||||
auto Data = ParamsObj->get(uCentralProtocol::DATA);
|
||||
Poco::JSON::Stringifier Stringify;
|
||||
std::ostringstream OS;
|
||||
Stringify.condense(ParamsObj, OS);
|
||||
KafkaManager()->PostMessage(KafkaTopics::WIFISCAN, SerialNumber_, std::make_shared<std::string>(OS.str()));
|
||||
KafkaManager()->PostMessage(KafkaTopics::WIFISCAN, SerialNumber_, *ParamsObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -233,10 +233,7 @@ namespace OpenWifi {
|
||||
FullEvent.set("timestamp", now);
|
||||
FullEvent.set("payload", KafkaNotification);
|
||||
|
||||
std::ostringstream OS;
|
||||
FullEvent.stringify(OS);
|
||||
KafkaManager()->PostMessage(KafkaTopics::DEVICE_EVENT_QUEUE, "system",
|
||||
std::make_shared<std::string>(OS.str()));
|
||||
KafkaManager()->PostMessage(KafkaTopics::DEVICE_EVENT_QUEUE, "system", FullEvent);
|
||||
}
|
||||
|
||||
void AP_WS_Server::Stop() {
|
||||
|
||||
@@ -14,8 +14,7 @@ namespace OpenWifi {
|
||||
Event.set("payload", payload_);
|
||||
std::ostringstream OS;
|
||||
Event.stringify(OS);
|
||||
auto payload = std::make_shared<std::string>(OS.str());
|
||||
KafkaManager()->PostMessage(KafkaTopics::DEVICE_EVENT_QUEUE, Utils::IntToSerialNumber(serialNumber_), payload);
|
||||
KafkaManager()->PostMessage(KafkaTopics::DEVICE_EVENT_QUEUE, Utils::IntToSerialNumber(serialNumber_), OS.str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1024,7 +1024,7 @@ namespace OpenWifi {
|
||||
RESTAPI_RPC::WaitForCommand(CMD_RPC, APCommands::Commands::wifiscan, false, Cmd, Params,
|
||||
*Request, *Response, timeout, nullptr, this, Logger_);
|
||||
if (Cmd.ErrorCode == 0) {
|
||||
KafkaManager()->PostMessage(KafkaTopics::WIFISCAN, SerialNumber_, std::make_shared<std::string>(Cmd.Results));
|
||||
KafkaManager()->PostMessage(KafkaTopics::WIFISCAN, SerialNumber_, Cmd.Results);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1069,7 +1069,7 @@ namespace OpenWifi {
|
||||
Logger_);
|
||||
if (Cmd.ErrorCode == 0) {
|
||||
KafkaManager()->PostMessage(KafkaTopics::DEVICE_EVENT_QUEUE, SerialNumber_,
|
||||
std::make_shared<std::string>(Cmd.Results));
|
||||
Cmd.Results);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -1126,9 +1126,6 @@ namespace OpenWifi {
|
||||
BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
|
||||
}
|
||||
|
||||
#define DBGLINE \
|
||||
{ std::cout << __LINE__ << std::endl; }
|
||||
|
||||
void RESTAPI_device_commandHandler::Rtty(
|
||||
const std::string &CMD_UUID, uint64_t CMD_RPC, std::chrono::milliseconds timeout,
|
||||
[[maybe_unused]] const GWObjects::DeviceRestrictions &Restrictions) {
|
||||
|
||||
@@ -14,18 +14,18 @@ namespace OpenWifi {
|
||||
void EventBusManager::run() {
|
||||
Running_ = true;
|
||||
Utils::SetThreadName("fmwk:EventMgr");
|
||||
auto Msg = std::make_shared<std::string>(MicroServiceMakeSystemEventMessage(KafkaTopics::ServiceEvents::EVENT_JOIN));
|
||||
auto Msg = (MicroServiceMakeSystemEventMessage(KafkaTopics::ServiceEvents::EVENT_JOIN));
|
||||
KafkaManager()->PostMessage(KafkaTopics::SERVICE_EVENTS, MicroServicePrivateEndPoint(), Msg,
|
||||
false);
|
||||
while (Running_) {
|
||||
Poco::Thread::trySleep((unsigned long)MicroServiceDaemonBusTimer());
|
||||
if (!Running_)
|
||||
break;
|
||||
Msg = std::make_shared<std::string>(MicroServiceMakeSystemEventMessage(KafkaTopics::ServiceEvents::EVENT_KEEP_ALIVE));
|
||||
Msg = (MicroServiceMakeSystemEventMessage(KafkaTopics::ServiceEvents::EVENT_KEEP_ALIVE));
|
||||
KafkaManager()->PostMessage(KafkaTopics::SERVICE_EVENTS, MicroServicePrivateEndPoint(),
|
||||
Msg, false);
|
||||
}
|
||||
Msg = std::make_shared<std::string>(MicroServiceMakeSystemEventMessage(KafkaTopics::ServiceEvents::EVENT_LEAVE));
|
||||
Msg = (MicroServiceMakeSystemEventMessage(KafkaTopics::ServiceEvents::EVENT_LEAVE));
|
||||
KafkaManager()->PostMessage(KafkaTopics::SERVICE_EVENTS, MicroServicePrivateEndPoint(), Msg,
|
||||
false);
|
||||
};
|
||||
|
||||
@@ -180,7 +180,7 @@ namespace OpenWifi {
|
||||
Consumer.async_commit(Msg);
|
||||
continue;
|
||||
}
|
||||
KafkaManager()->Dispatch(Msg.get_topic().c_str(), Msg.get_key(), std::make_shared<std::string>(Msg.get_payload()));
|
||||
KafkaManager()->Dispatch(Msg.get_topic().c_str(), Msg.get_key(), Msg.get_payload());
|
||||
if (!AutoCommit)
|
||||
Consumer.async_commit(Msg);
|
||||
}
|
||||
@@ -213,7 +213,7 @@ namespace OpenWifi {
|
||||
}
|
||||
|
||||
void KafkaProducer::Produce(const char *Topic, const std::string &Key,
|
||||
std::shared_ptr<std::string> Payload) {
|
||||
const std::string &Payload) {
|
||||
std::lock_guard G(Mutex_);
|
||||
Queue_.enqueueNotification(new KafkaMessage(Topic, Key, Payload));
|
||||
}
|
||||
@@ -276,7 +276,7 @@ namespace OpenWifi {
|
||||
}
|
||||
|
||||
void KafkaDispatcher::Dispatch(const char *Topic, const std::string &Key,
|
||||
const std::shared_ptr<std::string> Payload) {
|
||||
const std::string & Payload) {
|
||||
std::lock_guard G(Mutex_);
|
||||
auto It = Notifiers_.find(Topic);
|
||||
if (It != Notifiers_.end()) {
|
||||
@@ -333,20 +333,29 @@ namespace OpenWifi {
|
||||
}
|
||||
|
||||
void KafkaManager::PostMessage(const char *topic, const std::string &key,
|
||||
const std::shared_ptr<std::string> PayLoad, bool WrapMessage) {
|
||||
const std::string & PayLoad, bool WrapMessage) {
|
||||
if (KafkaEnabled_) {
|
||||
ProducerThr_.Produce(topic, key, WrapMessage ? WrapSystemId(PayLoad) : PayLoad);
|
||||
}
|
||||
}
|
||||
|
||||
void KafkaManager::PostMessage(const char *topic, const std::string &key,
|
||||
const Poco::JSON::Object &Object, bool WrapMessage) {
|
||||
if (KafkaEnabled_) {
|
||||
std::ostringstream ObjectStr;
|
||||
Object.stringify(ObjectStr);
|
||||
ProducerThr_.Produce(topic, key, WrapMessage ? WrapSystemId(ObjectStr.str()) : ObjectStr.str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void KafkaManager::Dispatch(const char *Topic, const std::string &Key,
|
||||
const std::shared_ptr<std::string> Payload) {
|
||||
const std::string &Payload) {
|
||||
Dispatcher_.Dispatch(Topic, Key, Payload);
|
||||
}
|
||||
|
||||
[[nodiscard]] const std::shared_ptr<std::string> KafkaManager::WrapSystemId(const std::shared_ptr<std::string> PayLoad) {
|
||||
*PayLoad = SystemInfoWrapper_ + *PayLoad + "}";
|
||||
return PayLoad;
|
||||
[[nodiscard]] std::string KafkaManager::WrapSystemId(const std::string & PayLoad) {
|
||||
return SystemInfoWrapper_ + PayLoad + "}";
|
||||
}
|
||||
|
||||
uint64_t KafkaManager::RegisterTopicWatcher(const std::string &Topic,
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include "Poco/Notification.h"
|
||||
#include "Poco/NotificationQueue.h"
|
||||
|
||||
#include "Poco/JSON/Object.h"
|
||||
#include "framework/KafkaTopics.h"
|
||||
#include "framework/OpenWifiTypes.h"
|
||||
#include "framework/SubSystemServer.h"
|
||||
@@ -18,17 +18,17 @@ namespace OpenWifi {
|
||||
|
||||
class KafkaMessage : public Poco::Notification {
|
||||
public:
|
||||
KafkaMessage(const char * Topic, const std::string &Key, std::shared_ptr<std::string> Payload)
|
||||
KafkaMessage(const char * Topic, const std::string &Key, const std::string &Payload)
|
||||
: Topic_(Topic), Key_(Key), Payload_(Payload) {}
|
||||
|
||||
inline const char * Topic() { return Topic_; }
|
||||
inline const std::string &Key() { return Key_; }
|
||||
inline const std::string &Payload() { return *Payload_; }
|
||||
inline const std::string &Payload() { return Payload_; }
|
||||
|
||||
private:
|
||||
const char *Topic_;
|
||||
std::string Key_;
|
||||
std::shared_ptr<std::string> Payload_;
|
||||
std::string Payload_;
|
||||
};
|
||||
|
||||
class KafkaProducer : public Poco::Runnable {
|
||||
@@ -36,7 +36,7 @@ namespace OpenWifi {
|
||||
void run() override;
|
||||
void Start();
|
||||
void Stop();
|
||||
void Produce(const char *Topic, const std::string &Key, std::shared_ptr<std::string> Payload);
|
||||
void Produce(const char *Topic, const std::string &Key, const std::string & Payload);
|
||||
|
||||
private:
|
||||
std::recursive_mutex Mutex_;
|
||||
@@ -63,7 +63,7 @@ namespace OpenWifi {
|
||||
void Stop();
|
||||
auto RegisterTopicWatcher(const std::string &Topic, Types::TopicNotifyFunction &F);
|
||||
void UnregisterTopicWatcher(const std::string &Topic, int Id);
|
||||
void Dispatch(const char *Topic, const std::string &Key, const std::shared_ptr<std::string> Payload);
|
||||
void Dispatch(const char *Topic, const std::string &Key, const std::string & Payload);
|
||||
void run() override;
|
||||
void Topics(std::vector<std::string> &T);
|
||||
|
||||
@@ -92,9 +92,12 @@ namespace OpenWifi {
|
||||
void Stop() override;
|
||||
|
||||
void PostMessage(const char *topic, const std::string &key,
|
||||
std::shared_ptr<std::string> PayLoad, bool WrapMessage = true);
|
||||
void Dispatch(const char *Topic, const std::string &Key, std::shared_ptr<std::string> Payload);
|
||||
[[nodiscard]] const std::shared_ptr<std::string> WrapSystemId(std::shared_ptr<std::string> PayLoad);
|
||||
const std::string &PayLoad, bool WrapMessage = true);
|
||||
void PostMessage(const char *topic, const std::string &key,
|
||||
const Poco::JSON::Object &Object, bool WrapMessage = true);
|
||||
|
||||
void Dispatch(const char *Topic, const std::string &Key, const std::string &Payload);
|
||||
[[nodiscard]] std::string WrapSystemId(const std::string & PayLoad);
|
||||
[[nodiscard]] inline bool Enabled() const { return KafkaEnabled_; }
|
||||
uint64_t RegisterTopicWatcher(const std::string &Topic, Types::TopicNotifyFunction &F);
|
||||
void UnregisterTopicWatcher(const std::string &Topic, uint64_t Id);
|
||||
|
||||
@@ -584,6 +584,26 @@ namespace OpenWifi {
|
||||
return ReturnRawJSON(os.str());
|
||||
}
|
||||
|
||||
template<class T> void ReturnObject(const std::vector<T> &Objects) {
|
||||
Poco::JSON::Array Arr;
|
||||
for(const auto &Object:Objects) {
|
||||
Poco::JSON::Object O;
|
||||
Object.to_json(O);
|
||||
Arr.add(O);
|
||||
}
|
||||
std::ostringstream os;
|
||||
Arr.stringify(os);
|
||||
return ReturnRawJSON(os.str());
|
||||
}
|
||||
|
||||
template<class T> void ReturnObject(const T &Object) {
|
||||
Poco::JSON::Object O;
|
||||
Object.to_json(O);
|
||||
std::ostringstream os;
|
||||
O.stringify(os);
|
||||
return ReturnRawJSON(os.str());
|
||||
}
|
||||
|
||||
inline void ReturnRawJSON(const std::string &json_doc) {
|
||||
PrepareResponse();
|
||||
if (Request != nullptr) {
|
||||
|
||||
@@ -40,6 +40,7 @@ namespace OpenWifi {
|
||||
};
|
||||
}
|
||||
|
||||
#define DBGLINE std::cout << __LINE__ << ":" << __FILE__ << ", " << __func__ << std::endl;
|
||||
namespace OpenWifi::RESTAPI::Errors {
|
||||
struct msg {
|
||||
uint64_t err_num;
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
//
|
||||
|
||||
#include "Poco/Path.h"
|
||||
|
||||
#include "Poco/TemporaryFile.h"
|
||||
#include "Poco/Crypto/ECKey.h"
|
||||
#include "framework/AppServiceRegistry.h"
|
||||
#include "framework/utils.h"
|
||||
|
||||
@@ -608,4 +609,154 @@ namespace OpenWifi::Utils {
|
||||
return DT.timestamp().epochTime();
|
||||
}
|
||||
|
||||
static std::string FileToString(const std::string &Filename) {
|
||||
std::ifstream ifs(Filename.c_str(),std::ios_base::in|std::ios_base::binary);
|
||||
std::ostringstream os;
|
||||
Poco::StreamCopier::copyStream(ifs,os);
|
||||
return os.str();
|
||||
}
|
||||
|
||||
bool CreateX509CSR(const CSRCreationParameters & Parameters, CSRCreationResults & Results) {
|
||||
int ret = 0;
|
||||
RSA *r = nullptr;
|
||||
BIGNUM *bne = nullptr;
|
||||
|
||||
int nVersion = 0;
|
||||
unsigned long e = RSA_F4;
|
||||
|
||||
X509_REQ *x509_req = nullptr;
|
||||
X509_NAME *x509_name = nullptr;
|
||||
EVP_PKEY *pKey = nullptr;
|
||||
// RSA *tem = nullptr;
|
||||
// BIO *bio_err = nullptr;
|
||||
|
||||
const char *szCountry = Parameters.Country.c_str();
|
||||
const char *szProvince = Parameters.Province.c_str();
|
||||
const char *szCity = Parameters.City.c_str();
|
||||
const char *szOrganization = Parameters.Organization.c_str();
|
||||
const char *szCommon = Parameters.CommonName.c_str();
|
||||
|
||||
Poco::TemporaryFile CsrPath, PubKey, PrivateKey;
|
||||
std::string Result;
|
||||
std::ifstream ifs;
|
||||
std::ostringstream ss;
|
||||
BIO *bp_public = nullptr,
|
||||
*bp_private = nullptr,
|
||||
*bp_csr = nullptr;
|
||||
|
||||
// 1. generate rsa key
|
||||
bne = BN_new();
|
||||
ret = BN_set_word(bne,e);
|
||||
if(ret != 1){
|
||||
goto free_all;
|
||||
}
|
||||
|
||||
r = RSA_new();
|
||||
ret = RSA_generate_key_ex(r, Parameters.bits, bne, nullptr);
|
||||
if(ret != 1){
|
||||
goto free_all;
|
||||
}
|
||||
|
||||
bp_public = BIO_new_file(PubKey.path().c_str(), "w+");
|
||||
ret = PEM_write_bio_RSAPublicKey(bp_public, r);
|
||||
if(ret != 1) {
|
||||
goto free_all;
|
||||
}
|
||||
|
||||
bp_private = BIO_new_file(PrivateKey.path().c_str(), "w+");
|
||||
ret = PEM_write_bio_RSAPrivateKey(bp_private, r, NULL, NULL, 0, NULL, NULL);
|
||||
if(ret != 1) {
|
||||
goto free_all;
|
||||
}
|
||||
|
||||
// 2. set version of x509 req
|
||||
x509_req = X509_REQ_new();
|
||||
ret = X509_REQ_set_version(x509_req, nVersion);
|
||||
if (ret != 1){
|
||||
goto free_all;
|
||||
}
|
||||
|
||||
// 3. set subject of x509 req
|
||||
x509_name = X509_REQ_get_subject_name(x509_req);
|
||||
|
||||
ret = X509_NAME_add_entry_by_txt(x509_name,"C", MBSTRING_ASC, (const unsigned char*)szCountry, -1, -1, 0);
|
||||
if (ret != 1){
|
||||
goto free_all;
|
||||
}
|
||||
|
||||
ret = X509_NAME_add_entry_by_txt(x509_name,"ST", MBSTRING_ASC, (const unsigned char*)szProvince, -1, -1, 0);
|
||||
if (ret != 1){
|
||||
goto free_all;
|
||||
}
|
||||
|
||||
ret = X509_NAME_add_entry_by_txt(x509_name,"L", MBSTRING_ASC, (const unsigned char*)szCity, -1, -1, 0);
|
||||
if (ret != 1){
|
||||
goto free_all;
|
||||
}
|
||||
|
||||
ret = X509_NAME_add_entry_by_txt(x509_name,"O", MBSTRING_ASC, (const unsigned char*)szOrganization, -1, -1, 0);
|
||||
if (ret != 1){
|
||||
goto free_all;
|
||||
}
|
||||
|
||||
ret = X509_NAME_add_entry_by_txt(x509_name,"CN", MBSTRING_ASC, (const unsigned char*)szCommon, -1, -1, 0);
|
||||
if (ret != 1){
|
||||
goto free_all;
|
||||
}
|
||||
|
||||
// 4. set public key of x509 req
|
||||
pKey = EVP_PKEY_new();
|
||||
EVP_PKEY_assign_RSA(pKey, r);
|
||||
r = nullptr; // will be free rsa when EVP_PKEY_free(pKey)
|
||||
|
||||
ret = X509_REQ_set_pubkey(x509_req, pKey);
|
||||
if (ret != 1){
|
||||
goto free_all;
|
||||
}
|
||||
|
||||
// 5. set sign key of x509 req
|
||||
ret = X509_REQ_sign(x509_req, pKey, EVP_sha1()); // return x509_req->signature->length
|
||||
if (ret <= 0){
|
||||
goto free_all;
|
||||
}
|
||||
|
||||
bp_csr = BIO_new_file(CsrPath.path().c_str(),"w");
|
||||
ret = PEM_write_bio_X509_REQ(bp_csr, x509_req);
|
||||
|
||||
// 6. free
|
||||
free_all:
|
||||
X509_REQ_free(x509_req);
|
||||
BIO_free_all(bp_csr);
|
||||
BIO_free_all(bp_public);
|
||||
BIO_free_all(bp_private);
|
||||
|
||||
EVP_PKEY_free(pKey);
|
||||
BN_free(bne);
|
||||
if(ret==1) {
|
||||
Results.CSR = FileToString(CsrPath.path());
|
||||
Results.PrivateKey = FileToString(PrivateKey.path());
|
||||
Results.PublicKey = FileToString(PubKey.path());
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool VerifyECKey(const std::string &key) {
|
||||
try {
|
||||
Poco::TemporaryFile F;
|
||||
|
||||
std::ofstream of(F.path().c_str(), std::ios_base::trunc | std::ios_base::out | std::ios_base::binary);
|
||||
of << key;
|
||||
of.close();
|
||||
|
||||
auto Key = Poco::SharedPtr<Poco::Crypto::ECKey>(
|
||||
new Poco::Crypto::ECKey("", F.path(),""));
|
||||
|
||||
return true;
|
||||
} catch (const Poco::Exception &E) {
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace OpenWifi::Utils
|
||||
|
||||
@@ -247,4 +247,17 @@ namespace OpenWifi::Utils {
|
||||
return count;
|
||||
}
|
||||
|
||||
struct CSRCreationParameters {
|
||||
std::string Country, Province, City,
|
||||
Organization, CommonName;
|
||||
int bits=2048;
|
||||
};
|
||||
|
||||
struct CSRCreationResults {
|
||||
std::string CSR, PublicKey, PrivateKey;
|
||||
};
|
||||
|
||||
bool CreateX509CSR(const CSRCreationParameters & Parameters, CSRCreationResults & Results);
|
||||
|
||||
bool VerifyECKey(const std::string &key);
|
||||
} // namespace OpenWifi::Utils
|
||||
|
||||
@@ -22,9 +22,6 @@
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
#define DBGLINE \
|
||||
{ std::cout << __LINE__ << std::endl; }
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
int RTTYS_server::Start() {
|
||||
|
||||
@@ -590,9 +590,7 @@ namespace OpenWifi {
|
||||
Poco::JSON::Object Message;
|
||||
Message.set("command", "device_deleted");
|
||||
Message.set("timestamp", Utils::Now());
|
||||
std::ostringstream StrPayload;
|
||||
Message.stringify(StrPayload);
|
||||
KafkaManager()->PostMessage(KafkaTopics::COMMAND, SerialNumber, std::make_shared<std::string>(StrPayload.str()));
|
||||
KafkaManager()->PostMessage(KafkaTopics::COMMAND, SerialNumber, Message);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user