android: Imported certificates may be clicked to delete them
authorTobias Brunner <tobias@strongswan.org>
Fri, 30 May 2014 17:52:40 +0000 (19:52 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 22 Jul 2014 08:41:50 +0000 (10:41 +0200)
src/frontends/android/res/values-de/strings.xml
src/frontends/android/res/values-pl/strings.xml
src/frontends/android/res/values-ru/strings.xml
src/frontends/android/res/values-ua/strings.xml
src/frontends/android/res/values/strings.xml
src/frontends/android/src/org/strongswan/android/ui/CertificateDeleteConfirmationDialog.java [new file with mode: 0644]
src/frontends/android/src/org/strongswan/android/ui/TrustedCertificatesActivity.java

index 269ac67..c9b6f9d 100644 (file)
@@ -79,6 +79,8 @@
     <string name="system_tab">System</string>
     <string name="user_tab">Benutzer</string>
     <string name="local_tab">Importiert</string>
+    <string name="delete_certificate_question">Zertifikat löschen?</string>
+    <string name="delete_certificate">Das Zertifikat wird permanent entfernt!</string>
 
     <!-- VPN state fragment -->
     <string name="state_label">Status:</string>
index 1e05a66..5bde18c 100644 (file)
@@ -79,6 +79,8 @@
     <string name="system_tab">System</string>
     <string name="user_tab">Użytkownik</string>
     <string name="local_tab">Imported</string>
+    <string name="delete_certificate_question">Delete certificate?</string>
+    <string name="delete_certificate">The certificate will be permanently removed!</string>
 
     <!-- VPN state fragment -->
     <string name="state_label">Status:</string>
index d90c28f..f61b251 100644 (file)
@@ -76,6 +76,8 @@
     <string name="system_tab">Система</string>
     <string name="user_tab">Пользователь</string>
     <string name="local_tab">Imported</string>
+    <string name="delete_certificate_question">Delete certificate?</string>
+    <string name="delete_certificate">The certificate will be permanently removed!</string>
 
     <!-- VPN state fragment -->
     <string name="state_label">Статус:</string>
index fe1e619..bff97ec 100644 (file)
@@ -77,6 +77,8 @@
     <string name="system_tab">Система</string>
     <string name="user_tab">Користувач</string>
     <string name="local_tab">Imported</string>
+    <string name="delete_certificate_question">Delete certificate?</string>
+    <string name="delete_certificate">The certificate will be permanently removed!</string>
 
     <!-- VPN state fragment -->
     <string name="state_label">Статус:</string>
index 7a80088..f03d3e4 100644 (file)
@@ -79,6 +79,8 @@
     <string name="system_tab">System</string>
     <string name="user_tab">User</string>
     <string name="local_tab">Imported</string>
+    <string name="delete_certificate_question">Delete certificate?</string>
+    <string name="delete_certificate">The certificate will be permanently removed!</string>
 
     <!-- VPN state fragment -->
     <string name="state_label">Status:</string>
diff --git a/src/frontends/android/src/org/strongswan/android/ui/CertificateDeleteConfirmationDialog.java b/src/frontends/android/src/org/strongswan/android/ui/CertificateDeleteConfirmationDialog.java
new file mode 100644 (file)
index 0000000..c381900
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2014 Tobias Brunner
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+package org.strongswan.android.ui;
+
+import org.strongswan.android.R;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.app.DialogFragment;
+import android.content.DialogInterface;
+import android.os.Bundle;
+
+/**
+ * Class that displays a confirmation dialog to delete a selected local
+ * certificate.
+ */
+public class CertificateDeleteConfirmationDialog extends DialogFragment
+{
+       public static final String ALIAS = "alias";
+       OnCertificateDeleteListener mListener;
+
+       /**
+        * Interface that can be implemented by parent activities to get the
+        * alias of the certificate to delete, if the user confirms the deletion.
+        */
+       public interface OnCertificateDeleteListener
+       {
+               public void onDelete(String alias);
+       }
+
+       @Override
+       public void onAttach(Activity activity)
+       {
+               super.onAttach(activity);
+               if (activity instanceof OnCertificateDeleteListener)
+               {
+                       mListener = (OnCertificateDeleteListener)activity;
+               }
+       }
+
+       @Override
+       public Dialog onCreateDialog(Bundle savedInstanceState)
+       {
+               return new AlertDialog.Builder(getActivity())
+                       .setIcon(android.R.drawable.ic_dialog_alert)
+                       .setTitle(R.string.delete_certificate_question)
+                       .setMessage(R.string.delete_certificate)
+                       .setPositiveButton(R.string.delete_profile, new DialogInterface.OnClickListener() {
+                               @Override
+                               public void onClick(DialogInterface dialog, int whichButton)
+                               {
+                                       if (mListener != null)
+                                       {
+                                               mListener.onDelete(getArguments().getString(ALIAS));
+                                       }
+                               }
+                       })
+                       .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
+                               @Override
+                               public void onClick(DialogInterface dialog, int which)
+                               {
+                                       dismiss();
+                               }
+                       }).create();
+       }
+}
index c175fb9..1211ef5 100644 (file)
 
 package org.strongswan.android.ui;
 
+import java.security.KeyStore;
+
 import org.strongswan.android.R;
 import org.strongswan.android.data.VpnProfileDataSource;
 import org.strongswan.android.logic.TrustedCertificateManager;
 import org.strongswan.android.logic.TrustedCertificateManager.TrustedCertificateSource;
 import org.strongswan.android.security.TrustedCertificateEntry;
+import org.strongswan.android.ui.CertificateDeleteConfirmationDialog.OnCertificateDeleteListener;
 
 import android.app.ActionBar;
 import android.app.ActionBar.Tab;
@@ -31,9 +34,10 @@ import android.os.Bundle;
 import android.view.Menu;
 import android.view.MenuItem;
 
-public class TrustedCertificatesActivity extends Activity implements TrustedCertificateListFragment.OnTrustedCertificateSelectedListener
+public class TrustedCertificatesActivity extends Activity implements TrustedCertificateListFragment.OnTrustedCertificateSelectedListener, OnCertificateDeleteListener
 {
        public static final String SELECT_CERTIFICATE = "org.strongswan.android.action.SELECT_CERTIFICATE";
+       private static final String DIALOG_TAG = "Dialog";
        private boolean mSelect;
 
        @Override
@@ -113,6 +117,35 @@ public class TrustedCertificatesActivity extends Activity implements TrustedCert
                        setResult(Activity.RESULT_OK, intent);
                        finish();
                }
+               else
+               {
+                       TrustedCertificatesTabListener listener;
+                       listener = (TrustedCertificatesTabListener)getActionBar().getSelectedTab().getTag();
+                       if (listener.mTag == "local")
+                       {
+                               Bundle args = new Bundle();
+                               args.putString(CertificateDeleteConfirmationDialog.ALIAS, selected.getAlias());
+                               CertificateDeleteConfirmationDialog dialog = new CertificateDeleteConfirmationDialog();
+                               dialog.setArguments(args);
+                               dialog.show(this.getFragmentManager(), DIALOG_TAG);
+                       }
+               }
+       }
+
+       @Override
+       public void onDelete(String alias)
+       {
+               try
+               {
+                       KeyStore store = KeyStore.getInstance("LocalCertificateStore");
+                       store.load(null, null);
+                       store.deleteEntry(alias);
+                       reloadCertificates();
+               }
+               catch (Exception e)
+               {
+                       e.printStackTrace();
+               }
        }
 
        private void reloadCertificates()