From 8099de4d0e04379abbec2f1931d37d9b89fbb529 Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Tue, 3 Jun 2014 12:55:13 +0200 Subject: Implementing clearing a CA certificate for keystone authentication method --- .../blinkt/openvpn/activities/ConfigConverter.java | 2 +- .../blinkt/openvpn/fragments/Settings_Basic.java | 15 ++++--- .../de/blinkt/openvpn/views/FileSelectLayout.java | 48 ++++++++++++++++------ main/src/main/res/layout/basic_settings.xml | 3 ++ main/src/main/res/layout/file_select.xml | 25 +++++++---- main/src/main/res/values/attrs.xml | 1 + 6 files changed, 68 insertions(+), 26 deletions(-) (limited to 'main/src') diff --git a/main/src/main/java/de/blinkt/openvpn/activities/ConfigConverter.java b/main/src/main/java/de/blinkt/openvpn/activities/ConfigConverter.java index f870e8a9..d4884ce8 100644 --- a/main/src/main/java/de/blinkt/openvpn/activities/ConfigConverter.java +++ b/main/src/main/java/de/blinkt/openvpn/activities/ConfigConverter.java @@ -340,7 +340,7 @@ public class ConfigConverter extends Activity implements FileSelectCallback { } boolean isCert = type == Utils.FileType.CA_CERTIFICATE || type == Utils.FileType.CLIENT_CERTIFICATE; - FileSelectLayout fl = new FileSelectLayout(this, getString(titleRes), isCert); + FileSelectLayout fl = new FileSelectLayout(this, getString(titleRes), isCert, false); fileSelectMap.put(type, fl); fl.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); diff --git a/main/src/main/java/de/blinkt/openvpn/fragments/Settings_Basic.java b/main/src/main/java/de/blinkt/openvpn/fragments/Settings_Basic.java index 4145c65f..63d41a9c 100644 --- a/main/src/main/java/de/blinkt/openvpn/fragments/Settings_Basic.java +++ b/main/src/main/java/de/blinkt/openvpn/fragments/Settings_Basic.java @@ -26,14 +26,15 @@ import android.widget.EditText; import android.widget.Spinner; import android.widget.TextView; import android.widget.ToggleButton; -import de.blinkt.openvpn.views.FileSelectLayout; + +import java.security.cert.X509Certificate; + import de.blinkt.openvpn.R; -import de.blinkt.openvpn.VpnProfile; import de.blinkt.openvpn.R.id; +import de.blinkt.openvpn.VpnProfile; import de.blinkt.openvpn.core.ProfileManager; import de.blinkt.openvpn.core.X509Utils; - -import java.security.cert.X509Certificate; +import de.blinkt.openvpn.views.FileSelectLayout; public class Settings_Basic extends Fragment implements View.OnClickListener, OnItemSelectedListener, Callback, FileSelectLayout.FileSelectCallback { private static final int CHOOSE_FILE_OFFSET = 1000; @@ -207,7 +208,8 @@ public class Settings_Basic extends Fragment implements View.OnClickListener, On mView.findViewById(R.id.statickeys).setVisibility(View.GONE); mView.findViewById(R.id.keystore).setVisibility(View.GONE); mView.findViewById(R.id.cacert).setVisibility(View.GONE); - mView.findViewById(R.id.userpassword).setVisibility(View.GONE); + ((FileSelectLayout) mView.findViewById(R.id.caselect)).setClearable(false); + mView.findViewById(R.id.userpassword).setVisibility(View.GONE); mView.findViewById(R.id.key_password_layout).setVisibility(View.GONE); // Fall through are by design @@ -236,7 +238,8 @@ public class Settings_Basic extends Fragment implements View.OnClickListener, On case VpnProfile.TYPE_KEYSTORE: mView.findViewById(R.id.keystore).setVisibility(View.VISIBLE); mView.findViewById(R.id.cacert).setVisibility(View.VISIBLE); - break; + ((FileSelectLayout) mView.findViewById(R.id.caselect)).setClearable(true); + break; case VpnProfile.TYPE_USERPASS: mView.findViewById(R.id.userpassword).setVisibility(View.VISIBLE); diff --git a/main/src/main/java/de/blinkt/openvpn/views/FileSelectLayout.java b/main/src/main/java/de/blinkt/openvpn/views/FileSelectLayout.java index 665b525f..fc2c1f37 100644 --- a/main/src/main/java/de/blinkt/openvpn/views/FileSelectLayout.java +++ b/main/src/main/java/de/blinkt/openvpn/views/FileSelectLayout.java @@ -1,10 +1,5 @@ package de.blinkt.openvpn.views; -import de.blinkt.openvpn.R; -import de.blinkt.openvpn.VpnProfile; -import de.blinkt.openvpn.activities.FileSelect; -import de.blinkt.openvpn.core.VpnStatus; -import de.blinkt.openvpn.core.X509Utils; import android.content.Context; import android.content.Intent; import android.content.res.TypedArray; @@ -14,15 +9,23 @@ import android.view.View.OnClickListener; import android.widget.Button; import android.widget.LinearLayout; import android.widget.TextView; -import de.blinkt.openvpn.fragments.Utils; -import java.io.*; +import java.io.IOException; -import static android.os.Build.*; +import de.blinkt.openvpn.R; +import de.blinkt.openvpn.VpnProfile; +import de.blinkt.openvpn.activities.FileSelect; +import de.blinkt.openvpn.core.VpnStatus; +import de.blinkt.openvpn.core.X509Utils; +import de.blinkt.openvpn.fragments.Utils; + +import static android.os.Build.VERSION; +import static android.os.Build.VERSION_CODES; public class FileSelectLayout extends LinearLayout implements OnClickListener { + public void parseResponse(Intent data, Context c) { if (VERSION.SDK_INT < VERSION_CODES.KITKAT) { String fileData = data.getStringExtra(FileSelect.RESULT_DATA); @@ -60,26 +63,30 @@ public class FileSelectLayout extends LinearLayout implements OnClickListener { private String mTitle; private boolean mShowClear; private TextView mDataDetails; + private Button mShowClearButton; + public FileSelectLayout(Context context, AttributeSet attrset) { super(context, attrset); TypedArray ta = context.obtainStyledAttributes(attrset, R.styleable.FileSelectLayout); - setupViews(ta.getString(R.styleable.FileSelectLayout_title), ta.getBoolean(R.styleable.FileSelectLayout_certificate, true)); + setupViews(ta.getString(R.styleable.FileSelectLayout_title), ta.getBoolean(R.styleable.FileSelectLayout_certificate, true), + ta.getBoolean(R.styleable.FileSelectLayout_showClear,false)); ta.recycle(); } - public FileSelectLayout (Context context, String title, boolean isCerticate) + public FileSelectLayout (Context context, String title, boolean isCerticate, boolean showClear) { super(context); - setupViews(title, isCerticate); + setupViews(title, isCerticate, showClear); + mShowClear = showClear; } - private void setupViews(String title, boolean isCertificate) { + private void setupViews(String title, boolean isCertificate, boolean showClear) { inflate(getContext(), R.layout.file_select, this); mTitle = title; @@ -92,6 +99,17 @@ public class FileSelectLayout extends LinearLayout implements OnClickListener { mDataDetails = (TextView) findViewById(R.id.file_selected_description); mSelectButton = (Button) findViewById(R.id.file_select_button); mSelectButton.setOnClickListener(this); + + mShowClearButton = (Button) findViewById(R.id.file_clear_button); + mShowClearButton.setOnClickListener(this); + } + + public void setClearable(boolean clearable) + { + mShowClear = clearable; + if (mShowClearButton != null && mData !=null) + mShowClearButton.setVisibility(mShowClear? VISIBLE : GONE); + } @@ -123,6 +141,7 @@ public class FileSelectLayout extends LinearLayout implements OnClickListener { if (data == null) { mDataView.setText(c.getString(R.string.no_data)); mDataDetails.setText(""); + mShowClearButton.setVisibility(GONE); } else { if (mData.startsWith(VpnProfile.DISPLAYNAME_TAG)) { mDataView.setText(c.getString(R.string.imported_from_file, VpnProfile.getDisplayName(mData))); @@ -132,6 +151,9 @@ public class FileSelectLayout extends LinearLayout implements OnClickListener { mDataView.setText(data); if (mIsCertificate) mDataDetails.setText(X509Utils.getCertificateFriendlyName(c, data)); + + // Show clear button if it should be shown + mShowClearButton.setVisibility(mShowClear? VISIBLE : GONE); } } @@ -145,6 +167,8 @@ public class FileSelectLayout extends LinearLayout implements OnClickListener { } else { getCertificateFileDialog(); } + } else if (v == mShowClearButton) { + setData(null, getContext()); } } diff --git a/main/src/main/res/layout/basic_settings.xml b/main/src/main/res/layout/basic_settings.xml index d5d8d2e3..86e0640e 100644 --- a/main/src/main/res/layout/basic_settings.xml +++ b/main/src/main/res/layout/basic_settings.xml @@ -107,13 +107,16 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" + tools:visibility="visible" android:visibility="gone" > + + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_margin="8dip" + android:gravity="center_vertical"> -