reactjs - 如何在 grpc-web 中使用 TLS?
问题描述
我目前正在尝试将 grpc-web 添加到 React-App 但我无法使其与 TLS 一起使用。我什至不知道如何正确导入客户端证书。
我正在使用带有 tls 的 grpc,并且通常设置正在运行。这意味着如果我使用一个简单的节点应用程序(无前端),我实现的所有服务都会按预期工作。
所以我知道使用@grpc/grpc-js 我可以做到以下几点:
import { credentials as _credentials } from '@grpc/grpc-js';
import { readFileSync } from 'fs';
const credentials = _credentials.createSsl(
readFileSync(__dirname + '../certs/ca.crt'),
readFileSync(__dirname + '../certs/client.key'),
readFileSync(__dirname + '../certs/client.crt')
)
但是 grpc-web 没有凭证对象。我目前拥有的只是:
const { ProjectMeta, Affirm } = require('./base_pb.js');
const { ProjectClient } = require('./base_grpc_web_pb.js');
// No idea how to import these correctly
// const credentials = ???
let client = new ProjectClient('https://localhost:8443', credentials, null);
当我查看 base_grpc_web_pb.js 中 ProjectClient 的定义时,我更加困惑。
proto.base.ProjectClient =
function(hostname, credentials, options) {
if (!options) options = {};
options.format = 'text';
/**
* @private @const {!grpc.web.GrpcWebClientBase} The client
*/
this.client_ = new grpc.web.GrpcWebClientBase(options);
/**
* @private @const {string} The hostname
*/
this.hostname_ = hostname;
};
甚至没有使用凭据参数???
在 grpcwebproxy 方面,我得到了:
2021/10/22 10:36:16 http: TLS handshake error from [::1]:59530: remote error: tls: unknown certificate
...我猜这是预期的?
希望任何人都可以帮助我解决这个问题。谢谢!
解决方案
推荐阅读
- java - 为什么Applet的继承类不需要覆盖其所有方法,因为Applet类是一个抽象类
- python - 如何计算tkinter python中文本区域中的空格
- dagre-d3 - Dagre-d3 graphlib:如何在不重绘整个图的情况下将新节点动态添加到图中?
- ios - Firebase Firestore 和 Protobuf 的词法或以前的问题,这两个文件夹是问题
- php - 有什么方法可以忽略 laravel 中的错误
- syntax-error - sybase与mybatis交互
- nativescript-vue - RadListView:未知的自定义元素:
- java - 在 PDFMergerUtility 中,是否有任何选项可以忽略错误?
- x86 - 通过分页,我们为每个 4 字节(字)映射虚拟到物理映射。但是我们如何访问该映射中的每个字节呢?
- solr - Solr 核心 schema.xml 在哪里?