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
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>.
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
18 package org
.strongswan
.android
.data
;
21 import android
.text
.TextUtils
;
23 import java
.util
.Arrays
;
24 import java
.util
.SortedSet
;
25 import java
.util
.TreeSet
;
26 import java
.util
.UUID
;
28 public class VpnProfile
implements Cloneable
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;
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;
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
;
46 private long mId
= -1;
48 public enum SelectedAppsHandling
50 SELECTED_APPS_DISABLE(0),
51 SELECTED_APPS_EXCLUDE(1),
52 SELECTED_APPS_ONLY(2);
54 private Integer mValue
;
56 SelectedAppsHandling(int value
)
61 public Integer
getValue()
69 this.mUUID
= UUID
.randomUUID();
77 public void setId(long id
)
82 public void setUUID(UUID uuid
)
92 public String
getName()
97 public void setName(String name
)
102 public String
getGateway()
107 public void setGateway(String gateway
)
109 this.mGateway
= gateway
;
112 public VpnType
getVpnType()
117 public void setVpnType(VpnType type
)
119 this.mVpnType
= type
;
122 public String
getIkeProposal()
127 public void setIkeProposal(String proposal
)
129 this.mIkeProposal
= proposal
;
132 public String
getEspProposal()
137 public void setEspProposal(String proposal
)
139 this.mEspProposal
= proposal
;
142 public String
getUsername()
147 public void setUsername(String username
)
149 this.mUsername
= username
;
152 public String
getPassword()
157 public void setPassword(String password
)
159 this.mPassword
= password
;
162 public String
getCertificateAlias()
167 public void setCertificateAlias(String alias
)
169 this.mCertificate
= alias
;
172 public String
getUserCertificateAlias()
174 return mUserCertificate
;
177 public void setUserCertificateAlias(String alias
)
179 this.mUserCertificate
= alias
;
182 public String
getLocalId()
187 public void setLocalId(String localId
)
189 this.mLocalId
= localId
;
192 public String
getRemoteId()
197 public void setRemoteId(String remoteId
)
199 this.mRemoteId
= remoteId
;
202 public Integer
getMTU()
207 public void setMTU(Integer mtu
)
212 public Integer
getPort()
217 public void setPort(Integer port
)
222 public Integer
getNATKeepAlive()
224 return mNATKeepAlive
;
227 public void setNATKeepAlive(Integer keepalive
)
229 this.mNATKeepAlive
= keepalive
;
232 public void setExcludedSubnets(String excludedSubnets
)
234 this.mExcludedSubnets
= excludedSubnets
;
237 public String
getExcludedSubnets()
239 return mExcludedSubnets
;
242 public void setIncludedSubnets(String includedSubnets
)
244 this.mIncludedSubnets
= includedSubnets
;
247 public String
getIncludedSubnets()
249 return mIncludedSubnets
;
252 public void setSelectedApps(String selectedApps
)
254 this.mSelectedApps
= selectedApps
;
257 public void setSelectedApps(SortedSet
<String
> selectedApps
)
259 this.mSelectedApps
= selectedApps
.size() > 0 ? TextUtils
.join(" ", selectedApps
) : null;
262 public String
getSelectedApps()
264 return mSelectedApps
;
267 public SortedSet
<String
> getSelectedAppsSet()
269 TreeSet
<String
> set
= new TreeSet
<>();
270 if (!TextUtils
.isEmpty(mSelectedApps
))
272 set
.addAll(Arrays
.asList(mSelectedApps
.split("\\s+")));
277 public void setSelectedAppsHandling(SelectedAppsHandling selectedAppsHandling
)
279 this.mSelectedAppsHandling
= selectedAppsHandling
;
282 public void setSelectedAppsHandling(Integer value
)
284 mSelectedAppsHandling
= SelectedAppsHandling
.SELECTED_APPS_DISABLE
;
285 for (SelectedAppsHandling handling
: SelectedAppsHandling
.values())
287 if (handling
.mValue
.equals(value
))
289 mSelectedAppsHandling
= handling
;
295 public SelectedAppsHandling
getSelectedAppsHandling()
297 return mSelectedAppsHandling
;
300 public Integer
getSplitTunneling()
302 return mSplitTunneling
;
305 public void setSplitTunneling(Integer splitTunneling
)
307 this.mSplitTunneling
= splitTunneling
;
310 public Integer
getFlags()
312 return mFlags
== null ?
0 : mFlags
;
315 public void setFlags(Integer flags
)
321 public String
toString()
327 public boolean equals(Object o
)
329 if (o
!= null && o
instanceof VpnProfile
)
331 VpnProfile other
= (VpnProfile
)o
;
332 if (this.mUUID
!= null && other
.getUUID() != null)
334 return this.mUUID
.equals(other
.getUUID());
336 return this.mId
== other
.getId();
342 public VpnProfile
clone()
346 return (VpnProfile
)super.clone();
348 catch (CloneNotSupportedException e
)
350 throw new AssertionError();