Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (C) 2004-2012 Savoir-Faire Linux Inc. |
| 3 | * |
| 4 | * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com> |
| 5 | * |
| 6 | * This program is free software: you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation, either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * If you own a pjsip commercial license you can also redistribute it |
| 11 | * and/or modify it under the terms of the GNU Lesser General Public License |
| 12 | * as an android library. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | */ |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 22 | package org.sflphone.account; |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 23 | |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 24 | import java.util.ArrayList; |
| 25 | import java.util.HashMap; |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 26 | |
Alexandre Lision | 4f906b2 | 2013-10-02 10:13:45 -0400 | [diff] [blame] | 27 | import android.util.Log; |
| 28 | |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 29 | public class AccountDetailTls implements AccountDetail { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 30 | |
| 31 | private static final String TAG = "AccountDetailTls"; |
| 32 | public static final String BUNDLE_TAG = "TlsPreferenceArrayList"; |
Alexandre Lision | 8ad3959 | 2013-11-21 13:23:58 -0500 | [diff] [blame] | 33 | |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 34 | public static final String CONFIG_TLS_LISTENER_PORT = "TLS.listenerPort"; |
| 35 | public static final String CONFIG_TLS_ENABLE = "TLS.enable"; |
| 36 | public static final String CONFIG_TLS_CA_LIST_FILE = "TLS.certificateListFile"; |
| 37 | public static final String CONFIG_TLS_CERTIFICATE_FILE = "TLS.certificateFile"; |
| 38 | public static final String CONFIG_TLS_PRIVATE_KEY_FILE = "TLS.privateKeyFile"; |
| 39 | public static final String CONFIG_TLS_PASSWORD = "TLS.password"; |
| 40 | public static final String CONFIG_TLS_METHOD = "TLS.method"; |
| 41 | public static final String CONFIG_TLS_CIPHERS = "TLS.ciphers"; |
| 42 | public static final String CONFIG_TLS_SERVER_NAME = "TLS.serverName"; |
| 43 | public static final String CONFIG_TLS_VERIFY_SERVER = "TLS.verifyServer"; |
| 44 | public static final String CONFIG_TLS_VERIFY_CLIENT = "TLS.verifyClient"; |
| 45 | public static final String CONFIG_TLS_REQUIRE_CLIENT_CERTIFICATE = "TLS.requireClientCertificate"; |
| 46 | public static final String CONFIG_TLS_NEGOTIATION_TIMEOUT_SEC = "TLS.negotiationTimeoutSec"; |
| 47 | public static final String CONFIG_TLS_NEGOTIATION_TIMEOUT_MSEC = "TLS.negotiationTimemoutMsec"; |
Alexandre Lision | 8ad3959 | 2013-11-21 13:23:58 -0500 | [diff] [blame] | 48 | |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 49 | private ArrayList<AccountDetail.PreferenceEntry> privateArray; |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 50 | |
Alexandre Lision | 8ad3959 | 2013-11-21 13:23:58 -0500 | [diff] [blame] | 51 | public static ArrayList<AccountDetail.PreferenceEntry> getPreferenceEntries() { |
Alexandre Savard | ae99293 | 2012-10-17 10:26:12 -0400 | [diff] [blame] | 52 | ArrayList<AccountDetail.PreferenceEntry> preference = new ArrayList<AccountDetail.PreferenceEntry>(); |
| 53 | |
Alexandre Lision | ab0cc9f | 2013-12-12 11:27:25 -0500 | [diff] [blame] | 54 | preference.add(new PreferenceEntry(CONFIG_TLS_LISTENER_PORT)); |
| 55 | preference.add(new PreferenceEntry(CONFIG_TLS_ENABLE, true)); |
| 56 | preference.add(new PreferenceEntry(CONFIG_TLS_CA_LIST_FILE)); |
| 57 | preference.add(new PreferenceEntry(CONFIG_TLS_CERTIFICATE_FILE)); |
| 58 | preference.add(new PreferenceEntry(CONFIG_TLS_PRIVATE_KEY_FILE)); |
| 59 | preference.add(new PreferenceEntry(CONFIG_TLS_PASSWORD)); |
| 60 | preference.add(new PreferenceEntry(CONFIG_TLS_METHOD)); |
| 61 | preference.add(new PreferenceEntry(CONFIG_TLS_CIPHERS)); |
| 62 | preference.add(new PreferenceEntry(CONFIG_TLS_SERVER_NAME)); |
| 63 | preference.add(new PreferenceEntry(CONFIG_TLS_VERIFY_SERVER)); |
| 64 | preference.add(new PreferenceEntry(CONFIG_TLS_VERIFY_CLIENT, true)); |
| 65 | preference.add(new PreferenceEntry(CONFIG_TLS_REQUIRE_CLIENT_CERTIFICATE, true)); |
| 66 | preference.add(new PreferenceEntry(CONFIG_TLS_NEGOTIATION_TIMEOUT_SEC)); |
| 67 | preference.add(new PreferenceEntry(CONFIG_TLS_NEGOTIATION_TIMEOUT_MSEC)); |
Alexandre Savard | ae99293 | 2012-10-17 10:26:12 -0400 | [diff] [blame] | 68 | |
| 69 | return preference; |
| 70 | } |
| 71 | |
Alexandre Lision | 8ad3959 | 2013-11-21 13:23:58 -0500 | [diff] [blame] | 72 | public AccountDetailTls() { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 73 | privateArray = getPreferenceEntries(); |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 74 | } |
| 75 | |
Alexandre Lision | 8ad3959 | 2013-11-21 13:23:58 -0500 | [diff] [blame] | 76 | public AccountDetailTls(HashMap<String, String> pref) { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 77 | privateArray = getPreferenceEntries(); |
| 78 | |
Alexandre Lision | 8ad3959 | 2013-11-21 13:23:58 -0500 | [diff] [blame] | 79 | for (AccountDetail.PreferenceEntry p : privateArray) { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 80 | p.mValue = pref.get(p.mKey); |
| 81 | } |
| 82 | } |
| 83 | |
Alexandre Lision | 8ad3959 | 2013-11-21 13:23:58 -0500 | [diff] [blame] | 84 | public AccountDetailTls(ArrayList<String> pref) { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 85 | privateArray = getPreferenceEntries(); |
| 86 | |
Alexandre Lision | 8ad3959 | 2013-11-21 13:23:58 -0500 | [diff] [blame] | 87 | if (pref.size() != privateArray.size()) { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 88 | Log.i(TAG, "Error list are not of equal size"); |
Alexandre Lision | 8ad3959 | 2013-11-21 13:23:58 -0500 | [diff] [blame] | 89 | } else { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 90 | int index = 0; |
Alexandre Lision | 8ad3959 | 2013-11-21 13:23:58 -0500 | [diff] [blame] | 91 | for (String s : pref) { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 92 | privateArray.get(index).mValue = s; |
| 93 | index++; |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | |
Alexandre Lision | 8ad3959 | 2013-11-21 13:23:58 -0500 | [diff] [blame] | 98 | public ArrayList<AccountDetail.PreferenceEntry> getDetailValues() { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 99 | return privateArray; |
| 100 | } |
| 101 | |
Alexandre Lision | 8ad3959 | 2013-11-21 13:23:58 -0500 | [diff] [blame] | 102 | public ArrayList<String> getValuesOnly() { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 103 | ArrayList<String> valueList = new ArrayList<String>(); |
| 104 | |
Alexandre Lision | 8ad3959 | 2013-11-21 13:23:58 -0500 | [diff] [blame] | 105 | for (AccountDetail.PreferenceEntry p : privateArray) { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 106 | valueList.add(p.mValue); |
| 107 | } |
| 108 | |
| 109 | return valueList; |
| 110 | } |
| 111 | |
Alexandre Lision | 8ad3959 | 2013-11-21 13:23:58 -0500 | [diff] [blame] | 112 | public HashMap<String, String> getDetailsHashMap() { |
Alexandre Savard | 833616f | 2012-10-30 16:02:30 -0400 | [diff] [blame] | 113 | HashMap<String, String> map = new HashMap<String, String>(); |
| 114 | |
Alexandre Lision | 8ad3959 | 2013-11-21 13:23:58 -0500 | [diff] [blame] | 115 | for (AccountDetail.PreferenceEntry p : privateArray) { |
| 116 | if (p.mValue == null) { |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 117 | map.put(p.mKey, ""); |
| 118 | } else { |
| 119 | map.put(p.mKey, p.mValue); |
| 120 | } |
Alexandre Savard | 833616f | 2012-10-30 16:02:30 -0400 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | return map; |
| 124 | } |
| 125 | |
Alexandre Lision | 8ad3959 | 2013-11-21 13:23:58 -0500 | [diff] [blame] | 126 | public String getDetailString(String key) { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 127 | String value = ""; |
| 128 | |
Alexandre Lision | 8ad3959 | 2013-11-21 13:23:58 -0500 | [diff] [blame] | 129 | for (AccountDetail.PreferenceEntry p : privateArray) { |
| 130 | if (p.mKey.equals(key)) { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 131 | value = p.mValue; |
| 132 | return value; |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | return value; |
| 137 | } |
| 138 | |
Alexandre Lision | 8ad3959 | 2013-11-21 13:23:58 -0500 | [diff] [blame] | 139 | public void setDetailString(String key, String newValue) { |
| 140 | for (int i = 0; i < privateArray.size(); ++i) { |
alision | 5de9178 | 2013-07-10 10:47:30 -0400 | [diff] [blame] | 141 | PreferenceEntry p = privateArray.get(i); |
Alexandre Lision | 8ad3959 | 2013-11-21 13:23:58 -0500 | [diff] [blame] | 142 | if (p.mKey.equals(key)) { |
alision | 5de9178 | 2013-07-10 10:47:30 -0400 | [diff] [blame] | 143 | privateArray.get(i).mValue = newValue; |
| 144 | } |
| 145 | } |
Alexandre Lision | 8ad3959 | 2013-11-21 13:23:58 -0500 | [diff] [blame] | 146 | |
Alexandre Savard | 833616f | 2012-10-30 16:02:30 -0400 | [diff] [blame] | 147 | } |
| 148 | |
Alexandre Lision | 8ad3959 | 2013-11-21 13:23:58 -0500 | [diff] [blame] | 149 | public boolean getDetailBoolean(String key) { |
| 150 | for (AccountDetail.PreferenceEntry p : privateArray) { |
| 151 | if (p.mKey.equals(key)) { |
| 152 | return p.mValue.contentEquals("true"); |
| 153 | } |
| 154 | } |
| 155 | return false; |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 156 | } |
| 157 | } |