Search in sources :

Example 1 with GroupKey

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());
}
Also used : KeystoreEncryptionKey(org.apache.ignite.spi.encryption.keystore.KeystoreEncryptionKey) IgniteEx(org.apache.ignite.internal.IgniteEx) GroupKey(org.apache.ignite.internal.managers.encryption.GroupKey) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Test(org.junit.Test)

Example 2 with GroupKey

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;
}
Also used : KeystoreEncryptionKey(org.apache.ignite.spi.encryption.keystore.KeystoreEncryptionKey) IgniteEx(org.apache.ignite.internal.IgniteEx) GroupKey(org.apache.ignite.internal.managers.encryption.GroupKey) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 3 with GroupKey

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));
    }
}
Also used : MetaStorage(org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage) GroupKey(org.apache.ignite.internal.managers.encryption.GroupKey)

Example 4 with GroupKey

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());
}
Also used : KeystoreEncryptionKey(org.apache.ignite.spi.encryption.keystore.KeystoreEncryptionKey) IgniteEx(org.apache.ignite.internal.IgniteEx) GroupKey(org.apache.ignite.internal.managers.encryption.GroupKey) Test(org.junit.Test)

Example 5 with GroupKey

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);
}
Also used : GroupKey(org.apache.ignite.internal.managers.encryption.GroupKey)

Aggregations

GroupKey (org.apache.ignite.internal.managers.encryption.GroupKey)26 KeystoreEncryptionKey (org.apache.ignite.spi.encryption.keystore.KeystoreEncryptionKey)16 IgniteEx (org.apache.ignite.internal.IgniteEx)14 Test (org.junit.Test)12 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)8 EncryptedCacheRestartTest (org.apache.ignite.internal.encryption.EncryptedCacheRestartTest)4 HashSet (java.util.HashSet)2 GridEncryptionManager (org.apache.ignite.internal.managers.encryption.GridEncryptionManager)2 RecordType (org.apache.ignite.internal.pagemem.wal.record.WALRecord.RecordType)2 MetaStorage (org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage)2 ByteBufferBackedDataInputImpl (org.apache.ignite.internal.processors.cache.persistence.wal.ByteBufferBackedDataInputImpl)2 RecordV1Serializer.putRecordType (org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordV1Serializer.putRecordType)2 T3 (org.apache.ignite.internal.util.typedef.T3)2 ByteBuffer (java.nio.ByteBuffer)1 MappedByteBuffer (java.nio.MappedByteBuffer)1