Merge changes from topic "ipsec-oneway-transform"

am: 60a21328d5

Change-Id: If98285e2bd41e2eedaf81f1ff0e5f2b2d3827f91
This commit is contained in:
nharold
2018-01-17 09:42:03 +00:00
committed by android-build-merger
2 changed files with 58 additions and 66 deletions

View File

@@ -56,10 +56,11 @@ public class IpSecServiceParameterizedTest {
private static final int TEST_SPI = 0xD1201D; private static final int TEST_SPI = 0xD1201D;
private final String mDestinationAddr; private final String mDestinationAddr;
private final String mSourceAddr;
@Parameterized.Parameters @Parameterized.Parameters
public static Collection ipSecConfigs() { public static Collection ipSecConfigs() {
return Arrays.asList(new Object[][] {{"8.8.4.4"}, {"2601::10"}}); return Arrays.asList(new Object[][] {{"1.2.3.4", "8.8.4.4"}, {"2601::2", "2601::10"}});
} }
private static final byte[] AEAD_KEY = { private static final byte[] AEAD_KEY = {
@@ -94,8 +95,9 @@ public class IpSecServiceParameterizedTest {
private static final IpSecAlgorithm AEAD_ALGO = private static final IpSecAlgorithm AEAD_ALGO =
new IpSecAlgorithm(IpSecAlgorithm.AUTH_CRYPT_AES_GCM, AEAD_KEY, 128); new IpSecAlgorithm(IpSecAlgorithm.AUTH_CRYPT_AES_GCM, AEAD_KEY, 128);
public IpSecServiceParameterizedTest(String remoteAddr) { public IpSecServiceParameterizedTest(String sourceAddr, String destAddr) {
mDestinationAddr = remoteAddr; mSourceAddr = sourceAddr;
mDestinationAddr = destAddr;
} }
@Before @Before
@@ -192,6 +194,7 @@ public class IpSecServiceParameterizedTest {
private void addDefaultSpisAndRemoteAddrToIpSecConfig(IpSecConfig config) throws Exception { private void addDefaultSpisAndRemoteAddrToIpSecConfig(IpSecConfig config) throws Exception {
config.setSpiResourceId(getNewSpiResourceId(mDestinationAddr, TEST_SPI)); config.setSpiResourceId(getNewSpiResourceId(mDestinationAddr, TEST_SPI));
config.setSourceAddress(mSourceAddr);
config.setDestinationAddress(mDestinationAddr); config.setDestinationAddress(mDestinationAddr);
} }

View File

@@ -105,9 +105,6 @@ public class IpSecServiceTest {
private static final IpSecAlgorithm AEAD_ALGO = private static final IpSecAlgorithm AEAD_ALGO =
new IpSecAlgorithm(IpSecAlgorithm.AUTH_CRYPT_AES_GCM, AEAD_KEY, 128); new IpSecAlgorithm(IpSecAlgorithm.AUTH_CRYPT_AES_GCM, AEAD_KEY, 128);
private static final int[] DIRECTIONS =
new int[] {IpSecTransform.DIRECTION_IN, IpSecTransform.DIRECTION_OUT};
static { static {
try { try {
INADDR_ANY = InetAddress.getByAddress(new byte[] {0, 0, 0, 0}); INADDR_ANY = InetAddress.getByAddress(new byte[] {0, 0, 0, 0});
@@ -303,83 +300,75 @@ public class IpSecServiceTest {
@Test @Test
public void testValidateAlgorithmsAuth() { public void testValidateAlgorithmsAuth() {
for (int direction : DIRECTIONS) { // Validate that correct algorithm type succeeds
// Validate that correct algorithm type succeeds IpSecConfig config = new IpSecConfig();
IpSecConfig config = new IpSecConfig(); config.setAuthentication(AUTH_ALGO);
config.setAuthentication(direction, AUTH_ALGO); mIpSecService.validateAlgorithms(config);
mIpSecService.validateAlgorithms(config, direction);
// Validate that incorrect algorithm types fails // Validate that incorrect algorithm types fails
for (IpSecAlgorithm algo : new IpSecAlgorithm[] {CRYPT_ALGO, AEAD_ALGO}) { for (IpSecAlgorithm algo : new IpSecAlgorithm[] {CRYPT_ALGO, AEAD_ALGO}) {
try { try {
config = new IpSecConfig(); config = new IpSecConfig();
config.setAuthentication(direction, algo); config.setAuthentication(algo);
mIpSecService.validateAlgorithms(config, direction); mIpSecService.validateAlgorithms(config);
fail("Did not throw exception on invalid algorithm type"); fail("Did not throw exception on invalid algorithm type");
} catch (IllegalArgumentException expected) { } catch (IllegalArgumentException expected) {
}
} }
} }
} }
@Test @Test
public void testValidateAlgorithmsCrypt() { public void testValidateAlgorithmsCrypt() {
for (int direction : DIRECTIONS) { // Validate that correct algorithm type succeeds
// Validate that correct algorithm type succeeds IpSecConfig config = new IpSecConfig();
IpSecConfig config = new IpSecConfig(); config.setEncryption(CRYPT_ALGO);
config.setEncryption(direction, CRYPT_ALGO); mIpSecService.validateAlgorithms(config);
mIpSecService.validateAlgorithms(config, direction);
// Validate that incorrect algorithm types fails // Validate that incorrect algorithm types fails
for (IpSecAlgorithm algo : new IpSecAlgorithm[] {AUTH_ALGO, AEAD_ALGO}) { for (IpSecAlgorithm algo : new IpSecAlgorithm[] {AUTH_ALGO, AEAD_ALGO}) {
try { try {
config = new IpSecConfig(); config = new IpSecConfig();
config.setEncryption(direction, algo); config.setEncryption(algo);
mIpSecService.validateAlgorithms(config, direction); mIpSecService.validateAlgorithms(config);
fail("Did not throw exception on invalid algorithm type"); fail("Did not throw exception on invalid algorithm type");
} catch (IllegalArgumentException expected) { } catch (IllegalArgumentException expected) {
}
} }
} }
} }
@Test @Test
public void testValidateAlgorithmsAead() { public void testValidateAlgorithmsAead() {
for (int direction : DIRECTIONS) { // Validate that correct algorithm type succeeds
// Validate that correct algorithm type succeeds IpSecConfig config = new IpSecConfig();
IpSecConfig config = new IpSecConfig(); config.setAuthenticatedEncryption(AEAD_ALGO);
config.setAuthenticatedEncryption(direction, AEAD_ALGO); mIpSecService.validateAlgorithms(config);
mIpSecService.validateAlgorithms(config, direction);
// Validate that incorrect algorithm types fails // Validate that incorrect algorithm types fails
for (IpSecAlgorithm algo : new IpSecAlgorithm[] {AUTH_ALGO, CRYPT_ALGO}) { for (IpSecAlgorithm algo : new IpSecAlgorithm[] {AUTH_ALGO, CRYPT_ALGO}) {
try { try {
config = new IpSecConfig(); config = new IpSecConfig();
config.setAuthenticatedEncryption(direction, algo); config.setAuthenticatedEncryption(algo);
mIpSecService.validateAlgorithms(config, direction); mIpSecService.validateAlgorithms(config);
fail("Did not throw exception on invalid algorithm type"); fail("Did not throw exception on invalid algorithm type");
} catch (IllegalArgumentException expected) { } catch (IllegalArgumentException expected) {
}
} }
} }
} }
@Test @Test
public void testValidateAlgorithmsAuthCrypt() { public void testValidateAlgorithmsAuthCrypt() {
for (int direction : DIRECTIONS) { // Validate that correct algorithm type succeeds
// Validate that correct algorithm type succeeds IpSecConfig config = new IpSecConfig();
IpSecConfig config = new IpSecConfig(); config.setAuthentication(AUTH_ALGO);
config.setAuthentication(direction, AUTH_ALGO); config.setEncryption(CRYPT_ALGO);
config.setEncryption(direction, CRYPT_ALGO); mIpSecService.validateAlgorithms(config);
mIpSecService.validateAlgorithms(config, direction);
}
} }
@Test @Test
public void testValidateAlgorithmsNoAlgorithms() { public void testValidateAlgorithmsNoAlgorithms() {
IpSecConfig config = new IpSecConfig(); IpSecConfig config = new IpSecConfig();
try { try {
mIpSecService.validateAlgorithms(config, IpSecTransform.DIRECTION_IN); mIpSecService.validateAlgorithms(config);
fail("Expected exception; no algorithms specified"); fail("Expected exception; no algorithms specified");
} catch (IllegalArgumentException expected) { } catch (IllegalArgumentException expected) {
} }
@@ -388,10 +377,10 @@ public class IpSecServiceTest {
@Test @Test
public void testValidateAlgorithmsAeadWithAuth() { public void testValidateAlgorithmsAeadWithAuth() {
IpSecConfig config = new IpSecConfig(); IpSecConfig config = new IpSecConfig();
config.setAuthenticatedEncryption(IpSecTransform.DIRECTION_IN, AEAD_ALGO); config.setAuthenticatedEncryption(AEAD_ALGO);
config.setAuthentication(IpSecTransform.DIRECTION_IN, AUTH_ALGO); config.setAuthentication(AUTH_ALGO);
try { try {
mIpSecService.validateAlgorithms(config, IpSecTransform.DIRECTION_IN); mIpSecService.validateAlgorithms(config);
fail("Expected exception; both AEAD and auth algorithm specified"); fail("Expected exception; both AEAD and auth algorithm specified");
} catch (IllegalArgumentException expected) { } catch (IllegalArgumentException expected) {
} }
@@ -400,10 +389,10 @@ public class IpSecServiceTest {
@Test @Test
public void testValidateAlgorithmsAeadWithCrypt() { public void testValidateAlgorithmsAeadWithCrypt() {
IpSecConfig config = new IpSecConfig(); IpSecConfig config = new IpSecConfig();
config.setAuthenticatedEncryption(IpSecTransform.DIRECTION_IN, AEAD_ALGO); config.setAuthenticatedEncryption(AEAD_ALGO);
config.setEncryption(IpSecTransform.DIRECTION_IN, CRYPT_ALGO); config.setEncryption(CRYPT_ALGO);
try { try {
mIpSecService.validateAlgorithms(config, IpSecTransform.DIRECTION_IN); mIpSecService.validateAlgorithms(config);
fail("Expected exception; both AEAD and crypt algorithm specified"); fail("Expected exception; both AEAD and crypt algorithm specified");
} catch (IllegalArgumentException expected) { } catch (IllegalArgumentException expected) {
} }
@@ -412,11 +401,11 @@ public class IpSecServiceTest {
@Test @Test
public void testValidateAlgorithmsAeadWithAuthAndCrypt() { public void testValidateAlgorithmsAeadWithAuthAndCrypt() {
IpSecConfig config = new IpSecConfig(); IpSecConfig config = new IpSecConfig();
config.setAuthenticatedEncryption(IpSecTransform.DIRECTION_IN, AEAD_ALGO); config.setAuthenticatedEncryption(AEAD_ALGO);
config.setAuthentication(IpSecTransform.DIRECTION_IN, AUTH_ALGO); config.setAuthentication(AUTH_ALGO);
config.setEncryption(IpSecTransform.DIRECTION_IN, CRYPT_ALGO); config.setEncryption(CRYPT_ALGO);
try { try {
mIpSecService.validateAlgorithms(config, IpSecTransform.DIRECTION_IN); mIpSecService.validateAlgorithms(config);
fail("Expected exception; AEAD, auth and crypt algorithm specified"); fail("Expected exception; AEAD, auth and crypt algorithm specified");
} catch (IllegalArgumentException expected) { } catch (IllegalArgumentException expected) {
} }