使用客户端身份验证证书设置 FTPS 连接
Setup FTPS connection with Client Authentication certs
我被要求使用客户端身份验证证书设置 FTPS 连接。我是客户端,连接到服务器。我在 Windows7 工作站上,在防火墙后面。一些其他信息:
- 仅限 TLS 1.2
- 仅被动模式
- 我的 WAN IP 已列入白名单
- 我现在正在连接测试 URL
- 没有出站防火墙(只有入站规则)
- 密钥应以 PEM 格式发送
证书是从Comodo买的,用IE10生成的。我以 .pfx 格式从 IE 导出了完整的证书,包括私钥和扩展属性。
我使用 OpenSSL 编写了一个小批处理文件来从 .pfx 中提取必要的部分:
::Extract the private key from the PFX
openssl pkcs12 -in comodo.pfx -nocerts -out encrypted.key
::Extract unencrypted private key
openssl rsa -in encrypted.key -out decrypted.key
::Extract the public cert in Base64 from the PFX
openssl pkcs12 -in comodo.pfx -clcerts -nokeys | openssl x509 -out comodo.cer
::Extract the chain bundle from the PFX
openssl pkcs12 -in comodo.pfx -nodes -nokeys -cacerts | openssl x509 -out comodo.crt
使用提取的关键部分,我一直在尝试各种 cURL (v7.46.0) 命令来连接到 FTPS 服务器。连接一直失败。我最近的尝试如下。错误几乎总是相同的。
curl -3 -k -v --ftp-ssl --tlsv1.2 --ftp-ssl-reqd --ftp-pasv --key decrypted.key --cacert comodo.crt --cert comodo.cer --user REMOVED:REMOVED ftp://ftps.REMOVED/
输出示例为:
> curl -3 -v -k --user REMOVED:REMOVED --ftp-ssl --tlsv1.2 --ftp-ssl-reqd --ftp-skip-pasv-ip --cert comodo.cer --key priv.pem ftp://ftps.REMOVED/
* Trying REMOVED_IP.
* Connected to ftps.REMOVED (REMOVED_IP) port 21 (#0)
< 220 Service ready for new user.
> AUTH SSL
< 234 Command AUTH okay; starting SSL connection.
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* Unknown SSL protocol error in connection to ftps.REMOVED:21
* Closing connection 0 curl: (35) Unknown SSL protocol error in connection to ftps.REMOVED:21
>pause
Press any key to continue . . .
奇怪的是,如果我连接到 FileZilla,我似乎可以通过 TLS 握手,但是当我尝试上传文件时会遇到不同的错误。由于此连接最终将与 cURL 建立,因此我专注于使用 cURL.
我已经尝试了一个多星期了。服务器管理员已从我的提供商那里购买了证书,并且可以毫无问题地进行连接。我被这个难住了。任何帮助将不胜感激。
将此问题移至 ServerFault,因为该社区中似乎有很多类似的主题:
https://serverfault.com/questions/820851/debugging-curl-ftps-connection-using-client-authentication-certificates-openss
我被要求使用客户端身份验证证书设置 FTPS 连接。我是客户端,连接到服务器。我在 Windows7 工作站上,在防火墙后面。一些其他信息:
- 仅限 TLS 1.2
- 仅被动模式
- 我的 WAN IP 已列入白名单
- 我现在正在连接测试 URL
- 没有出站防火墙(只有入站规则)
- 密钥应以 PEM 格式发送
证书是从Comodo买的,用IE10生成的。我以 .pfx 格式从 IE 导出了完整的证书,包括私钥和扩展属性。
我使用 OpenSSL 编写了一个小批处理文件来从 .pfx 中提取必要的部分:
::Extract the private key from the PFX
openssl pkcs12 -in comodo.pfx -nocerts -out encrypted.key
::Extract unencrypted private key
openssl rsa -in encrypted.key -out decrypted.key
::Extract the public cert in Base64 from the PFX
openssl pkcs12 -in comodo.pfx -clcerts -nokeys | openssl x509 -out comodo.cer
::Extract the chain bundle from the PFX
openssl pkcs12 -in comodo.pfx -nodes -nokeys -cacerts | openssl x509 -out comodo.crt
使用提取的关键部分,我一直在尝试各种 cURL (v7.46.0) 命令来连接到 FTPS 服务器。连接一直失败。我最近的尝试如下。错误几乎总是相同的。
curl -3 -k -v --ftp-ssl --tlsv1.2 --ftp-ssl-reqd --ftp-pasv --key decrypted.key --cacert comodo.crt --cert comodo.cer --user REMOVED:REMOVED ftp://ftps.REMOVED/
输出示例为:
> curl -3 -v -k --user REMOVED:REMOVED --ftp-ssl --tlsv1.2 --ftp-ssl-reqd --ftp-skip-pasv-ip --cert comodo.cer --key priv.pem ftp://ftps.REMOVED/
* Trying REMOVED_IP.
* Connected to ftps.REMOVED (REMOVED_IP) port 21 (#0)
< 220 Service ready for new user.
> AUTH SSL
< 234 Command AUTH okay; starting SSL connection.
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* Unknown SSL protocol error in connection to ftps.REMOVED:21
* Closing connection 0 curl: (35) Unknown SSL protocol error in connection to ftps.REMOVED:21
>pause
Press any key to continue . . .
奇怪的是,如果我连接到 FileZilla,我似乎可以通过 TLS 握手,但是当我尝试上传文件时会遇到不同的错误。由于此连接最终将与 cURL 建立,因此我专注于使用 cURL.
我已经尝试了一个多星期了。服务器管理员已从我的提供商那里购买了证书,并且可以毫无问题地进行连接。我被这个难住了。任何帮助将不胜感激。
将此问题移至 ServerFault,因为该社区中似乎有很多类似的主题: https://serverfault.com/questions/820851/debugging-curl-ftps-connection-using-client-authentication-certificates-openss