… | |
… | |
53 | import java.io.RandomAccessFile;
|
53 | import java.io.RandomAccessFile;
|
54 | import java.net.HttpURLConnection;
|
54 | import java.net.HttpURLConnection;
|
55 | import java.net.URL;
|
55 | import java.net.URL;
|
56 | import java.security.MessageDigest;
|
56 | import java.security.MessageDigest;
|
57 | import java.security.NoSuchAlgorithmException;
|
57 | import java.security.NoSuchAlgorithmException;
|
|
|
58 | import java.security.SecureRandom;
|
58 | import java.text.DecimalFormat;
|
59 | import java.text.DecimalFormat;
|
59 | import java.text.NumberFormat;
|
60 | import java.text.NumberFormat;
|
60 | import java.util.ArrayList;
|
61 | import java.util.ArrayList;
|
61 | import java.util.Iterator;
|
62 | import java.util.Iterator;
|
62 | import java.util.List;
|
63 | import java.util.List;
|
|
|
64 |
|
|
|
65 | import javax.net.ssl.HostnameVerifier;
|
|
|
66 | import javax.net.ssl.HttpsURLConnection;
|
|
|
67 | import javax.net.ssl.SSLContext;
|
|
|
68 | import javax.net.ssl.SSLSession;
|
|
|
69 | import javax.net.ssl.X509TrustManager;
|
63 |
|
70 |
|
64 | import android.os.Bundle;
|
71 | import android.os.Bundle;
|
65 | import android.os.Handler;
|
72 | import android.os.Handler;
|
66 | import android.os.Message;
|
73 | import android.os.Message;
|
67 | import android.util.Log;
|
74 | import android.util.Log;
|
… | |
… | |
70 | {
|
77 | {
|
71 | static final String ZANAVI_MAPS_BASE_URL = "http://dl.zanavi.cc/data/";
|
78 | static final String ZANAVI_MAPS_BASE_URL = "http://dl.zanavi.cc/data/";
|
72 | static final String ZANAVI_MAPS_SEVERTEXT_URL = "http://dl.zanavi.cc/server.txt";
|
79 | static final String ZANAVI_MAPS_SEVERTEXT_URL = "http://dl.zanavi.cc/server.txt";
|
73 | static final String ZANAVI_MAPS_BASE_URL_PROTO = "http://";
|
80 | static final String ZANAVI_MAPS_BASE_URL_PROTO = "http://";
|
74 | static final String ZANAVI_MAPS_BASE_URL_WO_SERVERNAME = "/data/";
|
81 | static final String ZANAVI_MAPS_BASE_URL_WO_SERVERNAME = "/data/";
|
|
|
82 | // static final String ZANAVI_MAPS_BASE_URL = "https://192.168.0.3:446/maps/";
|
|
|
83 | // static final String ZANAVI_MAPS_SEVERTEXT_URL = "https://192.168.0.3:446/maps/server.txt";
|
|
|
84 | // static final String ZANAVI_MAPS_BASE_URL_PROTO = "https://";
|
|
|
85 | // static final String ZANAVI_MAPS_BASE_URL_WO_SERVERNAME = "/maps/";
|
75 |
|
86 |
|
76 | static int MULTI_NUM_THREADS = 1; // how many download streams for 1 file
|
87 | static int MULTI_NUM_THREADS = 1; // how many download streams for 1 file
|
77 |
|
88 |
|
78 | public static class zanavi_osm_map_values
|
89 | public static class zanavi_osm_map_values
|
79 | {
|
90 | {
|
… | |
… | |
2055 | exit_code = 0;
|
2066 | exit_code = 0;
|
2056 |
|
2067 |
|
2057 | return exit_code;
|
2068 | return exit_code;
|
2058 | }
|
2069 | }
|
2059 |
|
2070 |
|
|
|
2071 | private void trust_Every_ssl_cert()
|
|
|
2072 | {
|
|
|
2073 | // NEVER enable this on a production release!!!!!!!!!!
|
|
|
2074 | try
|
|
|
2075 | {
|
|
|
2076 | HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier()
|
|
|
2077 | {
|
|
|
2078 | public boolean verify(String hostname, SSLSession session)
|
|
|
2079 | {
|
|
|
2080 | Log.d("NavitMapDownloader", "DANGER !!! trusted hostname=" + hostname + " DANGER !!!");
|
|
|
2081 | // return true -> mean we trust this cert !! DANGER !! DANGER !!
|
|
|
2082 | return true;
|
|
|
2083 | }
|
|
|
2084 | });
|
|
|
2085 | SSLContext context = SSLContext.getInstance("TLS");
|
|
|
2086 | context.init(null, new X509TrustManager[] { new X509TrustManager()
|
|
|
2087 | {
|
|
|
2088 | public java.security.cert.X509Certificate[] getAcceptedIssuers()
|
|
|
2089 | {
|
|
|
2090 | return new java.security.cert.X509Certificate[0];
|
|
|
2091 | }
|
|
|
2092 |
|
|
|
2093 | @Override
|
|
|
2094 | public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws java.security.cert.CertificateException
|
|
|
2095 | {
|
|
|
2096 | }
|
|
|
2097 |
|
|
|
2098 | @Override
|
|
|
2099 | public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws java.security.cert.CertificateException
|
|
|
2100 | {
|
|
|
2101 | }
|
|
|
2102 | } }, new SecureRandom());
|
|
|
2103 | HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
|
|
|
2104 | }
|
|
|
2105 | catch (Exception e)
|
|
|
2106 | {
|
|
|
2107 | e.printStackTrace();
|
|
|
2108 | }
|
|
|
2109 | // NEVER enable this on a production release!!!!!!!!!!
|
|
|
2110 | }
|
|
|
2111 |
|
2060 | public String d_get_servername()
|
2112 | public String d_get_servername()
|
2061 | {
|
2113 | {
|
|
|
2114 | // this is only for debugging
|
|
|
2115 | // NEVER enable this on a production release!!!!!!!!!!
|
|
|
2116 | // NEVER enable this on a production release!!!!!!!!!!
|
|
|
2117 | // trust_Every_ssl_cert();
|
|
|
2118 | // NEVER enable this on a production release!!!!!!!!!!
|
|
|
2119 | // NEVER enable this on a production release!!!!!!!!!!
|
|
|
2120 |
|
2062 | String servername = null;
|
2121 | String servername = null;
|
2063 | try
|
2122 | try
|
2064 | {
|
2123 | {
|
2065 | URL url = new URL(ZANAVI_MAPS_SEVERTEXT_URL);
|
2124 | URL url = new URL(ZANAVI_MAPS_SEVERTEXT_URL);
|
2066 | System.out.println(ZANAVI_MAPS_SEVERTEXT_URL);
|
2125 | System.out.println(ZANAVI_MAPS_SEVERTEXT_URL);
|
|
|
2126 |
|
2067 | HttpURLConnection c = (HttpURLConnection) url.openConnection();
|
2127 | HttpURLConnection c = (HttpURLConnection) url.openConnection();
|
2068 | c.addRequestProperty("User-Agent", Navit.UserAgentString);
|
2128 | c.addRequestProperty("User-Agent", Navit.UserAgentString);
|
2069 | c.addRequestProperty("Pragma", "no-cache");
|
2129 | c.addRequestProperty("Pragma", "no-cache");
|
2070 |
|
2130 |
|
2071 | c.setRequestMethod("GET");
|
2131 | c.setRequestMethod("GET");
|