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