From 41e5cc7039a626ca594134049e997bc9339097a9 Mon Sep 17 00:00:00 2001 From: Chiachang Wang Date: Thu, 17 Mar 2022 15:24:24 +0800 Subject: [PATCH] Store IkeTunnelConnectionParams in Ikev2VpnProfile IkeTunnelConnectionParams contains more information than the existing fields inside Ikev2VpnProfile. If the Ikev2VpnProfile is built from an IkeTunnelConnectionParams, saving it to the existing fields of Ikev2VpnProfile may cause information lost, such as IKE options. Thus, store the IkeTunnelConnectionParams as a field inside Ikev2VpnProfile. The other Ike options are mutually exclusive with IkeTunnelConnectionParams. The information such as Preshared key or username/password may not return expected values if a profile is built from an IkeTunnelConnectionParams. This may confuse API callers for using the other getters. Thus, expose a getter to retrieve IkeTunnelConnectionParams Bug: 184750836 Test: atest FrameworksNetTests CTS-Coverage-Bug: 184750836 Change-Id: I61e9a9549b87951956afdcbae2518228994e4729 --- core/api/current.txt | 1 + core/java/android/net/Ikev2VpnProfile.java | 26 +++++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/core/api/current.txt b/core/api/current.txt index 88f4eecbaaa46..4d1399f20cd3b 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -25213,6 +25213,7 @@ package android.net { public final class Ikev2VpnProfile extends android.net.PlatformVpnProfile { method @NonNull public java.util.List getAllowedAlgorithms(); + method @Nullable public android.net.ipsec.ike.IkeTunnelConnectionParams getIkeTunnelConnectionParams(); method public int getMaxMtu(); method @Nullable public String getPassword(); method @Nullable public byte[] getPresharedKey(); diff --git a/core/java/android/net/Ikev2VpnProfile.java b/core/java/android/net/Ikev2VpnProfile.java index 0fd3e034291b1..3abe83bd33731 100644 --- a/core/java/android/net/Ikev2VpnProfile.java +++ b/core/java/android/net/Ikev2VpnProfile.java @@ -142,6 +142,7 @@ public final class Ikev2VpnProfile extends PlatformVpnProfile { private final boolean mIsMetered; // Defaults in builder private final int mMaxMtu; // Defaults in builder private final boolean mIsRestrictedToTestNetworks; + @Nullable private final IkeTunnelConnectionParams mIkeTunConnParams; private Ikev2VpnProfile( int type, @@ -160,7 +161,8 @@ public final class Ikev2VpnProfile extends PlatformVpnProfile { int maxMtu, boolean restrictToTestNetworks, boolean excludeLocalRoutes, - boolean requiresInternetValidation) { + boolean requiresInternetValidation, + @Nullable IkeTunnelConnectionParams ikeTunConnParams) { super(type, excludeLocalRoutes, requiresInternetValidation); checkNotNull(serverAddr, MISSING_PARAM_MSG_TMPL, "Server address"); @@ -190,6 +192,8 @@ public final class Ikev2VpnProfile extends PlatformVpnProfile { mMaxMtu = maxMtu; mIsRestrictedToTestNetworks = restrictToTestNetworks; + mIkeTunConnParams = ikeTunConnParams; + validate(); } @@ -375,6 +379,12 @@ public final class Ikev2VpnProfile extends PlatformVpnProfile { return mMaxMtu; } + /** Retrieves the ikeTunnelConnectionParams contains IKEv2 configurations, if any was set. */ + @Nullable + public IkeTunnelConnectionParams getIkeTunnelConnectionParams() { + return mIkeTunConnParams; + } + /** * Returns whether or not this VPN profile is restricted to test networks. * @@ -403,7 +413,8 @@ public final class Ikev2VpnProfile extends PlatformVpnProfile { mMaxMtu, mIsRestrictedToTestNetworks, mExcludeLocalRoutes, - mRequiresInternetValidation); + mRequiresInternetValidation, + mIkeTunConnParams); } @Override @@ -429,7 +440,8 @@ public final class Ikev2VpnProfile extends PlatformVpnProfile { && mMaxMtu == other.mMaxMtu && mIsRestrictedToTestNetworks == other.mIsRestrictedToTestNetworks && mExcludeLocalRoutes == other.mExcludeLocalRoutes - && mRequiresInternetValidation == other.mRequiresInternetValidation; + && mRequiresInternetValidation == other.mRequiresInternetValidation + && Objects.equals(mIkeTunConnParams, other.mIkeTunConnParams); } /** @@ -504,6 +516,7 @@ public final class Ikev2VpnProfile extends PlatformVpnProfile { @NonNull public static Ikev2VpnProfile fromVpnProfile(@NonNull VpnProfile profile) throws GeneralSecurityException { + // TODO: Build the VpnProfile from mIkeTunConnParams if it exists. final Builder builder = new Builder(profile.server, profile.ipsecIdentifier); builder.setProxy(profile.proxy); builder.setAllowedAlgorithms(profile.getAllowedAlgorithms()); @@ -788,7 +801,7 @@ public final class Ikev2VpnProfile extends PlatformVpnProfile { private int mMaxMtu = PlatformVpnProfile.MAX_MTU_DEFAULT; private boolean mIsRestrictedToTestNetworks = false; private boolean mExcludeLocalRoutes = false; - @Nullable private IkeTunnelConnectionParams mIkeTunConnParams; + @Nullable private final IkeTunnelConnectionParams mIkeTunConnParams; /** * Creates a new builder with the basic parameters of an IKEv2/IPsec VPN. @@ -803,6 +816,8 @@ public final class Ikev2VpnProfile extends PlatformVpnProfile { mServerAddr = serverAddr; mUserIdentity = identity; + + mIkeTunConnParams = null; } /** @@ -1135,7 +1150,8 @@ public final class Ikev2VpnProfile extends PlatformVpnProfile { mMaxMtu, mIsRestrictedToTestNetworks, mExcludeLocalRoutes, - mRequiresInternetValidation); + mRequiresInternetValidation, + mIkeTunConnParams); } } }