summaryrefslogtreecommitdiff
path: root/main/src
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2014-06-03 12:55:13 +0200
committerArne Schwabe <arne@rfc2549.org>2014-06-03 12:55:13 +0200
commit8099de4d0e04379abbec2f1931d37d9b89fbb529 (patch)
treefca8cf1d2812c1034de86edb32c29bf5e6b71efc /main/src
parent7e6b8f0c0173ff419f604739bc05905475a770f3 (diff)
Implementing clearing a CA certificate for keystone authentication method
Diffstat (limited to 'main/src')
-rw-r--r--main/src/main/java/de/blinkt/openvpn/activities/ConfigConverter.java2
-rw-r--r--main/src/main/java/de/blinkt/openvpn/fragments/Settings_Basic.java15
-rw-r--r--main/src/main/java/de/blinkt/openvpn/views/FileSelectLayout.java48
-rw-r--r--main/src/main/res/layout/basic_settings.xml3
-rw-r--r--main/src/main/res/layout/file_select.xml25
-rw-r--r--main/src/main/res/values/attrs.xml1
6 files changed, 68 insertions, 26 deletions
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" >
<de.blinkt.openvpn.views.FileSelectLayout
android:id="@+id/caselect"
android:layout_width="match_parent"
android:layout_height="wrap_content"
+ blinkt:showClear="true"
blinkt:title="@string/ca_title" />
+
</LinearLayout>
<LinearLayout
diff --git a/main/src/main/res/layout/file_select.xml b/main/src/main/res/layout/file_select.xml
index 5e40b3a8..b6b2091a 100644
--- a/main/src/main/res/layout/file_select.xml
+++ b/main/src/main/res/layout/file_select.xml
@@ -17,12 +17,13 @@
<!-- A layout to select a certificate, akin to a file selector on web pages. -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_margin="8dip"
- android:gravity="center_vertical" >
+ 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">
- <Button
+<Button
android:id="@+id/file_select_button"
style="@style/accountSetupButton"
android:layout_width="wrap_content"
@@ -30,13 +31,23 @@
android:layout_alignParentRight="true"
android:text="@string/file_select" />
+ <Button
+ android:id="@+id/file_clear_button"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:layout_toLeftOf="@id/file_select_button"
+ android:visibility="gone"
+ tools:visibility="visible"
+ android:text="@string/clear"/>
+
<TextView
android:id="@+id/file_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
- android:layout_toLeftOf="@+id/file_select_button"
+ android:layout_toLeftOf="@+id/file_clear_button"
android:text="@string/client_certificate_title"
android:textStyle="bold" />
@@ -47,7 +58,7 @@
android:layout_alignParentLeft="true"
android:layout_below="@+id/file_title"
android:layout_marginLeft="16dip"
- android:layout_toLeftOf="@+id/file_select_button"
+ android:layout_toLeftOf="@+id/file_clear_button"
android:ellipsize="end"
android:singleLine="true"
android:text="@string/file_nothing_selected" />
diff --git a/main/src/main/res/values/attrs.xml b/main/src/main/res/values/attrs.xml
index 527664f8..7c8f4d71 100644
--- a/main/src/main/res/values/attrs.xml
+++ b/main/src/main/res/values/attrs.xml
@@ -5,5 +5,6 @@
<attr name="title" format="string|reference" />
<attr name="certificate" format="boolean" />
<!-- <attr name="taskid" format="integer" /> -->
+ <attr name="showClear" format="boolean" />
</declare-styleable>
</resources>