android:orientation="vertical" >
<TextView
- android:id="@+id/untrusted_header"
+ android:id="@+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ssl_validator_header"
/>
<TextView
- android:id="@+id/untrusted_reason_cert_not_trusted"
+ android:id="@+id/reason_cert_not_trusted"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:textAppearance="?android:attr/textAppearanceSmall"
/>
+
+ <TextView
+ android:id="@+id/reason_cert_expired"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="left"
+ android:paddingLeft="20dp"
+ android:text="@string/ssl_validator_reason_cert_expired"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ />
+
+ <TextView
+ android:id="@+id/reason_cert_not_yet_valid"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="left"
+ android:paddingLeft="20dp"
+ android:text="@string/ssl_validator_reason_cert_not_yet_valid"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ />
+
+ <TextView
+ android:id="@+id/reason_hostname_not_verified"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="left"
+ android:paddingLeft="20dp"
+ android:text="@string/ssl_validator_reason_hostname_not_verified"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ />
+
<ScrollView
- android:id="@+id/untrusted_details_scroll"
+ android:id="@+id/details_scroll"
android:visibility="gone"
android:padding="20dp"
android:layout_width="wrap_content"
android:layout_height="180dp">
<LinearLayout
- android:id="@+id/untrusted_details_view"
+ android:id="@+id/details_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:orientation="vertical" >
<TextView
- android:id="@+id/untrusted_null_cert"
+ android:id="@+id/null_cert"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
- android:id="@+id/untrusted_label_subject"
+ android:id="@+id/label_subject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
/>
<TextView
- android:id="@+id/untrusted_label_subject_CN"
+ android:id="@+id/label_subject_CN"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ssl_validator_label_CN"
/>
<TextView
- android:id="@+id/untrusted_value_subject_CN"
+ android:id="@+id/value_subject_CN"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
/>
<TextView
- android:id="@+id/untrusted_label_subject_O"
+ android:id="@+id/label_subject_O"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ssl_validator_label_O"
/>
<TextView
- android:id="@+id/untrusted_value_subject_O"
+ android:id="@+id/value_subject_O"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
/>
<TextView
- android:id="@+id/untrusted_label_subject_OU"
+ android:id="@+id/label_subject_OU"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ssl_validator_label_OU"
/>
<TextView
- android:id="@+id/untrusted_value_subject_OU"
+ android:id="@+id/value_subject_OU"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
/>
<TextView
- android:id="@+id/untrusted_label_subject_ST"
+ android:id="@+id/label_subject_ST"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ssl_validator_label_ST"
/>
<TextView
- android:id="@+id/untrusted_value_subject_ST"
+ android:id="@+id/value_subject_ST"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
/>
<TextView
- android:id="@+id/untrusted_label_subject_C"
+ android:id="@+id/label_subject_C"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ssl_validator_label_C"
/>
<TextView
- android:id="@+id/untrusted_value_subject_C"
+ android:id="@+id/value_subject_C"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
/>
<TextView
- android:id="@+id/untrusted_label_subject_L"
+ android:id="@+id/label_subject_L"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ssl_validator_label_L"
/>
<TextView
- android:id="@+id/untrusted_value_subject_L"
+ android:id="@+id/value_subject_L"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
<TextView
- android:id="@+id/untrusted_label_issuer"
+ android:id="@+id/label_issuer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
/>
<TextView
- android:id="@+id/untrusted_label_issuer_CN"
+ android:id="@+id/label_issuer_CN"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ssl_validator_label_CN"
/>
<TextView
- android:id="@+id/untrusted_value_issuer_CN"
+ android:id="@+id/value_issuer_CN"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
/>
<TextView
- android:id="@+id/untrusted_label_issuer_O"
+ android:id="@+id/label_issuer_O"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ssl_validator_label_O"
/>
<TextView
- android:id="@+id/untrusted_value_issuer_O"
+ android:id="@+id/value_issuer_O"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
/>
<TextView
- android:id="@+id/untrusted_label_issuer_OU"
+ android:id="@+id/label_issuer_OU"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ssl_validator_label_OU"
/>
<TextView
- android:id="@+id/untrusted_value_issuer_OU"
+ android:id="@+id/value_issuer_OU"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
/>
<TextView
- android:id="@+id/untrusted_label_issuer_ST"
+ android:id="@+id/label_issuer_ST"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ssl_validator_label_ST"
/>
<TextView
- android:id="@+id/untrusted_value_issuer_ST"
+ android:id="@+id/value_issuer_ST"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
/>
<TextView
- android:id="@+id/untrusted_label_issuer_C"
+ android:id="@+id/label_issuer_C"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ssl_validator_label_C"
/>
<TextView
- android:id="@+id/untrusted_value_issuer_C"
+ android:id="@+id/value_issuer_C"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
/>
<TextView
- android:id="@+id/untrusted_label_issuer_L"
+ android:id="@+id/label_issuer_L"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ssl_validator_label_L"
/>
<TextView
- android:id="@+id/untrusted_value_issuer_L"
+ android:id="@+id/value_issuer_L"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
/>
<TextView
- android:id="@+id/untrusted_label_validity"
+ android:id="@+id/label_validity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
/>
<TextView
- android:id="@+id/untrusted_label_validity_from"
+ android:id="@+id/label_validity_from"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ssl_validator_label_validity_from"
/>
<TextView
- android:id="@+id/untrusted_value_validity_from"
+ android:id="@+id/value_validity_from"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
/>
<TextView
- android:id="@+id/untrusted_label_validity_to"
+ android:id="@+id/label_validity_to"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ssl_validator_label_validity_to"
/>
<TextView
- android:id="@+id/untrusted_value_validity_to"
+ android:id="@+id/value_validity_to"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
<TextView
- android:id="@+id/untrusted_label_signature"
+ android:id="@+id/label_signature"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
/>
<TextView
- android:id="@+id/untrusted_label_signature_algorithm"
+ android:id="@+id/label_signature_algorithm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ssl_validator_label_signature_algorithm"
/>
<TextView
- android:id="@+id/untrusted_value_signature_algorithm"
+ android:id="@+id/value_signature_algorithm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
<TextView
- android:id="@+id/untrusted_value_signature"
+ android:id="@+id/value_signature"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
</ScrollView>
<TextView
- android:id="@+id/untrusted_question"
+ android:id="@+id/question"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:gravity="center" >
<Button
- android:id="@+id/untrusted_cancel"
+ android:id="@+id/cancel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/common_cancel" />
<Button
- android:id="@+id/untrusted_details_btn"
+ android:id="@+id/details_btn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/ssl_validator_btn_details_see" />
<Button
- android:id="@+id/untrusted_ok"
+ android:id="@+id/ok"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="180dp">
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ <LinearLayout
android:id="@+id/details_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<string name ="default_display_name_for_root_folder">ownCloud</string>
<!-- URLs and flags related -->
- <string name="server_url"></string>
+ <string name="server_url">https://test1.owncloud.com/oc6-shib</string>
<bool name="show_server_url_input">true</bool>
<bool name="show_welcome_link">true</bool>
<string name="welcome_link_url">"https://owncloud.com/mobile/new"</string>
<!-- Flags to setup the authentication methods available in the app -->
<string name="auth_method_oauth2">off</string>
- <string name="auth_method_saml_web_sso">off</string>
+ <string name="auth_method_saml_web_sso">on</string>
<!-- Colors -->
<color name="login_background_color">#FFFFFF</color>
\r
package com.owncloud.android.authentication;\r
\r
+import java.security.cert.X509Certificate;\r
+\r
import android.accounts.Account;\r
import android.accounts.AccountManager;\r
import android.app.AlertDialog;\r
import android.graphics.Rect;\r
import android.graphics.drawable.Drawable;\r
import android.net.Uri;\r
+import android.net.http.SslError;\r
import android.os.Bundle;\r
import android.os.Handler;\r
import android.preference.PreferenceManager;\r
import android.support.v4.app.Fragment;\r
+import android.support.v4.app.FragmentManager;\r
+import android.support.v4.app.FragmentTransaction;\r
import android.text.Editable;\r
import android.text.InputType;\r
import android.text.TextWatcher;\r
import com.owncloud.android.lib.resources.users.GetRemoteUserNameOperation;\r
import com.owncloud.android.ui.dialog.SamlWebViewDialog;\r
-import com.owncloud.android.ui.dialog.SslValidatorDialog;\r
+import com.owncloud.android.ui.dialog.SslUntrustedCertDialog;\r
+import com.owncloud.android.ui.dialog.SslUntrustedCertDialog.OnSslUntrustedCertListener;\r
import com.owncloud.android.ui.dialog.SslValidatorDialog.OnSslValidatorListener;\r
import com.owncloud.android.utils.Log_OC;\r
import com.owncloud.android.lib.resources.status.OwnCloudVersion;\r
* @author David A. Velasco\r
*/\r
public class AuthenticatorActivity extends AccountAuthenticatorActivity\r
-implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeListener, OnEditorActionListener, SsoWebViewClientListener{\r
+ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeListener, OnEditorActionListener, \r
+ SsoWebViewClientListener, OnSslUntrustedCertListener {\r
\r
private static final String TAG = AuthenticatorActivity.class.getSimpleName();\r
\r
private static final String AUTH_OPTIONAL = "optional";\r
\r
private static final int DIALOG_LOGIN_PROGRESS = 0;\r
- private static final int DIALOG_SSL_VALIDATOR = 1;\r
- private static final int DIALOG_CERT_NOT_SAVED = 2;\r
- private static final int DIALOG_OAUTH2_LOGIN_PROGRESS = 3;\r
+ private static final int DIALOG_CERT_NOT_SAVED = 1;\r
+ private static final int DIALOG_OAUTH2_LOGIN_PROGRESS = 2;\r
\r
public static final byte ACTION_CREATE = 0;\r
public static final byte ACTION_UPDATE_TOKEN = 1;\r
private Thread mOperationThread;\r
private GetRemoteStatusOperation mOcServerChkOperation;\r
private ExistenceCheckRemoteOperation mAuthCheckOperation;\r
- private RemoteOperationResult mLastSslUntrustedServerResult;\r
\r
private Uri mNewCapturedUriFromOAuth2Redirection;\r
\r
\r
private boolean mResumed; // Control if activity is resumed\r
\r
+ private String DIALOG_UNTRUSTED_CERT = "DIALOG_UNTRUSTED_CERT";\r
+\r
\r
/**\r
* {@inheritDoc}\r
\r
/// very special case (TODO: move to a common place for all the remote operations)\r
if (result.getCode() == ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED) {\r
- mLastSslUntrustedServerResult = result;\r
- showDialog(DIALOG_SSL_VALIDATOR); \r
+ showUntrustedCertDialog(result);\r
}\r
\r
/// retrieve discovered version and normalize server URL\r
\r
// very special case (TODO: move to a common place for all the remote operations) (dangerous here?)\r
if (result.getCode() == ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED) {\r
- mLastSslUntrustedServerResult = result;\r
- showDialog(DIALOG_SSL_VALIDATOR); \r
+ showUntrustedCertDialog(result);\r
}\r
\r
} else { // authorization fail due to client side - probably wrong credentials\r
case DIALOG_CERT_NOT_SAVED:\r
case DIALOG_OAUTH2_LOGIN_PROGRESS:\r
break;\r
- case DIALOG_SSL_VALIDATOR: {\r
- ((SslValidatorDialog)dialog).updateResult(mLastSslUntrustedServerResult);\r
- break;\r
- }\r
default:\r
Log_OC.e(TAG, "Incorrect dialog called with id = " + id);\r
}\r
dialog = working_dialog;\r
break;\r
}\r
- case DIALOG_SSL_VALIDATOR: {\r
- /// TODO start to use new dialog interface, at least for this (it is a FragmentDialog already)\r
- dialog = SslValidatorDialog.newInstance(this, mLastSslUntrustedServerResult, this);\r
- break;\r
- }\r
case DIALOG_CERT_NOT_SAVED: {\r
AlertDialog.Builder builder = new AlertDialog.Builder(this);\r
builder.setMessage(getResources().getString(R.string.ssl_validator_not_saved));\r
*/\r
public void onSavedCertificate() {\r
checkOcServer();\r
+ reloadWebView();\r
+ \r
}\r
\r
/**\r
@Override\r
public void onFailedSavingCertificate() {\r
showDialog(DIALOG_CERT_NOT_SAVED);\r
+ cancelWebView();\r
}\r
\r
\r
\r
}\r
\r
-\r
-\r
public void reloadWebView() {\r
Fragment fd = getSupportFragmentManager().findFragmentByTag(TAG_SAML_DIALOG);\r
if (fd != null && fd instanceof SamlWebViewDialog) {\r
((SamlWebViewDialog) fd).reloadWebView();\r
}\r
}\r
+\r
+ @Override\r
+ public void onCancelCertificate() {\r
+ cancelWebView();\r
+ }\r
+ \r
+ /**\r
+ * Show untrusted cert dialog \r
+ */\r
+ public void showUntrustedCertDialog(X509Certificate x509Certificate, SslError error) {\r
+ // Show a dialog with the certificate info\r
+ SslUntrustedCertDialog dialog = SslUntrustedCertDialog.newInstance(x509Certificate, error);\r
+ FragmentManager fm = getSupportFragmentManager();\r
+ FragmentTransaction ft = fm.beginTransaction();\r
+ dialog.show(ft, DIALOG_UNTRUSTED_CERT);\r
+ \r
+ }\r
+ \r
+ /**\r
+ * Show untrusted cert dialog \r
+ */\r
+ public void showUntrustedCertDialog(RemoteOperationResult result) {\r
+ // Show a dialog with the certificate info\r
+ SslUntrustedCertDialog dialog = SslUntrustedCertDialog.newInstance(result, this);\r
+ FragmentManager fm = getSupportFragmentManager();\r
+ FragmentTransaction ft = fm.beginTransaction();\r
+ dialog.show(ft, DIALOG_UNTRUSTED_CERT);\r
+ \r
+ }\r
+ \r
+ /**\r
+ * Dismiss untrusted cert dialog\r
+ */\r
+ public void dismissUntrustedCertDialog(){\r
+ Fragment frag = getSupportFragmentManager().findFragmentByTag(DIALOG_UNTRUSTED_CERT);\r
+ if (frag != null) {\r
+ SslUntrustedCertDialog dialog = (SslUntrustedCertDialog) frag;\r
+ dialog.dismiss();\r
+ }\r
+ }\r
\r
}\r
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
-import com.owncloud.android.R;
import com.owncloud.android.lib.common.network.NetworkUtils;
-import com.owncloud.android.ui.dialog.SslUntrustedCertDialog;
-import com.owncloud.android.ui.dialog.SslUntrustedCertDialog.OnSslUntrustedCertListener;
import com.owncloud.android.utils.Log_OC;
-import android.app.AlertDialog;
import android.content.Context;
-import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.net.http.SslCertificate;
import android.net.http.SslError;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
-import android.support.v4.app.FragmentActivity;
-import android.support.v4.app.FragmentManager;
-import android.support.v4.app.FragmentTransaction;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.CookieManager;
*
* @author David A. Velasco
*/
-public class SsoWebViewClient extends WebViewClient implements OnSslUntrustedCertListener {
+public class SsoWebViewClient extends WebViewClient {
private static final String TAG = SsoWebViewClient.class.getSimpleName();
-
- public final static String DIALOG_UNTRUSTED_CERT = "UNTRUSTED CERT";
public interface SsoWebViewClientListener {
public void onSsoFinished(String sessionCookie);
handler.proceed();
} else {
// Show a dialog with the certificate info
- SslUntrustedCertDialog dialog = SslUntrustedCertDialog.newInstance(mContext, x509Certificate, this, handler);
- FragmentManager fm = ((FragmentActivity)mContext).getSupportFragmentManager();
- FragmentTransaction ft = fm.beginTransaction();
- dialog.show(ft, DIALOG_UNTRUSTED_CERT);
+ ((AuthenticatorActivity)mContext).showUntrustedCertDialog(x509Certificate, error);
+// SslUntrustedCertDialog dialog = SslUntrustedCertDialog.newInstance(mContext, x509Certificate, error);
+// FragmentManager fm = ((FragmentActivity)mContext).getSupportFragmentManager();
+// FragmentTransaction ft = fm.beginTransaction();
+// dialog.show(ft, DIALOG_UNTRUSTED_CERT);
handler.cancel();
}
}
return false;
}
- @Override
- public void onFailedSavingCertificate() {
- AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
- builder.setMessage(mContext.getString(R.string.ssl_validator_not_saved));
- builder.setCancelable(false);
- builder.setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- dialog.dismiss();
- };
- });
- builder.create().show();
-
- }
-
}
package com.owncloud.android.ui.activity;
import java.io.File;
-
import android.accounts.Account;
import android.app.AlertDialog;
import android.app.Dialog;
import android.preference.PreferenceManager;
import android.provider.MediaStore;
import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
//import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import com.owncloud.android.services.OperationsService;
import com.owncloud.android.syncadapter.FileSyncAdapter;
import com.owncloud.android.ui.dialog.EditNameDialog;
+import com.owncloud.android.ui.dialog.SslUntrustedCertDialog;
import com.owncloud.android.ui.dialog.EditNameDialog.EditNameDialogListener;
-import com.owncloud.android.ui.dialog.SslValidatorDialog;
-import com.owncloud.android.ui.dialog.SslValidatorDialog.OnSslValidatorListener;
+import com.owncloud.android.ui.dialog.SslUntrustedCertDialog.OnSslUntrustedCertListener;
import com.owncloud.android.ui.fragment.FileDetailFragment;
import com.owncloud.android.ui.fragment.FileFragment;
import com.owncloud.android.ui.fragment.OCFileListFragment;
*/
public class FileDisplayActivity extends HookActivity implements
-OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNavigationListener, OnSslValidatorListener, EditNameDialogListener {
+OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNavigationListener, OnSslUntrustedCertListener, EditNameDialogListener {
private ArrayAdapter<String> mDirectories;
public static final int DIALOG_SHORT_WAIT = 0;
private static final int DIALOG_CHOOSE_UPLOAD_SOURCE = 1;
- private static final int DIALOG_SSL_VALIDATOR = 2;
- private static final int DIALOG_CERT_NOT_SAVED = 3;
+ //private static final int DIALOG_SSL_VALIDATOR = 2;
+ private static final int DIALOG_CERT_NOT_SAVED = 2;
public static final String ACTION_DETAILS = "com.owncloud.android.ui.activity.action.DETAILS";
private boolean mSyncInProgress = false;
//private boolean mRefreshSharesInProgress = false;
+ private String DIALOG_UNTRUSTED_CERT;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
Log_OC.d(TAG, "onCreate() start");
@Override
- protected void onPrepareDialog(int id, Dialog dialog, Bundle args) {
- if (id == DIALOG_SSL_VALIDATOR && mLastSslUntrustedServerResult != null) {
- ((SslValidatorDialog)dialog).updateResult(mLastSslUntrustedServerResult);
- }
- }
-
-
- @Override
protected Dialog onCreateDialog(int id) {
Dialog dialog = null;
AlertDialog.Builder builder;
dialog = builder.create();
break;
}
- case DIALOG_SSL_VALIDATOR: {
- dialog = SslValidatorDialog.newInstance(this, mLastSslUntrustedServerResult, this);
- break;
- }
case DIALOG_CERT_NOT_SAVED: {
builder = new AlertDialog.Builder(this);
builder.setMessage(getResources().getString(R.string.ssl_validator_not_saved));
if (synchResult != null) {
if (synchResult.getCode().equals(RemoteOperationResult.ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED)) {
mLastSslUntrustedServerResult = synchResult;
- showDialog(DIALOG_SSL_VALIDATOR);
}
}
}
if ((getSharesResult != null) &&
RemoteOperationResult.ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED.equals(getSharesResult.getCode())) {
mLastSslUntrustedServerResult = getSharesResult;
- showDialog(DIALOG_SSL_VALIDATOR);
+ showUntrustedCertDialog(mLastSslUntrustedServerResult);
}
//setSupportProgressBarIndeterminateVisibility(mRefreshSharesInProgress || mSyncInProgress);
msg.show();
if (result.isSslRecoverableException()) {
mLastSslUntrustedServerResult = result;
- showDialog(DIALOG_SSL_VALIDATOR);
+ showUntrustedCertDialog(mLastSslUntrustedServerResult);
}
}
}
msg.show();
if (result.isSslRecoverableException()) {
mLastSslUntrustedServerResult = result;
- showDialog(DIALOG_SSL_VALIDATOR);
+ showUntrustedCertDialog(mLastSslUntrustedServerResult);
}
}
}
mRefreshSharesInProgress = true;
}
*/
+
+ /**
+ * Show untrusted cert dialog
+ */
+ public void showUntrustedCertDialog(RemoteOperationResult result) {
+ // Show a dialog with the certificate info
+ SslUntrustedCertDialog dialog = SslUntrustedCertDialog.newInstance(result, this);
+ FragmentManager fm = getSupportFragmentManager();
+ FragmentTransaction ft = fm.beginTransaction();
+ dialog.show(ft, DIALOG_UNTRUSTED_CERT);
+
+ }
+
+ /**
+ * Dismiss untrusted cert dialog
+ */
+ public void dismissUntrustedCertDialog(){
+ Fragment frag = getSupportFragmentManager().findFragmentByTag(DIALOG_UNTRUSTED_CERT);
+ if (frag != null) {
+ SslUntrustedCertDialog dialog = (SslUntrustedCertDialog) frag;
+ dialog.dismiss();
+ }
+ }
+
+ @Override
+ public void onCancelCertificate() {
+ // TODO Auto-generated method stub
+
+ }
}
import javax.security.auth.x500.X500Principal;
+import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.app.SherlockDialogFragment;
import com.owncloud.android.R;
-import com.owncloud.android.authentication.AuthenticatorActivity;
+import com.owncloud.android.lib.common.network.CertificateCombinedException;
import com.owncloud.android.lib.common.network.NetworkUtils;
+import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.utils.Log_OC;
+import android.app.Activity;
import android.app.Dialog;
-import android.content.Context;
+import android.net.http.SslError;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
-import android.webkit.SslErrorHandler;
import android.widget.Button;
import android.widget.TextView;
* Dialog to show an Untrusted Certificate
*
* @author masensio
+ * @author David A. Velasco
*
*/
public class SslUntrustedCertDialog extends SherlockDialogFragment{
private X509Certificate mCertificate;
private View mView;
- private SslErrorHandler mHandler;
-
private OnSslUntrustedCertListener mListener;
+ private SslError mError;
+ private CertificateCombinedException mException = null;
public SslUntrustedCertDialog() {
}
- public SslUntrustedCertDialog(X509Certificate cert, OnSslUntrustedCertListener listener, SslErrorHandler handler) {
+ public SslUntrustedCertDialog(X509Certificate cert, SslError error) {
mCertificate = cert;
+ mError = error;
+ }
+
+ /**
+ * Private constructor.
+ *
+ * Instances have to be created through static {@link SslUntrustedCertDialog#newInstance}.
+ *
+ * @param context Android context where the dialog will live
+ * @param e Exception causing the need of prompt the user about the server certificate.
+ * @param listener Object to notice when the server certificate was added to the local certificates store.
+ */
+ private SslUntrustedCertDialog(RemoteOperationResult result, OnSslUntrustedCertListener listener) {
mListener = listener;
- mHandler = handler;
+ if (result.isSslRecoverableException()) {
+ mException = (CertificateCombinedException) result.getException();
+ mCertificate = mException.getServerCertificate();
+ }
}
+
- public static SslUntrustedCertDialog newInstance(Context context, X509Certificate cert, OnSslUntrustedCertListener listener,
- SslErrorHandler handler) {
+ public static SslUntrustedCertDialog newInstance(X509Certificate cert, SslError error) {
if (cert != null){
- SslUntrustedCertDialog dialog = new SslUntrustedCertDialog(cert, listener, handler);
+ SslUntrustedCertDialog dialog = new SslUntrustedCertDialog(cert, error);
+ return dialog;
+ } else { // TODO Review this case
+ SslUntrustedCertDialog dialog = new SslUntrustedCertDialog();
+ return dialog;
+ }
+ }
+
+
+
+ /**
+ * Creates a new SslUntrustedCertDialog to ask the user if an untrusted certificate from a server should
+ * be trusted.
+ *
+ * @param context Android context where the dialog will live.
+ * @param result Result of a failed remote operation.
+ * @param listener Object to notice when the server certificate was added to the local certificates store.
+ * @return A new SslUntrustedCertDialog instance. NULL if the operation can not be recovered
+ * by setting the certificate as reliable.
+ */
+ public static SslUntrustedCertDialog newInstance(RemoteOperationResult result, OnSslUntrustedCertListener listener) {
+ if (result != null && result.isSslRecoverableException()) {
+ SslUntrustedCertDialog dialog = new SslUntrustedCertDialog(result, listener);
return dialog;
} else {
return null;
}
@Override
+ public void onAttach(Activity activity) {
+ super.onAttach(activity);
+ if (activity instanceof SherlockActivity) {
+ mListener = (OnSslUntrustedCertListener) activity;
+ }
+ }
+
+ @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Create a view by inflating desired layout
mView = inflater.inflate(R.layout.ssl_untrusted_cert_layout, container, false);
- Button ok = (Button) mView.findViewById(R.id.untrusted_ok);
+ updateException(mException);
+
+ Button ok = (Button) mView.findViewById(R.id.ok);
ok.setOnClickListener(new OnClickListener() {
@Override
saveServerCert();
dismiss();
if (mListener != null) {
- ((AuthenticatorActivity)getSherlockActivity()).reloadWebView();
-
+ mListener.onSavedCertificate();
}
else
Log_OC.d(TAG, "Nobody there to notify the certificate was saved");
} catch (GeneralSecurityException e) {
dismiss();
if (mListener != null) {
- ((AuthenticatorActivity)getSherlockActivity()).cancelWebView();
mListener.onFailedSavingCertificate();
}
Log_OC.e(TAG, "Server certificate could not be saved in the known servers trust store ", e);
} catch (IOException e) {
dismiss();
if (mListener != null) {
- ((AuthenticatorActivity)getSherlockActivity()).cancelWebView();
mListener.onFailedSavingCertificate();
}
Log_OC.e(TAG, "Server certificate could not be saved in the known servers trust store ", e);
}
});
- Button cancel = (Button) mView.findViewById(R.id.untrusted_cancel);
+ Button cancel = (Button) mView.findViewById(R.id.cancel);
cancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
getDialog().cancel();
- ((AuthenticatorActivity)getSherlockActivity()).cancelWebView();
+ mListener.onCancelCertificate();
}
});
- Button details = (Button) mView.findViewById(R.id.untrusted_details_btn);
+ Button details = (Button) mView.findViewById(R.id.details_btn);
details.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
- View detailsScroll = mView.findViewById(R.id.untrusted_details_scroll);
+ View detailsScroll = mView.findViewById(R.id.details_scroll);
if (detailsScroll.getVisibility() == View.VISIBLE) {
detailsScroll.setVisibility(View.GONE);
((Button) v).setText(R.string.ssl_validator_btn_details_see);
super.onDestroyView();
}
+
+ private void updateException(CertificateCombinedException exception) {
+
+ /// clean
+ mView.findViewById(R.id.reason_cert_not_trusted).setVisibility(View.GONE);
+ mView.findViewById(R.id.reason_cert_expired).setVisibility(View.GONE);
+ mView.findViewById(R.id.reason_cert_not_yet_valid).setVisibility(View.GONE);
+ mView.findViewById(R.id.reason_hostname_not_verified).setVisibility(View.GONE);
+ mView.findViewById(R.id.details_scroll).setVisibility(View.GONE);
+
+
+ if (mException != null) {
+
+ /// refresh
+ if (mException.getCertPathValidatorException() != null) {
+ ((TextView)mView.findViewById(R.id.reason_cert_not_trusted)).setVisibility(View.VISIBLE);
+ }
+
+ if (mException.getCertificateExpiredException() != null) {
+ ((TextView)mView.findViewById(R.id.reason_cert_expired)).setVisibility(View.VISIBLE);
+ }
+
+ if (mException.getCertificateNotYetValidException() != null) {
+ ((TextView)mView.findViewById(R.id.reason_cert_not_yet_valid)).setVisibility(View.VISIBLE);
+ }
+
+ if (mException.getSslPeerUnverifiedException() != null ) {
+ ((TextView)mView.findViewById(R.id.reason_hostname_not_verified)).setVisibility(View.VISIBLE);
+ }
+
+ }
+
+ }
+
private void showCertificateData(X509Certificate cert) {
- TextView nullCerView = (TextView) mView.findViewById(R.id.untrusted_null_cert);
+ TextView nullCerView = (TextView) mView.findViewById(R.id.null_cert);
if (cert != null) {
nullCerView.setVisibility(View.GONE);
}
private void showSignature(X509Certificate cert) {
- TextView sigView = ((TextView)mView.findViewById(R.id.untrusted_value_signature));
- TextView algorithmView = ((TextView)mView.findViewById(R.id.untrusted_value_signature_algorithm));
+ TextView sigView = ((TextView)mView.findViewById(R.id.value_signature));
+ TextView algorithmView = ((TextView)mView.findViewById(R.id.value_signature_algorithm));
sigView.setText(getHex(cert.getSignature()));
algorithmView.setText(cert.getSigAlgName());
}
@SuppressWarnings("deprecation")
private void showValidity(Date notBefore, Date notAfter) {
- TextView fromView = ((TextView)mView.findViewById(R.id.untrusted_value_validity_from));
- TextView toView = ((TextView)mView.findViewById(R.id.untrusted_value_validity_to));
+ TextView fromView = ((TextView)mView.findViewById(R.id.value_validity_from));
+ TextView toView = ((TextView)mView.findViewById(R.id.value_validity_to));
fromView.setText(notBefore.toLocaleString());
toView.setText(notAfter.toLocaleString());
}
private void showSubject(X500Principal subject) {
Map<String, String> s = parsePrincipal(subject);
- TextView cnView = ((TextView)mView.findViewById(R.id.untrusted_value_subject_CN));
- TextView oView = ((TextView)mView.findViewById(R.id.untrusted_value_subject_O));
- TextView ouView = ((TextView)mView.findViewById(R.id.untrusted_value_subject_OU));
- TextView cView = ((TextView)mView.findViewById(R.id.untrusted_value_subject_C));
- TextView stView = ((TextView)mView.findViewById(R.id.untrusted_value_subject_ST));
- TextView lView = ((TextView)mView.findViewById(R.id.untrusted_value_subject_L));
+ TextView cnView = ((TextView)mView.findViewById(R.id.value_subject_CN));
+ TextView oView = ((TextView)mView.findViewById(R.id.value_subject_O));
+ TextView ouView = ((TextView)mView.findViewById(R.id.value_subject_OU));
+ TextView cView = ((TextView)mView.findViewById(R.id.value_subject_C));
+ TextView stView = ((TextView)mView.findViewById(R.id.value_subject_ST));
+ TextView lView = ((TextView)mView.findViewById(R.id.value_subject_L));
if (s.get("CN") != null) {
cnView.setText(s.get("CN"));
private void showIssuer(X500Principal issuer) {
Map<String, String> s = parsePrincipal(issuer);
- TextView cnView = ((TextView)mView.findViewById(R.id.untrusted_value_issuer_CN));
- TextView oView = ((TextView)mView.findViewById(R.id.untrusted_value_issuer_O));
- TextView ouView = ((TextView)mView.findViewById(R.id.untrusted_value_issuer_OU));
- TextView cView = ((TextView)mView.findViewById(R.id.untrusted_value_issuer_C));
- TextView stView = ((TextView)mView.findViewById(R.id.untrusted_value_issuer_ST));
- TextView lView = ((TextView)mView.findViewById(R.id.untrusted_value_issuer_L));
+ TextView cnView = ((TextView)mView.findViewById(R.id.value_issuer_CN));
+ TextView oView = ((TextView)mView.findViewById(R.id.value_issuer_O));
+ TextView ouView = ((TextView)mView.findViewById(R.id.value_issuer_OU));
+ TextView cView = ((TextView)mView.findViewById(R.id.value_issuer_C));
+ TextView stView = ((TextView)mView.findViewById(R.id.value_issuer_ST));
+ TextView lView = ((TextView)mView.findViewById(R.id.value_issuer_L));
if (s.get("CN") != null) {
cnView.setText(s.get("CN"));
public interface OnSslUntrustedCertListener {
+ public void onSavedCertificate();
+ public void onCancelCertificate();
public void onFailedSavingCertificate();
}
+
+
+
}