鍍金池/ 教程/ Android/ 更新你的Security Provider來(lái)對(duì)抗SSL漏洞利用
檢測(cè)常用的手勢(shì)
優(yōu)化layout的層級(jí)
用戶(hù)輸入
管理應(yīng)用的內(nèi)存
聯(lián)系人信息
開(kāi)發(fā)輔助程序
Android多媒體
添加語(yǔ)音功能
顯示位置地址
提供向下與橫向?qū)Ш?/span>
支持游戲控制器
訪問(wèn)可穿戴數(shù)據(jù)層
處理多點(diǎn)觸控手勢(shì)
全屏沉浸式應(yīng)用
為多線程創(chuàng)建管理器
數(shù)據(jù)保存
Intent的發(fā)送
更新Notification
優(yōu)化下載以高效地訪問(wèn)網(wǎng)絡(luò)
打印
打包可穿戴應(yīng)用
接收從其他App傳送來(lái)的數(shù)據(jù)
發(fā)送與接收消息
建立靈活動(dòng)態(tài)的UI
處理鍵盤(pán)輸入
Building a Work Policy Controller
建立測(cè)試環(huán)境
創(chuàng)建表盤(pán)
分享文件
顯示Notification進(jìn)度
實(shí)現(xiàn)自適應(yīng)UI流(Flows)
使用設(shè)備管理策略增強(qiáng)安全性
使用能感知版本的組件
執(zhí)行網(wǎng)絡(luò)操作
建立文件分享
添加移動(dòng)
更新你的Security Provider來(lái)對(duì)抗SSL漏洞利用
支持鍵盤(pán)導(dǎo)航
創(chuàng)建和監(jiān)視地理圍欄
發(fā)送并同步數(shù)據(jù)
使用BigView樣式
無(wú)線連接設(shè)備
提供向上導(dǎo)航與歷史導(dǎo)航
最小化定期更新造成的影響
實(shí)現(xiàn)向下的導(dǎo)航
支持不同的屏幕大小
Android 可穿戴應(yīng)用
添加動(dòng)畫(huà)
顯示聯(lián)系人頭像
使用OpenGL ES顯示圖像
處理輸入法可見(jiàn)性
分享文件
保持設(shè)備喚醒
淡化系統(tǒng)Bar
使用NFC分享文件
保存到Preference
Android聯(lián)系人信息與位置信息
創(chuàng)建標(biāo)準(zhǔn)的網(wǎng)絡(luò)請(qǐng)求
使用Drawables
管理Bitmap的內(nèi)存使用
管理Activity的生命周期
按需加載視圖
傳輸資源
為可穿戴設(shè)備創(chuàng)建自定義UI
在一個(gè)線程中執(zhí)行一段特定的代碼
性能優(yōu)化
隱藏導(dǎo)航欄
創(chuàng)建目錄瀏覽器
為多種大小的屏幕進(jìn)行規(guī)劃
View間漸變
使用觸摸手勢(shì)
高效加載大圖
使用CursorLoader在后臺(tái)加載數(shù)據(jù)
創(chuàng)建抽屜式導(dǎo)航(navigation drawer)
管理音頻焦點(diǎn)
創(chuàng)建后臺(tái)服務(wù)
創(chuàng)建功能測(cè)試
創(chuàng)建使用Material Design的應(yīng)用
停止與重啟Activity
添加一個(gè)簡(jiǎn)便的分享功能
啟動(dòng)Activity時(shí)保留導(dǎo)航
TV應(yīng)用清單
創(chuàng)建向后兼容的UI
?# 優(yōu)化自定義View
創(chuàng)建單元測(cè)試
在UI上顯示Bitmap
建立OpenGL ES的環(huán)境
構(gòu)建表盤(pán)服務(wù)
JNI Tips
建立搜索界面
實(shí)現(xiàn)自定義View的繪制
使用HTTPS與SSL
按需操控BroadcastReceiver
分享簡(jiǎn)單的數(shù)據(jù)
繪制形狀
Android位置信息
創(chuàng)建并運(yùn)行可穿戴應(yīng)用
執(zhí)行 Sync Adpater
獲取最后可知位置
創(chuàng)建 Android 項(xiàng)目
實(shí)現(xiàn)高效的導(dǎo)航
退出全屏的Activity
創(chuàng)建Card
兼容音頻輸出設(shè)備
同步數(shù)據(jù)單元
傳輸數(shù)據(jù)時(shí)避免消耗大量電量
保存到文件
緩存Bitmap
提供配置 Activity
調(diào)度重復(fù)的鬧鐘
實(shí)現(xiàn)輔助功能
重復(fù)的下載是冗余的
隱藏狀態(tài)欄
實(shí)現(xiàn)自定義的網(wǎng)絡(luò)請(qǐng)求
規(guī)劃界面和他們之間的關(guān)系
使用Sync Adapter傳輸數(shù)據(jù)
TV應(yīng)用內(nèi)搜索
響應(yīng)觸摸事件
使用Google Cloud Messaging(已廢棄)
控制相機(jī)
Android網(wǎng)絡(luò)連接與云服務(wù)
請(qǐng)求分享一個(gè)文件
處理TV硬件
響應(yīng)UI可見(jiàn)性的變化
使用網(wǎng)絡(luò)服務(wù)發(fā)現(xiàn)
指定輸入法類(lèi)型
優(yōu)化電池壽命
創(chuàng)建TV應(yīng)用
獲取聯(lián)系人列表
拖拽與縮放
啟動(dòng)與停止線程池中的線程
創(chuàng)建 Sync Adpater
使用 WiFi P2P 服務(wù)發(fā)現(xiàn)
開(kāi)始使用Material Design
代理至新的APIs
使用include標(biāo)簽重用layouts
使得View可交互
高效顯示Bitmap
創(chuàng)建企業(yè)級(jí)應(yīng)用
Fragments之間的交互
創(chuàng)建與執(zhí)行測(cè)試用例
綜合:設(shè)計(jì)我們的樣例 App
繪制表盤(pán)
建立簡(jiǎn)單的用戶(hù)界面
自定義動(dòng)畫(huà)
開(kāi)發(fā)輔助服務(wù)
避免出現(xiàn)程序無(wú)響應(yīng)ANR(Keeping Your App Responsive)
使用ViewPager實(shí)現(xiàn)屏幕滑動(dòng)
設(shè)計(jì)高效的導(dǎo)航
Android分享操作(Building Apps with Content Sharing)
提供向后的導(dǎo)航
保持向下兼容
創(chuàng)建TV播放應(yīng)用
縮放View
使用 WiFi 建立 P2P 連接
Android后臺(tái)任務(wù)
連接到網(wǎng)絡(luò)
為 Notification 添加頁(yè)面
使TV應(yīng)用是可被搜索的
添加Action Bar
使用Material的主題
啟動(dòng)另一個(gè)Activity
顯示正在播放卡片
適配不同的系統(tǒng)版本
輕松錄制視頻
創(chuàng)建可穿戴的應(yīng)用
創(chuàng)建自定義的布局
重新創(chuàng)建Activity
使用CursorLoader執(zhí)行查詢(xún)?nèi)蝿?wù)
使用舊的APIs實(shí)現(xiàn)新API的效果
使用備份API
安全要點(diǎn)
Android入門(mén)基礎(chǔ):從這里開(kāi)始
保存并搜索數(shù)據(jù)
根據(jù)網(wǎng)絡(luò)連接類(lèi)型來(lái)調(diào)整下載模式
使用Tabs創(chuàng)建Swipe視圖
SMP(Symmetric Multi-Processor) Primer for Android
解析 XML 數(shù)據(jù)
使用 Volley 傳輸網(wǎng)絡(luò)數(shù)據(jù)
建立ActionBar
Android交互設(shè)計(jì)
使用Intent修改聯(lián)系人信息
增加搜索功能
輕松拍攝照片
定義形狀
測(cè)試你的Activity
在 Notifcation 中接收語(yǔ)音輸入
與其他應(yīng)用的交互
管理系統(tǒng)UI
追蹤手勢(shì)移動(dòng)
Android界面設(shè)計(jì)
執(zhí)行 Android 程序
顯示確認(rèn)界面
創(chuàng)建Lists與Cards
打印HTML文檔
創(chuàng)建TV應(yīng)用
為多屏幕設(shè)計(jì)
定義Shadows與Clipping視圖
使用Fragment建立動(dòng)態(tài)UI
接收Activity返回的結(jié)果
布局變更動(dòng)畫(huà)
定位常見(jiàn)的問(wèn)題
自定義ActionBar的風(fēng)格
定義Layouts
發(fā)送簡(jiǎn)單的網(wǎng)絡(luò)請(qǐng)求
啟動(dòng)與銷(xiāo)毀Activity
與UI線程通信
非UI線程處理Bitmap
創(chuàng)建TV布局
提升Layout的性能
報(bào)告任務(wù)執(zhí)行狀態(tài)
判斷并監(jiān)測(cè)網(wǎng)絡(luò)連接狀態(tài)
兼容不同的設(shè)備
處理按鍵動(dòng)作
優(yōu)化性能和電池使用時(shí)間
給其他App發(fā)送簡(jiǎn)單的數(shù)據(jù)
Implementing App Restrictions
向后臺(tái)服務(wù)發(fā)送任務(wù)請(qǐng)求
展示Card翻轉(zhuǎn)動(dòng)畫(huà)
管理ViewGroup中的觸摸事件
兼容不同的屏幕密度
通過(guò)藍(lán)牙進(jìn)行調(diào)試
為可穿戴設(shè)備創(chuàng)建Notification
控制音量與音頻播放
獲取聯(lián)系人詳情
在表盤(pán)上顯示信息
提供向上的導(dǎo)航
滾動(dòng)手勢(shì)動(dòng)畫(huà)
幫助用戶(hù)在TV上找到內(nèi)容
創(chuàng)建TV導(dǎo)航
為索引指定App內(nèi)容
ActionBar的覆蓋疊加
Android Wear 上的位置檢測(cè)
保護(hù)安全與隱私的最佳策略
Ensuring Compatibility with Managed Profiles
解決云同步的保存沖突
獲取位置更新
創(chuàng)建List
測(cè)試程序
管理網(wǎng)絡(luò)的使用情況
為App內(nèi)容開(kāi)啟深度鏈接
推薦TV內(nèi)容
建立一個(gè)Notification
管理音頻播放
設(shè)計(jì)表盤(pán)
拍照
處理控制器輸入動(dòng)作
判斷并監(jiān)測(cè)設(shè)備的底座狀態(tài)與類(lèi)型
處理查詢(xún)的結(jié)果
保存到數(shù)據(jù)庫(kù)
支持多個(gè)游戲控制器
創(chuàng)建 Stub Content Provider
使得ListView滑動(dòng)順暢
處理數(shù)據(jù)層的事件
創(chuàng)建TV應(yīng)用的第一步
使得你的App內(nèi)容可被Google搜索
將 Notification 放成一疊
創(chuàng)建 Stub 授權(quán)器
暫停與恢復(fù)Activity
管理設(shè)備的喚醒狀態(tài)
Android圖像與動(dòng)畫(huà)
打印照片
云同步
創(chuàng)建TV直播應(yīng)用
為Notification賦加可穿戴特性
提供一個(gè)Card視圖
建立請(qǐng)求隊(duì)列(RequestQueue)
適配不同的語(yǔ)言
創(chuàng)建詳情頁(yè)
測(cè)試UI組件
接收其他設(shè)備的文件
創(chuàng)建自定義View
建立第一個(gè)App
創(chuàng)建2D Picker
監(jiān)測(cè)電池的電量與充電狀態(tài)
打印自定義文檔
抽象出新的APIs
通知提示用戶(hù)
獲取文件信息
運(yùn)用投影與相機(jī)視角
在IntentService中執(zhí)行后臺(tái)任務(wù)
多線程操作
創(chuàng)建一個(gè)Fragment
添加Action按鈕
在不同的 Android 系統(tǒng)版本支持控制器
維護(hù)兼容性
發(fā)送文件給其他設(shè)備
創(chuàng)建TV游戲應(yīng)用
創(chuàng)建自定義的View類(lèi)
代碼性能優(yōu)化建議
Intent過(guò)濾
適配不同的屏幕

更新你的Security Provider來(lái)對(duì)抗SSL漏洞利用

編寫(xiě):craftsmanBai - http://z1ng.net - 原文: http://developer.android.com/training/articles/security-gms-provider.html

安卓依靠security provider保障網(wǎng)絡(luò)通信安全。然而有時(shí)默認(rèn)的security provider存在安全漏洞。為了防止這些漏洞被利用,Google Play services 提供了一個(gè)自動(dòng)更新設(shè)備的security provider的方法來(lái)對(duì)抗已知的漏洞。通過(guò)調(diào)用Google Play services方法,可以確保你的應(yīng)用運(yùn)行在可以抵抗已知漏洞的設(shè)備上。

舉個(gè)例子,OpenSSL的漏洞(CVE-2014-0224)會(huì)導(dǎo)致中間人攻擊,在通信雙方不知情的情況下解密流量。Google Play services 5.0提供了一個(gè)補(bǔ)丁,但是必須確保應(yīng)用安裝了這個(gè)補(bǔ)丁。通過(guò)調(diào)用Google Play services方法,可以確保你的應(yīng)用運(yùn)行在可抵抗攻擊的安全設(shè)備上。

注意:更新設(shè)備的security provider不是更新android.net.SSLCertificateSocketFactory.比起使用這個(gè)類(lèi),我們更鼓勵(lì)應(yīng)用開(kāi)發(fā)者使用融入密碼學(xué)的高級(jí)方法。大多數(shù)應(yīng)用可以使用類(lèi)似HttpsURLConnection,HttpClient,AndroidHttpClient這樣的API,而不必去設(shè)置TrustManager或者創(chuàng)建一個(gè)SSLCertificateSocketFactory

使用ProviderInstaller給Security Provider打補(bǔ)丁

使用providerinstaller類(lèi)來(lái)更新設(shè)備的security provider。你可以通過(guò)調(diào)用該類(lèi)的方法[installIfNeeded()]()(或者[ installifneededasync]())來(lái)驗(yàn)證security provider是否為最新的(必要的話(huà)更新它)。

當(dāng)你調(diào)用[installifneeded]()時(shí),[providerinstaller]()會(huì)做以下事情:

  • 如果設(shè)備的Provider成功更新(或已經(jīng)是最新的),該方法返回正常。

  • 如果設(shè)備的Google Play services 庫(kù)已經(jīng)過(guò)時(shí)了,這個(gè)方法拋出[googleplayservicesrepairableexception]()異常表明無(wú)法更新Provider。應(yīng)用程序可以捕獲這個(gè)異常并向用戶(hù)彈出合適的對(duì)話(huà)框提示更新Google Play services。

  • 如果產(chǎn)生了不可恢復(fù)的錯(cuò)誤,該方法拋出[googleplayservicesnotavailableexception]()表示它無(wú)法更新[Provider]()。應(yīng)用程序可以捕獲異常并選擇合適的行動(dòng),如顯示標(biāo)準(zhǔn)問(wèn)題解決流程圖。

[installifneededasync]()方法類(lèi)似,但它不拋出異常,而是通過(guò)相應(yīng)的回調(diào)方法,以提示成功或失敗。

如果[installifneeded]()需要安裝一個(gè)新的[Provider](),可能耗費(fèi)30-50毫秒(較新的設(shè)備)到350毫秒(舊設(shè)備)。如果security provider已經(jīng)是最新的,該方法需要的時(shí)間量可以忽略不計(jì)。為了避免影響用戶(hù)體驗(yàn):

  • 線程加載后立即在后臺(tái)網(wǎng)絡(luò)線程中調(diào)用[installifneeded](),而不是等待線程嘗試使用網(wǎng)絡(luò)。(多次調(diào)用該方法沒(méi)有害處,如果安全提供程序不需要更新它會(huì)立即返回。)

  • 如果用戶(hù)體驗(yàn)會(huì)受線程阻塞的影響——比如從UI線程中調(diào)用,那么使用[installifneededasync()]()調(diào)用該方法的異步版本。(當(dāng)然,如果你要這樣做,在嘗試任何安全通信之前必須等待操作完成。[providerinstaller]()調(diào)用監(jiān)聽(tīng)者的[onproviderinstalled()]()方法發(fā)出成功信號(hào)。

警告:如果[providerinstaller]()無(wú)法安裝更新Provider,您的設(shè)備security provider會(huì)容易受到已知漏洞的攻擊。你的程序等同于所有HTTP通信未被加密。 一旦[Provider]()更新,所有安全API(包括SSL API)的調(diào)用會(huì)經(jīng)過(guò)它(但這并不適用于[android.net.sslcertificatesocketfactory](),面對(duì)[cve-2014-0224]()這種漏洞仍然是脆弱的)。

同步修補(bǔ)

修補(bǔ)security provider最簡(jiǎn)單的方法就是調(diào)用同步方法[installIfNeeded()](http://developer.android.com/reference/com/google/android/gms/security/ProviderInstaller.html##installIfNeeded(android.content.Context).如果用戶(hù)體驗(yàn)不會(huì)被線程阻塞影響的話(huà),這種方法很合適。

舉個(gè)例子,這里有一個(gè)sync adapter會(huì)更新security provider。由于它運(yùn)行在后臺(tái),因此在等待security provider更新的時(shí)候線程阻塞是可以的。sync adapter調(diào)用installifneeded()更新security provider。如果返回正常,sync adapter可以確保security provider是最新的。如果返回異常,sync adapter可以采取適當(dāng)?shù)男袆?dòng)(如提示用戶(hù)更新Google Play services)。


/**
 * Sample sync adapter using {@link ProviderInstaller}.
 */
public class SyncAdapter extends AbstractThreadedSyncAdapter {

  ...

  // This is called each time a sync is attempted; this is okay, since the
  // overhead is negligible if the security provider is up-to-date.
  @Override
  public void onPerformSync(Account account, Bundle extras, String authority,
      ContentProviderClient provider, SyncResult syncResult) {
    try {
      ProviderInstaller.installIfNeeded(getContext());
    } catch (GooglePlayServicesRepairableException e) {

      // Indicates that Google Play services is out of date, disabled, etc.

      // Prompt the user to install/update/enable Google Play services.
      GooglePlayServicesUtil.showErrorNotification(
          e.getConnectionStatusCode(), getContext());

      // Notify the SyncManager that a soft error occurred.
      syncResult.stats.numIOExceptions++;
      return;

    } catch (GooglePlayServicesNotAvailableException e) {
      // Indicates a non-recoverable error; the ProviderInstaller is not able
      // to install an up-to-date Provider.

      // Notify the SyncManager that a hard error occurred.
      syncResult.stats.numAuthExceptions++;
      return;
    }

    // If this is reached, you know that the provider was already up-to-date,
    // or was successfully updated.
  }
}

異步修補(bǔ)

更新security provider可能耗費(fèi)350毫秒(舊設(shè)備)。如果在一個(gè)會(huì)直接影響用戶(hù)體驗(yàn)的線程中更新,如UI線程,那么你不會(huì)希望進(jìn)行同步更新,因?yàn)檫@可能導(dǎo)致應(yīng)用程序或設(shè)備凍結(jié)直到操作完成。因此你應(yīng)該使用異步方法[installifneededasync()](http://developer.android.com/reference/com/google/android/gms/security/ProviderInstaller.html#installIfNeededAsync(android.content.Context, com.google.android.gms.security.ProviderInstaller.ProviderInstallListener)。方法通過(guò)調(diào)用回調(diào)函數(shù)來(lái)反饋其成功或失敗。 例如,下面是一些關(guān)于更新security provider在UI線程中的活動(dòng)的代碼。調(diào)用installifneededasync()來(lái)更新security provider,并指定自己為監(jiān)聽(tīng)器接收成功或失敗的通知。如果security provider是最新的或更新成功,會(huì)調(diào)用[onproviderinstalled()](http://developer.android.com/reference/com/google/android/gms/security/ProviderInstaller.ProviderInstallListener.html#onProviderInstalled()方法,并且知道通信是安全的。如果security provider無(wú)法更新,會(huì)調(diào)用[onproviderinstallfailed()](http://developer.android.com/reference/com/google/android/gms/security/ProviderInstaller.ProviderInstallListener.html#onProviderInstallFailed(int, android.content.Intent)方法,并采取適當(dāng)?shù)男袆?dòng)(如提示用戶(hù)更新Google Play services)

/**
 * Sample activity using {@link ProviderInstaller}.
 */
public class MainActivity extends Activity
    implements ProviderInstaller.ProviderInstallListener {

  private static final int ERROR_DIALOG_REQUEST_CODE = 1;

  private boolean mRetryProviderInstall;

  //Update the security provider when the activity is created.
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ProviderInstaller.installIfNeededAsync(this, this);
  }

  /**
   * This method is only called if the provider is successfully updated
   * (or is already up-to-date).
   */
  @Override
  protected void onProviderInstalled() {
    // Provider is up-to-date, app can make secure network calls.
  }

  /**
   * This method is called if updating fails; the error code indicates
   * whether the error is recoverable.
   */
  @Override
  protected void onProviderInstallFailed(int errorCode, Intent recoveryIntent) {
    if (GooglePlayServicesUtil.isUserRecoverableError(errorCode)) {
      // Recoverable error. Show a dialog prompting the user to
      // install/update/enable Google Play services.
      GooglePlayServicesUtil.showErrorDialogFragment(
          errorCode,
          this,
          ERROR_DIALOG_REQUEST_CODE,
          new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
              // The user chose not to take the recovery action
              onProviderInstallerNotAvailable();
            }
          });
    } else {
      // Google Play services is not available.
      onProviderInstallerNotAvailable();
    }
  }

  @Override
  protected void onActivityResult(int requestCode, int resultCode,
      Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == ERROR_DIALOG_REQUEST_CODE) {
      // Adding a fragment via GooglePlayServicesUtil.showErrorDialogFragment
      // before the instance state is restored throws an error. So instead,
      // set a flag here, which will cause the fragment to delay until
      // onPostResume.
      mRetryProviderInstall = true;
    }
  }

  /**
   * On resume, check to see if we flagged that we need to reinstall the
   * provider.
   */
  @Override
  protected void onPostResume() {
    super.onPostResult();
    if (mRetryProviderInstall) {
      // We can now safely retry installation.
      ProviderInstall.installIfNeededAsync(this, this);
    }
    mRetryProviderInstall = false;
  }

  private void onProviderInstallerNotAvailable() {
    // This is reached if the provider cannot be updated for some reason.
    // App should consider all HTTP communication to be vulnerable, and take
    // appropriate action.
  }
}