如何验证使用自签名证书签名的二进制文件?
我们希望向我们的应用程序添加自动软件更新,但我们公司尚未准备好从受信任的根 CA 购买代码签名证书,因此我们将使用自签名证书来签署代码更新(.exe和.dll)现在。
问题:如何使用 Microsoft 的加密 API 验证使用自签名证书签名的二进制文件,而无需安装证书? 要检查的 .cer 文件将与应用程序捆绑在一起。 或者使用通用的加密库更简单?
We want to add automatic software updates to our application, but our company isn't yet ready to buy a code-signing certificate from a trusted root CA, so we'll be using a self-signed certificate to sign code updates (.exe and .dll) for now.
Question: how to verify a binary signed with a self-signed certificate, without having to install the certificate, using Microsoft's Cryptography API? The .cer file to check against will be bundled with the application. Or is it simpler to use a generic Crypto library?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以跳过整个 X509 的事情,毕竟如果你要使用自己的证书,你并不真正需要它......
对于你想做的事情,首先你必须生成你的 RSA 私钥/公钥对。 然后将公钥存储在您的应用程序中。
当您有更新时,您可以通过获取 MD5 或 SHA-1 或您想要使用的任何哈希值在您的网站上对其进行签名; 然后你用私钥加密该哈希值。 安装的应用程序获取更新和签名(加密的哈希值); 当应用程序获取二进制文件时,它会计算其哈希值,然后使用公钥解密另一个文件并进行比较。 如果它们相同,那么这是一个有效的更新,否则您会拒绝它并警告用户或其他内容。
对于自签名的 X509 证书,机制将完全相同,但公钥将具有一堆附加数据,例如颁发者的身份,这将与证书的身份相同。
You can skip the whole X509 thing, after all you don't really need it if you're going to be using your own certificates...
For what you want to do, first you have to generate your RSA private/public key pair. Then you store the public key in your application.
When you have an update, you sign it on your site, by getting the MD5 or SHA-1 or whatever hash you want to use; then you encrypt that hash with the private key. The installed applications fetch the update and the signature (the encrypted hash); when the application gets the binary file, it computes its hash, then decrypts the other one using the public key and compares them. If they're identical then it's a valid update, otherwise you reject it and warn the user or something.
With X509 certificates that are self-signed the mechanism is going to be exactly that, but the public key is going to have a bunch of additional data like the identity of the issuer which will be the same identity of the certificate.
我似乎记得几年前听说过一种启用自签名证书的方法,回到 Win2k 时代,但它非常老套,根本不适合公共部署,并且可能已被“修复”。 如果您确实考虑使用其他加密库,或开发自己的加密库,请小心:很难区分好的加密和坏的加密。
I seem to recall hearing of a way to enable self-signed certs some years ago, back in the Win2k days, but it was very hacky, not at all suitable for public deployment and has probably been "fixed". If you do think about using some other crypto library, or developing your own, take care: it's very hard to distinguish good crypto from bad crypto.