android: Add properties for DNS servers
[strongswan.git] / src / frontends / android / app / src / main / java / org / strongswan / android / data / VpnProfile.java
1 /*
2 * Copyright (C) 2012-2019 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
34 public static final int FLAGS_SUPPRESS_CERT_REQS = 1 << 0;
35 public static final int FLAGS_DISABLE_CRL = 1 << 1;
36 public static final int FLAGS_DISABLE_OCSP = 1 << 2;
37 public static final int FLAGS_STRICT_REVOCATION = 1 << 3;
38 public static final int FLAGS_RSA_PSS = 1 << 4;
39
40 private String mName, mGateway, mUsername, mPassword, mCertificate, mUserCertificate;
41 private String mRemoteId, mLocalId, mExcludedSubnets, mIncludedSubnets, mSelectedApps;
42 private String mIkeProposal, mEspProposal, mDnsServers;
43 private Integer mMTU, mPort, mSplitTunneling, mNATKeepAlive, mFlags;
44 private SelectedAppsHandling mSelectedAppsHandling = SelectedAppsHandling.SELECTED_APPS_DISABLE;
45 private VpnType mVpnType;
46 private UUID mUUID;
47 private long mId = -1;
48
49 public enum SelectedAppsHandling
50 {
51 SELECTED_APPS_DISABLE(0),
52 SELECTED_APPS_EXCLUDE(1),
53 SELECTED_APPS_ONLY(2);
54
55 private Integer mValue;
56
57 SelectedAppsHandling(int value)
58 {
59 mValue = value;
60 }
61
62 public Integer getValue()
63 {
64 return mValue;
65 }
66 }
67
68 public VpnProfile()
69 {
70 this.mUUID = UUID.randomUUID();
71 }
72
73 public long getId()
74 {
75 return mId;
76 }
77
78 public void setId(long id)
79 {
80 this.mId = id;
81 }
82
83 public void setUUID(UUID uuid)
84 {
85 this.mUUID = uuid;
86 }
87
88 public UUID getUUID()
89 {
90 return mUUID;
91 }
92
93 public String getName()
94 {
95 return mName;
96 }
97
98 public void setName(String name)
99 {
100 this.mName = name;
101 }
102
103 public String getGateway()
104 {
105 return mGateway;
106 }
107
108 public void setGateway(String gateway)
109 {
110 this.mGateway = gateway;
111 }
112
113 public VpnType getVpnType()
114 {
115 return mVpnType;
116 }
117
118 public void setVpnType(VpnType type)
119 {
120 this.mVpnType = type;
121 }
122
123 public String getIkeProposal()
124 {
125 return mIkeProposal;
126 }
127
128 public void setIkeProposal(String proposal)
129 {
130 this.mIkeProposal = proposal;
131 }
132
133 public String getEspProposal()
134 {
135 return mEspProposal;
136 }
137
138 public void setEspProposal(String proposal)
139 {
140 this.mEspProposal = proposal;
141 }
142
143 public String getDnsServers()
144 {
145 return mDnsServers;
146 }
147
148 public void setDnsServers(String dns)
149 {
150 this.mDnsServers = dns;
151 }
152
153 public String getUsername()
154 {
155 return mUsername;
156 }
157
158 public void setUsername(String username)
159 {
160 this.mUsername = username;
161 }
162
163 public String getPassword()
164 {
165 return mPassword;
166 }
167
168 public void setPassword(String password)
169 {
170 this.mPassword = password;
171 }
172
173 public String getCertificateAlias()
174 {
175 return mCertificate;
176 }
177
178 public void setCertificateAlias(String alias)
179 {
180 this.mCertificate = alias;
181 }
182
183 public String getUserCertificateAlias()
184 {
185 return mUserCertificate;
186 }
187
188 public void setUserCertificateAlias(String alias)
189 {
190 this.mUserCertificate = alias;
191 }
192
193 public String getLocalId()
194 {
195 return mLocalId;
196 }
197
198 public void setLocalId(String localId)
199 {
200 this.mLocalId = localId;
201 }
202
203 public String getRemoteId()
204 {
205 return mRemoteId;
206 }
207
208 public void setRemoteId(String remoteId)
209 {
210 this.mRemoteId = remoteId;
211 }
212
213 public Integer getMTU()
214 {
215 return mMTU;
216 }
217
218 public void setMTU(Integer mtu)
219 {
220 this.mMTU = mtu;
221 }
222
223 public Integer getPort()
224 {
225 return mPort;
226 }
227
228 public void setPort(Integer port)
229 {
230 this.mPort = port;
231 }
232
233 public Integer getNATKeepAlive()
234 {
235 return mNATKeepAlive;
236 }
237
238 public void setNATKeepAlive(Integer keepalive)
239 {
240 this.mNATKeepAlive = keepalive;
241 }
242
243 public void setExcludedSubnets(String excludedSubnets)
244 {
245 this.mExcludedSubnets = excludedSubnets;
246 }
247
248 public String getExcludedSubnets()
249 {
250 return mExcludedSubnets;
251 }
252
253 public void setIncludedSubnets(String includedSubnets)
254 {
255 this.mIncludedSubnets = includedSubnets;
256 }
257
258 public String getIncludedSubnets()
259 {
260 return mIncludedSubnets;
261 }
262
263 public void setSelectedApps(String selectedApps)
264 {
265 this.mSelectedApps = selectedApps;
266 }
267
268 public void setSelectedApps(SortedSet<String> selectedApps)
269 {
270 this.mSelectedApps = selectedApps.size() > 0 ? TextUtils.join(" ", selectedApps) : null;
271 }
272
273 public String getSelectedApps()
274 {
275 return mSelectedApps;
276 }
277
278 public SortedSet<String> getSelectedAppsSet()
279 {
280 TreeSet<String> set = new TreeSet<>();
281 if (!TextUtils.isEmpty(mSelectedApps))
282 {
283 set.addAll(Arrays.asList(mSelectedApps.split("\\s+")));
284 }
285 return set;
286 }
287
288 public void setSelectedAppsHandling(SelectedAppsHandling selectedAppsHandling)
289 {
290 this.mSelectedAppsHandling = selectedAppsHandling;
291 }
292
293 public void setSelectedAppsHandling(Integer value)
294 {
295 mSelectedAppsHandling = SelectedAppsHandling.SELECTED_APPS_DISABLE;
296 for (SelectedAppsHandling handling : SelectedAppsHandling.values())
297 {
298 if (handling.mValue.equals(value))
299 {
300 mSelectedAppsHandling = handling;
301 break;
302 }
303 }
304 }
305
306 public SelectedAppsHandling getSelectedAppsHandling()
307 {
308 return mSelectedAppsHandling;
309 }
310
311 public Integer getSplitTunneling()
312 {
313 return mSplitTunneling;
314 }
315
316 public void setSplitTunneling(Integer splitTunneling)
317 {
318 this.mSplitTunneling = splitTunneling;
319 }
320
321 public Integer getFlags()
322 {
323 return mFlags == null ? 0 : mFlags;
324 }
325
326 public void setFlags(Integer flags)
327 {
328 this.mFlags = flags;
329 }
330
331 @Override
332 public String toString()
333 {
334 return mName;
335 }
336
337 @Override
338 public boolean equals(Object o)
339 {
340 if (o != null && o instanceof VpnProfile)
341 {
342 VpnProfile other = (VpnProfile)o;
343 if (this.mUUID != null && other.getUUID() != null)
344 {
345 return this.mUUID.equals(other.getUUID());
346 }
347 return this.mId == other.getId();
348 }
349 return false;
350 }
351
352 @Override
353 public VpnProfile clone()
354 {
355 try
356 {
357 return (VpnProfile)super.clone();
358 }
359 catch (CloneNotSupportedException e)
360 {
361 throw new AssertionError();
362 }
363 }
364 }