修复跨设备认证中pin码明文传输导致的安全问题

Signed-off-by: renguang1116 <renguang@huawei.com>
This commit is contained in:
renguang1116
2022-05-26 17:43:44 +08:00
parent c8ed632d14
commit 3ff95dba00
20 changed files with 129 additions and 240 deletions
+4 -2
View File
@@ -75,6 +75,7 @@ enum {
ERR_DM_AUTH_MESSAGE_INCOMPLETE = -20027,
ERR_DM_CREATE_GROUP_FAILED = -20028,
ERR_DM_IPC_READ_TOKEN_FAILED = -20029,
ERR_DM_AUTH_INPUT_PARAMETER_FAILED = -20030,
};
const std::string TARGET_PKG_NAME_KEY = "targetPkgName";
@@ -136,6 +137,7 @@ const std::string PIN_CODE_KEY = "pinCode";
const std::string NFC_CODE_KEY = "nfcCode";
const std::string QR_CODE_KEY = "qrCode";
const std::string TAG_AUTH_TOKEN = "authToken";
const std::string VERIFY_FAILED = "verifyFailed";
const int32_t AUTH_TYPE_PIN = 1;
const int32_t AUTH_TYPE_SCAN = 2;
const int32_t AUTH_TYPE_TOUCH = 3;
@@ -172,8 +174,8 @@ const std::string ETH_PORT = "ETH_PORT";
// ACE
const int32_t ACE_X = 50;
const int32_t ACE_Y = 300;
const int32_t ACE_WIDTH = 450;
const int32_t ACE_HEIGHT = 400;
const int32_t ACE_WIDTH = 580;
const int32_t ACE_HEIGHT = 520;
const std::string EVENT_CONFIRM = "EVENT_CONFIRM";
const std::string EVENT_CANCEL = "EVENT_CANCEL";
const std::string EVENT_INIT = "EVENT_INIT";
@@ -33,6 +33,7 @@ public:
int32_t StartAuth(std::string &authToken, std::shared_ptr<DmAuthManager> authManager) override;
int32_t VerifyAuthentication(std::string &authToken, const std::string &authParam) override;
int32_t CloseAuthInfo(const int32_t &pageId, std::shared_ptr<DmAuthManager> authManager) override;
int32_t UpdateAuthInfo(const int32_t &pageId) override;
};
} // namespace DistributedHardware
} // namespace OHOS
@@ -52,6 +52,11 @@ int32_t NoInteractionAuth::CloseAuthInfo(const int32_t &pageId, std::shared_ptr<
return DM_OK;
}
int32_t NoInteractionAuth::UpdateAuthInfo(const int32_t &pageId)
{
return DM_OK;
}
extern "C" IAuthentication *CreatePinAuthObject(void)
{
return new NoInteractionAuth;
+8 -1
View File
@@ -42,7 +42,7 @@ public:
* @tc.desc: Show Input PinDialog
* @tc.type: FUNC
*/
int32_t InputPinDialog(int32_t code, std::shared_ptr<DmAuthManager> authManager);
int32_t InputPinDialog(std::shared_ptr<DmAuthManager> authManager);
/**
* @tc.name: PinAuthUi::ClosePage
* @tc.desc: Close Page
@@ -50,6 +50,13 @@ public:
*/
int32_t ClosePage(const int32_t &pageId, std::shared_ptr<DmAuthManager> authManager);
/**
* @tc.name: PinAuth::UpdateAuthInfo
* @tc.desc: Update the page information
* @tc.type: FUNC
*/
int32_t UpdatePinDialog(int32_t pageId);
private:
int32_t StartFaUiService(std::shared_ptr<DmAbilityManager> dmAbilityManager);
};
+7
View File
@@ -58,6 +58,13 @@ public:
* @tc.type: FUNC
*/
int32_t CloseAuthInfo(const int32_t &pageId, std::shared_ptr<DmAuthManager> authManager) override;
/**
* @tc.name: PinAuth::UpdateAuthInfo
* @tc.desc: Update Auth Info of the PinAuth
* @tc.type: FUNC
*/
int32_t UpdateAuthInfo(const int32_t &pageId) override;
private:
int32_t times_ = 0;
std::shared_ptr<PinAuthUi> pinAuthUi_;
+2 -2
View File
@@ -27,9 +27,9 @@ class PinAuthUi {
public:
PinAuthUi();
int32_t ShowPinDialog(int32_t code, std::shared_ptr<DmAuthManager> authManager);
int32_t InputPinDialog(int32_t code, std::shared_ptr<DmAuthManager> authManager);
int32_t InputPinDialog(std::shared_ptr<DmAuthManager> authManager);
int32_t ClosePage(const int32_t &pageId, std::shared_ptr<DmAuthManager> authManager);
int32_t UpdatePinDialog(int32_t pageId);
private:
int32_t StartFaUiService(std::shared_ptr<DmAbilityManager> dmAbilityManager);
};
@@ -22,7 +22,7 @@
<text class="title-list">
请输入另一个设备显示的PIN码进行验证
</text>
<input class="title-pin" id="input" type="number" onchange="onChange"></input>
<input class="title-pin" id="input" type="string" onchange="onChange" value="{{inputValue}}"></input>
<text class="title-error" id="error" show="{{isShow}}">
PIN码输入错误,请重新输入(3次:还有{{isTimes}}次机会)
</text>
@@ -15,9 +15,10 @@
import router from '@ohos.router';
var numbs = 0;
var code = 0;
var inputVal = 0;
var inputVal;
var inputValue;
var isShow = false;
var isTimes = 3;
var EVENT_CONFIRM = "EVENT_CONFIRM";
var EVENT_CANCEL = "EVENT_CANCEL";
var EVENT_INIT = "EVENT_INIT";
@@ -26,37 +27,19 @@ var EVENT_CANCEL_CODE = "1";
var EVENT_INIT_CODE = "2";
export default {
data: {
pincode: router.getParams().pinCode,
isShow:false,
isTimes:3,
isShow: router.getParams().verifyFailed,
inputValue: "",
},
onInit() {
code = router.getParams().pinCode;
callNativeHandler(EVENT_INIT, EVENT_INIT_CODE);
},
onChange(e){
inputVal = e.value;
inputVal = e.value;
},
onConfirm() {
numbs = numbs + 1;
if(numbs <= 3){
console.info('click confirm numbs < 3 ');
if(code == inputVal){
console.info('click confirm code == inputVal');
callNativeHandler(EVENT_CONFIRM, EVENT_CONFIRM_CODE);
}else{
if(numbs == 3){
console.info('click confirm code != inputVal and numbs == 3');
callNativeHandler(EVENT_CANCEL, EVENT_CANCEL_CODE);
}
console.info('click confirm code != inputVal');
this.isShow = true;
this.isTimes = 3 - numbs;
}
}else{
console.info('click confirm numbs > 3 ');
callNativeHandler(EVENT_CANCEL, EVENT_CANCEL_CODE);
}
isTimes--;
callNativeHandler(EVENT_CONFIRM, inputVal);
inputValue = "";
},
onCancel() {
console.info('click cancel');
+6 -1
View File
@@ -33,7 +33,7 @@ int32_t PinAuthUi::ShowPinDialog(int32_t code, std::shared_ptr<DmAuthManager> au
return DM_OK;
}
int32_t PinAuthUi::InputPinDialog(int32_t code, std::shared_ptr<DmAuthManager> authManager)
int32_t PinAuthUi::InputPinDialog(std::shared_ptr<DmAuthManager> authManager)
{
LOGI("InputPinDialog start");
std::shared_ptr<DmAbilityManager> dmAbilityManager_ = std::make_shared<DmAbilityManager>();
@@ -66,5 +66,10 @@ int32_t PinAuthUi::StartFaUiService(std::shared_ptr<DmAbilityManager> dmAbilityM
}
return DM_OK;
}
int32_t PinAuthUi::UpdatePinDialog((int32_t pageId)
{
return DM_OK;
}
} // namespace DistributedHardware
} // namespace OHOS
+6 -10
View File
@@ -51,16 +51,7 @@ int32_t PinAuth::ShowAuthInfo(std::string &authToken, std::shared_ptr<DmAuthMana
int32_t PinAuth::StartAuth(std::string &authToken, std::shared_ptr<DmAuthManager> authManager)
{
nlohmann::json jsonObject = nlohmann::json::parse(authToken, nullptr, false);
if (jsonObject.is_discarded()) {
LOGE("DecodeRequestAuth jsonStr error");
return ERR_DM_FAILED;
}
if (!jsonObject.contains(PIN_CODE_KEY)) {
LOGE("err json string, first time");
return ERR_DM_FAILED;
}
return pinAuthUi_->InputPinDialog(jsonObject[PIN_CODE_KEY], authManager);
return pinAuthUi_->InputPinDialog(authManager);
}
int32_t PinAuth::VerifyAuthentication(std::string &authToken, const std::string &authParam)
@@ -106,6 +97,11 @@ int32_t PinAuth::CloseAuthInfo(const int32_t &pageId, std::shared_ptr<DmAuthMana
return pinAuthUi_->ClosePage(pageId, authManager);
}
int32_t PinAuth::UpdateAuthInfo(const int32_t &pageId)
{
return pinAuthUi_->UpdatePinDialog(pageId);
}
extern "C" IAuthentication *CreatePinAuthObject(void)
{
return new PinAuth;
+19 -7
View File
@@ -58,7 +58,7 @@ int32_t PinAuthUi::ShowPinDialog(int32_t code, std::shared_ptr<DmAuthManager> au
return DM_OK;
}
int32_t PinAuthUi::InputPinDialog(int32_t code, std::shared_ptr<DmAuthManager> authManager)
int32_t PinAuthUi::InputPinDialog(std::shared_ptr<DmAuthManager> authManager)
{
LOGI("InputPinDialog start");
if (authManager == nullptr) {
@@ -66,7 +66,7 @@ int32_t PinAuthUi::InputPinDialog(int32_t code, std::shared_ptr<DmAuthManager> a
return ERR_DM_FAILED;
}
nlohmann::json jsonObj;
jsonObj[PIN_CODE_KEY] = code;
jsonObj[VERIFY_FAILED] = false;
jsonObj.dump();
const std::string params = jsonObj.dump();
@@ -76,13 +76,13 @@ int32_t PinAuthUi::InputPinDialog(int32_t code, std::shared_ptr<DmAuthManager> a
OHOS::Rosen::WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW,
ACE_X, ACE_Y, ACE_WIDTH, ACE_HEIGHT,
[authManager](int32_t id, const std::string& event, const std::string& params) {
if (params == EVENT_INIT_CODE) {
if (event == EVENT_INIT) {
authManager->SetPageId(id);
}
if (params == EVENT_CANCEL_CODE || params == EVENT_CONFIRM_CODE) {
Ace::UIServiceMgrClient::GetInstance()->CancelDialog(id);
} else if (event == EVENT_CONFIRM) {
LOGI("CancelDialog start id:%d,event:%s,parms:%s", id, event.c_str(), params.c_str());
authManager->VerifyAuthentication(params.c_str());
authManager->AddMember(std::stoi(params));
} else {
authManager->SetReasonAndFinish(ERR_DM_AUTH_INPUT_PARAMETER_FAILED, AuthState::AUTH_REQUEST_JOIN);
}
});
LOGI("ShowConfigDialog end");
@@ -97,6 +97,18 @@ int32_t PinAuthUi::ClosePage(const int32_t &pageId, std::shared_ptr<DmAuthManage
return DM_OK;
}
int32_t PinAuthUi::UpdatePinDialog(int32_t pageId)
{
LOGI("UpdatePinDialog start");
nlohmann::json jsonObj;
jsonObj[VERIFY_FAILED] = true;
jsonObj.dump();
const std::string params = jsonObj.dump();
Ace::UIServiceMgrClient::GetInstance()->UpdateDialog(pageId, params);
LOGI("UpdatePinDialog end");
return DM_OK;
}
int32_t PinAuthUi::StartFaUiService(std::shared_ptr<DmAbilityManager> dmAbilityManager)
{
AbilityStatus status = dmAbilityManager->StartAbility(AbilityRole::ABILITY_ROLE_INITIATIVE);
@@ -131,23 +131,6 @@ public:
int32_t Enter() override;
};
class AuthRequestInputState : public AuthRequestState {
public:
/**
* @tc.name: AuthRequestInputState::GetStateType
* @tc.desc: Get State Type of the AuthRequest Input State
* @tc.type: FUNC
*/
int32_t GetStateType() override;
/**
* @tc.name: AuthRequestInputState::Enter
* @tc.desc: Enter of the AuthRequest Input State
* @tc.type: FUNC
*/
int32_t Enter() override;
};
class AuthRequestJoinState : public AuthRequestState {
public:
/**
@@ -28,6 +28,7 @@ public:
virtual int32_t StartAuth(std::string &authToken, std::shared_ptr<DmAuthManager> authManager) = 0;
virtual int32_t VerifyAuthentication(std::string &authToken, const std::string &authParam) = 0;
virtual int32_t CloseAuthInfo(const int32_t &pageId, std::shared_ptr<DmAuthManager> authManager) = 0;
virtual int32_t UpdateAuthInfo(const int32_t &pageId) = 0;
};
using CreateIAuthAdapterFuncPtr = IAuthentication *(*)(void);
@@ -39,7 +39,6 @@ typedef enum AuthState {
AUTH_REQUEST_NEGOTIATE,
AUTH_REQUEST_NEGOTIATE_DONE,
AUTH_REQUEST_REPLY,
AUTH_REQUEST_INPUT,
AUTH_REQUEST_JOIN,
AUTH_REQUEST_NETWORK,
AUTH_REQUEST_FINISH,
@@ -238,7 +237,7 @@ public:
* @tc.desc: Add Member of the DeviceManager Authenticate Manager
* @tc.type: FUNC
*/
int32_t AddMember(const std::string &deviceId);
int32_t AddMember(int32_t pinCode);
/**
* @tc.name: DmAuthManager::GetConnectAddr
@@ -367,11 +366,11 @@ public:
int32_t SetPageId(int32_t pageId);
/**
* @tc.name: DmAuthManager::SetReason
* @tc.name: DmAuthManager::SetReasonAndFinish
* @tc.desc: Set Reason of the DeviceManager Authenticate Manager
* @tc.type: FUNC
*/
int32_t SetReason(int32_t reason, int32_t state);
int32_t SetReasonAndFinish(int32_t reason, int32_t state);
private:
std::shared_ptr<SoftbusConnector> softbusConnector_;
@@ -388,6 +387,8 @@ private:
std::shared_ptr<DmAbilityManager> dmAbilityMgr_;
bool isCryptoSupport_ = false;
bool isFinishOfLocal_ = true;
int32_t authTimes_ = 0;
std::shared_ptr<IAuthentication> authPtr_;
};
} // namespace DistributedHardware
} // namespace OHOS
@@ -122,23 +122,6 @@ int32_t AuthRequestReplyState::Enter()
return DM_OK;
}
int32_t AuthRequestInputState::GetStateType()
{
return AuthState::AUTH_REQUEST_INPUT;
}
int32_t AuthRequestInputState::Enter()
{
LOGI("DmAuthManager::AuthRequestInputState");
std::shared_ptr<DmAuthManager> stateAuthManager = authManager_.lock();
if (stateAuthManager == nullptr) {
LOGE("AuthRequestState::authManager_ null");
return ERR_DM_FAILED;
}
stateAuthManager->ShowStartAuthDialog();
return DM_OK;
}
int32_t AuthRequestJoinState::GetStateType()
{
return AuthState::AUTH_REQUEST_JOIN;
@@ -152,7 +135,7 @@ int32_t AuthRequestJoinState::Enter()
LOGE("AuthRequestState::authManager_ null");
return ERR_DM_FAILED;
}
stateAuthManager->AddMember(context_->deviceId);
stateAuthManager->ShowStartAuthDialog();
return DM_OK;
}
@@ -40,6 +40,7 @@ const int32_t WAIT_NEGOTIATE_TIMEOUT = 10;
const int32_t WAIT_REQUEST_TIMEOUT = 10;
const int32_t CANCEL_PIN_CODE_DISPLAY = 1;
const int32_t DEVICE_ID_HALF = 2;
const int32_t MAX_AUTH_TIMES = 3;
DmAuthManager::DmAuthManager(std::shared_ptr<SoftbusConnector> softbusConnector,
std::shared_ptr<DeviceManagerServiceListener> listener,
@@ -84,6 +85,7 @@ int32_t DmAuthManager::AuthenticateDevice(const std::string &pkgName, int32_t au
return ERR_DM_INPUT_PARAMETER_EMPTY;
}
authPtr_ = authenticationMap_[authType];
if (timer_ == nullptr) {
timer_ = std::make_shared<DmTimer>();
}
@@ -160,14 +162,8 @@ int32_t DmAuthManager::VerifyAuthentication(const std::string &authParam)
LOGE("authResponseContext_ is not init");
return ERR_DM_AUTH_NOT_START;
}
std::shared_ptr<IAuthentication> ptr;
if (authenticationMap_.find(authResponseContext_->authType) == authenticationMap_.end()) {
LOGE("DmAuthManager::authenticationMap_ is null");
return ERR_DM_FAILED;
}
timer_->DeleteTimer(INPUT_TIMEOUT_TASK);
ptr = authenticationMap_[authResponseContext_->authType];
int32_t ret = ptr->VerifyAuthentication(authResponseContext_->authToken, authParam);
int32_t ret = authPtr_->VerifyAuthentication(authResponseContext_->authToken, authParam);
switch (ret) {
case DM_OK:
authRequestState_->TransitionTo(std::make_shared<AuthRequestJoinState>());
@@ -314,7 +310,7 @@ void DmAuthManager::OnDataReceived(const int32_t sessionId, const std::string me
void DmAuthManager::OnGroupCreated(int64_t requestId, const std::string &groupId)
{
LOGI("DmAuthManager::OnGroupCreated start");
LOGI("DmAuthManager::OnGroupCreated start group id %s", groupId.c_str());
if (authResponseState_ == nullptr) {
LOGE("DmAuthManager::AuthenticateDevice end");
return;
@@ -329,11 +325,11 @@ void DmAuthManager::OnGroupCreated(int64_t requestId, const std::string &groupId
int32_t pinCode = GeneratePincode();
nlohmann::json jsonObj;
jsonObj[PIN_CODE_KEY] = pinCode;
jsonObj[PIN_TOKEN] = authResponseContext_->token;
jsonObj[QR_CODE_KEY] = GenerateGroupName();
jsonObj[NFC_CODE_KEY] = GenerateGroupName();
authResponseContext_->authToken = jsonObj.dump();
LOGI("DmAuthManager::OnGroupCreated start group id %s", groupId.c_str());
authResponseContext_->groupId = groupId;
authResponseContext_->code = pinCode;
authMessageProcessor_->SetResponseContext(authResponseContext_);
@@ -344,24 +340,31 @@ void DmAuthManager::OnGroupCreated(int64_t requestId, const std::string &groupId
void DmAuthManager::OnMemberJoin(int64_t requestId, int32_t status)
{
LOGI("DmAuthManager OnMemberJoin start");
LOGI("DmAuthManager OnMemberJoin start authTimes %d", authTimes_);
if (authRequestState_ != nullptr) {
authTimes_++;
timer_->DeleteTimer(ADD_TIMEOUT_TASK);
if (status != DM_OK || authResponseContext_->requestId != requestId) {
if (authRequestState_ != nullptr) {
if (authRequestState_ != nullptr && authTimes_ >= MAX_AUTH_TIMES) {
authResponseContext_->state = AuthState::AUTH_REQUEST_JOIN;
authRequestContext_->reason = ERR_DM_INPUT_PARAMETER_EMPTY;
authRequestState_->TransitionTo(std::make_shared<AuthRequestFinishState>());
return;
} else {
timer_->StartTimer(INPUT_TIMEOUT_TASK, INPUT_TIMEOUT,
[this] (std::string name) {
DmAuthManager::HandleAuthenticateTimeout(name);
});
authPtr_->UpdateAuthInfo(authResponseContext_->pageId);
}
} else {
authRequestState_->TransitionTo(std::make_shared<AuthRequestNetworkState>());
}
authRequestState_->TransitionTo(std::make_shared<AuthRequestNetworkState>());
}
}
void DmAuthManager::HandleAuthenticateTimeout(std::string name)
{
LOGI("DmAuthManager::HandleAuthenticateTimeout start");
LOGI("DmAuthManager::HandleAuthenticateTimeout start timer name %s", name.c_str());
if (authRequestState_ != nullptr && authRequestState_->GetStateType() != AuthState::AUTH_REQUEST_FINISH) {
if (authResponseContext_ == nullptr) {
authResponseContext_ = std::make_shared<DmAuthResponseContext>();
@@ -427,6 +430,8 @@ void DmAuthManager::RespNegotiate(const int32_t &sessionId)
if (authentication == nullptr) {
LOGE("DmAuthManager::AuthenticateDevice authType %d not support.", authResponseContext_->authType);
authResponseContext_->reply = ERR_DM_UNSUPPORTED_AUTH_TYPE;
} else {
authPtr_ = authenticationMap_[authResponseContext_->authType];
}
std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_RESP_NEGOTIATE);
@@ -435,7 +440,7 @@ void DmAuthManager::RespNegotiate(const int32_t &sessionId)
softbusConnector_->GetSoftbusSession()->SendData(sessionId, message);
}
authResponseContext_ = authResponseState_->GetAuthContext();
if ((jsonObject[TAG_CRYPTO_SUPPORT] == true) && authResponseContext_->cryptoSupport) {
if (jsonObject[TAG_CRYPTO_SUPPORT] == true && authResponseContext_->cryptoSupport) {
if (jsonObject[TAG_CRYPTO_NAME] == authResponseContext_->cryptoName &&
jsonObject[TAG_CRYPTO_VERSION] == authResponseContext_->cryptoVer) {
isCryptoSupport_ = true;
@@ -502,7 +507,7 @@ void DmAuthManager::StartRespAuthProcess()
[this] (std::string name) {
DmAuthManager::HandleAuthenticateTimeout(name);
});
authRequestState_->TransitionTo(std::make_shared<AuthRequestInputState>());
authRequestState_->TransitionTo(std::make_shared<AuthRequestJoinState>());
} else {
LOGE("do not accept");
authResponseContext_->state = AuthState::AUTH_REQUEST_REPLY;
@@ -520,19 +525,15 @@ int32_t DmAuthManager::CreateGroup()
return DM_OK;
}
int32_t DmAuthManager::AddMember(const std::string &deviceId)
int32_t DmAuthManager::AddMember(int32_t pinCode)
{
LOGI("DmAuthManager::AddMember start");
nlohmann::json jsonObj = nlohmann::json::parse(authResponseContext_->authToken, nullptr, false);
if (jsonObj.is_discarded()) {
LOGE("DecodeRequestAuth jsonStr error");
return ERR_DM_FAILED;
}
LOGI("DmAuthManager::AddMember start pin code %d", pinCode);
LOGI("DmAuthManager::AddMember start group id %s", authResponseContext_->groupId.c_str());
timer_->DeleteTimer(INPUT_TIMEOUT_TASK);
nlohmann::json jsonObject;
jsonObject[TAG_GROUP_ID] = authResponseContext_->groupId;
jsonObject[TAG_GROUP_NAME] = authResponseContext_->groupName;
jsonObject[PIN_CODE_KEY] = jsonObj[PIN_CODE_KEY];
jsonObject[PIN_CODE_KEY] = pinCode;
jsonObject[TAG_REQUEST_ID] = authResponseContext_->requestId;
jsonObject[TAG_DEVICE_ID] = authResponseContext_->deviceId;
std::string connectInfo = jsonObject.dump();
@@ -540,18 +541,10 @@ int32_t DmAuthManager::AddMember(const std::string &deviceId)
[this] (std::string name) {
DmAuthManager::HandleAuthenticateTimeout(name);
});
int32_t ret = hiChainConnector_->AddMember(deviceId, connectInfo);
int32_t ret = hiChainConnector_->AddMember(authRequestContext_->deviceId, connectInfo);
if (ret != 0) {
return ERR_DM_FAILED;
}
LOGI("DmAuthManager::authRequestContext CancelDisplay start");
std::shared_ptr<IAuthentication> ptr;
if (authenticationMap_.find(authResponseContext_->authType) == authenticationMap_.end()) {
LOGE("DmAuthManager::authenticationMap_ is null");
return ERR_DM_FAILED;
}
ptr = authenticationMap_[authResponseContext_->authType];
ptr->CloseAuthInfo(authResponseContext_->pageId, shared_from_this());
return DM_OK;
}
@@ -578,13 +571,7 @@ void DmAuthManager::AuthenticateFinish()
LOGI("DmAuthManager::AuthenticateFinish start");
if (authResponseState_ != nullptr) {
if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_FINISH) {
std::shared_ptr<IAuthentication> ptr;
if (authenticationMap_.find(authResponseContext_->authType) == authenticationMap_.end()) {
LOGE("DmAuthManager::authenticationMap_ is null");
return ;
}
ptr = authenticationMap_[authResponseContext_->authType];
ptr->CloseAuthInfo(authResponseContext_->pageId, shared_from_this());
authPtr_->CloseAuthInfo(authResponseContext_->pageId, shared_from_this());
}
if (isFinishOfLocal_) {
authMessageProcessor_->SetResponseContext(authResponseContext_);
@@ -596,6 +583,7 @@ void DmAuthManager::AuthenticateFinish()
authResponseContext_ = nullptr;
authResponseState_ = nullptr;
authMessageProcessor_ = nullptr;
authPtr_ = nullptr;
} else if (authRequestState_ != nullptr) {
if (isFinishOfLocal_) {
authMessageProcessor_->SetResponseContext(authResponseContext_);
@@ -604,14 +592,8 @@ void DmAuthManager::AuthenticateFinish()
} else {
authRequestContext_->reason = authResponseContext_->reply;
}
if (authResponseContext_->state == AuthState::AUTH_REQUEST_INPUT) {
std::shared_ptr<IAuthentication> ptr;
if (authenticationMap_.find(authResponseContext_->authType) == authenticationMap_.end()) {
LOGE("DmAuthManager::authenticationMap_ is null");
return ;
}
ptr = authenticationMap_[authResponseContext_->authType];
ptr->CloseAuthInfo(authResponseContext_->pageId, shared_from_this());
if (authResponseContext_->state == AuthState::AUTH_REQUEST_JOIN) {
authPtr_->CloseAuthInfo(authResponseContext_->pageId, shared_from_this());
}
listener_->OnAuthResult(authRequestContext_->hostPkgName, authRequestContext_->deviceId,
authRequestContext_->token, authResponseContext_->state, authRequestContext_->reason);
@@ -622,6 +604,8 @@ void DmAuthManager::AuthenticateFinish()
authResponseContext_ = nullptr;
authRequestState_ = nullptr;
authMessageProcessor_ = nullptr;
authPtr_ = nullptr;
authTimes_ = 0;
}
LOGI("DmAuthManager::AuthenticateFinish complete");
}
@@ -686,12 +670,8 @@ int32_t DmAuthManager::SetAuthResponseState(std::shared_ptr<AuthResponseState> a
int32_t DmAuthManager::GetPinCode()
{
nlohmann::json jsonObj = nlohmann::json::parse(authResponseContext_->authToken, nullptr, false);
if (jsonObj.is_discarded()) {
LOGE("DecodeRequestAuth jsonStr error");
return ERR_DM_FAILED;
}
return jsonObj[PIN_CODE_KEY];
LOGI("ShowConfigDialog start add member pin code %d", authResponseContext_->code);
return authResponseContext_->code;
}
void DmAuthManager::ShowConfigDialog()
@@ -711,27 +691,17 @@ void DmAuthManager::ShowConfigDialog()
void DmAuthManager::ShowAuthInfoDialog()
{
LOGI("DmAuthManager::ShowAuthInfoDialog start");
std::shared_ptr<IAuthentication> ptr;
if (authenticationMap_.find(authResponseContext_->authType) == authenticationMap_.end()) {
LOGE("DmAuthManager::authenticationMap_ is null");
return;
}
ptr = authenticationMap_[authResponseContext_->authType];
LOGI("ShowAuthInfoDialog authToken:%s", authResponseContext_->authToken.c_str());
ptr->ShowAuthInfo(authResponseContext_->authToken, shared_from_this());
LOGI("DmAuthManager::ShowAuthInfoDialog start %d", authResponseContext_->code);
nlohmann::json jsonObj;
jsonObj[PIN_CODE_KEY] = authResponseContext_->code;
std::string authParam = jsonObj.dump();
authPtr_->ShowAuthInfo(authParam, shared_from_this());
}
void DmAuthManager::ShowStartAuthDialog()
{
LOGI("DmAuthManager::ShowStartAuthDialog start");
std::shared_ptr<IAuthentication> ptr;
if (authenticationMap_.find(authResponseContext_->authType) == authenticationMap_.end()) {
LOGE("DmAuthManager::authenticationMap_ is null");
return;
}
ptr = authenticationMap_[authResponseContext_->authType];
ptr->StartAuth(authResponseContext_->authToken, shared_from_this());
authPtr_->StartAuth(authResponseContext_->authToken, shared_from_this());
}
int32_t DmAuthManager::GetAuthenticationParam(DmAuthParam &authParam)
@@ -745,7 +715,7 @@ int32_t DmAuthManager::GetAuthenticationParam(DmAuthParam &authParam)
LOGE("Authenticate is not start");
return ERR_DM_AUTH_NOT_START;
}
dmAbilityMgr_->StartAbilityDone();
AbilityRole role = dmAbilityMgr_->GetAbilityRole();
authParam.direction = (int32_t)role;
@@ -835,17 +805,20 @@ int32_t DmAuthManager::SetPageId(int32_t pageId)
return DM_OK;
}
int32_t DmAuthManager::SetReason(int32_t reason, int32_t state)
int32_t DmAuthManager::SetReasonAndFinish(int32_t reason, int32_t state)
{
if (authResponseContext_ == nullptr) {
LOGE("Authenticate is not start");
return ERR_DM_AUTH_NOT_START;
}
if (state < AuthState::AUTH_REQUEST_FINISH) {
authRequestContext_->reason = reason;
}
authResponseContext_->state = state;
authResponseContext_->reply = reason;
if (authRequestState_ != nullptr && authRequestState_->GetStateType() != AuthState::AUTH_REQUEST_FINISH) {
authRequestContext_->reason = reason;
authRequestState_->TransitionTo(std::make_shared<AuthRequestFinishState>());
} else if (authResponseState_ != nullptr && authResponseState_->GetStateType() != AuthState::AUTH_RESPONSE_FINISH) {
authResponseState_->TransitionTo(std::make_shared<AuthResponseFinishState>());
}
return DM_OK;
}
} // namespace DistributedHardware
@@ -439,57 +439,6 @@ HWTEST_F(AuthRequestStateTest, Enter_008, testing::ext::TestSize.Level0)
ASSERT_EQ(ret, DM_OK);
}
/**
* @tc.name: AuthRequestInputState::GetStateType_005
* @tc.desc: 1 call AuthRequestInputState::GetStateType
* 2 check ret is AuthState::AUTH_REQUEST_INPUT
* @tc.type: FUNC
* @tc.require: AR000GHSJK
*/
HWTEST_F(AuthRequestStateTest, GetStateType_005, testing::ext::TestSize.Level0)
{
std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestInputState>();
int32_t ret = authRequestState->GetStateType();
ASSERT_EQ(ret, AuthState::AUTH_REQUEST_INPUT);
}
/**
* @tc.name: AuthRequestInputState::Enter_009
* @tc.desc: 1 set authManager to null
* 2 call AuthRequestInputState::Enter with authManager = null
* 3 check ret is ERR_DM_FAILED
* @tc.type: FUNC
* @tc.require: AR000GHSJK
*/
HWTEST_F(AuthRequestStateTest, Enter_009, testing::ext::TestSize.Level0)
{
std::shared_ptr<DmAuthManager> authManager =
std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector);
std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestInputState>();
authRequestState->SetAuthManager(nullptr);
int32_t ret = authRequestState->Enter();
ASSERT_EQ(ret, ERR_DM_FAILED);
}
/**
* @tc.name: AuthRequestInputState::Enter_010
* @tc.desc: 1 set authManager not null
* 2 call AuthRequestInputState::Enter with authManager != null
* 3 check ret is DM_OK
* @tc.type: FUNC
* @tc.require: AR000GHSJK
*/
HWTEST_F(AuthRequestStateTest, Enter_010, testing::ext::TestSize.Level0)
{
std::shared_ptr<DmAuthManager> authManager =
std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector);
authManager->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestInputState>();
authRequestState->SetAuthManager(authManager);
int32_t ret = authRequestState->Enter();
ASSERT_EQ(ret, DM_OK);
}
/**
* @tc.name: AuthRequestJoinState::GetStateType_006
* @tc.desc: 1 call AuthRequestJoinState::GetStateType
+2 -2
View File
@@ -208,10 +208,10 @@ HWTEST_F(DmAuthManagerTest, AddMember_001, testing::ext::TestSize.Level0)
authManager->authResponseContext_->code = 123;
authManager->authResponseContext_->requestId = 234;
authManager->authResponseContext_->deviceId = "234";
std::string deviceId = "44444";
int32_t pinCode = 444444;
authManager->hiChainConnector_->RegisterHiChainCallback(authManager);
authManager->SetAuthResponseState(authResponseState);
int32_t ret = authManager->AddMember(deviceId);
int32_t ret = authManager->AddMember(pinCode);
ASSERT_EQ(ret, ERR_DM_FAILED);
}
+2 -4
View File
@@ -86,8 +86,7 @@ HWTEST_F(PinAuthUiTest, ShowPinDialog_002, testing::ext::TestSize.Level0)
HWTEST_F(PinAuthUiTest, InputPinDialog_001, testing::ext::TestSize.Level0)
{
std::shared_ptr<PinAuthUi> pinAuthUi = std::make_shared<PinAuthUi>();
int32_t code = 123456;
int32_t ret = pinAuthUi->InputPinDialog(code, nullptr);
int32_t ret = pinAuthUi->InputPinDialog(nullptr);
ASSERT_EQ(ret, DM_OK);
}
@@ -100,8 +99,7 @@ HWTEST_F(PinAuthUiTest, InputPinDialog_001, testing::ext::TestSize.Level0)
HWTEST_F(PinAuthUiTest, InputPinDialog_002, testing::ext::TestSize.Level0)
{
std::shared_ptr<PinAuthUi> pinAuthUi = std::make_shared<PinAuthUi>();
int32_t code = 123456;
int32_t ret = pinAuthUi->InputPinDialog(code, authManager);
int32_t ret = pinAuthUi->InputPinDialog(authManager);
ASSERT_EQ(ret, DM_OK);
}
}
-17
View File
@@ -122,23 +122,6 @@ int32_t AuthRequestReplyState::Enter()
return DM_OK;
}
int32_t AuthRequestInputState::GetStateType()
{
return AuthState::AUTH_REQUEST_INPUT;
}
int32_t AuthRequestInputState::Enter()
{
LOGI("DmAuthManager::AuthRequestInputState");
std::shared_ptr<DmAuthManager> stateAuthManager = authManager_.lock();
if (stateAuthManager == nullptr) {
LOGE("AuthRequestState::authManager_ null");
return ERR_DM_FAILED;
}
stateAuthManager->ShowStartAuthDialog();
return DM_OK;
}
int32_t AuthRequestJoinState::GetStateType()
{
return AuthState::AUTH_REQUEST_JOIN;