Exemplo n.º 1
0
  private void print_https_cert(HttpsURLConnection con) {

    if (con != null) {

      try {

        System.out.println("Response Code : " + con.getResponseCode());
        System.out.println("Cipher Suite : " + con.getCipherSuite());
        System.out.println("\n");

        Certificate[] certs = con.getServerCertificates();
        for (Certificate cert : certs) {
          System.out.println("Cert Type : " + cert.getType());
          System.out.println("Cert Hash Code : " + cert.hashCode());
          System.out.println("Cert Public Key Algorithm : " + cert.getPublicKey().getAlgorithm());
          System.out.println("Cert Public Key Format : " + cert.getPublicKey().getFormat());
          System.out.println("\n");
        }

      } catch (SSLPeerUnverifiedException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
Exemplo n.º 2
0
 /** Bypass host name verification */
 public boolean verify(String hostname, SSLSession session) {
   System.out.println("Bypassing verification of hostname: " + hostname);
   try {
     System.out.println("Peer principal: " + session.getPeerPrincipal().toString());
   } catch (SSLPeerUnverifiedException e) {
     System.err.println("Unable to get peer principal");
     e.printStackTrace();
   }
   return true;
 }
  public boolean verify(String hostName, SSLSession session) {
    System.out.println("Server: " + hostName + ":" + session.getPeerPort());
    try {
      X509Certificate[] chain = session.getPeerCertificateChain();
      for (X509Certificate cert : chain) {

        System.out.println("DN: " + cert.getSubjectDN());
      }
    } catch (SSLPeerUnverifiedException e) {
      e.printStackTrace();
    }
    System.out.println("-----");
    return true;
  }
  @Override
  public void handshakeCompleted(HandshakeCompletedEvent event) {
    SSLSession session = event.getSession();
    String protocol = session.getProtocol();
    String cipherSuite = session.getCipherSuite();
    String peerName = null;

    try {
      peerName = session.getPeerPrincipal().getName();
      Log.d(TAG, "peerName: " + peerName);
    } catch (SSLPeerUnverifiedException e) {
      e.printStackTrace();
    }
    Log.d(TAG, "session: " + session);
    Log.d(TAG, "protocol: " + protocol);
    Log.d(TAG, "cipherSuite: " + cipherSuite);
  }