diff options
author | Arne Schwabe <arne@rfc2549.org> | 2021-10-13 19:24:42 +0200 |
---|---|---|
committer | Arne Schwabe <arne@rfc2549.org> | 2021-10-13 19:24:42 +0200 |
commit | 9ca366fb2db61926021866a37e14c332ebc57c59 (patch) | |
tree | a45ed863cf2c171bd16f553055edade89b957fb6 /main/src/ui/java | |
parent | 893ce60f739bb3432eecf540329b732debb38ed3 (diff) |
Fix summary of Auth settings dialog and add TLS Profile setting
Diffstat (limited to 'main/src/ui/java')
3 files changed, 34 insertions, 40 deletions
diff --git a/main/src/ui/java/de/blinkt/openvpn/fragments/Settings_Authentication.kt b/main/src/ui/java/de/blinkt/openvpn/fragments/Settings_Authentication.kt index 15687f26..d3de8116 100644 --- a/main/src/ui/java/de/blinkt/openvpn/fragments/Settings_Authentication.kt +++ b/main/src/ui/java/de/blinkt/openvpn/fragments/Settings_Authentication.kt @@ -24,8 +24,7 @@ import de.blinkt.openvpn.views.RemoteCNPreference import de.blinkt.openvpn.views.RemoteCNPreferenceDialog import java.io.IOException -class Settings_Authentication : OpenVpnPreferencesFragment(), Preference.OnPreferenceChangeListener, - Preference.OnPreferenceClickListener { +class Settings_Authentication : OpenVpnPreferencesFragment(), Preference.OnPreferenceClickListener { private lateinit var mExpectTLSCert: CheckBoxPreference private lateinit var mCheckRemoteCN: CheckBoxPreference private lateinit var mRemoteCN: RemoteCNPreference @@ -36,6 +35,7 @@ class Settings_Authentication : OpenVpnPreferencesFragment(), Preference.OnPrefe private var mTlsAuthFileData: String? = null private lateinit var mAuth: EditTextPreference private lateinit var mRemoteX509Name: EditTextPreference + private lateinit var mTLSProfile: ListPreference override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { } @@ -48,17 +48,17 @@ class Settings_Authentication : OpenVpnPreferencesFragment(), Preference.OnPrefe mExpectTLSCert = findPreference("remoteServerTLS")!! mCheckRemoteCN = findPreference("checkRemoteCN")!! mRemoteCN = findPreference("remotecn")!! - mRemoteCN.onPreferenceChangeListener = this + setRemoteCNSummaryProvider() mRemoteX509Name = findPreference("remotex509name")!! - mRemoteX509Name.onPreferenceChangeListener = this + mRemoteX509Name.setSummaryProvider { pref -> + if ((pref as EditTextPreference).text.isEmpty()) "CN (default)" else pref.text + } mUseTLSAuth = findPreference("useTLSAuth")!! mTLSAuthFile = findPreference("tlsAuthFile")!! mTLSAuthDirection = findPreference("tls_direction")!! - mTLSAuthFile.onPreferenceClickListener = this mDataCiphers = findPreference("dataciphers")!! - mDataCiphers.onPreferenceChangeListener = this mAuth = findPreference("auth")!! - mAuth.onPreferenceChangeListener = this + mTLSProfile = findPreference("tls_profile")!! loadSettings() } @@ -67,20 +67,17 @@ class Settings_Authentication : OpenVpnPreferencesFragment(), Preference.OnPrefe mCheckRemoteCN.isChecked = mProfile.mCheckRemoteCN mRemoteCN.setDN(mProfile.mRemoteCN) mRemoteCN.setAuthType(mProfile.mX509AuthType) - onPreferenceChange( - mRemoteCN, - Pair(mProfile.mX509AuthType, mProfile.mRemoteCN) - ) mRemoteX509Name.text = mProfile.mx509UsernameField ?: "" - onPreferenceChange(mRemoteX509Name, mProfile.mx509UsernameField ?: "") mUseTLSAuth.isChecked = mProfile.mUseTLSAuth + mTlsAuthFileData = mProfile.mTLSAuthFilename setTlsAuthSummary(mTlsAuthFileData) + mTLSAuthDirection.value = mProfile.mTLSAuthDirection + mDataCiphers.text = mProfile.mDataCiphers - onPreferenceChange(mDataCiphers, mProfile.mDataCiphers) mAuth.text = mProfile.mAuth - onPreferenceChange(mAuth, mProfile.mAuth) + if (mProfile.mAuthenticationType == VpnProfile.TYPE_STATICKEYS) { mExpectTLSCert.isEnabled = false mCheckRemoteCN.isEnabled = false @@ -89,6 +86,10 @@ class Settings_Authentication : OpenVpnPreferencesFragment(), Preference.OnPrefe mExpectTLSCert.isEnabled = true mCheckRemoteCN.isEnabled = true } + if (mProfile.mTlSCertProfile.isNullOrBlank()) + mTLSProfile.value = "legacy" + else + mTLSProfile.value = mProfile.mTlSCertProfile } override fun saveSettings() { @@ -99,36 +100,30 @@ class Settings_Authentication : OpenVpnPreferencesFragment(), Preference.OnPrefe mProfile.mUseTLSAuth = mUseTLSAuth.isChecked mProfile.mTLSAuthFilename = mTlsAuthFileData mProfile.mx509UsernameField = mRemoteX509Name.text - if (mTLSAuthDirection.value == null) mProfile.mTLSAuthDirection = - null else mProfile.mTLSAuthDirection = mTLSAuthDirection.value - if (mDataCiphers.text == null) mProfile.mDataCiphers = null else mProfile.mDataCiphers = - mDataCiphers.text - if (mAuth.text == null) mProfile.mAuth = null else mProfile.mAuth = mAuth.text + mProfile.mTLSAuthDirection = mTLSAuthDirection.value + mProfile.mDataCiphers = mDataCiphers.text + mProfile.mAuth = mAuth.text + mProfile.mTlSCertProfile = mTLSProfile.value } - override fun onPreferenceChange(preference: Preference, newValue: Any): Boolean { - if (preference === mRemoteCN && newValue is Pair<*, *>) { - val authtype = newValue.first as Int - val dn = newValue.second - if ("" == dn) { + private fun setRemoteCNSummaryProvider() + { + mRemoteCN.setSummaryProvider { + pref -> + pref as RemoteCNPreference; + + if ("" == pref.cnText) { if (mProfile.mConnections.size > 0) { - preference.summary = getX509String( - VpnProfile.X509_VERIFY_TLSREMOTE_RDN, + return@setSummaryProvider getX509String(VpnProfile.X509_VERIFY_TLSREMOTE_RDN, mProfile.mConnections[0].mServerName ) } else { - preference.setSummary(R.string.no_remote_defined) + return@setSummaryProvider getString(R.string.no_remote_defined) } } else { - preference.summary = getX509String(authtype, dn as String) + return@setSummaryProvider getX509String(pref.authtype, pref.cnText) } - } else if (preference === mDataCiphers || preference === mAuth) { - preference.summary = (newValue as CharSequence) - } else if (preference === mRemoteX509Name) { - preference.summary = - (if (newValue.toString().isEmpty()) "CN (default)" else newValue as CharSequence) } - return true } private fun getX509String(authtype: Int, dn: String): CharSequence { diff --git a/main/src/ui/java/de/blinkt/openvpn/views/RemoteCNPreference.java b/main/src/ui/java/de/blinkt/openvpn/views/RemoteCNPreference.java index 93a2d90f..ca94ac19 100644 --- a/main/src/ui/java/de/blinkt/openvpn/views/RemoteCNPreference.java +++ b/main/src/ui/java/de/blinkt/openvpn/views/RemoteCNPreference.java @@ -39,11 +39,13 @@ public class RemoteCNPreference extends DialogPreference { public void setDN(String dn) { mDn = dn; + notifyChanged(); } public void setAuthType(int x509authtype) { mDNType = x509authtype; + notifyChanged(); } public String getCNText() { diff --git a/main/src/ui/java/de/blinkt/openvpn/views/RemoteCNPreferenceDialog.java b/main/src/ui/java/de/blinkt/openvpn/views/RemoteCNPreferenceDialog.java index 37258489..303e5977 100644 --- a/main/src/ui/java/de/blinkt/openvpn/views/RemoteCNPreferenceDialog.java +++ b/main/src/ui/java/de/blinkt/openvpn/views/RemoteCNPreferenceDialog.java @@ -107,17 +107,14 @@ public class RemoteCNPreferenceDialog extends PreferenceDialogFragmentCompat { @Override public void onDialogClosed(boolean positiveResult) { - if (positiveResult) { RemoteCNPreference pref = ((RemoteCNPreference) getPreference()); String dn = mEditText.getText().toString(); int authtype = getAuthTypeFromSpinner(); - if (pref.callChangeListener(new Pair<>(authtype, dn))) { - pref.setDN(dn); - pref.setAuthType(authtype); - } - } + pref.setDN(dn); + pref.setAuthType(authtype); + } } |