当前位置:网站首页>超简单集成华为系统完整性检测,搞定设备安全防护
超简单集成华为系统完整性检测,搞定设备安全防护
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
边栏推荐
猜你喜欢
Solve the problem that the page does not refresh after the wechat applet uses switchtab to jump
Custom indoor map online tool
SEO solution development, how to break away from the shadow of the bow?
MES系统在工厂生产管理起到9大很重要的作用
超简单集成华为系统完整性检测,搞定设备安全防护
Rongyun has completed several hundred million RMB round D financing, and will continue to build global cloud communication capability
脑机接口先驱炮轰马斯克:“他走的是一条死胡同,说的话我一个字都不同意”
Using GaN based oversampling technique to improve the accuracy of model for mortality prediction of unbalanced covid-19
电商/直播速看!双11跑赢李佳琦就看这款单品了!
零基础小白python入门——深入Python中的文件操作
随机推荐
低功耗蓝牙单芯片为物联网助力
拉线式位移传感器在边坡裂缝中的作用
Program simulation perceptron algorithm (gradient descent method sklearn.linear_ Perception method in model)
Easyexcel exports according to the filter column (not empty in the middle, the order can be adjusted)
Centos7下基于Pseudo-Distributed的Hadoop环境搭建
Toolkit Pro helps interface development: shorten the project development cycle and quickly realize GUI with modern functional area style
(3)ASP.NET Core3.1 Ocelot认证
How to download and install autocad2020 in Chinese
The technology masters who ride the wind and waves gather again | Tencent cloud TVP continues to sail
零基础小白python入门——深入Python中的文件操作
cad教程 cad2016安装教程
企业公司开发微信小程序适用于哪些行业?
MES系统在工厂生产管理起到9大很重要的作用
Git + -- Code hosting in the history of version management
Analysis of h264nalu head
High quality defect analysis: let yourself write fewer bugs
Source code analysis of serilog -- implementation of sink
函数计算进阶-IP查询工具开发
【运维思考】如何做好云上运维服务?
js对象数组去重