Use TransformRecord to get SPI instead of SpiRecord
IpSecService.applyTunnelModeTransform() currently does not take an SpiRecord instance, yet implicitly requires that the SpiRecord instance is still alive based on the stored SpiRecord resourceId in the TransformRecord's IpSecConfig. This check is unnecessary, as the SpiRecord has been subsumed into the TransformRecord, and the kernel resources are kept alive whether or not the SpiRecord is still held by the user. This allows users of the IpSecManager API to allocate short-lived SPIs during the creation of an IpSecTransform, without having to keep track of both of them (even though the SPI is no longer usable). The TransformRecord.getSpiRecord() call is already used in multiple other places in the same method. Bug: 142072071 Test: New tests added, passing. Change-Id: I1959f3080946267243564459ff4207647922566e Merged-In: I1959f3080946267243564459ff4207647922566e (cherry picked from commit 5258b1b82f39bf17e0751bcb94479464250aaec5)
This commit is contained in:
@@ -571,6 +571,35 @@ public class IpSecServiceParameterizedTest {
|
|||||||
eq(TEST_SPI));
|
eq(TEST_SPI));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testApplyTransportModeTransformWithClosedSpi() throws Exception {
|
||||||
|
IpSecConfig ipSecConfig = new IpSecConfig();
|
||||||
|
addDefaultSpisAndRemoteAddrToIpSecConfig(ipSecConfig);
|
||||||
|
addAuthAndCryptToIpSecConfig(ipSecConfig);
|
||||||
|
|
||||||
|
IpSecTransformResponse createTransformResp =
|
||||||
|
mIpSecService.createTransform(ipSecConfig, new Binder(), "blessedPackage");
|
||||||
|
|
||||||
|
// Close SPI record
|
||||||
|
mIpSecService.releaseSecurityParameterIndex(ipSecConfig.getSpiResourceId());
|
||||||
|
|
||||||
|
Socket socket = new Socket();
|
||||||
|
socket.bind(null);
|
||||||
|
ParcelFileDescriptor pfd = ParcelFileDescriptor.fromSocket(socket);
|
||||||
|
|
||||||
|
int resourceId = createTransformResp.resourceId;
|
||||||
|
mIpSecService.applyTransportModeTransform(pfd, IpSecManager.DIRECTION_OUT, resourceId);
|
||||||
|
|
||||||
|
verify(mMockNetd)
|
||||||
|
.ipSecApplyTransportModeTransform(
|
||||||
|
eq(pfd),
|
||||||
|
eq(mUid),
|
||||||
|
eq(IpSecManager.DIRECTION_OUT),
|
||||||
|
anyString(),
|
||||||
|
anyString(),
|
||||||
|
eq(TEST_SPI));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRemoveTransportModeTransform() throws Exception {
|
public void testRemoveTransportModeTransform() throws Exception {
|
||||||
Socket socket = new Socket();
|
Socket socket = new Socket();
|
||||||
@@ -693,6 +722,45 @@ public class IpSecServiceParameterizedTest {
|
|||||||
verifyTransformNetdCalledForCreatingSA(ipSecConfig, createTransformResp);
|
verifyTransformNetdCalledForCreatingSA(ipSecConfig, createTransformResp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testApplyTunnelModeTransformWithClosedSpi() throws Exception {
|
||||||
|
IpSecConfig ipSecConfig = new IpSecConfig();
|
||||||
|
ipSecConfig.setMode(IpSecTransform.MODE_TUNNEL);
|
||||||
|
addDefaultSpisAndRemoteAddrToIpSecConfig(ipSecConfig);
|
||||||
|
addAuthAndCryptToIpSecConfig(ipSecConfig);
|
||||||
|
|
||||||
|
IpSecTransformResponse createTransformResp =
|
||||||
|
mIpSecService.createTransform(ipSecConfig, new Binder(), "blessedPackage");
|
||||||
|
IpSecTunnelInterfaceResponse createTunnelResp =
|
||||||
|
createAndValidateTunnel(mSourceAddr, mDestinationAddr, "blessedPackage");
|
||||||
|
|
||||||
|
// Close SPI record
|
||||||
|
mIpSecService.releaseSecurityParameterIndex(ipSecConfig.getSpiResourceId());
|
||||||
|
|
||||||
|
int transformResourceId = createTransformResp.resourceId;
|
||||||
|
int tunnelResourceId = createTunnelResp.resourceId;
|
||||||
|
mIpSecService.applyTunnelModeTransform(tunnelResourceId, IpSecManager.DIRECTION_OUT,
|
||||||
|
transformResourceId, "blessedPackage");
|
||||||
|
|
||||||
|
for (int selAddrFamily : ADDRESS_FAMILIES) {
|
||||||
|
verify(mMockNetd)
|
||||||
|
.ipSecUpdateSecurityPolicy(
|
||||||
|
eq(mUid),
|
||||||
|
eq(selAddrFamily),
|
||||||
|
eq(IpSecManager.DIRECTION_OUT),
|
||||||
|
anyString(),
|
||||||
|
anyString(),
|
||||||
|
eq(TEST_SPI),
|
||||||
|
anyInt(), // iKey/oKey
|
||||||
|
anyInt(), // mask
|
||||||
|
eq(tunnelResourceId));
|
||||||
|
}
|
||||||
|
|
||||||
|
ipSecConfig.setXfrmInterfaceId(tunnelResourceId);
|
||||||
|
verifyTransformNetdCalledForCreatingSA(ipSecConfig, createTransformResp);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddRemoveAddressFromTunnelInterface() throws Exception {
|
public void testAddRemoveAddressFromTunnelInterface() throws Exception {
|
||||||
for (String pkgName : new String[]{"blessedPackage", "systemPackage"}) {
|
for (String pkgName : new String[]{"blessedPackage", "systemPackage"}) {
|
||||||
|
|||||||
Reference in New Issue
Block a user