在Deno上设置HTTPS,使用自签名证书?

问题描述 投票:1回答:1

我在设置一个Deno服务器来处理HTTPS请求,我使用了自签名证书来完成这项工作。

import { serveTLS } from "https://deno.land/std/http/server.ts";

const body = new TextEncoder().encode("Hello HTTPS");
const options = {
  hostname: "localhost",
  port: 443,
  certFile: "./path/to/localhost.crt",
  keyFile: "./path/to/localhost.key",
};
// Top-level await supported
for await (const req of serveTLS(options)) {
  req.respond({ body });
}

我运行这段代码为: deno --allow-net --allow-read app.ts我得到以下错误信息

ERROR RS - rustls::session:571 - TLS alert received: Message {
    typ: Alert,
    version: TLSv1_3,
    payload: Alert(
        AlertMessagePayload {
            level: Fatal,
            description: BadCertificate,
        },
    ),
}
error: Uncaught InvalidData: received fatal alert: BadCertificate
► $deno$/errors.ts:57:13
    at InvalidData ($deno$/errors.ts:135:5)
    at constructError ($deno$/errors.ts:57:13)
    at unwrapResponse ($deno$/dispatch_json.ts:41:12)
    at sendAsync ($deno$/dispatch_json.ts:96:10)

是否可以在Deno中使用自签名证书? 出了什么问题,如何解决?

deno
1个回答
1
投票

这是一个与我的证书文件的问题,奇怪的是相同的证书与nodejs工作。我创建了本地证书和密钥,比使用这个 mkcert,然后它的工作!

© www.soinside.com 2019 - 2024. All rights reserved.