运行 使用自签名证书在带有 SSL 的渡槽中进行的测试导致错误

Running tests in aqueduct with SSL using self signed certificate results in error

我是使用 openSSL 和证书的新手。注意事项。

在我的接收器文件中,我正在使用 SecurityContext 来强制使用 HTTPs:

@override
SecurityContext get securityContext {
    return new SecurityContext()
        ..usePrivateKey("SSL/key.pem", password: keypassword)
        ..useCertificateChain("SSL/cert.pem", password: certpassword);
}

我正在本地开发并使用 OpenSSL 创建了自签名密钥和证书。当 运行 通过 aqueduct 服务的应用程序时,我没有任何问题(除了通过各自的浏览器确认我知道证书不是 CA 签名的)但是当 运行 我的测试我收到以下错误:

HandshakeException: Handshake error in client (OS Error: 
CERTIFICATE_VERIFY_FAILED: self signed certificate(ssl_cert.c:345))

这是否意味着我需要使用 CA 签名证书才能避免这种情况?

默认情况下,如果服务器的 SSL 证书是自签名的,Dart HttpClient 将失败。您可以覆盖它,但 TestClient 不会让您访问底层的 HttpClient。我们可以做到 属性 public,但是...

测试主要用于测试应用程序逻辑。是否使用 SSL 并不重要。 aqueduct serve 有 SSL 的 CLI 选项。当 运行 在本地或通过测试时,您可以省略 SSL。当 运行 远程使用签名的 SSL 证书时,您可以在启动时将密钥和文件路径添加到 CLI args:

aqueduct serve --ssl-key-path SSL/key.pem --ssl-certificate-path SSL/cert.pem