【问题标题】:Jose4j: Unable to find a suitable verification key for JWS w/ headerJose4j:无法为带有标头的 JWS 找到合适的验证密钥
【发布时间】:2019-01-24 16:58:39
【问题描述】:

验证失败,因为 key_ops 不符合从 SelectorSupport 中的静态方法 filterForInboundSigned(JsonWebSignature jws) 创建的 SimpleJwkFilter 的条件。公钥看起来像这样:

{
  "kid": "xxx",
  "use": "sig",
  "key_ops": [
    "sign"
  ],
  "kty": "xxx",
  "e": "xxx",
  "n": "xxx"
}

根据SimpleJwkFilter,“key_ops”必须为 null 或包含值“verify”以匹配条件。

有没有办法在 jose4j 中自定义这种行为?也许跳过“key_ops”的验证?

【问题讨论】:

  • 附带说明:在这种情况下,“签名”不应该是一个有效的操作,因为根据tools.ietf.org/html/rfc7517#page-7,“签名”和“验证”是一个有效的组合?

标签: jose4j


【解决方案1】:

如果您使用HttpsJwksVerificationKeyResolver,您可以拥有HttpsJwks 的简单小子类,它会在过滤器看到它们之前取消设置每个JWK 上的“key_ops”。看起来像这样:

class MyHttpsJwks extends HttpsJwks
{
    public MyHttpsJwks(String location)
    {
        super(location);
    }

    @Override
    public List<JsonWebKey> getJsonWebKeys() throws JoseException, IOException
    {
        List<JsonWebKey> jsonWebKeys = super.getJsonWebKeys();
        for (JsonWebKey jwk : jsonWebKeys)
        {
            jwk.setKeyOps(null);
        }
        return jsonWebKeys;
    }
}

然后像new HttpsJwksVerificationKeyResolver(new MyHttpsJwks("https://bad.example.com/jwks"));一样实例化解析器

如果您使用JwksVerificationKeyResolver,则可以在使用它实例化解析器之前对 JsonWebKey 列表执行相同的操作。如果您直接使用 VerificationJwkSelector 或 SimpleJwkFilter,列表上的类似预处理也将起作用。

FWIW,根据 RFC7517,“use”和“key_ops”参数不应该一起使用,如果它们是,它们应该传达相同的含义。我认为有问题的 JWK 没有兑现这一点,因为“sign”的“key_ops”表示密钥可用于计算数字签名,而“sig”的“使用”表示密钥可用于一般的数字签名操作(签名或验证)。

【讨论】:

    猜你喜欢
    • 2015-10-25
    • 2022-01-19
    • 2021-09-03
    • 2019-06-04
    • 2021-12-17
    • 2017-04-28
    • 1970-01-01
    • 2018-04-05
    • 2021-08-27
    相关资源
    最近更新 更多