IpSecConfig.java revision 19ce70b089310bc4ecb193b728e2ea7d3471ba20
1330e1089da80cddcd68758512370d217b19f8890Nathan Harold/*
2330e1089da80cddcd68758512370d217b19f8890Nathan Harold * Copyright (C) 2017 The Android Open Source Project
3330e1089da80cddcd68758512370d217b19f8890Nathan Harold *
4330e1089da80cddcd68758512370d217b19f8890Nathan Harold * Licensed under the Apache License, Version 2.0 (the "License");
5330e1089da80cddcd68758512370d217b19f8890Nathan Harold * you may not use this file except in compliance with the License.
6330e1089da80cddcd68758512370d217b19f8890Nathan Harold * You may obtain a copy of the License at
7330e1089da80cddcd68758512370d217b19f8890Nathan Harold *
8330e1089da80cddcd68758512370d217b19f8890Nathan Harold *      http://www.apache.org/licenses/LICENSE-2.0
9330e1089da80cddcd68758512370d217b19f8890Nathan Harold *
10330e1089da80cddcd68758512370d217b19f8890Nathan Harold * Unless required by applicable law or agreed to in writing, software
11330e1089da80cddcd68758512370d217b19f8890Nathan Harold * distributed under the License is distributed on an "AS IS" BASIS,
12330e1089da80cddcd68758512370d217b19f8890Nathan Harold * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13330e1089da80cddcd68758512370d217b19f8890Nathan Harold * See the License for the specific language governing permissions and
14330e1089da80cddcd68758512370d217b19f8890Nathan Harold * limitations under the License.
15330e1089da80cddcd68758512370d217b19f8890Nathan Harold */
16330e1089da80cddcd68758512370d217b19f8890Nathan Haroldpackage android.net;
17330e1089da80cddcd68758512370d217b19f8890Nathan Harold
18330e1089da80cddcd68758512370d217b19f8890Nathan Haroldimport android.os.Parcel;
19330e1089da80cddcd68758512370d217b19f8890Nathan Haroldimport android.os.Parcelable;
20a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold
21a10003d5de52339f4d30fedd7294941378e5f13cNathan Haroldimport com.android.internal.annotations.VisibleForTesting;
22330e1089da80cddcd68758512370d217b19f8890Nathan Harold
23330e1089da80cddcd68758512370d217b19f8890Nathan Harold/** @hide */
24330e1089da80cddcd68758512370d217b19f8890Nathan Haroldpublic final class IpSecConfig implements Parcelable {
2593962f34ce21f5aac825afbcebf2f3e8c7a30910Nathan Harold    private static final String TAG = "IpSecConfig";
26330e1089da80cddcd68758512370d217b19f8890Nathan Harold
27a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    // MODE_TRANSPORT or MODE_TUNNEL
28a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    private int mMode = IpSecTransform.MODE_TRANSPORT;
29330e1089da80cddcd68758512370d217b19f8890Nathan Harold
30a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    // Needs to be valid only for tunnel mode
31a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    // Preventing this from being null simplifies Java->Native binder
32a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    private String mLocalAddress = "";
33330e1089da80cddcd68758512370d217b19f8890Nathan Harold
34a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    // Preventing this from being null simplifies Java->Native binder
35a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    private String mRemoteAddress = "";
36330e1089da80cddcd68758512370d217b19f8890Nathan Harold
37a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    // The underlying network interface that represents the "gateway" Network
38a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    // for outbound packets. It may also be used to select packets.
39a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    private Network mNetwork;
40330e1089da80cddcd68758512370d217b19f8890Nathan Harold
41330e1089da80cddcd68758512370d217b19f8890Nathan Harold    public static class Flow {
42330e1089da80cddcd68758512370d217b19f8890Nathan Harold        // Minimum requirements for identifying a transform
43330e1089da80cddcd68758512370d217b19f8890Nathan Harold        // SPI identifying the IPsec flow in packet processing
44330e1089da80cddcd68758512370d217b19f8890Nathan Harold        // and a remote IP address
45a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        private int mSpiResourceId = IpSecManager.INVALID_RESOURCE_ID;
46330e1089da80cddcd68758512370d217b19f8890Nathan Harold
47330e1089da80cddcd68758512370d217b19f8890Nathan Harold        // Encryption Algorithm
48a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        private IpSecAlgorithm mEncryption;
49330e1089da80cddcd68758512370d217b19f8890Nathan Harold
50330e1089da80cddcd68758512370d217b19f8890Nathan Harold        // Authentication Algorithm
51a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        private IpSecAlgorithm mAuthentication;
52b0c95b19ab4384bfc7141abfe3840736d52b4a44ludi
53b0c95b19ab4384bfc7141abfe3840736d52b4a44ludi        @Override
54b0c95b19ab4384bfc7141abfe3840736d52b4a44ludi        public String toString() {
55b0c95b19ab4384bfc7141abfe3840736d52b4a44ludi            return new StringBuilder()
56a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold                    .append("{mSpiResourceId=")
57a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold                    .append(mSpiResourceId)
58a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold                    .append(", mEncryption=")
59a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold                    .append(mEncryption)
60a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold                    .append(", mAuthentication=")
61a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold                    .append(mAuthentication)
62b0c95b19ab4384bfc7141abfe3840736d52b4a44ludi                    .append("}")
63b0c95b19ab4384bfc7141abfe3840736d52b4a44ludi                    .toString();
64b0c95b19ab4384bfc7141abfe3840736d52b4a44ludi        }
6519ce70b089310bc4ecb193b728e2ea7d3471ba20Nathan Harold
6619ce70b089310bc4ecb193b728e2ea7d3471ba20Nathan Harold        static boolean equals(IpSecConfig.Flow lhs, IpSecConfig.Flow rhs) {
6719ce70b089310bc4ecb193b728e2ea7d3471ba20Nathan Harold            if (lhs == null || rhs == null) return (lhs == rhs);
6819ce70b089310bc4ecb193b728e2ea7d3471ba20Nathan Harold            return (lhs.mSpiResourceId == rhs.mSpiResourceId
6919ce70b089310bc4ecb193b728e2ea7d3471ba20Nathan Harold                    && IpSecAlgorithm.equals(lhs.mEncryption, rhs.mEncryption)
7019ce70b089310bc4ecb193b728e2ea7d3471ba20Nathan Harold                    && IpSecAlgorithm.equals(lhs.mAuthentication, rhs.mAuthentication));
7119ce70b089310bc4ecb193b728e2ea7d3471ba20Nathan Harold        }
72330e1089da80cddcd68758512370d217b19f8890Nathan Harold    }
73330e1089da80cddcd68758512370d217b19f8890Nathan Harold
74a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    private final Flow[] mFlow = new Flow[] {new Flow(), new Flow()};
75330e1089da80cddcd68758512370d217b19f8890Nathan Harold
76330e1089da80cddcd68758512370d217b19f8890Nathan Harold    // For tunnel mode IPv4 UDP Encapsulation
77330e1089da80cddcd68758512370d217b19f8890Nathan Harold    // IpSecTransform#ENCAP_ESP_*, such as ENCAP_ESP_OVER_UDP_IKE
78a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    private int mEncapType = IpSecTransform.ENCAP_NONE;
79a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    private int mEncapSocketResourceId = IpSecManager.INVALID_RESOURCE_ID;
80a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    private int mEncapRemotePort;
81330e1089da80cddcd68758512370d217b19f8890Nathan Harold
82330e1089da80cddcd68758512370d217b19f8890Nathan Harold    // An interval, in seconds between the NattKeepalive packets
83a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    private int mNattKeepaliveInterval;
84a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold
85a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    /** Set the mode for this IPsec transform */
86a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    public void setMode(int mode) {
87a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        mMode = mode;
88a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    }
89a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold
90a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    /** Set the local IP address for Tunnel mode */
91a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    public void setLocalAddress(String localAddress) {
92a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        if (localAddress == null) {
93a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold            throw new IllegalArgumentException("localAddress may not be null!");
94a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        }
95a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        mLocalAddress = localAddress;
96a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    }
97a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold
98a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    /** Set the remote IP address for this IPsec transform */
99a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    public void setRemoteAddress(String remoteAddress) {
100a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        if (remoteAddress == null) {
101a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold            throw new IllegalArgumentException("remoteAddress may not be null!");
102a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        }
103a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        mRemoteAddress = remoteAddress;
104a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    }
105a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold
106a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    /** Set the SPI for a given direction by resource ID */
107a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    public void setSpiResourceId(int direction, int resourceId) {
108a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        mFlow[direction].mSpiResourceId = resourceId;
109a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    }
110a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold
111a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    /** Set the encryption algorithm for a given direction */
112a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    public void setEncryption(int direction, IpSecAlgorithm encryption) {
113a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        mFlow[direction].mEncryption = encryption;
114a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    }
115a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold
116a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    /** Set the authentication algorithm for a given direction */
117a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    public void setAuthentication(int direction, IpSecAlgorithm authentication) {
118a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        mFlow[direction].mAuthentication = authentication;
119a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    }
120a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold
121a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    public void setNetwork(Network network) {
122a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        mNetwork = network;
123a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    }
124a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold
125a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    public void setEncapType(int encapType) {
126a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        mEncapType = encapType;
127a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    }
128a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold
129a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    public void setEncapSocketResourceId(int resourceId) {
130a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        mEncapSocketResourceId = resourceId;
131a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    }
132a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold
133a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    public void setEncapRemotePort(int port) {
134a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        mEncapRemotePort = port;
135a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    }
136a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold
137a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    public void setNattKeepaliveInterval(int interval) {
138a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        mNattKeepaliveInterval = interval;
139a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    }
140330e1089da80cddcd68758512370d217b19f8890Nathan Harold
14193962f34ce21f5aac825afbcebf2f3e8c7a30910Nathan Harold    // Transport or Tunnel
14293962f34ce21f5aac825afbcebf2f3e8c7a30910Nathan Harold    public int getMode() {
143a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        return mMode;
14493962f34ce21f5aac825afbcebf2f3e8c7a30910Nathan Harold    }
14593962f34ce21f5aac825afbcebf2f3e8c7a30910Nathan Harold
146a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    public String getLocalAddress() {
147a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        return mLocalAddress;
148330e1089da80cddcd68758512370d217b19f8890Nathan Harold    }
149330e1089da80cddcd68758512370d217b19f8890Nathan Harold
1508dc1fd0237992e1d693376b4f6eea45e7447e9dbNathan Harold    public int getSpiResourceId(int direction) {
151a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        return mFlow[direction].mSpiResourceId;
152330e1089da80cddcd68758512370d217b19f8890Nathan Harold    }
153330e1089da80cddcd68758512370d217b19f8890Nathan Harold
154a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    public String getRemoteAddress() {
155a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        return mRemoteAddress;
156330e1089da80cddcd68758512370d217b19f8890Nathan Harold    }
157330e1089da80cddcd68758512370d217b19f8890Nathan Harold
15893962f34ce21f5aac825afbcebf2f3e8c7a30910Nathan Harold    public IpSecAlgorithm getEncryption(int direction) {
159a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        return mFlow[direction].mEncryption;
160330e1089da80cddcd68758512370d217b19f8890Nathan Harold    }
161330e1089da80cddcd68758512370d217b19f8890Nathan Harold
16293962f34ce21f5aac825afbcebf2f3e8c7a30910Nathan Harold    public IpSecAlgorithm getAuthentication(int direction) {
163a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        return mFlow[direction].mAuthentication;
164330e1089da80cddcd68758512370d217b19f8890Nathan Harold    }
165330e1089da80cddcd68758512370d217b19f8890Nathan Harold
16693962f34ce21f5aac825afbcebf2f3e8c7a30910Nathan Harold    public Network getNetwork() {
167a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        return mNetwork;
168330e1089da80cddcd68758512370d217b19f8890Nathan Harold    }
169330e1089da80cddcd68758512370d217b19f8890Nathan Harold
170330e1089da80cddcd68758512370d217b19f8890Nathan Harold    public int getEncapType() {
171a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        return mEncapType;
172330e1089da80cddcd68758512370d217b19f8890Nathan Harold    }
173330e1089da80cddcd68758512370d217b19f8890Nathan Harold
174a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    public int getEncapSocketResourceId() {
175a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        return mEncapSocketResourceId;
176330e1089da80cddcd68758512370d217b19f8890Nathan Harold    }
177330e1089da80cddcd68758512370d217b19f8890Nathan Harold
178330e1089da80cddcd68758512370d217b19f8890Nathan Harold    public int getEncapRemotePort() {
179a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        return mEncapRemotePort;
180330e1089da80cddcd68758512370d217b19f8890Nathan Harold    }
181330e1089da80cddcd68758512370d217b19f8890Nathan Harold
18293962f34ce21f5aac825afbcebf2f3e8c7a30910Nathan Harold    public int getNattKeepaliveInterval() {
183a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        return mNattKeepaliveInterval;
184330e1089da80cddcd68758512370d217b19f8890Nathan Harold    }
185330e1089da80cddcd68758512370d217b19f8890Nathan Harold
186330e1089da80cddcd68758512370d217b19f8890Nathan Harold    // Parcelable Methods
187330e1089da80cddcd68758512370d217b19f8890Nathan Harold
188330e1089da80cddcd68758512370d217b19f8890Nathan Harold    @Override
189330e1089da80cddcd68758512370d217b19f8890Nathan Harold    public int describeContents() {
190330e1089da80cddcd68758512370d217b19f8890Nathan Harold        return 0;
191330e1089da80cddcd68758512370d217b19f8890Nathan Harold    }
192330e1089da80cddcd68758512370d217b19f8890Nathan Harold
193330e1089da80cddcd68758512370d217b19f8890Nathan Harold    @Override
194330e1089da80cddcd68758512370d217b19f8890Nathan Harold    public void writeToParcel(Parcel out, int flags) {
195a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        out.writeInt(mMode);
196a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        out.writeString(mLocalAddress);
197a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        out.writeString(mRemoteAddress);
198a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        out.writeParcelable(mNetwork, flags);
199a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        out.writeInt(mFlow[IpSecTransform.DIRECTION_IN].mSpiResourceId);
200a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        out.writeParcelable(mFlow[IpSecTransform.DIRECTION_IN].mEncryption, flags);
201a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        out.writeParcelable(mFlow[IpSecTransform.DIRECTION_IN].mAuthentication, flags);
202a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        out.writeInt(mFlow[IpSecTransform.DIRECTION_OUT].mSpiResourceId);
203a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        out.writeParcelable(mFlow[IpSecTransform.DIRECTION_OUT].mEncryption, flags);
204a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        out.writeParcelable(mFlow[IpSecTransform.DIRECTION_OUT].mAuthentication, flags);
205a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        out.writeInt(mEncapType);
206a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        out.writeInt(mEncapSocketResourceId);
207a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        out.writeInt(mEncapRemotePort);
20819ce70b089310bc4ecb193b728e2ea7d3471ba20Nathan Harold        out.writeInt(mNattKeepaliveInterval);
209330e1089da80cddcd68758512370d217b19f8890Nathan Harold    }
210330e1089da80cddcd68758512370d217b19f8890Nathan Harold
211a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    @VisibleForTesting
212a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold    public IpSecConfig() {}
213a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold
214330e1089da80cddcd68758512370d217b19f8890Nathan Harold    private IpSecConfig(Parcel in) {
215a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        mMode = in.readInt();
216a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        mLocalAddress = in.readString();
217a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        mRemoteAddress = in.readString();
218a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        mNetwork = (Network) in.readParcelable(Network.class.getClassLoader());
219a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        mFlow[IpSecTransform.DIRECTION_IN].mSpiResourceId = in.readInt();
220a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        mFlow[IpSecTransform.DIRECTION_IN].mEncryption =
221330e1089da80cddcd68758512370d217b19f8890Nathan Harold                (IpSecAlgorithm) in.readParcelable(IpSecAlgorithm.class.getClassLoader());
222a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        mFlow[IpSecTransform.DIRECTION_IN].mAuthentication =
223330e1089da80cddcd68758512370d217b19f8890Nathan Harold                (IpSecAlgorithm) in.readParcelable(IpSecAlgorithm.class.getClassLoader());
224a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        mFlow[IpSecTransform.DIRECTION_OUT].mSpiResourceId = in.readInt();
225a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        mFlow[IpSecTransform.DIRECTION_OUT].mEncryption =
226330e1089da80cddcd68758512370d217b19f8890Nathan Harold                (IpSecAlgorithm) in.readParcelable(IpSecAlgorithm.class.getClassLoader());
227a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        mFlow[IpSecTransform.DIRECTION_OUT].mAuthentication =
228330e1089da80cddcd68758512370d217b19f8890Nathan Harold                (IpSecAlgorithm) in.readParcelable(IpSecAlgorithm.class.getClassLoader());
229a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        mEncapType = in.readInt();
230a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        mEncapSocketResourceId = in.readInt();
231a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold        mEncapRemotePort = in.readInt();
23219ce70b089310bc4ecb193b728e2ea7d3471ba20Nathan Harold        mNattKeepaliveInterval = in.readInt();
233330e1089da80cddcd68758512370d217b19f8890Nathan Harold    }
234330e1089da80cddcd68758512370d217b19f8890Nathan Harold
235b0c95b19ab4384bfc7141abfe3840736d52b4a44ludi    @Override
236b0c95b19ab4384bfc7141abfe3840736d52b4a44ludi    public String toString() {
237b0c95b19ab4384bfc7141abfe3840736d52b4a44ludi        StringBuilder strBuilder = new StringBuilder();
238b0c95b19ab4384bfc7141abfe3840736d52b4a44ludi        strBuilder
239a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold                .append("{mMode=")
240a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold                .append(mMode == IpSecTransform.MODE_TUNNEL ? "TUNNEL" : "TRANSPORT")
241a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold                .append(", mLocalAddress=")
242a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold                .append(mLocalAddress)
243a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold                .append(", mRemoteAddress=")
244a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold                .append(mRemoteAddress)
245a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold                .append(", mNetwork=")
246a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold                .append(mNetwork)
247a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold                .append(", mEncapType=")
248a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold                .append(mEncapType)
249a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold                .append(", mEncapSocketResourceId=")
250a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold                .append(mEncapSocketResourceId)
251a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold                .append(", mEncapRemotePort=")
252a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold                .append(mEncapRemotePort)
253a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold                .append(", mNattKeepaliveInterval=")
254a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold                .append(mNattKeepaliveInterval)
255a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold                .append(", mFlow[OUT]=")
256a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold                .append(mFlow[IpSecTransform.DIRECTION_OUT])
257a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold                .append(", mFlow[IN]=")
258a10003d5de52339f4d30fedd7294941378e5f13cNathan Harold                .append(mFlow[IpSecTransform.DIRECTION_IN])
259b0c95b19ab4384bfc7141abfe3840736d52b4a44ludi                .append("}");
260b0c95b19ab4384bfc7141abfe3840736d52b4a44ludi
261b0c95b19ab4384bfc7141abfe3840736d52b4a44ludi        return strBuilder.toString();
262b0c95b19ab4384bfc7141abfe3840736d52b4a44ludi    }
263b0c95b19ab4384bfc7141abfe3840736d52b4a44ludi
264330e1089da80cddcd68758512370d217b19f8890Nathan Harold    public static final Parcelable.Creator<IpSecConfig> CREATOR =
265330e1089da80cddcd68758512370d217b19f8890Nathan Harold            new Parcelable.Creator<IpSecConfig>() {
266330e1089da80cddcd68758512370d217b19f8890Nathan Harold                public IpSecConfig createFromParcel(Parcel in) {
267330e1089da80cddcd68758512370d217b19f8890Nathan Harold                    return new IpSecConfig(in);
268330e1089da80cddcd68758512370d217b19f8890Nathan Harold                }
269330e1089da80cddcd68758512370d217b19f8890Nathan Harold
270330e1089da80cddcd68758512370d217b19f8890Nathan Harold                public IpSecConfig[] newArray(int size) {
271330e1089da80cddcd68758512370d217b19f8890Nathan Harold                    return new IpSecConfig[size];
272330e1089da80cddcd68758512370d217b19f8890Nathan Harold                }
273330e1089da80cddcd68758512370d217b19f8890Nathan Harold            };
27419ce70b089310bc4ecb193b728e2ea7d3471ba20Nathan Harold
27519ce70b089310bc4ecb193b728e2ea7d3471ba20Nathan Harold    @VisibleForTesting
27619ce70b089310bc4ecb193b728e2ea7d3471ba20Nathan Harold    public static boolean equals(IpSecConfig lhs, IpSecConfig rhs) {
27719ce70b089310bc4ecb193b728e2ea7d3471ba20Nathan Harold        if (lhs == null || rhs == null) return (lhs == rhs);
27819ce70b089310bc4ecb193b728e2ea7d3471ba20Nathan Harold        return (lhs.mMode == rhs.mMode
27919ce70b089310bc4ecb193b728e2ea7d3471ba20Nathan Harold                && lhs.mLocalAddress.equals(rhs.mLocalAddress)
28019ce70b089310bc4ecb193b728e2ea7d3471ba20Nathan Harold                && lhs.mRemoteAddress.equals(rhs.mRemoteAddress)
28119ce70b089310bc4ecb193b728e2ea7d3471ba20Nathan Harold                && ((lhs.mNetwork != null && lhs.mNetwork.equals(rhs.mNetwork))
28219ce70b089310bc4ecb193b728e2ea7d3471ba20Nathan Harold                        || (lhs.mNetwork == rhs.mNetwork))
28319ce70b089310bc4ecb193b728e2ea7d3471ba20Nathan Harold                && lhs.mEncapType == rhs.mEncapType
28419ce70b089310bc4ecb193b728e2ea7d3471ba20Nathan Harold                && lhs.mEncapSocketResourceId == rhs.mEncapSocketResourceId
28519ce70b089310bc4ecb193b728e2ea7d3471ba20Nathan Harold                && lhs.mEncapRemotePort == rhs.mEncapRemotePort
28619ce70b089310bc4ecb193b728e2ea7d3471ba20Nathan Harold                && lhs.mNattKeepaliveInterval == rhs.mNattKeepaliveInterval
28719ce70b089310bc4ecb193b728e2ea7d3471ba20Nathan Harold                && IpSecConfig.Flow.equals(lhs.mFlow[IpSecTransform.DIRECTION_OUT],
28819ce70b089310bc4ecb193b728e2ea7d3471ba20Nathan Harold                        rhs.mFlow[IpSecTransform.DIRECTION_OUT])
28919ce70b089310bc4ecb193b728e2ea7d3471ba20Nathan Harold                && IpSecConfig.Flow.equals(lhs.mFlow[IpSecTransform.DIRECTION_IN],
29019ce70b089310bc4ecb193b728e2ea7d3471ba20Nathan Harold                        rhs.mFlow[IpSecTransform.DIRECTION_IN]));
29119ce70b089310bc4ecb193b728e2ea7d3471ba20Nathan Harold    }
292330e1089da80cddcd68758512370d217b19f8890Nathan Harold}
293