int grpId = CU.cacheGroupId(cfg.getName(), cfg.getGroupName());
int grpId = CU.cacheGroupId(startedCacheCfg.getName(), startedCacheCfg.getGroupName());
/** @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); KeystoreEncryptionKey key = (KeystoreEncryptionKey)grid.context().encryption().groupKey(CU.cacheGroupId(ENCRYPTED_CACHE, null)); assertNotNull(key); assertNotNull(key.key()); }
/** */ 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); KeystoreEncryptionKey key = (KeystoreEncryptionKey)grid.context().encryption().groupKey(CU.cacheGroupId(cacheName, grpName)); assertNotNull(key); assertNotNull(key.key()); return key; } }
/** */ 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); KeystoreEncryptionKey encKey = (KeystoreEncryptionKey)grid.context().encryption().groupKey(grpId); MetaStorage metaStore = grid.context().cache().context().database().metaStorage(); if (keyShouldBeEmpty) { assertNull(encKey); assertNull(metaStore.readRaw(ENCRYPTION_KEY_PREFIX + grpId)); } else { assertNotNull(encKey); assertNotNull(metaStore.readRaw(ENCRYPTION_KEY_PREFIX + grpId)); } } }
/** @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(); KeystoreEncryptionKey key2 = (KeystoreEncryptionKey)encMgr.groupKey(CU.cacheGroupId(ENCRYPTED_CACHE, ENCRYPTED_GROUP)); assertNotNull(key2); assertNotNull(key2.key()); assertEquals(key.key(), key2.key()); }
/** */ 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()); KeystoreEncryptionKey encKey0 = (KeystoreEncryptionKey)grid0.context().encryption().groupKey(grpId); assertNotNull(encKey0); assertNotNull(encKey0.key()); if (!grid1.configuration().isClientMode()) { KeystoreEncryptionKey encKey1 = (KeystoreEncryptionKey)grid1.context().encryption().groupKey(grpId); assertNotNull(encKey1); assertNotNull(encKey1.key()); assertEquals(encKey0.key(), encKey1.key()); } else assertNull(grid1.context().encryption().groupKey(grpId)); } checkData(grid0); }
/** @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().groupKey(grpId); stopAllGrids(); grids = startTestGrids(false); checkEncryptedCaches(grids.get1(), grids.get2()); KeystoreEncryptionKey keyAfterRestart = (KeystoreEncryptionKey)grids.get1().context().encryption().groupKey(grpId); assertNotNull(keyAfterRestart); assertNotNull(keyAfterRestart.key()); assertEquals(keyBeforeRestart.key(), keyAfterRestart.key()); }
/** @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().groupKey(grpId); stopAllGrids(); grids = startTestGrids(false); checkEncryptedCaches(grids.get1(), grids.get2()); KeystoreEncryptionKey keyAfterRestart = (KeystoreEncryptionKey)grids.get1().context().encryption().groupKey(grpId); assertNotNull(keyAfterRestart); assertNotNull(keyAfterRestart.key()); assertEquals(keyBeforeRestart.key(), keyAfterRestart.key()); } }
int grpId = CU.cacheGroupId(cfg.getName(), cfg.getGroupName());
int grpId = CU.cacheGroupId(startedCacheCfg.getName(), startedCacheCfg.getGroupName());