了解 Android 应用认证

Understanding Android App certification

我正在慢慢了解 Android 应用程序签名的主题,但我理解的每一步只会引出一个进一步的问题。到目前为止我所了解的(我应该提到我的最终 objective 是在无头 Ubuntu 服务器上自动构建 Phonegap,所以我在下面写的所有内容都使用 Phonegap CLI)

A keystore is a sequence of private-public key pairs each protected with their own password. The keystore as a whole too has its own password. The public key IS the certificate that gets embedded in an APK. One can examine the certificate used in an APK as follows

Generating public-private keypairs is easy. It can even be automated by issuing a simple

echo y | keytool -genkeypair -dname "cn=com.example, ou=OrgUnitName, o=Org Name, c=US" -alias ANY -keypass aliasPwd -keystore /path/to/keystore -storepass keyStorePwd -validity days

我用 Phonegap 构建了一个 release apk,通过短信给自己发送了一个 link,下载并安装了 APK。我的 phone 给了我一些警告,然后安装了我的 APK。酷!

但这让我想知道……。我创建了第二个别名

echo y | keytool -genkeypair -dname "cn=com.microsoft, ou=Microsoft Mobile, o=Microsoft, c=US" -alias msft -keypass msftPwd -keystore /path/to/keystore -storepass keyStorePwd -validity 9999

这次我用 Microsoft 别名重建了 APK,给自己发送了一个 link 然后下载并安装了它(我在这里跳过了一些安装细节)。我的 Android phone 再次给了我一些警告,但似乎并没有过分担心我声称自己是 Microsoft。

我不明白。根据我在 Android 世界中阅读的内容,使用自签名证书是一种常见的做法。所以我可以完全自由地伪装成 microsoft.com 或者其他任何人?

Android Developer docs状态

You should sign all of your apps with the same certificate throughout the expected lifespan of your applications.

那么,如果有一天我将我的一个应用程序的权利卖给了其他人,会发生什么?这将有效地迫使买家重新开始使用新的 Android 应用程序,否则我将不得不向他们出售所有东西,而不仅仅是一个应用程序?

显然,以上都是正在有效处理的漏洞。但是,我完全不清楚应对它们的措施可能是什么。如果有人能解释我的理解和推理的缺陷,我将不胜感激。

So I have complete liberty to masquerade as microsoft.com or indeed anyone else?

这是一个自签名证书。没有人注意你在生成证书时使用的值,更不用说相信它们了。

The Android Developer docs state: "You should sign all of your apps with the same certificate throughout the expected lifespan of your applications."

按照措辞,我不同意该评估。在每个应用程序的预期生命周期内,每个应用程序都需要由相同的证书签名。多个应用程序是否由同一证书签名既是一项业务决策,也是一项技术决策。

So what happens if one day I sell the rights to one of my apps to someone else?

嗯,是吗?

That would either effectively force the buyer to start afresh with a new Android app or else I would be obliged to sell them everything, not just one app?

这就是为什么,如果您预计这可能是您想要做的事情,您会为每个应用程序使用一个单独的证书。例如,顾问绝对应该为每个应用程序制作一份证书(或至少为每个客户制作一份证书)。

相反,如果您正在构建一套应用程序,您特别需要它们之间安全地通信,您可以考虑为套件中的所有应用程序使用一个证书。业务后果是您需要出售整个套件的权利。