1 /*
2  * Copyright (C) 2021 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 
17 package android.net.ipsec.ike;
18 
19 import android.annotation.NonNull;
20 import android.annotation.SuppressLint;
21 
22 import java.util.Objects;
23 
24 /**
25  * IkeTunnelConnectionParams contains IKEv2 configurations to establish an IKE/IPsec tunnel.
26  *
27  * <p>This class containing IKEv2-specific configuration, authentication and authorization
28  * parameters to establish an IKE/IPsec tunnel.
29  */
30 public final class IkeTunnelConnectionParams {
31     private final IkeSessionParams mIkeParams;
32     private final TunnelModeChildSessionParams mChildParams;
33 
34     /**
35      * Construct an IkeTunnelConnectionParams instance.
36      *
37      * @param ikeParams the IKE Session configuration
38      * @param childParams the Tunnel mode Child Session configuration
39      */
IkeTunnelConnectionParams( @onNull IkeSessionParams ikeParams, @NonNull TunnelModeChildSessionParams childParams)40     public IkeTunnelConnectionParams(
41             @NonNull IkeSessionParams ikeParams,
42             @NonNull TunnelModeChildSessionParams childParams) {
43         Objects.requireNonNull(ikeParams, "ikeParams was null");
44         Objects.requireNonNull(childParams, "childParams was null");
45 
46         mIkeParams = ikeParams;
47         mChildParams = childParams;
48     }
49 
50     /** Returns the IKE Session configuration. */
51     @NonNull
getIkeSessionParams()52     public IkeSessionParams getIkeSessionParams() {
53         return mIkeParams;
54     }
55 
56     /** Returns the Tunnel mode Child Session configuration. */
57     @NonNull
getTunnelModeChildSessionParams()58     public TunnelModeChildSessionParams getTunnelModeChildSessionParams() {
59         return mChildParams;
60     }
61 
62     /** @hide */
63     @Override
hashCode()64     public int hashCode() {
65         return Objects.hash(mIkeParams, mChildParams);
66     }
67 
68     /** @hide */
69     // TODO: b/177434707 Calling IkeTunnelConnectionParams is safe because it does not depend on any
70     // platform API added after SDK R. Handle this case in a mainline standard way when b/177434707
71     // is fixed.
72     @SuppressLint("NewApi")
73     @Override
equals(Object o)74     public boolean equals(Object o) {
75         if (!(o instanceof IkeTunnelConnectionParams)) {
76             return false;
77         }
78 
79         IkeTunnelConnectionParams other = (IkeTunnelConnectionParams) o;
80 
81         return Objects.equals(mIkeParams, other.mIkeParams)
82                 && Objects.equals(mChildParams, other.mChildParams);
83     }
84 }
85