I have a certificate file AUTH_RSA256_8827cdaa76b01019066fbe4d914d67a0e31677bc.p12 and a password issued by the administrator of the service server. How java authorize for further parsing. The purpose of the program to connect, provide a certificate, then on the authorization page to your personal account there are 2 RadioButton a) and b) and a field for entering a password (which is the same as the password of the key), select b) and enter the password, (pass internal authorization), then, using jsoup, see the new rows of the table and bring me a message about the new rows. Constantly looking at the browser and clicking "update" is not difficult, but very inconvenient ...
With the help of the code (and consultations) I was only able to access (erroneously) and parse the page in which you need to provide a certificate in which there is a button "Select key"
<input class="btn btn-primary" name="selectP12File" id="selectP12File" value="Выберите ключ" onclick="selectP12File()" type="button"> Here is the code itself:
KeyStore clientStore = KeyStore.getInstance("PKCS12"); clientStore.load(new FileInputStream("C:\\AUTH_RSA256_8827cdaa76b01019066fbe4d914d67a0e31677bc.p12"), "mypassword".toCharArray()); KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); kmf.init(clientStore, "mypassword".toCharArray()); KeyManager[] kms = kmf.getKeyManagers(); KeyStore trustStore = KeyStore.getInstance("JKS"); trustStore.load(new FileInputStream("C:\\Program Files\\Java\\jre-9.0.4\\lib\\security\\cacerts"), "changeit".toCharArray()); TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); tmf.init(trustStore); TrustManager[] tms = tmf.getTrustManagers(); SSLContext sslContext = null; sslContext = SSLContext.getInstance("TLS"); sslContext.init(kms, tms, new SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory()); URL url = new URL("https://server/ru/user/login"); HttpsURLConnection urlConn = (HttpsURLConnection) url.openConnection(); if (urlConn != null) { System.out.println(); System.out.println("****** Content of the URL ********"); BufferedReader br = new BufferedReader(new InputStreamReader(urlConn.getInputStream())); String input; while ((input = br.readLine()) != null){ System.out.println(input); } br.close(); } else { System.out.println("not connect"); } urlConn.disconnect(); Previously a server certificate was added to the cacerts and keytool commands.
Please share your experience. I will be glad to constructive criticism and your opinion of what I am doing wrong. Thank you for attention!
