【问题标题】:Mutual Authentication with Jruby Manticore使用 Jruby Manticore 进行相互身份验证
【发布时间】:2015-07-28 17:31:52
【问题描述】:

我正在尝试连接到需要相互身份验证的远程服务器。我从服务器收到一个 .p12 文件,并使用以下命令生成我的私钥和客户端证书:

openssl pkcs12 -in my_dev.p12 -out clientCert.crt -nokeys -clcerts
openssl pkcs12 -in my_dev.p12  -nocerts -nodes -passin pass:mypassword | openssl rsa -out privkey.pem

我使用以下代码设置了 Manticore 客户端:

client = Manticore::Client.new(
    pool_max: 200,
    pool_max_per_route: 200,
    ssl: { verify: :disable, client_key: client_key , client_cert: client_cert })

url = "https://my_url.com"
resp = client.get(url).call

我得到的回应是这样的:

401 Unauthorized
Unauthorized
This server could not verify that you\nare authorized to access the document
requested.  Either you supplied the wrong
credentials (e.g., bad password), or your
browser doesn't understand how to supply
the credentials required.

我对使用相互身份验证非常陌生,并且不确定我到底哪里出错了。我是否正确提取了 clientCert 和 privateKey?我是否正确地向 Manticore 提供密钥和证书?

【问题讨论】:

    标签: ruby jruby mutual-authentication


    【解决方案1】:

    您可以通过 ssl[:keystore] 选项直接从 Manticore 使用 PKCS12 文件:

    client = Manticore::Client.new(
      pool_max: 200,
      pool_max_per_route: 200,
      ssl: { keystore: "/path/to/auth.p12", keystore_password: "your_password" }
    )
    

    keystore 用于您希望提供给远程服务器的证书,而truststore 用于您希望用于验证远程服务器身份的公共证书;在这种情况下,您可能不应该使用verify: :disable,因为您确实想验证连接另一端的身份。

    【讨论】:

    • 感谢克里斯的回复。我已经按照您上面的描述设置了客户端,但现在我收到此错误:“Manticore::ClientProtocolException: PKIX 路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException: 无法找到请求目标的有效认证路径”。这是我的客户端还是服务器的问题?
    • 这可能是由于 Manticore 无法验证服务器的证书(即,因为它不是 CA 签名的证书,和/或因为您缺乏适当的证书)。 :truststore 将允许您指定要使用的信任库(即包含服务器 SSL 证书的公共部分的信任库),或者您可以提供 ca_file 这是一个 X509 证书链。
    • 另外,您可以使用verify: :disable 试试看是否确实是问题所在,但正如我提到的,我不建议将其用于生产用途,因为这意味着您可能会连接到不受信任的服务器。
    • 使用verify: :disable 我得到以下信息:401 Unauthorized Unauthorized ”This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.” 我应该按原样使用我提供的 p12,还是需要在某处进行转换?我还联系了服务器端团队,以确保一切都按预期进行配置。
    • 应该能够按原样使用它。用于客户端身份验证的 Manticore specs 有一个使用 .p12 存储的示例。您可能可以使用openssl s_client 测试该文件,以查看它是否在 Manticore 之外正确验证。您也可能发现了一个错误 - 客户端证书身份验证没有经过广泛测试,但如果是这种情况,我很乐意帮助解决它(我是 Manticore 的作者)。
    猜你喜欢
    • 1970-01-01
    • 2019-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多