当前位置:网站首页>超简单集成华为系统完整性检测,搞定设备安全防护
超简单集成华为系统完整性检测,搞定设备安全防护
2020-11-09 16:56:00 【华为开发者论坛】
在不安全设备,如被root或解锁的手机上,运行应用通常会伴随着一定安全风险,例如被恶意病毒或木马软件利用root权限植入病毒、篡改用户设备信息和破坏系统等。因此,如何做好应用的安全防护、避免在不安全设备环境中产生安全风险,已经成为其开发者必须要考虑的因素。对此,华为开放安全检测服务,提供系统完整性检测(SysIntegrity API),可检测应用运行的设备环境是否安全,如设备是否被root、被解锁等。
一、服务介绍
华为系统完整性检测包括以下特点:
- 基于可信执行环境TEE提供系统完整性检测结果:在设备安全启动时,在TEE中评估检测系统完整性,可信度高,并动态评估系统完整性。
- 系统完整性检测结果安全可信:系统完整性检测结果经过数字证书签名,检测结果不可篡改。
其业务流程图如下图所示:

(1). 你的应用集成HMS Core SDK调用Safety Detect service。 (2). 请求TSMS(Trusted Security Management Service)服务器签名检测结果Server。 (3). 你的应用请求自己服务检测结果。 ---- 结束
二、场景案例介绍
目前已有金融、娱乐、便捷生活、新闻阅读等多个领域的App集成了华为系统完整性检测: 金融类应用集成华为SysIntegrity,可有效提升交易安全性。例如,可以在用户输入信用卡安全码(CVC)时,确认手机的系统环境是否安全。 如手机设备未通过系统完整性检测验证,则不允许使用该应用,以此保护交易安全:


生活、新闻阅读类应用,集成SysIntegrity后可有效防止黑客攻击,确保应用内付费等活动安全:

视频娱乐类应用集成SysIntegrity,可以帮助保护内容版权;当用户注册、观看和下载离线播放视屏时,可以确保用户在内容提供商认可的设备上,完成流媒体和视频播放:

三、开发代码
1 在AppGallery Connect中配置相关信息
在开发应用前,需要在AppGallery Connect中配置相关信息。 具体操作步骤:https://developer.huawei.com/consumer/cn/doc/HMSCore-Guides-V5/config-agc-0000001050416303-V5
2 配置HMS Core SDK的Maven仓地址
2.1 打开Android Studio项目级“build.gradle"文件

2.2 添加HUAWEI agcp插件以及Maven代码库 在allprojects-> repositories里面配置HMS Core SDK的Maven仓地址。
1. allprojects {
2. repositories {
3. google()
4. jcenter()
5. maven {url 'https://developer.huawei.com/repo/'}
6. }
7. }
在buildscript->repositories里面配置HMS Core SDK的Maven仓地址。
1. buildscript {
2. repositories {
3. google()
4. jcenter()
5. maven {url 'https://developer.huawei.com/repo/'}
6. }
7. }
在buildscript ->dependencies里面增加配置。
1. buildscript{
2. dependencies {
3. classpath 'com.huawei.agconnect:agcp:1.3.1.300'
4. }
5. }
3 创建SafetyDetectClient 并生成nonce值
1. // 创建SafetyDetectClient
2. SafetyDetectClient mClient = SafetyDetect.getClient(MainActivity.this);
3. // 生成 nonce值
4. byte[] nonce = new byte[24];
5. try {
6. SecureRandom random;
7. if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
8. random = SecureRandom.getInstanceStrong();
9. } else {
10. random = SecureRandom.getInstance("SHA1PRNG");
11. }
12. random.nextBytes(nonce);
13. } catch (NoSuchAlgorithmException e) {
14. Log.e(TAG, e.getMessage());
15. }
4 创建检测结果监听
1. // 实现OnSuccessListener接口,并从 onSuccess获取检测结果
2. protected class SysIntegrityOnSuccessListener implements OnSuccessListener<SysIntegrityResp> {
3.
4. // 获取系统完整性检测结果
5. @Override
6. public void onSuccess(SysIntegrityResp sysIntegrityResp) {
7.
8. }
9.
10. }
11. // 实现OnFailureListener接口,并从 onFailure异常详情
12. protected class SysIntegrityOnFailureListener implements OnFailureListener {
13. // 获取异常错误码已经异常详情
14. @Override
15. public void onFailure(Exception e) {
16.
17. }
18. }
5 调用系统完整性检测
1. // 调用系统完整性检测接口,********传入appid
2. Task task = mClient.sysIntegrity(nonce,"********");
3. task.addOnSuccessListener(new SysIntegrityOnSuccessListener()).addOnFailureListener(new SysIntegrityOnFailureListener());
6 结果验证
服务器中验证系统完整性检测结果可以参考开发者联盟官网。
DEMO演示

如果你对实现方式感兴趣,可以参考Github源码链接:https://github.com/HMS-Core/hms-safetydetect-demo-android
更详细的开发指南,请参考华为开发者联盟官网: 华为开发者联盟:https://developer.huawei.com/consumer/cn/doc/development/HMSCore-Guides/dysintegritydevelopment-0000001050156331
下载demo和示例代码请到Github:https://github.com/HMS-Core
解决集成问题请到Stack Overflow: https://stackoverflow.com/questions/tagged/huawei-mobile-services?tab=Newest
原文链接:https://developer.huawei.com/consumer/cn/forum/topic/0201393882637910006?fid=18
原作者:晚上吃啥
版权声明
本文为[华为开发者论坛]所创,转载请带上原文链接,感谢
https://my.oschina.net/u/4478396/blog/4710178
边栏推荐
- 使用基于GAN的过采样技术提高非平衡COVID-19死亡率预测的模型准确性
- 谈谈敏捷开发概念和迭代开发方案
- How to use Camtasia to make dynamic animation scene?
- 程序模拟感知机算法(梯度下降法、sklearn.linear_model中perception方法)
- 标梵IPFS矿机app软件开发软件 IPFSApp开发方法详解
- How about Tencent cloud amd cloud server?
- Using GaN based oversampling technique to improve the accuracy of model for mortality prediction of unbalanced covid-19
- 揭秘在召唤师峡谷中移动路径选择逻辑?
- Knowledge mapping 1.1 -- starting from NER
- 5分钟GET我使用Github 5 年总结的这些骚操作!
猜你喜欢

5分钟GET我使用Github 5 年总结的这些骚操作!

缓存的数据一致性

Talking about PHP file fragment upload from a requirement improvement

Program simulation perceptron algorithm (gradient descent method sklearn.linear_ Perception method in model)

High quality defect analysis: let yourself write fewer bugs

Openyurt in depth interpretation: how to build kubernetes native cloud edge efficient collaborative network?

Explore cache configuration of Android gradle plug-in

The selection of wire displacement encoder needs the guidance of precise electronics

程序模拟感知机算法(梯度下降法、sklearn.linear_model中perception方法)

Super discount, cloud server 88 yuan seconds
随机推荐
Function calculation advanced IP query tool development
明年起旧版本安卓设备将无法浏览大约30%的网页
How about Tencent cloud amd cloud server?
自己实现printf函数
Source code analysis of serilog -- implementation of sink
MES system is different from traditional management in industry application
echart 设置柱子之间的间距
Kubernetes-17: kubernets package management tool -- Introduction and use of Helm
Mobile security reinforcement helps app achieve comprehensive and effective security protection
.NET报表生成器Stimulsoft Reports.Net 发布最新版v2020.5!
Openyurt in depth interpretation: how to build kubernetes native cloud edge efficient collaborative network?
融云集成之避坑指南-Android推送篇
5分钟GET我使用Github 5 年总结的这些骚操作!
Using fastai to develop and deploy image classifier application
从一次需求改良漫谈php文件分片上传
Gesture switch background, let live with goods more immersive
QML Repeater
低功耗蓝牙单芯片为物联网助力
Cad2016 software installation tutorial
自定义室内地图在线工具