<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>
<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>
<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>
<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>
<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>
--- /dev/null
+/*
+ * 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();
+ }
+}
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;
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
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()