Search in sources :

Example 11 with OSecurityException

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

the class OEncryptionFactory method getEncryption.

public OEncryption getEncryption(final String name, final String iOptions) {
    OEncryption encryption = instances.get(name);
    if (encryption == null) {
        final Class<? extends OEncryption> encryptionClass;
        if (name == null)
            encryptionClass = ONothingEncryption.class;
        else
            encryptionClass = classes.get(name);
        if (encryptionClass != null) {
            try {
                encryption = encryptionClass.newInstance();
                encryption.configure(iOptions);
            } catch (Exception e) {
                throw OException.wrapException(new OSecurityException("Cannot instantiate encryption algorithm '" + name + "'"), e);
            }
        } else
            throw new OSecurityException("Encryption with name '" + name + "' is absent");
    }
    return encryption;
}
Also used : ONothingEncryption(com.orientechnologies.orient.core.encryption.impl.ONothingEncryption) OSecurityException(com.orientechnologies.orient.core.exception.OSecurityException) OSecurityException(com.orientechnologies.orient.core.exception.OSecurityException) OException(com.orientechnologies.common.exception.OException)

Example 12 with OSecurityException

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

the class OAESEncryption method encryptOrDecrypt.

public byte[] encryptOrDecrypt(final int mode, final byte[] input, final int offset, final int length) throws Exception {
    if (!initialized)
        throw new OSecurityException("AES encryption algorithm is not available");
    cipher.init(mode, theKey);
    final byte[] content;
    if (offset == 0 && length == input.length) {
        content = input;
    } else {
        content = new byte[length];
        System.arraycopy(input, offset, content, 0, length);
    }
    return cipher.doFinal(content);
}
Also used : OSecurityException(com.orientechnologies.orient.core.exception.OSecurityException)

Example 13 with OSecurityException

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

the class OAESEncryption method configure.

public OEncryption configure(final String iOptions) {
    initialized = false;
    if (iOptions == null)
        throw new OSecurityException("AES encryption has been selected, but no key was found. Please configure it by passing the key as property at database create/open. The property key is: '" + OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey() + "'");
    try {
        final byte[] key = OBase64Utils.decode(iOptions);
        // AES
        theKey = new SecretKeySpec(key, ALGORITHM_NAME);
        cipher = Cipher.getInstance(TRANSFORMATION);
    } catch (Exception e) {
        throw OException.wrapException(new OInvalidStorageEncryptionKeyException("Cannot initialize AES encryption with current key. Assure the key is a BASE64 - 128 oe 256 bits long"), e);
    }
    this.initialized = true;
    return this;
}
Also used : OInvalidStorageEncryptionKeyException(com.orientechnologies.orient.core.exception.OInvalidStorageEncryptionKeyException) SecretKeySpec(javax.crypto.spec.SecretKeySpec) OSecurityException(com.orientechnologies.orient.core.exception.OSecurityException) OSecurityException(com.orientechnologies.orient.core.exception.OSecurityException) OInvalidStorageEncryptionKeyException(com.orientechnologies.orient.core.exception.OInvalidStorageEncryptionKeyException) OException(com.orientechnologies.common.exception.OException)

Example 14 with OSecurityException

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

the class ODESEncryption method encryptOrDecrypt.

public byte[] encryptOrDecrypt(final int mode, final byte[] input, final int offset, final int length) throws Exception {
    if (!initialized)
        throw new OSecurityException("DES encryption algorithm is not available");
    cipher.init(mode, theKey);
    final byte[] content;
    if (offset == 0 && length == input.length) {
        content = input;
    } else {
        content = new byte[length];
        System.arraycopy(input, offset, content, 0, length);
    }
    return cipher.doFinal(content);
}
Also used : OSecurityException(com.orientechnologies.orient.core.exception.OSecurityException)

Example 15 with OSecurityException

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

the class OIdentifiableIterator method readCurrentRecord.

/**
   * Read the current record and increment the counter if the record was found.
   * 
   * @param iRecord
   *          to read value from database inside it. If record is null link will be created and stored in it.
   * @return record which was read from db.
   */
protected ORecord readCurrentRecord(ORecord iRecord, final int iMovement) {
    if (limit > -1 && browsedRecords >= limit)
        // LIMIT REACHED
        return null;
    do {
        final boolean moveResult;
        switch(iMovement) {
            case 1:
                moveResult = nextPosition();
                break;
            case -1:
                moveResult = prevPosition();
                break;
            case 0:
                moveResult = checkCurrentPosition();
                break;
            default:
                throw new IllegalStateException("Invalid movement value : " + iMovement);
        }
        if (!moveResult)
            return null;
        try {
            if (iRecord != null) {
                ORecordInternal.setIdentity(iRecord, new ORecordId(current.getClusterId(), current.getClusterPosition()));
                iRecord = lowLevelDatabase.load(iRecord, fetchPlan, false, true, iterateThroughTombstones, lockingStrategy);
            } else
                iRecord = lowLevelDatabase.load(current, fetchPlan, false, true, iterateThroughTombstones, lockingStrategy);
        } catch (ODatabaseException e) {
            if (Thread.interrupted() || lowLevelDatabase.isClosed())
                // THREAD INTERRUPTED: RETURN
                throw e;
            if (e.getCause() instanceof OSecurityException)
                throw e;
            OLogManager.instance().error(this, "Error on fetching record during browsing. The record has been skipped", e);
        }
        if (iRecord != null) {
            browsedRecords++;
            return iRecord;
        }
    } while (iMovement != 0);
    return null;
}
Also used : OSecurityException(com.orientechnologies.orient.core.exception.OSecurityException) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException) ORecordId(com.orientechnologies.orient.core.id.ORecordId)

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