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

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

我看到了这个讨论:https://github.com/a85/POSTMan-Chrome-Extension/issues/482,但它是关于MAC keystore的,我不能转置到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);

最佳答案

我有一个类似的问题,只是让它正常工作。我的私钥和证书存储在.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进行调用。

10-04 23:02
查看更多