Tôi phải kết nối với một dịch vụ web dựa trên REST.Bouncy Castle Keystore (BKS): java.io.IOException: Phiên bản sai của kho khóa
(https://someurl.com/api/lookup/jobfunction/lang/EN)
Trong IE hoặc trình duyệt chrome khi tôi cố gắng truy cập vào URL này, tôi nhận được một giấy chứng nhận rằng tôi phải tin tưởng và chấp nhận để tiếp tục Sau đó tôi phải nhập tên tài khoản và mật khẩu và sau đó tôi nhận phản hồi JSON.
Điều tương tự tôi phải làm điều đó một cách có lập trình cho một ứng dụng Android.
Đã thử với tùy chỉnh EasySSLSocketFactory and EasyX509TrustManager, Công việc chưa thực hiện. Tôi nhận được lỗi sau: java.security.cert.CertPathValidatorException: Không thể tìm thấy thẻ tin cậy cho đường dẫn chứng nhận.
Dùng keystore BKS, xin lưu ý mykeystore.bks đó là một tập tin rỗng trước khi tôi thực hiện dưới đây lệnh
keytool -importcert -v -trustcacerts -file "test.crt" -alias IntermediateCA -keystore "mykeystore.bks" -provider org.bouncycastle.jce.provider.BouncyCastleProvider -providerpath "bcprov-jdk15on-148.jar" -storetype BKS -storepass abcd1234 keytool -list -keystore "mykeystore.bks" -provider org.bouncycastle.jce.provider.BouncyCastleProvider -providerpath "bcprov-jdk15on-148.jar" -storetype BKS -storepass abcd1234
MyHTTPClient.java trông giống như dưới đây:
public class MyHttpClient extends DefaultHttpClient {
final Context context;
public MyHttpClient(Context context) {
this.context = context;
}
@Override
protected ClientConnectionManager createClientConnectionManager() {
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
// Register for port 443 our SSLSocketFactory with our keystore
// to the ConnectionManager
registry.register(new Scheme("https", newSslSocketFactory(), 443));
return new SingleClientConnManager(getParams(), registry);
}
private SSLSocketFactory newSslSocketFactory() {
try {
// Get an instance of the Bouncy Castle KeyStore format
KeyStore trusted = KeyStore.getInstance("BKS");
// Get the raw resource, which contains the keystore with
// your trusted certificates (root and any intermediate certs)
InputStream in = context.getResources().openRawResource(R.raw.mykeystore);
try {
// Initialize the keystore with the provided trusted certificates
// Also provide the password of the keystore
trusted.load(in, "abcd1234".toCharArray());
} finally {
in.close();
}
// Pass the keystore to the SSLSocketFactory. The factory is responsible
// for the verification of the server certificate.
SSLSocketFactory sf = new SSLSocketFactory(trusted);
// Hostname verification from certificate
// http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html#d4e506
sf.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
return sf;
} catch (Exception e) {
throw new AssertionError(e);
}
}
Khi tôi gọi dịch vụ web, tôi nhận được lỗi dưới đây: Gây ra bởi: java.lang.AssertionError: java.io.IOException: Phiên bản sai của ke y store
Vui lòng cho tôi biết tôi phải làm gì để kết nối với dịch vụ web dựa trên HTTPS còn lại có tên người dùng và thông tin đăng nhập passwd. ......
Xin chào các bạn, hãy luôn sử dụng bcprov-jdk15on-146.jar để tạo tệp kho khóa. Tôi đã giải quyết vấn đề bằng cách sử dụng bcprov-jdk15on-146.jar thay vì mới nhất bcprov-jdk15on-148.jar – user2290834
không có bcprov-jdk15on-148.jar trong thư mục cài đặt Java của tôi –
Câu hỏi đã được trả lời ở đây: http://stackoverflow.com/a/33197845/5459467 – Cukic0d