签名密钥、证书和客户端机密混淆

Signing keys, certificates and client secrets confusion

我对证​​书和签名密钥之间的区别有些困惑,有几个问题....

我已将 OpenIddict 配置为使用 JWT 承载身份验证。

1) AddDevelopmentSigningCertificate() 和 AddEphemeralSigningKey() 有什么区别?

当我使用一个或另一个时,我的应用程序可以正常工作。在开发过程中使用哪一个重要吗?

2) AddSigningCertificate() 和 AddSigningKey() 之间有什么区别,您什么时候会使用其中之一或两者?

据我了解,签名证书用于对 JWT 令牌进行签名。但是当您使用 AddSigningKey 时 - 它也用于签署 JWT 令牌。如果您同时使用两者,这是否意味着 JWT 令牌被签署了两次——一个在另一个之上?还是一个覆盖另一个?

在我的场景中,我正在使用 AddDevelopmentCertificate() 或 AddEphemeralSigningKey() 用于开发但用于生产我知道我需要设置一个签名证书,理想情况下应该位于机器商店中。

但我还需要一个唯一的签名密钥,该密钥与使用 JWT 承载身份验证的 API 端点(在 .NET Framework 4.x 中)共享。

我想知道这些函数对 JWT 令牌做了什么以及它们如何相互协作。

最后一个问题:在设置 OpenIddict 表并使用客户端应用程序为数据库播种时,会填充一个 Client Secret。在示例项目中,这些始终是 GUID。

3)使用JWT Bearer认证时是否使用了client secret?这如何与签名证书和签名密钥一起使用?

我真的很想了解这些东西是如何工作的,但在签名 key/certificate 荒野中有点迷路!

谢谢

What is the difference between AddDevelopmentSigningCertificate() and AddEphemeralSigningKey()?

AddDevelopmentSigningCertificate 将尝试生成一个自签名的 X.509 证书(包含一个 RSA 密钥)并将其存储在用户的证书存储中,以便即使在您重新启动应用程序后也可以重新使用它。

AddEphemeralSigningKey 只会生成一个 RSA 签名密钥,但不会将其保存在任何地方。一旦您重新启动应用程序,它将丢失。

这两种方法的用途完全相同:创建用于保护您的令牌的签名密钥。


What is the difference between AddSigningCertificate() and AddSigningKey() and when would you use one or the other or both?

唯一的区别是 AddSigningCertificate() 接受一个 X509Certificate2 参数,而 AddSigningKey() 接受一个 SecurityKey 实例。最终,AddSigningCertificate() 负责解析证书中的 RSA 或 ECDSA 密钥并调用 AddSigningKey().


But when you use AddSigningKey - that is also used to sign the JWT token. If you use both, does this mean that the JWT token gets signed twice - one on top of the other? Or does one override the other?

当您注册多个非对称签名密钥时,OpenIddict 仅使用第一个来签署令牌。其他的仅由发现端点公开,因此您稍后可以决定将它们设为“主键”而不会破坏您的客户端。


I understand that I need to set up a signed certificate that ideally should be located in the machine store.

是的。如果您无权访问机器或用户存储(推荐选项),您也可以将其存储在嵌入式程序集文件中。


But I also require a unique signing key that is shared with my API endpoint (in .NET Framework 4.x) that uses JWT Bearer Authentication.

这就是 AddSigningCertificate()AddSigningKey() 的用途。建议使用非对称签名密钥(即证书或 RsaSecurityKey/EcdsaSecurityKey 实例)。

如果您更喜欢使用对称密钥对您的 JWT 令牌进行 HMAC,请使用 AddSigningKey(new SymmetricSecurityKey([bytes]))

如果您的授权服务器颁发身份令牌,您将需要至少一个非对称密钥(证书或原始 RSA/ECDSA 密钥),但对称密钥将优先用于 JWT 访问令牌。


Is the client secret used when using JWT Bearer authentication? And how does this play along with the signing certificate and signing key?

客户端机密仅在与令牌或吊销端点通信时使用,而不是在您使用自己的 API 端点时使用。有关详细信息,请阅读 https://www.rfc-editor.org/rfc/rfc6749#section-2.3