IDEMPIERE-5604 Column Encryption not marking column as encrypted - data corruption (#1766)

This commit is contained in:
Carlos Ruiz 2023-04-02 09:38:37 +02:00 committed by GitHub
parent 65f565e542
commit 022ff3749b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 37 additions and 38 deletions

View File

@ -193,45 +193,44 @@ public class ColumnEncryption extends SvrProcess {
} }
} }
count = 0; if (error) {
// If only user chooses both encrypt the contents and override current msglog = new StringBuilder("Encryption NOT changed - Encryption=")
// settings resize the physical column and encrypt all its contents. .append(column.isEncrypted());
if (p_ChangeSetting && column.isEncrypted() != p_IsEncrypted) { addLog(0, null, null, msglog.toString());
int columnID = column.get_ID(); } else {
MTable table = MTable.get(getCtx(), column.getAD_Table_ID()); count = 0;
if (p_IsEncrypted) { // If only user chooses both encrypt the contents and override current
// Check if the encryption exceeds the current length. // settings resize the physical column and encrypt all its contents.
int oldLength = column.getFieldLength(); if (p_ChangeSetting && column.isEncrypted() != p_IsEncrypted) {
int newLength = encryptedColumnLength(p_MaxLength > 0 ? p_MaxLength : oldLength); int columnID = column.get_ID();
if (newLength > oldLength) { MTable table = MTable.get(getCtx(), column.getAD_Table_ID());
if (changeFieldLength(table, column, newLength) < 0) { if (p_IsEncrypted) {
log.warning("EncryptError [ChangeFieldLength]: " // Check if the encryption exceeds the current length.
+ "ColumnID=" + columnID + ", NewLength=" int oldLength = column.getFieldLength();
+ newLength); int newLength = encryptedColumnLength(p_MaxLength > 0 ? p_MaxLength : oldLength);
if (newLength > oldLength) {
if (changeFieldLength(table, column, newLength) < 0) {
log.warning("EncryptError [ChangeFieldLength]: "
+ "ColumnID=" + columnID + ", NewLength="
+ newLength);
throw new Exception();
}
}
// Encrypt column contents.
count = encryptColumnContents(columnName, column.getAD_Table_ID());
if (count == -1) {
log.warning("EncryptError: No records encrypted.");
throw new Exception();
}
} else {
// Decrypt column contents.
count = decryptColumnContents(columnName, column.getAD_Table_ID());
if (count == -1) {
log.warning("DecryptError: No records decrypted.");
throw new Exception(); throw new Exception();
} }
} }
// Encrypt column contents.
count = encryptColumnContents(columnName, column.getAD_Table_ID());
if (count == -1) {
log.warning("EncryptError: No records encrypted.");
throw new Exception();
}
} else {
// Decrypt column contents.
count = decryptColumnContents(columnName, column.getAD_Table_ID());
if (count == -1) {
log.warning("DecryptError: No records decrypted.");
throw new Exception();
}
}
if (error || !p_ChangeSetting){
msglog = new StringBuilder("Encryption NOT changed - Encryption=")
.append(column.isEncrypted());
addLog(0, null, null, msglog.toString());
} else {
column.setIsEncrypted(p_IsEncrypted); column.setIsEncrypted(p_IsEncrypted);
if (column.save()){ if (column.save()){
addLog(0, null, null, "#" + (p_IsEncrypted ? "Encrypted=" : "Decrypted=") +count); addLog(0, null, null, "#" + (p_IsEncrypted ? "Encrypted=" : "Decrypted=") +count);
@ -240,9 +239,9 @@ public class ColumnEncryption extends SvrProcess {
addLog(0, null, null, msglog.toString()); addLog(0, null, null, msglog.toString());
} else } else
addLog(0, null, null, "Save Error"); addLog(0, null, null, "Save Error");
} else {
addLog(0, null, null, "Can't perform " + (p_IsEncrypted ? "encryption. " : "decryption. ") + "Column is " + (p_IsEncrypted ? "already Encrypted." : " not Encrypted."));
} }
} else {
addLog(0, null, null, "Can't perform " + (p_IsEncrypted ? "encryption. " : "decryption. ") + "Column is " + (p_IsEncrypted ? "already Encrypted." : " not Encrypted."));
} }
StringBuilder msgreturn = new StringBuilder("Encryption=").append(column.isEncrypted()); StringBuilder msgreturn = new StringBuilder("Encryption=").append(column.isEncrypted());