use of org.apache.ignite.spi.encryption.keystore.KeystoreEncryptionKey in project ignite by apache.
the class KeystoreEncryptionSpiSelfTest method testKeyEncryptDecrypt.
/**
* @throws Exception If failed.
*/
@Test
public void testKeyEncryptDecrypt() throws Exception {
EncryptionSpi encSpi = spi();
KeystoreEncryptionKey k = (KeystoreEncryptionKey) encSpi.create();
assertNotNull(k);
assertNotNull(k.key());
checkKeyEncryptDecrypt(encSpi, k);
encSpi.setMasterKeyName(MASTER_KEY_NAME_2);
checkKeyEncryptDecrypt(encSpi, k);
}
use of org.apache.ignite.spi.encryption.keystore.KeystoreEncryptionKey in project ignite by apache.
the class KeystoreEncryptionSpiSelfTest method testEncryptDecrypt.
/**
* @throws Exception If failed.
*/
@Test
public void testEncryptDecrypt() throws Exception {
EncryptionSpi encSpi = spi();
KeystoreEncryptionKey k = (KeystoreEncryptionKey) encSpi.create();
assertNotNull(k);
assertNotNull(k.key());
byte[] plainText = "Just a test string to encrypt!".getBytes(UTF_8);
byte[] cipherText = new byte[spi().encryptedSize(plainText.length)];
encSpi.encrypt(ByteBuffer.wrap(plainText), k, ByteBuffer.wrap(cipherText));
assertNotNull(cipherText);
assertEquals(encSpi.encryptedSize(plainText.length), cipherText.length);
byte[] decryptedText = encSpi.decrypt(cipherText, k);
assertNotNull(decryptedText);
assertEquals(plainText.length, decryptedText.length);
assertEquals(new String(plainText, UTF_8), new String(decryptedText, UTF_8));
}
use of org.apache.ignite.spi.encryption.keystore.KeystoreEncryptionKey in project ignite by apache.
the class EncryptedCacheBigEntryTest method testCreateEncryptedCacheWithBigEntry.
/**
* @throws Exception If failed.
*/
@Test
public void testCreateEncryptedCacheWithBigEntry() throws Exception {
T2<IgniteEx, IgniteEx> grids = startTestGrids(true);
createEncryptedCache(grids.get1(), grids.get2(), cacheName(), null);
checkEncryptedCaches(grids.get1(), grids.get2());
int grpId = CU.cacheGroupId(cacheName(), null);
KeystoreEncryptionKey keyBeforeRestart = (KeystoreEncryptionKey) grids.get1().context().encryption().getActiveKey(grpId).key();
stopAllGrids();
grids = startTestGrids(false);
checkEncryptedCaches(grids.get1(), grids.get2());
GroupKey grpKeyAfterRestart = grids.get1().context().encryption().getActiveKey(grpId);
assertNotNull(grpKeyAfterRestart);
KeystoreEncryptionKey keyAfterRestart = (KeystoreEncryptionKey) grpKeyAfterRestart.key();
assertNotNull(keyAfterRestart);
assertNotNull(keyAfterRestart.key());
assertEquals(keyBeforeRestart.key(), keyAfterRestart.key());
}
use of org.apache.ignite.spi.encryption.keystore.KeystoreEncryptionKey in project ignite by apache.
the class AbstractEncryptionTest method checkEncryptedCaches.
/**
*/
void checkEncryptedCaches(IgniteEx grid0, IgniteEx grid1) {
Set<String> cacheNames = new HashSet<>(grid0.cacheNames());
cacheNames.addAll(grid1.cacheNames());
for (String cacheName : cacheNames) {
CacheConfiguration ccfg = grid1.cache(cacheName).getConfiguration(CacheConfiguration.class);
if (!ccfg.isEncryptionEnabled())
continue;
IgniteInternalCache<?, ?> encrypted0 = grid0.cachex(cacheName);
int grpId = CU.cacheGroupId(cacheName, ccfg.getGroupName());
assertNotNull(encrypted0);
IgniteInternalCache<?, ?> encrypted1 = grid1.cachex(cacheName);
assertNotNull(encrypted1);
assertTrue(encrypted1.configuration().isEncryptionEnabled());
GroupKey grpKey0 = grid0.context().encryption().getActiveKey(grpId);
assertNotNull(grpKey0);
KeystoreEncryptionKey encKey0 = (KeystoreEncryptionKey) grpKey0.key();
assertNotNull(encKey0);
assertNotNull(encKey0.key());
if (!grid1.configuration().isClientMode()) {
GroupKey grpKey1 = grid1.context().encryption().getActiveKey(grpId);
assertNotNull(grpKey1);
KeystoreEncryptionKey encKey1 = (KeystoreEncryptionKey) grpKey1.key();
assertNotNull(encKey1);
assertNotNull(encKey1.key());
assertEquals(encKey0.key(), encKey1.key());
} else
assertNull(grid1.context().encryption().getActiveKey(grpId));
}
checkData(grid0);
}
use of org.apache.ignite.spi.encryption.keystore.KeystoreEncryptionKey in project ignite by apache.
the class EncryptedCacheGroupCreateTest method testCreateEncryptedCacheGroup.
/**
* @throws Exception If failed.
*/
@Test
public void testCreateEncryptedCacheGroup() throws Exception {
KeystoreEncryptionKey key = createEncryptedCache(ENCRYPTED_CACHE, ENCRYPTED_GROUP);
CacheConfiguration<Long, String> ccfg = new CacheConfiguration<>(ENCRYPTED_CACHE + "2");
ccfg.setEncryptionEnabled(true);
ccfg.setGroupName(ENCRYPTED_GROUP);
IgniteEx grid = grid(0);
grid.createCache(ccfg);
IgniteInternalCache<Object, Object> encrypted2 = grid.cachex(ENCRYPTED_CACHE + "2");
GridEncryptionManager encMgr = encrypted2.context().kernalContext().encryption();
GroupKey grpKey2 = encMgr.getActiveKey(CU.cacheGroupId(ENCRYPTED_CACHE, ENCRYPTED_GROUP));
assertNotNull(grpKey2);
KeystoreEncryptionKey key2 = (KeystoreEncryptionKey) grpKey2.key();
assertNotNull(key2);
assertNotNull(key2.key());
assertEquals(key.key(), key2.key());
}
Aggregations