Nathan Harold | 330e108 | 2017-01-12 18:38:57 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package android.net; |
| 17 | |
| 18 | import android.os.Parcel; |
| 19 | import android.os.Parcelable; |
Nathan Harold | a10003d | 2017-08-23 13:46:33 -0700 | [diff] [blame] | 20 | |
| 21 | import com.android.internal.annotations.VisibleForTesting; |
Nathan Harold | 330e108 | 2017-01-12 18:38:57 -0800 | [diff] [blame] | 22 | |
Jonathan Basseri | c61b70d | 2017-04-21 15:53:51 -0700 | [diff] [blame] | 23 | /** |
| 24 | * This class encapsulates all the configuration parameters needed to create IPsec transforms and |
| 25 | * policies. |
| 26 | * |
| 27 | * @hide |
| 28 | */ |
Nathan Harold | 330e108 | 2017-01-12 18:38:57 -0800 | [diff] [blame] | 29 | public final class IpSecConfig implements Parcelable { |
Nathan Harold | 93962f3 | 2017-03-07 13:23:36 -0800 | [diff] [blame] | 30 | private static final String TAG = "IpSecConfig"; |
Nathan Harold | 330e108 | 2017-01-12 18:38:57 -0800 | [diff] [blame] | 31 | |
Nathan Harold | a10003d | 2017-08-23 13:46:33 -0700 | [diff] [blame] | 32 | // MODE_TRANSPORT or MODE_TUNNEL |
| 33 | private int mMode = IpSecTransform.MODE_TRANSPORT; |
Nathan Harold | 330e108 | 2017-01-12 18:38:57 -0800 | [diff] [blame] | 34 | |
Nathan Harold | a10003d | 2017-08-23 13:46:33 -0700 | [diff] [blame] | 35 | // Preventing this from being null simplifies Java->Native binder |
Nathan Harold | a252331 | 2018-01-05 19:25:13 -0800 | [diff] [blame] | 36 | private String mSourceAddress = ""; |
Nathan Harold | 330e108 | 2017-01-12 18:38:57 -0800 | [diff] [blame] | 37 | |
Nathan Harold | a10003d | 2017-08-23 13:46:33 -0700 | [diff] [blame] | 38 | // Preventing this from being null simplifies Java->Native binder |
Nathan Harold | a252331 | 2018-01-05 19:25:13 -0800 | [diff] [blame] | 39 | private String mDestinationAddress = ""; |
Nathan Harold | 330e108 | 2017-01-12 18:38:57 -0800 | [diff] [blame] | 40 | |
Nathan Harold | d6f50b2 | 2017-10-04 12:58:55 -0700 | [diff] [blame] | 41 | // The underlying Network that represents the "gateway" Network |
Nathan Harold | a10003d | 2017-08-23 13:46:33 -0700 | [diff] [blame] | 42 | // for outbound packets. It may also be used to select packets. |
| 43 | private Network mNetwork; |
Nathan Harold | 330e108 | 2017-01-12 18:38:57 -0800 | [diff] [blame] | 44 | |
Nathan Harold | a252331 | 2018-01-05 19:25:13 -0800 | [diff] [blame] | 45 | // Minimum requirements for identifying a transform |
| 46 | // SPI identifying the IPsec SA in packet processing |
| 47 | // and a destination IP address |
| 48 | private int mSpiResourceId = IpSecManager.INVALID_RESOURCE_ID; |
Nathan Harold | 330e108 | 2017-01-12 18:38:57 -0800 | [diff] [blame] | 49 | |
Nathan Harold | a252331 | 2018-01-05 19:25:13 -0800 | [diff] [blame] | 50 | // Encryption Algorithm |
| 51 | private IpSecAlgorithm mEncryption; |
Nathan Harold | 330e108 | 2017-01-12 18:38:57 -0800 | [diff] [blame] | 52 | |
Nathan Harold | a252331 | 2018-01-05 19:25:13 -0800 | [diff] [blame] | 53 | // Authentication Algorithm |
| 54 | private IpSecAlgorithm mAuthentication; |
ludi | b0c95b1 | 2017-05-22 10:52:23 -0700 | [diff] [blame] | 55 | |
Nathan Harold | a252331 | 2018-01-05 19:25:13 -0800 | [diff] [blame] | 56 | // Authenticated Encryption Algorithm |
| 57 | private IpSecAlgorithm mAuthenticatedEncryption; |
Nathan Harold | 330e108 | 2017-01-12 18:38:57 -0800 | [diff] [blame] | 58 | |
| 59 | // For tunnel mode IPv4 UDP Encapsulation |
| 60 | // IpSecTransform#ENCAP_ESP_*, such as ENCAP_ESP_OVER_UDP_IKE |
Nathan Harold | a10003d | 2017-08-23 13:46:33 -0700 | [diff] [blame] | 61 | private int mEncapType = IpSecTransform.ENCAP_NONE; |
| 62 | private int mEncapSocketResourceId = IpSecManager.INVALID_RESOURCE_ID; |
| 63 | private int mEncapRemotePort; |
Nathan Harold | 330e108 | 2017-01-12 18:38:57 -0800 | [diff] [blame] | 64 | |
Nathan Harold | 330e108 | 2017-01-12 18:38:57 -0800 | [diff] [blame] | 65 | // An interval, in seconds between the NattKeepalive packets |
Nathan Harold | a10003d | 2017-08-23 13:46:33 -0700 | [diff] [blame] | 66 | private int mNattKeepaliveInterval; |
| 67 | |
Benedict Wong | ab80e1f | 2018-07-25 18:46:19 -0700 | [diff] [blame] | 68 | // XFRM mark and mask; defaults to 0 (no mark/mask) |
Di Lu | 0b611f4 | 2018-01-11 11:35:25 -0800 | [diff] [blame] | 69 | private int mMarkValue; |
| 70 | private int mMarkMask; |
| 71 | |
Benedict Wong | 781dae6 | 2018-09-06 11:31:25 -0700 | [diff] [blame] | 72 | // XFRM interface id |
| 73 | private int mXfrmInterfaceId; |
| 74 | |
Nathan Harold | a10003d | 2017-08-23 13:46:33 -0700 | [diff] [blame] | 75 | /** Set the mode for this IPsec transform */ |
| 76 | public void setMode(int mode) { |
| 77 | mMode = mode; |
| 78 | } |
| 79 | |
Nathan Harold | a252331 | 2018-01-05 19:25:13 -0800 | [diff] [blame] | 80 | /** Set the source IP addres for this IPsec transform */ |
| 81 | public void setSourceAddress(String sourceAddress) { |
| 82 | mSourceAddress = sourceAddress; |
Nathan Harold | a10003d | 2017-08-23 13:46:33 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Nathan Harold | a252331 | 2018-01-05 19:25:13 -0800 | [diff] [blame] | 85 | /** Set the destination IP address for this IPsec transform */ |
| 86 | public void setDestinationAddress(String destinationAddress) { |
| 87 | mDestinationAddress = destinationAddress; |
Nathan Harold | a10003d | 2017-08-23 13:46:33 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Nathan Harold | a252331 | 2018-01-05 19:25:13 -0800 | [diff] [blame] | 90 | /** Set the SPI by resource ID */ |
| 91 | public void setSpiResourceId(int resourceId) { |
| 92 | mSpiResourceId = resourceId; |
Nathan Harold | a10003d | 2017-08-23 13:46:33 -0700 | [diff] [blame] | 93 | } |
| 94 | |
Nathan Harold | a252331 | 2018-01-05 19:25:13 -0800 | [diff] [blame] | 95 | /** Set the encryption algorithm */ |
| 96 | public void setEncryption(IpSecAlgorithm encryption) { |
| 97 | mEncryption = encryption; |
Nathan Harold | a10003d | 2017-08-23 13:46:33 -0700 | [diff] [blame] | 98 | } |
| 99 | |
Nathan Harold | a252331 | 2018-01-05 19:25:13 -0800 | [diff] [blame] | 100 | /** Set the authentication algorithm */ |
| 101 | public void setAuthentication(IpSecAlgorithm authentication) { |
| 102 | mAuthentication = authentication; |
Nathan Harold | a10003d | 2017-08-23 13:46:33 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Nathan Harold | a252331 | 2018-01-05 19:25:13 -0800 | [diff] [blame] | 105 | /** Set the authenticated encryption algorithm */ |
| 106 | public void setAuthenticatedEncryption(IpSecAlgorithm authenticatedEncryption) { |
| 107 | mAuthenticatedEncryption = authenticatedEncryption; |
Benedict Wong | 0febe5e | 2017-08-22 21:42:33 -0700 | [diff] [blame] | 108 | } |
| 109 | |
Nathan Harold | a252331 | 2018-01-05 19:25:13 -0800 | [diff] [blame] | 110 | /** Set the underlying network that will carry traffic for this transform */ |
Nathan Harold | a10003d | 2017-08-23 13:46:33 -0700 | [diff] [blame] | 111 | public void setNetwork(Network network) { |
| 112 | mNetwork = network; |
| 113 | } |
| 114 | |
| 115 | public void setEncapType(int encapType) { |
| 116 | mEncapType = encapType; |
| 117 | } |
| 118 | |
| 119 | public void setEncapSocketResourceId(int resourceId) { |
| 120 | mEncapSocketResourceId = resourceId; |
| 121 | } |
| 122 | |
| 123 | public void setEncapRemotePort(int port) { |
| 124 | mEncapRemotePort = port; |
| 125 | } |
| 126 | |
| 127 | public void setNattKeepaliveInterval(int interval) { |
| 128 | mNattKeepaliveInterval = interval; |
| 129 | } |
Nathan Harold | 330e108 | 2017-01-12 18:38:57 -0800 | [diff] [blame] | 130 | |
Benedict Wong | ab80e1f | 2018-07-25 18:46:19 -0700 | [diff] [blame] | 131 | /** |
| 132 | * Sets the mark value |
| 133 | * |
| 134 | * <p>Internal (System server) use only. Marks passed in by users will be overwritten or |
| 135 | * ignored. |
| 136 | */ |
Di Lu | 0b611f4 | 2018-01-11 11:35:25 -0800 | [diff] [blame] | 137 | public void setMarkValue(int mark) { |
| 138 | mMarkValue = mark; |
| 139 | } |
| 140 | |
Benedict Wong | ab80e1f | 2018-07-25 18:46:19 -0700 | [diff] [blame] | 141 | /** |
| 142 | * Sets the mark mask |
| 143 | * |
| 144 | * <p>Internal (System server) use only. Marks passed in by users will be overwritten or |
| 145 | * ignored. |
| 146 | */ |
Di Lu | 0b611f4 | 2018-01-11 11:35:25 -0800 | [diff] [blame] | 147 | public void setMarkMask(int mask) { |
| 148 | mMarkMask = mask; |
| 149 | } |
| 150 | |
Benedict Wong | 781dae6 | 2018-09-06 11:31:25 -0700 | [diff] [blame] | 151 | public void setXfrmInterfaceId(int xfrmInterfaceId) { |
| 152 | mXfrmInterfaceId = xfrmInterfaceId; |
| 153 | } |
| 154 | |
Nathan Harold | 93962f3 | 2017-03-07 13:23:36 -0800 | [diff] [blame] | 155 | // Transport or Tunnel |
| 156 | public int getMode() { |
Nathan Harold | a10003d | 2017-08-23 13:46:33 -0700 | [diff] [blame] | 157 | return mMode; |
Nathan Harold | 93962f3 | 2017-03-07 13:23:36 -0800 | [diff] [blame] | 158 | } |
| 159 | |
Nathan Harold | a252331 | 2018-01-05 19:25:13 -0800 | [diff] [blame] | 160 | public String getSourceAddress() { |
| 161 | return mSourceAddress; |
Nathan Harold | 330e108 | 2017-01-12 18:38:57 -0800 | [diff] [blame] | 162 | } |
| 163 | |
Nathan Harold | a252331 | 2018-01-05 19:25:13 -0800 | [diff] [blame] | 164 | public int getSpiResourceId() { |
| 165 | return mSpiResourceId; |
Nathan Harold | 330e108 | 2017-01-12 18:38:57 -0800 | [diff] [blame] | 166 | } |
| 167 | |
Nathan Harold | a252331 | 2018-01-05 19:25:13 -0800 | [diff] [blame] | 168 | public String getDestinationAddress() { |
| 169 | return mDestinationAddress; |
Nathan Harold | 330e108 | 2017-01-12 18:38:57 -0800 | [diff] [blame] | 170 | } |
| 171 | |
Nathan Harold | a252331 | 2018-01-05 19:25:13 -0800 | [diff] [blame] | 172 | public IpSecAlgorithm getEncryption() { |
| 173 | return mEncryption; |
Nathan Harold | 330e108 | 2017-01-12 18:38:57 -0800 | [diff] [blame] | 174 | } |
| 175 | |
Nathan Harold | a252331 | 2018-01-05 19:25:13 -0800 | [diff] [blame] | 176 | public IpSecAlgorithm getAuthentication() { |
| 177 | return mAuthentication; |
Nathan Harold | 330e108 | 2017-01-12 18:38:57 -0800 | [diff] [blame] | 178 | } |
| 179 | |
Nathan Harold | a252331 | 2018-01-05 19:25:13 -0800 | [diff] [blame] | 180 | public IpSecAlgorithm getAuthenticatedEncryption() { |
| 181 | return mAuthenticatedEncryption; |
Benedict Wong | 0febe5e | 2017-08-22 21:42:33 -0700 | [diff] [blame] | 182 | } |
| 183 | |
Nathan Harold | 93962f3 | 2017-03-07 13:23:36 -0800 | [diff] [blame] | 184 | public Network getNetwork() { |
Nathan Harold | a10003d | 2017-08-23 13:46:33 -0700 | [diff] [blame] | 185 | return mNetwork; |
Nathan Harold | 330e108 | 2017-01-12 18:38:57 -0800 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | public int getEncapType() { |
Nathan Harold | a10003d | 2017-08-23 13:46:33 -0700 | [diff] [blame] | 189 | return mEncapType; |
Nathan Harold | 330e108 | 2017-01-12 18:38:57 -0800 | [diff] [blame] | 190 | } |
| 191 | |
Nathan Harold | a10003d | 2017-08-23 13:46:33 -0700 | [diff] [blame] | 192 | public int getEncapSocketResourceId() { |
| 193 | return mEncapSocketResourceId; |
Nathan Harold | 330e108 | 2017-01-12 18:38:57 -0800 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | public int getEncapRemotePort() { |
Nathan Harold | a10003d | 2017-08-23 13:46:33 -0700 | [diff] [blame] | 197 | return mEncapRemotePort; |
Nathan Harold | 330e108 | 2017-01-12 18:38:57 -0800 | [diff] [blame] | 198 | } |
| 199 | |
Nathan Harold | 93962f3 | 2017-03-07 13:23:36 -0800 | [diff] [blame] | 200 | public int getNattKeepaliveInterval() { |
Nathan Harold | a10003d | 2017-08-23 13:46:33 -0700 | [diff] [blame] | 201 | return mNattKeepaliveInterval; |
Nathan Harold | 330e108 | 2017-01-12 18:38:57 -0800 | [diff] [blame] | 202 | } |
| 203 | |
Di Lu | 0b611f4 | 2018-01-11 11:35:25 -0800 | [diff] [blame] | 204 | public int getMarkValue() { |
| 205 | return mMarkValue; |
| 206 | } |
| 207 | |
| 208 | public int getMarkMask() { |
| 209 | return mMarkMask; |
| 210 | } |
| 211 | |
Benedict Wong | 781dae6 | 2018-09-06 11:31:25 -0700 | [diff] [blame] | 212 | public int getXfrmInterfaceId() { |
| 213 | return mXfrmInterfaceId; |
| 214 | } |
| 215 | |
Nathan Harold | 330e108 | 2017-01-12 18:38:57 -0800 | [diff] [blame] | 216 | // Parcelable Methods |
| 217 | |
| 218 | @Override |
| 219 | public int describeContents() { |
| 220 | return 0; |
| 221 | } |
| 222 | |
| 223 | @Override |
| 224 | public void writeToParcel(Parcel out, int flags) { |
Nathan Harold | a10003d | 2017-08-23 13:46:33 -0700 | [diff] [blame] | 225 | out.writeInt(mMode); |
Nathan Harold | a252331 | 2018-01-05 19:25:13 -0800 | [diff] [blame] | 226 | out.writeString(mSourceAddress); |
| 227 | out.writeString(mDestinationAddress); |
Nathan Harold | a10003d | 2017-08-23 13:46:33 -0700 | [diff] [blame] | 228 | out.writeParcelable(mNetwork, flags); |
Nathan Harold | a252331 | 2018-01-05 19:25:13 -0800 | [diff] [blame] | 229 | out.writeInt(mSpiResourceId); |
| 230 | out.writeParcelable(mEncryption, flags); |
| 231 | out.writeParcelable(mAuthentication, flags); |
| 232 | out.writeParcelable(mAuthenticatedEncryption, flags); |
Nathan Harold | a10003d | 2017-08-23 13:46:33 -0700 | [diff] [blame] | 233 | out.writeInt(mEncapType); |
| 234 | out.writeInt(mEncapSocketResourceId); |
| 235 | out.writeInt(mEncapRemotePort); |
Nathan Harold | 19ce70b | 2017-09-25 19:33:13 -0700 | [diff] [blame] | 236 | out.writeInt(mNattKeepaliveInterval); |
Di Lu | 0b611f4 | 2018-01-11 11:35:25 -0800 | [diff] [blame] | 237 | out.writeInt(mMarkValue); |
| 238 | out.writeInt(mMarkMask); |
Benedict Wong | 781dae6 | 2018-09-06 11:31:25 -0700 | [diff] [blame] | 239 | out.writeInt(mXfrmInterfaceId); |
Nathan Harold | 330e108 | 2017-01-12 18:38:57 -0800 | [diff] [blame] | 240 | } |
| 241 | |
Nathan Harold | a10003d | 2017-08-23 13:46:33 -0700 | [diff] [blame] | 242 | @VisibleForTesting |
| 243 | public IpSecConfig() {} |
Nathan Harold | 330e108 | 2017-01-12 18:38:57 -0800 | [diff] [blame] | 244 | |
Benedict Wong | 9dd3a38 | 2018-02-06 20:43:21 -0800 | [diff] [blame] | 245 | /** Copy constructor */ |
| 246 | @VisibleForTesting |
| 247 | public IpSecConfig(IpSecConfig c) { |
| 248 | mMode = c.mMode; |
| 249 | mSourceAddress = c.mSourceAddress; |
| 250 | mDestinationAddress = c.mDestinationAddress; |
| 251 | mNetwork = c.mNetwork; |
| 252 | mSpiResourceId = c.mSpiResourceId; |
| 253 | mEncryption = c.mEncryption; |
| 254 | mAuthentication = c.mAuthentication; |
| 255 | mAuthenticatedEncryption = c.mAuthenticatedEncryption; |
| 256 | mEncapType = c.mEncapType; |
| 257 | mEncapSocketResourceId = c.mEncapSocketResourceId; |
| 258 | mEncapRemotePort = c.mEncapRemotePort; |
| 259 | mNattKeepaliveInterval = c.mNattKeepaliveInterval; |
| 260 | mMarkValue = c.mMarkValue; |
| 261 | mMarkMask = c.mMarkMask; |
Benedict Wong | 781dae6 | 2018-09-06 11:31:25 -0700 | [diff] [blame] | 262 | mXfrmInterfaceId = c.mXfrmInterfaceId; |
Benedict Wong | 9dd3a38 | 2018-02-06 20:43:21 -0800 | [diff] [blame] | 263 | } |
| 264 | |
Nathan Harold | 330e108 | 2017-01-12 18:38:57 -0800 | [diff] [blame] | 265 | private IpSecConfig(Parcel in) { |
Nathan Harold | a10003d | 2017-08-23 13:46:33 -0700 | [diff] [blame] | 266 | mMode = in.readInt(); |
Nathan Harold | a252331 | 2018-01-05 19:25:13 -0800 | [diff] [blame] | 267 | mSourceAddress = in.readString(); |
| 268 | mDestinationAddress = in.readString(); |
Nathan Harold | a10003d | 2017-08-23 13:46:33 -0700 | [diff] [blame] | 269 | mNetwork = (Network) in.readParcelable(Network.class.getClassLoader()); |
Nathan Harold | a252331 | 2018-01-05 19:25:13 -0800 | [diff] [blame] | 270 | mSpiResourceId = in.readInt(); |
| 271 | mEncryption = |
Nathan Harold | 330e108 | 2017-01-12 18:38:57 -0800 | [diff] [blame] | 272 | (IpSecAlgorithm) in.readParcelable(IpSecAlgorithm.class.getClassLoader()); |
Nathan Harold | a252331 | 2018-01-05 19:25:13 -0800 | [diff] [blame] | 273 | mAuthentication = |
Nathan Harold | 330e108 | 2017-01-12 18:38:57 -0800 | [diff] [blame] | 274 | (IpSecAlgorithm) in.readParcelable(IpSecAlgorithm.class.getClassLoader()); |
Nathan Harold | a252331 | 2018-01-05 19:25:13 -0800 | [diff] [blame] | 275 | mAuthenticatedEncryption = |
Benedict Wong | 0febe5e | 2017-08-22 21:42:33 -0700 | [diff] [blame] | 276 | (IpSecAlgorithm) in.readParcelable(IpSecAlgorithm.class.getClassLoader()); |
Nathan Harold | a10003d | 2017-08-23 13:46:33 -0700 | [diff] [blame] | 277 | mEncapType = in.readInt(); |
| 278 | mEncapSocketResourceId = in.readInt(); |
| 279 | mEncapRemotePort = in.readInt(); |
Nathan Harold | 19ce70b | 2017-09-25 19:33:13 -0700 | [diff] [blame] | 280 | mNattKeepaliveInterval = in.readInt(); |
Di Lu | 0b611f4 | 2018-01-11 11:35:25 -0800 | [diff] [blame] | 281 | mMarkValue = in.readInt(); |
| 282 | mMarkMask = in.readInt(); |
Benedict Wong | 781dae6 | 2018-09-06 11:31:25 -0700 | [diff] [blame] | 283 | mXfrmInterfaceId = in.readInt(); |
Nathan Harold | 330e108 | 2017-01-12 18:38:57 -0800 | [diff] [blame] | 284 | } |
| 285 | |
ludi | b0c95b1 | 2017-05-22 10:52:23 -0700 | [diff] [blame] | 286 | @Override |
| 287 | public String toString() { |
| 288 | StringBuilder strBuilder = new StringBuilder(); |
| 289 | strBuilder |
Nathan Harold | a10003d | 2017-08-23 13:46:33 -0700 | [diff] [blame] | 290 | .append("{mMode=") |
| 291 | .append(mMode == IpSecTransform.MODE_TUNNEL ? "TUNNEL" : "TRANSPORT") |
Nathan Harold | a252331 | 2018-01-05 19:25:13 -0800 | [diff] [blame] | 292 | .append(", mSourceAddress=") |
| 293 | .append(mSourceAddress) |
| 294 | .append(", mDestinationAddress=") |
| 295 | .append(mDestinationAddress) |
Nathan Harold | a10003d | 2017-08-23 13:46:33 -0700 | [diff] [blame] | 296 | .append(", mNetwork=") |
| 297 | .append(mNetwork) |
| 298 | .append(", mEncapType=") |
| 299 | .append(mEncapType) |
| 300 | .append(", mEncapSocketResourceId=") |
| 301 | .append(mEncapSocketResourceId) |
| 302 | .append(", mEncapRemotePort=") |
| 303 | .append(mEncapRemotePort) |
| 304 | .append(", mNattKeepaliveInterval=") |
| 305 | .append(mNattKeepaliveInterval) |
Nathan Harold | a252331 | 2018-01-05 19:25:13 -0800 | [diff] [blame] | 306 | .append("{mSpiResourceId=") |
| 307 | .append(mSpiResourceId) |
| 308 | .append(", mEncryption=") |
| 309 | .append(mEncryption) |
| 310 | .append(", mAuthentication=") |
| 311 | .append(mAuthentication) |
| 312 | .append(", mAuthenticatedEncryption=") |
| 313 | .append(mAuthenticatedEncryption) |
Di Lu | 0b611f4 | 2018-01-11 11:35:25 -0800 | [diff] [blame] | 314 | .append(", mMarkValue=") |
| 315 | .append(mMarkValue) |
| 316 | .append(", mMarkMask=") |
| 317 | .append(mMarkMask) |
Benedict Wong | 781dae6 | 2018-09-06 11:31:25 -0700 | [diff] [blame] | 318 | .append(", mXfrmInterfaceId=") |
| 319 | .append(mXfrmInterfaceId) |
ludi | b0c95b1 | 2017-05-22 10:52:23 -0700 | [diff] [blame] | 320 | .append("}"); |
| 321 | |
| 322 | return strBuilder.toString(); |
| 323 | } |
| 324 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame^] | 325 | public static final @android.annotation.NonNull Parcelable.Creator<IpSecConfig> CREATOR = |
Nathan Harold | 330e108 | 2017-01-12 18:38:57 -0800 | [diff] [blame] | 326 | new Parcelable.Creator<IpSecConfig>() { |
| 327 | public IpSecConfig createFromParcel(Parcel in) { |
| 328 | return new IpSecConfig(in); |
| 329 | } |
| 330 | |
| 331 | public IpSecConfig[] newArray(int size) { |
| 332 | return new IpSecConfig[size]; |
| 333 | } |
| 334 | }; |
Nathan Harold | 19ce70b | 2017-09-25 19:33:13 -0700 | [diff] [blame] | 335 | |
| 336 | @VisibleForTesting |
Nathan Harold | d6f50b2 | 2017-10-04 12:58:55 -0700 | [diff] [blame] | 337 | /** Equals method used for testing */ |
Nathan Harold | 19ce70b | 2017-09-25 19:33:13 -0700 | [diff] [blame] | 338 | public static boolean equals(IpSecConfig lhs, IpSecConfig rhs) { |
| 339 | if (lhs == null || rhs == null) return (lhs == rhs); |
| 340 | return (lhs.mMode == rhs.mMode |
Nathan Harold | a252331 | 2018-01-05 19:25:13 -0800 | [diff] [blame] | 341 | && lhs.mSourceAddress.equals(rhs.mSourceAddress) |
| 342 | && lhs.mDestinationAddress.equals(rhs.mDestinationAddress) |
Nathan Harold | 19ce70b | 2017-09-25 19:33:13 -0700 | [diff] [blame] | 343 | && ((lhs.mNetwork != null && lhs.mNetwork.equals(rhs.mNetwork)) |
| 344 | || (lhs.mNetwork == rhs.mNetwork)) |
| 345 | && lhs.mEncapType == rhs.mEncapType |
| 346 | && lhs.mEncapSocketResourceId == rhs.mEncapSocketResourceId |
| 347 | && lhs.mEncapRemotePort == rhs.mEncapRemotePort |
| 348 | && lhs.mNattKeepaliveInterval == rhs.mNattKeepaliveInterval |
Nathan Harold | a252331 | 2018-01-05 19:25:13 -0800 | [diff] [blame] | 349 | && lhs.mSpiResourceId == rhs.mSpiResourceId |
| 350 | && IpSecAlgorithm.equals(lhs.mEncryption, rhs.mEncryption) |
Benedict Wong | 781dae6 | 2018-09-06 11:31:25 -0700 | [diff] [blame] | 351 | && IpSecAlgorithm.equals(lhs.mAuthenticatedEncryption, rhs.mAuthenticatedEncryption) |
Di Lu | 0b611f4 | 2018-01-11 11:35:25 -0800 | [diff] [blame] | 352 | && IpSecAlgorithm.equals(lhs.mAuthentication, rhs.mAuthentication) |
| 353 | && lhs.mMarkValue == rhs.mMarkValue |
Benedict Wong | 781dae6 | 2018-09-06 11:31:25 -0700 | [diff] [blame] | 354 | && lhs.mMarkMask == rhs.mMarkMask |
| 355 | && lhs.mXfrmInterfaceId == rhs.mXfrmInterfaceId); |
Nathan Harold | 19ce70b | 2017-09-25 19:33:13 -0700 | [diff] [blame] | 356 | } |
Nathan Harold | 330e108 | 2017-01-12 18:38:57 -0800 | [diff] [blame] | 357 | } |