Эх сурвалжийг харах

OC-3163: Check if the certificate is in the app cetificates repository (mKnownServers of NetworkUtils)

masensio 11 жил өмнө
parent
commit
1ace8a21ef

+ 1 - 1
owncloud-android-library

@@ -1 +1 @@
-Subproject commit cd4414a7bda686c84e1ca75dd10bcbf9b3f57f83
+Subproject commit b274963153efb8620071e958182adc3349dceb4e

+ 24 - 4
src/com/owncloud/android/authentication/SsoWebViewClient.java

@@ -20,7 +20,6 @@ package com.owncloud.android.authentication;
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.lang.ref.WeakReference;
-import java.security.KeyStore;
 import java.security.KeyStoreException;
 import java.security.NoSuchAlgorithmException;
 import java.security.cert.Certificate;
@@ -65,12 +64,14 @@ public class SsoWebViewClient extends WebViewClient {
         public void onSsoFinished(String sessionCookie);
     }
     
+    private Context mContext;
     private Handler mListenerHandler;
     private WeakReference<SsoWebViewClientListener> mListenerRef;
     private String mTargetUrl;
     private String mLastReloadedUrlAtError;
     
-    public SsoWebViewClient (Handler listenerHandler, SsoWebViewClientListener listener) {
+    public SsoWebViewClient (Context context, Handler listenerHandler, SsoWebViewClientListener listener) {
+        mContext = context;
         mListenerHandler = listenerHandler;
         mListenerRef = new WeakReference<SsoWebViewClient.SsoWebViewClientListener>(listener);
         mTargetUrl = "fake://url.to.be.set";
@@ -152,13 +153,32 @@ public class SsoWebViewClient extends WebViewClient {
         Log_OC.d(TAG, "onReceivedSslError : " + error);
         // Test 1
         X509Certificate x509Certificate = getX509CertificateFromError(error);
+        boolean isKnowServer = false;
         
         if (x509Certificate != null) {
             Log_OC.d(TAG, "------>>>>> x509Certificate " + x509Certificate.toString());
             
+            try {
+                isKnowServer = NetworkUtils.isCertInKnownServersStore((Certificate) x509Certificate, mContext);
+            } catch (KeyStoreException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            } catch (NoSuchAlgorithmException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            } catch (CertificateException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            } catch (IOException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
         }
-        
-        handler.proceed();
+         if (isKnowServer) {
+             handler.proceed();
+         } else {
+             
+         }
     }
     
     /**

+ 1 - 1
src/com/owncloud/android/ui/dialog/SamlWebViewDialog.java

@@ -103,7 +103,7 @@ public class SamlWebViewDialog extends SherlockDialogFragment {
         try {
             mSsoWebViewClientListener = (SsoWebViewClientListener) activity;
             mHandler = new Handler();
-            mWebViewClient = new SsoWebViewClient(mHandler, mSsoWebViewClientListener);
+            mWebViewClient = new SsoWebViewClient(activity, mHandler, mSsoWebViewClientListener);
             
        } catch (ClassCastException e) {
             throw new ClassCastException(activity.toString() + " must implement " + SsoWebViewClientListener.class.getSimpleName());