@Override
    public InputStream sendXmlRpc(byte[] request) throws IOException {
      // Create a trust manager that does not validate certificate for this connection
      TrustManager[] trustAllCerts = new TrustManager[] {new PyPITrustManager()};

      try {
        SSLContext sslContext = SSLContext.getInstance("TLS");
        sslContext.init(null, trustAllCerts, new SecureRandom());

        final HttpConfigurable settings = HttpConfigurable.getInstance();
        con = settings.openConnection(PYPI_LIST_URL);
        if (con instanceof HttpsURLConnection) {
          ((HttpsURLConnection) con).setSSLSocketFactory(sslContext.getSocketFactory());
        }
        con.setDoInput(true);
        con.setDoOutput(true);
        con.setUseCaches(false);
        con.setAllowUserInteraction(false);
        con.setRequestProperty("Content-Length", Integer.toString(request.length));
        con.setRequestProperty("Content-Type", "text/xml");
        if (auth != null) {
          con.setRequestProperty("Authorization", "Basic " + auth);
        }
        OutputStream out = con.getOutputStream();
        out.write(request);
        out.flush();
        out.close();
        return con.getInputStream();
      } catch (NoSuchAlgorithmException e) {
        LOG.warn(e.getMessage());
      } catch (KeyManagementException e) {
        LOG.warn(e.getMessage());
      }
      return super.sendXmlRpc(request);
    }
Example #2
0
  private searchMenuMgr() {

    try {
      KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
      trustStore.load(null, null);
      MySSLSocketFactory socketFactory = new MySSLSocketFactory(trustStore);
      socketFactory.setHostnameVerifier(MySSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
      client = new AsyncHttpClient();
      client.setSSLSocketFactory(socketFactory);
      client.setCookieStore(new PersistentCookieStore(Login_Main.getContext()));
      client.setTimeout(10000);
    } catch (KeyStoreException e) {
      e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
      e.printStackTrace();
    } catch (CertificateException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (KeyManagementException e) {
      e.printStackTrace();
    } catch (UnrecoverableKeyException e) {
      e.printStackTrace();
    }
  }
  private SSLSocketFactory createTrustedSocketFactory() {
    try {
      final SSLContext context = SSLContext.getInstance("ssl");
      final X509TrustManager trustManager =
          new X509TrustManager() {

            public void checkClientTrusted(X509Certificate[] x509Certificates, String s)
                throws CertificateException {}

            public void checkServerTrusted(X509Certificate[] x509Certificates, String s)
                throws CertificateException {}

            public X509Certificate[] getAcceptedIssuers() {
              return new X509Certificate[0];
            }
          };
      context.init(null, new TrustManager[] {trustManager}, null);
      return context.getSocketFactory();
    } catch (NoSuchAlgorithmException e) {
      e.printStackTrace();
    } catch (KeyManagementException e) {
      e.printStackTrace();
    }
    return null;
  }
 /**
  * @param maxTotal maxTotal
  * @param maxPerRoute maxPerRoute
  * @param timeout timeout
  * @param retryExecutionCount retryExecutionCount
  * @return
  */
 public static CloseableHttpClient createHttpClient(
     int maxTotal, int maxPerRoute, int timeout, int retryExecutionCount) {
   try {
     SSLContext sslContext = SSLContexts.custom().useSSL().build();
     SSLConnectionSocketFactory sf =
         new SSLConnectionSocketFactory(
             sslContext, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
     PoolingHttpClientConnectionManager poolingHttpClientConnectionManager =
         new PoolingHttpClientConnectionManager();
     poolingHttpClientConnectionManager.setMaxTotal(maxTotal);
     poolingHttpClientConnectionManager.setDefaultMaxPerRoute(maxPerRoute);
     SocketConfig socketConfig = SocketConfig.custom().setSoTimeout(timeout).build();
     poolingHttpClientConnectionManager.setDefaultSocketConfig(socketConfig);
     return HttpClientBuilder.create()
         .setConnectionManager(poolingHttpClientConnectionManager)
         .setSSLSocketFactory(sf)
         .setRetryHandler(new HttpRequestRetryHandlerImpl(retryExecutionCount))
         .build();
   } catch (KeyManagementException e) {
     e.printStackTrace();
   } catch (NoSuchAlgorithmException e) {
     e.printStackTrace();
   }
   return null;
 }
Example #5
0
 public static CloseableHttpClient createSSLClientDefault() {
   try {
     SSLContext sslContext =
         new SSLContextBuilder()
             .loadTrustMaterial(
                 null,
                 new TrustStrategy() {
                   // 信任所有
                   public boolean isTrusted(X509Certificate[] chain, String authType)
                       throws CertificateException {
                     return true;
                   }
                 })
             .build();
     SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext);
     return HttpClients.custom().setSSLSocketFactory(sslsf).build();
   } catch (KeyManagementException e) {
     e.printStackTrace();
   } catch (NoSuchAlgorithmException e) {
     e.printStackTrace();
   } catch (KeyStoreException e) {
     e.printStackTrace();
   }
   return HttpClients.createDefault();
 }
  private EasySSLSocketFactory() {
    super();
    TrustManager[] tm =
        new TrustManager[] {
          new X509TrustManager() {

            @Override
            public void checkClientTrusted(X509Certificate[] chain, String authType)
                throws CertificateException {
              // do nothing
            }

            @Override
            public void checkServerTrusted(X509Certificate[] chain, String authType)
                throws CertificateException {
              // do nothing
            }

            @Override
            public X509Certificate[] getAcceptedIssuers() {
              return new X509Certificate[0];
            }
          }
        };
    try {
      this.sslcontext = SSLContext.getInstance(SSLSocketFactory.TLS);
      this.sslcontext.init(null, tm, new SecureRandom());
      this.socketfactory = this.sslcontext.getSocketFactory();
    } catch (NoSuchAlgorithmException e) {
      Log.e(this.getClass().getName(), e.getMessage());
    } catch (KeyManagementException e) {
      Log.e(this.getClass().getName(), e.getMessage());
    }
  }
Example #7
0
  static {
    String[] enabledCiphers = null;
    String[] enabledProtocols = null;

    try {
      SSLContext sslContext = SSLContext.getInstance("TLS");
      sslContext.init(null, null, new SecureRandom());
      SSLSocketFactory sf = sslContext.getSocketFactory();
      SSLSocket sock = (SSLSocket) sf.createSocket();
      enabledCiphers = sock.getEnabledCipherSuites();
      enabledProtocols = sock.getEnabledProtocols();
    } catch (IOException ioe) {
      ioe.printStackTrace();
    } catch (KeyManagementException kme) {
      kme.printStackTrace();
    } catch (NoSuchAlgorithmException nsae) {
      nsae.printStackTrace();
    }

    ENABLED_CIPHERS =
        (enabledCiphers == null)
            ? null
            : reorder(enabledCiphers, ORDERED_KNOWN_CIPHERS, BLACKLISTED_CIPHERS);

    ENABLED_PROTOCOLS =
        (enabledProtocols == null)
            ? null
            : reorder(enabledProtocols, ORDERED_KNOWN_PROTOCOLS, null);
  }
  {
    TrustManager[] trustAllCerts =
        new TrustManager[] {
          new X509TrustManager() {
            public java.security.cert.X509Certificate[] getAcceptedIssuers() {
              return null;
            }

            public void checkClientTrusted(X509Certificate[] certs, String authType) {}

            public void checkServerTrusted(X509Certificate[] certs, String authType) {}
          }
        };

    SSLContext sc = null;
    try {
      sc = SSLContext.getInstance("SSL");
      sc.init(null, trustAllCerts, new java.security.SecureRandom());
    } catch (KeyManagementException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());

    HostnameVerifier allHostsValid =
        new HostnameVerifier() {
          public boolean verify(String hostname, SSLSession session) {
            return true;
          }
        };
    HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
  }
Example #9
0
  @POST
  @Produces("text/javascript")
  @Path("/comments")
  public String addPhotoCommentEvent(
      @QueryParam("id") String id,
      @QueryParam("threadId") String threadId,
      @FormParam("message") String body) {
    try {
      JSONObject member = new JSONObject();
      member.put("id", String.format("urn:member:%s", id));
      JSONObject post = new JSONObject();
      post.put("commenter", member);
      post.put("message", body);

      String url = String.format(_commentUrlTemplate, threadId);
      HttpJSONClient commentsClient = HttpJSONClient.create(url);
      return commentsClient.doPost(post.toString(2), _headers).toString(2);
    } catch (URISyntaxException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (JSONException e) {
      e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
      e.printStackTrace();
    } catch (KeyManagementException e) {
      e.printStackTrace();
    }
    return "{success: false}";
  }
  /**
   * ִ��http���á�true:�ɹ� false:ʧ��
   *
   * @return boolean
   */
  public boolean call() {

    boolean isRet = false;

    // http
    if (null == this.caFile && null == this.certFile) {
      try {
        this.callHttp();
        isRet = true;
      } catch (IOException e) {
        this.errInfo = e.getMessage();
      }
      return isRet;
    }

    // https
    try {
      this.callHttps();
      isRet = true;
    } catch (UnrecoverableKeyException e) {
      this.errInfo = e.getMessage();
    } catch (KeyManagementException e) {
      this.errInfo = e.getMessage();
    } catch (CertificateException e) {
      this.errInfo = e.getMessage();
    } catch (KeyStoreException e) {
      this.errInfo = e.getMessage();
    } catch (NoSuchAlgorithmException e) {
      this.errInfo = e.getMessage();
    } catch (IOException e) {
      this.errInfo = e.getMessage();
    }

    return isRet;
  }
Example #11
0
  private static SSLSocketFactory getSocketFactory(Boolean d) {
    // Enable debug mode to ignore all certificates
    if (DEBUG) {
      KeyStore trustStore;
      try {
        trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        trustStore.load(null, null);
        SSLSocketFactory sf = new DebugSSLSocketFactory(trustStore);
        sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
        return sf;

      } catch (KeyStoreException e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
      } catch (NoSuchAlgorithmException e3) {
        // TODO Auto-generated catch block
        e3.printStackTrace();
      } catch (CertificateException e3) {
        // TODO Auto-generated catch block
        e3.printStackTrace();
      } catch (IOException e3) {
        // TODO Auto-generated catch block
        e3.printStackTrace();
      } catch (KeyManagementException e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
      } catch (UnrecoverableKeyException e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
      }
    }

    return SSLSocketFactory.getSocketFactory();
  }
 /**
  * Key store 类型HttpClient
  *
  * @param keystore keystore
  * @param keyPassword keyPassword
  * @param supportedProtocols supportedProtocols
  * @param timeout timeout
  * @param retryExecutionCount retryExecutionCount
  * @return CloseableHttpClient
  */
 public static CloseableHttpClient createKeyMaterialHttpClient(
     KeyStore keystore,
     String keyPassword,
     String[] supportedProtocols,
     int timeout,
     int retryExecutionCount) {
   try {
     SSLContext sslContext =
         SSLContexts.custom()
             .useSSL()
             .loadKeyMaterial(keystore, keyPassword.toCharArray())
             .build();
     SSLConnectionSocketFactory sf =
         new SSLConnectionSocketFactory(
             sslContext,
             supportedProtocols,
             null,
             SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
     SocketConfig socketConfig = SocketConfig.custom().setSoTimeout(timeout).build();
     return HttpClientBuilder.create()
         .setDefaultSocketConfig(socketConfig)
         .setSSLSocketFactory(sf)
         .setRetryHandler(new HttpRequestRetryHandlerImpl(retryExecutionCount))
         .build();
   } catch (KeyManagementException e) {
     e.printStackTrace();
   } catch (NoSuchAlgorithmException e) {
     e.printStackTrace();
   } catch (UnrecoverableKeyException e) {
     e.printStackTrace();
   } catch (KeyStoreException e) {
     e.printStackTrace();
   }
   return null;
 }
Example #13
0
  public JSONObject httpsRequest(String requestUrl, String httpMethod, String defaultStr) {
    JSONObject res = new JSONObject();
    try {
      TrustManager[] tm = {new MyX509TrustManager()};
      SSLContext sslContext = SSLContext.getInstance("SSL", "SunJSSE");
      sslContext.init(null, tm, new SecureRandom());
      SSLSocketFactory sf = sslContext.getSocketFactory();

      URL url = new URL(requestUrl);
      HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
      conn.setSSLSocketFactory(sf);
      conn.setDoInput(true);
      conn.setDoOutput(true);
      conn.setUseCaches(false);
      conn.setRequestMethod(httpMethod);

      if (defaultStr != null) {
        OutputStream os = conn.getOutputStream();
        os.write(defaultStr.getBytes("UTF-8"));
        os.close();
      }

      InputStream is = conn.getInputStream();
      InputStreamReader isr = new InputStreamReader(is, "UTF-8");
      BufferedReader br = new BufferedReader(isr);

      String str = null;
      StringBuffer sb = new StringBuffer();
      while ((str = br.readLine()) != null) {
        sb.append(str);
      }
      br.close();
      isr.close();
      is.close();
      is = null;
      conn.disconnect();

      res = JSONObject.fromObject(sb.toString());

    } catch (KeyManagementException e) {
      e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (MalformedURLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (NoSuchProviderException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return res;
  }
  public static String httsRequest(String url, String contentdata) {
    String str_return = "";
    SSLContext sc = null;
    try {
      sc = SSLContext.getInstance("SSL");
    } catch (NoSuchAlgorithmException e) {

      e.printStackTrace();
    }
    try {
      sc.init(
          null, new TrustManager[] {new TrustAnyTrustManager()}, new java.security.SecureRandom());
    } catch (KeyManagementException e) {

      e.printStackTrace();
    }
    URL console = null;
    try {
      console = new URL(url);
    } catch (MalformedURLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    HttpsURLConnection conn;
    try {
      conn = (HttpsURLConnection) console.openConnection();
      conn.setRequestMethod("POST");
      conn.setSSLSocketFactory(sc.getSocketFactory());
      conn.setHostnameVerifier(new TrustAnyHostnameVerifier());
      conn.setRequestProperty("Accept", "application/json");
      conn.setDoInput(true);
      conn.setDoOutput(true);
      // contentdata="username=arcgis&password=arcgis123&client=requestip&f=json"
      String inpputs = contentdata;
      OutputStream os = conn.getOutputStream();
      os.write(inpputs.getBytes());
      os.close();
      conn.connect();
      InputStream is = conn.getInputStream();
      // // DataInputStream indata = new DataInputStream(is);
      BufferedReader reader = new BufferedReader(new InputStreamReader(is));
      String ret = "";
      while (ret != null) {
        ret = reader.readLine();
        if (ret != null && !ret.trim().equals("")) {
          str_return = str_return + ret;
        }
      }
      is.close();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    return str_return;
  }
Example #15
0
  private void testIt() {

    String https_url = requestURL;
    URL url;

    SSLSocketFactory socketFactory = null;

    try {

      try {
        socketFactory = createSSLContext().getSocketFactory();
      } catch (UnrecoverableKeyException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (KeyManagementException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (NoSuchAlgorithmException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (KeyStoreException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (CertificateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      url = new URL(https_url);
      HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
      conn.setDoInput(true); // Allow Inputs
      conn.setDoOutput(true); // Allow Outputs
      conn.setRequestMethod("POST");
      conn.setRequestProperty("Connection", "Keep-Alive");
      conn.setRequestProperty("ENCTYPE", "multipart/form-data");
      conn.setSSLSocketFactory(socketFactory);

      DataOutputStream dos = new DataOutputStream(conn.getOutputStream());

      conn.addRequestProperty("app_id", app_id);
      conn.addRequestProperty("app_key", app_key);

      // dump all cert info
      // print_https_cert(con);

      // dump all the content
      print_content(conn);

    } catch (MalformedURLException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
  public void Initiallize()
      throws KeyManagementException, UnrecoverableKeyException, NoSuchAlgorithmException,
          KeyStoreException {
    Scheme http = new Scheme("http", 80, PlainSocketFactory.getSocketFactory());
    // 创建TrustManager
    X509TrustManager xtm =
        new X509TrustManager() {
          public void checkClientTrusted(X509Certificate[] chain, String authType)
              throws CertificateException {}

          public void checkServerTrusted(X509Certificate[] chain, String authType)
              throws CertificateException {}

          public X509Certificate[] getAcceptedIssuers() {
            return null;
          }
        };
    // 这个好像是HOST验证
    X509HostnameVerifier hostnameVerifier =
        new X509HostnameVerifier() {
          public boolean verify(String arg0, SSLSession arg1) {
            return true;
          }

          public void verify(String arg0, SSLSocket arg1) throws IOException {}

          public void verify(String arg0, String[] arg1, String[] arg2) throws SSLException {}

          public void verify(String arg0, X509Certificate arg1) throws SSLException {}
        };
    SSLContext ctx = null;
    try {
      ctx = SSLContext.getInstance("TLS");
      ctx.init(null, new TrustManager[] {(TrustManager) xtm}, null);
      // 创建SSLSocketFactory
      socketFactory = new SSLSocketFactory(ctx);
      socketFactory.setHostnameVerifier(hostnameVerifier);
    } catch (NoSuchAlgorithmException e1) {
      e1.printStackTrace();
    } catch (KeyManagementException e) {
      e.printStackTrace();
    }
    SSLContext.setDefault(ctx);
    SSLSocketFactory ssf = new SSLSocketFactory(ctx);
    Scheme https = new Scheme("https", 443, ssf);
    sr = new SchemeRegistry();
    sr.register(http);
    sr.register(https);
    cm = new PoolingClientConnectionManager(sr);
    cm.setMaxTotal(200);
    cm.setDefaultMaxPerRoute(100);
  }
  public ConfiglessCustomHttpEngine() {
    super();
    HttpClientBuilder client = HttpClientBuilder.create();

    try {
      client.setSslcontext(createGullibleSslContext());
    } catch (KeyManagementException e) {
      e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
      e.printStackTrace();
    }
    this.httpClient = client.build();
  }
  public void openConnection() throws IOException {
    try {
      connectionFactory.useSslProtocol();
    } catch (NoSuchAlgorithmException ex) {
      throw new IOException(ex.toString());
    } catch (KeyManagementException ex) {
      throw new IOException(ex.toString());
    }

    if (connection == null) {
      connection = connectionFactory.newConnection();
    }
  }
Example #19
0
 static {
   try {
     _queryClient = HttpJSONClient.create("http://localhost:1340/activityviews");
     _publishClient = HttpJSONClient.create("http://localhost:1338/activities");
     //      _headers.put("X-LinkedIn-Auth-Member", "1");
   } catch (IOException e) {
     e.printStackTrace();
   } catch (NoSuchAlgorithmException e) {
     e.printStackTrace();
   } catch (KeyManagementException e) {
     e.printStackTrace();
   }
 }
 private SSLContext createSSLContext() {
   SSLContext sslcontext = null;
   try {
     sslcontext = SSLContext.getInstance("SSL");
     sslcontext.init(
         null, new TrustManager[] {new TrustAnyTrustManager()}, new java.security.SecureRandom());
   } catch (NoSuchAlgorithmException e) {
     e.printStackTrace();
   } catch (KeyManagementException e) {
     e.printStackTrace();
   }
   return sslcontext;
 }
 public static HttpClient createHttpClient() {
   try {
     SSLContext sslContext = SSLContexts.custom().useSSL().build();
     SSLConnectionSocketFactory sf =
         new SSLConnectionSocketFactory(
             sslContext, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
     return HttpClientBuilder.create().setSSLSocketFactory(sf).build();
   } catch (KeyManagementException e) {
     e.printStackTrace();
   } catch (NoSuchAlgorithmException e) {
     e.printStackTrace();
   }
   return null;
 }
Example #22
0
 private static SSLContext createSContext() {
   SSLContext sslcontext = null;
   try {
     sslcontext = SSLContext.getInstance("SSL");
   } catch (NoSuchAlgorithmException e) {
     e.printStackTrace();
   }
   try {
     sslcontext.init(null, new TrustManager[] {new TrustAnyTrustManager()}, null);
   } catch (KeyManagementException e) {
     e.printStackTrace();
     return null;
   }
   return sslcontext;
 }
Example #23
0
  public DummySSLSocketFactory() {

    try {
      SSLContext sslcontent = SSLContext.getInstance("TLS");
      sslcontent.init(
          null, // KeyManager not required
          new TrustManager[] {new DummyTrustManager()},
          new java.security.SecureRandom());
      factory = sslcontent.getSocketFactory();
    } catch (NoSuchAlgorithmException e) {
      e.printStackTrace();
    } catch (KeyManagementException e) {
      e.printStackTrace();
    }
  }
  private void sslFileTransfer(String filename) {
    try {
      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(tracker.springversion1.R.raw.mykeystore);
      trusted.load(in, "mysecret".toCharArray());

      String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
      TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm);
      tmf.init(trusted);

      // Create an SSLContext that uses our TrustManager
      SSLContext context = SSLContext.getInstance("TLS");
      context.init(null, tmf.getTrustManagers(), null);

      URL url = new URL(host);
      HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection();
      urlConnection.setSSLSocketFactory(context.getSocketFactory());

      transfer(urlConnection, filename);

      //			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);
      //
      //			Socket sslsocket = sf.createSocket();
      //			sslsocket.setKeepAlive(true);
      //
      //			InetSocketAddress address = new InetSocketAddress(host, 443);
      //			sslsocket.connect(address);
      //
      //			OutputStream sout = sslsocket.getOutputStream();

    } catch (KeyStoreException e) {
      Log.v("mark", "KeyStoreException:" + e.getMessage());
    } catch (NoSuchAlgorithmException e) {
      Log.v("mark", "NoSuchAlgorithmException:" + e.getMessage());
    } catch (CertificateException e) {
      Log.v("mark", "CertificateException:" + e.getMessage());
    } catch (IOException e) {
      Log.v("mark", "IOException:" + e.getMessage());
    } catch (KeyManagementException e) {
      Log.v("mark", "KeyManagementException:" + e.getMessage());
    }
  }
  // Static block code allowing all SSL connections bypassing the certificates verification
  // See https://developer.android.com/training/articles/security-ssl.html to check the real
  // certificates
  static {

    // Default cookie manager
    CookieManager cookieManager = new CookieManager();
    CookieHandler.setDefault(cookieManager);

    // Trust all SSL certificates
    TrustManager[] trustAllCerts =
        new TrustManager[] {
          new X509TrustManager() {
            public X509Certificate[] getAcceptedIssuers() {
              X509Certificate[] myTrustedAnchors = new X509Certificate[0];
              return myTrustedAnchors;
            }

            @Override
            public void checkClientTrusted(X509Certificate[] certs, String authType) {}

            @Override
            public void checkServerTrusted(X509Certificate[] certs, String authType) {}
          }
        };

    SSLContext sc = null;
    try {
      sc = SSLContext.getInstance("SSL");

      if (sc != null) {
        sc.init(null, trustAllCerts, new SecureRandom());
      }

    } catch (NoSuchAlgorithmException e) {
      e.printStackTrace();
    } catch (KeyManagementException e) {
      e.printStackTrace();
    }

    if (sc != null) {
      HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
      HttpsURLConnection.setDefaultHostnameVerifier(
          new HostnameVerifier() {
            @Override
            public boolean verify(String arg0, SSLSession arg1) {
              return true;
            }
          });
    }
  }
 @GET
 @Path("geostop")
 @Produces(MediaType.TEXT_PLAIN)
 public int stopGeoService() {
   // GeospatialManager geoManager = new GeospatialManager();
   try {
     status = GeospatialManager.geoStop();
   } catch (KeyManagementException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (NoSuchAlgorithmException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   return status;
 }
 @Path("georestart")
 // http://cloudant-rest-example.mybluemix.net/webapi/geostart
 @Produces(MediaType.TEXT_PLAIN)
 public int restartGeoService() {
   // GeospatialManager geoManager = new GeospatialManager();
   try {
     status = GeospatialManager.geoRestart();
   } catch (KeyManagementException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (NoSuchAlgorithmException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   return status;
 }
 @POST
 @Path("georegion")
 @Produces(MediaType.APPLICATION_JSON)
 @Consumes(MediaType.APPLICATION_JSON)
 public int regionsGeoService(String addInfo) {
   try {
     status = GeospatialManager.geoRegions(addInfo);
   } catch (KeyManagementException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (NoSuchAlgorithmException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   return status;
 }
Example #29
0
  public static void main(String[] args) {
    // TODO Auto-generated method stub
    SSLContextBuilder builder = new SSLContextBuilder();
    try {
      builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());

      SSLConnectionSocketFactory sslFactory = new SSLConnectionSocketFactory(builder.build());
      CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslFactory).build();

      HttpPost httpPost =
          new HttpPost("https://*****:*****@api.netkiller.com/v1/withdraw/create.json");
      httpPost.addHeader("content-type", "application/json");
      httpPost.addHeader("Accept", "application/json");

      HttpEntity httpEntity =
          new StringEntity(
              "{\"loginname\":\"888666\", \"bankname\":\"中国银行\",\"billno\":\"B040216210517590856\",\"flag\":\"a\",\"amount\":12,\"accountnumber\":\"9555500060007000\",\"accounttype\":\"借记卡\",\"createdate\":\"2016-09-10T20:12:12\",\"remarks\":\"CFD\",\"currency\":\"CNY\",\"accountname\":\"王宝强\",\"branchname\":\"南山支行\",\"bankaddress\":\"深圳市南山区科技园\",\"customerlevel\":2,\"trustlevel\":1}",
              "UTF-8");
      httpPost.setEntity(httpEntity);

      // HttpGet("https://*****:*****@api.netkiller.com/v1/withdraw/ping.json");
      CloseableHttpResponse response = httpclient.execute(httpPost);

      System.out.println(response.getStatusLine());
      HttpEntity entity = response.getEntity();
      String responseBody = EntityUtils.toString(entity, "UTF-8");
      System.out.println(responseBody.toString());
      response.close();
    } catch (NoSuchAlgorithmException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (KeyStoreException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (KeyManagementException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (ClientProtocolException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } finally {

    }
  }
Example #30
-1
  @Override
  public void onApplicationEvent(final ContextRefreshedEvent arg0) {

    final RegisterServiceDTO dto = new RegisterServiceDTO();
    dto.setName("spahl_haug_dice_v1");
    dto.setDescription("DiceService von Louisa Spahl und Torben Haug");
    dto.setService("dice");
    try {
      SSLUtil.turnOffSslChecking();
      dto.setUri(
          "http://" + getLocalHostLANAddress().getHostAddress() + ":" + getServerPort() + "/dice");
    } catch (final UnknownHostException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (final KeyManagementException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (final NoSuchAlgorithmException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    final RestTemplate restTemplate = new RestTemplate();
    final String base64Creds = "YWJxMzI5OkRLR1JIZDIwMTUy";
    final HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization", "Basic " + base64Creds);
    final HttpEntity<RegisterServiceDTO> request = new HttpEntity<RegisterServiceDTO>(dto, headers);
    final ResponseEntity<ResponseRegisterServiceDTO> registerServiceDTO =
        restTemplate.postForEntity(
            "https://vs-docker.informatik.haw-hamburg.de/ports/8053/services",
            request,
            ResponseRegisterServiceDTO.class);
    System.out.println(registerServiceDTO.getBody().get_uri());
    Main.setServiceID(registerServiceDTO.getBody().get_uri());
  }