Pou*_*hor 6 java ssl android google-chrome postman
我尝试测试一个'奇怪的'GET请求,我必须提供BASIC身份验证和客户端证书.
我尝试使用Postman Chrome进行检查,但我不明白如何将证书从chrome个人证书链接到我的请求.
我看到了这个讨论:https://github.com/a85/POSTMan-Chrome-Extension/issues/482但它是关于MAC密钥库的,我无法转置到W7/Chrome.
这是我的java代码设置,应该做与邮递员相同的工作,以帮助您了解我想要邮递员做什么.我们使用该帖子来编写它
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);
Run Code Online (Sandbox Code Playgroud)
我使用的是 Mac,但它对您来说可能类似。如果您可以在 PC 上使用 CURL,请先查看是否可以使用 CURL:
curl --insecure --cert-type P12 --cert /path-to/your-file.p12:the-password https://your-host.com/endpoint
Run Code Online (Sandbox Code Playgroud)
邮递员设置:
Postman->preferences->General
SSL certificate verification OFF
Run Code Online (Sandbox Code Playgroud)
邮递员证书:
Postman->preferences->Certificates
Client Certificates:
Host yourhost.com
CRT file
Key file
PFX file /path-to-file/CertificateFile.p12
Passphrase your-file-password
Run Code Online (Sandbox Code Playgroud)
我遇到了类似的问题并且刚刚开始工作。我的私钥和证书存储在 .pem 文件中,因此我首先需要将它们转换为 Windows 使用的格式。我使用以下命令做到了这一点:
openssl pkcs12 -inkey mycertandkey.pem -in mycert.crt -export -out mycertandkey.pfx
Run Code Online (Sandbox Code Playgroud)
我在 Linux 中执行此操作,但如果您安装了 openssl,它也应该在 Windows 中工作。
在 Windows 中运行certmgr.msc。右键单击“个人”文件夹并选择“所有任务”->“导入...”,然后选择 .pfx 文件。输入密码并将其导入到“个人”文件夹中。
完成后,您需要关闭正在运行的 Chrome 窗口。然后在新窗口中打开 Postman。当您尝试连接到 URL 时,这次它应该要求确认客户端证书的使用。确认后,您应该能够从那时起调用该 URL。
| 归档时间: |
|
| 查看次数: |
17738 次 |
| 最近记录: |