|
@@ -18,6 +18,7 @@
|
|
|
package org.apache.hadoop.hdfs;
|
|
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
+import static org.junit.Assert.assertFalse;
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
import static org.junit.Assert.fail;
|
|
|
|
|
@@ -133,12 +134,12 @@ public class TestEncryptedTransfer {
|
|
|
|
|
|
fs.close();
|
|
|
|
|
|
- if (resolverClazz != null && !resolverClazz.endsWith("TestTrustedChannelResolver")){
|
|
|
+ if (resolverClazz == null) {
|
|
|
// Test client and server negotiate cipher option
|
|
|
- GenericTestUtils.assertMatches(logs.getOutput(),
|
|
|
+ GenericTestUtils.assertDoesNotMatch(logs.getOutput(),
|
|
|
"Server using cipher suite");
|
|
|
// Check the IOStreamPair
|
|
|
- GenericTestUtils.assertMatches(logs1.getOutput(),
|
|
|
+ GenericTestUtils.assertDoesNotMatch(logs1.getOutput(),
|
|
|
"Creating IOStreamPair of CryptoInputStream and CryptoOutputStream.");
|
|
|
}
|
|
|
} finally {
|
|
@@ -174,9 +175,28 @@ public class TestEncryptedTransfer {
|
|
|
.build();
|
|
|
|
|
|
fs = getFileSystem(conf);
|
|
|
- assertEquals(PLAIN_TEXT, DFSTestUtil.readFile(fs, TEST_PATH));
|
|
|
- assertEquals(checksum, fs.getFileChecksum(TEST_PATH));
|
|
|
+ LogCapturer logs = GenericTestUtils.LogCapturer.captureLogs(
|
|
|
+ LogFactory.getLog(SaslDataTransferServer.class));
|
|
|
+ LogCapturer logs1 = GenericTestUtils.LogCapturer.captureLogs(
|
|
|
+ LogFactory.getLog(DataTransferSaslUtil.class));
|
|
|
+ try {
|
|
|
+ assertEquals(PLAIN_TEXT, DFSTestUtil.readFile(fs, TEST_PATH));
|
|
|
+ assertEquals(checksum, fs.getFileChecksum(TEST_PATH));
|
|
|
+ } finally {
|
|
|
+ logs.stopCapturing();
|
|
|
+ logs1.stopCapturing();
|
|
|
+ }
|
|
|
+
|
|
|
fs.close();
|
|
|
+
|
|
|
+ if (resolverClazz == null) {
|
|
|
+ // Test client and server negotiate cipher option
|
|
|
+ GenericTestUtils.assertDoesNotMatch(logs.getOutput(),
|
|
|
+ "Server using cipher suite");
|
|
|
+ // Check the IOStreamPair
|
|
|
+ GenericTestUtils.assertDoesNotMatch(logs1.getOutput(),
|
|
|
+ "Creating IOStreamPair of CryptoInputStream and CryptoOutputStream.");
|
|
|
+ }
|
|
|
} finally {
|
|
|
if (cluster != null) {
|
|
|
cluster.shutdown();
|
|
@@ -184,6 +204,61 @@ public class TestEncryptedTransfer {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testEncryptedReadWithAES() throws IOException {
|
|
|
+ MiniDFSCluster cluster = null;
|
|
|
+ try {
|
|
|
+ Configuration conf = new Configuration();
|
|
|
+ conf.set(DFSConfigKeys.DFS_ENCRYPT_DATA_TRANSFER_CIPHER_SUITES_KEY,
|
|
|
+ "AES/CTR/NoPadding");
|
|
|
+ cluster = new MiniDFSCluster.Builder(conf).build();
|
|
|
+
|
|
|
+ FileSystem fs = getFileSystem(conf);
|
|
|
+ writeTestDataToFile(fs);
|
|
|
+ assertEquals(PLAIN_TEXT, DFSTestUtil.readFile(fs, TEST_PATH));
|
|
|
+ FileChecksum checksum = fs.getFileChecksum(TEST_PATH);
|
|
|
+ fs.close();
|
|
|
+ cluster.shutdown();
|
|
|
+
|
|
|
+ setEncryptionConfigKeys(conf);
|
|
|
+
|
|
|
+ cluster = new MiniDFSCluster.Builder(conf)
|
|
|
+ .manageDataDfsDirs(false)
|
|
|
+ .manageNameDfsDirs(false)
|
|
|
+ .format(false)
|
|
|
+ .startupOption(StartupOption.REGULAR)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ fs = getFileSystem(conf);
|
|
|
+ LogCapturer logs = GenericTestUtils.LogCapturer.captureLogs(
|
|
|
+ LogFactory.getLog(SaslDataTransferServer.class));
|
|
|
+ LogCapturer logs1 = GenericTestUtils.LogCapturer.captureLogs(
|
|
|
+ LogFactory.getLog(DataTransferSaslUtil.class));
|
|
|
+ try {
|
|
|
+ assertEquals(PLAIN_TEXT, DFSTestUtil.readFile(fs, TEST_PATH));
|
|
|
+ assertEquals(checksum, fs.getFileChecksum(TEST_PATH));
|
|
|
+ } finally {
|
|
|
+ logs.stopCapturing();
|
|
|
+ logs1.stopCapturing();
|
|
|
+ }
|
|
|
+
|
|
|
+ fs.close();
|
|
|
+
|
|
|
+ if (resolverClazz == null) {
|
|
|
+ // Test client and server negotiate cipher option
|
|
|
+ GenericTestUtils.assertMatches(logs.getOutput(),
|
|
|
+ "Server using cipher suite");
|
|
|
+ // Check the IOStreamPair
|
|
|
+ GenericTestUtils.assertMatches(logs1.getOutput(),
|
|
|
+ "Creating IOStreamPair of CryptoInputStream and CryptoOutputStream.");
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ if (cluster != null) {
|
|
|
+ cluster.shutdown();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
public void testEncryptedReadAfterNameNodeRestart() throws IOException {
|
|
|
MiniDFSCluster cluster = null;
|
|
@@ -270,7 +345,7 @@ public class TestEncryptedTransfer {
|
|
|
}
|
|
|
fs.close();
|
|
|
|
|
|
- if (resolverClazz != null && !resolverClazz.endsWith("TestTrustedChannelResolver")){
|
|
|
+ if (resolverClazz == null) {
|
|
|
GenericTestUtils.assertMatches(logs.getOutput(),
|
|
|
"Failed to read expected encryption handshake from client at");
|
|
|
}
|
|
@@ -444,12 +519,12 @@ public class TestEncryptedTransfer {
|
|
|
assertEquals(PLAIN_TEXT, DFSTestUtil.readFile(fs, TEST_PATH));
|
|
|
fs.close();
|
|
|
|
|
|
- if (resolverClazz != null && !resolverClazz.endsWith("TestTrustedChannelResolver")){
|
|
|
+ if (resolverClazz == null) {
|
|
|
// Test client and server negotiate cipher option
|
|
|
- GenericTestUtils.assertMatches(logs.getOutput(),
|
|
|
+ GenericTestUtils.assertDoesNotMatch(logs.getOutput(),
|
|
|
"Server using cipher suite");
|
|
|
// Check the IOStreamPair
|
|
|
- GenericTestUtils.assertMatches(logs1.getOutput(),
|
|
|
+ GenericTestUtils.assertDoesNotMatch(logs1.getOutput(),
|
|
|
"Creating IOStreamPair of CryptoInputStream and CryptoOutputStream.");
|
|
|
}
|
|
|
} finally {
|