2012-07-17 17:23:21 +00:00
|
|
|
/*
|
2017-06-27 13:17:43 +00:00
|
|
|
* Copyright (C) 2012-2017 Tobias Brunner
|
2012-07-17 17:23:21 +00:00
|
|
|
* Copyright (C) 2012 Giuliano Grassi
|
|
|
|
* Copyright (C) 2012 Ralf Sager
|
2016-04-30 08:42:00 +00:00
|
|
|
* HSR Hochschule fuer Technik Rapperswil
|
2012-07-17 17:23:21 +00:00
|
|
|
*
|
|
|
|
* 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;
|
|
|
|
|
2013-07-03 14:27:36 +00:00
|
|
|
import android.app.Dialog;
|
2012-08-28 12:09:18 +00:00
|
|
|
import android.content.Context;
|
2012-08-07 16:03:51 +00:00
|
|
|
import android.content.DialogInterface;
|
2012-07-17 17:45:23 +00:00
|
|
|
import android.content.Intent;
|
2012-08-28 12:09:18 +00:00
|
|
|
import android.os.AsyncTask;
|
2017-08-24 13:18:32 +00:00
|
|
|
import android.os.Build;
|
2012-07-17 17:23:21 +00:00
|
|
|
import android.os.Bundle;
|
2012-08-28 12:09:18 +00:00
|
|
|
import android.security.KeyChain;
|
|
|
|
import android.security.KeyChainAliasCallback;
|
|
|
|
import android.security.KeyChainException;
|
2016-12-29 16:02:22 +00:00
|
|
|
import android.support.v4.content.LocalBroadcastManager;
|
2016-04-15 15:36:31 +00:00
|
|
|
import android.support.v7.app.AlertDialog;
|
2015-11-25 16:05:56 +00:00
|
|
|
import android.support.v7.app.AppCompatActivity;
|
2016-04-15 15:36:31 +00:00
|
|
|
import android.support.v7.app.AppCompatDialogFragment;
|
2016-04-29 13:37:35 +00:00
|
|
|
import android.text.Editable;
|
2013-07-03 14:27:36 +00:00
|
|
|
import android.text.Html;
|
2016-04-30 11:11:49 +00:00
|
|
|
import android.text.SpannableString;
|
|
|
|
import android.text.Spanned;
|
2016-04-29 13:37:35 +00:00
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.text.TextWatcher;
|
2017-11-14 10:18:13 +00:00
|
|
|
import android.text.method.LinkMovementMethod;
|
2012-07-17 17:23:21 +00:00
|
|
|
import android.util.Log;
|
2012-07-17 17:45:23 +00:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
|
|
|
import android.view.MenuItem;
|
2012-08-07 16:03:51 +00:00
|
|
|
import android.view.View;
|
2012-08-14 09:47:32 +00:00
|
|
|
import android.view.View.OnClickListener;
|
2012-08-27 14:51:41 +00:00
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.AdapterView;
|
|
|
|
import android.widget.AdapterView.OnItemSelectedListener;
|
2016-04-30 11:11:49 +00:00
|
|
|
import android.widget.ArrayAdapter;
|
2012-08-07 16:03:51 +00:00
|
|
|
import android.widget.CheckBox;
|
|
|
|
import android.widget.CompoundButton;
|
|
|
|
import android.widget.CompoundButton.OnCheckedChangeListener;
|
2012-07-17 17:23:21 +00:00
|
|
|
import android.widget.EditText;
|
2016-04-30 11:11:49 +00:00
|
|
|
import android.widget.MultiAutoCompleteTextView;
|
2014-07-14 12:24:31 +00:00
|
|
|
import android.widget.RelativeLayout;
|
2012-08-27 14:51:41 +00:00
|
|
|
import android.widget.Spinner;
|
2017-06-29 12:52:28 +00:00
|
|
|
import android.widget.Switch;
|
2014-07-14 12:24:31 +00:00
|
|
|
import android.widget.TextView;
|
2012-07-17 17:23:21 +00:00
|
|
|
|
2015-11-25 16:05:56 +00:00
|
|
|
import org.strongswan.android.R;
|
|
|
|
import org.strongswan.android.data.VpnProfile;
|
2017-06-27 13:17:43 +00:00
|
|
|
import org.strongswan.android.data.VpnProfile.SelectedAppsHandling;
|
2015-11-25 16:05:56 +00:00
|
|
|
import org.strongswan.android.data.VpnProfileDataSource;
|
|
|
|
import org.strongswan.android.data.VpnType;
|
|
|
|
import org.strongswan.android.data.VpnType.VpnTypeFeature;
|
|
|
|
import org.strongswan.android.logic.TrustedCertificateManager;
|
|
|
|
import org.strongswan.android.security.TrustedCertificateEntry;
|
2016-04-30 15:04:45 +00:00
|
|
|
import org.strongswan.android.ui.adapter.CertificateIdentitiesAdapter;
|
2016-04-30 08:42:00 +00:00
|
|
|
import org.strongswan.android.ui.widget.TextInputLayoutHelper;
|
2016-12-29 16:02:22 +00:00
|
|
|
import org.strongswan.android.utils.Constants;
|
2017-06-21 16:29:48 +00:00
|
|
|
import org.strongswan.android.utils.IPRangeSet;
|
2017-11-17 16:40:52 +00:00
|
|
|
import org.strongswan.android.utils.Utils;
|
2015-11-25 16:05:56 +00:00
|
|
|
|
|
|
|
import java.security.cert.X509Certificate;
|
2017-06-27 13:17:43 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.SortedSet;
|
|
|
|
import java.util.TreeSet;
|
2016-12-27 14:17:49 +00:00
|
|
|
import java.util.UUID;
|
2015-11-25 16:05:56 +00:00
|
|
|
|
|
|
|
public class VpnProfileDetailActivity extends AppCompatActivity
|
2012-07-17 17:23:21 +00:00
|
|
|
{
|
2012-08-14 09:47:32 +00:00
|
|
|
private static final int SELECT_TRUSTED_CERTIFICATE = 0;
|
2017-06-27 13:17:43 +00:00
|
|
|
private static final int SELECT_APPLICATIONS = 1;
|
2012-08-14 09:47:32 +00:00
|
|
|
|
2012-07-17 17:23:21 +00:00
|
|
|
private VpnProfileDataSource mDataSource;
|
|
|
|
private Long mId;
|
2012-08-14 09:47:32 +00:00
|
|
|
private TrustedCertificateEntry mCertEntry;
|
2012-08-28 12:09:18 +00:00
|
|
|
private String mUserCertLoading;
|
2016-04-30 15:04:45 +00:00
|
|
|
private CertificateIdentitiesAdapter mSelectUserIdAdapter;
|
|
|
|
private String mSelectedUserId;
|
2012-08-28 12:09:18 +00:00
|
|
|
private TrustedCertificateEntry mUserCertEntry;
|
2012-08-27 14:51:41 +00:00
|
|
|
private VpnType mVpnType = VpnType.IKEV2_EAP;
|
2017-06-27 13:17:43 +00:00
|
|
|
private SelectedAppsHandling mSelectedAppsHandling = SelectedAppsHandling.SELECTED_APPS_DISABLE;
|
|
|
|
private SortedSet<String> mSelectedApps = new TreeSet<>();
|
2012-07-17 17:23:21 +00:00
|
|
|
private VpnProfile mProfile;
|
2016-04-30 11:11:49 +00:00
|
|
|
private MultiAutoCompleteTextView mName;
|
2016-04-30 08:42:00 +00:00
|
|
|
private TextInputLayoutHelper mNameWrap;
|
2012-07-17 17:23:21 +00:00
|
|
|
private EditText mGateway;
|
2016-04-30 08:42:00 +00:00
|
|
|
private TextInputLayoutHelper mGatewayWrap;
|
2012-08-27 14:51:41 +00:00
|
|
|
private Spinner mSelectVpnType;
|
|
|
|
private ViewGroup mUsernamePassword;
|
2012-07-17 17:23:21 +00:00
|
|
|
private EditText mUsername;
|
2016-04-30 08:42:00 +00:00
|
|
|
private TextInputLayoutHelper mUsernameWrap;
|
2012-07-17 17:23:21 +00:00
|
|
|
private EditText mPassword;
|
2012-08-28 12:09:18 +00:00
|
|
|
private ViewGroup mUserCertificate;
|
2014-07-14 12:24:31 +00:00
|
|
|
private RelativeLayout mSelectUserCert;
|
2016-04-30 15:04:45 +00:00
|
|
|
private Spinner mSelectUserId;
|
2012-08-07 16:03:51 +00:00
|
|
|
private CheckBox mCheckAuto;
|
2014-07-14 12:24:31 +00:00
|
|
|
private RelativeLayout mSelectCert;
|
|
|
|
private RelativeLayout mTncNotice;
|
2015-06-15 14:59:12 +00:00
|
|
|
private CheckBox mShowAdvanced;
|
|
|
|
private ViewGroup mAdvancedSettings;
|
2016-04-30 11:11:49 +00:00
|
|
|
private MultiAutoCompleteTextView mRemoteId;
|
2016-04-30 10:25:49 +00:00
|
|
|
private TextInputLayoutHelper mRemoteIdWrap;
|
2015-06-15 14:59:12 +00:00
|
|
|
private EditText mMTU;
|
2016-04-30 08:42:00 +00:00
|
|
|
private TextInputLayoutHelper mMTUWrap;
|
2015-06-16 14:42:40 +00:00
|
|
|
private EditText mPort;
|
2016-04-30 08:42:00 +00:00
|
|
|
private TextInputLayoutHelper mPortWrap;
|
2017-06-29 12:52:28 +00:00
|
|
|
private Switch mCertReq;
|
2017-06-28 16:44:45 +00:00
|
|
|
private EditText mNATKeepalive;
|
|
|
|
private TextInputLayoutHelper mNATKeepaliveWrap;
|
2017-06-22 10:26:19 +00:00
|
|
|
private EditText mIncludedSubnets;
|
|
|
|
private TextInputLayoutHelper mIncludedSubnetsWrap;
|
2017-06-21 16:29:48 +00:00
|
|
|
private EditText mExcludedSubnets;
|
|
|
|
private TextInputLayoutHelper mExcludedSubnetsWrap;
|
2015-07-24 09:47:53 +00:00
|
|
|
private CheckBox mBlockIPv4;
|
|
|
|
private CheckBox mBlockIPv6;
|
2017-06-27 13:17:43 +00:00
|
|
|
private Spinner mSelectSelectedAppsHandling;
|
|
|
|
private RelativeLayout mSelectApps;
|
2017-11-14 10:18:13 +00:00
|
|
|
private TextInputLayoutHelper mIkeProposalWrap;
|
|
|
|
private EditText mIkeProposal;
|
|
|
|
private TextInputLayoutHelper mEspProposalWrap;
|
|
|
|
private EditText mEspProposal;
|
2012-08-14 09:47:32 +00:00
|
|
|
|
2012-07-17 17:23:21 +00:00
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState)
|
|
|
|
{
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
/* the title is set when we load the profile, if any */
|
2015-11-25 16:05:56 +00:00
|
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
2012-07-17 17:23:21 +00:00
|
|
|
|
|
|
|
mDataSource = new VpnProfileDataSource(this);
|
|
|
|
mDataSource.open();
|
|
|
|
|
|
|
|
setContentView(R.layout.profile_detail_view);
|
|
|
|
|
2016-04-30 11:11:49 +00:00
|
|
|
mName = (MultiAutoCompleteTextView)findViewById(R.id.name);
|
2016-04-30 08:42:00 +00:00
|
|
|
mNameWrap = (TextInputLayoutHelper)findViewById(R.id.name_wrap);
|
2012-07-17 17:23:21 +00:00
|
|
|
mGateway = (EditText)findViewById(R.id.gateway);
|
2016-04-30 08:42:00 +00:00
|
|
|
mGatewayWrap = (TextInputLayoutHelper) findViewById(R.id.gateway_wrap);
|
2012-08-27 14:51:41 +00:00
|
|
|
mSelectVpnType = (Spinner)findViewById(R.id.vpn_type);
|
2014-07-14 12:24:31 +00:00
|
|
|
mTncNotice = (RelativeLayout)findViewById(R.id.tnc_notice);
|
2012-08-27 14:51:41 +00:00
|
|
|
|
|
|
|
mUsernamePassword = (ViewGroup)findViewById(R.id.username_password_group);
|
2012-07-17 17:23:21 +00:00
|
|
|
mUsername = (EditText)findViewById(R.id.username);
|
2016-04-30 08:42:00 +00:00
|
|
|
mUsernameWrap = (TextInputLayoutHelper) findViewById(R.id.username_wrap);
|
2012-08-27 14:51:41 +00:00
|
|
|
mPassword = (EditText)findViewById(R.id.password);
|
2012-07-17 17:23:21 +00:00
|
|
|
|
2012-08-28 12:09:18 +00:00
|
|
|
mUserCertificate = (ViewGroup)findViewById(R.id.user_certificate_group);
|
2014-07-14 12:24:31 +00:00
|
|
|
mSelectUserCert = (RelativeLayout)findViewById(R.id.select_user_certificate);
|
2016-04-30 15:04:45 +00:00
|
|
|
mSelectUserId = (Spinner)findViewById(R.id.select_user_id);
|
2012-08-28 12:09:18 +00:00
|
|
|
|
2012-08-07 16:03:51 +00:00
|
|
|
mCheckAuto = (CheckBox)findViewById(R.id.ca_auto);
|
2014-07-14 12:24:31 +00:00
|
|
|
mSelectCert = (RelativeLayout)findViewById(R.id.select_certificate);
|
2012-08-27 14:51:41 +00:00
|
|
|
|
2015-06-15 14:59:12 +00:00
|
|
|
mShowAdvanced = (CheckBox)findViewById(R.id.show_advanced);
|
|
|
|
mAdvancedSettings = (ViewGroup)findViewById(R.id.advanced_settings);
|
|
|
|
|
2016-04-30 11:11:49 +00:00
|
|
|
mRemoteId = (MultiAutoCompleteTextView)findViewById(R.id.remote_id);
|
2016-04-30 10:25:49 +00:00
|
|
|
mRemoteIdWrap = (TextInputLayoutHelper) findViewById(R.id.remote_id_wrap);
|
2015-06-15 14:59:12 +00:00
|
|
|
mMTU = (EditText)findViewById(R.id.mtu);
|
2016-04-30 08:42:00 +00:00
|
|
|
mMTUWrap = (TextInputLayoutHelper) findViewById(R.id.mtu_wrap);
|
2015-06-16 14:42:40 +00:00
|
|
|
mPort = (EditText)findViewById(R.id.port);
|
2016-04-30 08:42:00 +00:00
|
|
|
mPortWrap = (TextInputLayoutHelper) findViewById(R.id.port_wrap);
|
2017-06-28 16:44:45 +00:00
|
|
|
mNATKeepalive = (EditText)findViewById(R.id.nat_keepalive);
|
|
|
|
mNATKeepaliveWrap = (TextInputLayoutHelper) findViewById(R.id.nat_keepalive_wrap);
|
2017-06-29 12:52:28 +00:00
|
|
|
mCertReq = (Switch)findViewById(R.id.cert_req);
|
2017-06-22 10:26:19 +00:00
|
|
|
mIncludedSubnets = (EditText)findViewById(R.id.included_subnets);
|
|
|
|
mIncludedSubnetsWrap = (TextInputLayoutHelper)findViewById(R.id.included_subnets_wrap);
|
2017-06-21 16:29:48 +00:00
|
|
|
mExcludedSubnets = (EditText)findViewById(R.id.excluded_subnets);
|
|
|
|
mExcludedSubnetsWrap = (TextInputLayoutHelper)findViewById(R.id.excluded_subnets_wrap);
|
2015-07-24 09:47:53 +00:00
|
|
|
mBlockIPv4 = (CheckBox)findViewById(R.id.split_tunneling_v4);
|
|
|
|
mBlockIPv6 = (CheckBox)findViewById(R.id.split_tunneling_v6);
|
2015-06-15 14:59:12 +00:00
|
|
|
|
2017-06-27 13:17:43 +00:00
|
|
|
mSelectSelectedAppsHandling = (Spinner)findViewById(R.id.apps_handling);
|
|
|
|
mSelectApps = (RelativeLayout)findViewById(R.id.select_applications);
|
|
|
|
|
2017-11-14 10:18:13 +00:00
|
|
|
mIkeProposal = (EditText)findViewById(R.id.ike_proposal);
|
|
|
|
mIkeProposalWrap = (TextInputLayoutHelper)findViewById(R.id.ike_proposal_wrap);
|
|
|
|
mEspProposal = (EditText)findViewById(R.id.esp_proposal);
|
|
|
|
mEspProposalWrap = (TextInputLayoutHelper)findViewById(R.id.esp_proposal_wrap);
|
|
|
|
/* make the link clickable */
|
|
|
|
((TextView)findViewById(R.id.proposal_intro)).setMovementMethod(LinkMovementMethod.getInstance());
|
|
|
|
|
2016-04-30 11:11:49 +00:00
|
|
|
final SpaceTokenizer spaceTokenizer = new SpaceTokenizer();
|
|
|
|
mName.setTokenizer(spaceTokenizer);
|
|
|
|
mRemoteId.setTokenizer(spaceTokenizer);
|
|
|
|
final ArrayAdapter<String> completeAdapter = new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line);
|
|
|
|
mName.setAdapter(completeAdapter);
|
|
|
|
mRemoteId.setAdapter(completeAdapter);
|
|
|
|
|
2017-08-24 13:18:32 +00:00
|
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
|
|
|
|
{
|
|
|
|
findViewById(R.id.apps).setVisibility(View.GONE);
|
|
|
|
mSelectSelectedAppsHandling.setVisibility(View.GONE);
|
|
|
|
mSelectApps.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
2016-04-29 13:37:35 +00:00
|
|
|
mGateway.addTextChangedListener(new TextWatcher() {
|
|
|
|
@Override
|
|
|
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTextChanged(CharSequence s, int start, int before, int count) {}
|
|
|
|
|
|
|
|
@Override
|
2016-04-30 08:42:00 +00:00
|
|
|
public void afterTextChanged(Editable s)
|
|
|
|
{
|
2016-04-30 11:11:49 +00:00
|
|
|
completeAdapter.clear();
|
|
|
|
completeAdapter.add(mGateway.getText().toString());
|
2016-04-29 13:37:35 +00:00
|
|
|
if (TextUtils.isEmpty(mGateway.getText()))
|
|
|
|
{
|
2016-04-30 08:42:00 +00:00
|
|
|
mNameWrap.setHelperText(getString(R.string.profile_name_hint));
|
2016-04-30 10:25:49 +00:00
|
|
|
mRemoteIdWrap.setHelperText(getString(R.string.profile_remote_id_hint));
|
2016-04-29 13:37:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-04-30 08:42:00 +00:00
|
|
|
mNameWrap.setHelperText(String.format(getString(R.string.profile_name_hint_gateway), mGateway.getText()));
|
2016-04-30 10:25:49 +00:00
|
|
|
mRemoteIdWrap.setHelperText(String.format(getString(R.string.profile_remote_id_hint_gateway), mGateway.getText()));
|
2016-04-29 13:37:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-08-27 14:51:41 +00:00
|
|
|
mSelectVpnType.setOnItemSelectedListener(new OnItemSelectedListener() {
|
|
|
|
@Override
|
|
|
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
|
|
|
|
{
|
|
|
|
mVpnType = VpnType.values()[position];
|
2012-08-28 12:09:18 +00:00
|
|
|
updateCredentialView();
|
2012-08-27 14:51:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onNothingSelected(AdapterView<?> parent)
|
|
|
|
{ /* should not happen */
|
|
|
|
mVpnType = VpnType.IKEV2_EAP;
|
2012-08-28 12:09:18 +00:00
|
|
|
updateCredentialView();
|
2012-08-27 14:51:41 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-07-14 12:24:31 +00:00
|
|
|
((TextView)mTncNotice.findViewById(android.R.id.text1)).setText(R.string.tnc_notice_title);
|
|
|
|
((TextView)mTncNotice.findViewById(android.R.id.text2)).setText(R.string.tnc_notice_subtitle);
|
2013-07-03 14:27:36 +00:00
|
|
|
mTncNotice.setOnClickListener(new OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v)
|
|
|
|
{
|
2016-04-15 15:36:31 +00:00
|
|
|
new TncNoticeDialog().show(VpnProfileDetailActivity.this.getSupportFragmentManager(), "TncNotice");
|
2013-07-03 14:27:36 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-08-28 12:09:18 +00:00
|
|
|
mSelectUserCert.setOnClickListener(new SelectUserCertOnClickListener());
|
2016-04-30 15:04:45 +00:00
|
|
|
mSelectUserIdAdapter = new CertificateIdentitiesAdapter(this);
|
|
|
|
mSelectUserId.setAdapter(mSelectUserIdAdapter);
|
|
|
|
mSelectUserId.setOnItemSelectedListener(new OnItemSelectedListener() {
|
|
|
|
@Override
|
|
|
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
|
|
|
|
{
|
|
|
|
if (mUserCertEntry != null)
|
|
|
|
{ /* we don't store the subject DN as it is in the reverse order and the default anyway */
|
|
|
|
mSelectedUserId = position == 0 ? null : mSelectUserIdAdapter.getItem(position);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onNothingSelected(AdapterView<?> parent)
|
|
|
|
{
|
|
|
|
mSelectedUserId = null;
|
|
|
|
}
|
|
|
|
});
|
2012-08-28 12:09:18 +00:00
|
|
|
|
2012-08-07 16:03:51 +00:00
|
|
|
mCheckAuto.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
|
|
|
|
{
|
2012-08-14 09:47:32 +00:00
|
|
|
updateCertificateSelector();
|
|
|
|
}
|
|
|
|
});
|
2012-08-07 16:03:51 +00:00
|
|
|
|
2012-08-14 09:47:32 +00:00
|
|
|
mSelectCert.setOnClickListener(new OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v)
|
|
|
|
{
|
|
|
|
Intent intent = new Intent(VpnProfileDetailActivity.this, TrustedCertificatesActivity.class);
|
2014-05-30 15:34:49 +00:00
|
|
|
intent.setAction(TrustedCertificatesActivity.SELECT_CERTIFICATE);
|
2012-08-14 09:47:32 +00:00
|
|
|
startActivityForResult(intent, SELECT_TRUSTED_CERTIFICATE);
|
2012-08-07 16:03:51 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-06-15 14:59:12 +00:00
|
|
|
mShowAdvanced.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
|
|
|
|
{
|
|
|
|
updateAdvancedSettings();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-06-27 13:17:43 +00:00
|
|
|
mSelectSelectedAppsHandling.setOnItemSelectedListener(new OnItemSelectedListener() {
|
|
|
|
@Override
|
|
|
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
|
|
|
|
{
|
|
|
|
mSelectedAppsHandling = SelectedAppsHandling.values()[position];
|
|
|
|
updateAppsSelector();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onNothingSelected(AdapterView<?> parent)
|
|
|
|
{ /* should not happen */
|
|
|
|
mSelectedAppsHandling = SelectedAppsHandling.SELECTED_APPS_DISABLE;
|
|
|
|
updateAppsSelector();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
mSelectApps.setOnClickListener(new OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v)
|
|
|
|
{
|
|
|
|
Intent intent = new Intent(VpnProfileDetailActivity.this, SelectedApplicationsActivity.class);
|
|
|
|
intent.putExtra(VpnProfileDataSource.KEY_SELECTED_APPS_LIST, new ArrayList<>(mSelectedApps));
|
|
|
|
startActivityForResult(intent, SELECT_APPLICATIONS);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-07-17 17:23:21 +00:00
|
|
|
mId = savedInstanceState == null ? null : savedInstanceState.getLong(VpnProfileDataSource.KEY_ID);
|
|
|
|
if (mId == null)
|
|
|
|
{
|
|
|
|
Bundle extras = getIntent().getExtras();
|
|
|
|
mId = extras == null ? null : extras.getLong(VpnProfileDataSource.KEY_ID);
|
|
|
|
}
|
|
|
|
|
2012-08-14 09:47:32 +00:00
|
|
|
loadProfileData(savedInstanceState);
|
2012-08-07 16:03:51 +00:00
|
|
|
|
2012-08-28 12:09:18 +00:00
|
|
|
updateCredentialView();
|
2012-08-14 09:47:32 +00:00
|
|
|
updateCertificateSelector();
|
2015-06-15 14:59:12 +00:00
|
|
|
updateAdvancedSettings();
|
2017-06-27 13:17:43 +00:00
|
|
|
updateAppsSelector();
|
2012-07-17 17:23:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onDestroy()
|
|
|
|
{
|
|
|
|
super.onDestroy();
|
|
|
|
mDataSource.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onSaveInstanceState(Bundle outState)
|
|
|
|
{
|
|
|
|
super.onSaveInstanceState(outState);
|
2012-08-14 09:31:37 +00:00
|
|
|
if (mId != null)
|
|
|
|
{
|
|
|
|
outState.putLong(VpnProfileDataSource.KEY_ID, mId);
|
|
|
|
}
|
2012-08-28 12:09:18 +00:00
|
|
|
if (mUserCertEntry != null)
|
|
|
|
{
|
|
|
|
outState.putString(VpnProfileDataSource.KEY_USER_CERTIFICATE, mUserCertEntry.getAlias());
|
|
|
|
}
|
2016-04-30 15:04:45 +00:00
|
|
|
if (mSelectedUserId != null)
|
|
|
|
{
|
|
|
|
outState.putString(VpnProfileDataSource.KEY_LOCAL_ID, mSelectedUserId);
|
|
|
|
}
|
2012-08-14 09:47:32 +00:00
|
|
|
if (mCertEntry != null)
|
|
|
|
{
|
|
|
|
outState.putString(VpnProfileDataSource.KEY_CERTIFICATE, mCertEntry.getAlias());
|
|
|
|
}
|
2017-06-27 13:17:43 +00:00
|
|
|
outState.putStringArrayList(VpnProfileDataSource.KEY_SELECTED_APPS_LIST, new ArrayList<>(mSelectedApps));
|
2012-07-17 17:23:21 +00:00
|
|
|
}
|
|
|
|
|
2012-07-17 17:45:23 +00:00
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu)
|
|
|
|
{
|
|
|
|
MenuInflater inflater = getMenuInflater();
|
|
|
|
inflater.inflate(R.menu.profile_edit, menu);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item)
|
|
|
|
{
|
|
|
|
switch (item.getItemId())
|
|
|
|
{
|
|
|
|
case android.R.id.home:
|
|
|
|
case R.id.menu_cancel:
|
|
|
|
finish();
|
|
|
|
return true;
|
|
|
|
case R.id.menu_accept:
|
|
|
|
saveProfile();
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-14 09:47:32 +00:00
|
|
|
@Override
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data)
|
|
|
|
{
|
|
|
|
switch (requestCode)
|
|
|
|
{
|
|
|
|
case SELECT_TRUSTED_CERTIFICATE:
|
|
|
|
if (resultCode == RESULT_OK)
|
|
|
|
{
|
|
|
|
String alias = data.getStringExtra(VpnProfileDataSource.KEY_CERTIFICATE);
|
|
|
|
X509Certificate certificate = TrustedCertificateManager.getInstance().getCACertificateFromAlias(alias);
|
|
|
|
mCertEntry = certificate == null ? null : new TrustedCertificateEntry(alias, certificate);
|
|
|
|
updateCertificateSelector();
|
|
|
|
}
|
|
|
|
break;
|
2017-06-27 13:17:43 +00:00
|
|
|
case SELECT_APPLICATIONS:
|
|
|
|
if (resultCode == RESULT_OK)
|
|
|
|
{
|
|
|
|
ArrayList<String> selection = data.getStringArrayListExtra(VpnProfileDataSource.KEY_SELECTED_APPS_LIST);
|
|
|
|
mSelectedApps = new TreeSet<>(selection);
|
|
|
|
updateAppsSelector();
|
|
|
|
}
|
|
|
|
break;
|
2012-08-14 09:47:32 +00:00
|
|
|
default:
|
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-27 14:51:41 +00:00
|
|
|
/**
|
2012-08-28 12:09:18 +00:00
|
|
|
* Update the UI to enter credentials depending on the type of VPN currently selected
|
2012-08-27 14:51:41 +00:00
|
|
|
*/
|
2012-08-28 12:09:18 +00:00
|
|
|
private void updateCredentialView()
|
2012-08-27 14:51:41 +00:00
|
|
|
{
|
2014-09-10 09:25:03 +00:00
|
|
|
mUsernamePassword.setVisibility(mVpnType.has(VpnTypeFeature.USER_PASS) ? View.VISIBLE : View.GONE);
|
|
|
|
mUserCertificate.setVisibility(mVpnType.has(VpnTypeFeature.CERTIFICATE) ? View.VISIBLE : View.GONE);
|
|
|
|
mTncNotice.setVisibility(mVpnType.has(VpnTypeFeature.BYOD) ? View.VISIBLE : View.GONE);
|
2012-08-28 12:09:18 +00:00
|
|
|
|
2014-09-10 09:25:03 +00:00
|
|
|
if (mVpnType.has(VpnTypeFeature.CERTIFICATE))
|
2012-08-28 12:09:18 +00:00
|
|
|
{
|
2016-04-30 15:04:45 +00:00
|
|
|
mSelectUserId.setEnabled(false);
|
2012-08-28 12:09:18 +00:00
|
|
|
if (mUserCertLoading != null)
|
|
|
|
{
|
2014-07-14 12:24:31 +00:00
|
|
|
((TextView)mSelectUserCert.findViewById(android.R.id.text1)).setText(mUserCertLoading);
|
|
|
|
((TextView)mSelectUserCert.findViewById(android.R.id.text2)).setText(R.string.loading);
|
2012-08-28 12:09:18 +00:00
|
|
|
}
|
|
|
|
else if (mUserCertEntry != null)
|
|
|
|
{ /* clear any errors and set the new data */
|
2014-07-14 12:24:31 +00:00
|
|
|
((TextView)mSelectUserCert.findViewById(android.R.id.text1)).setError(null);
|
|
|
|
((TextView)mSelectUserCert.findViewById(android.R.id.text1)).setText(mUserCertEntry.getAlias());
|
|
|
|
((TextView)mSelectUserCert.findViewById(android.R.id.text2)).setText(mUserCertEntry.getCertificate().getSubjectDN().toString());
|
2016-04-30 15:04:45 +00:00
|
|
|
mSelectUserIdAdapter.setCertificate(mUserCertEntry);
|
|
|
|
mSelectUserId.setSelection(mSelectUserIdAdapter.getPosition(mSelectedUserId));
|
|
|
|
mSelectUserId.setEnabled(true);
|
2012-08-28 12:09:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-07-14 12:24:31 +00:00
|
|
|
((TextView)mSelectUserCert.findViewById(android.R.id.text1)).setText(R.string.profile_user_select_certificate_label);
|
|
|
|
((TextView)mSelectUserCert.findViewById(android.R.id.text2)).setText(R.string.profile_user_select_certificate);
|
2016-04-30 15:04:45 +00:00
|
|
|
mSelectUserIdAdapter.setCertificate(null);
|
2012-08-28 12:09:18 +00:00
|
|
|
}
|
|
|
|
}
|
2012-08-27 14:51:41 +00:00
|
|
|
}
|
|
|
|
|
2012-08-07 16:03:51 +00:00
|
|
|
/**
|
|
|
|
* Show an alert in case the previously selected certificate is not found anymore
|
|
|
|
* or the user did not select a certificate in the spinner.
|
|
|
|
*/
|
|
|
|
private void showCertificateAlert()
|
|
|
|
{
|
|
|
|
AlertDialog.Builder adb = new AlertDialog.Builder(VpnProfileDetailActivity.this);
|
|
|
|
adb.setTitle(R.string.alert_text_nocertfound_title);
|
|
|
|
adb.setMessage(R.string.alert_text_nocertfound);
|
|
|
|
adb.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int id)
|
|
|
|
{
|
|
|
|
dialog.cancel();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
adb.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-08-14 09:47:32 +00:00
|
|
|
* Update the CA certificate selection UI depending on whether the
|
|
|
|
* certificate should be automatically selected or not.
|
2012-08-07 16:03:51 +00:00
|
|
|
*/
|
2012-08-14 09:47:32 +00:00
|
|
|
private void updateCertificateSelector()
|
2012-08-07 16:03:51 +00:00
|
|
|
{
|
2012-08-14 09:47:32 +00:00
|
|
|
if (!mCheckAuto.isChecked())
|
2012-08-07 16:03:51 +00:00
|
|
|
{
|
2012-08-14 09:47:32 +00:00
|
|
|
mSelectCert.setEnabled(true);
|
|
|
|
mSelectCert.setVisibility(View.VISIBLE);
|
2012-08-07 16:03:51 +00:00
|
|
|
|
2012-08-14 09:47:32 +00:00
|
|
|
if (mCertEntry != null)
|
|
|
|
{
|
2014-07-14 12:24:31 +00:00
|
|
|
((TextView)mSelectCert.findViewById(android.R.id.text1)).setText(mCertEntry.getSubjectPrimary());
|
|
|
|
((TextView)mSelectCert.findViewById(android.R.id.text2)).setText(mCertEntry.getSubjectSecondary());
|
2012-08-14 09:47:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-07-14 12:24:31 +00:00
|
|
|
((TextView)mSelectCert.findViewById(android.R.id.text1)).setText(R.string.profile_ca_select_certificate_label);
|
|
|
|
((TextView)mSelectCert.findViewById(android.R.id.text2)).setText(R.string.profile_ca_select_certificate);
|
2012-08-14 09:47:32 +00:00
|
|
|
}
|
2012-08-07 16:03:51 +00:00
|
|
|
}
|
2012-08-14 09:47:32 +00:00
|
|
|
else
|
2012-08-07 16:03:51 +00:00
|
|
|
{
|
2012-08-14 09:47:32 +00:00
|
|
|
mSelectCert.setEnabled(false);
|
|
|
|
mSelectCert.setVisibility(View.GONE);
|
2012-08-07 16:03:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-27 13:17:43 +00:00
|
|
|
/**
|
|
|
|
* Update the application selection UI
|
|
|
|
*/
|
|
|
|
private void updateAppsSelector()
|
|
|
|
{
|
|
|
|
if (mSelectedAppsHandling == SelectedAppsHandling.SELECTED_APPS_DISABLE)
|
|
|
|
{
|
|
|
|
mSelectApps.setEnabled(false);
|
|
|
|
mSelectApps.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mSelectApps.setEnabled(true);
|
|
|
|
mSelectApps.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
((TextView)mSelectApps.findViewById(android.R.id.text1)).setText(R.string.profile_select_apps);
|
|
|
|
String selected;
|
|
|
|
switch (mSelectedApps.size())
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
selected = getString(R.string.profile_select_no_apps);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
selected = getString(R.string.profile_select_one_app);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
selected = getString(R.string.profile_select_x_apps, mSelectedApps.size());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
((TextView)mSelectApps.findViewById(android.R.id.text2)).setText(selected);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-15 14:59:12 +00:00
|
|
|
/**
|
|
|
|
* Update the advanced settings UI depending on whether any advanced
|
|
|
|
* settings have already been made.
|
|
|
|
*/
|
|
|
|
private void updateAdvancedSettings()
|
|
|
|
{
|
|
|
|
boolean show = mShowAdvanced.isChecked();
|
|
|
|
if (!show && mProfile != null)
|
|
|
|
{
|
2017-06-29 12:52:28 +00:00
|
|
|
Integer st = mProfile.getSplitTunneling(), flags = mProfile.getFlags();
|
2016-04-30 10:25:49 +00:00
|
|
|
show = mProfile.getRemoteId() != null || mProfile.getMTU() != null ||
|
2017-06-29 12:52:28 +00:00
|
|
|
mProfile.getPort() != null || mProfile.getNATKeepAlive() != null ||
|
|
|
|
(flags != null && flags != 0) || (st != null && st != 0) ||
|
2017-06-27 13:17:43 +00:00
|
|
|
mProfile.getIncludedSubnets() != null || mProfile.getExcludedSubnets() != null ||
|
2017-11-14 10:18:13 +00:00
|
|
|
mProfile.getSelectedAppsHandling() != SelectedAppsHandling.SELECTED_APPS_DISABLE ||
|
|
|
|
mProfile.getIkeProposal() != null || mProfile.getEspProposal() != null;
|
2015-06-15 14:59:12 +00:00
|
|
|
}
|
|
|
|
mShowAdvanced.setVisibility(!show ? View.VISIBLE : View.GONE);
|
|
|
|
mAdvancedSettings.setVisibility(show ? View.VISIBLE : View.GONE);
|
|
|
|
}
|
|
|
|
|
2012-07-17 17:45:23 +00:00
|
|
|
/**
|
|
|
|
* Save or update the profile depending on whether we actually have a
|
|
|
|
* profile object or not (this was created in updateProfileData)
|
|
|
|
*/
|
|
|
|
private void saveProfile()
|
|
|
|
{
|
|
|
|
if (verifyInput())
|
|
|
|
{
|
|
|
|
if (mProfile != null)
|
|
|
|
{
|
|
|
|
updateProfileData();
|
2016-12-27 14:17:49 +00:00
|
|
|
if (mProfile.getUUID() == null)
|
|
|
|
{
|
|
|
|
mProfile.setUUID(UUID.randomUUID());
|
|
|
|
}
|
2012-07-17 17:45:23 +00:00
|
|
|
mDataSource.updateVpnProfile(mProfile);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mProfile = new VpnProfile();
|
|
|
|
updateProfileData();
|
|
|
|
mDataSource.insertProfile(mProfile);
|
|
|
|
}
|
2016-12-29 16:02:22 +00:00
|
|
|
Intent intent = new Intent(Constants.VPN_PROFILES_CHANGED);
|
|
|
|
intent.putExtra(Constants.VPN_PROFILES_SINGLE, mProfile.getId());
|
|
|
|
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
|
|
|
|
|
2012-07-17 17:45:23 +00:00
|
|
|
setResult(RESULT_OK, new Intent().putExtra(VpnProfileDataSource.KEY_ID, mProfile.getId()));
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Verify the user input and display error messages.
|
|
|
|
* @return true if the input is valid
|
|
|
|
*/
|
|
|
|
private boolean verifyInput()
|
|
|
|
{
|
|
|
|
boolean valid = true;
|
|
|
|
if (mGateway.getText().toString().trim().isEmpty())
|
|
|
|
{
|
2016-04-30 08:42:00 +00:00
|
|
|
mGatewayWrap.setError(getString(R.string.alert_text_no_input_gateway));
|
2012-07-17 17:45:23 +00:00
|
|
|
valid = false;
|
|
|
|
}
|
2014-09-10 09:25:03 +00:00
|
|
|
if (mVpnType.has(VpnTypeFeature.USER_PASS))
|
2012-07-17 17:45:23 +00:00
|
|
|
{
|
2012-08-27 14:51:41 +00:00
|
|
|
if (mUsername.getText().toString().trim().isEmpty())
|
|
|
|
{
|
2016-04-30 08:42:00 +00:00
|
|
|
mUsernameWrap.setError(getString(R.string.alert_text_no_input_username));
|
2012-08-27 14:51:41 +00:00
|
|
|
valid = false;
|
|
|
|
}
|
2012-07-17 17:45:23 +00:00
|
|
|
}
|
2014-09-10 09:25:03 +00:00
|
|
|
if (mVpnType.has(VpnTypeFeature.CERTIFICATE) && mUserCertEntry == null)
|
2012-08-28 12:09:18 +00:00
|
|
|
{ /* let's show an error icon */
|
2014-07-14 12:24:31 +00:00
|
|
|
((TextView)mSelectUserCert.findViewById(android.R.id.text1)).setError("");
|
2012-08-28 12:09:18 +00:00
|
|
|
valid = false;
|
|
|
|
}
|
2012-08-14 09:47:32 +00:00
|
|
|
if (!mCheckAuto.isChecked() && mCertEntry == null)
|
2012-08-07 16:03:51 +00:00
|
|
|
{
|
|
|
|
showCertificateAlert();
|
|
|
|
valid = false;
|
|
|
|
}
|
2016-12-29 16:02:22 +00:00
|
|
|
if (!validateInteger(mMTU, Constants.MTU_MIN, Constants.MTU_MAX))
|
2015-06-15 14:59:12 +00:00
|
|
|
{
|
2016-12-29 16:02:22 +00:00
|
|
|
mMTUWrap.setError(String.format(getString(R.string.alert_text_out_of_range), Constants.MTU_MIN, Constants.MTU_MAX));
|
2015-06-15 14:59:12 +00:00
|
|
|
valid = false;
|
|
|
|
}
|
2017-06-22 10:26:19 +00:00
|
|
|
if (!validateSubnets(mIncludedSubnets))
|
|
|
|
{
|
|
|
|
mIncludedSubnetsWrap.setError(getString(R.string.alert_text_no_subnets));
|
|
|
|
valid = false;
|
|
|
|
}
|
2017-06-21 16:29:48 +00:00
|
|
|
if (!validateSubnets(mExcludedSubnets))
|
|
|
|
{
|
|
|
|
mExcludedSubnetsWrap.setError(getString(R.string.alert_text_no_subnets));
|
|
|
|
valid = false;
|
|
|
|
}
|
2016-11-02 15:33:29 +00:00
|
|
|
if (!validateInteger(mPort, 1, 65535))
|
2015-06-16 14:42:40 +00:00
|
|
|
{
|
2016-04-30 08:42:00 +00:00
|
|
|
mPortWrap.setError(String.format(getString(R.string.alert_text_out_of_range), 1, 65535));
|
2015-06-16 14:42:40 +00:00
|
|
|
valid = false;
|
|
|
|
}
|
2017-06-28 16:44:45 +00:00
|
|
|
if (!validateInteger(mNATKeepalive, Constants.NAT_KEEPALIVE_MIN, Constants.NAT_KEEPALIVE_MAX))
|
|
|
|
{
|
|
|
|
mNATKeepaliveWrap.setError(String.format(getString(R.string.alert_text_out_of_range),
|
|
|
|
Constants.NAT_KEEPALIVE_MIN, Constants.NAT_KEEPALIVE_MAX));
|
|
|
|
valid = false;
|
|
|
|
}
|
2017-11-17 16:40:52 +00:00
|
|
|
if (!validateProposal(mIkeProposal, true))
|
|
|
|
{
|
|
|
|
mIkeProposalWrap.setError(getString(R.string.alert_text_no_proposal));
|
|
|
|
valid = false;
|
|
|
|
}
|
|
|
|
if (!validateProposal(mEspProposal, false))
|
|
|
|
{
|
|
|
|
mEspProposalWrap.setError(getString(R.string.alert_text_no_proposal));
|
|
|
|
valid = false;
|
|
|
|
}
|
2012-07-17 17:45:23 +00:00
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the profile object with the data entered by the user
|
|
|
|
*/
|
|
|
|
private void updateProfileData()
|
|
|
|
{
|
|
|
|
/* the name is optional, we default to the gateway if none is given */
|
|
|
|
String name = mName.getText().toString().trim();
|
|
|
|
String gateway = mGateway.getText().toString().trim();
|
|
|
|
mProfile.setName(name.isEmpty() ? gateway : name);
|
|
|
|
mProfile.setGateway(gateway);
|
2012-08-27 14:51:41 +00:00
|
|
|
mProfile.setVpnType(mVpnType);
|
2014-09-10 09:25:03 +00:00
|
|
|
if (mVpnType.has(VpnTypeFeature.USER_PASS))
|
2012-08-27 14:51:41 +00:00
|
|
|
{
|
|
|
|
mProfile.setUsername(mUsername.getText().toString().trim());
|
|
|
|
String password = mPassword.getText().toString().trim();
|
|
|
|
password = password.isEmpty() ? null : password;
|
|
|
|
mProfile.setPassword(password);
|
|
|
|
}
|
2014-09-10 09:25:03 +00:00
|
|
|
if (mVpnType.has(VpnTypeFeature.CERTIFICATE))
|
2012-08-28 12:09:18 +00:00
|
|
|
{
|
|
|
|
mProfile.setUserCertificateAlias(mUserCertEntry.getAlias());
|
2016-04-30 15:04:45 +00:00
|
|
|
mProfile.setLocalId(mSelectedUserId);
|
2012-08-28 12:09:18 +00:00
|
|
|
}
|
2012-08-14 09:47:32 +00:00
|
|
|
String certAlias = mCheckAuto.isChecked() ? null : mCertEntry.getAlias();
|
|
|
|
mProfile.setCertificateAlias(certAlias);
|
2016-04-30 10:25:49 +00:00
|
|
|
String remote_id = mRemoteId.getText().toString().trim();
|
|
|
|
mProfile.setRemoteId(remote_id.isEmpty() ? null : remote_id);
|
2015-06-15 14:59:12 +00:00
|
|
|
mProfile.setMTU(getInteger(mMTU));
|
2015-06-16 14:42:40 +00:00
|
|
|
mProfile.setPort(getInteger(mPort));
|
2017-06-28 16:44:45 +00:00
|
|
|
mProfile.setNATKeepAlive(getInteger(mNATKeepalive));
|
2017-06-29 12:52:28 +00:00
|
|
|
int flags = 0;
|
|
|
|
flags |= !mCertReq.isChecked() ? VpnProfile.FLAGS_SUPPRESS_CERT_REQS : 0;
|
|
|
|
mProfile.setFlags(flags);
|
2017-06-22 10:26:19 +00:00
|
|
|
String included = mIncludedSubnets.getText().toString().trim();
|
|
|
|
mProfile.setIncludedSubnets(included.isEmpty() ? null : included);
|
2017-06-21 16:29:48 +00:00
|
|
|
String excluded = mExcludedSubnets.getText().toString().trim();
|
|
|
|
mProfile.setExcludedSubnets(excluded.isEmpty() ? null : excluded);
|
2015-07-24 09:47:53 +00:00
|
|
|
int st = 0;
|
|
|
|
st |= mBlockIPv4.isChecked() ? VpnProfile.SPLIT_TUNNELING_BLOCK_IPV4 : 0;
|
|
|
|
st |= mBlockIPv6.isChecked() ? VpnProfile.SPLIT_TUNNELING_BLOCK_IPV6 : 0;
|
|
|
|
mProfile.setSplitTunneling(st == 0 ? null : st);
|
2017-06-27 13:17:43 +00:00
|
|
|
mProfile.setSelectedAppsHandling(mSelectedAppsHandling);
|
|
|
|
mProfile.setSelectedApps(mSelectedApps);
|
2017-11-14 10:18:13 +00:00
|
|
|
String ike = mIkeProposal.getText().toString().trim();
|
|
|
|
mProfile.setIkeProposal(ike.isEmpty() ? null : ike);
|
|
|
|
String esp = mEspProposal.getText().toString().trim();
|
|
|
|
mProfile.setEspProposal(esp.isEmpty() ? null : esp);
|
2012-07-17 17:45:23 +00:00
|
|
|
}
|
|
|
|
|
2012-07-17 17:23:21 +00:00
|
|
|
/**
|
|
|
|
* Load an existing profile if we got an ID
|
2012-08-14 09:47:32 +00:00
|
|
|
*
|
|
|
|
* @param savedInstanceState previously saved state
|
2012-07-17 17:23:21 +00:00
|
|
|
*/
|
2012-08-14 09:47:32 +00:00
|
|
|
private void loadProfileData(Bundle savedInstanceState)
|
2012-07-17 17:23:21 +00:00
|
|
|
{
|
2016-04-30 15:04:45 +00:00
|
|
|
String useralias = null, local_id = null, alias = null;
|
2017-06-29 12:52:28 +00:00
|
|
|
Integer flags = null;
|
2012-08-14 09:47:32 +00:00
|
|
|
|
2015-11-25 16:05:56 +00:00
|
|
|
getSupportActionBar().setTitle(R.string.add_profile);
|
2012-08-27 14:53:07 +00:00
|
|
|
if (mId != null && mId != 0)
|
2012-07-17 17:23:21 +00:00
|
|
|
{
|
|
|
|
mProfile = mDataSource.getVpnProfile(mId);
|
|
|
|
if (mProfile != null)
|
|
|
|
{
|
|
|
|
mName.setText(mProfile.getName());
|
|
|
|
mGateway.setText(mProfile.getGateway());
|
2012-08-27 14:51:41 +00:00
|
|
|
mVpnType = mProfile.getVpnType();
|
2012-07-17 17:23:21 +00:00
|
|
|
mUsername.setText(mProfile.getUsername());
|
|
|
|
mPassword.setText(mProfile.getPassword());
|
2016-04-30 10:25:49 +00:00
|
|
|
mRemoteId.setText(mProfile.getRemoteId());
|
2015-06-15 14:59:12 +00:00
|
|
|
mMTU.setText(mProfile.getMTU() != null ? mProfile.getMTU().toString() : null);
|
2015-06-16 14:42:40 +00:00
|
|
|
mPort.setText(mProfile.getPort() != null ? mProfile.getPort().toString() : null);
|
2017-06-28 16:44:45 +00:00
|
|
|
mNATKeepalive.setText(mProfile.getNATKeepAlive() != null ? mProfile.getNATKeepAlive().toString() : null);
|
2017-06-22 10:26:19 +00:00
|
|
|
mIncludedSubnets.setText(mProfile.getIncludedSubnets());
|
2017-06-21 16:29:48 +00:00
|
|
|
mExcludedSubnets.setText(mProfile.getExcludedSubnets());
|
2016-12-29 16:02:22 +00:00
|
|
|
mBlockIPv4.setChecked(mProfile.getSplitTunneling() != null && (mProfile.getSplitTunneling() & VpnProfile.SPLIT_TUNNELING_BLOCK_IPV4) != 0);
|
|
|
|
mBlockIPv6.setChecked(mProfile.getSplitTunneling() != null && (mProfile.getSplitTunneling() & VpnProfile.SPLIT_TUNNELING_BLOCK_IPV6) != 0);
|
2017-06-27 13:17:43 +00:00
|
|
|
mSelectedAppsHandling = mProfile.getSelectedAppsHandling();
|
|
|
|
mSelectedApps = mProfile.getSelectedAppsSet();
|
2017-11-14 10:18:13 +00:00
|
|
|
mIkeProposal.setText(mProfile.getIkeProposal());
|
|
|
|
mEspProposal.setText(mProfile.getEspProposal());
|
2017-06-29 12:52:28 +00:00
|
|
|
flags = mProfile.getFlags();
|
2012-08-28 12:09:18 +00:00
|
|
|
useralias = mProfile.getUserCertificateAlias();
|
2016-04-30 15:04:45 +00:00
|
|
|
local_id = mProfile.getLocalId();
|
2012-08-14 09:47:32 +00:00
|
|
|
alias = mProfile.getCertificateAlias();
|
2015-11-25 16:05:56 +00:00
|
|
|
getSupportActionBar().setTitle(mProfile.getName());
|
2012-07-17 17:23:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Log.e(VpnProfileDetailActivity.class.getSimpleName(),
|
|
|
|
"VPN profile with id " + mId + " not found");
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
}
|
2012-08-14 09:47:32 +00:00
|
|
|
|
2012-08-27 14:51:41 +00:00
|
|
|
mSelectVpnType.setSelection(mVpnType.ordinal());
|
2017-06-29 12:52:28 +00:00
|
|
|
mCertReq.setChecked(flags == null || (flags & VpnProfile.FLAGS_SUPPRESS_CERT_REQS) == 0);
|
2012-08-27 14:51:41 +00:00
|
|
|
|
2012-08-28 12:09:18 +00:00
|
|
|
/* check if the user selected a user certificate previously */
|
2016-04-30 15:04:45 +00:00
|
|
|
useralias = savedInstanceState == null ? useralias : savedInstanceState.getString(VpnProfileDataSource.KEY_USER_CERTIFICATE);
|
|
|
|
local_id = savedInstanceState == null ? local_id : savedInstanceState.getString(VpnProfileDataSource.KEY_LOCAL_ID);
|
2012-08-28 12:09:18 +00:00
|
|
|
if (useralias != null)
|
|
|
|
{
|
|
|
|
UserCertificateLoader loader = new UserCertificateLoader(this, useralias);
|
|
|
|
mUserCertLoading = useralias;
|
2016-04-30 15:04:45 +00:00
|
|
|
mSelectedUserId = local_id;
|
2012-08-28 12:09:18 +00:00
|
|
|
loader.execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check if the user selected a CA certificate previously */
|
2012-08-14 09:47:32 +00:00
|
|
|
alias = savedInstanceState == null ? alias : savedInstanceState.getString(VpnProfileDataSource.KEY_CERTIFICATE);
|
|
|
|
mCheckAuto.setChecked(alias == null);
|
|
|
|
if (alias != null)
|
|
|
|
{
|
|
|
|
X509Certificate certificate = TrustedCertificateManager.getInstance().getCACertificateFromAlias(alias);
|
|
|
|
if (certificate != null)
|
|
|
|
{
|
|
|
|
mCertEntry = new TrustedCertificateEntry(alias, certificate);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ /* previously selected certificate is not here anymore */
|
|
|
|
showCertificateAlert();
|
|
|
|
mCertEntry = null;
|
|
|
|
}
|
|
|
|
}
|
2017-06-27 13:17:43 +00:00
|
|
|
|
|
|
|
mSelectSelectedAppsHandling.setSelection(mSelectedAppsHandling.ordinal());
|
|
|
|
if (savedInstanceState != null)
|
|
|
|
{
|
|
|
|
ArrayList<String> selectedApps = savedInstanceState.getStringArrayList(VpnProfileDataSource.KEY_SELECTED_APPS_LIST);
|
|
|
|
mSelectedApps = new TreeSet<>(selectedApps);
|
|
|
|
}
|
2012-07-17 17:23:21 +00:00
|
|
|
}
|
2012-08-28 12:09:18 +00:00
|
|
|
|
2015-06-15 14:59:12 +00:00
|
|
|
/**
|
|
|
|
* Get the integer value in the given text box or null if empty
|
|
|
|
*
|
|
|
|
* @param view text box (numeric entry assumed)
|
|
|
|
*/
|
|
|
|
private Integer getInteger(EditText view)
|
|
|
|
{
|
|
|
|
String value = view.getText().toString().trim();
|
2016-06-13 14:12:17 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
return value.isEmpty() ? null : Integer.valueOf(value);
|
|
|
|
}
|
|
|
|
catch (NumberFormatException e)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
2015-06-15 14:59:12 +00:00
|
|
|
}
|
|
|
|
|
2016-11-02 15:33:29 +00:00
|
|
|
/**
|
|
|
|
* Check that the value in the given text box is a valid integer in the given range
|
|
|
|
*
|
|
|
|
* @param view text box (numeric entry assumed)
|
|
|
|
* @param min minimum value (inclusive)
|
|
|
|
* @param max maximum value (inclusive)
|
|
|
|
*/
|
|
|
|
private boolean validateInteger(EditText view, Integer min, Integer max)
|
|
|
|
{
|
|
|
|
String value = view.getText().toString().trim();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (value.isEmpty())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
Integer val = Integer.valueOf(value);
|
|
|
|
return min <= val && val <= max;
|
|
|
|
}
|
|
|
|
catch (NumberFormatException e)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-21 16:29:48 +00:00
|
|
|
/**
|
|
|
|
* Check that the value in the given text box is a valid list of subnets/ranges
|
|
|
|
*
|
|
|
|
* @param view text box
|
|
|
|
*/
|
|
|
|
private boolean validateSubnets(EditText view)
|
|
|
|
{
|
|
|
|
String value = view.getText().toString().trim();
|
|
|
|
return value.isEmpty() || IPRangeSet.fromString(value) != null;
|
|
|
|
}
|
|
|
|
|
2017-11-17 16:40:52 +00:00
|
|
|
/**
|
|
|
|
* Check that the value in the given text box is a valid proposal
|
|
|
|
*
|
|
|
|
* @param view text box
|
|
|
|
*/
|
|
|
|
private boolean validateProposal(EditText view, boolean ike)
|
|
|
|
{
|
|
|
|
String value = view.getText().toString().trim();
|
|
|
|
return value.isEmpty() || Utils.isProposalValid(ike, value);
|
|
|
|
}
|
|
|
|
|
2012-08-28 12:09:18 +00:00
|
|
|
private class SelectUserCertOnClickListener implements OnClickListener, KeyChainAliasCallback
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onClick(View v)
|
|
|
|
{
|
|
|
|
String useralias = mUserCertEntry != null ? mUserCertEntry.getAlias() : null;
|
|
|
|
KeyChain.choosePrivateKeyAlias(VpnProfileDetailActivity.this, this, new String[] { "RSA" }, null, null, -1, useralias);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void alias(final String alias)
|
|
|
|
{
|
|
|
|
if (alias != null)
|
|
|
|
{ /* otherwise the dialog was canceled, the request denied */
|
|
|
|
try
|
|
|
|
{
|
|
|
|
final X509Certificate[] chain = KeyChain.getCertificateChain(VpnProfileDetailActivity.this, alias);
|
|
|
|
/* alias() is not called from our main thread */
|
|
|
|
runOnUiThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run()
|
|
|
|
{
|
|
|
|
if (chain != null && chain.length > 0)
|
|
|
|
{
|
|
|
|
mUserCertEntry = new TrustedCertificateEntry(alias, chain[0]);
|
|
|
|
}
|
|
|
|
updateCredentialView();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-12-29 16:02:22 +00:00
|
|
|
catch (KeyChainException | InterruptedException e)
|
2012-08-28 12:09:18 +00:00
|
|
|
{
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load the selected user certificate asynchronously. This cannot be done
|
|
|
|
* from the main thread as getCertificateChain() calls back to our main
|
|
|
|
* thread to bind to the KeyChain service resulting in a deadlock.
|
|
|
|
*/
|
|
|
|
private class UserCertificateLoader extends AsyncTask<Void, Void, X509Certificate>
|
|
|
|
{
|
|
|
|
private final Context mContext;
|
|
|
|
private final String mAlias;
|
|
|
|
|
|
|
|
public UserCertificateLoader(Context context, String alias)
|
|
|
|
{
|
|
|
|
mContext = context;
|
|
|
|
mAlias = alias;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected X509Certificate doInBackground(Void... params)
|
|
|
|
{
|
|
|
|
X509Certificate[] chain = null;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
chain = KeyChain.getCertificateChain(mContext, mAlias);
|
|
|
|
}
|
2016-12-29 16:02:22 +00:00
|
|
|
catch (KeyChainException | InterruptedException e)
|
2012-08-28 12:09:18 +00:00
|
|
|
{
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
if (chain != null && chain.length > 0)
|
|
|
|
{
|
|
|
|
return chain[0];
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(X509Certificate result)
|
|
|
|
{
|
|
|
|
if (result != null)
|
|
|
|
{
|
|
|
|
mUserCertEntry = new TrustedCertificateEntry(mAlias, result);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ /* previously selected certificate is not here anymore */
|
2014-07-14 12:24:31 +00:00
|
|
|
((TextView)mSelectUserCert.findViewById(android.R.id.text1)).setError("");
|
2012-08-28 12:09:18 +00:00
|
|
|
mUserCertEntry = null;
|
|
|
|
}
|
|
|
|
mUserCertLoading = null;
|
|
|
|
updateCredentialView();
|
|
|
|
}
|
|
|
|
}
|
2013-07-03 14:27:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Dialog with notification message if EAP-TNC is used.
|
|
|
|
*/
|
2016-04-15 15:36:31 +00:00
|
|
|
public static class TncNoticeDialog extends AppCompatDialogFragment
|
2013-07-03 14:27:36 +00:00
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public Dialog onCreateDialog(Bundle savedInstanceState)
|
|
|
|
{
|
|
|
|
return new AlertDialog.Builder(getActivity())
|
|
|
|
.setTitle(R.string.tnc_notice_title)
|
|
|
|
.setMessage(Html.fromHtml(getString(R.string.tnc_notice_details)))
|
|
|
|
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int id)
|
|
|
|
{
|
|
|
|
dialog.dismiss();
|
|
|
|
}
|
|
|
|
}).create();
|
|
|
|
}
|
|
|
|
}
|
2016-04-30 11:11:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tokenizer implementation that separates by white-space
|
|
|
|
*/
|
|
|
|
public static class SpaceTokenizer implements MultiAutoCompleteTextView.Tokenizer
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public int findTokenStart(CharSequence text, int cursor)
|
|
|
|
{
|
|
|
|
int i = cursor;
|
|
|
|
|
|
|
|
while (i > 0 && !Character.isWhitespace(text.charAt(i - 1)))
|
|
|
|
{
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int findTokenEnd(CharSequence text, int cursor)
|
|
|
|
{
|
|
|
|
int i = cursor;
|
|
|
|
int len = text.length();
|
|
|
|
|
|
|
|
while (i < len)
|
|
|
|
{
|
|
|
|
if (Character.isWhitespace(text.charAt(i)))
|
|
|
|
{
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public CharSequence terminateToken(CharSequence text)
|
|
|
|
{
|
|
|
|
int i = text.length();
|
|
|
|
|
|
|
|
if (i > 0 && Character.isWhitespace(text.charAt(i - 1)))
|
|
|
|
{
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (text instanceof Spanned)
|
|
|
|
{
|
|
|
|
SpannableString sp = new SpannableString(text + " ");
|
|
|
|
TextUtils.copySpansFrom((Spanned) text, 0, text.length(), Object.class, sp, 0);
|
|
|
|
return sp;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return text + " ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-17 17:23:21 +00:00
|
|
|
}
|