Skip to content
Snippets Groups Projects
Commit 1e61e309 authored by Alexandre Lision's avatar Alexandre Lision
Browse files

ui: Add feedback when choosing crt file

This commit introduces security check when user chooses a certificate,
displaying an icon showing test result (passed/failed)

Refs #45008
parent 7e348c76
Branches
Tags
No related merge requests found
Showing
with 133 additions and 86 deletions
res/drawable-hdpi/ic_error.png

1.46 KiB

res/drawable-hdpi/ic_good.png

1.59 KiB

res/drawable-hdpi/ic_warning.png

947 B

res/drawable-mdpi/ic_error.png

687 B

res/drawable-mdpi/ic_good.png

645 B

res/drawable-mdpi/ic_warning.png

532 B

res/drawable-xhdpi/ic_error.png

1.28 KiB

res/drawable-xhdpi/ic_good.png

1.41 KiB

res/drawable-xhdpi/ic_warning.png

945 B

res/drawable-xxhdpi/ic_error.png

2.57 KiB

res/drawable-xxhdpi/ic_good.png

3.35 KiB

res/drawable-xxhdpi/ic_warning.png

1.82 KiB

...@@ -60,6 +60,7 @@ as that of the covered work. ...@@ -60,6 +60,7 @@ as that of the covered work.
android:key="TLS.certificateListFile" android:key="TLS.certificateListFile"
android:persistent="false" android:persistent="false"
android:title="@string/account_tls_certificate_list_label" /> android:title="@string/account_tls_certificate_list_label" />
<Preference <Preference
android:id="@+id/account_tls_certificate_file" android:id="@+id/account_tls_certificate_file"
android:key="TLS.certificateFile" android:key="TLS.certificateFile"
......
...@@ -40,16 +40,55 @@ import android.preference.Preference.OnPreferenceChangeListener; ...@@ -40,16 +40,55 @@ import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener; import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceScreen; import android.preference.PreferenceScreen;
import android.util.Log; import android.util.Log;
import org.sflphone.R;
import org.sflphone.fragments.NestedSettingsFragment; import org.sflphone.fragments.NestedSettingsFragment;
import org.sflphone.model.Account; import org.sflphone.model.Account;
import java.io.File; import java.io.File;
public class TLSManager { public class TLSManager {
private static final String TAG = TLSManager.class.getSimpleName();
private static final int SELECT_CA_LIST_RC = 42;
private static final int SELECT_PRIVATE_KEY_RC = 43;
private static final int SELECT_CERTIFICATE_RC = 44;
private OnPreferenceClickListener filePickerListener = new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
if (preference.getKey().contentEquals(AccountDetailTls.CONFIG_TLS_CA_LIST_FILE)) {
performFileSearch(SELECT_CA_LIST_RC);
}
if (preference.getKey().contentEquals(AccountDetailTls.CONFIG_TLS_PRIVATE_KEY_FILE)) {
performFileSearch(SELECT_PRIVATE_KEY_RC);
}
if (preference.getKey().contentEquals(AccountDetailTls.CONFIG_TLS_CERTIFICATE_FILE)) {
performFileSearch(SELECT_CERTIFICATE_RC);
}
return true;
}
};
PreferenceScreen mScreen; PreferenceScreen mScreen;
private Account mAccount; private Account mAccount;
private NestedSettingsFragment mFrag; private NestedSettingsFragment mFrag;
private static final String TAG = TLSManager.class.getSimpleName(); private OnPreferenceChangeListener tlsListener = new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
Log.i("TLS", "Setting " + preference.getKey() + " to" + newValue);
if (preference.getKey().contentEquals("TLS.enable")) {
togglePreferenceScreen((Boolean) newValue);
}
if (preference instanceof CheckBoxPreference) {
mAccount.getTlsDetails().setDetailString(preference.getKey(), Boolean.toString((Boolean) newValue));
} else {
preference.setSummary((String) newValue);
mAccount.getTlsDetails().setDetailString(preference.getKey(), (String) newValue);
}
mAccount.notifyObservers();
return true;
}
};
public void onCreate(NestedSettingsFragment con, PreferenceScreen preferenceScreen, Account acc) { public void onCreate(NestedSettingsFragment con, PreferenceScreen preferenceScreen, Account acc) {
mFrag = con; mFrag = con;
...@@ -70,8 +109,10 @@ public class TLSManager { ...@@ -70,8 +109,10 @@ public class TLSManager {
mScreen.getPreference(i).getKey())); mScreen.getPreference(i).getKey()));
} else { } else {
if (current.getKey().contentEquals(AccountDetailTls.CONFIG_TLS_CA_LIST_FILE)) { if (current.getKey().contentEquals(AccountDetailTls.CONFIG_TLS_CA_LIST_FILE)) {
current.setSummary(new File(mAccount.getTlsDetails().getDetailString(AccountDetailTls.CONFIG_TLS_CA_LIST_FILE)).getName()); File crt = new File(mAccount.getTlsDetails().getDetailString(AccountDetailTls.CONFIG_TLS_CA_LIST_FILE));
current.setSummary(crt.getName());
current.setOnPreferenceClickListener(filePickerListener); current.setOnPreferenceClickListener(filePickerListener);
setFeedbackIcon(crt.getAbsolutePath());
} else if (current.getKey().contentEquals(AccountDetailTls.CONFIG_TLS_PRIVATE_KEY_FILE)) { } else if (current.getKey().contentEquals(AccountDetailTls.CONFIG_TLS_PRIVATE_KEY_FILE)) {
current.setSummary(new File(mAccount.getTlsDetails().getDetailString(AccountDetailTls.CONFIG_TLS_PRIVATE_KEY_FILE)).getName()); current.setSummary(new File(mAccount.getTlsDetails().getDetailString(AccountDetailTls.CONFIG_TLS_PRIVATE_KEY_FILE)).getName());
current.setOnPreferenceClickListener(filePickerListener); current.setOnPreferenceClickListener(filePickerListener);
...@@ -94,21 +135,13 @@ public class TLSManager { ...@@ -94,21 +135,13 @@ public class TLSManager {
} }
} }
private OnPreferenceClickListener filePickerListener = new OnPreferenceClickListener() { private void setFeedbackIcon(String crtPath) {
@Override if(!mFrag.checkCertificate(crtPath)){
public boolean onPreferenceClick(Preference preference) { mScreen.findPreference(AccountDetailTls.CONFIG_TLS_CA_LIST_FILE).setIcon(R.drawable.ic_error);
if (preference.getKey().contentEquals(AccountDetailTls.CONFIG_TLS_CA_LIST_FILE)) { } else {
performFileSearch(SELECT_CA_LIST_RC); mScreen.findPreference(AccountDetailTls.CONFIG_TLS_CA_LIST_FILE).setIcon(R.drawable.ic_good);
}
if (preference.getKey().contentEquals(AccountDetailTls.CONFIG_TLS_PRIVATE_KEY_FILE)) {
performFileSearch(SELECT_PRIVATE_KEY_RC);
}
if (preference.getKey().contentEquals(AccountDetailTls.CONFIG_TLS_CERTIFICATE_FILE)) {
performFileSearch(SELECT_CERTIFICATE_RC);
} }
return true;
} }
};
public void setTLSListener() { public void setTLSListener() {
for (int i = 0; i < mScreen.getPreferenceCount(); ++i) { for (int i = 0; i < mScreen.getPreferenceCount(); ++i) {
...@@ -116,39 +149,12 @@ public class TLSManager { ...@@ -116,39 +149,12 @@ public class TLSManager {
} }
} }
private OnPreferenceChangeListener tlsListener = new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
Log.i("TLS", "Setting " + preference.getKey() + " to" + newValue);
if (preference.getKey().contentEquals("TLS.enable")) {
togglePreferenceScreen((Boolean) newValue);
}
if (preference instanceof CheckBoxPreference) {
mAccount.getTlsDetails().setDetailString(preference.getKey(), Boolean.toString((Boolean) newValue));
} else {
preference.setSummary((String) newValue);
mAccount.getTlsDetails().setDetailString(preference.getKey(), (String) newValue);
}
mAccount.notifyObservers();
return true;
}
};
private void togglePreferenceScreen(Boolean state) { private void togglePreferenceScreen(Boolean state) {
for (int i = 1; i < mScreen.getPreferenceCount(); ++i) { for (int i = 1; i < mScreen.getPreferenceCount(); ++i) {
mScreen.getPreference(i).setEnabled(state); mScreen.getPreference(i).setEnabled(state);
} }
} }
private static final int SELECT_CA_LIST_RC = 42;
private static final int SELECT_PRIVATE_KEY_RC = 43;
private static final int SELECT_CERTIFICATE_RC = 44;
public void performFileSearch(int requestCodeToSet) { public void performFileSearch(int requestCodeToSet) {
// ACTION_OPEN_DOCUMENT is the intent to choose a file via the system's file // ACTION_OPEN_DOCUMENT is the intent to choose a file via the system's file
...@@ -173,13 +179,14 @@ public class TLSManager { ...@@ -173,13 +179,14 @@ public class TLSManager {
if (resultCode == Activity.RESULT_CANCELED) if (resultCode == Activity.RESULT_CANCELED)
return; return;
File myFile = new File(data.getData().toString()); File myFile = new File(data.getData().getEncodedPath());
Log.i(TAG, "file selected:" + data.getData()); Log.i(TAG, "file selected:" + data.getData());
switch (requestCode) { switch (requestCode) {
case SELECT_CA_LIST_RC: case SELECT_CA_LIST_RC:
mScreen.findPreference(AccountDetailTls.CONFIG_TLS_CA_LIST_FILE).setSummary(myFile.getName()); mScreen.findPreference(AccountDetailTls.CONFIG_TLS_CA_LIST_FILE).setSummary(myFile.getName());
mAccount.getTlsDetails().setDetailString(AccountDetailTls.CONFIG_TLS_CA_LIST_FILE, myFile.getAbsolutePath()); mAccount.getTlsDetails().setDetailString(AccountDetailTls.CONFIG_TLS_CA_LIST_FILE, myFile.getAbsolutePath());
mAccount.notifyObservers(); mAccount.notifyObservers();
setFeedbackIcon(myFile.getAbsolutePath());
break; break;
case SELECT_PRIVATE_KEY_RC: case SELECT_PRIVATE_KEY_RC:
mScreen.findPreference(AccountDetailTls.CONFIG_TLS_PRIVATE_KEY_FILE).setSummary(myFile.getName()); mScreen.findPreference(AccountDetailTls.CONFIG_TLS_PRIVATE_KEY_FILE).setSummary(myFile.getName());
......
...@@ -182,8 +182,6 @@ public class CallActivity extends FragmentActivity implements IMFragment.Callbac ...@@ -182,8 +182,6 @@ public class CallActivity extends FragmentActivity implements IMFragment.Callbac
if (u != null) { if (u != null) {
CallContact c = CallContact.ContactBuilder.buildUnknownContact(u.getSchemeSpecificPart()); CallContact c = CallContact.ContactBuilder.buildUnknownContact(u.getSchemeSpecificPart());
try { try {
mService.destroyNotification();
String accountID = (String) mService.getAccountList().get(1); // We use the first account to place outgoing calls String accountID = (String) mService.getAccountList().get(1); // We use the first account to place outgoing calls
HashMap<String, String> details = (HashMap<String, String>) mService.getAccountDetails(accountID); HashMap<String, String> details = (HashMap<String, String>) mService.getAccountDetails(accountID);
ArrayList<HashMap<String, String>> credentials = (ArrayList<HashMap<String, String>>) mService.getCredentials(accountID); ArrayList<HashMap<String, String>> credentials = (ArrayList<HashMap<String, String>>) mService.getCredentials(accountID);
...@@ -219,7 +217,6 @@ public class CallActivity extends FragmentActivity implements IMFragment.Callbac ...@@ -219,7 +217,6 @@ public class CallActivity extends FragmentActivity implements IMFragment.Callbac
IMBundle.putParcelableArrayList("messages", new ArrayList<SipMessage>()); IMBundle.putParcelableArrayList("messages", new ArrayList<SipMessage>());
mIMFragment.setArguments(IMBundle); mIMFragment.setArguments(IMBundle);
} }
} }
mSlidingPaneLayout.setCurFragment(mCurrentCallFragment); mSlidingPaneLayout.setCurFragment(mCurrentCallFragment);
......
...@@ -116,8 +116,6 @@ public class HomeActivity extends FragmentActivity implements DialingFragment.Ca ...@@ -116,8 +116,6 @@ public class HomeActivity extends FragmentActivity implements DialingFragment.Ca
@Override @Override
protected void onSaveInstanceState(Bundle bundle) { protected void onSaveInstanceState(Bundle bundle) {
super.onSaveInstanceState(bundle); super.onSaveInstanceState(bundle);
getFragmentManager().putFragment(bundle, "ContactsListFragment", mContactsFragment);
Log.w(TAG, "onSaveInstanceState()");
} }
@Override @Override
...@@ -133,13 +131,8 @@ public class HomeActivity extends FragmentActivity implements DialingFragment.Ca ...@@ -133,13 +131,8 @@ public class HomeActivity extends FragmentActivity implements DialingFragment.Ca
bindService(intent, mConnection, Context.BIND_AUTO_CREATE); bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
} }
if (savedInstanceState != null) {
mContactsFragment = (ContactListFragment) getFragmentManager().getFragment(savedInstanceState, "ContactsListFragment");
}
if (mContactsFragment == null) {
mContactsFragment = new ContactListFragment(); mContactsFragment = new ContactListFragment();
getFragmentManager().beginTransaction().replace(R.id.contacts_frame, mContactsFragment).commit(); getFragmentManager().beginTransaction().replace(R.id.contacts_frame, mContactsFragment).commit();
}
mContactDrawer = (SlidingUpPanelLayout) findViewById(R.id.contact_panel); mContactDrawer = (SlidingUpPanelLayout) findViewById(R.id.contact_panel);
// mContactDrawer.setShadowDrawable(getResources().getDrawable(R.drawable.above_shadow)); // mContactDrawer.setShadowDrawable(getResources().getDrawable(R.drawable.above_shadow));
...@@ -259,8 +252,8 @@ public class HomeActivity extends FragmentActivity implements DialingFragment.Ca ...@@ -259,8 +252,8 @@ public class HomeActivity extends FragmentActivity implements DialingFragment.Ca
} }
private static boolean copyAsset(AssetManager assetManager, String fromAssetPath, String toPath) { private static boolean copyAsset(AssetManager assetManager, String fromAssetPath, String toPath) {
InputStream in = null; InputStream in;
OutputStream out = null; OutputStream out;
try { try {
in = assetManager.open(fromAssetPath); in = assetManager.open(fromAssetPath);
new File(toPath).createNewFile(); new File(toPath).createNewFile();
...@@ -382,14 +375,9 @@ public class HomeActivity extends FragmentActivity implements DialingFragment.Ca ...@@ -382,14 +375,9 @@ public class HomeActivity extends FragmentActivity implements DialingFragment.Ca
@Override @Override
public void onServiceConnected(ComponentName className, IBinder binder) { public void onServiceConnected(ComponentName className, IBinder binder) {
service = ISipService.Stub.asInterface(binder); service = ISipService.Stub.asInterface(binder);
try {
fMenu = new MenuFragment(); fMenu = new MenuFragment();
fContent = new HomeFragment(); fContent = new HomeFragment();
getSupportFragmentManager().beginTransaction().replace(R.id.left_drawer, fMenu).replace(R.id.main_frame, fContent, "Home").addToBackStack("Home").commit(); getSupportFragmentManager().beginTransaction().replace(R.id.left_drawer, fMenu).replace(R.id.main_frame, fContent, "Home").addToBackStack("Home").commit();
service.destroyNotification();
} catch (RemoteException e) {
Log.e(TAG, e.toString());
}
mBound = true; mBound = true;
Log.d(TAG, "Service connected service=" + service); Log.d(TAG, "Service connected service=" + service);
} }
......
...@@ -88,6 +88,15 @@ public class NestedSettingsFragment extends PreferenceFragment { ...@@ -88,6 +88,15 @@ public class NestedSettingsFragment extends PreferenceFragment {
return results; return results;
} }
public boolean checkCertificate(String crt) {
try {
return mCallbacks.getService().checkCertificateValidity(crt);
} catch (RemoteException e) {
e.printStackTrace();
}
return false;
}
public interface Callbacks { public interface Callbacks {
public Account getAccount(); public Account getAccount();
......
...@@ -31,14 +31,14 @@ interface ISipService { ...@@ -31,14 +31,14 @@ interface ISipService {
void setActiveCodecList(in List codecs, in String accountID); void setActiveCodecList(in List codecs, in String accountID);
Map getRingtoneList(); Map getRingtoneList();
boolean checkForPrivateKey(in String pemPath);
boolean checkCertificateValidity(in String pemPath);
boolean checkHostnameCertificate(in String certificatePath, in String host, in String port);
// FIXME // FIXME
void toggleSpeakerPhone(in boolean toggle); void toggleSpeakerPhone(in boolean toggle);
/* Notification */
void createNotification();
void destroyNotification();
/* Recording */ /* Recording */
void setRecordPath(in String path); void setRecordPath(in String path);
String getRecordPath(); String getRecordPath();
......
...@@ -1073,6 +1073,63 @@ public class SipService extends Service { ...@@ -1073,6 +1073,63 @@ public class SipService extends Service {
return null; return null;
} }
@Override
public boolean checkForPrivateKey(final String pemPath) throws RemoteException {
class hasPrivateKey extends SipRunnableWithReturn {
@Override
protected Boolean doRun() throws SameThreadException {
Log.i(TAG, "SipService.isCaptureMuted() thread running...");
return configurationManagerJNI.checkForPrivateKey(pemPath);
}
}
hasPrivateKey runInstance = new hasPrivateKey();
getExecutor().execute(runInstance);
while (!runInstance.isDone()) {
}
return (Boolean) runInstance.getVal();
}
@Override
public boolean checkCertificateValidity(final String pemPath) throws RemoteException {
class isValid extends SipRunnableWithReturn {
@Override
protected Boolean doRun() throws SameThreadException {
Log.i(TAG, "SipService.isCaptureMuted() thread running...");
return configurationManagerJNI.checkCertificateValidity(pemPath);
}
}
isValid runInstance = new isValid();
getExecutor().execute(runInstance);
while (!runInstance.isDone()) {
}
return (Boolean) runInstance.getVal();
}
@Override
public boolean checkHostnameCertificate(final String certificatePath, final String host, final String port) throws RemoteException {
class isValid extends SipRunnableWithReturn {
@Override
protected Boolean doRun() throws SameThreadException {
Log.i(TAG, "SipService.isCaptureMuted() thread running...");
return configurationManagerJNI.checkHostnameCertificate(certificatePath, host, port);
}
}
isValid runInstance = new isValid();
getExecutor().execute(runInstance);
while (!runInstance.isDone()) {
}
return (Boolean) runInstance.getVal();
}
@Override @Override
public void setActiveCodecList(final List codecs, final String accountID) throws RemoteException { public void setActiveCodecList(final List codecs, final String accountID) throws RemoteException {
getExecutor().execute(new SipRunnable() { getExecutor().execute(new SipRunnable() {
...@@ -1088,18 +1145,6 @@ public class SipService extends Service { ...@@ -1088,18 +1145,6 @@ public class SipService extends Service {
}); });
} }
/***********************
* Notification API
***********************/
@Override
public void createNotification() throws RemoteException {
}
@Override
public void destroyNotification() throws RemoteException {
}
@Override @Override
public Conference getCurrentCall() throws RemoteException { public Conference getCurrentCall() throws RemoteException {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment