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);
}
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());
}
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);
}
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);
}
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();
}
Aggregations