Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bc545c8a authored by Yan Yan's avatar Yan Yan Committed by Gerrit Code Review
Browse files

Merge changes from topics "encrypted-tunnel-interface", "iketunnelparams", "vcn-encrypted-tunnel"

* changes:
  Replace VcnControlPlaneConfig with TunnelConnectionParams
  Convert TunnelConnectionParams to/from PersistableBundle
  Create TunnelConnectionParams interface
parents 2984d878 4eaa894d
Loading
Loading
Loading
Loading
+4 −10
Original line number Diff line number Diff line
@@ -25138,6 +25138,9 @@ package android.net {
    field public static final int UNSUPPORTED = -1; // 0xffffffff
  }
  public interface TunnelConnectionParams {
  }
  public abstract class Uri implements java.lang.Comparable<android.net.Uri> android.os.Parcelable {
    method public abstract android.net.Uri.Builder buildUpon();
    method public int compareTo(android.net.Uri);
@@ -25698,15 +25701,6 @@ package android.net.vcn {
    method @NonNull public android.net.vcn.VcnConfig build();
  }
  public abstract class VcnControlPlaneConfig {
  }
  public final class VcnControlPlaneIkeConfig extends android.net.vcn.VcnControlPlaneConfig {
    ctor public VcnControlPlaneIkeConfig(@NonNull android.net.ipsec.ike.IkeSessionParams, @NonNull android.net.ipsec.ike.TunnelModeChildSessionParams);
    method @NonNull public android.net.ipsec.ike.TunnelModeChildSessionParams getChildSessionParams();
    method @NonNull public android.net.ipsec.ike.IkeSessionParams getIkeSessionParams();
  }
  public final class VcnGatewayConnectionConfig {
    method @NonNull public int[] getExposedCapabilities();
    method @NonNull public String getGatewayConnectionName();
@@ -25715,7 +25709,7 @@ package android.net.vcn {
  }
  public static final class VcnGatewayConnectionConfig.Builder {
    ctor public VcnGatewayConnectionConfig.Builder(@NonNull String, @NonNull android.net.vcn.VcnControlPlaneConfig);
    ctor public VcnGatewayConnectionConfig.Builder(@NonNull String, @NonNull android.net.TunnelConnectionParams);
    method @NonNull public android.net.vcn.VcnGatewayConnectionConfig.Builder addExposedCapability(int);
    method @NonNull public android.net.vcn.VcnGatewayConnectionConfig build();
    method @NonNull public android.net.vcn.VcnGatewayConnectionConfig.Builder removeExposedCapability(int);
+29 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package android.net;

/**
 * TunnelConnectionParams represents a configuration to set up a tunnel connection.
 *
 * <p>Concrete implementations for a control plane protocol should implement this interface.
 * Subclasses should be immutable data classes containing connection, authentication and
 * authorization parameters required to establish a tunnel connection.
 *
 * @see android.net.ipsec.ike.IkeTunnelConnectionParams
 */
// TODO:b/186071626 Remove TunnelConnectionParams when non-updatable API stub can resolve
// IkeTunnelConnectionParams
public interface TunnelConnectionParams {}
+0 −112
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package android.net.vcn;

import android.annotation.IntDef;
import android.annotation.NonNull;
import android.os.PersistableBundle;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Objects;

/**
 * This class represents a control plane configuration for a Virtual Carrier Network connection.
 *
 * <p>Each {@link VcnGatewayConnectionConfig} must have a {@link VcnControlPlaneConfig}, containing
 * all connection, authentication and authorization parameters required to establish a Gateway
 * Connection with a remote endpoint.
 *
 * <p>A {@link VcnControlPlaneConfig} object can be shared by multiple {@link
 * VcnGatewayConnectionConfig}(s) if they will used for connecting with the same remote endpoint.
 *
 * @see VcnManager
 * @see VcnGatewayConnectionConfig
 */
public abstract class VcnControlPlaneConfig {
    /** @hide */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef({CONFIG_TYPE_IKE})
    public @interface ConfigType {}

    /** @hide */
    public static final int CONFIG_TYPE_IKE = 1;

    private static final String CONFIG_TYPE_KEY = "mConfigType";
    @ConfigType private final int mConfigType;

    /**
     * Package private constructor.
     *
     * @hide
     */
    VcnControlPlaneConfig(int configType) {
        mConfigType = configType;
    }

    /**
     * Constructs a VcnControlPlaneConfig object by deserializing a PersistableBundle.
     *
     * @param in the {@link PersistableBundle} containing an {@link VcnControlPlaneConfig} object
     * @hide
     */
    public static VcnControlPlaneConfig fromPersistableBundle(@NonNull PersistableBundle in) {
        Objects.requireNonNull(in, "PersistableBundle was null");

        int configType = in.getInt(CONFIG_TYPE_KEY);
        switch (configType) {
            case CONFIG_TYPE_IKE:
                return new VcnControlPlaneIkeConfig(in);
            default:
                throw new IllegalStateException("Unrecognized configType: " + configType);
        }
    }

    /**
     * Converts this VcnControlPlaneConfig to a PersistableBundle.
     *
     * @hide
     */
    @NonNull
    public PersistableBundle toPersistableBundle() {
        final PersistableBundle result = new PersistableBundle();
        result.putInt(CONFIG_TYPE_KEY, mConfigType);
        return result;
    }

    /** @hide */
    @Override
    public int hashCode() {
        return Objects.hash(mConfigType);
    }

    /** @hide */
    @Override
    public boolean equals(Object o) {
        if (!(o instanceof VcnControlPlaneConfig)) {
            return false;
        }

        return mConfigType == ((VcnControlPlaneConfig) o).mConfigType;
    }

    /**
     * Returns a deep copy of this object.
     *
     * @hide
     */
    public abstract VcnControlPlaneConfig copy();
}
+0 −158
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.net.vcn;

import static android.net.vcn.VcnControlPlaneConfig.CONFIG_TYPE_IKE;

import android.annotation.NonNull;
import android.net.ipsec.ike.IkeSessionParams;
import android.net.ipsec.ike.TunnelModeChildSessionParams;
import android.net.vcn.persistablebundleutils.IkeSessionParamsUtils;
import android.net.vcn.persistablebundleutils.TunnelModeChildSessionParamsUtils;
import android.os.PersistableBundle;
import android.util.ArraySet;
import android.util.Log;

import java.util.Objects;

/**
 * This class is an IKEv2 control plane configuration for a Virtual Carrier Network connection.
 *
 * <p>This class is an extension of the {@link VcnControlPlaneConfig}, containing IKEv2-specific
 * configuration, authentication and authorization parameters.
 *
 * @see VcnControlPlaneConfig
 */
public final class VcnControlPlaneIkeConfig extends VcnControlPlaneConfig {
    private static final String TAG = VcnControlPlaneIkeConfig.class.getSimpleName();

    private static final String IKE_PARAMS_KEY = "mIkeParams";
    @NonNull private final IkeSessionParams mIkeParams;

    private static final String CHILD_PARAMS_KEY = "mChildParams";
    @NonNull private final TunnelModeChildSessionParams mChildParams;

    private static final ArraySet<String> BUNDLE_KEY_SET = new ArraySet<>();

    {
        BUNDLE_KEY_SET.add(IKE_PARAMS_KEY);
        BUNDLE_KEY_SET.add(CHILD_PARAMS_KEY);
    }

    /**
     * Constructs a VcnControlPlaneIkeConfig object.
     *
     * @param ikeParams the IKE Session negotiation parameters
     * @param childParams the tunnel mode Child Session negotiation parameters
     */
    public VcnControlPlaneIkeConfig(
            @NonNull IkeSessionParams ikeParams,
            @NonNull TunnelModeChildSessionParams childParams) {
        super(CONFIG_TYPE_IKE);
        mIkeParams = ikeParams;
        mChildParams = childParams;
        validate();
    }

    /**
     * Constructs a VcnControlPlaneIkeConfig object by deserializing a PersistableBundle.
     *
     * @param in the {@link PersistableBundle} containing an {@link VcnControlPlaneIkeConfig} object
     * @hide
     */
    public VcnControlPlaneIkeConfig(@NonNull PersistableBundle in) {
        super(CONFIG_TYPE_IKE);
        final PersistableBundle ikeParamsBundle = in.getPersistableBundle(IKE_PARAMS_KEY);
        final PersistableBundle childParamsBundle = in.getPersistableBundle(CHILD_PARAMS_KEY);

        Objects.requireNonNull(ikeParamsBundle, "IKE Session Params was null");
        Objects.requireNonNull(childParamsBundle, "Child Session Params was null");

        mIkeParams = IkeSessionParamsUtils.fromPersistableBundle(ikeParamsBundle);
        mChildParams = TunnelModeChildSessionParamsUtils.fromPersistableBundle(childParamsBundle);

        for (String key : in.keySet()) {
            if (!BUNDLE_KEY_SET.contains(key)) {
                Log.w(TAG, "Found an unexpected key in the PersistableBundle: " + key);
            }
        }

        validate();
    }

    private void validate() {
        Objects.requireNonNull(mIkeParams, "mIkeParams was null");
        Objects.requireNonNull(mChildParams, "mChildParams was null");
    }

    /**
     * Converts this VcnControlPlaneConfig to a PersistableBundle.
     *
     * @hide
     */
    @Override
    @NonNull
    public PersistableBundle toPersistableBundle() {
        final PersistableBundle result = super.toPersistableBundle();
        result.putPersistableBundle(
                IKE_PARAMS_KEY, IkeSessionParamsUtils.toPersistableBundle(mIkeParams));
        result.putPersistableBundle(
                CHILD_PARAMS_KEY,
                TunnelModeChildSessionParamsUtils.toPersistableBundle(mChildParams));
        return result;
    }

    /** Retrieves the IKE Session configuration. */
    @NonNull
    public IkeSessionParams getIkeSessionParams() {
        return mIkeParams;
    }

    /** Retrieves the tunnel mode Child Session configuration. */
    @NonNull
    public TunnelModeChildSessionParams getChildSessionParams() {
        return mChildParams;
    }

    /** @hide */
    @Override
    public int hashCode() {
        return Objects.hash(super.hashCode(), mIkeParams, mChildParams);
    }

    /** @hide */
    @Override
    public boolean equals(Object o) {
        if (!(o instanceof VcnControlPlaneIkeConfig)) {
            return false;
        }

        VcnControlPlaneIkeConfig other = (VcnControlPlaneIkeConfig) o;

        return super.equals(o)
                && Objects.equals(mIkeParams, other.mIkeParams)
                && Objects.equals(mChildParams, other.mChildParams);
    }

    /** @hide */
    @Override
    public VcnControlPlaneConfig copy() {
        return new VcnControlPlaneIkeConfig(
                new IkeSessionParams.Builder(mIkeParams).build(),
                new TunnelModeChildSessionParams.Builder(mChildParams).build());
    }
}
+26 −21
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ import android.annotation.Nullable;
import android.annotation.SuppressLint;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.TunnelConnectionParams;
import android.net.vcn.persistablebundleutils.TunnelConnectionParamsUtils;
import android.os.PersistableBundle;
import android.util.ArraySet;

@@ -151,8 +153,8 @@ public final class VcnGatewayConnectionConfig {
    private static final String GATEWAY_CONNECTION_NAME_KEY = "mGatewayConnectionName";
    @NonNull private final String mGatewayConnectionName;

    private static final String CTRL_PLANE_CONFIG_KEY = "mCtrlPlaneConfig";
    @NonNull private VcnControlPlaneConfig mCtrlPlaneConfig;
    private static final String TUNNEL_CONNECTION_PARAMS_KEY = "mTunnelConnectionParams";
    @NonNull private TunnelConnectionParams mTunnelConnectionParams;

    private static final String EXPOSED_CAPABILITIES_KEY = "mExposedCapabilities";
    @NonNull private final SortedSet<Integer> mExposedCapabilities;
@@ -169,13 +171,13 @@ public final class VcnGatewayConnectionConfig {
    /** Builds a VcnGatewayConnectionConfig with the specified parameters. */
    private VcnGatewayConnectionConfig(
            @NonNull String gatewayConnectionName,
            @NonNull VcnControlPlaneConfig ctrlPlaneConfig,
            @NonNull TunnelConnectionParams tunnelConnectionParams,
            @NonNull Set<Integer> exposedCapabilities,
            @NonNull Set<Integer> underlyingCapabilities,
            @NonNull long[] retryIntervalsMs,
            @IntRange(from = MIN_MTU_V6) int maxMtu) {
        mGatewayConnectionName = gatewayConnectionName;
        mCtrlPlaneConfig = ctrlPlaneConfig;
        mTunnelConnectionParams = tunnelConnectionParams;
        mExposedCapabilities = new TreeSet(exposedCapabilities);
        mUnderlyingCapabilities = new TreeSet(underlyingCapabilities);
        mRetryIntervalsMs = retryIntervalsMs;
@@ -187,9 +189,10 @@ public final class VcnGatewayConnectionConfig {
    /** @hide */
    @VisibleForTesting(visibility = Visibility.PRIVATE)
    public VcnGatewayConnectionConfig(@NonNull PersistableBundle in) {
        final PersistableBundle ctrlPlaneConfigBundle =
                in.getPersistableBundle(CTRL_PLANE_CONFIG_KEY);
        Objects.requireNonNull(ctrlPlaneConfigBundle, "ctrlPlaneConfigBundle was null");
        final PersistableBundle tunnelConnectionParamsBundle =
                in.getPersistableBundle(TUNNEL_CONNECTION_PARAMS_KEY);
        Objects.requireNonNull(
                tunnelConnectionParamsBundle, "tunnelConnectionParamsBundle was null");

        final PersistableBundle exposedCapsBundle =
                in.getPersistableBundle(EXPOSED_CAPABILITIES_KEY);
@@ -197,7 +200,8 @@ public final class VcnGatewayConnectionConfig {
                in.getPersistableBundle(UNDERLYING_CAPABILITIES_KEY);

        mGatewayConnectionName = in.getString(GATEWAY_CONNECTION_NAME_KEY);
        mCtrlPlaneConfig = VcnControlPlaneConfig.fromPersistableBundle(ctrlPlaneConfigBundle);
        mTunnelConnectionParams =
                TunnelConnectionParamsUtils.fromPersistableBundle(tunnelConnectionParamsBundle);
        mExposedCapabilities = new TreeSet<>(PersistableBundleUtils.toList(
                exposedCapsBundle, PersistableBundleUtils.INTEGER_DESERIALIZER));
        mUnderlyingCapabilities = new TreeSet<>(PersistableBundleUtils.toList(
@@ -210,7 +214,7 @@ public final class VcnGatewayConnectionConfig {

    private void validate() {
        Objects.requireNonNull(mGatewayConnectionName, "gatewayConnectionName was null");
        Objects.requireNonNull(mCtrlPlaneConfig, "control plane config was null");
        Objects.requireNonNull(mTunnelConnectionParams, "tunnel connection parameter was null");

        Preconditions.checkArgument(
                mExposedCapabilities != null && !mExposedCapabilities.isEmpty(),
@@ -262,13 +266,13 @@ public final class VcnGatewayConnectionConfig {
    }

    /**
     * Returns control plane configuration.
     * Returns tunnel connection parameters.
     *
     * @hide
     */
    @NonNull
    public VcnControlPlaneConfig getControlPlaneConfig() {
        return mCtrlPlaneConfig.copy();
    public TunnelConnectionParams getTunnelConnectionParams() {
        return mTunnelConnectionParams;
    }

    /**
@@ -360,7 +364,8 @@ public final class VcnGatewayConnectionConfig {
    public PersistableBundle toPersistableBundle() {
        final PersistableBundle result = new PersistableBundle();

        final PersistableBundle ctrlPlaneConfigBundle = mCtrlPlaneConfig.toPersistableBundle();
        final PersistableBundle tunnelConnectionParamsBundle =
                TunnelConnectionParamsUtils.toPersistableBundle(mTunnelConnectionParams);
        final PersistableBundle exposedCapsBundle =
                PersistableBundleUtils.fromList(
                        new ArrayList<>(mExposedCapabilities),
@@ -371,7 +376,7 @@ public final class VcnGatewayConnectionConfig {
                        PersistableBundleUtils.INTEGER_SERIALIZER);

        result.putString(GATEWAY_CONNECTION_NAME_KEY, mGatewayConnectionName);
        result.putPersistableBundle(CTRL_PLANE_CONFIG_KEY, ctrlPlaneConfigBundle);
        result.putPersistableBundle(TUNNEL_CONNECTION_PARAMS_KEY, tunnelConnectionParamsBundle);
        result.putPersistableBundle(EXPOSED_CAPABILITIES_KEY, exposedCapsBundle);
        result.putPersistableBundle(UNDERLYING_CAPABILITIES_KEY, underlyingCapsBundle);
        result.putLongArray(RETRY_INTERVAL_MS_KEY, mRetryIntervalsMs);
@@ -409,7 +414,7 @@ public final class VcnGatewayConnectionConfig {
     */
    public static final class Builder {
        @NonNull private final String mGatewayConnectionName;
        @NonNull private final VcnControlPlaneConfig mCtrlPlaneConfig;
        @NonNull private final TunnelConnectionParams mTunnelConnectionParams;
        @NonNull private final Set<Integer> mExposedCapabilities = new ArraySet();
        @NonNull private final Set<Integer> mUnderlyingCapabilities = new ArraySet();
        @NonNull private long[] mRetryIntervalsMs = DEFAULT_RETRY_INTERVALS_MS;
@@ -427,18 +432,18 @@ public final class VcnGatewayConnectionConfig {
         *     VcnConfig} must be given a unique name. This name is used by the caller to
         *     distinguish between VcnGatewayConnectionConfigs configured on a single {@link
         *     VcnConfig}. This will be used as the identifier in VcnStatusCallback invocations.
         * @param ctrlPlaneConfig the control plane configuration
         * @see VcnControlPlaneConfig
         * @param tunnelConnectionParams the tunnel connection configuration
         * @see TunnelConnectionParams
         * @see VcnManager.VcnStatusCallback#onGatewayConnectionError
         */
        public Builder(
                @NonNull String gatewayConnectionName,
                @NonNull VcnControlPlaneConfig ctrlPlaneConfig) {
                @NonNull TunnelConnectionParams tunnelConnectionParams) {
            Objects.requireNonNull(gatewayConnectionName, "gatewayConnectionName was null");
            Objects.requireNonNull(ctrlPlaneConfig, "ctrlPlaneConfig was null");
            Objects.requireNonNull(tunnelConnectionParams, "tunnelConnectionParams was null");

            mGatewayConnectionName = gatewayConnectionName;
            mCtrlPlaneConfig = ctrlPlaneConfig;
            mTunnelConnectionParams = tunnelConnectionParams;
        }

        /**
@@ -583,7 +588,7 @@ public final class VcnGatewayConnectionConfig {
        public VcnGatewayConnectionConfig build() {
            return new VcnGatewayConnectionConfig(
                    mGatewayConnectionName,
                    mCtrlPlaneConfig,
                    mTunnelConnectionParams,
                    mExposedCapabilities,
                    mUnderlyingCapabilities,
                    mRetryIntervalsMs,
Loading