简体   繁体   English

Android-证书固定与公钥固定

[英]Android-Certificate pinning vs public key pinning

I am trying to understand how certificate pinning and public key are done.我试图了解证书固定和公钥是如何完成的。 After reading different blog I got more confused about the concept and due to which I am adding this question.I want to know 1.How to implement certificate pinning with an example阅读不同的博客后,我对这个概念更加困惑,因此我添加了这个问题。我想知道 1.How to implement certificate pinning with an example

2.How to implement public key pinning with example 2.如何通过实例实现公钥固定

Certificate or public key pining is just a "whitelist" of excepted connection certificate information so that you can confirm who you connected to is what you expect to be connected to. 证书或公钥密钥只是例外连接证书信息的“白名单”,因此您可以确认您连接的是您希望连接的人。 Basically it can detect man in the middle situations. 基本上它可以在中间情况下检测到人。

Check out as a good general overview. 检查出来是一个很好的概述。

The only difference between certificate pinning and public key pinning is what data you are checking against in your whitelist. 证书固定和公钥固定之间的唯一区别是您在白名单中检查的数据。 Since the certificate contains the public key you can think of the certificate being a superset of the data being checked. 由于证书包含公钥,因此您可以将证书视为正在检查的数据的超集。 What you check will determine how strict you want to be to detecting minor certificate "changes". 您检查的内容将决定您希望检测次要证书“更改”的严格程度。

There are also many ways to implement pinning as outlined in the above link. 如上面的链接所述,还有许多实现固定的方法。 It's just comes down to what you decide to check against and how you store it in a whitelist. 这只取决于您决定检查的内容以及如何将其存储在白名单中。 Since you are talking about Android, the link above mentions a Android recommended way so you may like to look into that. 由于您正在谈论Android,上面的链接提到了Android推荐的方式,因此您可能希望调查一下。

Another implementation you may like to look at is the Mozilla pining implementation which is pinning the public key with a whitelist of sha256 hash of the public key stored in hex form. 您可能希望看到的另一个实现是Mozilla pining实现 ,它使用以十六进制形式存储的公钥的sha256哈希的白名单来固定公钥。

Update: As mentioned by @Robert, certificate pinning should be done in addition to standard certificate chain checking. 更新:如@Robert所述,除标准证书链检查外,还应进行证书锁定。 It should not replace the standard certificate chain checking, specially when pining at the root / intermediate certificate level. 它不应取代标准证书链检查,特别是在根/中间证书级别进行处理时。

Pinning root or intermediate pining can make it less secure but more resilient to certificate changes. 固定根或中间压缩会降低安全性,但对证书更改更具弹性。 Usage of this type of setup depends on why you are using certificate pinning and if you can update your client whitelist easily or not. 此类设置的使用取决于您使用证书固定的原因以及是否可以轻松更新客户端白名单。 These are security trade offs you make based on your specific situation. 这些是您根据具体情况进行的安全权衡。

1.How to implement certificate pinning with an example 1.如何通过一个例子实现证书绑定

In my opinion you shouldn't follow this approach because you need to harcoded the certificates inside the mobile app binary, therefore requiring that each time they are renewed a new version of the mobile needs to be released with some antecedence that will support both certificates and will need to force all users to upgrade.在我看来,您不应该遵循这种方法,因为您需要在移动应用程序二进制文件中对证书进行硬编码,因此要求每次更新它们时都需要发布一个新版本的移动设备,并且需要一些支持证书和将需要强制所有用户升级。 After all users have upgraded you will need to release another version of the mobile app to remove the old certificates.在所有用户升级后,您将需要发布另一个版本的移动应用程序以删除旧证书。

2.How to implement public key pinning with example 2.如何通过实例实现公钥固定

The best approach here is to use the Mobile Certificate Pinning Generator online tool that will create the proper network security config file to add to the Android app.这里最好的方法是使用移动证书锁定生成器在线工具,该工具将创建适当的网络安全配置文件以添加到 Android 应用程序。

I recommend you to read the section Preventing MitM Attacks in this answer I gave to another question where you will learn how to implement static certificate pinning and how to bypass it:我建议您阅读我在另一个问题中给出的这个答案中的Preventing MitM Attacks部分,您将在其中学习如何实现静态证书固定以及如何绕过它:

The easiest and quick way you can go about implementing static certificate pinning in a mobile app is by using the [Mobile Certificate Pinning Generator](Mobile Certificate Pinning Generator) that accepts a list of domains you want to pin against and generates for you the correct certificate pinning configurations to use on Android and iOS.在移动应用程序中实现静态证书固定的最简单快捷的方法是使用 [移动证书固定生成器](移动证书固定生成器),它接受您想要固定的域列表并为您生成正确的在 Android 和 iOS 上使用的证书固定配置。

Give it a list of domains to pin:给它一个要固定的域列表:

移动证书固定生成器网页上的配置选项卡

And the tool generates for you the Android configuration:该工具会为您生成 Android 配置:

Android 证书固定配置

The tool even as instructions how to go about adding the configurations to your mobile app, that you can find below the certificate pinning configuration box.该工具甚至作为如何将配置添加到您的移动应用程序的说明,您可以在证书固定配置框下方找到。 They also provide an hands on example Pin Test App for Android and for iOS that are a step by step tutorial.他们还提供了一个适用于AndroidiOS 的实例 Pin 测试应用程序,这是一个分步教程。

This approach will not require a release of a new mobile app each time the certificate is renewed with the same public key.这种方法不需要每次使用相同的公钥更新证书时都发布新的移动应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM