@react-native-ohos/react-native-sensitive-info 6.0.1-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.OpenSource +11 -0
- package/README.md +13 -0
- package/build/index.es.js +33 -0
- package/build/index.es.js.map +1 -0
- package/build/index.js +35 -0
- package/build/index.js.map +1 -0
- package/harmony/react_native_sensitive_info/BuildProfile.ets +17 -0
- package/harmony/react_native_sensitive_info/build-profile.json5 +28 -0
- package/harmony/react_native_sensitive_info/hvigorfile.ts +6 -0
- package/harmony/react_native_sensitive_info/index.ets +7 -0
- package/harmony/react_native_sensitive_info/obfuscation-rules.txt +18 -0
- package/harmony/react_native_sensitive_info/oh-package.json5 +13 -0
- package/harmony/react_native_sensitive_info/src/main/cpp/CMakeLists.txt +9 -0
- package/harmony/react_native_sensitive_info/src/main/cpp/SensitiveInfoPackage.h +19 -0
- package/harmony/react_native_sensitive_info/src/main/cpp/generated/RNOH/generated/BaseReactNativeSensitiveInfoPackage.h +72 -0
- package/harmony/react_native_sensitive_info/src/main/cpp/generated/RNOH/generated/turbo_modules/SensitiveInfoNativeModule.cpp +24 -0
- package/harmony/react_native_sensitive_info/src/main/cpp/generated/RNOH/generated/turbo_modules/SensitiveInfoNativeModule.h +16 -0
- package/harmony/react_native_sensitive_info/src/main/cpp/generated/react/renderer/components/react_native_sensitive_info/ComponentDescriptors.h +24 -0
- package/harmony/react_native_sensitive_info/src/main/cpp/generated/react/renderer/components/react_native_sensitive_info/EventEmitters.cpp +16 -0
- package/harmony/react_native_sensitive_info/src/main/cpp/generated/react/renderer/components/react_native_sensitive_info/EventEmitters.h +17 -0
- package/harmony/react_native_sensitive_info/src/main/cpp/generated/react/renderer/components/react_native_sensitive_info/Props.cpp +19 -0
- package/harmony/react_native_sensitive_info/src/main/cpp/generated/react/renderer/components/react_native_sensitive_info/Props.h +18 -0
- package/harmony/react_native_sensitive_info/src/main/cpp/generated/react/renderer/components/react_native_sensitive_info/ShadowNodes.cpp +17 -0
- package/harmony/react_native_sensitive_info/src/main/cpp/generated/react/renderer/components/react_native_sensitive_info/ShadowNodes.h +23 -0
- package/harmony/react_native_sensitive_info/src/main/cpp/generated/react/renderer/components/react_native_sensitive_info/States.cpp +16 -0
- package/harmony/react_native_sensitive_info/src/main/cpp/generated/react/renderer/components/react_native_sensitive_info/States.h +19 -0
- package/harmony/react_native_sensitive_info/src/main/ets/Logger.ts +64 -0
- package/harmony/react_native_sensitive_info/src/main/ets/RNSensitiveInfoPackage.ts +46 -0
- package/harmony/react_native_sensitive_info/src/main/ets/RNSensitiveInfoTurboModule.ts +230 -0
- package/harmony/react_native_sensitive_info/src/main/ets/generated/components/ts.ts +5 -0
- package/harmony/react_native_sensitive_info/src/main/ets/generated/index.ets +5 -0
- package/harmony/react_native_sensitive_info/src/main/ets/generated/ts.ts +6 -0
- package/harmony/react_native_sensitive_info/src/main/ets/generated/turboModules/SensitiveInfoNativeModule.ts +34 -0
- package/harmony/react_native_sensitive_info/src/main/ets/generated/turboModules/ts.ts +5 -0
- package/harmony/react_native_sensitive_info/src/main/ets/pages/index.ets +26 -0
- package/harmony/react_native_sensitive_info/src/main/ets/tools.ts +60 -0
- package/harmony/react_native_sensitive_info/src/main/ets/utils/Calc.ets +9 -0
- package/harmony/react_native_sensitive_info/src/main/module.json5 +11 -0
- package/harmony/react_native_sensitive_info/src/main/resources/base/element/color.json +8 -0
- package/harmony/react_native_sensitive_info/src/main/resources/base/element/string.json +16 -0
- package/harmony/react_native_sensitive_info/src/main/resources/base/media/background.png +0 -0
- package/harmony/react_native_sensitive_info/src/main/resources/base/media/foreground.png +0 -0
- package/harmony/react_native_sensitive_info/src/main/resources/base/media/layered_image.json +7 -0
- package/harmony/react_native_sensitive_info/src/main/resources/base/media/startIcon.png +0 -0
- package/harmony/react_native_sensitive_info/src/main/resources/base/profile/main_pages.json +5 -0
- package/harmony/react_native_sensitive_info/src/main/resources/en_US/element/string.json +16 -0
- package/harmony/react_native_sensitive_info/src/main/resources/zh_CN/element/string.json +16 -0
- package/harmony/react_native_sensitive_info/src/mock/mock-config.json5 +2 -0
- package/harmony/react_native_sensitive_info/src/ohosTest/ets/test/Ability.test.ets +41 -0
- package/harmony/react_native_sensitive_info/src/ohosTest/ets/test/List.test.ets +11 -0
- package/harmony/react_native_sensitive_info/src/ohosTest/ets/testability/TestAbility.ets +61 -0
- package/harmony/react_native_sensitive_info/src/ohosTest/ets/testability/pages/Index.ets +23 -0
- package/harmony/react_native_sensitive_info/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ets +98 -0
- package/harmony/react_native_sensitive_info/src/ohosTest/module.json5 +28 -0
- package/harmony/react_native_sensitive_info/src/ohosTest/resources/base/element/color.json +8 -0
- package/harmony/react_native_sensitive_info/src/ohosTest/resources/base/element/string.json +16 -0
- package/harmony/react_native_sensitive_info/src/ohosTest/resources/base/media/icon.png +0 -0
- package/harmony/react_native_sensitive_info/src/ohosTest/resources/base/profile/test_pages.json +5 -0
- package/harmony/react_native_sensitive_info/src/test/List.test.ets +11 -0
- package/harmony/react_native_sensitive_info/src/test/LocalUnit.test.ets +39 -0
- package/harmony/react_native_sensitive_info/ts.ts +9 -0
- package/harmony/react_native_sensitive_info.har +0 -0
- package/index.d.ts +74 -0
- package/package.json +70 -0
- package/react-native-sensitive-info.podspec +19 -0
- package/src/NativeSensitiveInfo.ts +81 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2024 Huawei Device Co., Ltd.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { RNPackage, TurboModulesFactory } from '@rnoh/react-native-openharmony/ts';
|
|
26
|
+
import type { TurboModule, TurboModuleContext } from '@rnoh/react-native-openharmony/ts';
|
|
27
|
+
import { TM } from './generated/ts'
|
|
28
|
+
import { RNSensitiveInfoTurboModule } from './RNSensitiveInfoTurboModule';
|
|
29
|
+
|
|
30
|
+
class RNSensitiveInfoTurboModuleFactory extends TurboModulesFactory {
|
|
31
|
+
createTurboModule(name: string): TurboModule | null {
|
|
32
|
+
if (this.hasTurboModule(name)) {
|
|
33
|
+
return new RNSensitiveInfoTurboModule(this.ctx);
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
hasTurboModule(name: string): boolean {
|
|
38
|
+
return name === TM.SensitiveInfoNativeModule.NAME;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export class RNSensitiveInfoPackage extends RNPackage {
|
|
43
|
+
createTurboModulesFactory(ctx: TurboModuleContext): TurboModulesFactory {
|
|
44
|
+
return new RNSensitiveInfoTurboModuleFactory(ctx);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2024 Huawei Device Co., Ltd.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
import userAuth from '@ohos.userIAM.userAuth';
|
|
25
|
+
import dataPreferences from '@ohos.data.preferences';
|
|
26
|
+
import { BusinessError } from '@ohos.base';
|
|
27
|
+
import { TurboModule } from '@rnoh/react-native-openharmony/ts';
|
|
28
|
+
import { TM } from './generated/ts';
|
|
29
|
+
import cryptoFramework from '@ohos.security.cryptoFramework';
|
|
30
|
+
import buffer from '@ohos.buffer';
|
|
31
|
+
|
|
32
|
+
import Logger from './Logger'
|
|
33
|
+
import { util } from '@kit.ArkTS';
|
|
34
|
+
import { tool } from './tools';
|
|
35
|
+
|
|
36
|
+
let preferences: dataPreferences.Preferences | null = null;
|
|
37
|
+
let tools = new tool()
|
|
38
|
+
const DEFAULT = 'default'
|
|
39
|
+
const UTF8 = 'utf-8'
|
|
40
|
+
let invalidateEnrollment = false;
|
|
41
|
+
|
|
42
|
+
const keyData = new Uint8Array([83, 217, 231, 76, 28, 113, 23, 219, 250, 71, 209, 210, 205, 97, 32, 159])
|
|
43
|
+
|
|
44
|
+
export class RNSensitiveInfoTurboModule extends TurboModule implements TM.SensitiveInfoNativeModule.Spec {
|
|
45
|
+
constructor(ctx) {
|
|
46
|
+
super(ctx);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
stringToArray(str: string): Uint8Array {
|
|
50
|
+
let textEncoder = new util.TextEncoder();
|
|
51
|
+
return textEncoder.encodeInto(str);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
setItem(key: string, value: string, options: TM.SensitiveInfoNativeModule.RNSensitiveInfoOptions): Promise<null> {
|
|
55
|
+
return new Promise(async () => {
|
|
56
|
+
let preferencesName: dataPreferences.Options = { name: this.sharedPreferences(options) };
|
|
57
|
+
preferences = dataPreferences.getPreferencesSync(this.ctx.uiAbilityContext, preferencesName);
|
|
58
|
+
let symKey = await tools.genSymKeyByData(keyData);
|
|
59
|
+
let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(value, UTF8).buffer) };
|
|
60
|
+
let encryptText = await tools.encryptMessagePromise(symKey, plainText);
|
|
61
|
+
preferences.put(key, encryptText.data, (err: BusinessError) => {
|
|
62
|
+
if (err) {
|
|
63
|
+
Logger.error("Failed to put value of 'startup'. code =" + err.code + ", message =" + err.message);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
Logger.info("Succeeded in putting value of 'startup'.");
|
|
67
|
+
})
|
|
68
|
+
preferences.flush((err: BusinessError) => {
|
|
69
|
+
if (err) {
|
|
70
|
+
Logger.error("Failed to flush. code =" + err.code + ", message =" + err.message);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
Logger.info("Succeeded in flushing.");
|
|
74
|
+
})
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
getItem(key: string, options: TM.SensitiveInfoNativeModule.RNSensitiveInfoOptions): Promise<string> {
|
|
79
|
+
return new Promise((res) => {
|
|
80
|
+
let preferencesName: dataPreferences.Options = { name: this.sharedPreferences(options) };
|
|
81
|
+
preferences = dataPreferences.getPreferencesSync(this.ctx.uiAbilityContext, preferencesName);
|
|
82
|
+
let decryptResult: string
|
|
83
|
+
preferences.get(key, DEFAULT, async(err: BusinessError, val: Uint8Array) => {
|
|
84
|
+
if (err) {
|
|
85
|
+
Logger.error("Failed to get value of 'startup'. code =" + err.code + ", message =" + err.message);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
let symKey = await tools.genSymKeyByData(keyData);
|
|
89
|
+
let plainText: cryptoFramework.DataBlob = { data: val };
|
|
90
|
+
let decryptText = await tools.decryptMessagePromise(symKey, plainText);
|
|
91
|
+
if (decryptText.data) {
|
|
92
|
+
decryptResult = buffer.from(decryptText.data).toString(UTF8)
|
|
93
|
+
res(decryptResult)
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async decrypt(value: Uint8Array) {
|
|
100
|
+
let symKey = await tools.genSymKeyByData(keyData);
|
|
101
|
+
let decryptResult: string
|
|
102
|
+
let plainText: cryptoFramework.DataBlob = { data: value };
|
|
103
|
+
let decryptText = await tools.decryptMessagePromise(symKey, plainText);
|
|
104
|
+
if (decryptText.data) {
|
|
105
|
+
decryptResult = buffer.from(decryptText.data).toString(UTF8)
|
|
106
|
+
return decryptResult
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
hasItem(key: string, options: TM.SensitiveInfoNativeModule.RNSensitiveInfoOptions): Promise<boolean> {
|
|
111
|
+
return new Promise(res => {
|
|
112
|
+
let preferencesName: dataPreferences.Options = { name: this.sharedPreferences(options) };
|
|
113
|
+
preferences = dataPreferences.getPreferencesSync(this.ctx.uiAbilityContext, preferencesName);
|
|
114
|
+
preferences.has(key, (err: BusinessError, val: boolean) => {
|
|
115
|
+
if (err) {
|
|
116
|
+
Logger.error("Failed to check the key 'startup'. code =" + err.code + ", message =" + err.message);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (val) { res(true) }
|
|
120
|
+
else { res(false) }
|
|
121
|
+
})
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
getObjKeys(obj: Object): string[] {
|
|
126
|
+
let keys = Object.keys(obj);
|
|
127
|
+
return keys;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
getAllItems(options: TM.SensitiveInfoNativeModule.RNSensitiveInfoOptions): Promise<any> {
|
|
131
|
+
return new Promise((res) => {
|
|
132
|
+
let preferencesName: dataPreferences.Options = { name: this.sharedPreferences(options) };
|
|
133
|
+
preferences = dataPreferences.getPreferencesSync(this.ctx.uiAbilityContext, preferencesName);
|
|
134
|
+
preferences.getAll(async (err: BusinessError, value: Object) => {
|
|
135
|
+
if (err) {
|
|
136
|
+
Logger.error("Failed to get all key-values. code =" + err.code + ", message =" + err.message);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
let allKeys = this.getObjKeys(value);
|
|
140
|
+
let newValues: Object = Object.create(null);
|
|
141
|
+
for (const item of allKeys) {
|
|
142
|
+
newValues[item] = await this.decrypt(value[item]); // 等待异步方法完成
|
|
143
|
+
}
|
|
144
|
+
console.info('key-values:',JSON.stringify(newValues) )
|
|
145
|
+
res(newValues)
|
|
146
|
+
})
|
|
147
|
+
})
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
deleteItem(key: string, options: TM.SensitiveInfoNativeModule.RNSensitiveInfoOptions): Promise<void> {
|
|
151
|
+
return new Promise(() => {
|
|
152
|
+
let preferencesName: dataPreferences.Options = { name: this.sharedPreferences(options) };
|
|
153
|
+
preferences = dataPreferences.getPreferencesSync(this.ctx.uiAbilityContext, preferencesName);
|
|
154
|
+
preferences.delete(key, (err: BusinessError) => {
|
|
155
|
+
if (err) {
|
|
156
|
+
Logger.error("Failed to delete the key 'startup'. code =" + err.code + ", message =" + err.message);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
})
|
|
160
|
+
})
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
isSensorAvailable(): Promise<Object> {
|
|
164
|
+
return new Promise((res) => {
|
|
165
|
+
try {
|
|
166
|
+
if (invalidateEnrollment){
|
|
167
|
+
return
|
|
168
|
+
}
|
|
169
|
+
let userAuthInstance = userAuth.getUserAuthInstance(tools.authParam, tools.widgetParam);
|
|
170
|
+
Logger.info('get userAuth instance success');
|
|
171
|
+
userAuthInstance.start()
|
|
172
|
+
Logger.info('auth start success');
|
|
173
|
+
userAuthInstance.on('result', {
|
|
174
|
+
onResult(result) {
|
|
175
|
+
Logger.info('userAuthInstance callback result = ' + JSON.stringify(result));
|
|
176
|
+
res(result)
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
} catch (error) {
|
|
180
|
+
res(error)
|
|
181
|
+
Logger.error('auth catch error: ' + JSON.stringify(error));
|
|
182
|
+
}
|
|
183
|
+
})
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
hasEnrolledFingerprints(): Promise<boolean> {
|
|
187
|
+
return new Promise((res) => {
|
|
188
|
+
try {
|
|
189
|
+
userAuth.getAvailableStatus(userAuth.UserAuthType.FINGERPRINT, userAuth.AuthTrustLevel.ATL1);
|
|
190
|
+
Logger.info('current auth trust level is supported');
|
|
191
|
+
res(true)
|
|
192
|
+
} catch (error) {
|
|
193
|
+
const err: BusinessError = error as BusinessError;
|
|
194
|
+
res(false)
|
|
195
|
+
Logger.info(`current auth trust level is not supported. Code is ${err?.code}, message is ${err?.message}`);
|
|
196
|
+
}
|
|
197
|
+
})
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
sharedPreferences(options: TM.SensitiveInfoNativeModule.RNSensitiveInfoOptions): string {
|
|
201
|
+
let obj = Object.keys(options)
|
|
202
|
+
let name: string =
|
|
203
|
+
obj.indexOf("sharedPreferencesName") !== -1 ? options.sharedPreferencesName : "shared_preferences";
|
|
204
|
+
if (name == null) {
|
|
205
|
+
name = "shared_preferences";
|
|
206
|
+
}
|
|
207
|
+
return name;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
cancelFingerprintAuth(): void {
|
|
211
|
+
if (invalidateEnrollment){
|
|
212
|
+
return
|
|
213
|
+
}
|
|
214
|
+
try {
|
|
215
|
+
let userAuthInstance = userAuth.getUserAuthInstance(tools.authParam, tools.widgetParam);
|
|
216
|
+
userAuthInstance.off('result', {
|
|
217
|
+
onResult (result) {
|
|
218
|
+
Logger.info('auth off result: ' + JSON.stringify(result));
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
Logger.info('auth off success');
|
|
222
|
+
} catch (error) {
|
|
223
|
+
Logger.error('auth catch error: ' + JSON.stringify(error));
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
setInvalidatedByBiometricEnrollment(set: boolean): void {
|
|
228
|
+
invalidateEnrollment = set
|
|
229
|
+
}
|
|
230
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was generated by "react-native codegen-lib-harmony"
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { Tag } from "@rnoh/react-native-openharmony/ts"
|
|
6
|
+
|
|
7
|
+
export namespace SensitiveInfoNativeModule {
|
|
8
|
+
export const NAME = 'SensitiveInfoNativeModule' as const
|
|
9
|
+
|
|
10
|
+
export type RNSensitiveInfoAndroidDialogStrings = {header?: string, description?: string, hint?: string, success?: string, notRecognized?: string, cancel?: string, cancelled?: string}
|
|
11
|
+
|
|
12
|
+
export type RNSensitiveInfoOptions = {kSecAccessControl?: unknown, kSecAttrAccessible?: unknown, kSecAttrSynchronizable?: boolean, keychainService?: string, sharedPreferencesName?: string, touchID?: boolean, showModal?: boolean, kSecUseOperationPrompt?: string, kLocalizedFallbackTitle?: string, strings?: RNSensitiveInfoAndroidDialogStrings}
|
|
13
|
+
|
|
14
|
+
export interface Spec {
|
|
15
|
+
setItem(key: string, value: string, options: RNSensitiveInfoOptions): Promise<void>;
|
|
16
|
+
|
|
17
|
+
getItem(key: string, options: RNSensitiveInfoOptions): Promise<string>;
|
|
18
|
+
|
|
19
|
+
hasItem(key: string, options: RNSensitiveInfoOptions): Promise<boolean>;
|
|
20
|
+
|
|
21
|
+
getAllItems(options: RNSensitiveInfoOptions): Promise<void>;
|
|
22
|
+
|
|
23
|
+
deleteItem(key: string, options: RNSensitiveInfoOptions): Promise<void>;
|
|
24
|
+
|
|
25
|
+
isSensorAvailable(): Promise<Object>;
|
|
26
|
+
|
|
27
|
+
hasEnrolledFingerprints(): Promise<boolean>;
|
|
28
|
+
|
|
29
|
+
cancelFingerprintAuth(): void;
|
|
30
|
+
|
|
31
|
+
setInvalidatedByBiometricEnrollment(set: boolean): void;
|
|
32
|
+
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
|
|
3
|
+
* Use of this source code is governed by a MIT license that can be
|
|
4
|
+
* found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
@Entry
|
|
8
|
+
@Component
|
|
9
|
+
struct Index {
|
|
10
|
+
@State message: string = 'Hello World';
|
|
11
|
+
|
|
12
|
+
build() {
|
|
13
|
+
RelativeContainer() {
|
|
14
|
+
Text(this.message)
|
|
15
|
+
.id('HelloWorld')
|
|
16
|
+
.fontSize(50)
|
|
17
|
+
.fontWeight(FontWeight.Bold)
|
|
18
|
+
.alignRules({
|
|
19
|
+
center: { anchor: '__container__', align: VerticalAlign.Center },
|
|
20
|
+
middle: { anchor: '__container__', align: HorizontalAlign.Center }
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
.height('100%')
|
|
24
|
+
.width('100%')
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
|
|
3
|
+
* Use of this source code is governed by a MIT license that can be
|
|
4
|
+
* found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import cryptoFramework from '@ohos.security.cryptoFramework';
|
|
8
|
+
import userAuth from '@ohos.userIAM.userAuth';
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
export class tool {
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
widgetParam: userAuth.WidgetParam = {
|
|
15
|
+
title: '请输入密码',
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
authParam: userAuth.AuthParam = {
|
|
19
|
+
challenge: new Uint8Array([49, 49, 49, 49, 49, 49]),
|
|
20
|
+
authType: [userAuth.UserAuthType.FINGERPRINT],
|
|
21
|
+
authTrustLevel: userAuth.AuthTrustLevel.ATL1,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
genIvParamsSpec() {
|
|
25
|
+
let arr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; // 16 bytes
|
|
26
|
+
let dataIv = new Uint8Array(arr);
|
|
27
|
+
let ivBlob: cryptoFramework.DataBlob = { data: dataIv };
|
|
28
|
+
let ivParamsSpec: cryptoFramework.IvParamsSpec = {
|
|
29
|
+
algName: "IvParamsSpec",
|
|
30
|
+
iv: ivBlob
|
|
31
|
+
};
|
|
32
|
+
return ivParamsSpec;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// 分段加密消息
|
|
36
|
+
async encryptMessagePromise(symKey: cryptoFramework.SymKey, plainText: cryptoFramework.DataBlob) {
|
|
37
|
+
let cipher = cryptoFramework.createCipher('AES128|CBC|PKCS7');
|
|
38
|
+
let iv = this.genIvParamsSpec();
|
|
39
|
+
await cipher.init(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, iv);
|
|
40
|
+
let cipherData = await cipher.doFinal(plainText);
|
|
41
|
+
return cipherData;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// 分段解密消息
|
|
45
|
+
async decryptMessagePromise(symKey: cryptoFramework.SymKey, cipherText: cryptoFramework.DataBlob) {
|
|
46
|
+
let decoder = cryptoFramework.createCipher('AES128|CBC|PKCS7');
|
|
47
|
+
let iv = this.genIvParamsSpec();
|
|
48
|
+
await decoder.init(cryptoFramework.CryptoMode.DECRYPT_MODE, symKey, iv);
|
|
49
|
+
let decryptData = await decoder.doFinal(cipherText);
|
|
50
|
+
return decryptData;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async genSymKeyByData(symKeyData: Uint8Array) {
|
|
54
|
+
let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData };
|
|
55
|
+
let aesGenerator = cryptoFramework.createSymKeyGenerator('AES128');
|
|
56
|
+
let symKey = await aesGenerator.convertKey(symKeyBlob);
|
|
57
|
+
console.info('convertKey success');
|
|
58
|
+
return symKey;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"string": [
|
|
3
|
+
{
|
|
4
|
+
"name": "module_desc",
|
|
5
|
+
"value": "module description"
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
"name": "React_native_sensitive_infoAbility_desc",
|
|
9
|
+
"value": "description"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"name": "React_native_sensitive_infoAbility_label",
|
|
13
|
+
"value": "label"
|
|
14
|
+
}
|
|
15
|
+
]
|
|
16
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"string": [
|
|
3
|
+
{
|
|
4
|
+
"name": "module_desc",
|
|
5
|
+
"value": "module description"
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
"name": "React_native_sensitive_infoAbility_desc",
|
|
9
|
+
"value": "description"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"name": "React_native_sensitive_infoAbility_label",
|
|
13
|
+
"value": "label"
|
|
14
|
+
}
|
|
15
|
+
]
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"string": [
|
|
3
|
+
{
|
|
4
|
+
"name": "module_desc",
|
|
5
|
+
"value": "模块描述"
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
"name": "React_native_sensitive_infoAbility_desc",
|
|
9
|
+
"value": "description"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"name": "React_native_sensitive_infoAbility_label",
|
|
13
|
+
"value": "label"
|
|
14
|
+
}
|
|
15
|
+
]
|
|
16
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
|
|
3
|
+
* Use of this source code is governed by a MIT license that can be
|
|
4
|
+
* found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { hilog } from '@kit.PerformanceAnalysisKit';
|
|
8
|
+
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
|
|
9
|
+
|
|
10
|
+
export default function abilityTest() {
|
|
11
|
+
describe('ActsAbilityTest', () => {
|
|
12
|
+
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
|
|
13
|
+
beforeAll(() => {
|
|
14
|
+
// Presets an action, which is performed only once before all test cases of the test suite start.
|
|
15
|
+
// This API supports only one parameter: preset action function.
|
|
16
|
+
})
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
// Presets an action, which is performed before each unit test case starts.
|
|
19
|
+
// The number of execution times is the same as the number of test cases defined by **it**.
|
|
20
|
+
// This API supports only one parameter: preset action function.
|
|
21
|
+
})
|
|
22
|
+
afterEach(() => {
|
|
23
|
+
// Presets a clear action, which is performed after each unit test case ends.
|
|
24
|
+
// The number of execution times is the same as the number of test cases defined by **it**.
|
|
25
|
+
// This API supports only one parameter: clear action function.
|
|
26
|
+
})
|
|
27
|
+
afterAll(() => {
|
|
28
|
+
// Presets a clear action, which is performed after all test cases of the test suite end.
|
|
29
|
+
// This API supports only one parameter: clear action function.
|
|
30
|
+
})
|
|
31
|
+
it('assertContain', 0, () => {
|
|
32
|
+
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
|
|
33
|
+
hilog.info(0x0000, 'testTag', '%{public}s', 'it begin');
|
|
34
|
+
let a = 'abc';
|
|
35
|
+
let b = 'b';
|
|
36
|
+
// Defines a variety of assertion methods, which are used to declare expected boolean conditions.
|
|
37
|
+
expect(a).assertContain(b);
|
|
38
|
+
expect(a).assertEqual(a);
|
|
39
|
+
})
|
|
40
|
+
})
|
|
41
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
|
|
3
|
+
* Use of this source code is governed by a MIT license that can be
|
|
4
|
+
* found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import abilityTest from './Ability.test';
|
|
8
|
+
|
|
9
|
+
export default function testsuite() {
|
|
10
|
+
abilityTest();
|
|
11
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
|
|
3
|
+
* Use of this source code is governed by a MIT license that can be
|
|
4
|
+
* found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
|
|
8
|
+
import { abilityDelegatorRegistry } from '@kit.TestKit';
|
|
9
|
+
import { hilog } from '@kit.PerformanceAnalysisKit';
|
|
10
|
+
import { window } from '@kit.ArkUI';
|
|
11
|
+
import { Hypium } from '@ohos/hypium';
|
|
12
|
+
import testsuite from '../test/List.test';
|
|
13
|
+
|
|
14
|
+
const ON_DESTROY_ERROR = -2;
|
|
15
|
+
|
|
16
|
+
export default class TestAbility extends UIAbility {
|
|
17
|
+
abilityDelegator: abilityDelegatorRegistry.AbilityDelegator;
|
|
18
|
+
|
|
19
|
+
constructor() {
|
|
20
|
+
super();
|
|
21
|
+
this.abilityDelegator = abilityDelegatorRegistry.getAbilityDelegator();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
|
|
25
|
+
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate');
|
|
26
|
+
hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? '');
|
|
27
|
+
hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? '');
|
|
28
|
+
let abilityDelegatorArguments: abilityDelegatorRegistry.AbilityDelegatorArgs;
|
|
29
|
+
abilityDelegatorArguments = abilityDelegatorRegistry.getArguments();
|
|
30
|
+
hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!');
|
|
31
|
+
Hypium.hypiumTest(this.abilityDelegator, abilityDelegatorArguments, testsuite);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
onDestroy() {
|
|
35
|
+
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy');
|
|
36
|
+
this.abilityDelegator.finishTest('TestAbility onDestroy unexpectedly!', ON_DESTROY_ERROR, () => {});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
onWindowStageCreate(windowStage: window.WindowStage) {
|
|
40
|
+
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate');
|
|
41
|
+
windowStage.loadContent('testability/pages/Index', (err) => {
|
|
42
|
+
if (err.code) {
|
|
43
|
+
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.');
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
onWindowStageDestroy() {
|
|
51
|
+
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
onForeground() {
|
|
55
|
+
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
onBackground() {
|
|
59
|
+
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground');
|
|
60
|
+
}
|
|
61
|
+
}
|