• 动态注册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

  • 相关阅读:
    Minio对象存储
    白话解说TCP/IP协议三次握手和四次挥手
    企业环境下MySQL5.5调优
    Mac下iTerm2配置lrzsz功能
    七牛云图床和Markdown使用
    SSIS: 把存储在数据库中的图片导出来
    关闭Outlook的时候使之最小化
    【转】CTE(公用表表达式)
    通过SSIS监控远程服务器磁盘空间并发送邮件报警
    在Windows Server 2008 R2 中架设 SMTP 服务器
  • 原文地址:https://www.cnblogs.com/moonflow/p/3197160.html
Copyright © 2020-2023  润新知