| Name | Date | Size | #Lines | LOC | ||
|---|---|---|---|---|---|---|
| .. | - | - | ||||
| AppScope/ | 12-May-2024 | - | 36 | 33 | ||
| entry/ | 12-May-2024 | - | 1,461 | 1,277 | ||
| hvigor/ | 12-May-2024 | - | 24 | 22 | ||
| screenshots/device/ | 12-May-2024 | - | ||||
| .gitignore | D | 12-May-2024 | 119 | 11 | 11 | |
| README.md | D | 12-May-2024 | 2.4 KiB | 31 | 17 | |
| README_zh.md | D | 12-May-2024 | 4.6 KiB | 78 | 48 | |
| build-profile.json5 | D | 12-May-2024 | 1.1 KiB | 42 | 41 | |
| hvigorfile.ts | D | 12-May-2024 | 159 | 2 | 1 | |
| hvigorw | D | 12-May-2024 | 2 KiB | 62 | 53 | |
| hvigorw.bat | D | 12-May-2024 | 2.1 KiB | 80 | 60 | |
| oh-package.json5 | D | 12-May-2024 | 882 | 28 | 26 | |
| ohosTest.md | D | 12-May-2024 | 1.8 KiB | 16 | 12 |
README.md
1# Certificate Framework 2 3### Introduction 4 5This sample shows how `@ohos.security.cert` works to implement the function of verifying signature data. The implementation scenario is as follows: 6 71. Signature verification scenario using correct original data and signature data: Simulate the server obtains the public key through the client certificate, verifies the signature data using the public key, and verifies the client's identity and the integrity of the original data. 82. Scenario of using incorrect original or signature data for signature verification: Simulate an attacker modifying the original or signature data. When the server uses the public key for signature verification, the attacker's identity is untrustworthy or the original data is incomplete, resulting in verification failure. 9 10### Usage 11 121. Click the **Data Display** button, and the correct certificate, original, and signature data contents will be displayed in the text boxes of the page. 13 142. Click the **Signature Verification** button, and a pop-up window will pop up on the page, indicating that **Verification passed**. 15 163. Click the **Modify Original Data** button, and the page will display the modified original data and the correct certificate and signature data; Click the signature verification button, and a pop-up window will pop up on the page, indicating **Verification failed**. 17 184. Click the **Modify Signature Data** button, and the page will display the modified signature data, correct certificate, and original data; Click the signature verification button, and a pop-up window will pop up on the page, indicating **Verification failed**. 195. Click the **Data Display** button to restore the display of correct certificates, original and signature data on the page; Click the **Signature Verification** button, and a pop-up window will pop up on the page, indicating that **Verification passed**. 20 21### Dependency 22 23* [crypto framework.](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis/js-apis-cryptoFramework.md#ohossecuritycryptoframework-%E5%8A%A0%E8%A7%A3%E5%AF%86%E7%AE%97%E6%B3%95%E5%BA%93%E6%A1%86%E6%9E%B6) 24 25### Constraints 26 271. This sample can only be run on standard-system devices. 282. This sample has been adapted to the API version 9 SDK, version number 3.2.12.2. 293. This sample requires DevEco Studio 3.1 Release(Build Version: 3.1.0.500) to compile and run. 30 31
README_zh.md
1# 证书算法库框架 2 3### 介绍 4 5本示例使用了[@ohos.security.cert](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis/js-apis-cert.md)相关接口实现了对签名数据进行校验的功能。 6 7实现场景如下: 8 91)使用**正确**的原始数据和签名数据进行签名校验场景:模拟服务端通过客户端证书获取公钥,利用公钥对签名数据进行校验,验证客户端身份和原始数据完整性。 10 112)使用**错误**的原始数据或签名数据进行签名校验场景:模拟攻击者修改原始数据或签名数据,服务端在利用公钥进行签名校验时,攻击者身份不可信或原始数据不完整,验证失败。 12 13### 效果预览 14 15| 主页 | 校验通过 | 校验失败 | 16|:-------:|:------------------------------------------:|:---------------------------------------:| 17|  |  |  | 18 19使用说明 20 211、点击**数据展示**按钮,页面文本框中分别显示正确的证书、原始和签名数据内容。 22 232、点击**签名校验**按钮,页面弹出弹窗,提示**校验通过**。 24 253、点击**修改原始数据**按钮,页面显示修改后的原始数据和正确的证书、签名数据;点击签名校验按钮,页面弹出弹窗,提示**校验失败**。 26 274、点击**修改签名数据**按钮,页面显示修改后的签名数据和正确的证书、原始数据;点击签名校验按钮,页面弹出弹窗,提示**校验失败**。 28 295、点击**数据展示**按钮,页面恢复正确证书、原始和签名数据的展示;点击**签名校验**按钮,页面弹出弹窗,提示**校验通过**。 30 31### 工程目录 32 33``` 34entry/src/main/ets/ 35|---entryability 36| |---EntryAbility.ts 37|---model 38| |---CertFrameworkModel.ts // 证书算法库框架模型文件 39| |---Logger.ts // 日志文件 40|---pages 41| |---Index.ets // 主界面 42``` 43 44### 具体实现 45 46* 使用证书公钥实现签名校验的功能接口Verify封装在CertFrameworkModel中 47 * 获取证书公钥:首先调用[cert.createX509Cert](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis/js-apis-cert.md#cryptocertcreatex509cert)接口生成证书对象certObject,使用certObject对象的[getPublicKey](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis/js-apis-cert.md#getpublickey)能力获取公钥pubKey;然后调用[cryptoFramework.createAsyKeyGenerator](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis/js-apis-cryptoFramework.md#cryptoframeworkcreateasykeygenerator)接口创建密钥生成器keyGenerator,使用keyGenerator的[convertKey](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis/js-apis-cryptoFramework.md#convertkey-1)能力将公钥pubKey转换为正确的格式。 48 * 使用公钥校验签名:首先调用[cryptoFramework.createVerify](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis/js-apis-cryptoFramework.md#cryptoframeworkcreateverify)接口创建验签对象verifier,使用公钥pubKey对验签对象verifier进行初始化[verifier.init](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis/js-apis-cryptoFramework.md#init-6);然后使用验签对象verifier的[verify](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis/js-apis-cryptoFramework.md#verify-1)能力对签名进行校验。 49 50### 相关权限 51 52不涉及。 53 54### 依赖 55 56* 加解密算法库框架[@ohos.security.cryptoFramework](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis/js-apis-cryptoFramework.md#ohossecuritycryptoframework-%E5%8A%A0%E8%A7%A3%E5%AF%86%E7%AE%97%E6%B3%95%E5%BA%93%E6%A1%86%E6%9E%B6) 57 58### 约束与限制 59 601、本示例仅支持标准系统上运行。 61 622、本示例已适配API version 9版本SDK,版本号:3.2.12.2。 63 643、本示例需要使用DevEco Studio 3.1 Release(Build Version: 3.1.0.500)及以上版本才可编译运行。 65 66### 下载 67 68 如需单独下载本工程,执行如下命令: 69 70``` 71git init 72git config core.sparsecheckout true 73echo code/BasicFeature/Security/CertificateFramework/ > .git/info/sparse-checkout 74git remote add origin https://gitee.com/openharmony/applications_app_samples.git 75git pull origin master 76``` 77 78