• 动态注册broadcast的安全考虑


    一、android service通知activity更新
    方式有
    1. service 通过广播的形式发送broadcast,向这个activity的内部类发广播的消息来更新界面
    2. service直接向activity发intent,把activity的launchMode设置为singleInstance

    二、安全性
    这边关注第1种方式的广播和接收intent安全,如果不对广播的发送和接收进行判断,会有很大的安全隐患
    在我的场景中,是动态注册broadcast,考虑安全如下:

    A、针对sendBroadcast
    1.通常采用的安全方式有setPackage设置包名
    intent.setAction("com.example.tianqitong.recv");
    intent.setPackage("com.example.tianqitong");
    sendBroadcast(intent);

    2.可以通过使用LocalBroadcastManager,确保了应用程序外部的任何组件都收不到你广播的Intent

    3.设置权限
    sendBroadcast(intent,"broadcast.permission");

    还要加上android:protectionLevel权限级别

    <uses-permission android:name="broadcast.permission" /> //声明使用权限
    <permission android:name="broadcast.permission" android:protectionLevel="signature" /> //自定义权限

    B、针对Receive
    1.可以通过使用LocalBroadcastManager,使其他应用程序也不能向你的接收器发送广播

    2.对于动态注册的广播可以通过类似registerReceiver(BroadcastReceiver, IntentFilter, String, android.os.Handler)的接口指定发送者必须具备的permission
    其中string为指定的permission,必须加android:protectionLevel
    譬如:
    <permission android:name="broadcast.permission" android:protectionLevel="signature" />


    参考:
    http://blog.csdn.net/t12x3456/article/details/9256609
    http://blog.csdn.net/hotdogzu/article/details/7940820
    http://blog.csdn.net/abc13939746593/article/details/8186916
    http://my.eoe.cn/weiblog/archive/4590.html
    http://www.sectop.com/?p=187
    https://developer.android.com/training/articles/security-tips.html
    https://developer.android.com/reference/android/content/BroadcastReceiver.html#Security
    http://book.51cto.com/art/201304/389200.htm

  • 相关阅读:
    excel 读取
    MSDN异步编程概述 [C#] zzhttp://www.cnblogs.com/hxhbluestar/articles/60023.html
    window.opener showModelessDialog showModalDialog 获取|控制父窗体的区别
    MySql中文乱码解决方法
    关于随机数
    javascript 日期处理(注意事项)
    一个简单访问office程序的控件,不依赖officedll
    关于12306的bug
    回车提交
    js动态添加外部js(顶)
  • 原文地址:https://www.cnblogs.com/moonflow/p/3197160.html
Copyright © 2020-2023  润新知