Tell me what am I doing wrong?
Authorization is required at https: //test.local , for authentication, cert.pfx certificate and login: password are used. cert.pfx - I exported firefox from a browser to really make sure that the certificate was correct I imported it (into a web browser) on other machines. Authorization was successful.
From the received certificate, I created keystore.jks
openssl pkcs12 -in custom_cert.p12 -out custom_cert.pem -nodes -nokeys openssl pkcs12 -in custom_cert.p12 -out custom_key.pem -nodes -nocerts openssl pkcs8 -topk8 -nocrypt -in custom_key.pem -inform PEM -out custom_key.der -outform DER openssl x509 -in custom_cert.pem -inform PEM -out custom_cert.der -outform DER This is how my connection looks like.
String URL = "test.local"; try { KeyStore kS = KeyStore.getInstance( KeyStore.getDefaultType() ); FileInputStream fIS = new FileInputStream("keystore.jks"); kS.load(fIS, "123456".toCharArray()); KeyManagerFactory kMF = KeyManagerFactory.getInstance("SunX509"); kMF.init(kS, "123456".toCharArray()); KeyManager[] kMs = kMF.getKeyManagers(); TrustManagerFactory tMF = TrustManagerFactory.getInstance("SunX509"); tMF.init(kS); TrustManager[] tM = tMF.getTrustManagers(); SSLContext sslContext = SSLContext.getInstance("SSL"); sslContext.init(kMs, tM, new SecureRandom()); SSLContext.setDefault(sslContext); javax.net.ssl.SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory(); SSLSocket sslClientSocket = (SSLSocket) sslSocketFactory.createSocket(URL,443); sslClientSocket.startHandshake(); HttpHost targetHost = new HttpHost(URL, 443, "https"); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, SSLConnectionSocketFactory.STRICT_HOSTNAME_VERIFIER); CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials( new AuthScope(targetHost.getHostName(),443), new UsernamePasswordCredentials("Fedya.Ivakin", "191919")); HttpClient httpclient = HttpClients.custom() .setSSLSocketFactory(sslsf) .setDefaultCredentialsProvider(credsProvider) .setSslcontext(sslContext) .build(); AuthCache authCache = new BasicAuthCache(); BasicScheme basicAuth = new BasicScheme(); authCache.put(targetHost, basicAuth); HttpClientContext context = HttpClientContext.create(); context.setCredentialsProvider(credsProvider); HttpGet httpget = new HttpGet("/"); HttpResponse response = httpclient.execute(targetHost, httpget, context); System.out.println(response.getStatusLine()); As a result, I get HTTP / 1.1 403 Forbidden.
Although there are no errors, where to dig? Tell me please.