VpnProfile.java 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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. package org.strongswan.android.data;
  18. import android.text.TextUtils;
  19. import java.util.Arrays;
  20. import java.util.SortedSet;
  21. import java.util.TreeSet;
  22. import java.util.UUID;
  23. public class VpnProfile implements Cloneable
  24. {
  25. /* While storing this as EnumSet would be nicer this simplifies storing it in a database */
  26. public static final int SPLIT_TUNNELING_BLOCK_IPV4 = 1;
  27. public static final int SPLIT_TUNNELING_BLOCK_IPV6 = 2;
  28. public static final int FLAGS_SUPPRESS_CERT_REQS = 1 << 0;
  29. public static final int FLAGS_DISABLE_CRL = 1 << 1;
  30. public static final int FLAGS_DISABLE_OCSP = 1 << 2;
  31. public static final int FLAGS_STRICT_REVOCATION = 1 << 3;
  32. public static final int FLAGS_RSA_PSS = 1 << 4;
  33. private String mName, mGateway, mUsername, mPassword, mCertificate, mUserCertificate;
  34. private String mRemoteId, mLocalId, mExcludedSubnets, mIncludedSubnets, mSelectedApps;
  35. private String mIkeProposal, mEspProposal, mDnsServers;
  36. private Integer mMTU, mPort, mSplitTunneling, mNATKeepAlive, mFlags;
  37. private SelectedAppsHandling mSelectedAppsHandling = SelectedAppsHandling.SELECTED_APPS_DISABLE;
  38. private VpnType mVpnType;
  39. private UUID mUUID;
  40. private long mId = -1;
  41. public enum SelectedAppsHandling
  42. {
  43. SELECTED_APPS_DISABLE(0),
  44. SELECTED_APPS_EXCLUDE(1),
  45. SELECTED_APPS_ONLY(2);
  46. private Integer mValue;
  47. SelectedAppsHandling(int value)
  48. {
  49. mValue = value;
  50. }
  51. public Integer getValue()
  52. {
  53. return mValue;
  54. }
  55. }
  56. public VpnProfile()
  57. {
  58. this.mUUID = UUID.randomUUID();
  59. }
  60. public long getId()
  61. {
  62. return mId;
  63. }
  64. public void setId(long id)
  65. {
  66. this.mId = id;
  67. }
  68. public void setUUID(UUID uuid)
  69. {
  70. this.mUUID = uuid;
  71. }
  72. public UUID getUUID()
  73. {
  74. return mUUID;
  75. }
  76. public String getName()
  77. {
  78. return mName;
  79. }
  80. public void setName(String name)
  81. {
  82. this.mName = name;
  83. }
  84. public String getGateway()
  85. {
  86. return mGateway;
  87. }
  88. public void setGateway(String gateway)
  89. {
  90. this.mGateway = gateway;
  91. }
  92. public VpnType getVpnType()
  93. {
  94. return mVpnType;
  95. }
  96. public void setVpnType(VpnType type)
  97. {
  98. this.mVpnType = type;
  99. }
  100. public String getIkeProposal()
  101. {
  102. return mIkeProposal;
  103. }
  104. public void setIkeProposal(String proposal)
  105. {
  106. this.mIkeProposal = proposal;
  107. }
  108. public String getEspProposal()
  109. {
  110. return mEspProposal;
  111. }
  112. public void setEspProposal(String proposal)
  113. {
  114. this.mEspProposal = proposal;
  115. }
  116. public String getDnsServers()
  117. {
  118. return mDnsServers;
  119. }
  120. public void setDnsServers(String dns)
  121. {
  122. this.mDnsServers = dns;
  123. }
  124. public String getUsername()
  125. {
  126. return mUsername;
  127. }
  128. public void setUsername(String username)
  129. {
  130. this.mUsername = username;
  131. }
  132. public String getPassword()
  133. {
  134. return mPassword;
  135. }
  136. public void setPassword(String password)
  137. {
  138. this.mPassword = password;
  139. }
  140. public String getCertificateAlias()
  141. {
  142. return mCertificate;
  143. }
  144. public void setCertificateAlias(String alias)
  145. {
  146. this.mCertificate = alias;
  147. }
  148. public String getUserCertificateAlias()
  149. {
  150. return mUserCertificate;
  151. }
  152. public void setUserCertificateAlias(String alias)
  153. {
  154. this.mUserCertificate = alias;
  155. }
  156. public String getLocalId()
  157. {
  158. return mLocalId;
  159. }
  160. public void setLocalId(String localId)
  161. {
  162. this.mLocalId = localId;
  163. }
  164. public String getRemoteId()
  165. {
  166. return mRemoteId;
  167. }
  168. public void setRemoteId(String remoteId)
  169. {
  170. this.mRemoteId = remoteId;
  171. }
  172. public Integer getMTU()
  173. {
  174. return mMTU;
  175. }
  176. public void setMTU(Integer mtu)
  177. {
  178. this.mMTU = mtu;
  179. }
  180. public Integer getPort()
  181. {
  182. return mPort;
  183. }
  184. public void setPort(Integer port)
  185. {
  186. this.mPort = port;
  187. }
  188. public Integer getNATKeepAlive()
  189. {
  190. return mNATKeepAlive;
  191. }
  192. public void setNATKeepAlive(Integer keepalive)
  193. {
  194. this.mNATKeepAlive = keepalive;
  195. }
  196. public void setExcludedSubnets(String excludedSubnets)
  197. {
  198. this.mExcludedSubnets = excludedSubnets;
  199. }
  200. public String getExcludedSubnets()
  201. {
  202. return mExcludedSubnets;
  203. }
  204. public void setIncludedSubnets(String includedSubnets)
  205. {
  206. this.mIncludedSubnets = includedSubnets;
  207. }
  208. public String getIncludedSubnets()
  209. {
  210. return mIncludedSubnets;
  211. }
  212. public void setSelectedApps(String selectedApps)
  213. {
  214. this.mSelectedApps = selectedApps;
  215. }
  216. public void setSelectedApps(SortedSet<String> selectedApps)
  217. {
  218. this.mSelectedApps = selectedApps.size() > 0 ? TextUtils.join(" ", selectedApps) : null;
  219. }
  220. public String getSelectedApps()
  221. {
  222. return mSelectedApps;
  223. }
  224. public SortedSet<String> getSelectedAppsSet()
  225. {
  226. TreeSet<String> set = new TreeSet<>();
  227. if (!TextUtils.isEmpty(mSelectedApps))
  228. {
  229. set.addAll(Arrays.asList(mSelectedApps.split("\\s+")));
  230. }
  231. return set;
  232. }
  233. public void setSelectedAppsHandling(SelectedAppsHandling selectedAppsHandling)
  234. {
  235. this.mSelectedAppsHandling = selectedAppsHandling;
  236. }
  237. public void setSelectedAppsHandling(Integer value)
  238. {
  239. mSelectedAppsHandling = SelectedAppsHandling.SELECTED_APPS_DISABLE;
  240. for (SelectedAppsHandling handling : SelectedAppsHandling.values())
  241. {
  242. if (handling.mValue.equals(value))
  243. {
  244. mSelectedAppsHandling = handling;
  245. break;
  246. }
  247. }
  248. }
  249. public SelectedAppsHandling getSelectedAppsHandling()
  250. {
  251. return mSelectedAppsHandling;
  252. }
  253. public Integer getSplitTunneling()
  254. {
  255. return mSplitTunneling;
  256. }
  257. public void setSplitTunneling(Integer splitTunneling)
  258. {
  259. this.mSplitTunneling = splitTunneling;
  260. }
  261. public Integer getFlags()
  262. {
  263. return mFlags == null ? 0 : mFlags;
  264. }
  265. public void setFlags(Integer flags)
  266. {
  267. this.mFlags = flags;
  268. }
  269. @Override
  270. public String toString()
  271. {
  272. return mName;
  273. }
  274. @Override
  275. public boolean equals(Object o)
  276. {
  277. if (o != null && o instanceof VpnProfile)
  278. {
  279. VpnProfile other = (VpnProfile)o;
  280. if (this.mUUID != null && other.getUUID() != null)
  281. {
  282. return this.mUUID.equals(other.getUUID());
  283. }
  284. return this.mId == other.getId();
  285. }
  286. return false;
  287. }
  288. @Override
  289. public VpnProfile clone()
  290. {
  291. try
  292. {
  293. return (VpnProfile)super.clone();
  294. }
  295. catch (CloneNotSupportedException e)
  296. {
  297. throw new AssertionError();
  298. }
  299. }
  300. }