如何在Chrome的Postman中添加客户端PKCS12证书,适用于W7操作系统?

15

我尝试测试一种“奇怪”的GET请求,其中我必须提供基本身份验证和客户端证书。

我尝试使用Postman Chrome进行检查,但我不知道如何将chrome个人证书与我的请求链接起来。

我看到了这个讨论:https://github.com/a85/POSTMan-Chrome-Extension/issues/482,但它是关于MAC密钥库的,我无法将其转换到W7 / Chrome。

这是我的Java代码设置,应该可以像Postman那样完成同样的工作,以帮助您了解我想要Postman做什么。我们使用该帖子来编写它。

        InputStream is = context.getResources().getAssets().open("CertificateFile.p12");
        KeyStore keyStore = KeyStore.getInstance("PKCS12");
        BufferedInputStream bis = new BufferedInputStream(is);
        String password ="xxxxx";
        keyStore.load(bis, password.toCharArray()); // password is the PKCS#12 password. If there is no password, just pass null
        // Init SSL Context
        KeyManagerFactory kmf = KeyManagerFactory.getInstance("X509");
        kmf.init(keyStore, password.toCharArray());
        KeyManager[] keyManagers = kmf.getKeyManagers();
        SSLContext sslContext = SSLContext.getInstance("TLS");
        sslContext.init(keyManagers, null, null);
        HttpsURLConnection urlConnection = null; 
        String strURL = "theUrlITryToHit";
        url = new URL(strURL);
        urlConnection = (HttpsURLConnection) url.openConnection();
        if(urlConnection instanceof HttpsURLConnection) {
            ((HttpsURLConnection)urlConnection)
            .setSSLSocketFactory(sslContext.getSocketFactory());
        }
        urlConnection.setRequestMethod("GET");
        String basicAuth = "Basic " + Base64.encodeToString("pseudo:password".getBytes(), Base64.NO_WRAP);
        urlConnection.setRequestProperty ("Authorization", basicAuth);

你找到解决方案了吗?我想在Postman中添加证书进行测试,你能帮我吗? - Abderrahim
2个回答

21

我正在使用Mac,但对于你来说可能也是类似的。 如果您可以在PC上使用CURL,请先尝试使用CURL进行测试:

curl --insecure --cert-type P12 --cert /path-to/your-file.p12:the-password https://your-host.com/endpoint

Postman设置:

Postman->preferences->General
SSL certificate verification OFF

Postman证书:

Postman->preferences->Certificates
Client Certificates:


Host yourhost.com
CRT file
Key file
PFX file  /path-to-file/CertificateFile.p12  
Passphrase your-file-password

在MAC上应该可以工作,但这仅因为Mac的curl支持p12格式...在其他平台上,您必须使用.pem格式 - 我认为这是由于特定的构建和使用的安全库(netscape vs others)所致。 - Pierluigi Vernetto
在Ubuntu上工作过。 - Seyed Morteza Mousavi
为什么要关闭Postman的SSL证书验证设置呢? 我猜想,如果这个设置被关闭了,Postman甚至不会尝试将客户端证书发送到服务器。因此它将无法正常工作。 - Saion Chatterjee

3

我曾遇到类似问题,但现在已经解决了。我的私钥和证书都存储在一个.pem文件中,因此我需要将它们放入Windows可用的格式中。我使用以下命令完成此操作:

openssl pkcs12 -inkey mycertandkey.pem -in mycert.crt -export -out mycertandkey.pfx

我在Linux上完成了这个操作,但如果您已安装openssl,则应该也可以在Windows上运行。
在Windows中运行certmgr.msc。右键单击“个人”文件夹,选择“所有任务” -> “导入...”,然后选择.pfx文件。输入密码并将其导入到“个人”文件夹中。
完成后,您需要关闭正在运行的Chrome窗口。然后在新窗口中打开Postman。当您尝试连接到URL时,这次它应该要求确认使用客户端证书。一旦确认,您就应该能够从那时起调用该URL。

我会尝试一下(即使我不再需要它)。谢谢。 - Poutrathor
我遇到了一个问题,我想调用一个需要客户端证书的服务。Postman正确地提示我选择要发送的客户端证书,但是我没有将它导入到我的个人文件夹中。在导入后,我无法让Postman重新提示我输入证书。我不仅需要关闭Chrome和Postman,还需要终止所有仍在运行的Chrome.exe进程。然后当我再次打开Postman并调用服务时,它会提示我,并且我能够选择正确的证书。 - jakejgordon

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接