在过去的几周里,我一直在使用Rust-lang Rocket v0.5-rc来创建我的web应用程序。为了获得我的SSL证书和域名,我一直在使用不含IP的服务.
我用OpenSSL生成了一个2048位RSA密钥,将其转换为PKCS-8,创建了一个CSR (使用预先制作的密钥)并将其上传到无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)通信。
有什么想法吗?
发布于 2022-03-08 22:03:24
问题可能是你并没有真正连接到火箭网络服务器。您使用的主机名很可能会解析为公共IP地址,其中可能有其他内容正在侦听。首先尝试使用localhost对https://localhost进行测试,然后接受无效的证书(或跳到此消息的末尾,以了解如何更改主机文件)。如果结果是这样的话,您将需要在您的路由器中设置端口转发端口443。
但这只是猜测。我不知道你为什么会有这样的错误,但是我可以为来自TrustCor的免费主机名设置Rocket证书。以下是我所采取的步骤:
我让火箭使用入门页面。我的main.rs看起来和他们的一模一样,我使用的是0.5.0-rc.1版本。我得到了“你好世界!”卷曲在http://127.0.0.1:8000上。所以我知道在没有TLS的情况下一切正常。
接下来,我用openssl生成了一个密钥和csr,
openssl req -nodes -days 365 -newkey rsa:2048 -keyout key.pem -out cert.csr重要的一行是我设置为rocket-test.zapto.org的“公共名称”。我没有为密钥设置密码。不需要更改密钥或csr格式。默认情况下,openssl会以正确的格式生成火箭/锈蚀和无IP。
我创建了主机名,然后按照没有IP的指南上传CSR,https://www.noip.com/support/knowledgebase/configure-trustcor-standard-dv-ssl/
我等待证书发布,然后从"PEM链(推荐)“链接下载它。

我把文件和我的钥匙一起移到我的货物项目目录中。我也改变了火箭的港口听443,因为你有它。以下是我的文件的样子:
$ grep ^rocket Cargo.toml
rocket = { version = "0.5.0-rc.1", features = ["tls"] }
$ cat Rocket.toml
[global]
port = 443
[default.tls]
certs = "rocket-test_zapto_org.pem-chain"
key = "key.pem"
$ ls -1 *pem*
key.pem
rocket-test_zapto_org.pem-chain
$ head -n 2 key.pem
-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC4gZZbg2iWPlyi
$ head -n 2 rocket-test_zapto_org.pem-chain
-----BEGIN CERTIFICATE-----
MIIGpzCCBY+gAwIBAgIMV2rPeuY8+0gQuie4MA0GCSqGSIb3DQEBCwUAMFsxCzAJ在https://127.0.0.1:443,上cargo run显示它不再监听http://127.0.0.1:8000,
$ cargo run
...
Rocket has launched from https://127.0.0.1:443首先,我们测试它在不验证主机名的情况下工作(--insecure不验证证书的公共名称),
$ curl --insecure https://127.0.0.1
Hello, world!现在我们可以在--resolve中使用curl来检查它是否使用了正确的公共名称,
$ curl --resolve rocket-test.zapto.org:443:127.0.0.1 https://rocket-test.zapto.org
Hello, world!要使用浏览器进行本地测试,我们需要在浏览器中将名称解析为127.0.0.1。我们可以通过将它添加到/etc/hosts文件来做到这一点。看起来您在Windows上,所以主机文件位于C:\Windows\System32\Drivers\etc\hosts。如果该文件不存在,则创建该文件,并在末尾添加一个类似于此的条目(当然是您的主机名),
127.0.0.1 rocket-test.zapto.org然后,我可以打开我的浏览器到https://rocket-test.zapto.org,它将工作。

https://stackoverflow.com/questions/71380276
复制相似问题