// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once #include "Endpoint.hpp" #include "Service/Service.hpp" #include "backup/BackupEndpoint.hpp" #include "deviceInfo/DeviceInfoEndpoint.hpp" #include "update/UpdateEndpoint.hpp" #include "filesystem/FilesystemEndpoint.hpp" #include "factoryReset/FactoryResetEndpoint.hpp" #include "calllog/CalllogEndpoint.hpp" #include "contacts/ContactsEndpoint.hpp" #include "developerMode/DeveloperModeEndpoint.hpp" #include "messages/MessagesEndpoint.hpp" #include "restore/RestoreEndpoint.hpp" #include "update/UpdateEndpoint.hpp" #include #include "security/SecurityEndpoint.hpp" class EndpointFactory { public: virtual ~EndpointFactory() = default; virtual auto create(parserFSM::Context &context, sys::Service *ownerServicePtr) -> std::unique_ptr { LOG_DEBUG("Creating endpoint: %d", static_cast(context.getEndpoint())); switch (context.getEndpoint()) { case parserFSM::EndpointType::update: return std::make_unique(ownerServicePtr); case parserFSM::EndpointType::filesystemUpload: return FilesystemEndpoint::createInstance(ownerServicePtr); case parserFSM::EndpointType::backup: return std::make_unique(ownerServicePtr); case parserFSM::EndpointType::deviceInfo: return std::make_unique(ownerServicePtr); case parserFSM::EndpointType::restore: return std::make_unique(ownerServicePtr); case parserFSM::EndpointType::contacts: return std::make_unique(ownerServicePtr); case parserFSM::EndpointType::messages: return std::make_unique(ownerServicePtr); case parserFSM::EndpointType::factory: return std::make_unique(ownerServicePtr); case parserFSM::EndpointType::calllog: return std::make_unique(ownerServicePtr); #if ENABLE_DEVELOPER_MODE_ENDPOINT case parserFSM::EndpointType::developerMode: return std::make_unique(ownerServicePtr); #endif case parserFSM::EndpointType::bluetooth: return std::make_unique(ownerServicePtr); case parserFSM::EndpointType::usbSecurity: return std::make_unique(ownerServicePtr); default: return nullptr; } } }; class SecuredEndpointFactory : public EndpointFactory { static constexpr auto Whitelist = {parserFSM::EndpointType::developerMode, parserFSM::EndpointType::usbSecurity}; public: explicit SecuredEndpointFactory(EndpointSecurity security) : endpointSecurity(security) {} auto create(parserFSM::Context &context, sys::Service *ownerServicePtr) -> std::unique_ptr override { auto security = endpointSecurity; if (std::find(Whitelist.begin(), Whitelist.end(), context.getEndpoint()) != Whitelist.end()) { security = EndpointSecurity::Allow; } switch (security) { case EndpointSecurity::Allow: return EndpointFactory::create(context, ownerServicePtr); default: return std::make_unique(ownerServicePtr); } } private: EndpointSecurity endpointSecurity; };