Android 安全与权限Word文档格式.docx
- 文档编号:6333539
- 上传时间:2023-05-06
- 格式:DOCX
- 页数:23
- 大小:32.77KB
Android 安全与权限Word文档格式.docx
《Android 安全与权限Word文档格式.docx》由会员分享,可在线阅读,更多相关《Android 安全与权限Word文档格式.docx(23页珍藏版)》请在冰点文库上搜索。
sprivatedata(suchascontactsore-mails),readingorwritinganotherapplication'
sfiles,performingnetworkaccess,keepingthedeviceawake,etc.
安全架构
Android安全架构中一个中心思想就是:
应用程序在默认的情况下不可以执行任何对其他应用程序,系统或者用户带来负面影响的操作。
这包括读或写用户的私有数据(如联系人数据或email数据),读或写另一个应用程序的文件,网络连接,保持设备处于非睡眠状态。
Anapplication'
sprocessisasecuresandbox.Itcan'
tdisruptotherapplications,exceptbyexplicitlydeclaringthepermissionsitneedsforadditionalcapabilitiesnotprovidedbythebasicsandbox.Thesepermissionsitrequestscanbehandledbytheoperatinginvariousways,typicallybyautomaticallyallowingordisallowingbasedoncertificatesorbypromptingtheuser.Thepermissionsrequiredbyanapplicationaredeclaredstaticallyinthatapplication,sotheycanbeknownup-frontatinstalltimeandwillnotchangeafterthat.
一个应用程序的进程就是一个安全的沙盒。
它不能干扰其它应用程序,除非显式地声明了"
permissions"
,以便它能够获取基本沙盒所不具备的额外的能力。
它请求的这些权限"
可以被各种各样的操作处理,如自动允许该权限或者通过用户提示或者证书来禁止该权限。
应用程序需要的那些"
是静态的在程序中声明,所以他们会在程序安装时就被知晓,并不会再改变。
ApplicationSigning
AllAndroidapplications(.apkfiles)mustbesignedwithacertificatewhoseprivatekeyisheldbytheirdeveloper.Thiscertificateidentifiestheauthoroftheapplication.Thecertificatedoesnotneedtobesignedbyacertificateauthority:
itisperfectlyallowable,andtypical,forAndroidapplicationstouseself-signedcertificates.Thecertificateisusedonlytoestablishtrustrelationshipsbetweenapplications,notforwholesalecontroloverwhetheranapplicationcanbeinstalled.Themostsignificantwaysthatsignaturesimpactsecurityisbydeterminingwhocanaccesssignature-basedpermissionsandwhocanshareuserIDs.
所有的Android应用程序(.apk文件)必须用证书进行签名认证,而这个证书的私钥是由开发者保有的。
该证书可以用以识别应用程序的作者。
该证书也不需要CA签名认证(注:
CA就是一个第三方的证书认证机构,如verisign等)。
Android应用程序允许而且一般也都是使用self-signed证书(即自签名证书)。
证书是用于在应用程序之间建立信任关系,而不是用于控制程序是否可以安装。
签名影响安全性的最重要的方式是通过决定谁可以进入基于签名的permisssions,以及谁可以share用户IDs。
UserIDsandFileAccess
EachAndroidpackage(.apk)fileinstalledonthedeviceisgivenitsownuniqueLinuxuserID,creatingasandboxforitandpreventingitfromtouchingotherapplications(orotherapplicationsfromtouchingit).ThisuserIDisassignedtoitwhentheapplicationisinstalledonthedevice,andremainsconstantforthedurationofitslifeonthatdevice.
用户IDs和文件存取
每一个Android应用程序(.apk文件)都会在安装时就分配一个独有的Linux用户ID,这就为它建立了一个沙盒,使其不能与其他应用程序进行接触(也不会让其它应用程序接触它)。
这个用户ID会在安装时分配给它,并在该设备上一直保持同一个数值。
Becausesecurityenforcementhappensattheprocesslevel,thecodeofanytwopackagescannotnormallyruninthesameprocess,sincetheyneedtorunasdifferentLinuxusers.YoucanusethesharedUserIdattributeintheAndroidManifest.xml'
smanifesttagofeachpackagetohavethemassignedthesameuserID.Bydoingthis,forpurposesofsecuritythetwopackagesarethentreatedasbeingthesameapplication,withthesameuserIDandfilepermissions.Notethatinordertoretainsecurity,onlytwoapplicationssignedwiththesamesignature(andrequestingthesamesharedUserId)willbegiventhesameuserID.
由于安全性限制措施是发生进程级,所以两个package中的代码不会运行在同一个进程当中,他们要作为不同的Linux用户出现。
我们可以通过使用AndroidManifest.xml文件中的manifest标签中的sharedUserId属性,来使不同的package共用同一个用户ID。
通过这种方式,这两个package就会被认为是同一个应用程序,拥有同一个用户ID(实际不一定),并且拥有同样的文件存取权限。
注意:
为了保持安全,只有当两个应用程序被同一个签名签署的时候(并且请求了同一个sharedUserId)才会被分配同样的用户ID.
Anydatastoredbyanapplicationwillbeassignedthatapplication'
suserID,andnotnormallyaccessibletootherpackages.WhencreatinganewfilewithgetSharedPreferences(String,int),openFileOutput(String,int),oropenOrCreateDatabase(String,int,SQLiteDatabase.CursorFactory),youcanusetheMODE_WORLD_READABLEand/orMODE_WORLD_WRITEABLEflagstoallowanyotherpackagetoread/writethefile.Whensettingtheseflags,thefileisstillownedbyyourapplication,butitsglobalreadand/orwritepermissionshavebeensetappropriatelysoanyotherapplicationcanseeit.
所有存储在应用程序中的数据都会赋予一个属性-该应用程序的用户ID,这使得其他package无法访问这些数据。
当通过这些方法getSharedPreferences(String,int),openFileOutput(String,int),oropenOrCreateDatabase(String,int,SQLiteDatabase.CursorFactory)来创建一个新文件时,你可以通过使用MODE_WORLD_READABLEand/orMODE_WORLD_WRITEABLE标志位来设置是否允许其他package来访问读写这个文件。
当设置这些标志位时,该文件仍然属于该应用程序,但是它的globalreadand/orwrite权限已经被设置,使得它对于其他任何应用程序都是可见的。
AbasicAndroidapplicationhasnopermissionsassociatedwithit,meaningitcannotdoanythingthatwouldadverselyimpacttheuserexperienceoranydataonthedevice.Tomakeuseofprotectedfeaturesofthedevice,youmustincludeinyourAndroidManifest.xmloneormore<
uses-permission>
tagsdeclaringthepermissionsthatyourapplicationneeds.
一个基本的Android程序通常是没有任何permissions与之关联的,这就是说它不能做任何扰乱用户或破坏数据的勾当。
那么为了使用设备被保护的features,我们就必须在AndroidManifest.xml添加一个或多个<
标签,用以声明你的应用程序需要的permissions.
下面是个例子,不翻译啦!
Forexample,anapplicationthatneedstomonitorincomingSMSmessageswouldspecify:
<
manifestxmlns:
android="
package="
com.android.app.myapp"
>
<
uses-permissionandroid:
name="
android.permission.RECEIVE_SMS"
/>
/manifest>
Atapplicationinstalltime,permissionsrequestedbytheapplicationaregrantedtoitbythepackageinstaller,basedonchecksagainstthesignaturesoftheapplicationsdeclaringthosepermissionsand/orinteractionwiththeuser.Nocheckswiththeuseraredonewhileanapplicationisrunning:
iteitherwasgrantedaparticularpermissionwheninstalled,andcanusethatfeatureasdesired,orthepermissionwasnotgrantedandanyattempttousethefeaturewillfailwithoutpromptingtheuser.
应用程序按照的时候,应用程序请求的permissions是通过packageinstaller来批准获取的。
packageinstaller是通过检查该应用程序的签名和/或用户的交换结果来确定是否给予该程序request的权限。
在用户使用过程中不会去检查权限,也就是说要么在安装的时候就批准该权限,使其按照设计可以使用该权限;
要么就不批准,这样用户也就根本无法使用该feature,也不会有任何提示告知用户尝试失败。
OftentimesapermissionfailurewillresultinaSecurityExceptionbeingthrownbacktotheapplication.However,thisisnotguaranteedtooccureverywhere.Forexample,thesendBroadcast(Intent)methodcheckspermissionsasdataisbeingdeliveredtoeachreceiver,afterthemethodcallhasreturned,soyouwillnotreceiveanexceptioniftherearepermissionfailures.Inalmostallcases,however,apermissionfailurewillbeprintedtothesystemlog.
很多时候,一个permissionfailure会导致一个SecurityException被抛回该应用程序.但是Android并不保证这种情况会处处发生。
例如,当数据被deliver到每一个receiver的时候,sendBroadcast(Intent)方法会去检查permissions,在这个方法调用返回之后,你也不会收到任何exception。
几乎绝大多数情况,一个permissionfailure都会打印到log当中。
ThepermissionsprovidedbytheAndroidsystemcanbefoundatManifest.permission.Anyapplicationmayalsodefineandenforceitsownpermissions,sothisisnotacomprehensivelistofallpossiblepermissions.
Android系统定义的权限可以在Manifest.permission中找到。
任何一个程序都可以定义并强制执行自己独有的permissions,因此Manifest.permission中定义的permissions并不是一个完整的列表(即有肯能有自定义的permissions)。
Aparticularpermissionmaybeenforcedatanumberofplacesduringyourprogram'
soperation:
一个特定的permission可能会在程序操作的很多地方都被强制实施:
Atthetimeofacallintothesystem,topreventanapplicationfromexecutingcertainfunctions.
当系统有来电的时候,用以阻止程序执行其它功能。
Whenstartinganactivity,topreventapplicationsfromlaunchingactivitiesofotherapplications.
当启动一个activity的时候,会阻止应用程序启动其它应用的Acitivity。
Bothsendingandreceivingbroadcasts,tocontrolwhocanreceiveyourbroadcastorwhocansendabroadcasttoyou.
在发送和接收广播的时候,去控制谁可以接收你的广播或谁可以发送广播给你。
Whenaccessingandoperatingonacontentprovider.
当进入并操作一个contentprovider的时候
Bindingorstartingaservice.
当绑定或开始一个service的时候
DeclaringandEnforcingPermissions声明和实施permissions
Toenforceyourownpermissions,youmustfirstdeclaretheminyour
AndroidManifest.xml
usingoneormore
permission>
tags.
Forexample,anapplicationthatwantstocontrolwhocanstartoneofitsactivitiescoulddeclareapermissionforthisoperationasfollows:
为了实现你自己的permissions,你必须首先在AndroidManifest.xml文件中声明该permissions.通常我们通过使用一到多个<
tag来进行声明。
下面例子说明了一个应用程序它想控制谁才可以启动它的Activity:
Java代码
1.<
manifest
xmlns:
2.
package="
com.me.app.myapp"
>
3.
4.
permission
android:
com.me.app.myapp.permission.DEADLY_ACTIVITY"
5.
label="
@string/permlab_deadlyActivity"
6.
description="
@string/permdesc_deadlyActivity"
7.
permissionGroup="
android.permission-group.COST_MONEY"
8.
protectionLevel="
dangerous"
/>
9.
10.<
The
protectionLevel>
attributeisrequired,tellingthesystemhowtheuseristobeinformedofapplicationsrequiringthepermission,orwhoisallowedtoholdthatpermission,asdescribedinthelinkeddocumentation.
permissionGroup>
attributeisoptional,andonlyusedtohelpthesystemdis
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Android 安全与权限 安全 权限