Search in sources :

Example 21 with AccumuloConfiguration

use of org.apache.accumulo.core.conf.AccumuloConfiguration in project accumulo by apache.

the class CryptoTest method testKeyEncryptionNormalPath.

@Test
public void testKeyEncryptionNormalPath() throws IOException {
    AccumuloConfiguration conf = setAndGetAccumuloConfig(CRYPTO_ON_CONF);
    CryptoModule cryptoModule = CryptoModuleFactory.getCryptoModule(conf);
    CryptoModuleParameters params = CryptoModuleFactory.createParamsObjectFromAccumuloConfiguration(conf);
    assertTrue(cryptoModule instanceof DefaultCryptoModule);
    assertNotNull(params.getKeyEncryptionStrategyClass());
    assertEquals("org.apache.accumulo.core.security.crypto.CachingHDFSSecretKeyEncryptionStrategy", params.getKeyEncryptionStrategyClass());
    byte[] resultingBytes = setUpSampleEncryptedBytes(cryptoModule, params);
    params = CryptoModuleFactory.createParamsObjectFromAccumuloConfiguration(conf);
    params.setOverrideStreamsSecretKeyEncryptionStrategy(true);
    ByteArrayInputStream in = new ByteArrayInputStream(resultingBytes);
    params.setEncryptedInputStream(in);
    params = cryptoModule.getDecryptingInputStream(params);
    assertNotNull(params.getPlaintextInputStream());
    DataInputStream dataIn = new DataInputStream(params.getPlaintextInputStream());
    String markerString = dataIn.readUTF();
    int markerInt = dataIn.readInt();
    assertEquals(MARKER_STRING, markerString);
    assertEquals(MARKER_INT, markerInt);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataInputStream(java.io.DataInputStream) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration) Test(org.junit.Test)

Example 22 with AccumuloConfiguration

use of org.apache.accumulo.core.conf.AccumuloConfiguration in project accumulo by apache.

the class CryptoTest method testNoCryptoStream.

@Test
public void testNoCryptoStream() throws IOException {
    AccumuloConfiguration conf = setAndGetAccumuloConfig(CRYPTO_OFF_CONF);
    CryptoModuleParameters params = CryptoModuleFactory.createParamsObjectFromAccumuloConfiguration(conf);
    assertNotNull(params);
    assertEquals("NullCipher", params.getCipherSuite());
    CryptoModule cryptoModule = CryptoModuleFactory.getCryptoModule(conf);
    assertNotNull(cryptoModule);
    assertTrue(cryptoModule instanceof CryptoModuleFactory.NullCryptoModule);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    params.setPlaintextOutputStream(out);
    params = cryptoModule.getEncryptingOutputStream(params);
    assertNotNull(params.getEncryptedOutputStream());
    assertEquals(out, params.getEncryptedOutputStream());
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration) Test(org.junit.Test)

Example 23 with AccumuloConfiguration

use of org.apache.accumulo.core.conf.AccumuloConfiguration in project accumulo by apache.

the class CryptoTest method testCryptoModuleParamsValidation1.

@Test
public void testCryptoModuleParamsValidation1() throws IOException {
    AccumuloConfiguration conf = setAndGetAccumuloConfig(CRYPTO_ON_CONF);
    CryptoModuleParameters params = CryptoModuleFactory.createParamsObjectFromAccumuloConfiguration(conf);
    CryptoModule cryptoModule = CryptoModuleFactory.getCryptoModule(conf);
    assertTrue(cryptoModule instanceof DefaultCryptoModule);
    exception.expect(RuntimeException.class);
    cryptoModule.getEncryptingOutputStream(params);
}
Also used : AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration) Test(org.junit.Test)

Example 24 with AccumuloConfiguration

use of org.apache.accumulo.core.conf.AccumuloConfiguration in project accumulo by apache.

the class CryptoTest method testCryptoModuleBasicReadWrite.

@Test
public void testCryptoModuleBasicReadWrite() throws IOException {
    AccumuloConfiguration conf = setAndGetAccumuloConfig(CRYPTO_ON_KEK_OFF_CONF);
    CryptoModule cryptoModule = CryptoModuleFactory.getCryptoModule(conf);
    CryptoModuleParameters params = CryptoModuleFactory.createParamsObjectFromAccumuloConfiguration(conf);
    assertTrue(cryptoModule instanceof DefaultCryptoModule);
    byte[] resultingBytes = setUpSampleEncryptedBytes(cryptoModule, params);
    // If we get here, we have encrypted bytes
    ByteArrayInputStream in = new ByteArrayInputStream(resultingBytes);
    params = CryptoModuleFactory.createParamsObjectFromAccumuloConfiguration(conf);
    params.setEncryptedInputStream(in);
    params = cryptoModule.getDecryptingInputStream(params);
    InputStream plaintextIn = params.getPlaintextInputStream();
    assertNotNull(plaintextIn);
    assertNotSame(plaintextIn, in);
    DataInputStream dataIn = new DataInputStream(plaintextIn);
    String markerString = dataIn.readUTF();
    int markerInt = dataIn.readInt();
    assertEquals(MARKER_STRING, markerString);
    assertEquals(MARKER_INT, markerInt);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataInputStream(java.io.DataInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DataInputStream(java.io.DataInputStream) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration) Test(org.junit.Test)

Example 25 with AccumuloConfiguration

use of org.apache.accumulo.core.conf.AccumuloConfiguration in project accumulo by apache.

the class CryptoTest method testKeyEncryptionAndCheckThatFileCannotBeReadWithoutKEK.

@Test
public void testKeyEncryptionAndCheckThatFileCannotBeReadWithoutKEK() throws IOException {
    AccumuloConfiguration conf = setAndGetAccumuloConfig(CRYPTO_ON_CONF);
    CryptoModule cryptoModule = CryptoModuleFactory.getCryptoModule(conf);
    CryptoModuleParameters params = CryptoModuleFactory.createParamsObjectFromAccumuloConfiguration(conf);
    // CRYPTO_ON_CONF uses AESWrap which produces wrapped keys that are too large and require a change to
    // JCE Unlimited Strength Jurisdiction. Using AES/ECB/NoPadding should avoid this problem.
    params.getAllOptions().put(Property.CRYPTO_DEFAULT_KEY_STRATEGY_CIPHER_SUITE.getKey(), "AES/ECB/NoPadding");
    assertTrue(cryptoModule instanceof DefaultCryptoModule);
    assertNotNull(params.getKeyEncryptionStrategyClass());
    assertEquals("org.apache.accumulo.core.security.crypto.CachingHDFSSecretKeyEncryptionStrategy", params.getKeyEncryptionStrategyClass());
    byte[] resultingBytes = setUpSampleEncryptedBytes(cryptoModule, params);
    // So now that we have bytes encrypted by a key encrypted to a KEK, turn off the KEK configuration and try
    // to decrypt. We expect this to fail. This also tests our ability to override the key encryption strategy.
    conf = setAndGetAccumuloConfig(CRYPTO_ON_KEK_OFF_CONF);
    params = CryptoModuleFactory.createParamsObjectFromAccumuloConfiguration(conf);
    params.setOverrideStreamsSecretKeyEncryptionStrategy(true);
    ByteArrayInputStream in = new ByteArrayInputStream(resultingBytes);
    params.setEncryptedInputStream(in);
    params = cryptoModule.getDecryptingInputStream(params);
    assertNotNull(params.getPlaintextInputStream());
    DataInputStream dataIn = new DataInputStream(params.getPlaintextInputStream());
    // We expect the following operation to fail and throw an exception
    exception.expect(IOException.class);
    @SuppressWarnings("unused") String markerString = dataIn.readUTF();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataInputStream(java.io.DataInputStream) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration) Test(org.junit.Test)

Aggregations

AccumuloConfiguration (org.apache.accumulo.core.conf.AccumuloConfiguration)117 Test (org.junit.Test)44 Path (org.apache.hadoop.fs.Path)26 ConfigurationCopy (org.apache.accumulo.core.conf.ConfigurationCopy)25 IOException (java.io.IOException)23 Configuration (org.apache.hadoop.conf.Configuration)19 HashMap (java.util.HashMap)17 ClientConfiguration (org.apache.accumulo.core.client.ClientConfiguration)13 Key (org.apache.accumulo.core.data.Key)13 DefaultConfiguration (org.apache.accumulo.core.conf.DefaultConfiguration)12 Property (org.apache.accumulo.core.conf.Property)12 Value (org.apache.accumulo.core.data.Value)12 ByteArrayInputStream (java.io.ByteArrayInputStream)11 DataInputStream (java.io.DataInputStream)11 FileSystem (org.apache.hadoop.fs.FileSystem)11 ArrayList (java.util.ArrayList)10 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)9 Text (org.apache.hadoop.io.Text)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 AccumuloException (org.apache.accumulo.core.client.AccumuloException)8