使用 NO-IP 信任认证配置 Rocket 0.5 TLS
过去几周我一直在使用 Rust-lang Rocket v0.5-rc 来创建我的 Web 应用程序。 为了获得我的SSL证书和域名,我一直在使用NO-IP免费服务。
我使用 OpenSSL 生成了 2048 位 RSA 密钥,将其转换为 PKCS-8,创建了 CSR(使用预制密钥)并将其上传到 NO-IP。 一段时间后,我下载了证书链并按照所述配置了 Rocket.toml:
[global]
port = 443
address = "0.0.0.0"
[default.tls]
certs = "certs.pem"
key = "key.key"
但是,当我尝试通过 Firefox 连接到网站时,我收到“连接丢失”或“SSL 格式错误”警告。
服务器输出:
Finished dev [unoptimized + debuginfo] target(s) in 0.13s
Running `target\debug\rocket_project.exe`
Configured for debug.
>> address: 0.0.0.0
>> port: 443
>> workers: 8
>> ident: Rocket
>> keep-alive: 5s
>> limits: bytes = 8KiB, data-form = 2MiB, file = 1MiB, form = 32KiB, json = 1MiB, msgpack = 1MiB, string = 8KiB
>> tls: enabled
>> temp dir: C:\Users\talhk\AppData\Local\Temp\
>> log level: normal
>> cli colors: true
>> shutdown: ctrlc = true, force = true, grace = 2s, mercy = 3s
Warning: found set deprecated profile `development`
>> profile was replaced by `debug`
Warning: found set deprecated profile `production`
>> profile was replaced by `release`
Routes:
>> (index) GET /
>> (get_file_external) GET /<file..>
Fairings:
>> Shield (liftoff, response, singleton)
Shield:
>> Permissions-Policy: interest-cohort=()
>> X-Content-Type-Options: nosniff
>> X-Frame-Options: SAMEORIGIN
Rocket has launched from https://0.0.0.0:443
Error: connection accept error: received corrupt message
Error: optimistically retrying now
Warning: Received SIGINT. Requesting shutdown.
Received shutdown request. Waiting for pending I/O...
附加信息:当我使用 Wireshark 找出发生的情况时,它将其描述为 TCP(而不是 TLS)通信。
有什么想法吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题可能是您实际上并未连接到 Rocket 网络服务器。您使用的主机名很可能会解析为其他设备可能正在监听的公共 IP 地址。首先尝试使用 localhost 和 https://localhost 进行测试,并接受无效证书(或跳到此消息的末尾了解如何更改主机文件)。如果情况确实如此,您将需要 在路由器中为端口 443 设置端口转发。
但这只是猜测。我不知道为什么你会得到这个特定的错误,但我能够使用 TrustCor 证书设置 Rocket,以获得来自 https://www.noip.com。以下是我采取的步骤:
我使用 入门页面< /a>.我的
main.rs
看起来和他们的一样,我使用的是0.5.0-rc.1
版本。我得到“你好世界!”在http://127.0.0.1:8000
上使用curl。所以我知道一切都在没有 TLS 的情况下工作。接下来,我使用 openssl 生成了密钥和 csr,
重要的一行是“通用名称”,我将其设置为
rocket-test.zapto.org
。我没有为密钥设置密码。无需更改密钥或 csr 格式。openssl
默认情况下以正确的格式为 Rocket / rustls 和 No-IP 生成它们。我创建了主机名,然后按照 No-IP 指南上传 CSR,https://www.noip.com/support/knowledgebase/configure-trustcor-standard-dv-ssl/
我等待证书颁发,然后从“PEM链(推荐)”链接。
我将该文件与我的密钥一起移动到我的货物项目目录中。我还更改了 Rocket 正在侦听 443 的端口,正如您所拥有的那样。我的文件如下所示:
cargo run
显示它在 https://127.0.0.1:443 上监听,不再是 http:/ /127.0.0.1:8000,The problem could be that you are not actually connecting to your Rocket webserver. The hostname you are using most likely resolves to a public IP address where something else might be listening. Try testing using localhost first with https://localhost and accept the invalid certificate (or skip to the end of this message for how to change your hosts file). If that turns out to be the case you will need to set up port forwarding in your router for port 443.
But that is just a guess. I'm not sure why you got that specific error, but I was able to set up Rocket with a TrustCor cert for a free hostname from https://www.noip.com. Here are the steps I took:
I got rocket working using the Getting Started page. My
main.rs
looks just like theirs and I'm using version0.5.0-rc.1
. I get "Hello World!" with curl onhttp://127.0.0.1:8000
. So I know everything is working without TLS.Next, I generated a key and csr with openssl,
The important line is the "Common Name" which I set to
rocket-test.zapto.org
. I did not set a password for the key. There is no need to change the key or csr format.openssl
by default generates them in the correct format for Rocket / rustls and No-IP.I created the hostname and then I followed the No-IP guide to upload the CSR, https://www.noip.com/support/knowledgebase/configure-trustcor-standard-dv-ssl/
I waited for the cert to be issued and then I downloaded it from the "PEM Chain (Recommended)" link.
I moved the file to my cargo project directory along with my key. I also changed the port Rocket is listening on to 443 as your have it. Here is what my files look like:
cargo run
shows it listening on https://127.0.0.1:443, no longer http://127.0.0.1:8000,First we test that it is working without verifying the hostname (
--insecure
does not verify the Common Name of the certificate),Now we can use curl with
--resolve
to check that it is working with the correct Common Name,To test locally with a browser we need the name to resolve to 127.0.0.1 in the browser. We can do that by adding it to the
/etc/hosts
file. It looks like you're on Windows so the hosts file is atC:\Windows\System32\Drivers\etc\hosts
. Create the file if it does not exist and add an entry at the end that looks like this (with your hostname of course),Then I can open my browser to
https://rocket-test.zapto.org
and it will work.