Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

+ Adds Android Market links support.

+ Fix url shorteners redirections to SSL hosts (https).
  • Loading branch information...
commit eb802361195a3f9e5fbb22cc61811afa2385a1d5 1 parent 96233a3
@skarcha authored
Showing with 99 additions and 1 deletion.
  1. +7 −0 AndroidManifest.xml
  2. +92 −1 src/com/skarcha/nobrowser/Main.java
View
7 AndroidManifest.xml
@@ -25,6 +25,13 @@
<action android:name="android.intent.action.VIEW"></action>
<category android:name="android.intent.category.DEFAULT"></category>
<category android:name="android.intent.category.BROWSABLE"></category>
+ <data android:scheme="http" android:host="market.android.com"></data>
+ <data android:scheme="https" android:host="market.android.com"></data>
+ </intent-filter>
+ <intent-filter>
+ <action android:name="android.intent.action.VIEW"></action>
+ <category android:name="android.intent.category.DEFAULT"></category>
+ <category android:name="android.intent.category.BROWSABLE"></category>
<data android:host="bit.ly" android:scheme="http"></data>
<data android:host="goo.gl" android:scheme="http"></data>
<data android:host="is.gd" android:scheme="http"></data>
View
93 src/com/skarcha/nobrowser/Main.java
@@ -4,6 +4,8 @@
import java.net.URI;
import java.net.URISyntaxException;
+import javax.net.ssl.SSLException;
+
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
@@ -11,6 +13,9 @@
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpHead;
+import org.apache.http.conn.ssl.AbstractVerifier;
+import org.apache.http.conn.ssl.SSLSocketFactory;
+import org.apache.http.conn.ssl.X509HostnameVerifier;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.BasicHttpContext;
@@ -68,6 +73,10 @@ public void onCreate(Bundle savedInstanceState) {
finishIntent = processTwitlonger(finalUrl);
}
+ else if (finalUrl.contains("://market.android.com")) {
+ finishIntent = processMarket(finalUrl);
+ }
+
else {
finishIntent = processDefault(finalUrl);
}
@@ -153,6 +162,29 @@ private String getContent (String url) throws IOException, IOException {
return description;
}
+ private boolean processMarket (String url) {
+ String MarketUrl = null;
+
+ try {
+ URI oldUri = new URI(url);
+ String path = oldUri.getPath();
+ String query = oldUri.getQuery();
+ MarketUrl = "market:/" + path + "?" + query;
+ } catch (URISyntaxException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ if (MarketUrl != null) {
+ Intent intent = new Intent();
+ intent.setAction(Intent.ACTION_VIEW);
+ intent.setData(android.net.Uri.parse(MarketUrl));
+ startActivity(intent);
+ }
+
+ return true;
+ }
+
private boolean processDefault (String url) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
@@ -196,7 +228,8 @@ private String getFinalURL (String url) throws IOException, IOException {
return YoutubeUrl;
}
- HttpClient httpclient = new DefaultHttpClient();
+ //HttpClient httpclient = new DefaultHttpClient();
+ HttpClient httpclient = getTolerantClient();
try {
HttpHead httphead = new HttpHead(url);
HttpContext localContext = new BasicHttpContext();
@@ -223,4 +256,62 @@ private void getPrefs() {
private void toast(String texto) {
Toast.makeText(this, texto, Toast.LENGTH_SHORT).show();
}
+
+/*
+ * Black box for me at the moment.
+ * Extracted from: http://stackoverflow.com/questions/3135679/android-httpclient-hostname-in-certificate-didnt-match-example-com-exa/3136980#3136980
+ *
+ * This is the ugly hack to this message:
+ * javax.net.ssl.SSLException: hostname in certificate didn't match <market.android.com> != <*.google.com>
+ *
+ * Ugly hack start here...
+ */
+
+ class MyVerifier extends AbstractVerifier {
+
+ private final X509HostnameVerifier delegate;
+
+ public MyVerifier(final X509HostnameVerifier delegate) {
+ this.delegate = delegate;
+ }
+
+ @Override
+ public void verify(String host, String[] cns, String[] subjectAlts)
+ throws SSLException {
+/*
+ boolean ok = false;
+ try {
+ delegate.verify(host, cns, subjectAlts);
+ } catch (SSLException e) {
+ for (String cn : cns) {
+ if (cn.startsWith("*.")) {
+ try {
+ delegate.verify(host, new String[] {
+ cn.substring(2) }, subjectAlts);
+ ok = true;
+ } catch (Exception e1) { }
+ }
+ }
+ if(!ok) throw e;
+ }
+*/
+ }
+ }
+
+ public DefaultHttpClient getTolerantClient() {
+ DefaultHttpClient client = new DefaultHttpClient();
+ SSLSocketFactory sslSocketFactory = (SSLSocketFactory) client
+ .getConnectionManager().getSchemeRegistry().getScheme("https")
+ .getSocketFactory();
+ final X509HostnameVerifier delegate = sslSocketFactory
+ .getHostnameVerifier();
+ if (!(delegate instanceof MyVerifier)) {
+ sslSocketFactory.setHostnameVerifier(new MyVerifier(delegate));
+ }
+ return client;
+ }
+
+/*
+ * Ugly hack ends here...
+ */
}
Please sign in to comment.
Something went wrong with that request. Please try again.