java - 如何将客户端 pkcs12 证书添加到 Postman Chrome,W7?

标签 java android google-chrome ssl postman

我尝试测试一个“奇怪”的 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);

最佳答案

我使用的是 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

关于java - 如何将客户端 pkcs12 证书添加到 Postman Chrome,W7?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27501819/

相关文章:

java - 在 OnClickListener 内部我无法访问很多东西 - 如何处理?

android - 即使应用程序在 android 中被杀死,处理程序实例如何运行可运行的?

google-chrome - webgl 照明着色器适用于 Firefox,但不适用于 chrome

java - 无法将参数添加到准备好的语句中。 JAVA。 Spring MVC

java - 为 Objective-C 和 Java 编写通用代码的最佳方法?

java - 如何搜索工作资料联系人

google-chrome - 编辑和重播 XHR chrome/firefox 等?

java - 如何让 Java 查看文件的特定位置

java - 尝试使用渐变绘画时 setPaint() 不起作用

selenium - protractor/selenium 开始忽略 protractor.conf.js 中的 chrome 选项 (chromeOptions)