Search in sources :

Example 1 with AESCryptoService

use of org.apache.accumulo.core.spi.crypto.AESCryptoService in project accumulo by apache.

the class CryptoTest method simpleGCMTest.

@Test
public void simpleGCMTest() throws Exception {
    AccumuloConfiguration conf = getAccumuloConfig(ConfigMode.CRYPTO_ON);
    CryptoService cs = new AESCryptoService();
    cs.init(conf.getAllPropertiesWithPrefix(Property.INSTANCE_CRYPTO_PREFIX));
    CryptoEnvironment encEnv = new CryptoEnvironmentImpl(Scope.RFILE, null);
    FileEncrypter encrypter = cs.getFileEncrypter(encEnv);
    byte[] params = encrypter.getDecryptionParameters();
    assertNotNull(params);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    DataOutputStream dataOut = new DataOutputStream(out);
    CryptoUtils.writeParams(params, dataOut);
    OutputStream encrypted = encrypter.encryptStream(dataOut);
    assertNotNull(encrypted);
    DataOutputStream cipherOut = new DataOutputStream(encrypted);
    cipherOut.writeUTF(MARKER_STRING);
    cipherOut.close();
    dataOut.close();
    encrypted.close();
    out.close();
    byte[] cipherText = out.toByteArray();
    // decrypt
    ByteArrayInputStream in = new ByteArrayInputStream(cipherText);
    FileDecrypter decrypter = getFileDecrypter(cs, Scope.RFILE, new DataInputStream(in));
    DataInputStream decrypted = new DataInputStream(decrypter.decryptStream(in));
    String plainText = decrypted.readUTF();
    decrypted.close();
    in.close();
    assertEquals(MARKER_STRING, new String(plainText));
}
Also used : CryptoEnvironment(org.apache.accumulo.core.spi.crypto.CryptoEnvironment) DataOutputStream(java.io.DataOutputStream) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) CryptoUtils.getFileDecrypter(org.apache.accumulo.core.crypto.CryptoUtils.getFileDecrypter) FileDecrypter(org.apache.accumulo.core.spi.crypto.FileDecrypter) DataOutputStream(java.io.DataOutputStream) NoFlushOutputStream(org.apache.accumulo.core.crypto.streams.NoFlushOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) FileEncrypter(org.apache.accumulo.core.spi.crypto.FileEncrypter) AESCryptoService(org.apache.accumulo.core.spi.crypto.AESCryptoService) AESCryptoService(org.apache.accumulo.core.spi.crypto.AESCryptoService) CryptoService(org.apache.accumulo.core.spi.crypto.CryptoService) ByteArrayInputStream(java.io.ByteArrayInputStream) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration) Test(org.junit.jupiter.api.Test)

Example 2 with AESCryptoService

use of org.apache.accumulo.core.spi.crypto.AESCryptoService in project accumulo by apache.

the class CryptoTest method testAESCryptoServiceWALDisabled.

/**
 * AESCryptoService is configured but only for reading
 */
@Test
public void testAESCryptoServiceWALDisabled() throws Exception {
    AESCryptoService cs = new AESCryptoService();
    // make sure we can read encrypted
    byte[] encryptedBytes = encrypt(cs, Scope.WAL, ConfigMode.CRYPTO_ON);
    String stringEncryptedBytes = Arrays.toString(encryptedBytes);
    String stringifiedMarkerBytes = getStringifiedBytes(null, MARKER_STRING, MARKER_INT);
    assertNotEquals(stringEncryptedBytes, stringifiedMarkerBytes);
    decrypt(encryptedBytes, Scope.WAL, ConfigMode.CRYPTO_ON_DISABLED);
    // make sure we don't encrypt when disabled
    byte[] plainBytes = encrypt(cs, Scope.WAL, ConfigMode.CRYPTO_ON_DISABLED);
    String stringPlainBytes = Arrays.toString(plainBytes);
    assertNotEquals(stringEncryptedBytes, stringPlainBytes);
    decrypt(plainBytes, Scope.WAL, ConfigMode.CRYPTO_ON_DISABLED);
}
Also used : AESCryptoService(org.apache.accumulo.core.spi.crypto.AESCryptoService) Test(org.junit.jupiter.api.Test)

Example 3 with AESCryptoService

use of org.apache.accumulo.core.spi.crypto.AESCryptoService in project accumulo by apache.

the class CryptoTest method testAESCryptoServiceRFILEDisabled.

/**
 * AESCryptoService is configured but only for reading
 */
@Test
public void testAESCryptoServiceRFILEDisabled() throws Exception {
    AESCryptoService cs = new AESCryptoService();
    // make sure we can read encrypted
    byte[] encryptedBytes = encrypt(cs, Scope.RFILE, ConfigMode.CRYPTO_ON);
    String stringEncryptedBytes = Arrays.toString(encryptedBytes);
    String stringifiedMarkerBytes = getStringifiedBytes(null, MARKER_STRING, MARKER_INT);
    assertNotEquals(stringEncryptedBytes, stringifiedMarkerBytes);
    decrypt(encryptedBytes, Scope.RFILE, ConfigMode.CRYPTO_ON_DISABLED);
    // make sure we don't encrypt when disabled
    byte[] plainBytes = encrypt(cs, Scope.RFILE, ConfigMode.CRYPTO_ON_DISABLED);
    String stringPlainBytes = Arrays.toString(plainBytes);
    assertNotEquals(stringEncryptedBytes, stringPlainBytes);
    decrypt(plainBytes, Scope.RFILE, ConfigMode.CRYPTO_ON_DISABLED);
}
Also used : AESCryptoService(org.apache.accumulo.core.spi.crypto.AESCryptoService) Test(org.junit.jupiter.api.Test)

Example 4 with AESCryptoService

use of org.apache.accumulo.core.spi.crypto.AESCryptoService in project accumulo by apache.

the class CryptoTest method testAESCryptoServiceRFILE.

@Test
public void testAESCryptoServiceRFILE() throws Exception {
    AESCryptoService cs = new AESCryptoService();
    byte[] resultingBytes = encrypt(cs, Scope.RFILE, ConfigMode.CRYPTO_ON);
    String stringifiedBytes = Arrays.toString(resultingBytes);
    String stringifiedMarkerBytes = getStringifiedBytes(null, MARKER_STRING, MARKER_INT);
    assertNotEquals(stringifiedBytes, stringifiedMarkerBytes);
    decrypt(resultingBytes, Scope.RFILE, ConfigMode.CRYPTO_ON);
}
Also used : AESCryptoService(org.apache.accumulo.core.spi.crypto.AESCryptoService) Test(org.junit.jupiter.api.Test)

Example 5 with AESCryptoService

use of org.apache.accumulo.core.spi.crypto.AESCryptoService in project accumulo by apache.

the class CryptoTest method testAESCryptoServiceWAL.

@Test
public void testAESCryptoServiceWAL() throws Exception {
    AESCryptoService cs = new AESCryptoService();
    byte[] resultingBytes = encrypt(cs, Scope.WAL, ConfigMode.CRYPTO_ON);
    String stringifiedBytes = Arrays.toString(resultingBytes);
    String stringifiedMarkerBytes = getStringifiedBytes(null, MARKER_STRING, MARKER_INT);
    assertNotEquals(stringifiedBytes, stringifiedMarkerBytes);
    decrypt(resultingBytes, Scope.WAL, ConfigMode.CRYPTO_ON);
}
Also used : AESCryptoService(org.apache.accumulo.core.spi.crypto.AESCryptoService) Test(org.junit.jupiter.api.Test)

Aggregations

AESCryptoService (org.apache.accumulo.core.spi.crypto.AESCryptoService)5 Test (org.junit.jupiter.api.Test)5 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 OutputStream (java.io.OutputStream)1 AccumuloConfiguration (org.apache.accumulo.core.conf.AccumuloConfiguration)1 CryptoUtils.getFileDecrypter (org.apache.accumulo.core.crypto.CryptoUtils.getFileDecrypter)1 NoFlushOutputStream (org.apache.accumulo.core.crypto.streams.NoFlushOutputStream)1 CryptoEnvironment (org.apache.accumulo.core.spi.crypto.CryptoEnvironment)1 CryptoService (org.apache.accumulo.core.spi.crypto.CryptoService)1 FileDecrypter (org.apache.accumulo.core.spi.crypto.FileDecrypter)1 FileEncrypter (org.apache.accumulo.core.spi.crypto.FileEncrypter)1 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)1