小编Bre*_*nte的帖子

如何用自定义 SPI 替换核心类/功能?

我正在尝试通过自定义 SPI 添加一些后量子密钥算法(来自 liboqs-java)到 Keycloak。我可以使用我添加的算法生成密钥,但在操作它们时遇到了一些问题。

Keycloak 在使用我的新算法处理密钥时遇到问题...我认为 Java BouncyCastle 无法识别后量子算法(例如 Dilithium2),并且会导致系统崩溃。

我在 BCPemUtilsProvider Keycloak 类上的 JcaPEMWriter BouncyCastle 类上遇到了具体问题。我的解决方案是重写 BCPemUtilsProvider,这样我就可以替换 BouncyCastle 函数,但是为了做到这一点,我需要从 Keycloak 更改核心文件并重新编译整个项目,这对于每个微小的更改都需要花费大量时间。

我想通过 SPI(如果可能)或一些轻量级解决方案来解决这个问题,这样我就可以在实际的时间内进行测试。有没有办法在不重新编译整个 Keycloak 的情况下更改核心功能(或者,也许是我没有看到的另一种解决方案)?

提前致谢!!

顺便说一句,这是密钥生成的代码:

public AbstractGeneratedDLSecretKeyProvider(ComponentModel model, KeyUse use, String type, String algorithm) {
        this.status = KeyStatus.from(model.get(Attributes.ACTIVE_KEY, true), model.get(Attributes.ENABLED_KEY, true));
        this.kid = model.get(Attributes.KID_KEY);
        this.model = model;
        this.use = use;
        this.type = type;
        this.algorithm = algorithm;

        if (model.hasNote(PrivateKey.class.getName()) && model.hasNote(PublicKey.class.getName())) {
            privateKey = model.getNote(PrivateKey.class.getName());
            publicKey = model.getNote(PublicKey.class.getName());
        } else {
            Signature signer = new Signature("Dilithium2");

            signer.generate_keypair(); …
Run Code Online (Sandbox Code Playgroud)

java cryptography bouncycastle keycloak post-quantum-cryptography

5
推荐指数
1
解决办法
333
查看次数