如何验证和更改 JWT 算法
How to verify and change a JWT Alg
我正在使用 ASP.Net OpenID Connect Server 项目 (ASOS) 为我的 WebAPI 创建和使用 JWT。
我现在正在尝试对令牌执行各种验证。
我想知道如何检查 "alg" 类型。
我知道 "none" 可以传入的问题,这意味着有人可以伪造令牌(我不确定是否只是特定的库有问题,或者这是否只是一般的好习惯检查,但如果我执行该检查,我会感觉更安全)。
另外,如何验证 JWT 的完整性?
目前我的令牌发行者和 WebAPI 在同一个项目中,所以我猜它是自动为我检查的?还是根本没有检查?
我的理解是,如果您未指定任何签名凭证,则会在磁盘上为您添加某种签名凭证(不确定我在哪里读到的)。
提供某种签名凭证会自动更新 "alg" 属性 吗?
如果我的令牌发行者在一台服务器上,而我的 WebAPI 位于完全不同的地方怎么办。我将如何验证令牌是否来自我的令牌发行者并且没有受到干扰。
大概我必须手动添加证书,然后以某种方式共享 public 密钥?
如果是这样,有人可以指出我应该在哪里添加 public 键来检查 JWT 完整性吗?
大概这部分更多是关于 asp.net Core 而不是 OpenIDConnect Server (ASOS)?
谢谢。
I'd like to know how to check the "alg" type.
您可以使用 jwt.io 之类的工具来读取 JWT 的 header,其中包含您要查找的 alg
值。
I'm aware of an issue where "none" can be passed in, which means that someone can forge the tokens (I'm not sure if it's just specific libraries that have the issue, or if it's just generally good practice to check, but I'd feel safer if I was performing that check).
ASOS 依赖于 IdentityModel——微软开发的一个框架——来生成 JWT 令牌(你可以看看 this other answer for more information)。据我所知,它不受您提到的安全漏洞的影响。
要亲自尝试,您可以使用 jwt.io 更改 alg
header 值并将生成的编码 JWT 发送到您的 API.
Also, how can I verify the integrity of the JWT?
Currently my token issuer and WebAPI are in the same project so I'm guessing that it's checked for me automatically? Or is it not checked at all?
What if my token issuer is on 1 server and my WebAPI was somewhere completely different. How would I go about validating that the token came from my token issuer and hadn't been interfered with.
Presumably I'd have to add a certificate manually, then share the public key somehow? If that's the case, could someone point me to where I should add the public key to check the JWT integrity? Presumably this part is more about asp.net Core than OpenIDConnect Server (ASOS)?
如果您使用 JWT 承载中间件,那么它会自动为您完成。为此,它直接下载 ASOS' JWK set endpoint 公开的 public 签名密钥(默认情况下,在 /.well-known/jwks
)。
这是一个例子:
My understanding is that some kind of signing credential is added for you on disk if you don't specify any (Not sure where I read that).
最新的正式版(beta6)是这样,但是下个版本会去掉这个功能。我们鼓励您注册 X.509 证书或使用临时签名密钥(在开发期间)。否则会抛出异常。
Would providing some kind of signing credential automatically update the "alg" property?
是的。 ASOS 原生支持对称密钥和 RSA 密钥。例如,如果您在调用 options.SigningCredentials.AddKey(...)
时使用 SymmetricSecurityKey
,将返回 HS256
(HMAC-SHA256) 而不是 RS256
(RSA-SHA256)。您可以使用接受 SigningCredentials
实例的 Add
重载提供额外的算法。
我正在使用 ASP.Net OpenID Connect Server 项目 (ASOS) 为我的 WebAPI 创建和使用 JWT。
我现在正在尝试对令牌执行各种验证。
我想知道如何检查 "alg" 类型。 我知道 "none" 可以传入的问题,这意味着有人可以伪造令牌(我不确定是否只是特定的库有问题,或者这是否只是一般的好习惯检查,但如果我执行该检查,我会感觉更安全)。
另外,如何验证 JWT 的完整性?
目前我的令牌发行者和 WebAPI 在同一个项目中,所以我猜它是自动为我检查的?还是根本没有检查?
我的理解是,如果您未指定任何签名凭证,则会在磁盘上为您添加某种签名凭证(不确定我在哪里读到的)。
提供某种签名凭证会自动更新 "alg" 属性 吗?
如果我的令牌发行者在一台服务器上,而我的 WebAPI 位于完全不同的地方怎么办。我将如何验证令牌是否来自我的令牌发行者并且没有受到干扰。
大概我必须手动添加证书,然后以某种方式共享 public 密钥? 如果是这样,有人可以指出我应该在哪里添加 public 键来检查 JWT 完整性吗? 大概这部分更多是关于 asp.net Core 而不是 OpenIDConnect Server (ASOS)?
谢谢。
I'd like to know how to check the "alg" type.
您可以使用 jwt.io 之类的工具来读取 JWT 的 header,其中包含您要查找的 alg
值。
I'm aware of an issue where "none" can be passed in, which means that someone can forge the tokens (I'm not sure if it's just specific libraries that have the issue, or if it's just generally good practice to check, but I'd feel safer if I was performing that check).
ASOS 依赖于 IdentityModel——微软开发的一个框架——来生成 JWT 令牌(你可以看看 this other answer for more information)。据我所知,它不受您提到的安全漏洞的影响。
要亲自尝试,您可以使用 jwt.io 更改 alg
header 值并将生成的编码 JWT 发送到您的 API.
Also, how can I verify the integrity of the JWT?
Currently my token issuer and WebAPI are in the same project so I'm guessing that it's checked for me automatically? Or is it not checked at all?
What if my token issuer is on 1 server and my WebAPI was somewhere completely different. How would I go about validating that the token came from my token issuer and hadn't been interfered with.
Presumably I'd have to add a certificate manually, then share the public key somehow? If that's the case, could someone point me to where I should add the public key to check the JWT integrity? Presumably this part is more about asp.net Core than OpenIDConnect Server (ASOS)?
如果您使用 JWT 承载中间件,那么它会自动为您完成。为此,它直接下载 ASOS' JWK set endpoint 公开的 public 签名密钥(默认情况下,在 /.well-known/jwks
)。
这是一个例子:
My understanding is that some kind of signing credential is added for you on disk if you don't specify any (Not sure where I read that).
最新的正式版(beta6)是这样,但是下个版本会去掉这个功能。我们鼓励您注册 X.509 证书或使用临时签名密钥(在开发期间)。否则会抛出异常。
Would providing some kind of signing credential automatically update the "alg" property?
是的。 ASOS 原生支持对称密钥和 RSA 密钥。例如,如果您在调用 options.SigningCredentials.AddKey(...)
时使用 SymmetricSecurityKey
,将返回 HS256
(HMAC-SHA256) 而不是 RS256
(RSA-SHA256)。您可以使用接受 SigningCredentials
实例的 Add
重载提供额外的算法。