• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef REMOTE_AUTH_CONTEXT_H
17 #define REMOTE_AUTH_CONTEXT_H
18 
19 #include <cstdint>
20 #include <memory>
21 #include <mutex>
22 
23 #include "authentication_impl.h"
24 #include "remote_executor_proxy.h"
25 #include "simple_auth_context.h"
26 
27 namespace OHOS {
28 namespace UserIam {
29 namespace UserAuth {
30 struct RemoteAuthContextParam {
31     AuthType authType;
32     std::string connectionName;
33     std::string collectorNetworkId;
34     std::vector<uint8_t> executorInfoMsg;
35 };
36 
37 class RemoteAuthContext : public SimpleAuthContext {
38 public:
39     RemoteAuthContext(uint64_t contextId, std::shared_ptr<Authentication> auth, RemoteAuthContextParam &param,
40         std::shared_ptr<ContextCallback> callback);
41     ~RemoteAuthContext() override;
42     ContextType GetContextType() const override;
43 
44     void SetExecutorInfoMsg(std::vector<uint8_t> msg);
45 
46     void OnMessage(const std::string &connectionName, const std::string &srcEndPoint,
47         const std::shared_ptr<Attributes> &request, std::shared_ptr<Attributes> &reply);
48     void OnConnectStatus(const std::string &connectionName, ConnectStatus connectStatus);
49 
50     void OnTimeOut();
51 
52 protected:
53     bool OnStart() override;
54 
55 #ifndef IAM_TEST_ENABLE
56 private:
57 #endif
58     bool StartAuth();
59     void StartAuthDelayed();
60     bool SetupConnection();
61     bool SendQueryExecutorInfoMsg();
62 
63     std::recursive_mutex mutex_;
64     int32_t authType_ = INVALID_AUTH_TYPE;
65     std::string connectionName_;
66     std::string collectorNetworkId_;
67     std::vector<uint8_t> executorInfoMsg_;
68 
69     bool needSetupConnection_ = false;
70     std::string endPointName_;
71     std::shared_ptr<RemoteExecutorProxy> remoteExecutorProxy_ = nullptr;
72     std::optional<uint32_t> cancelTimerId_ = std::nullopt;
73 };
74 } // namespace UserAuth
75 } // namespace UserIam
76 } // namespace OHOS
77 #endif // REMOTE_AUTH_CONTEXT_H