如何在 Vapor Web 框架中安装 SSL 证书?

How to install SSL certificate in Vapor web framework?

我想安装 SSL(Comodo 通配符证书,例如:“*.test.com”) 在 Vapor Web 框架中,我得到的 "servers.json" 是:

{
    "default": {
        "port": "$PORT:443",
        "host": "api.test.com",
        "securityLayer": "tls",
        "tls": {
            "certificates": "chain",
            "certificateFile": "/path/ssl-bundle.crt",
            "chainFile": "/path/ssl-bundle.crt",
            "privateKeyFile": "/path/key.pem",
            "signature": "signedFile",
            "caCertificateFile": "/path/AddTrustExternalCARoot.crt"
            }
    }
}

我已经使用 openssl 命令确保 "public/private" 密钥匹配。关于像 "ssl-bundle.crt" 这样的 certificateFile 部分,我也尝试了 "*.test.com.crt" 和 "key.pem" (仍然使用 openssl 通过验证,唯一的区别是 test.com的证书,另一个是捆绑证书,已按正确的顺序组合。)。此外,所有证书和密钥的格式也是正确的。我还确保 cert/key 文件位置正确,以便 Vapor 可以找到这些文件。但是我还是不能正确启动服务器,一直显示错误。 我试图在 xcode 中找到确切的位置,但我只能在这个方法中看到它失败: "tls_accept_fds()",它在 CLibreSSL 库的 tls_server.c 中。

另外,我看到 xcode 向我显示的错误消息:

使用调试模式跟踪后,我只能知道程序似乎在"SSL_set_rfd()"或"SSL_set_rfd()"中抛出了错误,但我并不清楚。 xcode 只向我显示了这个,我在调试控制台中找不到任何其他错误消息。结果,到目前为止我只能确定错误应该在这个块中:

int
tls_accept_fds(struct tls *ctx, struct tls **cctx, int fd_read, int fd_write)
{
struct tls *conn_ctx = NULL;

// I pass this block
if ((ctx->flags & TLS_SERVER) == 0) {
    tls_set_errorx(ctx, "not a server context");
    goto err;
}

// I pass this block
if ((conn_ctx = tls_server_conn(ctx)) == NULL) {
    tls_set_errorx(ctx, "connection context failure");
    goto err;
}

// I pass this block
if ((conn_ctx->ssl_conn = SSL_new(ctx->ssl_ctx)) == NULL) {
    tls_set_errorx(ctx, "ssl failure");
    goto err;
}

// I pass this block
if (SSL_set_app_data(conn_ctx->ssl_conn, conn_ctx) != 1) {
    tls_set_errorx(ctx, "ssl application data failure");
    goto err;
}

// The error occurs here, in SSL_set_rfd or SSL_set_wfd, it will then go to err part: "*cctx = NULL;", not even go into the if block.
if (SSL_set_rfd(conn_ctx->ssl_conn, fd_read) != 1 ||
    SSL_set_wfd(conn_ctx->ssl_conn, fd_write) != 1) {
    tls_set_errorx(ctx, "ssl file descriptor failure");
    goto err;
}

*cctx = conn_ctx;

return (0);

err:
tls_free(conn_ctx);

*cctx = NULL;

return (-1);
}

所以,以上是我目前得到的所有信息,我在网上已经好几天找不到解决方案了... 谁能给我任何关于如何在 Vapor Web 框架中安装 SSL 的提示?我已经可以在 Apache、Nginx、Tomcat 等中正确安装 SSL。但是在Vapor中从来没有成功过,这似乎是C库问题,但我不知道它失败的真正原因,非常感谢您提供任何可能的帮助。

错误已在此处找到并修复:https://github.com/vapor/tls/pull/27