mirror of
https://gitee.com/openharmony/security_privacy_center
synced 2025-02-17 05:58:14 +00:00
commit
71cb950414
84
CertManager/src/main/ets/model/CheckUserAuthModel.ets
Normal file
84
CertManager/src/main/ets/model/CheckUserAuthModel.ets
Normal file
@ -0,0 +1,84 @@
|
||||
/**
|
||||
* Copyright (c) 2024 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 userAuth from '@ohos.userIAM.userAuth';
|
||||
import { BusinessError } from '@ohos.base';
|
||||
|
||||
export class CheckUserAuthModel {
|
||||
public isAuthTypeSupported(authType: userAuth.UserAuthType): boolean {
|
||||
try {
|
||||
userAuth.getAvailableStatus(authType, userAuth.AuthTrustLevel.ATL1);
|
||||
console.log('[CMa&CheckUserAuthModel]: ' + 'userAuthType' + authType + 'is supported');
|
||||
return true;
|
||||
} catch (error) {
|
||||
let err: BusinessError = error as BusinessError;
|
||||
console.error(`[CMa&CheckUserAuthModel]: userAuthType ${authType} is not supported, message is ${err?.message}`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public auth(titleStr: string, callback: (authResult: boolean) => void): void {
|
||||
let fingerPrint: boolean = this.isAuthTypeSupported(userAuth.UserAuthType.FINGERPRINT);
|
||||
let pin: boolean = this.isAuthTypeSupported(userAuth.UserAuthType.PIN);
|
||||
let authTypeArray = [userAuth.UserAuthType.FINGERPRINT];
|
||||
if (fingerPrint) {
|
||||
authTypeArray = [userAuth.UserAuthType.FINGERPRINT];
|
||||
if (pin) {
|
||||
authTypeArray = [userAuth.UserAuthType.FINGERPRINT, userAuth.UserAuthType.PIN];
|
||||
}
|
||||
} else if (pin) {
|
||||
authTypeArray = [userAuth.UserAuthType.PIN];
|
||||
} else {
|
||||
/* The user does not set identity authentication. */
|
||||
callback(true);
|
||||
}
|
||||
|
||||
const authParam: userAuth.AuthParam = {
|
||||
challenge: new Uint8Array([49, 49, 49, 49, 49, 49]),
|
||||
authType: authTypeArray,
|
||||
authTrustLevel: userAuth.AuthTrustLevel.ATL1
|
||||
}
|
||||
const widgetParam: userAuth.WidgetParam = {
|
||||
title: titleStr
|
||||
};
|
||||
|
||||
try {
|
||||
let userAuthInstance = userAuth.getUserAuthInstance(authParam, widgetParam);
|
||||
console.log('[CMa&CheckUserAuthModel]: get userAuth instance success');
|
||||
userAuthInstance.start();
|
||||
|
||||
userAuthInstance.on('result', {
|
||||
onResult(result) {
|
||||
if (result.result === userAuth.UserAuthResultCode.SUCCESS) {
|
||||
callback(true);
|
||||
} else if (result.result === userAuth.UserAuthResultCode.CANCELED) {
|
||||
/* User cancels authentication. */
|
||||
callback(false);
|
||||
} else {
|
||||
/* User authentication failed. */
|
||||
callback(false);
|
||||
}
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
let err: BusinessError = error as BusinessError;
|
||||
console.error(`[CMa&CheckUserAuthModel]: auth catch error. code is ${err?.code}, message is ${err?.message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let checkUserAuthModel = new CheckUserAuthModel();
|
||||
|
||||
export default checkUserAuthModel as CheckUserAuthModel;
|
@ -18,9 +18,8 @@ import HeadComponent from '../common/component/headComponent';
|
||||
import CmFaPresenter from '../presenter/CmFaPresenter';
|
||||
import { GlobalContext } from '../common/GlobalContext';
|
||||
import ComponentConfig from '../common/component/ComponentConfig';
|
||||
import userAuth from '@ohos.userIAM.userAuth';
|
||||
import { BusinessError } from '@ohos.base';
|
||||
import router from '@ohos.router';
|
||||
import checkUserAuthModel from '../model/CheckUserAuthModel';
|
||||
|
||||
|
||||
@Entry
|
||||
@ -33,64 +32,18 @@ struct CertificateComponent {
|
||||
@State installCertFlag: boolean = false;
|
||||
@State pageKey: string = '';
|
||||
|
||||
getIdentity() {
|
||||
const authParam: userAuth.AuthParam = {
|
||||
challenge: new Uint8Array([49, 49, 49, 49, 49, 49]),
|
||||
authType: [userAuth.UserAuthType.FINGERPRINT, userAuth.UserAuthType.PIN],
|
||||
authTrustLevel: userAuth.AuthTrustLevel.ATL3
|
||||
}
|
||||
const widgetParam: userAuth.WidgetParam = {
|
||||
title: '请进行身份验证'
|
||||
};
|
||||
let that = this;
|
||||
try {
|
||||
let userAuthInstance = userAuth.getUserAuthInstance(authParam, widgetParam);
|
||||
console.log('get userAuth instance success: ' + userAuthInstance);
|
||||
userAuthInstance.on('result', {
|
||||
onResult(result) {
|
||||
userAuthInstance.off('result');
|
||||
if (result.result === userAuth.UserAuthResultCode.SUCCESS) {
|
||||
if (that.installCertFlag) {
|
||||
that.mFaPresenter.startInstallCert();
|
||||
} else {
|
||||
that.mFaPresenter.startInstallEvidence();
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
userAuthInstance.start();
|
||||
} catch (error) {
|
||||
const err: BusinessError = error as BusinessError;
|
||||
console.log(`auth catch error.code is ${err?.code},message is ${err?.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
checkUserAuth() {
|
||||
try {
|
||||
userAuth.getAvailableStatus(userAuth.UserAuthType.FINGERPRINT, userAuth.AuthTrustLevel.ATL3)
|
||||
this.getIdentity()
|
||||
} catch (error) {
|
||||
const err: BusinessError = error as BusinessError;
|
||||
console.log(`not support.code is ${err.code}, mesage is ${err.message}`);
|
||||
if (err.code === userAuth.UserAuthResultCode.TYPE_NOT_SUPPORT ||
|
||||
err.code === userAuth.UserAuthResultCode.NOT_ENROLLED) {
|
||||
try {
|
||||
userAuth.getAvailableStatus(userAuth.UserAuthType.PIN, userAuth.AuthTrustLevel.ATL3);
|
||||
this.getIdentity();
|
||||
} catch (error) {
|
||||
const err: BusinessError = error as BusinessError;
|
||||
console.log(`not support.code is ${err.code}, mesage is ${err.message}`);
|
||||
if (err.code === userAuth.UserAuthResultCode.NOT_ENROLLED ||
|
||||
err.code === userAuth.UserAuthResultCode.TYPE_NOT_SUPPORT) {
|
||||
if (this.installCertFlag) {
|
||||
this.mFaPresenter.startInstallCert();
|
||||
} else {
|
||||
this.mFaPresenter.startInstallEvidence();
|
||||
}
|
||||
}
|
||||
let titleStr = getContext().resourceManager.getStringSync($r('app.string.Identity_Authentication'));
|
||||
checkUserAuthModel.auth(titleStr, (authResult: boolean) => {
|
||||
if (authResult) {
|
||||
console.log('checkUserAuth success');
|
||||
if (this.installCertFlag) {
|
||||
this.mFaPresenter.startInstallCert();
|
||||
} else {
|
||||
this.mFaPresenter.startInstallEvidence();
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
build() {
|
||||
|
@ -57,7 +57,6 @@
|
||||
"value": "删除所有证书与凭据"
|
||||
},
|
||||
|
||||
|
||||
{
|
||||
"name": "deleteAllCredDialogTitle",
|
||||
"value": "删除所有证书与凭据"
|
||||
@ -288,7 +287,7 @@
|
||||
},
|
||||
{
|
||||
"name": "root_certificate_message",
|
||||
"value": "警告:为网站启用此证书将允许第三方查看发送给网站的任何私人数据"
|
||||
"value": "警告:为网站启用此证书将允许第三方查看发送给网站的任何私人数据。"
|
||||
},
|
||||
{
|
||||
"name": "root_certificate_cancel",
|
||||
@ -384,15 +383,15 @@
|
||||
},
|
||||
{
|
||||
"name": "Install_Error_NOT_FOUND",
|
||||
"value": "无法识别此文件"
|
||||
"value": "无法识别此文件。"
|
||||
},
|
||||
{
|
||||
"name": "Install_ERROR_INCORRECT_FORMAT",
|
||||
"value": "证书已损坏"
|
||||
"value": "证书已损坏。"
|
||||
},
|
||||
{
|
||||
"name": "Install_Error_MAX_QUANTITY_REACHED",
|
||||
"value": "证书数量已达上限,请清理证书"
|
||||
"value": "证书数量已达上限,请清理证书。"
|
||||
},
|
||||
{
|
||||
"name": "OK",
|
||||
|
@ -57,7 +57,6 @@
|
||||
"value": "Delete All Credentials and Certificates"
|
||||
},
|
||||
|
||||
|
||||
{
|
||||
"name": "deleteAllCredDialogTitle",
|
||||
"value": "Delete All Credentials and Certificates"
|
||||
@ -288,7 +287,7 @@
|
||||
},
|
||||
{
|
||||
"name": "root_certificate_message",
|
||||
"value": "Warning: Enabling this certificate for a website will allow third parties to view any private data sent to the website"
|
||||
"value": "Warning: Enabling this certificate for a website will allow third parties to view any private data sent to the website."
|
||||
},
|
||||
{
|
||||
"name": "root_certificate_cancel",
|
||||
@ -372,11 +371,11 @@
|
||||
},
|
||||
{
|
||||
"name": "Install_Cred_Success",
|
||||
"value": "Certificate installation failure"
|
||||
"value": "Install credentials successfully"
|
||||
},
|
||||
{
|
||||
"name": "Install_Cert_Failed",
|
||||
"value": "Install credentials successfully"
|
||||
"value": "Install certificate failure"
|
||||
},
|
||||
{
|
||||
"name": "Install_Cred_Failed",
|
||||
@ -384,15 +383,15 @@
|
||||
},
|
||||
{
|
||||
"name": "Install_Error_NOT_FOUND",
|
||||
"value": "This file is not recognized"
|
||||
"value": "This file is not recognized."
|
||||
},
|
||||
{
|
||||
"name": "Install_ERROR_INCORRECT_FORMAT",
|
||||
"value": "Certificate corrupted"
|
||||
"value": "Certificate corrupted."
|
||||
},
|
||||
{
|
||||
"name": "Install_Error_MAX_QUANTITY_REACHED",
|
||||
"value": "The number of certificates has reached the upper limit. Please clear the certificates"
|
||||
"value": "The number of certificates has reached the upper limit, Please clear the certificates."
|
||||
},
|
||||
{
|
||||
"name": "OK",
|
||||
|
Loading…
x
Reference in New Issue
Block a user