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

Commit 033a4308 authored by Benedict Wong's avatar Benedict Wong
Browse files

Override network and use config IKE session

This change ensures the IKE configs are used with the correct network

Bug: 163604823
Test: FrameworksVcnTests
Change-Id: Ieb2a9b202204577f6e6969ef30245baed6382aa6
parent b5244fbc
Loading
Loading
Loading
Loading
+15 −8
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ import android.net.ipsec.ike.exceptions.AuthenticationFailedException;
import android.net.ipsec.ike.exceptions.IkeException;
import android.net.ipsec.ike.exceptions.IkeInternalException;
import android.net.ipsec.ike.exceptions.IkeProtocolException;
import android.net.vcn.VcnControlPlaneIkeConfig;
import android.net.vcn.VcnGatewayConnectionConfig;
import android.net.vcn.VcnTransportInfo;
import android.net.wifi.WifiInfo;
@@ -1348,7 +1349,7 @@ public class VcnGatewayConnection extends StateMachine {
                mIkeSession = null;
            }

            mIkeSession = buildIkeSession();
            mIkeSession = buildIkeSession(mUnderlying.network);
        }

        @Override
@@ -1939,23 +1940,29 @@ public class VcnGatewayConnection extends StateMachine {
                new EventDisconnectRequestedInfo(reason, shouldQuit));
    }

    private IkeSessionParams buildIkeParams() {
        // TODO: Implement this once IkeSessionParams is persisted
        return null;
    private IkeSessionParams buildIkeParams(@NonNull Network network) {
        final VcnControlPlaneIkeConfig controlPlaneConfig =
                (VcnControlPlaneIkeConfig) mConnectionConfig.getControlPlaneConfig();
        final IkeSessionParams.Builder builder =
                new IkeSessionParams.Builder(controlPlaneConfig.getIkeSessionParams());
        builder.setConfiguredNetwork(network);

        return builder.build();
    }

    private ChildSessionParams buildChildParams() {
        // TODO: Implement this once IkeSessionParams is persisted
        return null;
        final VcnControlPlaneIkeConfig controlPlaneConfig =
                (VcnControlPlaneIkeConfig) mConnectionConfig.getControlPlaneConfig();
        return controlPlaneConfig.getChildSessionParams();
    }

    @VisibleForTesting(visibility = Visibility.PRIVATE)
    VcnIkeSession buildIkeSession() {
    VcnIkeSession buildIkeSession(@NonNull Network network) {
        final int token = ++mCurrentToken;

        return mDeps.newIkeSession(
                mVcnContext,
                buildIkeParams(),
                buildIkeParams(network),
                buildChildParams(),
                new IkeSessionCallbackImpl(token),
                new VcnChildSessionCallback(token));
+1 −1
Original line number Diff line number Diff line
@@ -73,7 +73,7 @@ public class VcnGatewayConnectionConnectedStateTest extends VcnGatewayConnection

        mGatewayConnection.setUnderlyingNetwork(TEST_UNDERLYING_NETWORK_RECORD_1);

        mIkeSession = mGatewayConnection.buildIkeSession();
        mIkeSession = mGatewayConnection.buildIkeSession(TEST_UNDERLYING_NETWORK_RECORD_1.network);
        mGatewayConnection.setIkeSession(mIkeSession);

        mGatewayConnection.transitionTo(mGatewayConnection.mConnectedState);
+9 −1
Original line number Diff line number Diff line
@@ -25,12 +25,15 @@ import static org.mockito.Matchers.any;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;

import android.net.ipsec.ike.IkeSessionParams;

import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;

/** Tests for VcnGatewayConnection.ConnectingState */
@RunWith(AndroidJUnit4.class)
@@ -51,7 +54,12 @@ public class VcnGatewayConnectionConnectingStateTest extends VcnGatewayConnectio

    @Test
    public void testEnterStateCreatesNewIkeSession() throws Exception {
        verify(mDeps).newIkeSession(any(), any(), any(), any(), any());
        final ArgumentCaptor<IkeSessionParams> paramsCaptor =
                ArgumentCaptor.forClass(IkeSessionParams.class);
        verify(mDeps).newIkeSession(any(), paramsCaptor.capture(), any(), any(), any());
        assertEquals(
                TEST_UNDERLYING_NETWORK_RECORD_1.network,
                paramsCaptor.getValue().getConfiguredNetwork());
    }

    @Test
+2 −1
Original line number Diff line number Diff line
@@ -38,7 +38,8 @@ public class VcnGatewayConnectionDisconnectingStateTest extends VcnGatewayConnec
    public void setUp() throws Exception {
        super.setUp();

        mGatewayConnection.setIkeSession(mGatewayConnection.buildIkeSession());
        mGatewayConnection.setIkeSession(
                mGatewayConnection.buildIkeSession(TEST_UNDERLYING_NETWORK_RECORD_2.network));

        // ensure that mGatewayConnection has an underlying Network before entering
        // DisconnectingState