mirror of
https://gitee.com/openharmony/useriam_user_auth_framework
synced 2024-11-27 09:50:45 +00:00
fix debug
Signed-off-by: youliang_1314 <youliang4@huawei.com> Change-Id: I7ac7ae0fdd10c725890a17edaa4bb8ed6fce2986
This commit is contained in:
parent
4b7c2314b4
commit
9d6b9a454e
@ -48,7 +48,8 @@
|
||||
"//base/useriam/user_auth_framework/common/executors:userauth_executors",
|
||||
"//base/useriam/user_auth_framework/frameworks/js/napi/user_idm:useridm",
|
||||
"//base/useriam/user_auth_framework/frameworks/js/napi/user_auth:userauth_napi",
|
||||
"//base/useriam/user_auth_framework/frameworks/js/napi/user_auth:userauth"
|
||||
"//base/useriam/user_auth_framework/frameworks/js/napi/user_auth:userauth",
|
||||
"//base/useriam/user_auth_framework/frameworks/native/ipc:userauth_client_ipc"
|
||||
],
|
||||
"inner_kits": [
|
||||
{
|
||||
|
51
frameworks/native/ipc/BUILD.gn
Normal file
51
frameworks/native/ipc/BUILD.gn
Normal file
@ -0,0 +1,51 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# 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.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
|
||||
config("userauth_client_ipc_config") {
|
||||
include_dirs = [ "inc" ]
|
||||
}
|
||||
|
||||
ohos_source_set("userauth_client_ipc") {
|
||||
include_dirs = [
|
||||
"//base/useriam/user_auth_framework/interfaces/inner_api",
|
||||
"//base/useriam/user_auth_framework/common/utils",
|
||||
"//base/useriam/user_auth_framework/services/common_defines/interfaces",
|
||||
"//base/useriam/user_auth_framework/services/common_defines/types",
|
||||
"//base/useriam/user_auth_framework/services/core/inc",
|
||||
"inc",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"src/co_auth_proxy.cpp",
|
||||
"src/executor_callback_stub.cpp",
|
||||
"src/executor_messenger_proxy.cpp",
|
||||
"src/user_auth_callback_stub.cpp",
|
||||
"src/user_auth_proxy.cpp",
|
||||
"src/user_idm_callback_stub.cpp",
|
||||
"src/user_idm_proxy.cpp",
|
||||
"src/executor_messenger_client.cpp",
|
||||
]
|
||||
|
||||
configs = [ "//base/useriam/user_auth_framework/common:iam_log_config" ]
|
||||
public_configs = [ ":userauth_client_ipc_config" ]
|
||||
remove_configs = [ "//build/config/compiler:no_exceptions" ]
|
||||
|
||||
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"utils_base:utils",
|
||||
]
|
||||
}
|
41
frameworks/native/ipc/inc/co_auth_proxy.h
Normal file
41
frameworks/native/ipc/inc/co_auth_proxy.h
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef CO_AUTH_PROXY_H
|
||||
#define CO_AUTH_PROXY_H
|
||||
|
||||
#include "co_auth_interface.h"
|
||||
#include "iremote_proxy.h"
|
||||
#include "message_parcel.h"
|
||||
#include "nocopyable.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
class CoAuthProxy : public IRemoteProxy<CoAuthInterface>, public NoCopyable {
|
||||
public:
|
||||
explicit CoAuthProxy(const sptr<IRemoteObject> &impl);
|
||||
~CoAuthProxy() override = default;
|
||||
uint64_t ExecutorRegister(const ExecutorRegisterInfo &info, sptr<ExecutorCallbackInterface> &callback) override;
|
||||
|
||||
private:
|
||||
static inline BrokerDelegator<CoAuthProxy> delegator_;
|
||||
bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply);
|
||||
int32_t WriteExecutorInfo(const ExecutorRegisterInfo &info, MessageParcel &data);
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
#endif // CO_AUTH_PROXY_H
|
54
frameworks/native/ipc/inc/executor_callback_stub.h
Normal file
54
frameworks/native/ipc/inc/executor_callback_stub.h
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef EXECUTOR_CALLBACK_STUB_H
|
||||
#define EXECUTOR_CALLBACK_STUB_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "co_auth_client_callback.h"
|
||||
#include "executor_callback_interface.h"
|
||||
#include "iremote_stub.h"
|
||||
#include "message_parcel.h"
|
||||
#include "nocopyable.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
class ExecutorCallbackStub : public IRemoteStub<ExecutorCallbackInterface>, public NoCopyable {
|
||||
public:
|
||||
explicit ExecutorCallbackStub(const std::shared_ptr<ExecutorRegisterCallback> &impl);
|
||||
~ExecutorCallbackStub() override = default;
|
||||
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
|
||||
void OnMessengerReady(sptr<ExecutorMessengerInterface> &messenger, const std::vector<uint8_t> &publicKey,
|
||||
const std::vector<uint64_t> &templateIdList) override;
|
||||
int32_t OnBeginExecute(uint64_t scheduleId, const std::vector<uint8_t> &publicKey,
|
||||
const Attributes &command) override;
|
||||
int32_t OnEndExecute(uint64_t scheduleId, const Attributes &command) override;
|
||||
int32_t OnSetProperty(const Attributes &properties) override;
|
||||
int32_t OnGetProperty(const Attributes &condition, Attributes &values) override;
|
||||
|
||||
private:
|
||||
int32_t OnMessengerReadyStub(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t OnBeginExecuteStub(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t OnEndExecuteStub(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t OnSetPropertyStub(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t OnGetPropertyStub(MessageParcel &data, MessageParcel &reply);
|
||||
std::shared_ptr<ExecutorRegisterCallback> callback_ {nullptr};
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
#endif // EXECUTOR_CALLBACK_STUB_H
|
39
frameworks/native/ipc/inc/executor_messenger_client.h
Normal file
39
frameworks/native/ipc/inc/executor_messenger_client.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef EXECUTOR_MESSENGER_CLIENT_H
|
||||
#define EXECUTOR_MESSENGER_CLIENT_H
|
||||
|
||||
#include "co_auth_client_defines.h"
|
||||
#include "executor_messenger_interface.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
class ExecutorMessengerClient final : public ExecutorMessenger {
|
||||
public:
|
||||
ExecutorMessengerClient(const sptr<ExecutorMessengerInterface> &messenger);
|
||||
int32_t SendData(uint64_t scheduleId, uint64_t transNum, ExecutorRole srcRole, ExecutorRole dstRole,
|
||||
const std::shared_ptr<AuthMessage> &msg) override;
|
||||
int32_t Finish(uint64_t scheduleId, ExecutorRole srcRole, int32_t resultCode,
|
||||
const Attributes &finalResult) override;
|
||||
|
||||
private:
|
||||
sptr<ExecutorMessengerInterface> messenger_ {nullptr};
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
#endif // EXECUTOR_MESSENGER_CLIENT_H
|
43
frameworks/native/ipc/inc/executor_messenger_proxy.h
Normal file
43
frameworks/native/ipc/inc/executor_messenger_proxy.h
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef EXECUTOR_MESSENGER_PROXY_H
|
||||
#define EXECUTOR_MESSENGER_PROXY_H
|
||||
|
||||
#include "executor_messenger_interface.h"
|
||||
#include "iremote_proxy.h"
|
||||
#include "message_parcel.h"
|
||||
#include "nocopyable.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
class ExecutorMessengerProxy : public IRemoteProxy<ExecutorMessengerInterface>, public NoCopyable {
|
||||
public:
|
||||
explicit ExecutorMessengerProxy(const sptr<IRemoteObject> &impl);
|
||||
~ExecutorMessengerProxy() override = default;
|
||||
int32_t SendData(uint64_t scheduleId, uint64_t transNum, ExecutorRole srcRole, ExecutorRole dstRole,
|
||||
const std::vector<uint8_t> &msg) override;
|
||||
int32_t Finish(uint64_t scheduleId, ExecutorRole srcRole, ResultCode resultCode,
|
||||
const std::shared_ptr<Attributes> &finalResult) override;
|
||||
|
||||
private:
|
||||
static inline BrokerDelegator<ExecutorMessengerProxy> delegator_;
|
||||
bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply);
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
#endif // EXECUTOR_MESSENGER_PROXY_H
|
73
frameworks/native/ipc/inc/user_auth_callback_stub.h
Normal file
73
frameworks/native/ipc/inc/user_auth_callback_stub.h
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef USER_AUTH_CALLBACK_STUB_H
|
||||
#define USER_AUTH_CALLBACK_STUB_H
|
||||
|
||||
// #include "iam_hitrace_helper.h"
|
||||
#include "iremote_stub.h"
|
||||
#include "message_parcel.h"
|
||||
#include "nocopyable.h"
|
||||
#include "user_auth_callback_interface.h"
|
||||
#include "user_auth_client_callback.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
class UserAuthCallbackStub : public IRemoteStub<UserAuthCallbackInterface>, public NoCopyable {
|
||||
public:
|
||||
explicit UserAuthCallbackStub(const std::shared_ptr<AuthenticationCallback> &impl);
|
||||
explicit UserAuthCallbackStub(const std::shared_ptr<IdentificationCallback> &impl);
|
||||
~UserAuthCallbackStub() override = default;
|
||||
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
|
||||
void OnAcquireInfo(int32_t module, uint32_t acquireInfo, int32_t extraInfo) override;
|
||||
void OnAuthResult(int32_t result, const Attributes &extraInfo) override;
|
||||
void OnIdentifyResult(int32_t result, const Attributes &extraInfo) override;
|
||||
|
||||
private:
|
||||
int32_t OnAcquireInfoStub(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t OnAuthResultStub(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t OnIdentifyResultStub(MessageParcel &data, MessageParcel &reply);
|
||||
std::shared_ptr<AuthenticationCallback> authCallback_ {nullptr};
|
||||
std::shared_ptr<IdentificationCallback> identifyCallback_ {nullptr};
|
||||
};
|
||||
|
||||
class GetExecutorPropertyCallbackStub : public IRemoteStub<GetExecutorPropertyCallbackInterface>, public NoCopyable {
|
||||
public:
|
||||
explicit GetExecutorPropertyCallbackStub(const std::shared_ptr<GetPropCallback> &impl);
|
||||
~GetExecutorPropertyCallbackStub() override = default;
|
||||
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
|
||||
void OnGetExecutorPropertyResult(int32_t result, const Attributes &attributes) override;
|
||||
|
||||
private:
|
||||
int32_t OnGetExecutorPropertyResultStub(MessageParcel &data, MessageParcel &reply);
|
||||
std::shared_ptr<GetPropCallback> getPropCallback_ {nullptr};
|
||||
};
|
||||
|
||||
class SetExecutorPropertyCallbackStub : public IRemoteStub<SetExecutorPropertyCallbackInterface>, public NoCopyable {
|
||||
public:
|
||||
explicit SetExecutorPropertyCallbackStub(const std::shared_ptr<SetPropCallback> &impl);
|
||||
~SetExecutorPropertyCallbackStub() override = default;
|
||||
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
|
||||
void OnSetExecutorPropertyResult(int32_t result) override;
|
||||
|
||||
private:
|
||||
int32_t OnSetExecutorPropertyResultStub(MessageParcel &data, MessageParcel &reply);
|
||||
std::shared_ptr<SetPropCallback> setPropCallback_ {nullptr};
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
#endif // USER_AUTH_CALLBACK_STUB_H
|
51
frameworks/native/ipc/inc/user_auth_proxy.h
Normal file
51
frameworks/native/ipc/inc/user_auth_proxy.h
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef USER_AUTH_PROXY_H
|
||||
#define USER_AUTH_PROXY_H
|
||||
|
||||
#include "iremote_proxy.h"
|
||||
#include "message_parcel.h"
|
||||
#include "nocopyable.h"
|
||||
#include "user_auth_interface.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
class UserAuthProxy : public IRemoteProxy<UserAuthInterface>, public NoCopyable {
|
||||
public:
|
||||
explicit UserAuthProxy(const sptr<IRemoteObject> &object);
|
||||
~UserAuthProxy() override = default;
|
||||
int32_t GetAvailableStatus(AuthType authType, AuthTrustLevel authTrustLevel) override;
|
||||
void GetProperty(std::optional<int32_t> userId, AuthType authType,
|
||||
const std::vector<Attributes::AttributeKey> &keys,
|
||||
sptr<GetExecutorPropertyCallbackInterface> &callback) override;
|
||||
void SetProperty(std::optional<int32_t> userId, AuthType authType, const Attributes &attributes,
|
||||
sptr<SetExecutorPropertyCallbackInterface> &callback) override;
|
||||
uint64_t AuthUser(std::optional<int32_t> userId, const std::vector<uint8_t> &challenge, AuthType authType,
|
||||
AuthTrustLevel authTrustLevel, sptr<UserAuthCallbackInterface> &callback) override;
|
||||
uint64_t Identify(const std::vector<uint8_t> &challenge, AuthType authType,
|
||||
sptr<UserAuthCallbackInterface> &callback) override;
|
||||
int32_t CancelAuthOrIdentify(uint64_t contextId) override;
|
||||
int32_t GetVersion() override;
|
||||
|
||||
private:
|
||||
static inline BrokerDelegator<UserAuthProxy> delegator_;
|
||||
bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply);
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
#endif // USER_AUTH_PROXY_H
|
70
frameworks/native/ipc/inc/user_idm_callback_stub.h
Normal file
70
frameworks/native/ipc/inc/user_idm_callback_stub.h
Normal file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef USER_IDM_CALLBACK_STUB_H
|
||||
#define USER_IDM_CALLBACK_STUB_H
|
||||
|
||||
// #include "iam_hitrace_helper.h"
|
||||
#include "iremote_stub.h"
|
||||
#include "message_parcel.h"
|
||||
#include "nocopyable.h"
|
||||
#include "user_idm_callback_interface.h"
|
||||
#include "user_idm_client_callback.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
class IdmCallbackStub : public IRemoteStub<IdmCallbackInterface>, public NoCopyable {
|
||||
public:
|
||||
explicit IdmCallbackStub(const std::shared_ptr<UserIdmClientCallback> &impl);
|
||||
~IdmCallbackStub() override = default;
|
||||
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
|
||||
void OnResult(int32_t result, const Attributes &reqRet) override;
|
||||
void OnAcquireInfo(int32_t module, int32_t acquire, const Attributes &reqRet) override;
|
||||
|
||||
private:
|
||||
int32_t OnResultStub(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t OnAcquireInfoStub(MessageParcel &data, MessageParcel &reply);
|
||||
std::shared_ptr<UserIdmClientCallback> idmClientCallback_ {nullptr};
|
||||
};
|
||||
|
||||
class IdmGetCredInfoCallbackStub : public IRemoteStub<IdmGetCredInfoCallbackInterface>, public NoCopyable {
|
||||
public:
|
||||
explicit IdmGetCredInfoCallbackStub(const std::shared_ptr<GetCredentialInfoCallback> &impl);
|
||||
~IdmGetCredInfoCallbackStub() override = default;
|
||||
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
|
||||
void OnCredentialInfos(const std::vector<std::shared_ptr<CredentialInfo>> infoList,
|
||||
const std::optional<PinSubType> pinSubType) override;
|
||||
|
||||
private:
|
||||
int32_t OnCredentialInfosStub(MessageParcel &data, MessageParcel &reply);
|
||||
std::shared_ptr<GetCredentialInfoCallback> getCredInfoCallback_ {nullptr};
|
||||
};
|
||||
|
||||
class IdmGetSecureUserInfoCallbackStub : public IRemoteStub<IdmGetSecureUserInfoCallbackInterface>, public NoCopyable {
|
||||
public:
|
||||
explicit IdmGetSecureUserInfoCallbackStub(const std::shared_ptr<GetSecUserInfoCallback> &impl);
|
||||
~IdmGetSecureUserInfoCallbackStub() override = default;
|
||||
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
|
||||
void OnSecureUserInfo(const std::shared_ptr<SecureUserInfo> info) override;
|
||||
|
||||
private:
|
||||
int32_t OnSecureUserInfoStub(MessageParcel &data, MessageParcel &reply);
|
||||
std::shared_ptr<GetSecUserInfoCallback> getSecInfoCallback_ {nullptr};
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
#endif // USER_IDM_CALLBACK_STUB_H
|
55
frameworks/native/ipc/inc/user_idm_proxy.h
Normal file
55
frameworks/native/ipc/inc/user_idm_proxy.h
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef USER_IDM_PROXY_H
|
||||
#define USER_IDM_PROXY_H
|
||||
|
||||
#include "iremote_proxy.h"
|
||||
#include "message_parcel.h"
|
||||
#include "nocopyable.h"
|
||||
#include "user_idm_interface.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
class UserIdmProxy : public IRemoteProxy<UserIdmInterface>, public NoCopyable {
|
||||
public:
|
||||
explicit UserIdmProxy(const sptr<IRemoteObject> &object);
|
||||
~UserIdmProxy() override = default;
|
||||
int32_t OpenSession(std::optional<int32_t> userId, std::vector<uint8_t> &challenge) override;
|
||||
void CloseSession(std::optional<int32_t> userId) override;
|
||||
int32_t GetCredentialInfo(std::optional<int32_t> userId, AuthType authType,
|
||||
const sptr<IdmGetCredInfoCallbackInterface> &callback) override;
|
||||
int32_t GetSecInfo(std::optional<int32_t> userId,
|
||||
const sptr<IdmGetSecureUserInfoCallbackInterface> &callback) override;
|
||||
void AddCredential(std::optional<int32_t> userId, AuthType authType, PinSubType pinSubType,
|
||||
const std::vector<uint8_t> &token, const sptr<IdmCallbackInterface> &callback, bool isUpdate) override;
|
||||
void UpdateCredential(std::optional<int32_t> userId, AuthType authType, PinSubType pinSubType,
|
||||
const std::vector<uint8_t> &token, const sptr<IdmCallbackInterface> &callback) override;
|
||||
int32_t Cancel(std::optional<int32_t> userId, const std::optional<std::vector<uint8_t>> &challenge) override;
|
||||
int32_t EnforceDelUser(int32_t userId, const sptr<IdmCallbackInterface> &callback) override;
|
||||
void DelUser(std::optional<int32_t> userId, const std::vector<uint8_t> authToken,
|
||||
const sptr<IdmCallbackInterface> &callback) override;
|
||||
void DelCredential(std::optional<int32_t> userId, uint64_t credentialId,
|
||||
const std::vector<uint8_t> &authToken, const sptr<IdmCallbackInterface> &callback) override;
|
||||
|
||||
private:
|
||||
static inline BrokerDelegator<UserIdmProxy> delegator_;
|
||||
bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply);
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
#endif // USER_IDM_PROXY_H
|
116
frameworks/native/ipc/src/co_auth_proxy.cpp
Normal file
116
frameworks/native/ipc/src/co_auth_proxy.cpp
Normal file
@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "co_auth_proxy.h"
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
#include "iam_common_defines.h"
|
||||
#include "iam_logger.h"
|
||||
|
||||
#define LOG_LABEL UserIAM::Common::LABEL_AUTH_EXECUTOR_MGR_SDK
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
CoAuthProxy::CoAuthProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<CoAuthInterface>(impl)
|
||||
{
|
||||
}
|
||||
|
||||
int32_t CoAuthProxy::WriteExecutorInfo(const ExecutorRegisterInfo &info, MessageParcel &data)
|
||||
{
|
||||
if (!data.WriteUint32(info.authType)) {
|
||||
IAM_LOGE("failed to write authType");
|
||||
return FAIL;
|
||||
}
|
||||
if (!data.WriteUint32(info.executorRole)) {
|
||||
IAM_LOGE("failed to write executorRole");
|
||||
return FAIL;
|
||||
}
|
||||
if (!data.WriteUint32(info.executorSensorHint)) {
|
||||
IAM_LOGE("failed to write executorSensorHint");
|
||||
return FAIL;
|
||||
}
|
||||
if (!data.WriteUint32(info.executorMatcher)) {
|
||||
IAM_LOGE("failed to write executorMatcher");
|
||||
return FAIL;
|
||||
}
|
||||
if (!data.WriteUint32(info.esl)) {
|
||||
IAM_LOGE("failed to write esl");
|
||||
return FAIL;
|
||||
}
|
||||
if (!data.WriteUInt8Vector(info.publicKey)) {
|
||||
IAM_LOGE("failed to write publicKey");
|
||||
return FAIL;
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
uint64_t CoAuthProxy::ExecutorRegister(const ExecutorRegisterInfo &info, sptr<ExecutorCallbackInterface> &callback)
|
||||
{
|
||||
IAM_LOGI("start");
|
||||
const uint64_t BAD_CONTEXT_ID = 0;
|
||||
if (callback == nullptr) {
|
||||
IAM_LOGE("callback is nullptr");
|
||||
return BAD_CONTEXT_ID;
|
||||
}
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
|
||||
if (!data.WriteInterfaceToken(CoAuthProxy::GetDescriptor())) {
|
||||
IAM_LOGE("failed to write descriptor");
|
||||
return BAD_CONTEXT_ID;
|
||||
}
|
||||
if (WriteExecutorInfo(info, data) != SUCCESS) {
|
||||
IAM_LOGE("failed to write executor info");
|
||||
return BAD_CONTEXT_ID;
|
||||
}
|
||||
if (!data.WriteRemoteObject(callback->AsObject())) {
|
||||
IAM_LOGE("failed to write callback");
|
||||
return BAD_CONTEXT_ID;
|
||||
}
|
||||
|
||||
bool ret = SendRequest(CoAuthInterface::CO_AUTH_EXECUTOR_REGISTER, data, reply);
|
||||
if (!ret) {
|
||||
IAM_LOGE("failed to send request");
|
||||
return BAD_CONTEXT_ID;
|
||||
}
|
||||
uint64_t result = 0;
|
||||
if (!reply.ReadUint64(result)) {
|
||||
IAM_LOGE("failed to read result");
|
||||
return BAD_CONTEXT_ID;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool CoAuthProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
IAM_LOGI("code = %{public}u", code);
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
IAM_LOGE("failed to get remote");
|
||||
return false;
|
||||
}
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
int32_t result = remote->SendRequest(code, data, reply, option);
|
||||
if (result != OHOS::NO_ERROR) {
|
||||
IAM_LOGE("failed to send request, result = %{public}d", result);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
227
frameworks/native/ipc/src/executor_callback_stub.cpp
Normal file
227
frameworks/native/ipc/src/executor_callback_stub.cpp
Normal file
@ -0,0 +1,227 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "executor_callback_stub.h"
|
||||
|
||||
#include "executor_messenger_proxy.h"
|
||||
#include "executor_messenger_client.h"
|
||||
#include "iam_common_defines.h"
|
||||
#include "iam_logger.h"
|
||||
#include "iam_ptr.h"
|
||||
|
||||
#define LOG_LABEL UserIAM::Common::LABEL_AUTH_EXECUTOR_MGR_SDK
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
ExecutorCallbackStub::ExecutorCallbackStub(const std::shared_ptr<ExecutorRegisterCallback> &impl) : callback_(impl)
|
||||
{
|
||||
}
|
||||
|
||||
int32_t ExecutorCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
|
||||
MessageParcel &reply, MessageOption &option)
|
||||
{
|
||||
IAM_LOGD("cmd = %{public}u, flags = %{public}d", code, option.GetFlags());
|
||||
if (ExecutorCallbackStub::GetDescriptor() != data.ReadInterfaceToken()) {
|
||||
IAM_LOGE("descriptor is not matched");
|
||||
return FAIL;
|
||||
}
|
||||
switch (code) {
|
||||
case ExecutorCallbackInterface::ON_MESSENGER_READY:
|
||||
return OnMessengerReadyStub(data, reply);
|
||||
case ExecutorCallbackInterface::ON_BEGIN_EXECUTE:
|
||||
return OnBeginExecuteStub(data, reply);
|
||||
case ExecutorCallbackInterface::ON_END_EXECUTE:
|
||||
return OnEndExecuteStub(data, reply);
|
||||
case ExecutorCallbackInterface::ON_SET_PROPERTY:
|
||||
return OnSetPropertyStub(data, reply);
|
||||
case ExecutorCallbackInterface::ON_GET_PROPERTY:
|
||||
return OnGetPropertyStub(data, reply);
|
||||
default:
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t ExecutorCallbackStub::OnMessengerReadyStub(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
sptr<IRemoteObject> obj = data.ReadRemoteObject();
|
||||
if (obj == nullptr) {
|
||||
IAM_LOGE("failed to read remote object");
|
||||
return READ_PARCEL_ERROR;
|
||||
}
|
||||
sptr<ExecutorMessengerInterface> messenger = iface_cast<ExecutorMessengerProxy>(obj);
|
||||
if (messenger == nullptr) {
|
||||
IAM_LOGE("executor messenger is nullptr");
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> publicKey;
|
||||
std::vector<uint64_t> templateIds;
|
||||
|
||||
if (!data.ReadUInt8Vector(&publicKey)) {
|
||||
IAM_LOGE("failed to read publicKey");
|
||||
return READ_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.ReadUInt64Vector(&templateIds)) {
|
||||
IAM_LOGE("failed to read templateIds");
|
||||
return READ_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
OnMessengerReady(messenger, publicKey, templateIds);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ExecutorCallbackStub::OnBeginExecuteStub(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
uint64_t scheduleId;
|
||||
std::vector<uint8_t> publicKey;
|
||||
std::vector<uint8_t> buffer;
|
||||
|
||||
if (!data.ReadUint64(scheduleId)) {
|
||||
IAM_LOGE("failed to read scheduleId");
|
||||
return READ_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.ReadUInt8Vector(&publicKey)) {
|
||||
IAM_LOGE("failed to read publicKey");
|
||||
return READ_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.ReadUInt8Vector(&buffer)) {
|
||||
IAM_LOGE("failed to read command");
|
||||
return READ_PARCEL_ERROR;
|
||||
}
|
||||
Attributes commandAttrs(buffer);
|
||||
|
||||
int32_t result = OnBeginExecute(scheduleId, publicKey, commandAttrs);
|
||||
if (!reply.WriteInt32(result)) {
|
||||
IAM_LOGE("failed to write OnBeginExecute result");
|
||||
return WRITE_PARCEL_ERROR;
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ExecutorCallbackStub::OnEndExecuteStub(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
uint64_t scheduleId;
|
||||
std::vector<uint8_t> buffer;
|
||||
|
||||
if (!data.ReadUint64(scheduleId)) {
|
||||
IAM_LOGE("failed to read scheduleId");
|
||||
return READ_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.ReadUInt8Vector(&buffer)) {
|
||||
IAM_LOGE("failed to read command");
|
||||
return READ_PARCEL_ERROR;
|
||||
}
|
||||
Attributes consumerAttr(buffer);
|
||||
|
||||
int32_t result = OnEndExecute(scheduleId, consumerAttr);
|
||||
if (!reply.WriteInt32(result)) {
|
||||
IAM_LOGE("failed to write OnEndExecute result");
|
||||
return WRITE_PARCEL_ERROR;
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ExecutorCallbackStub::OnSetPropertyStub(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
std::vector<uint8_t> buffer;
|
||||
if (!data.ReadUInt8Vector(&buffer)) {
|
||||
IAM_LOGE("failed to read properties");
|
||||
return READ_PARCEL_ERROR;
|
||||
}
|
||||
Attributes properties(buffer);
|
||||
|
||||
int32_t result = OnSetProperty(properties);
|
||||
if (!reply.WriteInt32(result)) {
|
||||
IAM_LOGE("failed to write OnSetProperty result");
|
||||
return WRITE_PARCEL_ERROR;
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ExecutorCallbackStub::OnGetPropertyStub(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
std::vector<uint8_t> buffer;
|
||||
if (!data.ReadUInt8Vector(&buffer)) {
|
||||
IAM_LOGE("failed to read conditions");
|
||||
return READ_PARCEL_ERROR;
|
||||
}
|
||||
Attributes conditions(buffer);
|
||||
Attributes values;
|
||||
|
||||
int32_t result = OnGetProperty(conditions, values);
|
||||
if (!reply.WriteInt32(result)) {
|
||||
IAM_LOGE("failed to write OnGetProperty result");
|
||||
return WRITE_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> replyBuffer = values.Serialize();
|
||||
if (!reply.WriteUInt8Vector(replyBuffer)) {
|
||||
IAM_LOGE("failed to write replyBuffer");
|
||||
return WRITE_PARCEL_ERROR;
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
void ExecutorCallbackStub::OnMessengerReady(sptr<ExecutorMessengerInterface> &messenger,
|
||||
const std::vector<uint8_t> &publicKey, const std::vector<uint64_t> &templateIdList)
|
||||
{
|
||||
if (callback_ == nullptr) {
|
||||
IAM_LOGE("callback is nullptr");
|
||||
return;
|
||||
}
|
||||
auto tempMessenger = UserIAM::Common::MakeShared<ExecutorMessengerClient>(messenger);
|
||||
callback_->OnMessengerReady(tempMessenger, publicKey, templateIdList);
|
||||
}
|
||||
|
||||
int32_t ExecutorCallbackStub::OnBeginExecute(uint64_t scheduleId, const std::vector<uint8_t> &publicKey,
|
||||
const Attributes &command)
|
||||
{
|
||||
if (callback_ == nullptr) {
|
||||
IAM_LOGE("callback is nullptr");
|
||||
return FAIL;
|
||||
}
|
||||
return callback_->OnBeginExecute(scheduleId, publicKey, command);
|
||||
}
|
||||
|
||||
int32_t ExecutorCallbackStub::OnEndExecute(uint64_t scheduleId, const Attributes &command)
|
||||
{
|
||||
if (callback_ == nullptr) {
|
||||
IAM_LOGE("callback is nullptr");
|
||||
return FAIL;
|
||||
}
|
||||
return callback_->OnEndExecute(scheduleId, command);
|
||||
}
|
||||
|
||||
int32_t ExecutorCallbackStub::OnSetProperty(const Attributes &properties)
|
||||
{
|
||||
if (callback_ == nullptr) {
|
||||
IAM_LOGE("callback is nullptr");
|
||||
return FAIL;
|
||||
}
|
||||
return callback_->OnSetProperty(properties);
|
||||
}
|
||||
|
||||
int32_t ExecutorCallbackStub::OnGetProperty(const Attributes &condition, Attributes &values)
|
||||
{
|
||||
if (callback_ == nullptr) {
|
||||
IAM_LOGE("callback is nullptr");
|
||||
return FAIL;
|
||||
}
|
||||
return callback_->OnGetProperty(condition, values);
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
54
frameworks/native/ipc/src/executor_messenger_client.cpp
Normal file
54
frameworks/native/ipc/src/executor_messenger_client.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "executor_messenger_client.h"
|
||||
|
||||
#include "iam_logger.h"
|
||||
#include "iam_ptr.h"
|
||||
|
||||
#define LOG_LABEL UserIAM::Common::LABEL_AUTH_EXECUTOR_MGR_SDK
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
int32_t ExecutorMessengerClient::SendData(uint64_t scheduleId, uint64_t transNum, ExecutorRole srcRole, ExecutorRole dstRole,
|
||||
const std::shared_ptr<AuthMessage> &msg)
|
||||
{
|
||||
if (messenger_ == nullptr) {
|
||||
IAM_LOGE("messenger is nullptr");
|
||||
return FAIL;
|
||||
}
|
||||
std::vector<uint8_t> buffer;
|
||||
if (msg == nullptr) {
|
||||
IAM_LOGE("msg is nullptr");
|
||||
} else {
|
||||
AuthMessage::As(buffer);
|
||||
}
|
||||
return messenger_->SendData(scheduleId, transNum, srcRole, dstRole, buffer);
|
||||
}
|
||||
|
||||
int32_t ExecutorMessengerClient::Finish(uint64_t scheduleId, ExecutorRole srcRole, int32_t resultCode,
|
||||
const Attributes &finalResult)
|
||||
{
|
||||
if (messenger_ == nullptr) {
|
||||
IAM_LOGE("messenger is nullptr");
|
||||
return FAIL;
|
||||
}
|
||||
auto attr = UserIAM::Common::MakeShared<Attributes>(finalResult.Serialize());
|
||||
return messenger_->Finish(scheduleId, srcRole, static_cast<ResultCode>(resultCode), attr);
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
133
frameworks/native/ipc/src/executor_messenger_proxy.cpp
Normal file
133
frameworks/native/ipc/src/executor_messenger_proxy.cpp
Normal file
@ -0,0 +1,133 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "executor_messenger_proxy.h"
|
||||
|
||||
#include "iam_logger.h"
|
||||
|
||||
#define LOG_LABEL UserIAM::Common::LABEL_AUTH_EXECUTOR_MGR_SDK
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
ExecutorMessengerProxy::ExecutorMessengerProxy(const sptr<IRemoteObject> &impl)
|
||||
: IRemoteProxy<ExecutorMessengerInterface>(impl)
|
||||
{
|
||||
}
|
||||
|
||||
int32_t ExecutorMessengerProxy::SendData(uint64_t scheduleId, uint64_t transNum, ExecutorRole srcRole,
|
||||
ExecutorRole dstRole, const std::vector<uint8_t> &msg)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
|
||||
if (!data.WriteInterfaceToken(ExecutorMessengerProxy::GetDescriptor())) {
|
||||
IAM_LOGE("failed to write descriptor");
|
||||
return WRITE_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.WriteUint64(scheduleId)) {
|
||||
IAM_LOGE("failed to write scheduleId");
|
||||
return WRITE_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.WriteUint64(transNum)) {
|
||||
IAM_LOGE("failed to write transNum");
|
||||
return WRITE_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.WriteUint32(srcRole)) {
|
||||
IAM_LOGE("failed to write srcRole");
|
||||
return WRITE_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.WriteUint32(dstRole)) {
|
||||
IAM_LOGE("failed to write dstRole");
|
||||
return WRITE_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.WriteUInt8Vector(msg)) {
|
||||
IAM_LOGE("failed to write msg");
|
||||
return WRITE_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
bool ret = SendRequest(ExecutorMessengerInterface::CO_AUTH_SEND_DATA, data, reply);
|
||||
if (!ret) {
|
||||
IAM_LOGE("failed to send request");
|
||||
return FAIL;
|
||||
}
|
||||
int32_t result = 0;
|
||||
if (!reply.ReadInt32(result)) {
|
||||
IAM_LOGE("failed to read result");
|
||||
return READ_PARCEL_ERROR;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t ExecutorMessengerProxy::Finish(uint64_t scheduleId, ExecutorRole srcRole, ResultCode resultCode,
|
||||
const std::shared_ptr<Attributes> &finalResult)
|
||||
{
|
||||
if (finalResult == nullptr) {
|
||||
IAM_LOGE("finalResult is nullptr");
|
||||
return INVALID_PARAMETERS;
|
||||
}
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
|
||||
if (!data.WriteInterfaceToken(ExecutorMessengerProxy::GetDescriptor())) {
|
||||
IAM_LOGE("failed to write descriptor");
|
||||
return WRITE_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.WriteUint32(srcRole)) {
|
||||
IAM_LOGE("failed to write srcRole");
|
||||
return WRITE_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.WriteInt32(resultCode)) {
|
||||
IAM_LOGE("failed to write resultCode");
|
||||
return WRITE_PARCEL_ERROR;
|
||||
}
|
||||
std::vector<uint8_t> buffer = finalResult->Serialize();
|
||||
if (!data.WriteUInt8Vector(buffer)) {
|
||||
IAM_LOGE("failed to write finalResult");
|
||||
return WRITE_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
bool ret = SendRequest(ExecutorMessengerInterface::CO_AUTH_FINISH, data, reply);
|
||||
if (!ret) {
|
||||
IAM_LOGE("failed to send request");
|
||||
return FAIL;
|
||||
}
|
||||
int32_t result = 0;
|
||||
if (!reply.ReadInt32(result)) {
|
||||
IAM_LOGE("failed to read result");
|
||||
return READ_PARCEL_ERROR;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool ExecutorMessengerProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
IAM_LOGI("code = %{public}u", code);
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
IAM_LOGE("failed to get remote");
|
||||
return false;
|
||||
}
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
int32_t result = remote->SendRequest(code, data, reply, option);
|
||||
if (result != OHOS::NO_ERROR) {
|
||||
IAM_LOGE("failed to send request, result = %{public}d", result);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
239
frameworks/native/ipc/src/user_auth_callback_stub.cpp
Normal file
239
frameworks/native/ipc/src/user_auth_callback_stub.cpp
Normal file
@ -0,0 +1,239 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "user_auth_callback_stub.h"
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
#include "iam_logger.h"
|
||||
#include "iam_ptr.h"
|
||||
#include "user_auth_interface.h"
|
||||
|
||||
#define LOG_LABEL UserIAM::Common::LABEL_USER_AUTH_SDK
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
UserAuthCallbackStub::UserAuthCallbackStub(const std::shared_ptr<AuthenticationCallback> &impl) : authCallback_(impl)
|
||||
{
|
||||
}
|
||||
|
||||
UserAuthCallbackStub::UserAuthCallbackStub(const std::shared_ptr<IdentificationCallback> &impl) : identifyCallback_(impl)
|
||||
{
|
||||
}
|
||||
|
||||
int32_t UserAuthCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option)
|
||||
{
|
||||
IAM_LOGD("cmd = %{public}u, flags = %{public}d", code, option.GetFlags());
|
||||
if (UserAuthCallbackStub::GetDescriptor() != data.ReadInterfaceToken()) {
|
||||
IAM_LOGE("descriptor is not matched");
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
switch (code) {
|
||||
case UserAuthInterface::USER_AUTH_ACQUIRE_INFO:
|
||||
return OnAcquireInfoStub(data, reply);
|
||||
case UserAuthInterface::USER_AUTH_ON_RESULT:
|
||||
return OnAuthResultStub(data, reply);
|
||||
case UserAuthInterface::USER_AUTH_ON_IDENTIFY_RESULT:
|
||||
return OnIdentifyResultStub(data, reply);
|
||||
default:
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t UserAuthCallbackStub::OnAcquireInfoStub(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
int32_t module;
|
||||
uint32_t acquireInfo;
|
||||
std::vector<uint8_t> buffer;
|
||||
|
||||
if (!data.ReadInt32(module)) {
|
||||
IAM_LOGE("failed to read module");
|
||||
return READ_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.ReadUint32(acquireInfo)) {
|
||||
IAM_LOGE("failed to read acquireInfo");
|
||||
return READ_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.ReadUInt8Vector(&buffer)) {
|
||||
IAM_LOGE("failed to read buffer");
|
||||
return READ_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
// Attributes extraInfo(buffer);
|
||||
OnAcquireInfo(module, acquireInfo, 0);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
int32_t UserAuthCallbackStub::OnAuthResultStub(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
int32_t result;
|
||||
std::vector<uint8_t> buffer;
|
||||
|
||||
if (!data.ReadInt32(result)) {
|
||||
IAM_LOGE("failed to read result");
|
||||
return READ_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.ReadUInt8Vector(&buffer)) {
|
||||
IAM_LOGE("failed to read buffer");
|
||||
return READ_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
Attributes extraInfo(buffer);
|
||||
OnAuthResult(result, extraInfo);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
int32_t UserAuthCallbackStub::OnIdentifyResultStub(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
int32_t result;
|
||||
std::vector<uint8_t> buffer;
|
||||
|
||||
if (!data.ReadInt32(result)) {
|
||||
IAM_LOGE("failed to read result");
|
||||
return READ_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.ReadUInt8Vector(&buffer)) {
|
||||
IAM_LOGE("failed to read buffer");
|
||||
return READ_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
Attributes extraInfo(buffer);
|
||||
OnIdentifyResult(result, extraInfo);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
void UserAuthCallbackStub::OnAcquireInfo(int32_t module, uint32_t acquireInfo, int32_t extraInfo)
|
||||
{
|
||||
if (authCallback_ == nullptr) {
|
||||
IAM_LOGE("auth callback is nullptr");
|
||||
return;
|
||||
}
|
||||
Attributes attr;
|
||||
authCallback_->OnAcquireInfo(module, acquireInfo, attr);
|
||||
}
|
||||
|
||||
void UserAuthCallbackStub::OnAuthResult(int32_t result, const Attributes &extraInfo)
|
||||
{
|
||||
if (authCallback_ == nullptr) {
|
||||
IAM_LOGE("auth callback is nullptr");
|
||||
return;
|
||||
}
|
||||
authCallback_->OnResult(result, extraInfo);
|
||||
}
|
||||
|
||||
void UserAuthCallbackStub::OnIdentifyResult(int32_t result, const Attributes &extraInfo)
|
||||
{
|
||||
if (identifyCallback_ == nullptr) {
|
||||
IAM_LOGE("identify callback is nullptr");
|
||||
return;
|
||||
}
|
||||
identifyCallback_->OnResult(result, extraInfo);
|
||||
}
|
||||
|
||||
GetExecutorPropertyCallbackStub::GetExecutorPropertyCallbackStub(const std::shared_ptr<GetPropCallback> &impl)
|
||||
: getPropCallback_(impl)
|
||||
{
|
||||
}
|
||||
|
||||
int32_t GetExecutorPropertyCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option)
|
||||
{
|
||||
IAM_LOGD("cmd = %{public}u, flags = %{public}d", code, option.GetFlags());
|
||||
if (GetExecutorPropertyCallbackStub::GetDescriptor() != data.ReadInterfaceToken()) {
|
||||
IAM_LOGE("descriptor is not matched");
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
if (code == UserAuthInterface::USER_AUTH_GET_EX_PROP) {
|
||||
return OnGetExecutorPropertyResultStub(data, reply);
|
||||
}
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
|
||||
int32_t GetExecutorPropertyCallbackStub::OnGetExecutorPropertyResultStub(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
int32_t result;
|
||||
std::vector<uint8_t> buffer;
|
||||
|
||||
if (!data.ReadInt32(result)) {
|
||||
IAM_LOGE("failed to read result");
|
||||
return READ_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.ReadUInt8Vector(&buffer)) {
|
||||
IAM_LOGE("failed to read buffer");
|
||||
return READ_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
Attributes attr(buffer);
|
||||
OnGetExecutorPropertyResult(result, attr);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
void GetExecutorPropertyCallbackStub::OnGetExecutorPropertyResult(int32_t result, const Attributes &attributes)
|
||||
{
|
||||
if (getPropCallback_ == nullptr) {
|
||||
IAM_LOGE("get prop callback is nullptr");
|
||||
return;
|
||||
}
|
||||
getPropCallback_->OnResult(result, attributes);
|
||||
}
|
||||
|
||||
SetExecutorPropertyCallbackStub::SetExecutorPropertyCallbackStub(const std::shared_ptr<SetPropCallback> &impl)
|
||||
: setPropCallback_(impl)
|
||||
{
|
||||
}
|
||||
|
||||
int32_t SetExecutorPropertyCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option)
|
||||
{
|
||||
IAM_LOGD("cmd = %{public}u, flags = %{public}d", code, option.GetFlags());
|
||||
if (SetExecutorPropertyCallbackStub::GetDescriptor() != data.ReadInterfaceToken()) {
|
||||
IAM_LOGE("descriptor is not matched");
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
if (code == UserAuthInterface::USER_AUTH_SET_EX_PROP) {
|
||||
return OnSetExecutorPropertyResultStub(data, reply);
|
||||
}
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
|
||||
int32_t SetExecutorPropertyCallbackStub::OnSetExecutorPropertyResultStub(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
int32_t result;
|
||||
|
||||
if (!data.ReadInt32(result)) {
|
||||
IAM_LOGE("failed to read result");
|
||||
return READ_PARCEL_ERROR;
|
||||
}
|
||||
OnSetExecutorPropertyResult(result);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
void SetExecutorPropertyCallbackStub::OnSetExecutorPropertyResult(int32_t result)
|
||||
{
|
||||
if (setPropCallback_ == nullptr) {
|
||||
IAM_LOGE("set prop callback is nullptr");
|
||||
return;
|
||||
}
|
||||
Attributes attr;
|
||||
setPropCallback_->OnResult(result, attr);
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
296
frameworks/native/ipc/src/user_auth_proxy.cpp
Normal file
296
frameworks/native/ipc/src/user_auth_proxy.cpp
Normal file
@ -0,0 +1,296 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "user_auth_proxy.h"
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
#include "iam_logger.h"
|
||||
|
||||
#define LOG_LABEL UserIAM::Common::LABEL_USER_AUTH_SDK
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
namespace {
|
||||
const uint64_t BAD_CONTEXT_ID = 0;
|
||||
} // namespace
|
||||
|
||||
UserAuthProxy::UserAuthProxy(const sptr<IRemoteObject> &object) : IRemoteProxy<UserAuthInterface>(object)
|
||||
{
|
||||
}
|
||||
|
||||
int32_t UserAuthProxy::GetAvailableStatus(AuthType authType, AuthTrustLevel authTrustLevel)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
|
||||
if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) {
|
||||
IAM_LOGE("failed to write descriptor");
|
||||
return WRITE_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.WriteUint32(authType)) {
|
||||
IAM_LOGE("failed to write authType");
|
||||
return WRITE_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.WriteUint32(authTrustLevel)) {
|
||||
IAM_LOGE("failed to write authTrustLevel");
|
||||
return WRITE_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
bool ret = SendRequest(UserAuthInterface::USER_AUTH_GET_AVAILABLE_STATUS, data, reply);
|
||||
if (!ret) {
|
||||
return FAIL;
|
||||
}
|
||||
int32_t result = SUCCESS;
|
||||
if (!reply.ReadInt32(result)) {
|
||||
IAM_LOGE("failed to read result");
|
||||
return READ_PARCEL_ERROR;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void UserAuthProxy::GetProperty(std::optional<int32_t> userId, AuthType authType,
|
||||
const std::vector<Attributes::AttributeKey> &keys, sptr<GetExecutorPropertyCallbackInterface> &callback)
|
||||
{
|
||||
if (callback == nullptr) {
|
||||
IAM_LOGE("callback is nullptr");
|
||||
return;
|
||||
}
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
|
||||
std::vector<uint32_t> attrKeys;
|
||||
for (const auto &key : keys) {
|
||||
attrKeys.push_back(static_cast<uint32_t>(key));
|
||||
}
|
||||
|
||||
if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) {
|
||||
IAM_LOGE("failed to write descriptor");
|
||||
return;
|
||||
}
|
||||
if (userId.has_value() && !data.WriteInt32(userId.value())) {
|
||||
IAM_LOGE("failed to write userId");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteUint32(authType)) {
|
||||
IAM_LOGE("failed to write authType");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteUInt32Vector(attrKeys)) {
|
||||
IAM_LOGE("failed to write keys");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteRemoteObject(callback->AsObject())) {
|
||||
IAM_LOGE("failed to write callback");
|
||||
return;
|
||||
}
|
||||
|
||||
bool ret = SendRequest(userId.has_value() ? UserAuthInterface::USER_AUTH_GET_PROPERTY_BY_ID :
|
||||
UserAuthInterface::USER_AUTH_GET_PROPERTY, data, reply);
|
||||
if (!ret) {
|
||||
Attributes attr;
|
||||
callback->OnGetExecutorPropertyResult(FAIL, attr);
|
||||
}
|
||||
}
|
||||
|
||||
void UserAuthProxy::SetProperty(std::optional<int32_t> userId, AuthType authType, const Attributes &attributes,
|
||||
sptr<SetExecutorPropertyCallbackInterface> &callback)
|
||||
{
|
||||
if (callback == nullptr) {
|
||||
IAM_LOGE("callback is nullptr");
|
||||
return;
|
||||
}
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
|
||||
if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) {
|
||||
IAM_LOGE("failed to write descriptor");
|
||||
return;
|
||||
}
|
||||
if (userId.has_value() && !data.WriteInt32(userId.value())) {
|
||||
IAM_LOGE("failed to write userId");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteUint32(authType)) {
|
||||
IAM_LOGE("failed to write authType");
|
||||
return;
|
||||
}
|
||||
auto buffer = attributes.Serialize();
|
||||
if (!data.WriteUInt8Vector(buffer)) {
|
||||
IAM_LOGE("failed to write attributes");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteRemoteObject(callback->AsObject())) {
|
||||
IAM_LOGE("failed to write callback");
|
||||
return;
|
||||
}
|
||||
|
||||
bool ret = SendRequest(UserAuthInterface::USER_AUTH_SET_PROPERTY, data, reply);
|
||||
if (!ret) {
|
||||
callback->OnSetExecutorPropertyResult(FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t UserAuthProxy::AuthUser(std::optional<int32_t> userId, const std::vector<uint8_t> &challenge,
|
||||
AuthType authType, AuthTrustLevel authTrustLevel, sptr<UserAuthCallbackInterface> &callback)
|
||||
{
|
||||
if (callback == nullptr) {
|
||||
IAM_LOGE("callback is nullptr");
|
||||
return BAD_CONTEXT_ID;
|
||||
}
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
|
||||
if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) {
|
||||
IAM_LOGE("failed to write descriptor");
|
||||
return BAD_CONTEXT_ID;
|
||||
}
|
||||
if (userId.has_value() && !data.WriteInt32(userId.value())) {
|
||||
IAM_LOGE("failed to write userId");
|
||||
return BAD_CONTEXT_ID;
|
||||
}
|
||||
if (!data.WriteUInt8Vector(challenge)) {
|
||||
IAM_LOGE("failed to write challenge");
|
||||
return BAD_CONTEXT_ID;
|
||||
}
|
||||
if (!data.WriteUint32(authType)) {
|
||||
IAM_LOGE("failed to write authType");
|
||||
return BAD_CONTEXT_ID;
|
||||
}
|
||||
if (!data.WriteUint32(authTrustLevel)) {
|
||||
IAM_LOGE("failed to write authTrustLevel");
|
||||
return BAD_CONTEXT_ID;
|
||||
}
|
||||
if (!data.WriteRemoteObject(callback->AsObject())) {
|
||||
IAM_LOGE("failed to write callback");
|
||||
return BAD_CONTEXT_ID;
|
||||
}
|
||||
|
||||
bool ret = SendRequest(userId.has_value() ? UserAuthInterface::USER_AUTH_AUTH_USER :
|
||||
UserAuthInterface::USER_AUTH_AUTH, data, reply);
|
||||
if (!ret) {
|
||||
return BAD_CONTEXT_ID;
|
||||
}
|
||||
uint64_t result = BAD_CONTEXT_ID;
|
||||
if (!reply.ReadUint64(result)) {
|
||||
IAM_LOGE("failed to read result");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
uint64_t UserAuthProxy::Identify(const std::vector<uint8_t> &challenge, AuthType authType,
|
||||
sptr<UserAuthCallbackInterface> &callback)
|
||||
{
|
||||
if (callback == nullptr) {
|
||||
IAM_LOGE("callback is nullptr");
|
||||
return BAD_CONTEXT_ID;
|
||||
}
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
|
||||
if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) {
|
||||
IAM_LOGE("failed to write descriptor");
|
||||
return BAD_CONTEXT_ID;
|
||||
}
|
||||
if (!data.WriteUInt8Vector(challenge)) {
|
||||
IAM_LOGE("failed to write challenge");
|
||||
return BAD_CONTEXT_ID;
|
||||
}
|
||||
if (!data.WriteUint32(authType)) {
|
||||
IAM_LOGE("failed to write authType");
|
||||
return BAD_CONTEXT_ID;
|
||||
}
|
||||
if (!data.WriteRemoteObject(callback->AsObject())) {
|
||||
IAM_LOGE("failed to write callback");
|
||||
return BAD_CONTEXT_ID;
|
||||
}
|
||||
|
||||
bool ret = SendRequest(UserAuthInterface::USER_AUTH_IDENTIFY, data, reply);
|
||||
if (!ret) {
|
||||
return BAD_CONTEXT_ID;
|
||||
}
|
||||
uint64_t result = BAD_CONTEXT_ID;
|
||||
if (!reply.ReadUint64(result)) {
|
||||
IAM_LOGE("failed to read result");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t UserAuthProxy::CancelAuthOrIdentify(uint64_t contextId)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
|
||||
if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) {
|
||||
IAM_LOGE("failed to write descriptor");
|
||||
return FAIL;
|
||||
}
|
||||
if (!data.WriteUint64(contextId)) {
|
||||
IAM_LOGE("failed to write contextId");
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
bool ret = SendRequest(UserAuthInterface::USER_AUTH_CANCEL_AUTH, data, reply);
|
||||
if (!ret) {
|
||||
return FAIL;
|
||||
}
|
||||
int32_t result = FAIL;
|
||||
if (!reply.ReadInt32(result)) {
|
||||
IAM_LOGE("failed to read result");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t UserAuthProxy::GetVersion()
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
|
||||
if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) {
|
||||
IAM_LOGE("failed to write descriptor");
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
bool ret = SendRequest(UserAuthInterface::USER_AUTH_GET_VERSION, data, reply);
|
||||
if (!ret) {
|
||||
return FAIL;
|
||||
}
|
||||
int32_t result = FAIL;
|
||||
if (!reply.ReadInt32(result)) {
|
||||
IAM_LOGE("failed to read result");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool UserAuthProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
IAM_LOGI("code = %{public}u", code);
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
IAM_LOGE("failed to get remote");
|
||||
return false;
|
||||
}
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
int32_t result = remote->SendRequest(code, data, reply, option);
|
||||
if (result != OHOS::NO_ERROR) {
|
||||
IAM_LOGE("failed to send request, result = %{public}d", result);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
230
frameworks/native/ipc/src/user_idm_callback_stub.cpp
Normal file
230
frameworks/native/ipc/src/user_idm_callback_stub.cpp
Normal file
@ -0,0 +1,230 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "user_idm_callback_stub.h"
|
||||
|
||||
#include "iam_logger.h"
|
||||
#include "iam_ptr.h"
|
||||
|
||||
#define LOG_LABEL UserIAM::Common::LABEL_USER_IDM_SDK
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
IdmCallbackStub::IdmCallbackStub(const std::shared_ptr<UserIdmClientCallback> &impl) : idmClientCallback_(impl)
|
||||
{
|
||||
}
|
||||
|
||||
int32_t IdmCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option)
|
||||
{
|
||||
IAM_LOGD("cmd = %{public}u, flags = %{public}d", code, option.GetFlags());
|
||||
if (IdmCallbackStub::GetDescriptor() != data.ReadInterfaceToken()) {
|
||||
IAM_LOGE("descriptor is not matched");
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
switch (code) {
|
||||
case IdmCallbackInterface::IDM_CALLBACK_ON_RESULT:
|
||||
return OnResultStub(data, reply);
|
||||
case IdmCallbackInterface::IDM_CALLBACK_ON_ACQUIRE_INFO:
|
||||
return OnAcquireInfoStub(data, reply);
|
||||
default:
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t IdmCallbackStub::OnResultStub(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
int32_t result;
|
||||
std::vector<uint8_t> buffer;
|
||||
|
||||
if (!data.ReadInt32(result)) {
|
||||
IAM_LOGE("failed to read result");
|
||||
return READ_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.ReadUInt8Vector(&buffer)) {
|
||||
IAM_LOGE("failed to read buffer");
|
||||
return READ_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
Attributes extraInfo(buffer);
|
||||
OnResult(result, extraInfo);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
int32_t IdmCallbackStub::OnAcquireInfoStub(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
int32_t module;
|
||||
int32_t acquireInfo;
|
||||
std::vector<uint8_t> buffer;
|
||||
|
||||
if (!data.ReadInt32(module)) {
|
||||
IAM_LOGE("failed to read module");
|
||||
return READ_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.ReadInt32(acquireInfo)) {
|
||||
IAM_LOGE("failed to read acquireInfo");
|
||||
return READ_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.ReadUInt8Vector(&buffer)) {
|
||||
IAM_LOGE("failed to read buffer");
|
||||
return READ_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
Attributes extraInfo(buffer);
|
||||
OnAcquireInfo(module, acquireInfo, extraInfo);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
void IdmCallbackStub::OnResult(int32_t result, const Attributes &reqRet)
|
||||
{
|
||||
if (idmClientCallback_ == nullptr) {
|
||||
IAM_LOGE("idm client callback is nullptr");
|
||||
return;
|
||||
}
|
||||
idmClientCallback_->OnResult(result, reqRet);
|
||||
}
|
||||
|
||||
void IdmCallbackStub::OnAcquireInfo(int32_t module, int32_t acquire, const Attributes &reqRet)
|
||||
{
|
||||
if (idmClientCallback_ == nullptr) {
|
||||
IAM_LOGE("idm client callback is nullptr");
|
||||
return;
|
||||
}
|
||||
idmClientCallback_->OnAcquireInfo(module, static_cast<uint32_t>(acquire), reqRet);
|
||||
}
|
||||
|
||||
IdmGetCredInfoCallbackStub::IdmGetCredInfoCallbackStub(
|
||||
const std::shared_ptr<GetCredentialInfoCallback> &impl) : getCredInfoCallback_(impl)
|
||||
{
|
||||
}
|
||||
|
||||
int32_t IdmGetCredInfoCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option)
|
||||
{
|
||||
IAM_LOGD("cmd = %{public}u, flags = %{public}d", code, option.GetFlags());
|
||||
if (IdmGetCredInfoCallbackStub::GetDescriptor() != data.ReadInterfaceToken()) {
|
||||
IAM_LOGE("descriptor is not matched");
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
if (code == IdmGetCredInfoCallbackInterface::ON_GET_INFO) {
|
||||
return OnCredentialInfosStub(data, reply);
|
||||
}
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
|
||||
int32_t IdmGetCredInfoCallbackStub::OnCredentialInfosStub(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
if (getCredInfoCallback_ == nullptr) {
|
||||
IAM_LOGE("idm client callback is nullptr");
|
||||
return FAIL;
|
||||
}
|
||||
uint32_t vectorSize = 0;
|
||||
std::vector<UserAuth::CredentialInfo> credInfos;
|
||||
if (!data.ReadUint32(vectorSize)) {
|
||||
IAM_LOGE("read size fail");
|
||||
getCredInfoCallback_->OnCredentialInfo(credInfos);
|
||||
return READ_PARCEL_ERROR;
|
||||
}
|
||||
for (uint32_t i = 0; i < vectorSize; ++i) {
|
||||
UserAuth::CredentialInfo info = {};
|
||||
if (!data.ReadUint64(info.credentialId)) {
|
||||
IAM_LOGE("failed to read credentialId");
|
||||
getCredInfoCallback_->OnCredentialInfo(credInfos);
|
||||
return READ_PARCEL_ERROR;
|
||||
}
|
||||
uint32_t authType = 0;
|
||||
if (!data.ReadUint32(authType)) {
|
||||
IAM_LOGE("failed to read authType");
|
||||
getCredInfoCallback_->OnCredentialInfo(credInfos);
|
||||
return READ_PARCEL_ERROR;
|
||||
}
|
||||
info.authType = static_cast<AuthType>(authType);
|
||||
uint64_t pinSubType = 0;
|
||||
if (!data.ReadUint64(pinSubType)) {
|
||||
IAM_LOGE("failed to read pinSubType");
|
||||
getCredInfoCallback_->OnCredentialInfo(credInfos);
|
||||
return READ_PARCEL_ERROR;
|
||||
}
|
||||
info.pinType = static_cast<PinSubType>(pinSubType);
|
||||
if (!data.ReadUint64(info.templateId)) {
|
||||
IAM_LOGE("failed to read templateId");
|
||||
getCredInfoCallback_->OnCredentialInfo(credInfos);
|
||||
return READ_PARCEL_ERROR;
|
||||
}
|
||||
credInfos.push_back(info);
|
||||
}
|
||||
|
||||
getCredInfoCallback_->OnCredentialInfo(credInfos);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
void IdmGetCredInfoCallbackStub::OnCredentialInfos(const std::vector<std::shared_ptr<CredentialInfo>> infoList,
|
||||
const std::optional<PinSubType> pinSubType)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
IdmGetSecureUserInfoCallbackStub::IdmGetSecureUserInfoCallbackStub(const std::shared_ptr<GetSecUserInfoCallback> &impl)
|
||||
: getSecInfoCallback_(impl)
|
||||
{
|
||||
}
|
||||
|
||||
int32_t IdmGetSecureUserInfoCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option)
|
||||
{
|
||||
IAM_LOGD("cmd = %{public}u, flags = %{public}d", code, option.GetFlags());
|
||||
if (IdmGetSecureUserInfoCallbackStub::GetDescriptor() != data.ReadInterfaceToken()) {
|
||||
IAM_LOGE("descriptor is not matched");
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
if (code == IdmGetSecureUserInfoCallbackInterface::ON_GET_SEC_INFO) {
|
||||
return OnSecureUserInfoStub(data, reply);
|
||||
}
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
|
||||
int32_t IdmGetSecureUserInfoCallbackStub::OnSecureUserInfoStub(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
SecUserInfo info = {};
|
||||
uint32_t enrolledInfoLen;
|
||||
|
||||
if (!data.ReadUint64(info.secureUid)) {
|
||||
IAM_LOGE("failed to read secureUid");
|
||||
return READ_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.ReadUint32(enrolledInfoLen)) {
|
||||
IAM_LOGE("failed to read enrolledInfoLen");
|
||||
return READ_PARCEL_ERROR;
|
||||
}
|
||||
// 调用OnSecureUserInfo(), 参数不一致
|
||||
if (getSecInfoCallback_ == nullptr) {
|
||||
IAM_LOGE("get secure info callback is nullptr");
|
||||
return FAIL;
|
||||
}
|
||||
getSecInfoCallback_->OnSecUserInfo(info);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
void IdmGetSecureUserInfoCallbackStub::OnSecureUserInfo(const std::shared_ptr<SecureUserInfo> info)
|
||||
{
|
||||
return;
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
380
frameworks/native/ipc/src/user_idm_proxy.cpp
Normal file
380
frameworks/native/ipc/src/user_idm_proxy.cpp
Normal file
@ -0,0 +1,380 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "user_idm_proxy.h"
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
#include "iam_logger.h"
|
||||
|
||||
#define LOG_LABEL UserIAM::Common::LABEL_USER_IDM_SDK
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
UserIdmProxy::UserIdmProxy(const sptr<IRemoteObject> &object) : IRemoteProxy<UserIdmInterface>(object)
|
||||
{
|
||||
}
|
||||
|
||||
int32_t UserIdmProxy::OpenSession(std::optional<int32_t> userId, std::vector<uint8_t> &challenge)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
|
||||
if (!data.WriteInterfaceToken(UserIdmProxy::GetDescriptor())) {
|
||||
IAM_LOGE("failed to write descriptor");
|
||||
return FAIL;
|
||||
}
|
||||
if (userId.has_value() && !data.WriteInt32(userId.value())) {
|
||||
IAM_LOGE("failed to write userId");
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
bool ret = SendRequest(userId.has_value() ? UserIdmInterface::USER_IDM_OPEN_SESSION_BY_ID :
|
||||
UserIdmInterface::USER_IDM_OPEN_SESSION, data, reply);
|
||||
if (!ret) {
|
||||
return FAIL;
|
||||
}
|
||||
if (!reply.ReadUInt8Vector(&challenge)) {
|
||||
IAM_LOGE("failed to read challenge");
|
||||
return FAIL;
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
void UserIdmProxy::CloseSession(std::optional<int32_t> userId)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
|
||||
if (!data.WriteInterfaceToken(UserIdmProxy::GetDescriptor())) {
|
||||
IAM_LOGE("failed to write descriptor");
|
||||
return;
|
||||
}
|
||||
if (userId.has_value() && !data.WriteInt32(userId.value())) {
|
||||
IAM_LOGE("failed to write userId");
|
||||
return;
|
||||
}
|
||||
|
||||
SendRequest(userId.has_value() ? UserIdmInterface::USER_IDM_CLOSE_SESSION_BY_ID :
|
||||
UserIdmInterface::USER_IDM_CLOSE_SESSION, data, reply);
|
||||
}
|
||||
|
||||
int32_t UserIdmProxy::GetCredentialInfo(std::optional<int32_t> userId, AuthType authType,
|
||||
const sptr<IdmGetCredInfoCallbackInterface> &callback)
|
||||
{
|
||||
if (callback == nullptr) {
|
||||
IAM_LOGE("callback is nullptr");
|
||||
return FAIL;
|
||||
}
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
|
||||
if (!data.WriteInterfaceToken(UserIdmProxy::GetDescriptor())) {
|
||||
IAM_LOGE("failed to write descriptor");
|
||||
return FAIL;
|
||||
}
|
||||
if (userId.has_value() && !data.WriteInt32(userId.value())) {
|
||||
IAM_LOGE("failed to write userId");
|
||||
return FAIL;
|
||||
}
|
||||
if (!data.WriteUint32(authType)) {
|
||||
IAM_LOGE("failed to write authType");
|
||||
return FAIL;
|
||||
}
|
||||
if (!data.WriteRemoteObject(callback->AsObject())) {
|
||||
IAM_LOGE("failed to write callback");
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
bool ret = SendRequest(userId.has_value() ? UserIdmInterface::USER_IDM_GET_AUTH_INFO_BY_ID :
|
||||
UserIdmInterface::USER_IDM_GET_AUTH_INFO, data, reply);
|
||||
if (!ret) {
|
||||
return FAIL;
|
||||
}
|
||||
int32_t result = FAIL;
|
||||
if (!reply.ReadInt32(result)) {
|
||||
IAM_LOGE("failed to read result");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t UserIdmProxy::GetSecInfo(std::optional<int32_t> userId,
|
||||
const sptr<IdmGetSecureUserInfoCallbackInterface> &callback)
|
||||
{
|
||||
if (callback == nullptr) {
|
||||
IAM_LOGE("callback is nullptr");
|
||||
return FAIL;
|
||||
}
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
|
||||
if (!data.WriteInterfaceToken(UserIdmProxy::GetDescriptor())) {
|
||||
IAM_LOGE("failed to write descriptor");
|
||||
return FAIL;
|
||||
}
|
||||
if (userId.has_value() && !data.WriteInt32(userId.value())) {
|
||||
IAM_LOGE("failed to write userId");
|
||||
return FAIL;
|
||||
}
|
||||
if (!data.WriteRemoteObject(callback->AsObject())) {
|
||||
IAM_LOGE("failed to write callback");
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
bool ret = SendRequest(UserIdmInterface::USER_IDM_GET_SEC_INFO, data, reply);
|
||||
if (!ret) {
|
||||
callback->OnSecureUserInfo(nullptr);
|
||||
return FAIL;
|
||||
}
|
||||
int32_t result = FAIL;
|
||||
if (!reply.ReadInt32(result)) {
|
||||
IAM_LOGE("failed to read result");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void UserIdmProxy::AddCredential(std::optional<int32_t> userId, AuthType authType, PinSubType pinSubType,
|
||||
const std::vector<uint8_t> &token, const sptr<IdmCallbackInterface> &callback, bool isUpdate)
|
||||
{
|
||||
if (callback == nullptr) {
|
||||
IAM_LOGE("callback is nullptr");
|
||||
return;
|
||||
}
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
|
||||
if (!data.WriteInterfaceToken(UserIdmProxy::GetDescriptor())) {
|
||||
IAM_LOGE("failed to write descriptor");
|
||||
return;
|
||||
}
|
||||
if (userId.has_value() && !data.WriteInt32(userId.value())) {
|
||||
IAM_LOGE("failed to write userId");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteUint32(authType)) {
|
||||
IAM_LOGE("failed to write authType");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteUint64(pinSubType)) {
|
||||
IAM_LOGE("failed to write pinSubType");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteUInt8Vector(token)) {
|
||||
IAM_LOGE("failed to write token");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteRemoteObject(callback->AsObject())) {
|
||||
IAM_LOGE("failed to write callback");
|
||||
return;
|
||||
}
|
||||
|
||||
SendRequest(userId.has_value() ? UserIdmInterface::USER_IDM_ADD_CREDENTIAL_BY_ID :
|
||||
UserIdmInterface::USER_IDM_ADD_CREDENTIAL, data, reply);
|
||||
}
|
||||
|
||||
void UserIdmProxy::UpdateCredential(std::optional<int32_t> userId, AuthType authType, PinSubType pinSubType,
|
||||
const std::vector<uint8_t> &token, const sptr<IdmCallbackInterface> &callback)
|
||||
{
|
||||
if (callback == nullptr) {
|
||||
IAM_LOGE("callback is nullptr");
|
||||
return;
|
||||
}
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
|
||||
if (!data.WriteInterfaceToken(UserIdmProxy::GetDescriptor())) {
|
||||
IAM_LOGE("failed to write descriptor");
|
||||
return;
|
||||
}
|
||||
if (userId.has_value() && !data.WriteInt32(userId.value())) {
|
||||
IAM_LOGE("failed to write userId");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteUint32(authType)) {
|
||||
IAM_LOGE("failed to write authType");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteUint64(pinSubType)) {
|
||||
IAM_LOGE("failed to write pinSubType");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteUInt8Vector(token)) {
|
||||
IAM_LOGE("failed to write token");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteRemoteObject(callback->AsObject())) {
|
||||
IAM_LOGE("failed to write callback");
|
||||
return;
|
||||
}
|
||||
|
||||
bool ret = SendRequest(userId.has_value() ? UserIdmInterface::USER_IDM_UPDATE_CREDENTIAL_BY_ID :
|
||||
UserIdmInterface::USER_IDM_UPDATE_CREDENTIAL, data, reply);
|
||||
if (!ret) {
|
||||
Attributes extraInfo;
|
||||
callback->OnResult(FAIL, extraInfo);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t UserIdmProxy::Cancel(std::optional<int32_t> userId, const std::optional<std::vector<uint8_t>> &challenge)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
|
||||
if (!data.WriteInterfaceToken(UserIdmProxy::GetDescriptor())) {
|
||||
IAM_LOGE("failed to write descriptor");
|
||||
return FAIL;
|
||||
}
|
||||
if (userId.has_value() && !data.WriteInt32(userId.value())) {
|
||||
IAM_LOGE("failed to write userId");
|
||||
return FAIL;
|
||||
}
|
||||
if (challenge.has_value() && !data.WriteUInt8Vector(challenge.value())) {
|
||||
IAM_LOGE("failed to write challenge");
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
bool ret = SendRequest(userId.has_value() ? UserIdmInterface::USER_IDM_CANCEL_BY_ID :
|
||||
UserIdmInterface::USER_IDM_CANCEL, data, reply);
|
||||
if (!ret) {
|
||||
return FAIL;
|
||||
}
|
||||
int32_t result = FAIL;
|
||||
if (!reply.ReadInt32(result)) {
|
||||
IAM_LOGE("failed to read result");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t UserIdmProxy::EnforceDelUser(int32_t userId, const sptr<IdmCallbackInterface> &callback)
|
||||
{
|
||||
if (callback == nullptr) {
|
||||
IAM_LOGE("callback is nullptr");
|
||||
return FAIL;
|
||||
}
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
|
||||
if (!data.WriteInterfaceToken(UserIdmProxy::GetDescriptor())) {
|
||||
IAM_LOGE("failed to write descriptor");
|
||||
return FAIL;
|
||||
}
|
||||
if (!data.WriteInt32(userId)) {
|
||||
IAM_LOGE("failed to write userId");
|
||||
return FAIL;
|
||||
}
|
||||
if (!data.WriteRemoteObject(callback->AsObject())) {
|
||||
IAM_LOGE("failed to write callback");
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
bool ret = SendRequest(UserIdmInterface::USER_IDM_ENFORCE_DEL_USER, data, reply);
|
||||
if (!ret) {
|
||||
Attributes attr;
|
||||
callback->OnResult(FAIL, attr);
|
||||
return FAIL;
|
||||
}
|
||||
int32_t result = FAIL;
|
||||
if (!reply.ReadInt32(result)) {
|
||||
IAM_LOGE("failed to read result");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void UserIdmProxy::DelUser(std::optional<int32_t> userId, const std::vector<uint8_t> authToken,
|
||||
const sptr<IdmCallbackInterface> &callback)
|
||||
{
|
||||
if (callback == nullptr) {
|
||||
IAM_LOGE("callback is nullptr");
|
||||
return;
|
||||
}
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
|
||||
if (!data.WriteInterfaceToken(UserIdmProxy::GetDescriptor())) {
|
||||
IAM_LOGE("failed to write descriptor");
|
||||
return;
|
||||
}
|
||||
if (userId.has_value() && !data.WriteInt32(userId.value())) {
|
||||
IAM_LOGE("failed to write userId");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteUInt8Vector(authToken)) {
|
||||
IAM_LOGE("failed to write authToken");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteRemoteObject(callback->AsObject())) {
|
||||
IAM_LOGE("failed to write callback");
|
||||
return;
|
||||
}
|
||||
|
||||
SendRequest(userId.has_value() ? UserIdmInterface::USER_IDM_DEL_USER_BY_ID :
|
||||
UserIdmInterface::USER_IDM_DEL_USER, data, reply);
|
||||
}
|
||||
|
||||
void UserIdmProxy::DelCredential(std::optional<int32_t> userId, uint64_t credentialId,
|
||||
const std::vector<uint8_t> &authToken, const sptr<IdmCallbackInterface> &callback)
|
||||
{
|
||||
if (callback == nullptr) {
|
||||
IAM_LOGE("callback is nullptr");
|
||||
return;
|
||||
}
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
|
||||
if (!data.WriteInterfaceToken(UserIdmProxy::GetDescriptor())) {
|
||||
IAM_LOGE("failed to write descriptor");
|
||||
return;
|
||||
}
|
||||
if (userId.has_value() && !data.WriteInt32(userId.value())) {
|
||||
IAM_LOGE("failed to write userId");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteUint64(credentialId)) {
|
||||
IAM_LOGE("failed to write credentialId");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteUInt8Vector(authToken)) {
|
||||
IAM_LOGE("failed to write authToken");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteRemoteObject(callback->AsObject())) {
|
||||
IAM_LOGE("failed to write callback");
|
||||
return;
|
||||
}
|
||||
|
||||
SendRequest(userId.has_value() ? UserIdmInterface::USER_IDM_DEL_CREDENTIAL :
|
||||
UserIdmInterface::USER_IDM_DEL_CRED, data, reply);
|
||||
}
|
||||
|
||||
bool UserIdmProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
IAM_LOGI("code = %{public}u", code);
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
IAM_LOGE("failed to get remote");
|
||||
return false;
|
||||
}
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
int32_t result = remote->SendRequest(code, data, reply, option);
|
||||
if (result != OHOS::NO_ERROR) {
|
||||
IAM_LOGE("failed to send request, result = %{public}d", result);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
Loading…
Reference in New Issue
Block a user