Search in sources :

Example 21 with OSecurityException

use of com.orientechnologies.orient.core.exception.OSecurityException in project orientdb by orientechnologies.

the class OAESEncryptionTest method testCreatedAESEncryptedDatabase.

public void testCreatedAESEncryptedDatabase() {
    String buildDirectory = System.getProperty("buildDirectory", ".");
    final String dbPath = buildDirectory + File.separator + DBNAME_DATABASETEST;
    OFileUtils.deleteRecursively(new File(dbPath));
    final ODatabase db = new ODatabaseDocumentTx("plocal:" + dbPath);
    db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_METHOD.getKey(), "aes");
    db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA==");
    db.create();
    try {
        db.command(new OCommandSQL("create class TestEncryption")).execute();
        db.command(new OCommandSQL("insert into TestEncryption set name = 'Jay'")).execute();
        List result = db.query(new OSQLSynchQuery<ODocument>("select from TestEncryption"));
        Assert.assertEquals(result.size(), 1);
        db.close();
        db.open("admin", "admin");
        OStorage storage = ((ODatabaseDocumentInternal) db).getStorage();
        db.close();
        storage.close(true, false);
        db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA==");
        db.open("admin", "admin");
        result = db.query(new OSQLSynchQuery<ODocument>("select from TestEncryption"));
        Assert.assertEquals(result.size(), 1);
        storage = ((ODatabaseDocumentInternal) db).getStorage();
        db.close();
        storage.close(true, false);
        db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "invalidPassword");
        try {
            db.open("admin", "admin");
            storage = ((ODatabaseDocumentInternal) db).getStorage();
            Assert.fail();
        } catch (OSecurityException e) {
            Assert.assertTrue(true);
        } finally {
            db.activateOnCurrentThread();
            db.close();
            storage.close(true, false);
        }
        db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA=-");
        try {
            db.open("admin", "admin");
            storage = ((ODatabaseDocumentInternal) db).getStorage();
            Assert.fail();
        } catch (OSecurityException e) {
            Assert.assertTrue(true);
        } finally {
            db.activateOnCurrentThread();
            db.close();
            storage.close(true, false);
        }
        db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA==");
        db.open("admin", "admin");
        result = db.query(new OSQLSynchQuery<ODocument>("select from TestEncryption"));
        Assert.assertEquals(result.size(), 1);
    } finally {
        db.activateOnCurrentThread();
        if (db.isClosed())
            db.open("admin", "admin");
        db.drop();
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OStorage(com.orientechnologies.orient.core.storage.OStorage) List(java.util.List) OSecurityException(com.orientechnologies.orient.core.exception.OSecurityException) ODatabase(com.orientechnologies.orient.core.db.ODatabase) File(java.io.File) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 22 with OSecurityException

use of com.orientechnologies.orient.core.exception.OSecurityException in project orientdb by orientechnologies.

the class ODESEncryptionTest method testCreatedDESEncryptedCluster.

public void testCreatedDESEncryptedCluster() {
    OFileUtils.deleteRecursively(new File("target/" + DBNAME_CLUSTERTEST));
    final ODatabase db = new ODatabaseDocumentTx("plocal:target/" + DBNAME_CLUSTERTEST);
    db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA==");
    db.create();
    try {
        db.command(new OCommandSQL("create class TestEncryption")).execute();
        db.command(new OCommandSQL("alter class TestEncryption encryption des")).execute();
        db.command(new OCommandSQL("insert into TestEncryption set name = 'Jay'")).execute();
        List result = db.query(new OSQLSynchQuery<ODocument>("select from TestEncryption"));
        Assert.assertEquals(result.size(), 1);
        db.close();
        db.open("admin", "admin");
        db.close();
        Orient.instance().getStorage(DBNAME_CLUSTERTEST).close(true, false);
        db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA==");
        db.open("admin", "admin");
        result = db.query(new OSQLSynchQuery<ODocument>("select from TestEncryption"));
        Assert.assertEquals(result.size(), 1);
        db.close();
        Orient.instance().getStorage(DBNAME_CLUSTERTEST).close(true, false);
        db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "invalidPassword");
        try {
            db.open("admin", "admin");
            db.query(new OSQLSynchQuery<ODocument>("select from TestEncryption"));
            result = db.query(new OSQLSynchQuery<ODocument>("select from OUser"));
            Assert.assertFalse(result.isEmpty());
            Assert.fail();
        } catch (OSecurityException e) {
            Assert.assertTrue(true);
        } finally {
            db.activateOnCurrentThread();
            db.close();
            Orient.instance().getStorage(DBNAME_CLUSTERTEST).close(true, false);
        }
        db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA=-");
        try {
            db.open("admin", "admin");
            db.query(new OSQLSynchQuery<ODocument>("select from TestEncryption"));
            Assert.fail();
        } catch (OSecurityException e) {
            Assert.assertTrue(true);
        } finally {
            db.activateOnCurrentThread();
            db.close();
            Orient.instance().getStorage(DBNAME_CLUSTERTEST).close(true, false);
        }
        db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA==");
        db.open("admin", "admin");
        result = db.query(new OSQLSynchQuery<ODocument>("select from TestEncryption"));
        Assert.assertEquals(result.size(), 1);
    } finally {
        db.activateOnCurrentThread();
        if (db.exists())
            db.drop();
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) List(java.util.List) OSecurityException(com.orientechnologies.orient.core.exception.OSecurityException) ODatabase(com.orientechnologies.orient.core.db.ODatabase) File(java.io.File) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 23 with OSecurityException

use of com.orientechnologies.orient.core.exception.OSecurityException in project orientdb by orientechnologies.

the class ONothingEncryptionTest method testCreatedNothingEncryptedDatabase.

public void testCreatedNothingEncryptedDatabase() {
    OFileUtils.deleteRecursively(new File("target/" + DBNAME_DATABASETEST));
    final ODatabase db = new ODatabaseDocumentTx("plocal:target/" + DBNAME_DATABASETEST);
    db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_METHOD.getKey(), "des");
    db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA==");
    db.create();
    try {
        db.command(new OCommandSQL("create class TestEncryption")).execute();
        db.command(new OCommandSQL("insert into TestEncryption set name = 'Jay'")).execute();
        List result = db.query(new OSQLSynchQuery<ODocument>("select from TestEncryption"));
        Assert.assertEquals(result.size(), 1);
        db.close();
        db.open("admin", "admin");
        db.close();
        Orient.instance().getStorage(DBNAME_DATABASETEST).close(true, false);
        db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA==");
        db.open("admin", "admin");
        result = db.query(new OSQLSynchQuery<ODocument>("select from TestEncryption"));
        Assert.assertEquals(result.size(), 1);
        db.close();
        Orient.instance().getStorage(DBNAME_DATABASETEST).close(true, false);
        db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "invalidPassword");
        try {
            db.open("admin", "admin");
            Assert.fail();
        } catch (OSecurityException e) {
            Assert.assertTrue(true);
        } finally {
            db.activateOnCurrentThread();
            db.close();
            Orient.instance().getStorage(DBNAME_DATABASETEST).close(true, false);
        }
        db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA=-");
        try {
            db.open("admin", "admin");
            Assert.fail();
        } catch (OSecurityException e) {
            Assert.assertTrue(true);
        } finally {
            db.activateOnCurrentThread();
            db.close();
            Orient.instance().getStorage(DBNAME_DATABASETEST).close(true, false);
        }
        db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA==");
        db.open("admin", "admin");
        result = db.query(new OSQLSynchQuery<ODocument>("select from TestEncryption"));
        Assert.assertEquals(result.size(), 1);
    } finally {
        db.activateOnCurrentThread();
        db.drop();
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) List(java.util.List) OSecurityException(com.orientechnologies.orient.core.exception.OSecurityException) ODatabase(com.orientechnologies.orient.core.db.ODatabase) File(java.io.File) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 24 with OSecurityException

use of com.orientechnologies.orient.core.exception.OSecurityException in project orientdb by orientechnologies.

the class OrientGraphFactoryEncryptionTest method verifyDatabaseEncryption.

public void verifyDatabaseEncryption(OrientGraphFactory fc) {
    ODatabaseDocumentTx db = fc.getDatabase();
    db.command(new OCommandSQL("create class TestEncryption")).execute();
    db.command(new OCommandSQL("insert into TestEncryption set name = 'Jay'")).execute();
    List result = db.query(new OSQLSynchQuery<ODocument>("select from TestEncryption"));
    Assert.assertEquals(result.size(), 1);
    db.close();
    db = fc.getDatabase();
    OStorage storage = ((ODatabaseDocumentInternal) db).getStorage();
    db.close();
    storage.close(true, false);
    fc.setProperty(STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA==");
    db = fc.getDatabase();
    result = db.query(new OSQLSynchQuery<ODocument>("select from TestEncryption"));
    Assert.assertEquals(result.size(), 1);
    storage = ((ODatabaseDocumentInternal) db).getStorage();
    db.close();
    storage.close(true, false);
    db = fc.getDatabase();
    db.setProperty(STORAGE_ENCRYPTION_KEY.getKey(), "invalidPassword");
    try {
        storage = ((ODatabaseDocumentInternal) db).getStorage();
        Assert.fail();
    } catch (OSecurityException e) {
        Assert.assertTrue(true);
    } finally {
        db.activateOnCurrentThread();
        db.close();
        storage.close(true, false);
    }
    fc.setProperty(STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA=-");
    try {
        db = fc.getDatabase();
        storage = ((ODatabaseDocumentInternal) db).getStorage();
        Assert.fail();
    } catch (OSecurityException e) {
        Assert.assertTrue(true);
    } finally {
        db.activateOnCurrentThread();
        db.close();
        storage.close(true, false);
    }
    fc.setProperty(STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA==");
    db = fc.getDatabase();
    result = db.query(new OSQLSynchQuery<ODocument>("select from TestEncryption"));
    Assert.assertEquals(result.size(), 1);
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OStorage(com.orientechnologies.orient.core.storage.OStorage) List(java.util.List) OSecurityException(com.orientechnologies.orient.core.exception.OSecurityException) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OSecurityException (com.orientechnologies.orient.core.exception.OSecurityException)24 OException (com.orientechnologies.common.exception.OException)13 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)8 IOException (java.io.IOException)8 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)7 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)7 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)6 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)6 FileNotFoundException (java.io.FileNotFoundException)6 KeyStoreException (java.security.KeyStoreException)6 List (java.util.List)6 BadPaddingException (javax.crypto.BadPaddingException)6 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)6 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)6 ODatabase (com.orientechnologies.orient.core.db.ODatabase)5 File (java.io.File)5 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)4 OStorage (com.orientechnologies.orient.core.storage.OStorage)3 OConfigurationException (com.orientechnologies.orient.core.exception.OConfigurationException)2