2 * Copyright (C) 2012-2019 Tobias Brunner
3 * Copyright (C) 2012 Giuliano Grassi
4 * Copyright (C) 2012 Ralf Sager
6 * Copyright (C) secunet Security Networks AG
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 package org
.strongswan
.android
.data
;
22 import android
.text
.TextUtils
;
24 import java
.util
.Arrays
;
25 import java
.util
.Objects
;
26 import java
.util
.SortedSet
;
27 import java
.util
.TreeSet
;
28 import java
.util
.UUID
;
30 public class VpnProfile
implements Cloneable
32 /* While storing this as EnumSet would be nicer this simplifies storing it in a database */
33 public static final int SPLIT_TUNNELING_BLOCK_IPV4
= 1;
34 public static final int SPLIT_TUNNELING_BLOCK_IPV6
= 2;
36 public static final int FLAGS_SUPPRESS_CERT_REQS
= 1 << 0;
37 public static final int FLAGS_DISABLE_CRL
= 1 << 1;
38 public static final int FLAGS_DISABLE_OCSP
= 1 << 2;
39 public static final int FLAGS_STRICT_REVOCATION
= 1 << 3;
40 public static final int FLAGS_RSA_PSS
= 1 << 4;
41 public static final int FLAGS_IPv6_TRANSPORT
= 1 << 5;
43 private String mName
, mGateway
, mUsername
, mPassword
, mCertificate
, mUserCertificate
;
44 private String mRemoteId
, mLocalId
, mExcludedSubnets
, mIncludedSubnets
, mSelectedApps
;
45 private String mIkeProposal
, mEspProposal
, mDnsServers
;
46 private Integer mMTU
, mPort
, mSplitTunneling
, mNATKeepAlive
, mFlags
;
47 private SelectedAppsHandling mSelectedAppsHandling
= SelectedAppsHandling
.SELECTED_APPS_DISABLE
;
48 private VpnType mVpnType
;
50 private long mId
= -1;
52 public enum SelectedAppsHandling
54 SELECTED_APPS_DISABLE(0),
55 SELECTED_APPS_EXCLUDE(1),
56 SELECTED_APPS_ONLY(2);
58 private Integer mValue
;
60 SelectedAppsHandling(int value
)
65 public Integer
getValue()
73 this.mUUID
= UUID
.randomUUID();
81 public void setId(long id
)
86 public void setUUID(UUID uuid
)
96 public String
getName()
101 public void setName(String name
)
106 public String
getGateway()
111 public void setGateway(String gateway
)
113 this.mGateway
= gateway
;
116 public VpnType
getVpnType()
121 public void setVpnType(VpnType type
)
123 this.mVpnType
= type
;
126 public String
getIkeProposal()
131 public void setIkeProposal(String proposal
)
133 this.mIkeProposal
= proposal
;
136 public String
getEspProposal()
141 public void setEspProposal(String proposal
)
143 this.mEspProposal
= proposal
;
146 public String
getDnsServers()
151 public void setDnsServers(String dns
)
153 this.mDnsServers
= dns
;
156 public String
getUsername()
161 public void setUsername(String username
)
163 this.mUsername
= username
;
166 public String
getPassword()
171 public void setPassword(String password
)
173 this.mPassword
= password
;
176 public String
getCertificateAlias()
181 public void setCertificateAlias(String alias
)
183 this.mCertificate
= alias
;
186 public String
getUserCertificateAlias()
188 return mUserCertificate
;
191 public void setUserCertificateAlias(String alias
)
193 this.mUserCertificate
= alias
;
196 public String
getLocalId()
201 public void setLocalId(String localId
)
203 this.mLocalId
= localId
;
206 public String
getRemoteId()
211 public void setRemoteId(String remoteId
)
213 this.mRemoteId
= remoteId
;
216 public Integer
getMTU()
221 public void setMTU(Integer mtu
)
226 public Integer
getPort()
231 public void setPort(Integer port
)
236 public Integer
getNATKeepAlive()
238 return mNATKeepAlive
;
241 public void setNATKeepAlive(Integer keepalive
)
243 this.mNATKeepAlive
= keepalive
;
246 public void setExcludedSubnets(String excludedSubnets
)
248 this.mExcludedSubnets
= excludedSubnets
;
251 public String
getExcludedSubnets()
253 return mExcludedSubnets
;
256 public void setIncludedSubnets(String includedSubnets
)
258 this.mIncludedSubnets
= includedSubnets
;
261 public String
getIncludedSubnets()
263 return mIncludedSubnets
;
266 public void setSelectedApps(String selectedApps
)
268 this.mSelectedApps
= selectedApps
;
271 public void setSelectedApps(SortedSet
<String
> selectedApps
)
273 this.mSelectedApps
= selectedApps
.size() > 0 ? TextUtils
.join(" ", selectedApps
) : null;
276 public String
getSelectedApps()
278 return mSelectedApps
;
281 public SortedSet
<String
> getSelectedAppsSet()
283 TreeSet
<String
> set
= new TreeSet
<>();
284 if (!TextUtils
.isEmpty(mSelectedApps
))
286 set
.addAll(Arrays
.asList(mSelectedApps
.split("\\s+")));
291 public void setSelectedAppsHandling(SelectedAppsHandling selectedAppsHandling
)
293 this.mSelectedAppsHandling
= selectedAppsHandling
;
296 public void setSelectedAppsHandling(Integer value
)
298 mSelectedAppsHandling
= SelectedAppsHandling
.SELECTED_APPS_DISABLE
;
299 for (SelectedAppsHandling handling
: SelectedAppsHandling
.values())
301 if (handling
.mValue
.equals(value
))
303 mSelectedAppsHandling
= handling
;
309 public SelectedAppsHandling
getSelectedAppsHandling()
311 return mSelectedAppsHandling
;
314 public Integer
getSplitTunneling()
316 return mSplitTunneling
;
319 public void setSplitTunneling(Integer splitTunneling
)
321 this.mSplitTunneling
= splitTunneling
;
324 public Integer
getFlags()
326 return mFlags
== null ?
0 : mFlags
;
329 public void setFlags(Integer flags
)
335 public String
toString()
341 public boolean equals(Object o
)
347 if (o
== null || getClass() != o
.getClass())
351 VpnProfile that
= (VpnProfile
)o
;
352 return Objects
.equals(mUUID
, that
.mUUID
);
356 public int hashCode()
358 return Objects
.hash(mUUID
);
362 public VpnProfile
clone()
366 return (VpnProfile
)super.clone();
368 catch (CloneNotSupportedException e
)
370 throw new AssertionError();