@@ -281,88 +281,4 @@ public static String[] jsonArrayToArray(JSONArray jsonArray) throws JSONExceptio
281281 public static ILogger getLogger () {
282282 return AdjustFactory .getLogger ();
283283 }
284-
285-
286- static UtilNetworking .IConnectionOptions testConnectionOptions () {
287- return new UtilNetworking .IConnectionOptions () {
288- @ Override
289- public void applyConnectionOptions (final HttpsURLConnection connection ,
290- final String clientSdk )
291- {
292- UtilNetworking .IConnectionOptions defaultConnectionOption =
293- UtilNetworking .createDefaultConnectionOptions ();
294- defaultConnectionOption .applyConnectionOptions (connection , clientSdk );
295- try {
296- SSLContext sc = SSLContext .getInstance ("TLS" );
297- sc .init (null , new TrustManager []{
298- new X509TrustManager () {
299- public java .security .cert .X509Certificate [] getAcceptedIssuers () {
300- Log .d ("TestApp" ,"getAcceptedIssuers" );
301- return null ;
302- }
303- public void checkClientTrusted (
304- X509Certificate [] certs , String authType ) {
305- Log .d ("TestApp" ,"checkClientTrusted " );
306- }
307- public void checkServerTrusted (
308- X509Certificate [] certs , String authType ) throws CertificateException {
309- Log .d ("TestApp" ,"checkServerTrusted " );
310-
311- String serverThumbprint = "7BCFF44099A35BC093BB48C5A6B9A516CDFDA0D1" ;
312- X509Certificate certificate = certs [0 ];
313-
314- MessageDigest md = null ;
315- try {
316- md = MessageDigest .getInstance ("SHA1" );
317- byte [] publicKey = md .digest (certificate .getEncoded ());
318- String hexString = byte2HexFormatted (publicKey );
319-
320- if (!hexString .equalsIgnoreCase (serverThumbprint )) {
321- throw new CertificateException ();
322- }
323- } catch (NoSuchAlgorithmException e ) {
324- Log .e ("TestApp" ,"testingMode error " + e .getMessage ());
325- } catch (CertificateEncodingException e ) {
326- Log .e ("TestApp" ,"testingMode error " + e .getMessage ());
327- }
328- }
329- }
330- }, new java .security .SecureRandom ());
331- connection .setSSLSocketFactory (sc .getSocketFactory ());
332-
333- connection .setHostnameVerifier (new HostnameVerifier () {
334- @ Override
335- public boolean verify (String hostname , SSLSession session ) {
336- Log .d ("TestApp" ,"verify hostname " );
337- return true ;
338- }
339- });
340- } catch (Exception e ) {
341- Log .e ("TestApp" ,"testingMode error " + e .getMessage ());
342- }
343- }
344- };
345- }
346-
347- private static String byte2HexFormatted (byte [] arr ) {
348- StringBuilder str = new StringBuilder (arr .length * 2 );
349-
350- for (int i = 0 ; i < arr .length ; i ++) {
351- String h = Integer .toHexString (arr [i ]);
352- int l = h .length ();
353-
354- if (l == 1 ) {
355- h = "0" + h ;
356- }
357-
358- if (l > 2 ) {
359- h = h .substring (l - 2 , l );
360- }
361-
362- str .append (h .toUpperCase ());
363-
364- // if (i < (arr.length - 1)) str.append(':');
365- }
366- return str .toString ();
367- }
368284}
0 commit comments