当前位置:网站首页>超简单集成华为系统完整性检测,搞定设备安全防护
超简单集成华为系统完整性检测,搞定设备安全防护
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
边栏推荐
- Simple use of AE (after effects)
- I do digital transformation in traditional industries (1)
- 使用Fastai开发和部署图像分类器应用
- It's so easy to replace the video background with the sound and shadow
- Implement printf function by yourself
- How to design and implement storage QoS?
- The latest version of pycharm 2020.3: pair programming, intelligent text proofreading and downloading experience
- 自定义室内地图在线工具
- Program simulation perceptron algorithm (gradient descent method sklearn.linear_ Perception method in model)
- Why is your money transferred? This article tells you the answer
猜你喜欢

Exhibition cloud technology interpretation | in the face of emergencies, how does app do a good job in crash analysis and performance monitoring?

EasyExcel根据筛选列导出(中间不空列,顺序可调整)

How to download and install autocad2020 in Chinese

Full stack technology experience tells you: how much does it cost to develop a mall small program?

On agile development concept and iterative development scheme

浮点数之间的等值判断

融云集成之避坑指南-Android推送篇

零基础小白python入门——深入Python中的文件操作

(3) ASP.NET Core3.1 Ocelot certification

Flink的安装和测试
随机推荐
Centos7下基于Pseudo-Distributed的Hadoop环境搭建
低功耗蓝牙单芯片为物联网助力
H264Nalu头部解析
5 minutes get I use GitHub's 5-year summary of these operations!
轻松构建高颜值应用界面,这些内置图标多重要!
从一次需求改良漫谈php文件分片上传
The latest version of pycharm 2020.3: pair programming, intelligent text proofreading and downloading experience
Kubernetes-17:Kubernets包管理工具—&gt;Helm介绍与使用
cad教程 cad2016安装教程
MES系统在行业应用里区别于传统式管理
Express yourself with wechat expression translation, programmer's little romance, get up quickly!
Source code analysis of serilog -- implementation of sink
Equivalent judgment between floating point numbers
用微信表情翻译表白,程序员的小浪漫,赶紧Get起来!
[share] interface tests how to transfer files in post request
Why does it take more and more time to develop a software?
融云集成之避坑指南-Android推送篇
It's so easy to replace the video background with the sound and shadow
Revealing the logic of moving path selection in Summoner Canyon?
Simple use of AE (after effects)