forked from rdkcentral/rdkservices
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSecurityAgent.h
171 lines (144 loc) · 6.5 KB
/
SecurityAgent.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
* If not stated otherwise in this file or this component's LICENSE file the
* following copyright and licenses apply:
*
* Copyright 2020 RDK Management
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include "Module.h"
#include "AccessControlList.h"
#include <securityagent/IPCSecurityToken.h>
#include <interfaces/json/JsonData_SecurityAgent.h>
namespace WPEFramework {
namespace Plugin {
class SecurityAgent : public PluginHost::IAuthenticate,
public PluginHost::IPlugin,
public PluginHost::JSONRPC,
public PluginHost::IWeb {
private:
class TokenDispatcher : public RPC::Communicator {
public:
TokenDispatcher() = delete;
TokenDispatcher(const TokenDispatcher&) = delete;
TokenDispatcher& operator=(const TokenDispatcher&) = delete;
TokenDispatcher(
const Core::NodeId& source,
const std::string& proxyStubPath,
PluginHost::IAuthenticate* parentInterface,
const Core::ProxyType<RPC::InvokeServer>& engine
)
: RPC::Communicator(source, proxyStubPath, Core::ProxyType<Core::IIPCServer>(engine))
, _parentInterface(parentInterface)
{
if(_parentInterface != nullptr){
_parentInterface->AddRef();
}
engine->Announcements(Announcement());
Open(Core::infinite);
}
~TokenDispatcher() override
{
if(_parentInterface != nullptr){
_parentInterface->Release();
}
Close(Core::infinite);
}
private:
void* Aquire(const string&, const uint32_t interfaceId, const uint32_t versionId) override
{
void* result = nullptr;
if (((versionId == 1) || (versionId == static_cast<uint32_t>(~0))) && ((interfaceId == PluginHost::IAuthenticate::ID) || (interfaceId == Core::IUnknown::ID))) {
_parentInterface->AddRef();
TRACE(Trace::Information, ("SecurityAgent interface(IAuthenticate) aquired => %p", this));
result = _parentInterface;
}
return (result);
}
private:
PluginHost::IAuthenticate* _parentInterface;
};
class Config : public Core::JSON::Container {
private:
Config(const Config&) = delete;
Config& operator=(const Config&) = delete;
public:
Config()
: Core::JSON::Container()
, ACL(_T("acl.json"))
, Connector()
{
Add(_T("acl"), &ACL);
Add(_T("connector"), &Connector);
}
~Config()
{
}
public:
Core::JSON::String ACL;
Core::JSON::String Connector;
};
public:
SecurityAgent(const SecurityAgent&) = delete;
SecurityAgent& operator=(const SecurityAgent&) = delete;
SecurityAgent();
virtual ~SecurityAgent();
// Build QueryInterface implementation, specifying all possible interfaces to be returned.
BEGIN_INTERFACE_MAP(SecurityAgent)
INTERFACE_ENTRY(PluginHost::IPlugin)
INTERFACE_ENTRY(PluginHost::IWeb)
INTERFACE_ENTRY(PluginHost::IAuthenticate)
INTERFACE_ENTRY(PluginHost::IDispatcher)
END_INTERFACE_MAP
public:
// IPlugin methods
// -------------------------------------------------------------------------------------------------------
virtual const string Initialize(PluginHost::IShell* service) override;
virtual void Deinitialize(PluginHost::IShell* service) override;
virtual string Information() const override;
// IAuthenticate methods
// -------------------------------------------------------------------------------------------------------
virtual uint32_t CreateToken(const uint16_t length, const uint8_t buffer[], string& token);
virtual PluginHost::ISecurity* Officer(const string& token);
// IWeb methods
// -------------------------------------------------------------------------------------------------------
//! Whenever a request is received, it might carry some additional data in the body. This method allows
//! the plugin to attach a deserializable data object (ref counted) to be loaded with any potential found
//! in the body of the request.
//! @}
virtual void Inbound(Web::Request& request);
//! @{
//! ==================================== CALLED ON THREADPOOL THREAD ======================================
//! If everything is received correctly, the request is passed to us, on a thread from the thread pool, to
//! do our thing and to return the result in the response object. Here the actual specific module work,
//! based on a a request is handled.
//! @}
virtual Core::ProxyType<Web::Response> Process(const Web::Request& request);
private:
// JsonRPC methods
// -------------------------------------------------------------------------------------------------------
void RegisterAll();
void UnregisterAll();
#ifdef SECURITY_TESTING_MODE
uint32_t endpoint_createtoken(const JsonData::SecurityAgent::CreatetokenParamsData& params, JsonData::SecurityAgent::CreatetokenResultInfo& response);
#endif // DEBUG
uint32_t endpoint_validate(const JsonData::SecurityAgent::CreatetokenResultInfo& params, JsonData::SecurityAgent::ValidateResultData& response);
private:
AccessControlList _acl;
uint8_t _skipURL;
std::unique_ptr<TokenDispatcher> _dispatcher;
Core::ProxyType<RPC::InvokeServer> _engine;
};
} // namespace Plugin
} // namespace WPEFramework