use of org.apache.ignite.internal.managers.encryption.GroupKey in project ignite by apache.
the class EncryptedCacheCreateTest method testCreateEncryptedCache.
/**
* @throws Exception If failed.
*/
@Test
public void testCreateEncryptedCache() throws Exception {
CacheConfiguration<Long, String> ccfg = new CacheConfiguration<>(ENCRYPTED_CACHE);
ccfg.setEncryptionEnabled(true);
IgniteEx grid = grid(0);
grid.createCache(ccfg);
IgniteInternalCache<Object, Object> enc = grid.cachex(ENCRYPTED_CACHE);
assertNotNull(enc);
GroupKey grpKey = grid.context().encryption().getActiveKey(CU.cacheGroupId(ENCRYPTED_CACHE, null));
assertNotNull(grpKey);
KeystoreEncryptionKey key = (KeystoreEncryptionKey) grpKey.key();
assertNotNull(key);
assertNotNull(key.key());
}
use of org.apache.ignite.internal.managers.encryption.GroupKey in project ignite by apache.
the class EncryptedCacheGroupCreateTest method createEncryptedCache.
/**
*/
private KeystoreEncryptionKey createEncryptedCache(String cacheName, String grpName) {
CacheConfiguration<Long, String> ccfg = new CacheConfiguration<>(cacheName);
ccfg.setEncryptionEnabled(true);
ccfg.setGroupName(grpName);
IgniteEx grid = grid(0);
grid.createCache(ccfg);
IgniteInternalCache<Object, Object> enc = grid.cachex(cacheName);
assertNotNull(enc);
GroupKey grpKey = grid.context().encryption().getActiveKey(CU.cacheGroupId(cacheName, grpName));
assertNotNull(grpKey);
KeystoreEncryptionKey key = (KeystoreEncryptionKey) grpKey.key();
assertNotNull(key);
assertNotNull(key.key());
return key;
}
use of org.apache.ignite.internal.managers.encryption.GroupKey in project ignite by apache.
the class EncryptedCacheDestroyTest method checkCacheDestroyed.
/**
*/
private void checkCacheDestroyed(IgniteEx grid, String encCacheName, String grpName, boolean keyShouldBeEmpty) throws Exception {
awaitPartitionMapExchange();
Collection<String> cacheNames = grid.cacheNames();
for (String cacheName : cacheNames) {
if (cacheName.equals(encCacheName))
fail(encCacheName + " should be destroyed.");
}
int grpId = CU.cacheGroupId(encCacheName, grpName);
GroupKey encKey = grid.context().encryption().getActiveKey(grpId);
MetaStorage metaStore = grid.context().cache().context().database().metaStorage();
if (keyShouldBeEmpty) {
assertNull(encKey);
assertNull(metaStore.readRaw(ENCRYPTION_KEYS_PREFIX + grpId));
} else {
assertNotNull(encKey);
assertNotNull(metaStore.readRaw(ENCRYPTION_KEYS_PREFIX + grpId));
}
}
use of org.apache.ignite.internal.managers.encryption.GroupKey in project ignite by apache.
the class EncryptedCacheRestartTest method testCreateEncryptedCache.
/**
* @throws Exception If failed.
*/
@Test
public void testCreateEncryptedCache() 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.internal.managers.encryption.GroupKey in project ignite by apache.
the class EncryptedFileIO method decrypt.
/**
* @param encrypted Encrypted buffer.
* @param destBuf Destination buffer.
*/
private void decrypt(ByteBuffer encrypted, ByteBuffer destBuf) throws IOException {
int keyId = encrypted.get(encryptedDataSize() + 4) & 0xff;
GroupKey key = keyProvider.groupKey(groupId, keyId);
assert key != null : "No encryption key found for cache group " + groupId + " by key id " + keyId;
encUtil.decrypt(encrypted, destBuf, key);
}
Aggregations