-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fixed bug with management of TX isolation from cached vertices
The solution is in the force of reloading of the record when the page is not in transaction. This assure the record is the same as for the loaded page. Without this fix, the record can be outdated managed with the loading of an updated page, so the MVCC check passes causing a overwrite of a new record with an old one.
- Loading branch information
Showing
7 changed files
with
122 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
package com.arcadedb.event; | ||
|
||
import com.arcadedb.TestHelper; | ||
import com.arcadedb.database.Database; | ||
import com.arcadedb.database.Record; | ||
import com.arcadedb.graph.MutableVertex; | ||
import com.arcadedb.graph.Vertex; | ||
|
@@ -45,7 +46,8 @@ | |
* | ||
* @author Luca Garulli ([email protected]) | ||
*/ | ||
public class RecordEncryptionTest extends TestHelper implements BeforeRecordCreateListener, AfterRecordReadListener, BeforeRecordUpdateListener { | ||
public class RecordEncryptionTest extends TestHelper | ||
implements BeforeRecordCreateListener, AfterRecordReadListener, BeforeRecordUpdateListener { | ||
private final static String password = "JustAPassword"; | ||
private final static String PASSWORD_ALGORITHM = "PBKDF2WithHmacSHA256"; | ||
private final static String ALGORITHM = "AES/CBC/PKCS5Padding"; | ||
|
@@ -73,13 +75,15 @@ public void beginTest() { | |
} | ||
|
||
@Test | ||
public void testEncryptionAtRest() { | ||
public void testEncryption() { | ||
database.transaction(() -> { | ||
final MutableVertex v1 = database.newVertex("BackAccount").set("secret", "Nobody must know Elon and Zuck are brothers").save(); | ||
final MutableVertex v1 = database.newVertex("BackAccount").set("secret", "Nobody must know Elon and Zuck are brothers") | ||
.save(); | ||
}); | ||
|
||
Assertions.assertEquals(1, creates.get()); | ||
|
||
database.setTransactionIsolationLevel(Database.TRANSACTION_ISOLATION_LEVEL.REPEATABLE_READ); | ||
database.transaction(() -> { | ||
final Vertex v1 = database.iterateType("BackAccount", true).next().asVertex(); | ||
Assertions.assertEquals("Nobody must know Elon and Zuck are brothers", v1.getString("secret")); | ||
|
@@ -140,25 +144,26 @@ public boolean onBeforeUpdate(Record record) { | |
} | ||
|
||
public static String encrypt(String algorithm, String input, SecretKey key, IvParameterSpec iv) | ||
throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, BadPaddingException, | ||
IllegalBlockSizeException { | ||
throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, | ||
BadPaddingException, IllegalBlockSizeException { | ||
final Cipher cipher = Cipher.getInstance(algorithm); | ||
cipher.init(Cipher.ENCRYPT_MODE, key, iv); | ||
final byte[] cipherText = cipher.doFinal(input.getBytes()); | ||
return Base64.getEncoder().encodeToString(cipherText); | ||
} | ||
|
||
public static String decrypt(String algorithm, String cipherText, SecretKey key, IvParameterSpec iv) | ||
throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, BadPaddingException, | ||
IllegalBlockSizeException { | ||
throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, | ||
BadPaddingException, IllegalBlockSizeException { | ||
|
||
final Cipher cipher = Cipher.getInstance(algorithm); | ||
cipher.init(Cipher.DECRYPT_MODE, key, iv); | ||
final byte[] plainText = cipher.doFinal(Base64.getDecoder().decode(cipherText)); | ||
return new String(plainText); | ||
} | ||
|
||
public static SecretKey getKeyFromPassword(final String password, final String salt) throws NoSuchAlgorithmException, InvalidKeySpecException { | ||
public static SecretKey getKeyFromPassword(final String password, final String salt) | ||
throws NoSuchAlgorithmException, InvalidKeySpecException { | ||
final SecretKeyFactory factory = SecretKeyFactory.getInstance(PASSWORD_ALGORITHM); | ||
final KeySpec spec = new PBEKeySpec(password.toCharArray(), salt.getBytes(), SALT_ITERATIONS, KEY_LENGTH); | ||
return new SecretKeySpec(factory.generateSecret(spec).getEncoded(), "AES"); | ||
|