Las clases que implementan la conexion HTTPS son las siguientes:
Código
public class Https { public static void main(String args[]) throws MalformedURLException, NoSuchAlgorithmException, Exception { //System.setProperty("javax.net.ssl.trustStore","tomcatKeystore"); //Para aceptar certificados que no estan en el keystore del cliente SSLContext sc = SSLContext.getInstance("TLS"); sc.init(null, new TrustManager[] { new SimpleTrustManager1() }, null); SSLSocketFactory ssf = sc.getSocketFactory(); HttpsURLConnection urlConection = (HttpsURLConnection) url.openConnection(); urlConection.setSSLSocketFactory(ssf); //urlConection.setHostnameVerifier(new SimpleHostnameVerifier()); urlConection.connect(); byte[] bytes = new byte[1024]; int leidos; while ((leidos = is.read(bytes)) != -1){ fos.write(bytes, 0, leidos); } fos.close(); is.close(); } }
Y la del TrustManager:
Código
public class SimpleTrustManager1 implements X509TrustManager { private Set<X509Certificate> certs = new HashSet<X509Certificate>(); //Cargamos los certificados del Keystore en el atributo certs } } } for(int i=0; i<chain.length; i++){ if(certs.contains(chain[i])){ return; } } " no se puede verificar. " + //throw new CertificateException("La clave no está en el trustore"); } }
Me salta la excepcion:
Exception in thread "main" java.io.IOException: HTTPS hostname wrong: should be <192.168.2.2>
at sun.net.www.protocol.https.HttpsClient.checkURLSpoofing(HttpsClient.java:524)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:448)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:166)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:133)
at conexionHTTPS.Https.main(Https.java:45)
Alguien me puede guiar en como corregir dicho error???
Saludos.
alzehimer_cerebral





Autor



En línea



Ademas el connect es el que lanza la excepcion, tambien la lanza el getInputStream si comento la linea del connect! Yo diria que una mala gestion de la clase SimpleTrustManager1 lanza la excepcion ya que el constructor realmente no esta haciendo nada, alguien sabe como podria cargar el keystore que tiene cada cliente en su maquina en la variable certs???
