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