在 Hyperledger Fabric 中,如何使用 HSM 在客户端中设置 TLS 通信

问题描述

我使用 Hyperledger Fabric V1.4 并且我正在将我的所有私钥移动到 HSM。在创建网关以使用我的合同时查看我的代码,我添加一个 TLS 证书和一个私钥,但是需要私钥并且使用 HSM 我无法访问它,那么我如何连接到我的网关?

这是我连接到网关的方式:

const gateway = new Gateway();
const ccpPath = path.resolve(this.ccpPath);
await gateway.connect(ccpPath,{ wallet:this.wallet,identity: userId,discovery: { enabled: true,asLocalhost: this.asLocalhost } });

const client = gateway.getClient();
client.setTlsClientCertAndKey(identityUsuarioTLS.certificate,identityUsuarioTLS.privateKey);

我看到我可以添加一个 CryptoSuite,我猜我可以告诉客户端它的私钥有一个 HSM,但我不知道在哪里可以告诉客户端使用什么身份TLS 通信。

查看代码,如果我使用不带参数的 setTlsClientCertAndKey() 然后它会创建并自签名证书,但我的 HSM 中已经有了一个

setTlsClientCertAndKey(clientCert,clientKey) {
    logger.debug('setTlsClientCertAndKey - start');
    if (clientCert && clientKey) {
        this._tls_mutual.clientCert = clientCert;
        this._tls_mutual.clientKey = clientKey;
        this._tls_mutual.clientCertHash = null;
        this._tls_mutual.selfGenerated = false;
    } else {
        if (this._userContext) {
            logger.debug('setTlsClientCertAndKey - generating self-signed TLS client certificate');
            // generate X509 cert pair
            // use the default software cryptosuite,not the client assigned cryptosuite,which may be
            // HSM,or the default has been set to HSM. FABN-830
            const key = Client.newCryptoSuite({software: true}).generateEphemeralKey();
            this._tls_mutual.clientKey = key.toBytes();
            this._tls_mutual.clientCert = key.generateX509Certificate(this._userContext.getName());
            this._tls_mutual.selfGenerated = true;
        }
    }

}

我还没有找到关于这方面的文档,所以任何能引导我走向正确方向的帮助都会很棒。

谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)