android: Add properties for IKE and ESP proposals
[strongswan.git] / src / frontends / android / app / src / main / java / org / strongswan / android / data / VpnProfile.java
1 /*
2 * Copyright (C) 2012-2017 Tobias Brunner
3 * Copyright (C) 2012 Giuliano Grassi
4 * Copyright (C) 2012 Ralf Sager
5 * HSR Hochschule fuer Technik Rapperswil
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 */
17
18 package org.strongswan.android.data;
19
20
21 import android.text.TextUtils;
22
23 import java.util.Arrays;
24 import java.util.SortedSet;
25 import java.util.TreeSet;
26 import java.util.UUID;
27
28 public class VpnProfile implements Cloneable
29 {
30 /* While storing this as EnumSet would be nicer this simplifies storing it in a database */
31 public static final int SPLIT_TUNNELING_BLOCK_IPV4 = 1;
32 public static final int SPLIT_TUNNELING_BLOCK_IPV6 = 2;
33 public static final int FLAGS_SUPPRESS_CERT_REQS = 1;
34
35 private String mName, mGateway, mUsername, mPassword, mCertificate, mUserCertificate;
36 private String mRemoteId, mLocalId, mExcludedSubnets, mIncludedSubnets, mSelectedApps;
37 private String mIkeProposal, mEspProposal;
38 private Integer mMTU, mPort, mSplitTunneling, mNATKeepAlive, mFlags;
39 private SelectedAppsHandling mSelectedAppsHandling = SelectedAppsHandling.SELECTED_APPS_DISABLE;
40 private VpnType mVpnType;
41 private UUID mUUID;
42 private long mId = -1;
43
44 public enum SelectedAppsHandling
45 {
46 SELECTED_APPS_DISABLE(0),
47 SELECTED_APPS_EXCLUDE(1),
48 SELECTED_APPS_ONLY(2);
49
50 private Integer mValue;
51
52 SelectedAppsHandling(int value)
53 {
54 mValue = value;
55 }
56
57 public Integer getValue()
58 {
59 return mValue;
60 }
61 }
62
63 public VpnProfile()
64 {
65 this.mUUID = UUID.randomUUID();
66 }
67
68 public long getId()
69 {
70 return mId;
71 }
72
73 public void setId(long id)
74 {
75 this.mId = id;
76 }
77
78 public void setUUID(UUID uuid)
79 {
80 this.mUUID = uuid;
81 }
82
83 public UUID getUUID()
84 {
85 return mUUID;
86 }
87
88 public String getName()
89 {
90 return mName;
91 }
92
93 public void setName(String name)
94 {
95 this.mName = name;
96 }
97
98 public String getGateway()
99 {
100 return mGateway;
101 }
102
103 public void setGateway(String gateway)
104 {
105 this.mGateway = gateway;
106 }
107
108 public VpnType getVpnType()
109 {
110 return mVpnType;
111 }
112
113 public void setVpnType(VpnType type)
114 {
115 this.mVpnType = type;
116 }
117
118 public String getIkeProposal()
119 {
120 return mIkeProposal;
121 }
122
123 public void setIkeProposal(String proposal)
124 {
125 this.mIkeProposal = proposal;
126 }
127
128 public String getEspProposal()
129 {
130 return mEspProposal;
131 }
132
133 public void setEspProposal(String proposal)
134 {
135 this.mEspProposal = proposal;
136 }
137
138 public String getUsername()
139 {
140 return mUsername;
141 }
142
143 public void setUsername(String username)
144 {
145 this.mUsername = username;
146 }
147
148 public String getPassword()
149 {
150 return mPassword;
151 }
152
153 public void setPassword(String password)
154 {
155 this.mPassword = password;
156 }
157
158 public String getCertificateAlias()
159 {
160 return mCertificate;
161 }
162
163 public void setCertificateAlias(String alias)
164 {
165 this.mCertificate = alias;
166 }
167
168 public String getUserCertificateAlias()
169 {
170 return mUserCertificate;
171 }
172
173 public void setUserCertificateAlias(String alias)
174 {
175 this.mUserCertificate = alias;
176 }
177
178 public String getLocalId()
179 {
180 return mLocalId;
181 }
182
183 public void setLocalId(String localId)
184 {
185 this.mLocalId = localId;
186 }
187
188 public String getRemoteId()
189 {
190 return mRemoteId;
191 }
192
193 public void setRemoteId(String remoteId)
194 {
195 this.mRemoteId = remoteId;
196 }
197
198 public Integer getMTU()
199 {
200 return mMTU;
201 }
202
203 public void setMTU(Integer mtu)
204 {
205 this.mMTU = mtu;
206 }
207
208 public Integer getPort()
209 {
210 return mPort;
211 }
212
213 public void setPort(Integer port)
214 {
215 this.mPort = port;
216 }
217
218 public Integer getNATKeepAlive()
219 {
220 return mNATKeepAlive;
221 }
222
223 public void setNATKeepAlive(Integer keepalive)
224 {
225 this.mNATKeepAlive = keepalive;
226 }
227
228 public void setExcludedSubnets(String excludedSubnets)
229 {
230 this.mExcludedSubnets = excludedSubnets;
231 }
232
233 public String getExcludedSubnets()
234 {
235 return mExcludedSubnets;
236 }
237
238 public void setIncludedSubnets(String includedSubnets)
239 {
240 this.mIncludedSubnets = includedSubnets;
241 }
242
243 public String getIncludedSubnets()
244 {
245 return mIncludedSubnets;
246 }
247
248 public void setSelectedApps(String selectedApps)
249 {
250 this.mSelectedApps = selectedApps;
251 }
252
253 public void setSelectedApps(SortedSet<String> selectedApps)
254 {
255 this.mSelectedApps = selectedApps.size() > 0 ? TextUtils.join(" ", selectedApps) : null;
256 }
257
258 public String getSelectedApps()
259 {
260 return mSelectedApps;
261 }
262
263 public SortedSet<String> getSelectedAppsSet()
264 {
265 TreeSet<String> set = new TreeSet<>();
266 if (!TextUtils.isEmpty(mSelectedApps))
267 {
268 set.addAll(Arrays.asList(mSelectedApps.split("\\s+")));
269 }
270 return set;
271 }
272
273 public void setSelectedAppsHandling(SelectedAppsHandling selectedAppsHandling)
274 {
275 this.mSelectedAppsHandling = selectedAppsHandling;
276 }
277
278 public void setSelectedAppsHandling(Integer value)
279 {
280 mSelectedAppsHandling = SelectedAppsHandling.SELECTED_APPS_DISABLE;
281 for (SelectedAppsHandling handling : SelectedAppsHandling.values())
282 {
283 if (handling.mValue.equals(value))
284 {
285 mSelectedAppsHandling = handling;
286 break;
287 }
288 }
289 }
290
291 public SelectedAppsHandling getSelectedAppsHandling()
292 {
293 return mSelectedAppsHandling;
294 }
295
296 public Integer getSplitTunneling()
297 {
298 return mSplitTunneling;
299 }
300
301 public void setSplitTunneling(Integer splitTunneling)
302 {
303 this.mSplitTunneling = splitTunneling;
304 }
305
306 public Integer getFlags()
307 {
308 return mFlags == null ? 0 : mFlags;
309 }
310
311 public void setFlags(Integer flags)
312 {
313 this.mFlags = flags;
314 }
315
316 @Override
317 public String toString()
318 {
319 return mName;
320 }
321
322 @Override
323 public boolean equals(Object o)
324 {
325 if (o != null && o instanceof VpnProfile)
326 {
327 VpnProfile other = (VpnProfile)o;
328 if (this.mUUID != null && other.getUUID() != null)
329 {
330 return this.mUUID.equals(other.getUUID());
331 }
332 return this.mId == other.getId();
333 }
334 return false;
335 }
336
337 @Override
338 public VpnProfile clone()
339 {
340 try
341 {
342 return (VpnProfile)super.clone();
343 }
344 catch (CloneNotSupportedException e)
345 {
346 throw new AssertionError();
347 }
348 }
349 }