当前位置:网站首页>超简单集成华为系统完整性检测,搞定设备安全防护
超简单集成华为系统完整性检测,搞定设备安全防护
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
边栏推荐
- echart 设置柱子之间的间距
- High quality defect analysis: let yourself write fewer bugs
- Low power Bluetooth single chip helps Internet of things
- Serilog 源码解析——Sink 的实现
- SEO解决方案制定,如何脱离杯弓蛇影?
- Ubuntu18.04 NAT模式下配置静态IP地址 -2020.11.09
- Flink的安装和测试
- EasyExcel根据筛选列导出(中间不空列,顺序可调整)
- Exhibition cloud technology interpretation | in the face of emergencies, how does app do a good job in crash analysis and performance monitoring?
- 会展云技术解读 | 面对突发事故,APP 如何做好崩溃分析与性能监控?
猜你喜欢
How to choose the development of Biao fan interactive interpretation program?
SEO解决方案制定,如何脱离杯弓蛇影?
MES系统在工厂生产管理起到9大很重要的作用
在Python中创建文字云或标签云
Openyurt in depth interpretation: how to build kubernetes native cloud edge efficient collaborative network?
如何设计并实现存储QoS?
Gesture switch background, let live with goods more immersive
EasyExcel根据筛选列导出(中间不空列,顺序可调整)
How to use Camtasia to make dynamic animation scene?
The internal network penetration of raspberry is built and maintained. No server is required for intranet penetration
随机推荐
5分钟GET我使用Github 5 年总结的这些骚操作!
.NET报表生成器Stimulsoft Reports.Net 发布最新版v2020.5!
Six axes of calibration service
校准服务的六个轴心
MES system is different from traditional management in industry application
Do you think it's easy to learn programming? In fact, it's hard! Do you think it's hard to learn programming? In fact, it's very simple!
用微信表情翻译表白,程序员的小浪漫,赶紧Get起来!
Flash Book curd project
全栈技术实践经历告诉你:开发一个商城小程序要多少钱?
Cad2016 download autocad2016 download installation detailed tutorial CAD Download
Solve the problem that the page does not refresh after the wechat applet uses switchtab to jump
It's so easy to replace the video background with the sound and shadow
flask图书CURD小项目
CAD tutorial cad2016 installation course
浅谈API网关(API Gateway)如何承载API经济生态链
低功耗蓝牙单芯片为物联网助力
详解Git
In the third stage, day16 user module jumps to SSO single sign on jsonp / CORS cross domain user login verification
函数计算进阶-IP查询工具开发
CentOS view the number of CPU cores and cpuinfo analysis