代码签名与加密

Code Signing vs. Encryption

所以,我正在寻求一些帮助,主要是了解代码签名和加密的过程,因为我在这两个主题上仍然犹豫不决。

我认为我明白了:

问题:当我使用证书签署代码时,负载是否也会被加密?这与网站的 SSL 安全性有何不同,可确保连接的安全性和隐私性?他们似乎都使用相同的技术来完成许多不同的任务。

稍后我会在这里逐点回应一些关于误解的总结/注释:

First thing needed is a KEY, which is generated using some encryption algorithm (RSA/SHA1/etc)

是的,关键是开始。实际上,在签名的情况下,它是一个密钥对——您正在生成一个 public / 私钥对。私密的部分你留着,public的部分大家可能都知道。对算法的小修正 - Sha1 用于散列,而不是用于加密。所以对于证书,它通常是 RSA/DSA/ECDSA。

With this key we create a certificate signing request or CSR (something to do with X509?) which holds all of our information that will be on the certificate (Name, Location, Email, Domain)

是的,要获得典型的网站证书(x509 标准),您需要签名请求/CSR/PKCS#11(同样的事情)。

Both the KEY and the CSR get sent to the Root CA who then issues a certificate - in the form of a .pem or .p12 file (using the CSR and key for generation).

不,只有密钥的 public 部分(已包含在 CSR 中)被发送到颁发证书的 CA。除了您,没有人需要私钥。

Something about intermediate CAs and more certificates

根 CA 不会签署您的证书(出于与提高安全性和保持离线相关的各种原因)。中间 CA 会这样做,并且它们由根 CA 签名。这意味着如果你想使用你的证书来保护浏览器的流量,你通常需要包含中间证书。您可以通过检查 https://www.ssllabs.com/ssltest/ 来验证是否一切就绪 - 它会告诉您链中是否缺少某些证书。

This cert can then be used in addition to the intermediate CAs to sign a file so that it basically has your name on it and recipients can be assured it's the what you intended them to receive.

是的。它可用于签署文件(S/MIME 格式),但也可用于协商安全的互联网连接。

The public key inside of the certificate is used to encrypt the contents of the file using aes and as a result the certificate must be installed on the destination before installing the encrypted file. (this seems secure but not what people would want, secret code that people can't read or decode but still has function)

您描述的更像是 DRM。只有拥有密钥的人才能读取该文件,但从安全角度来看,这没有多大意义,因为您需要首先将密钥提供给他们。你可以把程序弄得更复杂更混乱,但最终他们还是要知道另一部分的关键。

此外,即使在那种情况下,您也应该分发 public 密钥,而不是私钥。您可以从您的私钥生成您的 public 密钥,但反之则不行。

I guess it makes sense that you can't make the file entirely encrypted because it needs to be decoded to be executed on the target. Am I off on this?

你是对的。安全执行加密软件的唯一方法是将执行引擎/密钥置于软件无法触及的地方——例如嵌入硬件中。这对于纯软件解决方案是不现实的。

When I sign code using a certificate, does the payload also get encrypted?

负载是什么意思?

  • 应用程序发送的数据 - 没有。这需要明确地完成
  • 应用程序代码 - 没有。它没有加密,签名唯一说明的是拥有证书的人签署了代码并且之后没有更改。或者更准确地说,某种哈希值是从应用程序二进制文件中计算出来的,并且该短哈希值是用您的私钥加密的。当您分发您的应用程序时,每个人都可以使用您的 public 密钥解密签名并将哈希值与您提供的哈希值进行比较。

How is this different than SSL security for a website, ensuring the security and privacy of a connection?

完全不同。 TLS 是关于就用于加密传输中的数据的密钥达成一致。代码签名是关于证明代码没有被修改并且来自您(可能)信任的同一实体。

It seems like they all use the same technology to accomplish many different tasks.

是的。这一切都基于 private/public 密钥对。它可以用于许多不同的目的。 X509 证书实际上包括它们可用于的用途列表。名单是:

  • TLS WWW 服务器身份验证
  • TLS WWW 客户端身份验证
  • 可下载可执行代码的签名
  • 电子邮件保护
  • 将对象的哈希绑定到时间
  • 签署 OCSP 响应