如何使用数字证书检查与远程服务器的连接(客户机authentication)

我有一个数字证书,带有服务器和客户端身份validation扩展以及一个私钥。

现在我想连接到一个远程服务器(REST Web服务),它应该接受我的请求,因为我的证书。 作为第一步,我想检查这个连接是否会工作。 远程服务器不在我的控制之下。

我有这个REST的URL https://host.test.com/REST/admin/user/1212/ ,我需要做的证书请求。 那么我怎样才能通过命令行(Linux系统)来做到这一点?

你可以使用curl或wget。

curl --cert <your cert> 

要么

 wget --certificate=<yourt cert> 

证书(当然带有私钥)需要位于一个p12文件中。 您可以指定该文件的密码。

您可以使用openssl s_client检查证书的有效性。

 openssl s_client -connect www.google.com -CApath /usr/share/ca-certificates 

这给了我:

 [mark@pericles ~]$ openssl s_client -connect www.google.de:443 -CApath /usr/share/ca-certificates/ CONNECTED(00000004) depth=3 C = US, O = Equifax, OU = Equifax Secure Certificate Authority verify return:1 depth=2 C = US, O = GeoTrust Inc., CN = GeoTrust Global CA verify return:1 depth=1 C = US, O = Google Inc, CN = Google Internet Authority G2 verify return:1 depth=0 C = US, ST = California, L = Mountain View, O = Google Inc, CN = google.com verify return:1 --- Certificate chain 0 s:/C=US/ST=California/L=Mountain View/O=Google Inc/CN=google.com i:/C=US/O=Google Inc/CN=Google Internet Authority G2 1 s:/C=US/O=Google Inc/CN=Google Internet Authority G2 i:/C=US/O=GeoTrust Inc./CN=GeoTrust Global CA 2 s:/C=US/O=GeoTrust Inc./CN=GeoTrust Global CA i:/C=US/O=Equifax/OU=Equifax Secure Certificate Authority --- <snip> Verify return code: 0 (ok) --- 

-CApath参数指向要validation的CA证书。 我在Arch Linux上,因此它们在/ usr / share / ca-certificates中。

debugging证书时,这是非常方便的,但是当你不能控制另一方的时候,这个方法也是非常有用的。

要使用客户端证书,请将以下内容添加到s_client命令行中:

 -cert xxx.pem -key xxx.pem 

这里xxx.pem包含客户端证书和密钥。 你只需将它传递给两个选项。