Search in sources :

Example 6 with KeystoreEncryptionKey

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

Example 7 with KeystoreEncryptionKey

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

Example 8 with KeystoreEncryptionKey

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());
}
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 9 with KeystoreEncryptionKey

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

Example 10 with KeystoreEncryptionKey

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

Aggregations

KeystoreEncryptionKey (org.apache.ignite.spi.encryption.keystore.KeystoreEncryptionKey)12 GroupKey (org.apache.ignite.internal.managers.encryption.GroupKey)8 Test (org.junit.Test)8 IgniteEx (org.apache.ignite.internal.IgniteEx)7 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)4 EncryptedCacheRestartTest (org.apache.ignite.internal.encryption.EncryptedCacheRestartTest)2 KeystoreEncryptionSpi (org.apache.ignite.spi.encryption.keystore.KeystoreEncryptionSpi)2 ByteBuffer (java.nio.ByteBuffer)1 HashSet (java.util.HashSet)1 JmhAbstractBenchmark (org.apache.ignite.internal.benchmarks.jmh.JmhAbstractBenchmark)1 GridEncryptionManager (org.apache.ignite.internal.managers.encryption.GridEncryptionManager)1 Benchmark (org.openjdk.jmh.annotations.Benchmark)1