【问题标题】:Setting up HTTPS on Deno , with self signed certificate?使用自签名证书在 Deno 上设置 HTTPS?
【发布时间】:2020-06-16 17:07:00
【问题描述】:

我正在设置一个 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 中使用自签名证书? 出了什么问题以及如何解决?

【问题讨论】:

  • 解决问题的替代方法(来自上游 rustls 问题):github.com/ctz/rustls/issues/124#issuecomment-337983154
  • @KevinQian 是的,这个看起来很相关,我会看看并更新。
  • 甚至无法达到我可能会出错的地步,复制了您的代码,使用我的本地自签名证书进行设置(与我的节点服务器一起使用)。出现错误:Uncaught PermissionDenied: Permission denied (os error 13) at unwrapResponse ($deno$/ops/dispatch_json.ts:43:11) at Object.sendSync ($deno$/ops/dispatch_json.ts:72:10) at Object.listenTls ($deno$/ops/tls.ts:67:10) at listenTls ($deno$/tls.ts:51:22) at serveTLS (server.ts:313:20) 源自 rust,无法根据此处所写的内容找到解决方案:github.com/rust-lang/cargo/issues/6757
  • @exside 这是我的证书文件的问题,奇怪的是相同的证书正在与 nodejs 一起使用。我创建了本地证书而不是使用这个mkcert,然后它工作了!

标签: deno


【解决方案1】:

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

【讨论】:

  • 干扰!谢谢你告诉我!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-03-01
  • 2014-06-22
  • 2017-02-19
  • 2011-02-06
  • 1970-01-01
  • 1970-01-01
  • 2012-12-10
相关资源
最近更新 更多